Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions editor/js/Menubar.Add.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
17 changes: 14 additions & 3 deletions editor/js/Sidebar.Geometry.LatheGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 ) );

}

Expand Down Expand Up @@ -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 );

Expand All @@ -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 ) );
Expand Down
59 changes: 47 additions & 12 deletions src/extras/geometries/LatheGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ++ ) {
Expand All @@ -38,27 +57,43 @@ 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 );

}

}

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;
Expand Down
3 changes: 2 additions & 1 deletion src/loaders/ObjectLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ THREE.ObjectLoader.prototype = {
data.points,
data.segments,
data.phiStart,
data.phiLength
data.phiLength,
data.axe
);

break;
Expand Down