Sidebar.Geometry.RingGeometry.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. // innerRadius
  11. const innerRadiusRow = new UIRow();
  12. const innerRadius = new UINumber( parameters.innerRadius ).onChange( update );
  13. innerRadiusRow.add( new UIText( strings.getKey( 'sidebar/geometry/ring_geometry/innerRadius' ) ).setClass( 'Label' ) );
  14. innerRadiusRow.add( innerRadius );
  15. container.add( innerRadiusRow );
  16. // outerRadius
  17. const outerRadiusRow = new UIRow();
  18. const outerRadius = new UINumber( parameters.outerRadius ).onChange( update );
  19. outerRadiusRow.add( new UIText( strings.getKey( 'sidebar/geometry/ring_geometry/outerRadius' ) ).setClass( 'Label' ) );
  20. outerRadiusRow.add( outerRadius );
  21. container.add( outerRadiusRow );
  22. // thetaSegments
  23. const thetaSegmentsRow = new UIRow();
  24. const thetaSegments = new UIInteger( parameters.thetaSegments ).setRange( 3, Infinity ).onChange( update );
  25. thetaSegmentsRow.add( new UIText( strings.getKey( 'sidebar/geometry/ring_geometry/thetaSegments' ) ).setClass( 'Label' ) );
  26. thetaSegmentsRow.add( thetaSegments );
  27. container.add( thetaSegmentsRow );
  28. // phiSegments
  29. const phiSegmentsRow = new UIRow();
  30. const phiSegments = new UIInteger( parameters.phiSegments ).setRange( 3, Infinity ).onChange( update );
  31. phiSegmentsRow.add( new UIText( strings.getKey( 'sidebar/geometry/ring_geometry/phiSegments' ) ).setClass( 'Label' ) );
  32. phiSegmentsRow.add( phiSegments );
  33. container.add( phiSegmentsRow );
  34. // thetaStart
  35. const thetaStartRow = new UIRow();
  36. const thetaStart = new UINumber( parameters.thetaStart * THREE.MathUtils.RAD2DEG ).setUnit( '°' ).setStep( 10 ).onChange( update );
  37. thetaStartRow.add( new UIText( strings.getKey( 'sidebar/geometry/ring_geometry/thetastart' ) ).setClass( 'Label' ) );
  38. thetaStartRow.add( thetaStart );
  39. container.add( thetaStartRow );
  40. // thetaLength
  41. const thetaLengthRow = new UIRow();
  42. const thetaLength = new UINumber( parameters.thetaLength * THREE.MathUtils.RAD2DEG ).setUnit( '°' ).setStep( 10 ).onChange( update );
  43. thetaLengthRow.add( new UIText( strings.getKey( 'sidebar/geometry/ring_geometry/thetalength' ) ).setClass( 'Label' ) );
  44. thetaLengthRow.add( thetaLength );
  45. container.add( thetaLengthRow );
  46. //
  47. function refreshUI() {
  48. const parameters = object.geometry.parameters;
  49. innerRadius.setValue( parameters.innerRadius );
  50. outerRadius.setValue( parameters.outerRadius );
  51. thetaSegments.setValue( parameters.thetaSegments );
  52. phiSegments.setValue( parameters.phiSegments );
  53. thetaStart.setValue( parameters.thetaStart * THREE.MathUtils.RAD2DEG );
  54. thetaLength.setValue( parameters.thetaLength * THREE.MathUtils.RAD2DEG );
  55. }
  56. signals.geometryChanged.add( function ( mesh ) {
  57. if ( mesh === object ) {
  58. refreshUI();
  59. }
  60. } );
  61. //
  62. function update() {
  63. editor.execute( new SetGeometryCommand( editor, object, new THREE.RingGeometry(
  64. innerRadius.getValue(),
  65. outerRadius.getValue(),
  66. thetaSegments.getValue(),
  67. phiSegments.getValue(),
  68. thetaStart.getValue() * THREE.MathUtils.DEG2RAD,
  69. thetaLength.getValue() * THREE.MathUtils.DEG2RAD
  70. ) ) );
  71. }
  72. return container;
  73. }
  74. export { GeometryParametersPanel };