Sidebar.Geometry.TubeGeometry.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import * as THREE from 'three';
  2. import { UIDiv, 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. const strings = editor.strings;
  7. const container = new UIDiv();
  8. const geometry = object.geometry;
  9. const parameters = geometry.parameters;
  10. // points
  11. const pointsRow = new UIRow();
  12. pointsRow.add( new UIText( strings.getKey( 'sidebar/geometry/tube_geometry/path' ) ).setWidth( '90px' ) );
  13. const points = new UIPoints3().setValue( parameters.path.points ).onChange( update );
  14. pointsRow.add( points );
  15. container.add( pointsRow );
  16. // radius
  17. const radiusRow = new UIRow();
  18. const 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. const tubularSegmentsRow = new UIRow();
  24. const 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. const radialSegmentsRow = new UIRow();
  30. const 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. const closedRow = new UIRow();
  36. const 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. const curveTypeRow = new UIRow();
  42. const 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. const tensionRow = new UIRow().setDisplay( curveType.getValue() == 'catmullrom' ? '' : 'none' );
  47. const 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 };