Sidebar.Geometry.TubeGeometry.js 3.2 KB

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