Sidebar.Geometry.CapsuleGeometry.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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( function ( mesh ) {
  43. if ( mesh === object ) {
  44. refreshUI();
  45. }
  46. } );
  47. //
  48. function update() {
  49. editor.execute( new SetGeometryCommand( editor, object, new THREE.CapsuleGeometry(
  50. radius.getValue(),
  51. length.getValue(),
  52. capSegments.getValue(),
  53. radialSegments.getValue()
  54. ) ) );
  55. }
  56. return container;
  57. }
  58. export { GeometryParametersPanel };