Sidebar.Geometry.TubeGeometry.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. var parameterPoints = parameters.path.points;
  20. for ( var i = 0; i < parameterPoints.length; i ++ ) {
  21. var point = parameterPoints[ i ];
  22. pointsList.add( createPointRow( point.x, point.y, point.z ) );
  23. }
  24. var addPointButton = new UI.Button( '+' ).onClick( function () {
  25. if ( pointsUI.length === 0 ) {
  26. pointsList.add( createPointRow( 0, 0, 0 ) );
  27. } else {
  28. var point = pointsUI[ pointsUI.length - 1 ];
  29. pointsList.add( createPointRow( point.x.getValue(), point.y.getValue(), point.z.getValue() ) );
  30. }
  31. update();
  32. } );
  33. points.add( addPointButton );
  34. container.add( pointsRow );
  35. // radius
  36. var radiusRow = new UI.Row();
  37. var radius = new UI.Number( parameters.radius ).onChange( update );
  38. radiusRow.add( new UI.Text( strings.getKey( 'sidebar/geometry/tube_geometry/radius' ) ).setWidth( '90px' ) );
  39. radiusRow.add( radius );
  40. container.add( radiusRow );
  41. // tubularSegments
  42. var tubularSegmentsRow = new UI.Row();
  43. var tubularSegments = new UI.Integer( parameters.tubularSegments ).onChange( update );
  44. tubularSegmentsRow.add( new UI.Text( strings.getKey( 'sidebar/geometry/tube_geometry/tubularsegments' ) ).setWidth( '90px' ) );
  45. tubularSegmentsRow.add( tubularSegments );
  46. container.add( tubularSegmentsRow );
  47. // radialSegments
  48. var radialSegmentsRow = new UI.Row();
  49. var radialSegments = new UI.Integer( parameters.radialSegments ).onChange( update );
  50. radialSegmentsRow.add( new UI.Text( strings.getKey( 'sidebar/geometry/tube_geometry/radialsegments' ) ).setWidth( '90px' ) );
  51. radialSegmentsRow.add( radialSegments );
  52. container.add( radialSegmentsRow );
  53. // closed
  54. var closedRow = new UI.Row();
  55. var closed = new UI.Checkbox( parameters.closed ).onChange( update );
  56. closedRow.add( new UI.Text( strings.getKey( 'sidebar/geometry/tube_geometry/closed' ) ).setWidth( '90px' ) );
  57. closedRow.add( closed );
  58. container.add( closedRow );
  59. // curveType
  60. var curveTypeRow = new UI.Row();
  61. var curveType = new UI.Select().setOptions( { centripetal: 'centripetal', chordal: 'chordal', catmullrom: 'catmullrom' } ).setValue( parameters.path.curveType ).onChange( update );
  62. curveTypeRow.add( new UI.Text( strings.getKey( 'sidebar/geometry/tube_geometry/curvetype' ) ).setWidth( '90px' ), curveType );
  63. container.add( curveTypeRow );
  64. // tension
  65. var tensionRow = new UI.Row().setDisplay( curveType.getValue() == 'catmullrom' ? '' : 'none' );
  66. var tension = new UI.Number( parameters.path.tension ).setStep( 0.01 ).onChange( update );
  67. tensionRow.add( new UI.Text( strings.getKey( 'sidebar/geometry/tube_geometry/tension' ) ).setWidth( '90px' ), tension );
  68. container.add( tensionRow );
  69. //
  70. function update() {
  71. var points = [];
  72. var count = 0;
  73. for ( var i = 0; i < pointsUI.length; i ++ ) {
  74. var pointUI = pointsUI[ i ];
  75. if ( ! pointUI ) continue;
  76. points.push( new THREE.Vector3( pointUI.x.getValue(), pointUI.y.getValue(), pointUI.z.getValue() ) );
  77. count ++;
  78. pointUI.lbl.setValue( count );
  79. }
  80. tensionRow.setDisplay( curveType.getValue() == 'catmullrom' ? '' : 'none' );
  81. editor.execute( new SetGeometryCommand( object, new THREE[ geometry.type ](
  82. new THREE.CatmullRomCurve3( points, closed.getValue(), curveType.getValue(), tension.getValue() ),
  83. tubularSegments.getValue(),
  84. radius.getValue(),
  85. radialSegments.getValue(),
  86. closed.getValue()
  87. ) ) );
  88. }
  89. function createPointRow( x, y, z ) {
  90. var pointRow = new UI.Div();
  91. var lbl = new UI.Text( lastPointIdx + 1 ).setWidth( '20px' );
  92. var txtX = new UI.Number( x ).setWidth( '30px' ).onChange( update );
  93. var txtY = new UI.Number( y ).setWidth( '30px' ).onChange( update );
  94. var txtZ = new UI.Number( z ).setWidth( '30px' ).onChange( update );
  95. var idx = lastPointIdx;
  96. var btn = new UI.Button( '-' ).onClick( function () {
  97. deletePointRow( idx );
  98. } );
  99. pointsUI.push( { row: pointRow, lbl: lbl, x: txtX, y: txtY, z: txtZ } );
  100. lastPointIdx ++;
  101. pointRow.add( lbl, txtX, txtY, txtZ, btn );
  102. return pointRow;
  103. }
  104. function deletePointRow( idx ) {
  105. if ( ! pointsUI[ idx ] ) return;
  106. pointsList.remove( pointsUI[ idx ].row );
  107. pointsUI[ idx ] = null;
  108. update();
  109. }
  110. return container;
  111. };
  112. Sidebar.Geometry.TubeBufferGeometry = Sidebar.Geometry.TubeGeometry;