Sidebar.Geometry.LatheGeometry.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import * as THREE from 'three';
  2. import { UIDiv, UIRow, UIText, UIInteger, UINumber } from './libs/ui.js';
  3. import { UIPoints2 } from './libs/ui.three.js';
  4. import { SetGeometryCommand } from './commands/SetGeometryCommand.js';
  5. function GeometryParametersPanel( editor, object ) {
  6. const strings = editor.strings;
  7. const signals = editor.signals;
  8. const container = new UIDiv();
  9. const geometry = object.geometry;
  10. const parameters = geometry.parameters;
  11. // segments
  12. const segmentsRow = new UIRow();
  13. const segments = new UIInteger( parameters.segments ).onChange( update );
  14. segmentsRow.add( new UIText( strings.getKey( 'sidebar/geometry/lathe_geometry/segments' ) ).setClass( 'Label' ) );
  15. segmentsRow.add( segments );
  16. container.add( segmentsRow );
  17. // phiStart
  18. const phiStartRow = new UIRow();
  19. const phiStart = new UINumber( parameters.phiStart * THREE.MathUtils.RAD2DEG ).onChange( update );
  20. phiStartRow.add( new UIText( strings.getKey( 'sidebar/geometry/lathe_geometry/phistart' ) ).setClass( 'Label' ) );
  21. phiStartRow.add( phiStart );
  22. container.add( phiStartRow );
  23. // phiLength
  24. const phiLengthRow = new UIRow();
  25. const phiLength = new UINumber( parameters.phiLength * THREE.MathUtils.RAD2DEG ).onChange( update );
  26. phiLengthRow.add( new UIText( strings.getKey( 'sidebar/geometry/lathe_geometry/philength' ) ).setClass( 'Label' ) );
  27. phiLengthRow.add( phiLength );
  28. container.add( phiLengthRow );
  29. // points
  30. const pointsRow = new UIRow();
  31. pointsRow.add( new UIText( strings.getKey( 'sidebar/geometry/lathe_geometry/points' ) ).setClass( 'Label' ) );
  32. const points = new UIPoints2().setValue( parameters.points ).onChange( update );
  33. pointsRow.add( points );
  34. container.add( pointsRow );
  35. //
  36. function refreshUI() {
  37. const parameters = object.geometry.parameters;
  38. segments.setValue( parameters.segments );
  39. phiStart.setValue( parameters.phiStart * THREE.MathUtils.RAD2DEG );
  40. phiLength.setValue( parameters.phiLength * THREE.MathUtils.RAD2DEG );
  41. }
  42. signals.geometryChanged.add( refreshUI );
  43. function update() {
  44. editor.execute( new SetGeometryCommand( editor, object, new THREE.LatheGeometry(
  45. points.getValue(),
  46. segments.getValue(),
  47. phiStart.getValue() * THREE.MathUtils.DEG2RAD,
  48. phiLength.getValue() * THREE.MathUtils.DEG2RAD
  49. ) ) );
  50. }
  51. return container;
  52. }
  53. export { GeometryParametersPanel };