2
0

Sidebar.Geometry.TorusKnotGeometry.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 container = new UIDiv();
  7. const geometry = object.geometry;
  8. const parameters = geometry.parameters;
  9. // radius
  10. const radiusRow = new UIRow();
  11. const radius = new UINumber( parameters.radius ).onChange( update );
  12. radiusRow.add( new UIText( strings.getKey( 'sidebar/geometry/torusKnot_geometry/radius' ) ).setWidth( '90px' ) );
  13. radiusRow.add( radius );
  14. container.add( radiusRow );
  15. // tube
  16. const tubeRow = new UIRow();
  17. const tube = new UINumber( parameters.tube ).onChange( update );
  18. tubeRow.add( new UIText( strings.getKey( 'sidebar/geometry/torusKnot_geometry/tube' ) ).setWidth( '90px' ) );
  19. tubeRow.add( tube );
  20. container.add( tubeRow );
  21. // tubularSegments
  22. const tubularSegmentsRow = new UIRow();
  23. const tubularSegments = new UIInteger( parameters.tubularSegments ).setRange( 1, Infinity ).onChange( update );
  24. tubularSegmentsRow.add( new UIText( strings.getKey( 'sidebar/geometry/torusKnot_geometry/tubularsegments' ) ).setWidth( '90px' ) );
  25. tubularSegmentsRow.add( tubularSegments );
  26. container.add( tubularSegmentsRow );
  27. // radialSegments
  28. const radialSegmentsRow = new UIRow();
  29. const radialSegments = new UIInteger( parameters.radialSegments ).setRange( 1, Infinity ).onChange( update );
  30. radialSegmentsRow.add( new UIText( strings.getKey( 'sidebar/geometry/torusKnot_geometry/radialsegments' ) ).setWidth( '90px' ) );
  31. radialSegmentsRow.add( radialSegments );
  32. container.add( radialSegmentsRow );
  33. // p
  34. const pRow = new UIRow();
  35. const p = new UINumber( parameters.p ).onChange( update );
  36. pRow.add( new UIText( strings.getKey( 'sidebar/geometry/torusKnot_geometry/p' ) ).setWidth( '90px' ) );
  37. pRow.add( p );
  38. container.add( pRow );
  39. // q
  40. const qRow = new UIRow();
  41. const q = new UINumber( parameters.q ).onChange( update );
  42. qRow.add( new UIText( strings.getKey( 'sidebar/geometry/torusKnot_geometry/q' ) ).setWidth( '90px' ) );
  43. qRow.add( q );
  44. container.add( qRow );
  45. //
  46. function update() {
  47. editor.execute( new SetGeometryCommand( editor, object, new THREE.TorusKnotGeometry(
  48. radius.getValue(),
  49. tube.getValue(),
  50. tubularSegments.getValue(),
  51. radialSegments.getValue(),
  52. p.getValue(),
  53. q.getValue()
  54. ) ) );
  55. }
  56. return container;
  57. }
  58. export { GeometryParametersPanel };