Sidebar.Geometry.SphereGeometry.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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/sphere_geometry/radius' ) ).setClass( 'Label' ) );
  14. radiusRow.add( radius );
  15. container.add( radiusRow );
  16. // widthSegments
  17. const widthSegmentsRow = new UIRow();
  18. const widthSegments = new UIInteger( parameters.widthSegments ).setRange( 1, Infinity ).onChange( update );
  19. widthSegmentsRow.add( new UIText( strings.getKey( 'sidebar/geometry/sphere_geometry/widthsegments' ) ).setClass( 'Label' ) );
  20. widthSegmentsRow.add( widthSegments );
  21. container.add( widthSegmentsRow );
  22. // heightSegments
  23. const heightSegmentsRow = new UIRow();
  24. const heightSegments = new UIInteger( parameters.heightSegments ).setRange( 1, Infinity ).onChange( update );
  25. heightSegmentsRow.add( new UIText( strings.getKey( 'sidebar/geometry/sphere_geometry/heightsegments' ) ).setClass( 'Label' ) );
  26. heightSegmentsRow.add( heightSegments );
  27. container.add( heightSegmentsRow );
  28. // phiStart
  29. const phiStartRow = new UIRow();
  30. const phiStart = new UINumber( parameters.phiStart * THREE.MathUtils.RAD2DEG ).setUnit( '°' ).setStep( 10 ).onChange( update );
  31. phiStartRow.add( new UIText( strings.getKey( 'sidebar/geometry/sphere_geometry/phistart' ) ).setClass( 'Label' ) );
  32. phiStartRow.add( phiStart );
  33. container.add( phiStartRow );
  34. // phiLength
  35. const phiLengthRow = new UIRow();
  36. const phiLength = new UINumber( parameters.phiLength * THREE.MathUtils.RAD2DEG ).setUnit( '°' ).setStep( 10 ).onChange( update );
  37. phiLengthRow.add( new UIText( strings.getKey( 'sidebar/geometry/sphere_geometry/philength' ) ).setClass( 'Label' ) );
  38. phiLengthRow.add( phiLength );
  39. container.add( phiLengthRow );
  40. // thetaStart
  41. const thetaStartRow = new UIRow();
  42. const thetaStart = new UINumber( parameters.thetaStart * THREE.MathUtils.RAD2DEG ).setUnit( '°' ).setStep( 10 ).onChange( update );
  43. thetaStartRow.add( new UIText( strings.getKey( 'sidebar/geometry/sphere_geometry/thetastart' ) ).setClass( 'Label' ) );
  44. thetaStartRow.add( thetaStart );
  45. container.add( thetaStartRow );
  46. // thetaLength
  47. const thetaLengthRow = new UIRow();
  48. const thetaLength = new UINumber( parameters.thetaLength * THREE.MathUtils.RAD2DEG ).setUnit( '°' ).setStep( 10 ).onChange( update );
  49. thetaLengthRow.add( new UIText( strings.getKey( 'sidebar/geometry/sphere_geometry/thetalength' ) ).setClass( 'Label' ) );
  50. thetaLengthRow.add( thetaLength );
  51. container.add( thetaLengthRow );
  52. //
  53. function refreshUI() {
  54. const parameters = object.geometry.parameters;
  55. radius.setValue( parameters.radius );
  56. widthSegments.setValue( parameters.widthSegments );
  57. heightSegments.setValue( parameters.heightSegments );
  58. phiStart.setValue( parameters.phiStart * THREE.MathUtils.RAD2DEG );
  59. phiLength.setValue( parameters.phiLength * THREE.MathUtils.RAD2DEG );
  60. thetaStart.setValue( parameters.thetaStart * THREE.MathUtils.RAD2DEG );
  61. thetaLength.setValue( parameters.thetaLength * THREE.MathUtils.RAD2DEG );
  62. }
  63. signals.geometryChanged.add( function ( mesh ) {
  64. if ( mesh === object ) {
  65. refreshUI();
  66. }
  67. } );
  68. //
  69. function update() {
  70. editor.execute( new SetGeometryCommand( editor, object, new THREE.SphereGeometry(
  71. radius.getValue(),
  72. widthSegments.getValue(),
  73. heightSegments.getValue(),
  74. phiStart.getValue() * THREE.MathUtils.DEG2RAD,
  75. phiLength.getValue() * THREE.MathUtils.DEG2RAD,
  76. thetaStart.getValue() * THREE.MathUtils.DEG2RAD,
  77. thetaLength.getValue() * THREE.MathUtils.DEG2RAD
  78. ) ) );
  79. }
  80. return container;
  81. }
  82. export { GeometryParametersPanel };