Sidebar.Geometry.CapsuleGeometry.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. // radius
  11. const radiusRow = new UIRow();
  12. const radius = new UINumber( parameters.radius ).onChange( update );
  13. radiusRow.add( new UIText( strings.getKey( 'sidebar/geometry/capsule_geometry/radius' ) ).setClass( 'Label' ) );
  14. radiusRow.add( radius );
  15. container.add( radiusRow );
  16. // length
  17. const lengthRow = new UIRow();
  18. const length = new UINumber( parameters.length ).onChange( update );
  19. lengthRow.add( new UIText( strings.getKey( 'sidebar/geometry/capsule_geometry/length' ) ).setClass( 'Label' ) );
  20. lengthRow.add( length );
  21. container.add( lengthRow );
  22. // capSegments
  23. const capSegmentsRow = new UIRow();
  24. const capSegments = new UIInteger( parameters.capSegments ).setRange( 1, Infinity ).onChange( update );
  25. capSegmentsRow.add( new UIText( strings.getKey( 'sidebar/geometry/capsule_geometry/capseg' ) ).setClass( 'Label' ) );
  26. capSegmentsRow.add( capSegments );
  27. container.add( capSegmentsRow );
  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/capsule_geometry/radialseg' ) ).setClass( 'Label' ) );
  32. radialSegmentsRow.add( radialSegments );
  33. container.add( radialSegmentsRow );
  34. //
  35. function refreshUI() {
  36. const parameters = object.geometry.parameters;
  37. radius.setValue( parameters.radius );
  38. length.setValue( parameters.length );
  39. capSegments.setValue( parameters.capSegments );
  40. radialSegments.setValue( parameters.radialSegments );
  41. }
  42. signals.geometryChanged.add( refreshUI );
  43. //
  44. function update() {
  45. editor.execute( new SetGeometryCommand( editor, object, new THREE.CapsuleGeometry(
  46. radius.getValue(),
  47. length.getValue(),
  48. capSegments.getValue(),
  49. radialSegments.getValue()
  50. ) ) );
  51. }
  52. return container;
  53. }
  54. export { GeometryParametersPanel };