Sidebar.Geometry.TorusGeometry.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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/torus_geometry/radius' ) ).setClass( 'Label' ) );
  14. radiusRow.add( radius );
  15. container.add( radiusRow );
  16. // tube
  17. const tubeRow = new UIRow();
  18. const tube = new UINumber( parameters.tube ).onChange( update );
  19. tubeRow.add( new UIText( strings.getKey( 'sidebar/geometry/torus_geometry/tube' ) ).setClass( 'Label' ) );
  20. tubeRow.add( tube );
  21. container.add( tubeRow );
  22. // radialSegments
  23. const radialSegmentsRow = new UIRow();
  24. const radialSegments = new UIInteger( parameters.radialSegments ).setRange( 1, Infinity ).onChange( update );
  25. radialSegmentsRow.add( new UIText( strings.getKey( 'sidebar/geometry/torus_geometry/radialsegments' ) ).setClass( 'Label' ) );
  26. radialSegmentsRow.add( radialSegments );
  27. container.add( radialSegmentsRow );
  28. // tubularSegments
  29. const tubularSegmentsRow = new UIRow();
  30. const tubularSegments = new UIInteger( parameters.tubularSegments ).setRange( 1, Infinity ).onChange( update );
  31. tubularSegmentsRow.add( new UIText( strings.getKey( 'sidebar/geometry/torus_geometry/tubularsegments' ) ).setClass( 'Label' ) );
  32. tubularSegmentsRow.add( tubularSegments );
  33. container.add( tubularSegmentsRow );
  34. // arc
  35. const arcRow = new UIRow();
  36. const arc = new UINumber( parameters.arc * THREE.MathUtils.RAD2DEG ).setUnit( '°' ).setStep( 10 ).onChange( update );
  37. arcRow.add( new UIText( strings.getKey( 'sidebar/geometry/torus_geometry/arc' ) ).setClass( 'Label' ) );
  38. arcRow.add( arc );
  39. container.add( arcRow );
  40. //
  41. function refreshUI() {
  42. const parameters = object.geometry.parameters;
  43. radius.setValue( parameters.radius );
  44. tube.setValue( parameters.tube );
  45. radialSegments.setValue( parameters.radialSegments );
  46. tubularSegments.setValue( parameters.tubularSegments );
  47. arc.setValue( parameters.arc * THREE.MathUtils.RAD2DEG );
  48. }
  49. signals.geometryChanged.add( function ( mesh ) {
  50. if ( mesh === object ) {
  51. refreshUI();
  52. }
  53. } );
  54. //
  55. function update() {
  56. editor.execute( new SetGeometryCommand( editor, object, new THREE.TorusGeometry(
  57. radius.getValue(),
  58. tube.getValue(),
  59. radialSegments.getValue(),
  60. tubularSegments.getValue(),
  61. arc.getValue() * THREE.MathUtils.DEG2RAD
  62. ) ) );
  63. }
  64. return container;
  65. }
  66. export { GeometryParametersPanel };