Sidebar.Geometry.LatheGeometry.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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( function ( mesh ) {
  43. if ( mesh === object ) {
  44. refreshUI();
  45. }
  46. } );
  47. //
  48. function update() {
  49. editor.execute( new SetGeometryCommand( editor, object, new THREE.LatheGeometry(
  50. points.getValue(),
  51. segments.getValue(),
  52. phiStart.getValue() * THREE.MathUtils.DEG2RAD,
  53. phiLength.getValue() * THREE.MathUtils.DEG2RAD
  54. ) ) );
  55. }
  56. return container;
  57. }
  58. export { GeometryParametersPanel };
粤ICP备19079148号