Sidebar.Geometry.LatheGeometry.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. points.setValue( parameters.points, false );
  39. segments.setValue( parameters.segments );
  40. phiStart.setValue( parameters.phiStart * THREE.MathUtils.RAD2DEG );
  41. phiLength.setValue( parameters.phiLength * THREE.MathUtils.RAD2DEG );
  42. }
  43. signals.geometryChanged.add( function ( mesh ) {
  44. if ( mesh === object ) {
  45. refreshUI();
  46. }
  47. } );
  48. //
  49. function update() {
  50. editor.execute( new SetGeometryCommand( editor, object, new THREE.LatheGeometry(
  51. points.getValue(),
  52. segments.getValue(),
  53. phiStart.getValue() * THREE.MathUtils.DEG2RAD,
  54. phiLength.getValue() * THREE.MathUtils.DEG2RAD
  55. ) ) );
  56. }
  57. return container;
  58. }
  59. export { GeometryParametersPanel };