Sidebar.Geometry.TorusKnotGeometry.js 2.9 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. // radius
  11. const radiusRow = new UIRow();
  12. const radius = new UINumber( parameters.radius ).onChange( update );
  13. radiusRow.add( new UIText( strings.getKey( 'sidebar/geometry/torusKnot_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/torusKnot_geometry/tube' ) ).setClass( 'Label' ) );
  20. tubeRow.add( tube );
  21. container.add( tubeRow );
  22. // tubularSegments
  23. const tubularSegmentsRow = new UIRow();
  24. const tubularSegments = new UIInteger( parameters.tubularSegments ).setRange( 1, Infinity ).onChange( update );
  25. tubularSegmentsRow.add( new UIText( strings.getKey( 'sidebar/geometry/torusKnot_geometry/tubularsegments' ) ).setClass( 'Label' ) );
  26. tubularSegmentsRow.add( tubularSegments );
  27. container.add( tubularSegmentsRow );
  28. // radialSegments
  29. const radialSegmentsRow = new UIRow();
  30. const radialSegments = new UIInteger( parameters.radialSegments ).setRange( 1, Infinity ).onChange( update );
  31. radialSegmentsRow.add( new UIText( strings.getKey( 'sidebar/geometry/torusKnot_geometry/radialsegments' ) ).setClass( 'Label' ) );
  32. radialSegmentsRow.add( radialSegments );
  33. container.add( radialSegmentsRow );
  34. // p
  35. const pRow = new UIRow();
  36. const p = new UIInteger( parameters.p ).onChange( update );
  37. pRow.add( new UIText( strings.getKey( 'sidebar/geometry/torusKnot_geometry/p' ) ).setClass( 'Label' ) );
  38. pRow.add( p );
  39. container.add( pRow );
  40. // q
  41. const qRow = new UIRow();
  42. const q = new UIInteger( parameters.q ).onChange( update );
  43. qRow.add( new UIText( strings.getKey( 'sidebar/geometry/torusKnot_geometry/q' ) ).setClass( 'Label' ) );
  44. qRow.add( q );
  45. container.add( qRow );
  46. //
  47. function refreshUI() {
  48. const parameters = object.geometry.parameters;
  49. radius.setValue( parameters.radius );
  50. tube.setValue( parameters.tube );
  51. tubularSegments.setValue( parameters.tubularSegments );
  52. radialSegments.setValue( parameters.radialSegments );
  53. p.setValue( parameters.p );
  54. q.setValue( parameters.q );
  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.TorusKnotGeometry(
  64. radius.getValue(),
  65. tube.getValue(),
  66. tubularSegments.getValue(),
  67. radialSegments.getValue(),
  68. p.getValue(),
  69. q.getValue()
  70. ) ) );
  71. }
  72. return container;
  73. }
  74. export { GeometryParametersPanel };