|
@@ -7,7 +7,9 @@
|
|
|
|
|
|
THREE.ParametricGeometries = {
|
|
THREE.ParametricGeometries = {
|
|
|
|
|
|
- klein: function ( v, u ) {
|
|
|
|
|
|
+ klein: function ( v, u, optionalTarget ) {
|
|
|
|
+
|
|
|
|
+ var result = optionalTarget || new THREE.Vector3();
|
|
|
|
|
|
u *= Math.PI;
|
|
u *= Math.PI;
|
|
v *= 2 * Math.PI;
|
|
v *= 2 * Math.PI;
|
|
@@ -28,25 +30,29 @@ THREE.ParametricGeometries = {
|
|
|
|
|
|
y = - 2 * ( 1 - Math.cos( u ) / 2 ) * Math.sin( v );
|
|
y = - 2 * ( 1 - Math.cos( u ) / 2 ) * Math.sin( v );
|
|
|
|
|
|
- return new THREE.Vector3( x, y, z );
|
|
|
|
|
|
+ return result.set( x, y, z );
|
|
|
|
|
|
},
|
|
},
|
|
|
|
|
|
plane: function ( width, height ) {
|
|
plane: function ( width, height ) {
|
|
|
|
|
|
- return function( u, v ) {
|
|
|
|
|
|
+ return function( u, v, optionalTarget ) {
|
|
|
|
+
|
|
|
|
+ var result = optionalTarget || new THREE.Vector3();
|
|
|
|
|
|
var x = u * width;
|
|
var x = u * width;
|
|
var y = 0;
|
|
var y = 0;
|
|
var z = v * height;
|
|
var z = v * height;
|
|
|
|
|
|
- return new THREE.Vector3( x, y, z );
|
|
|
|
|
|
+ return result.set( x, y, z );
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
},
|
|
},
|
|
|
|
|
|
- mobius: function( u, t ) {
|
|
|
|
|
|
+ mobius: function( u, t, optionalTarget ) {
|
|
|
|
+
|
|
|
|
+ var result = optionalTarget || new THREE.Vector3();
|
|
|
|
|
|
// flat mobius strip
|
|
// flat mobius strip
|
|
// http://www.wolframalpha.com/input/?i=M%C3%B6bius+strip+parametric+equations&lk=1&a=ClashPrefs_*Surface.MoebiusStrip.SurfaceProperty.ParametricEquations-
|
|
// http://www.wolframalpha.com/input/?i=M%C3%B6bius+strip+parametric+equations&lk=1&a=ClashPrefs_*Surface.MoebiusStrip.SurfaceProperty.ParametricEquations-
|
|
@@ -56,28 +62,36 @@ THREE.ParametricGeometries = {
|
|
var x, y, z;
|
|
var x, y, z;
|
|
|
|
|
|
var a = 2;
|
|
var a = 2;
|
|
|
|
+
|
|
x = Math.cos( v ) * ( a + u * Math.cos( v / 2 ) );
|
|
x = Math.cos( v ) * ( a + u * Math.cos( v / 2 ) );
|
|
y = Math.sin( v ) * ( a + u * Math.cos( v / 2 ) );
|
|
y = Math.sin( v ) * ( a + u * Math.cos( v / 2 ) );
|
|
z = u * Math.sin( v / 2 );
|
|
z = u * Math.sin( v / 2 );
|
|
- return new THREE.Vector3( x, y, z );
|
|
|
|
|
|
+
|
|
|
|
+ return result.set( x, y, z );
|
|
|
|
|
|
},
|
|
},
|
|
|
|
|
|
- mobius3d: function( u, t ) {
|
|
|
|
|
|
+ mobius3d: function( u, t, optionalTarget ) {
|
|
|
|
+
|
|
|
|
+ var result = optionalTarget || new THREE.Vector3();
|
|
|
|
|
|
// volumetric mobius strip
|
|
// volumetric mobius strip
|
|
|
|
+
|
|
u *= Math.PI;
|
|
u *= Math.PI;
|
|
t *= 2 * Math.PI;
|
|
t *= 2 * Math.PI;
|
|
|
|
|
|
u = u * 2;
|
|
u = u * 2;
|
|
var phi = u / 2;
|
|
var phi = u / 2;
|
|
var major = 2.25, a = 0.125, b = 0.65;
|
|
var major = 2.25, a = 0.125, b = 0.65;
|
|
|
|
+
|
|
var x, y, z;
|
|
var x, y, z;
|
|
|
|
+
|
|
x = a * Math.cos( t ) * Math.cos( phi ) - b * Math.sin( t ) * Math.sin( phi );
|
|
x = a * Math.cos( t ) * Math.cos( phi ) - b * Math.sin( t ) * Math.sin( phi );
|
|
z = a * Math.cos( t ) * Math.sin( phi ) + b * Math.sin( t ) * Math.cos( phi );
|
|
z = a * Math.cos( t ) * Math.sin( phi ) + b * Math.sin( t ) * Math.cos( phi );
|
|
y = ( major + x ) * Math.sin( u );
|
|
y = ( major + x ) * Math.sin( u );
|
|
x = ( major + x ) * Math.cos( u );
|
|
x = ( major + x ) * Math.cos( u );
|
|
- return new THREE.Vector3( x, y, z );
|
|
|
|
|
|
+
|
|
|
|
+ return result.set( x, y, z );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -108,7 +122,7 @@ THREE.ParametricGeometries.TubeGeometry = function( path, segments, radius, segm
|
|
|
|
|
|
x, y, z, tx, ty, tz, u, v,
|
|
x, y, z, tx, ty, tz, u, v,
|
|
|
|
|
|
- cx, cy, pos, pos2 = new THREE.Vector3(),
|
|
|
|
|
|
+ cx, cy, pos,
|
|
i, j, ip, jp, a, b, c, d, uva, uvb, uvc, uvd;
|
|
i, j, ip, jp, a, b, c, d, uva, uvb, uvc, uvd;
|
|
|
|
|
|
var frames = path.computeFrenetFrames( segments, closed ),
|
|
var frames = path.computeFrenetFrames( segments, closed ),
|
|
@@ -123,7 +137,9 @@ THREE.ParametricGeometries.TubeGeometry = function( path, segments, radius, segm
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- var ParametricTube = function( u, v ) {
|
|
|
|
|
|
+ var ParametricTube = function( u, v, optionalTarget ) {
|
|
|
|
+
|
|
|
|
+ var result = optionalTarget || new THREE.Vector3();
|
|
|
|
|
|
v *= 2 * Math.PI;
|
|
v *= 2 * Math.PI;
|
|
|
|
|
|
@@ -147,12 +163,11 @@ THREE.ParametricGeometries.TubeGeometry = function( path, segments, radius, segm
|
|
cx = - scope.radius * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
|
|
cx = - scope.radius * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
|
|
cy = scope.radius * Math.sin( v );
|
|
cy = scope.radius * Math.sin( v );
|
|
|
|
|
|
- pos2.copy( pos );
|
|
|
|
- pos2.x += cx * normal.x + cy * binormal.x;
|
|
|
|
- pos2.y += cx * normal.y + cy * binormal.y;
|
|
|
|
- pos2.z += cx * normal.z + cy * binormal.z;
|
|
|
|
|
|
+ pos.x += cx * normal.x + cy * binormal.x;
|
|
|
|
+ pos.y += cx * normal.y + cy * binormal.y;
|
|
|
|
+ pos.z += cx * normal.z + cy * binormal.z;
|
|
|
|
|
|
- return pos2.clone();
|
|
|
|
|
|
+ return result.copy( pos );
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
@@ -222,7 +237,9 @@ THREE.ParametricGeometries.TorusKnotGeometry.prototype.constructor = THREE.Param
|
|
*********************************************/
|
|
*********************************************/
|
|
THREE.ParametricGeometries.SphereGeometry = function( size, u, v ) {
|
|
THREE.ParametricGeometries.SphereGeometry = function( size, u, v ) {
|
|
|
|
|
|
- function sphere( u, v ) {
|
|
|
|
|
|
+ function sphere( u, v, optionalTarget ) {
|
|
|
|
+
|
|
|
|
+ var result = optionalTarget || new THREE.Vector3();
|
|
|
|
|
|
u *= Math.PI;
|
|
u *= Math.PI;
|
|
v *= 2 * Math.PI;
|
|
v *= 2 * Math.PI;
|
|
@@ -231,8 +248,7 @@ THREE.ParametricGeometries.SphereGeometry = function( size, u, v ) {
|
|
var y = size * Math.sin( u ) * Math.sin( v );
|
|
var y = size * Math.sin( u ) * Math.sin( v );
|
|
var z = size * Math.cos( u );
|
|
var z = size * Math.cos( u );
|
|
|
|
|
|
-
|
|
|
|
- return new THREE.Vector3( x, y, z );
|
|
|
|
|
|
+ return result.set( x, y, z );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -252,13 +268,15 @@ THREE.ParametricGeometries.SphereGeometry.prototype.constructor = THREE.Parametr
|
|
|
|
|
|
THREE.ParametricGeometries.PlaneGeometry = function( width, depth, segmentsWidth, segmentsDepth ) {
|
|
THREE.ParametricGeometries.PlaneGeometry = function( width, depth, segmentsWidth, segmentsDepth ) {
|
|
|
|
|
|
- function plane( u, v ) {
|
|
|
|
|
|
+ function plane( u, v, optionalTarget ) {
|
|
|
|
+
|
|
|
|
+ var result = optionalTarget || new THREE.Vector3();
|
|
|
|
|
|
var x = u * width;
|
|
var x = u * width;
|
|
var y = 0;
|
|
var y = 0;
|
|
var z = v * depth;
|
|
var z = v * depth;
|
|
|
|
|
|
- return new THREE.Vector3( x, y, z );
|
|
|
|
|
|
+ return result.set( x, y, z );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|