Sidebar.Geometry.TetrahedronGeometry.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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/tetrahedron_geometry/radius' ) ).setClass( 'Label' ) );
  14. radiusRow.add( radius );
  15. container.add( radiusRow );
  16. // detail
  17. const detailRow = new UIRow();
  18. const detail = new UIInteger( parameters.detail ).setRange( 0, Infinity ).onChange( update );
  19. detailRow.add( new UIText( strings.getKey( 'sidebar/geometry/tetrahedron_geometry/detail' ) ).setClass( 'Label' ) );
  20. detailRow.add( detail );
  21. container.add( detailRow );
  22. //
  23. function refreshUI() {
  24. const parameters = object.geometry.parameters;
  25. radius.setValue( parameters.radius );
  26. detail.setValue( parameters.detail );
  27. }
  28. signals.geometryChanged.add( function ( mesh ) {
  29. if ( mesh === object ) {
  30. refreshUI();
  31. }
  32. } );
  33. //
  34. function update() {
  35. editor.execute( new SetGeometryCommand( editor, object, new THREE.TetrahedronGeometry(
  36. radius.getValue(),
  37. detail.getValue()
  38. ) ) );
  39. }
  40. return container;
  41. }
  42. export { GeometryParametersPanel };