Sidebar.Geometry.CylinderGeometry.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import * as THREE from 'three';
  2. import { UIDiv, UIRow, UIText, UIInteger, UICheckbox, UINumber } from './libs/ui.js';
  3. import { SetGeometryCommand } from './commands/SetGeometryCommand.js';
  4. function GeometryParametersPanel( editor, object ) {
  5. const strings = editor.strings;
  6. const signals = editor.signals;
  7. const container = new UIDiv();
  8. const geometry = object.geometry;
  9. const parameters = geometry.parameters;
  10. // radiusTop
  11. const radiusTopRow = new UIRow();
  12. const radiusTop = new UINumber( parameters.radiusTop ).onChange( update );
  13. radiusTopRow.add( new UIText( strings.getKey( 'sidebar/geometry/cylinder_geometry/radiustop' ) ).setClass( 'Label' ) );
  14. radiusTopRow.add( radiusTop );
  15. container.add( radiusTopRow );
  16. // radiusBottom
  17. const radiusBottomRow = new UIRow();
  18. const radiusBottom = new UINumber( parameters.radiusBottom ).onChange( update );
  19. radiusBottomRow.add( new UIText( strings.getKey( 'sidebar/geometry/cylinder_geometry/radiusbottom' ) ).setClass( 'Label' ) );
  20. radiusBottomRow.add( radiusBottom );
  21. container.add( radiusBottomRow );
  22. // height
  23. const heightRow = new UIRow();
  24. const height = new UINumber( parameters.height ).onChange( update );
  25. heightRow.add( new UIText( strings.getKey( 'sidebar/geometry/cylinder_geometry/height' ) ).setClass( 'Label' ) );
  26. heightRow.add( height );
  27. container.add( heightRow );
  28. // radialSegments
  29. const radialSegmentsRow = new UIRow();
  30. const radialSegments = new UIInteger( parameters.radialSegments ).setRange( 1, Infinity ).onChange( update );
  31. radialSegmentsRow.add( new UIText( strings.getKey( 'sidebar/geometry/cylinder_geometry/radialsegments' ) ).setClass( 'Label' ) );
  32. radialSegmentsRow.add( radialSegments );
  33. container.add( radialSegmentsRow );
  34. // heightSegments
  35. const heightSegmentsRow = new UIRow();
  36. const heightSegments = new UIInteger( parameters.heightSegments ).setRange( 1, Infinity ).onChange( update );
  37. heightSegmentsRow.add( new UIText( strings.getKey( 'sidebar/geometry/cylinder_geometry/heightsegments' ) ).setClass( 'Label' ) );
  38. heightSegmentsRow.add( heightSegments );
  39. container.add( heightSegmentsRow );
  40. // openEnded
  41. const openEndedRow = new UIRow();
  42. const openEnded = new UICheckbox( parameters.openEnded ).onChange( update );
  43. openEndedRow.add( new UIText( strings.getKey( 'sidebar/geometry/cylinder_geometry/openended' ) ).setClass( 'Label' ) );
  44. openEndedRow.add( openEnded );
  45. container.add( openEndedRow );
  46. //
  47. function refreshUI() {
  48. const parameters = object.geometry.parameters;
  49. radiusTop.setValue( parameters.radiusTop );
  50. radiusBottom.setValue( parameters.radiusBottom );
  51. height.setValue( parameters.height );
  52. radialSegments.setValue( parameters.radialSegments );
  53. heightSegments.setValue( parameters.heightSegments );
  54. openEnded.setValue( parameters.openEnded );
  55. }
  56. signals.geometryChanged.add( refreshUI );
  57. //
  58. function update() {
  59. editor.execute( new SetGeometryCommand( editor, object, new THREE.CylinderGeometry(
  60. radiusTop.getValue(),
  61. radiusBottom.getValue(),
  62. height.getValue(),
  63. radialSegments.getValue(),
  64. heightSegments.getValue(),
  65. openEnded.getValue()
  66. ) ) );
  67. }
  68. return container;
  69. }
  70. export { GeometryParametersPanel };