Sidebar.Geometry.TubeGeometry.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /**
  2. * @author Temdog007 / http://github.com/Temdog007
  3. */
  4. import {
  5. CatmullRomCurve3,
  6. TubeBufferGeometry
  7. } from '../../build/three.module.js';
  8. import { UIRow, UIText, UIInteger, UISelect, UICheckbox, UINumber } from './libs/ui.js';
  9. import { UIPoints3 } from './libs/ui.three.js';
  10. import { SetGeometryCommand } from './commands/SetGeometryCommand.js';
  11. var SidebarGeometryTubeGeometry = function ( editor, object ) {
  12. var strings = editor.strings;
  13. var container = new UIRow();
  14. var geometry = object.geometry;
  15. var parameters = geometry.parameters;
  16. // points
  17. var pointsRow = new UIRow();
  18. pointsRow.add( new UIText( strings.getKey( 'sidebar/geometry/tube_geometry/path' ) ).setWidth( '90px' ) );
  19. var points = new UIPoints3().setValue( parameters.path.points ).onChange( update );
  20. pointsRow.add( points );
  21. container.add( pointsRow );
  22. // radius
  23. var radiusRow = new UIRow();
  24. var radius = new UINumber( parameters.radius ).onChange( update );
  25. radiusRow.add( new UIText( strings.getKey( 'sidebar/geometry/tube_geometry/radius' ) ).setWidth( '90px' ) );
  26. radiusRow.add( radius );
  27. container.add( radiusRow );
  28. // tubularSegments
  29. var tubularSegmentsRow = new UIRow();
  30. var tubularSegments = new UIInteger( parameters.tubularSegments ).onChange( update );
  31. tubularSegmentsRow.add( new UIText( strings.getKey( 'sidebar/geometry/tube_geometry/tubularsegments' ) ).setWidth( '90px' ) );
  32. tubularSegmentsRow.add( tubularSegments );
  33. container.add( tubularSegmentsRow );
  34. // radialSegments
  35. var radialSegmentsRow = new UIRow();
  36. var radialSegments = new UIInteger( parameters.radialSegments ).onChange( update );
  37. radialSegmentsRow.add( new UIText( strings.getKey( 'sidebar/geometry/tube_geometry/radialsegments' ) ).setWidth( '90px' ) );
  38. radialSegmentsRow.add( radialSegments );
  39. container.add( radialSegmentsRow );
  40. // closed
  41. var closedRow = new UIRow();
  42. var closed = new UICheckbox( parameters.closed ).onChange( update );
  43. closedRow.add( new UIText( strings.getKey( 'sidebar/geometry/tube_geometry/closed' ) ).setWidth( '90px' ) );
  44. closedRow.add( closed );
  45. container.add( closedRow );
  46. // curveType
  47. var curveTypeRow = new UIRow();
  48. var curveType = new UISelect().setOptions( { centripetal: 'centripetal', chordal: 'chordal', catmullrom: 'catmullrom' } ).setValue( parameters.path.curveType ).onChange( update );
  49. curveTypeRow.add( new UIText( strings.getKey( 'sidebar/geometry/tube_geometry/curvetype' ) ).setWidth( '90px' ), curveType );
  50. container.add( curveTypeRow );
  51. // tension
  52. var tensionRow = new UIRow().setDisplay( curveType.getValue() == 'catmullrom' ? '' : 'none' );
  53. var tension = new UINumber( parameters.path.tension ).setStep( 0.01 ).onChange( update );
  54. tensionRow.add( new UIText( strings.getKey( 'sidebar/geometry/tube_geometry/tension' ) ).setWidth( '90px' ), tension );
  55. container.add( tensionRow );
  56. //
  57. function update() {
  58. tensionRow.setDisplay( curveType.getValue() == 'catmullrom' ? '' : 'none' );
  59. editor.execute( new SetGeometryCommand( editor, object, new TubeBufferGeometry(
  60. new CatmullRomCurve3( points.getValue(), closed.getValue(), curveType.getValue(), tension.getValue() ),
  61. tubularSegments.getValue(),
  62. radius.getValue(),
  63. radialSegments.getValue(),
  64. closed.getValue()
  65. ) ) );
  66. }
  67. return container;
  68. };
  69. export { SidebarGeometryTubeGeometry };