Sidebar.Geometry.BoxGeometry.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import * as THREE from 'three';
  2. import { UIDiv, UIRow, UIText, UINumber, UIInteger } 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. // width
  11. const widthRow = new UIRow();
  12. const width = new UINumber().setPrecision( 3 ).setValue( parameters.width ).onChange( update );
  13. widthRow.add( new UIText( strings.getKey( 'sidebar/geometry/box_geometry/width' ) ).setClass( 'Label' ) );
  14. widthRow.add( width );
  15. container.add( widthRow );
  16. // height
  17. const heightRow = new UIRow();
  18. const height = new UINumber().setPrecision( 3 ).setValue( parameters.height ).onChange( update );
  19. heightRow.add( new UIText( strings.getKey( 'sidebar/geometry/box_geometry/height' ) ).setClass( 'Label' ) );
  20. heightRow.add( height );
  21. container.add( heightRow );
  22. // depth
  23. const depthRow = new UIRow();
  24. const depth = new UINumber().setPrecision( 3 ).setValue( parameters.depth ).onChange( update );
  25. depthRow.add( new UIText( strings.getKey( 'sidebar/geometry/box_geometry/depth' ) ).setClass( 'Label' ) );
  26. depthRow.add( depth );
  27. container.add( depthRow );
  28. // widthSegments
  29. const widthSegmentsRow = new UIRow();
  30. const widthSegments = new UIInteger( parameters.widthSegments ).setRange( 1, Infinity ).onChange( update );
  31. widthSegmentsRow.add( new UIText( strings.getKey( 'sidebar/geometry/box_geometry/widthseg' ) ).setClass( 'Label' ) );
  32. widthSegmentsRow.add( widthSegments );
  33. container.add( widthSegmentsRow );
  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/box_geometry/heightseg' ) ).setClass( 'Label' ) );
  38. heightSegmentsRow.add( heightSegments );
  39. container.add( heightSegmentsRow );
  40. // depthSegments
  41. const depthSegmentsRow = new UIRow();
  42. const depthSegments = new UIInteger( parameters.depthSegments ).setRange( 1, Infinity ).onChange( update );
  43. depthSegmentsRow.add( new UIText( strings.getKey( 'sidebar/geometry/box_geometry/depthseg' ) ).setClass( 'Label' ) );
  44. depthSegmentsRow.add( depthSegments );
  45. container.add( depthSegmentsRow );
  46. //
  47. function refreshUI() {
  48. const parameters = object.geometry.parameters;
  49. width.setValue( parameters.width );
  50. height.setValue( parameters.height );
  51. depth.setValue( parameters.depth );
  52. widthSegments.setValue( parameters.widthSegments );
  53. heightSegments.setValue( parameters.heightSegments );
  54. depthSegments.setValue( parameters.depthSegments );
  55. }
  56. signals.geometryChanged.add( function ( mesh ) {
  57. if ( mesh === object ) {
  58. refreshUI();
  59. }
  60. } );
  61. //
  62. function update() {
  63. editor.execute( new SetGeometryCommand( editor, object, new THREE.BoxGeometry(
  64. width.getValue(),
  65. height.getValue(),
  66. depth.getValue(),
  67. widthSegments.getValue(),
  68. heightSegments.getValue(),
  69. depthSegments.getValue()
  70. ) ) );
  71. }
  72. return container;
  73. }
  74. export { GeometryParametersPanel };