diff --git a/editor/js/Menubar.Add.js b/editor/js/Menubar.Add.js index 75928c046c119c..d59c3d45da8014 100644 --- a/editor/js/Menubar.Add.js +++ b/editor/js/Menubar.Add.js @@ -254,19 +254,19 @@ Menubar.Add = function ( editor ) { var phiStart = 0; var phiLength = 2 * Math.PI; - points.push( new THREE.Vector3( 0, 0, 0 ) ); - points.push( new THREE.Vector3( 4, 0, 0 ) ); - points.push( new THREE.Vector3( 3.5, 0, 0.5 ) ); - points.push( new THREE.Vector3( 1, 0, 0.75 ) ); - points.push( new THREE.Vector3( 0.8, 0, 1 ) ); - points.push( new THREE.Vector3( 0.8, 0, 4 ) ); - points.push( new THREE.Vector3( 1, 0, 4.2 ) ); - points.push( new THREE.Vector3( 1.4, 0, 4.8 ) ); - points.push( new THREE.Vector3( 2, 0, 5 ) ); - points.push( new THREE.Vector3( 2.5, 0, 5.4 ) ); - points.push( new THREE.Vector3( 2.5, 0, 12 ) ); - - var geometry = new THREE.LatheGeometry( points, segments, phiStart, phiLength ); + points.push( new THREE.Vector2( 0, 0 ) ); + points.push( new THREE.Vector2( 4, 0 ) ); + points.push( new THREE.Vector2( 3.5, 0.5 ) ); + points.push( new THREE.Vector2( 1, 0.75 ) ); + points.push( new THREE.Vector2( 0.8, 1 ) ); + points.push( new THREE.Vector2( 0.8, 4 ) ); + points.push( new THREE.Vector2( 1, 4.2 ) ); + points.push( new THREE.Vector2( 1.4, 4.8 ) ); + points.push( new THREE.Vector2( 2, 5 ) ); + points.push( new THREE.Vector2( 2.5, 5.4 ) ); + points.push( new THREE.Vector2( 3, 12 ) ); + + var geometry = new THREE.LatheGeometry( points, segments, phiStart, phiLength, 'Y' ); var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial( { side: THREE.DoubleSide } ) ); mesh.name = 'Lathe ' + ( ++ meshCount ); diff --git a/editor/js/Sidebar.Geometry.LatheGeometry.js b/editor/js/Sidebar.Geometry.LatheGeometry.js index 304a6706713c03..da504ba2248ce8 100644 --- a/editor/js/Sidebar.Geometry.LatheGeometry.js +++ b/editor/js/Sidebar.Geometry.LatheGeometry.js @@ -40,6 +40,16 @@ Sidebar.Geometry.LatheGeometry = function( editor, object ) { container.add( phiLengthRow ); + // axe + + var axeRow = new UI.Row(); + var axe = new UI.Input( parameters.axe ).setWidth( '10px' ).onChange( update ); + + axeRow.add( new UI.Text( 'Axe' ).setWidth( '90px' ) ); + axeRow.add( axe ); + + container.add( axeRow ); + // points var lastPointIdx = 0; @@ -57,7 +67,7 @@ Sidebar.Geometry.LatheGeometry = function( editor, object ) { for ( var i = 0; i < parameters.points.length; i ++ ) { var point = parameters.points[ i ]; - pointsList.add( createPointRow( point.x, point.z ) ); + pointsList.add( createPointRow( point.x, point.y ) ); } @@ -119,7 +129,7 @@ Sidebar.Geometry.LatheGeometry = function( editor, object ) { if ( ! pointUI ) continue; - points.push( new THREE.Vector3( pointUI.x.getValue(), 0, pointUI.y.getValue() ) ); + points.push( new THREE.Vector2( pointUI.x.getValue(), pointUI.y.getValue() ) ); count ++; pointUI.lbl.setValue( count ); @@ -129,7 +139,8 @@ Sidebar.Geometry.LatheGeometry = function( editor, object ) { points, segments.getValue(), phiStart.getValue() / 180 * Math.PI, - phiLength.getValue() / 180 * Math.PI + phiLength.getValue() / 180 * Math.PI, + axe.getValue() ); editor.execute( new SetGeometryCommand( object, geometry ) ); diff --git a/src/extras/geometries/LatheGeometry.js b/src/extras/geometries/LatheGeometry.js index f702c4a026b270..1ca29e2797a986 100644 --- a/src/extras/geometries/LatheGeometry.js +++ b/src/extras/geometries/LatheGeometry.js @@ -4,31 +4,50 @@ * @author bhouston / http://clara.io */ -// points - to create a closed torus, one must use a set of points +// points - to create a closed torus, one must use a set of points // like so: [ a, b, c, d, a ], see first is the same as last. // segments - the number of circumference segments to create // phiStart - the starting radian // phiLength - the radian (0 to 2*PI) range of the lathed section // 2*pi is a closed lathe, less than 2PI is a portion. +// axe - the axis of revolution ('X', 'Y' or 'Z') -THREE.LatheGeometry = function ( points, segments, phiStart, phiLength ) { +THREE.LatheGeometry = function( points, segments, phiStart, phiLength, axe ) { + + var thePoints = points; + if ( points.length && points[ 0 ] instanceof THREE.Vector3 ) { + + console.warn( 'THREE.LatheGeometry has been updated. Use an array of THREE.Vector2 as first parameter.' ); + + thePoints = []; + axe = 'Z'; + for ( var i = 0; i < points.length; i ++ ) { + + var pt = points[ i ]; + thePoints.push( new THREE.Vector2( Math.sqrt( pt.x * pt.x + pt.y * pt.y ), pt.z ) ); + + } + + } THREE.Geometry.call( this ); this.type = 'LatheGeometry'; this.parameters = { - points: points, + points: thePoints, segments: segments, phiStart: phiStart, - phiLength: phiLength + phiLength: phiLength, + axe: axe }; segments = segments || 12; phiStart = phiStart || 0; phiLength = phiLength || 2 * Math.PI; + axe = axe || 'Y'; - var inversePointLength = 1.0 / ( points.length - 1 ); + var inversePointLength = 1.0 / ( thePoints.length - 1 ); var inverseSegments = 1.0 / segments; for ( var i = 0, il = segments; i <= il; i ++ ) { @@ -38,15 +57,31 @@ THREE.LatheGeometry = function ( points, segments, phiStart, phiLength ) { var c = Math.cos( phi ), s = Math.sin( phi ); - for ( var j = 0, jl = points.length; j < jl; j ++ ) { + for ( var j = 0, jl = thePoints.length; j < jl; j ++ ) { - var pt = points[ j ]; + var pt = thePoints[ j ]; var vertex = new THREE.Vector3(); - vertex.x = c * pt.x - s * pt.y; - vertex.y = s * pt.x + c * pt.y; - vertex.z = pt.z; + if ( axe === 'Z' ) { + + vertex.x = c * pt.x; + vertex.y = s * pt.x; + vertex.z = pt.y; + + } else if ( axe === 'X' ) { + + vertex.y = c * pt.x; + vertex.z = s * pt.x; + vertex.x = pt.y; + + } else { + + vertex.z = c * pt.x; + vertex.x = s * pt.x; + vertex.y = pt.y; + + } this.vertices.push( vertex ); @@ -54,11 +89,11 @@ THREE.LatheGeometry = function ( points, segments, phiStart, phiLength ) { } - var np = points.length; + var np = thePoints.length; for ( var i = 0, il = segments; i < il; i ++ ) { - for ( var j = 0, jl = points.length - 1; j < jl; j ++ ) { + for ( var j = 0, jl = thePoints.length - 1; j < jl; j ++ ) { var base = j + np * i; var a = base; diff --git a/src/loaders/ObjectLoader.js b/src/loaders/ObjectLoader.js index 2f205144a1e6a2..63ec4d51e8bdc0 100755 --- a/src/loaders/ObjectLoader.js +++ b/src/loaders/ObjectLoader.js @@ -263,7 +263,8 @@ THREE.ObjectLoader.prototype = { data.points, data.segments, data.phiStart, - data.phiLength + data.phiLength, + data.axe ); break;