Sidebar.Geometry.TubeGeometry.js 3.2 KB

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