Sidebar.Geometry.TubeGeometry.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /**
  2. * @author Temdog007 / http://github.com/Temdog007
  3. */
  4. Sidebar.Geometry.TubeGeometry = function ( editor, object ) {
  5. var strings = editor.strings;
  6. var signals = editor.signals;
  7. var container = new UI.Row();
  8. var geometry = object.geometry;
  9. var parameters = geometry.parameters;
  10. // points
  11. var lastPointIdx = 0;
  12. var pointsUI = [];
  13. var pointsRow = new UI.Row();
  14. pointsRow.add( new UI.Text( strings.getKey( 'sidebar/geometry/tube_geometry/path' ) ).setWidth( '90px' ) );
  15. var points = new UI.Span().setDisplay( 'inline-block' );
  16. pointsRow.add( points );
  17. var pointsList = new UI.Div();
  18. points.add( pointsList );
  19. ( function () {
  20. var points = parameters.path.points;
  21. for ( var i = 0; i < points.length; i ++ ) {
  22. var point = points[ i ];
  23. pointsList.add( createPointRow( point.x, point.y, point.z ) );
  24. }
  25. } )();
  26. var addPointButton = new UI.Button( '+' ).onClick( function () {
  27. if ( pointsUI.length === 0 ) {
  28. pointsList.add( createPointRow( 0, 0, 0 ) );
  29. } else {
  30. var point = pointsUI[ pointsUI.length - 1 ];
  31. pointsList.add( createPointRow( point.x.getValue(), point.y.getValue(), point.z.getValue() ) );
  32. }
  33. update();
  34. } );
  35. points.add( addPointButton );
  36. container.add( pointsRow );
  37. // radius
  38. var radiusRow = new UI.Row();
  39. var radius = new UI.Number( parameters.radius ).onChange( update );
  40. radiusRow.add( new UI.Text( strings.getKey( 'sidebar/geometry/tube_geometry/radius' ) ).setWidth( '90px' ) );
  41. radiusRow.add( radius );
  42. container.add( radiusRow );
  43. // tubularSegments
  44. var tubularSegmentsRow = new UI.Row();
  45. var tubularSegments = new UI.Integer( parameters.tubularSegments ).onChange( update );
  46. tubularSegmentsRow.add( new UI.Text( strings.getKey( 'sidebar/geometry/tube_geometry/tubularsegments' ) ).setWidth( '90px' ) );
  47. tubularSegmentsRow.add( tubularSegments );
  48. container.add( tubularSegmentsRow );
  49. // radialSegments
  50. var radialSegmentsRow = new UI.Row();
  51. var radialSegments = new UI.Integer( parameters.radialSegments ).onChange( update );
  52. radialSegmentsRow.add( new UI.Text( strings.getKey( 'sidebar/geometry/tube_geometry/radialsegments' ) ).setWidth( '90px' ) );
  53. radialSegmentsRow.add( radialSegments );
  54. container.add( radialSegmentsRow );
  55. // closed
  56. var closedRow = new UI.Row();
  57. var closed = new UI.Checkbox( parameters.closed ).onChange( update );
  58. closedRow.add( new UI.Text( strings.getKey( 'sidebar/geometry/tube_geometry/closed' ) ).setWidth( '90px' ) );
  59. closedRow.add( closed );
  60. container.add( closedRow );
  61. //
  62. function update() {
  63. var points = [];
  64. var count = 0;
  65. for ( var i = 0; i < pointsUI.length; i ++ ) {
  66. var pointUI = pointsUI[ i ];
  67. if ( ! pointUI ) continue;
  68. points.push( new THREE.Vector3( pointUI.x.getValue(), pointUI.y.getValue(), pointUI.z.getValue() ) );
  69. count ++;
  70. pointUI.lbl.setValue( count );
  71. }
  72. editor.execute( new SetGeometryCommand( object, new THREE[ geometry.type ](
  73. new THREE.CatmullRomCurve3( points ),
  74. tubularSegments.getValue(),
  75. radius.getValue(),
  76. radialSegments.getValue(),
  77. closed.getValue()
  78. ) ) );
  79. }
  80. function createPointRow( x, y, z ) {
  81. var pointRow = new UI.Div();
  82. var lbl = new UI.Text( lastPointIdx + 1 ).setWidth( '20px' );
  83. var txtX = new UI.Number( x ).setWidth( '30px' ).onChange( update );
  84. var txtY = new UI.Number( y ).setWidth( '30px' ).onChange( update );
  85. var txtZ = new UI.Number( z ).setWidth( '30px' ).onChange( update );
  86. var idx = lastPointIdx;
  87. var btn = new UI.Button( '-' ).onClick( function () {
  88. deletePointRow( idx );
  89. } );
  90. pointsUI.push( { row: pointRow, lbl: lbl, x: txtX, y: txtY, z: txtZ } );
  91. lastPointIdx ++;
  92. pointRow.add( lbl, txtX, txtY, txtZ, btn );
  93. return pointRow;
  94. }
  95. function deletePointRow( idx ) {
  96. if ( ! pointsUI[ idx ] ) return;
  97. pointsList.remove( pointsUI[ idx ].row );
  98. pointsUI[ idx ] = null;
  99. update();
  100. }
  101. return container;
  102. };
  103. Sidebar.Geometry.TubeBufferGeometry = Sidebar.Geometry.TubeGeometry;
粤ICP备19079148号