Sidebar.Geometry.PlaneGeometry.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import * as THREE from 'three';
  2. import { UIDiv, UIRow, UIText, UIInteger, 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. // width
  11. const widthRow = new UIRow();
  12. const width = new UINumber( parameters.width ).onChange( update );
  13. widthRow.add( new UIText( strings.getKey( 'sidebar/geometry/plane_geometry/width' ) ).setClass( 'Label' ) );
  14. widthRow.add( width );
  15. container.add( widthRow );
  16. // height
  17. const heightRow = new UIRow();
  18. const height = new UINumber( parameters.height ).onChange( update );
  19. heightRow.add( new UIText( strings.getKey( 'sidebar/geometry/plane_geometry/height' ) ).setClass( 'Label' ) );
  20. heightRow.add( height );
  21. container.add( heightRow );
  22. // widthSegments
  23. const widthSegmentsRow = new UIRow();
  24. const widthSegments = new UIInteger( parameters.widthSegments ).setRange( 1, Infinity ).onChange( update );
  25. widthSegmentsRow.add( new UIText( strings.getKey( 'sidebar/geometry/plane_geometry/widthsegments' ) ).setClass( 'Label' ) );
  26. widthSegmentsRow.add( widthSegments );
  27. container.add( widthSegmentsRow );
  28. // heightSegments
  29. const heightSegmentsRow = new UIRow();
  30. const heightSegments = new UIInteger( parameters.heightSegments ).setRange( 1, Infinity ).onChange( update );
  31. heightSegmentsRow.add( new UIText( strings.getKey( 'sidebar/geometry/plane_geometry/heightsegments' ) ).setClass( 'Label' ) );
  32. heightSegmentsRow.add( heightSegments );
  33. container.add( heightSegmentsRow );
  34. //
  35. function refreshUI() {
  36. const parameters = object.geometry.parameters;
  37. width.setValue( parameters.width );
  38. height.setValue( parameters.height );
  39. widthSegments.setValue( parameters.widthSegments );
  40. heightSegments.setValue( parameters.heightSegments );
  41. }
  42. signals.geometryChanged.add( function ( mesh ) {
  43. if ( mesh === object ) {
  44. refreshUI();
  45. }
  46. } );
  47. //
  48. function update() {
  49. editor.execute( new SetGeometryCommand( editor, object, new THREE.PlaneGeometry(
  50. width.getValue(),
  51. height.getValue(),
  52. widthSegments.getValue(),
  53. heightSegments.getValue()
  54. ) ) );
  55. }
  56. return container;
  57. }
  58. export { GeometryParametersPanel };