1
0

Sidebar.Geometry.CircleGeometry.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import * as THREE from 'three';
  2. import { UIDiv, UIRow, UIText, UIInteger, UINumber } 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/circle_geometry/radius' ) ).setClass( 'Label' ) );
  14. radiusRow.add( radius );
  15. container.add( radiusRow );
  16. // segments
  17. const segmentsRow = new UIRow();
  18. const segments = new UIInteger( parameters.segments ).setRange( 3, Infinity ).onChange( update );
  19. segmentsRow.add( new UIText( strings.getKey( 'sidebar/geometry/circle_geometry/segments' ) ).setClass( 'Label' ) );
  20. segmentsRow.add( segments );
  21. container.add( segmentsRow );
  22. // thetaStart
  23. const thetaStartRow = new UIRow();
  24. const thetaStart = new UINumber( parameters.thetaStart * THREE.MathUtils.RAD2DEG ).setUnit( '°' ).setStep( 10 ).onChange( update );
  25. thetaStartRow.add( new UIText( strings.getKey( 'sidebar/geometry/circle_geometry/thetastart' ) ).setClass( 'Label' ) );
  26. thetaStartRow.add( thetaStart );
  27. container.add( thetaStartRow );
  28. // thetaLength
  29. const thetaLengthRow = new UIRow();
  30. const thetaLength = new UINumber( parameters.thetaLength * THREE.MathUtils.RAD2DEG ).setUnit( '°' ).setStep( 10 ).onChange( update );
  31. thetaLengthRow.add( new UIText( strings.getKey( 'sidebar/geometry/circle_geometry/thetalength' ) ).setClass( 'Label' ) );
  32. thetaLengthRow.add( thetaLength );
  33. container.add( thetaLengthRow );
  34. //
  35. function refreshUI() {
  36. const parameters = object.geometry.parameters;
  37. radius.setValue( parameters.radius );
  38. segments.setValue( parameters.segments );
  39. thetaStart.setValue( parameters.thetaStart * THREE.MathUtils.RAD2DEG );
  40. thetaLength.setValue( parameters.thetaLength * 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.CircleGeometry(
  50. radius.getValue(),
  51. segments.getValue(),
  52. thetaStart.getValue() * THREE.MathUtils.DEG2RAD,
  53. thetaLength.getValue() * THREE.MathUtils.DEG2RAD
  54. ) ) );
  55. }
  56. return container;
  57. }
  58. export { GeometryParametersPanel };