Sidebar.Geometry.TubeGeometry.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import * as THREE from 'three';
  2. import { UIDiv, UIRow, UIText, UIInteger, UISelect, UICheckbox, UINumber } from './libs/ui.js';
  3. import { UIPoints3 } from './libs/ui.three.js';
  4. import { SetGeometryCommand } from './commands/SetGeometryCommand.js';
  5. function GeometryParametersPanel( editor, object ) {
  6. const strings = editor.strings;
  7. const signals = editor.signals;
  8. const container = new UIDiv();
  9. const geometry = object.geometry;
  10. const parameters = geometry.parameters;
  11. // points
  12. const pointsRow = new UIRow();
  13. pointsRow.add( new UIText( strings.getKey( 'sidebar/geometry/tube_geometry/path' ) ).setClass( 'Label' ) );
  14. const points = new UIPoints3().setValue( parameters.path.points ).onChange( update );
  15. pointsRow.add( points );
  16. container.add( pointsRow );
  17. // radius
  18. const radiusRow = new UIRow();
  19. const radius = new UINumber( parameters.radius ).onChange( update );
  20. radiusRow.add( new UIText( strings.getKey( 'sidebar/geometry/tube_geometry/radius' ) ).setClass( 'Label' ) );
  21. radiusRow.add( radius );
  22. container.add( radiusRow );
  23. // tubularSegments
  24. const tubularSegmentsRow = new UIRow();
  25. const tubularSegments = new UIInteger( parameters.tubularSegments ).onChange( update );
  26. tubularSegmentsRow.add( new UIText( strings.getKey( 'sidebar/geometry/tube_geometry/tubularsegments' ) ).setClass( 'Label' ) );
  27. tubularSegmentsRow.add( tubularSegments );
  28. container.add( tubularSegmentsRow );
  29. // radialSegments
  30. const radialSegmentsRow = new UIRow();
  31. const radialSegments = new UIInteger( parameters.radialSegments ).onChange( update );
  32. radialSegmentsRow.add( new UIText( strings.getKey( 'sidebar/geometry/tube_geometry/radialsegments' ) ).setClass( 'Label' ) );
  33. radialSegmentsRow.add( radialSegments );
  34. container.add( radialSegmentsRow );
  35. // closed
  36. const closedRow = new UIRow();
  37. const closed = new UICheckbox( parameters.closed ).onChange( update );
  38. closedRow.add( new UIText( strings.getKey( 'sidebar/geometry/tube_geometry/closed' ) ).setClass( 'Label' ) );
  39. closedRow.add( closed );
  40. container.add( closedRow );
  41. // curveType
  42. const curveTypeRow = new UIRow();
  43. const curveType = new UISelect().setOptions( { centripetal: 'centripetal', chordal: 'chordal', catmullrom: 'catmullrom' } ).setValue( parameters.path.curveType ).onChange( update );
  44. curveTypeRow.add( new UIText( strings.getKey( 'sidebar/geometry/tube_geometry/curvetype' ) ).setClass( 'Label' ), curveType );
  45. container.add( curveTypeRow );
  46. // tension
  47. const tensionRow = new UIRow().setDisplay( curveType.getValue() == 'catmullrom' ? '' : 'none' );
  48. const tension = new UINumber( parameters.path.tension ).setStep( 0.01 ).onChange( update );
  49. tensionRow.add( new UIText( strings.getKey( 'sidebar/geometry/tube_geometry/tension' ) ).setClass( 'Label' ), tension );
  50. container.add( tensionRow );
  51. //
  52. function refreshUI() {
  53. const parameters = object.geometry.parameters;
  54. tubularSegments.setValue( parameters.tubularSegments );
  55. radius.setValue( parameters.radius );
  56. radialSegments.setValue( parameters.radialSegments );
  57. closed.setValue( parameters.closed );
  58. points.setValue( parameters.path.points, false );
  59. curveType.setValue( parameters.path.curveType );
  60. tension.setValue( parameters.path.tension );
  61. tensionRow.setDisplay( curveType.getValue() == 'catmullrom' ? '' : 'none' );
  62. }
  63. signals.geometryChanged.add( function ( mesh ) {
  64. if ( mesh === object ) {
  65. refreshUI();
  66. }
  67. } );
  68. //
  69. function update() {
  70. tensionRow.setDisplay( curveType.getValue() == 'catmullrom' ? '' : 'none' );
  71. editor.execute( new SetGeometryCommand( editor, object, new THREE.TubeGeometry(
  72. new THREE.CatmullRomCurve3( points.getValue(), closed.getValue(), curveType.getValue(), tension.getValue() ),
  73. tubularSegments.getValue(),
  74. radius.getValue(),
  75. radialSegments.getValue(),
  76. closed.getValue()
  77. ) ) );
  78. }
  79. return container;
  80. }
  81. export { GeometryParametersPanel };