提交 c1fa178d 编写于 作者: M Mr.doob

Merge remote-tracking branch 'bhouston/transform' into dev

......@@ -361,7 +361,7 @@
loader.load( url, function ( geometry, geometryBonds ) {
var offset = THREE.GeometryUtils.center( geometry );
geometryBonds.applyMatrix( new THREE.Matrix4().makeTranslation( offset.x, offset.y, offset.z ) );
geometryBonds.applyMatrix( new THREE.Matrix4().makeTranslation( offset ) );
for ( var i = 0; i < geometry.vertices.length; i ++ ) {
......
......@@ -93,26 +93,31 @@
var pxGeometry = new THREE.PlaneGeometry( 100, 100 );
pxGeometry.faces[ 0 ].materialIndex = 1;
pxGeometry.applyMatrix( new THREE.Matrix4().makeRotationY( Math.PI / 2 ) );
pxGeometry.applyMatrix( new THREE.Matrix4().makeTranslation( 50, 0, 0 ) );
pxGeometry.applyMatrix( new THREE.Matrix4().makeTranslation(
new THREE.Vector3( 50, 0, 0 ) ) );
var nxGeometry = new THREE.PlaneGeometry( 100, 100 );
nxGeometry.faces[ 0 ].materialIndex = 1;
nxGeometry.applyMatrix( new THREE.Matrix4().makeRotationY( - Math.PI / 2 ) );
nxGeometry.applyMatrix( new THREE.Matrix4().makeTranslation( - 50, 0, 0 ) );
nxGeometry.applyMatrix( new THREE.Matrix4().makeTranslation(
new THREE.Vector3( - 50, 0, 0 ) ) );
var pyGeometry = new THREE.PlaneGeometry( 100, 100 );
pyGeometry.faces[ 0 ].materialIndex = 0;
pyGeometry.applyMatrix( new THREE.Matrix4().makeRotationX( - Math.PI / 2 ) );
pyGeometry.applyMatrix( new THREE.Matrix4().makeTranslation( 0, 50, 0 ) );
pyGeometry.applyMatrix( new THREE.Matrix4().makeTranslation(
new THREE.Vector3( 0, 50, 0 ) ) );
var pzGeometry = new THREE.PlaneGeometry( 100, 100 );
pzGeometry.faces[ 0 ].materialIndex = 1;
pzGeometry.applyMatrix( new THREE.Matrix4().makeTranslation( 0, 0, 50 ) );
pzGeometry.applyMatrix( new THREE.Matrix4().makeTranslation(
new THREE.Vector3( 0, 0, 50 ) ) );
var nzGeometry = new THREE.PlaneGeometry( 100, 100 );
nzGeometry.faces[ 0 ].materialIndex = 1;
nzGeometry.applyMatrix( new THREE.Matrix4().makeRotationY( Math.PI ) );
nzGeometry.applyMatrix( new THREE.Matrix4().makeTranslation( 0, 0, -50 ) );
nzGeometry.applyMatrix( new THREE.Matrix4().makeTranslation(
new THREE.Vector3( 0, 0, -50 ) ) );
//
......
......@@ -104,30 +104,35 @@
pxGeometry.faces[ 0 ].materialIndex = 1;
pxGeometry.faces[ 0 ].vertexColors = [ light, shadow, shadow, light ];
pxGeometry.applyMatrix( new THREE.Matrix4().makeRotationY( Math.PI / 2 ) );
pxGeometry.applyMatrix( new THREE.Matrix4().makeTranslation( 50, 0, 0 ) );
pxGeometry.applyMatrix( new THREE.Matrix4().makeTranslation(
new THREE.Vector3( 50, 0, 0 ) ) );
var nxGeometry = new THREE.PlaneGeometry( 100, 100 );
nxGeometry.faces[ 0 ].materialIndex = 1;
nxGeometry.faces[ 0 ].vertexColors = [ light, shadow, shadow, light ];
nxGeometry.applyMatrix( new THREE.Matrix4().makeRotationY( - Math.PI / 2 ) );
nxGeometry.applyMatrix( new THREE.Matrix4().makeTranslation( - 50, 0, 0 ) );
nxGeometry.applyMatrix( new THREE.Matrix4().makeTranslation(
new THREE.Vector3( - 50, 0, 0 ) ) );
var pyGeometry = new THREE.PlaneGeometry( 100, 100 );
pyGeometry.faces[ 0 ].materialIndex = 0;
pyGeometry.faces[ 0 ].vertexColors = [ light, light, light, light ];
pyGeometry.applyMatrix( new THREE.Matrix4().makeRotationX( - Math.PI / 2 ) );
pyGeometry.applyMatrix( new THREE.Matrix4().makeTranslation( 0, 50, 0 ) );
pyGeometry.applyMatrix( new THREE.Matrix4().makeTranslation(
new THREE.Vector3( 0, 50, 0 ) ) );
var pzGeometry = new THREE.PlaneGeometry( 100, 100 );
pzGeometry.faces[ 0 ].materialIndex = 1;
pzGeometry.faces[ 0 ].vertexColors = [ light, shadow, shadow, light ];
pzGeometry.applyMatrix( new THREE.Matrix4().makeTranslation( 0, 0, 50 ) );
pzGeometry.applyMatrix( new THREE.Matrix4().makeTranslation(
new THREE.Vector3( 0, 0, 50 ) ) );
var nzGeometry = new THREE.PlaneGeometry( 100, 100 );
nzGeometry.faces[ 0 ].materialIndex = 1;
nzGeometry.faces[ 0 ].vertexColors = [ light, shadow, shadow, light ];
nzGeometry.applyMatrix( new THREE.Matrix4().makeRotationY( Math.PI ) );
nzGeometry.applyMatrix( new THREE.Matrix4().makeTranslation( 0, 0, -50 ) );
nzGeometry.applyMatrix( new THREE.Matrix4().makeTranslation(
new THREE.Vector3( 0, 0, -50 ) ) );
//
......
......@@ -212,7 +212,7 @@
if ( params.scale ) {
geometry.applyMatrix( new THREE.Matrix4().makeScale( params.scale, params.scale, params.scale ) );
geometry.applyMatrix( new THREE.Matrix4().makeScale( new THREE.Vector3( params.scale, params.scale, params.scale ) ) );
}
......
......@@ -89,7 +89,7 @@
inverseMatrix.getInverse( object.matrixWorld );
localRay.copy( raycaster.ray ).transformSelf( inverseMatrix );
localRay.copy( raycaster.ray ).transform( inverseMatrix );
for ( var f = 0, fl = geometry.faces.length; f < fl; f ++ ) {
......
......@@ -383,7 +383,7 @@ THREE.GeometryUtils = {
offset.add( bb.min, bb.max );
offset.multiplyScalar( -0.5 );
geometry.applyMatrix( new THREE.Matrix4().makeTranslation( offset.x, offset.y, offset.z ) );
geometry.applyMatrix( new THREE.Matrix4().makeTranslation( offset ) );
geometry.computeBoundingBox();
return offset;
......
......@@ -237,15 +237,6 @@ THREE.Box2.prototype = {
},
scale: function ( factor ) {
var sizeDeltaHalf = this.size().multiplyScalar( ( factor - 1 ) * 0.5 );
this.expandByVector( sizeDeltaHalf );
return this;
},
equals: function ( box ) {
return box.min.equals( this.min ) && box.max.equals( this.max );
......
......@@ -244,19 +244,31 @@ THREE.Box3.prototype = {
},
translate: function ( offset ) {
this.min.addSelf( offset );
this.max.addSelf( offset );
transform: function ( matrix ) {
// NOTE: I am using a binary pattern to specify all 2^3 combinations below
var newPoints = [
matrix.multiplyVector3( THREE.Box3.__v0.set( this.min.x, this.min.y, this.min.z ) ), // 000
matrix.multiplyVector3( THREE.Box3.__v1.set( this.min.x, this.min.y, this.max.z ) ), // 001
matrix.multiplyVector3( THREE.Box3.__v2.set( this.min.x, this.max.y, this.min.z ) ), // 010
matrix.multiplyVector3( THREE.Box3.__v3.set( this.min.x, this.max.y, this.max.z ) ), // 011
matrix.multiplyVector3( THREE.Box3.__v4.set( this.max.x, this.min.y, this.min.z ) ), // 100
matrix.multiplyVector3( THREE.Box3.__v5.set( this.max.x, this.min.y, this.max.z ) ), // 101
matrix.multiplyVector3( THREE.Box3.__v6.set( this.max.x, this.max.y, this.min.z ) ), // 110
matrix.multiplyVector3( THREE.Box3.__v7.set( this.max.x, this.max.y, this.max.z ) ) // 111
];
this.makeEmpty();
this.setFromPoints( newPoints );
return this;
},
scale: function ( factor ) {
translate: function ( offset ) {
var sizeDeltaHalf = this.size().multiplyScalar( ( factor - 1 ) * 0.5 );
this.expandByVector( sizeDeltaHalf );
this.min.addSelf( offset );
this.max.addSelf( offset );
return this;
......@@ -276,4 +288,11 @@ THREE.Box3.prototype = {
};
THREE.Box3.__v0 = new THREE.Vector3();
THREE.Box3.__v1 = new THREE.Vector3();
THREE.Box3.__v2 = new THREE.Vector3();
THREE.Box3.__v3 = new THREE.Vector3();
THREE.Box3.__v4 = new THREE.Vector3();
THREE.Box3.__v5 = new THREE.Vector3();
THREE.Box3.__v6 = new THREE.Vector3();
THREE.Box3.__v7 = new THREE.Vector3();
......@@ -587,7 +587,7 @@ THREE.Matrix4.prototype = {
mRotation.identity();
mRotation.setRotationFromQuaternion( rotation );
mScale.makeScale( scale.x, scale.y, scale.z );
mScale.makeScale( scale );
this.multiply( mRotation, mScale );
......@@ -888,13 +888,13 @@ THREE.Matrix4.prototype = {
//
makeTranslation: function ( x, y, z ) {
makeTranslation: function ( offset ) {
this.set(
1, 0, 0, x,
0, 1, 0, y,
0, 0, 1, z,
1, 0, 0, offset.x,
0, 1, 0, offset.y,
0, 0, 1, offset.z,
0, 0, 0, 1
);
......@@ -977,13 +977,13 @@ THREE.Matrix4.prototype = {
},
makeScale: function ( x, y, z ) {
makeScale: function ( factor ) {
this.set(
x, 0, 0, 0,
0, y, 0, 0,
0, 0, z, 0,
factor.x, 0, 0, 0,
0, factor.y, 0, 0,
0, 0, factor.z, 0,
0, 0, 0, 1
);
......
......@@ -4,7 +4,7 @@
THREE.Plane = function ( normal, constant ) {
this.normal = normal !== undefined ? normal.clone() : new THREE.Vector3();
this.normal = normal !== undefined ? normal.clone() : new THREE.Vector3( 1, 0, 0 );
this.constant = constant !== undefined ? constant : 0;
};
......@@ -33,8 +33,8 @@ THREE.Plane.prototype = {
setFromNormalAndCoplanarPoint: function ( normal, point ) {
this.normal.copy( normal );
this.constant = - point.dot( normal );
this.normal.copy( normal ).normalize();
this.constant = - point.dot( this.normal ); // must be this.normal, not normal, as this.normal is normalized
return this;
......@@ -43,7 +43,7 @@ THREE.Plane.prototype = {
setFromCoplanarPoints: function ( a, b, c ) {
var normal = THREE.Plane.__v1.sub( c, b ).crossSelf(
THREE.Plane.__v2.sub( a, b ) );
THREE.Plane.__v2.sub( a, b ) ).normalize();
// Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
......@@ -119,9 +119,27 @@ THREE.Plane.prototype = {
},
transform: function( matrix, optionalNormalMatrix ) {
var newNormal = THREE.Plane.__v1, newCoplanarPoint = THREE.Plane.__v2;
// compute new normal based on theory here:
// http://www.songho.ca/opengl/gl_normaltransform.html
optionalNormalMatrix = optionalNormalMatrix || new THREE.Matrix3().getInverse( matrix ).transpose();
newNormal = optionalNormalMatrix.multiplyVector3( newNormal.copy( this.normal ) );
newCoplanarPoint = this.coplanarPoint( newCoplanarPoint );
newCoplanarPoint = matrix.multiplyVector3( newCoplanarPoint );
this.setFromNormalAndCoplanarPoint( newNormal, newCoplanarPoint );
return this;
},
translate: function ( offset ) {
this.constant = - offset.dot( this.normal );
this.constant = this.constant - offset.dot( this.normal );
return this;
......@@ -141,5 +159,6 @@ THREE.Plane.prototype = {
};
THREE.Plane.__vZero = new THREE.Vector3( 0, 0, 0 );
THREE.Plane.__v1 = new THREE.Vector3();
THREE.Plane.__v2 = new THREE.Vector3();
......@@ -131,7 +131,7 @@ THREE.Ray.prototype = {
},
transformSelf: function ( matrix4 ) {
transform: function ( matrix4 ) {
this.direction = matrix4.multiplyVector3( this.direction.addSelf( this.origin ) );
this.origin = matrix4.multiplyVector3( this.origin );
......
......@@ -96,17 +96,18 @@ THREE.Sphere.prototype = {
},
translate: function ( offset ) {
this.center.addSelf( this.offset );
transform: function ( matrix ) {
this.center = matrix.multiplyVector3( this.center );
this.radius = this.radius * matrix.getMaxScaleOnAxis();
return this;
},
scale: function ( factor ) {
translate: function ( offset ) {
this.radius *= factor;
this.center.addSelf( offset );
return this;
......@@ -120,7 +121,7 @@ THREE.Sphere.prototype = {
clone: function () {
return new THREE.Sphere3().copy( this );
return new THREE.Sphere().copy( this );
}
......
......@@ -242,16 +242,4 @@ test( "translate", function() {
ok( a.clone().translate( one2 ).translate( one2.clone().negate() ).equals( a ), "Passed!" );
ok( d.clone().translate( one2 ).equals( b ), "Passed!" );
ok( b.clone().translate( one2.clone().negate() ).equals( d ), "Passed!" );
});
test( "scale", function() {
var a = new THREE.Box2( zero2, zero2 );
var b = new THREE.Box2( zero2, one2 );
var c = new THREE.Box2( one2.clone().negate(), one2 );
var d = new THREE.Box2( one2.clone().negate(), zero2 );
ok( a.clone().scale( 0 ).equals( a ), "Passed!" );
ok( c.clone().scale( 0 ).equals( a ), "Passed!" );
ok( b.clone().scale( 3 ).equals( new THREE.Box2( new THREE.Vector2( -1, -1, -1 ), new THREE.Vector2( 2, 2, 2 ) ) ), "Passed!" );
ok( d.clone().scale( 3 ).equals( new THREE.Box2( new THREE.Vector2( 2, 2, 2 ).negate(), new THREE.Vector2( 1, 1, 1 ) ) ), "Passed!" );
});
});
\ No newline at end of file
......@@ -232,26 +232,36 @@ test( "union", function() {
ok( b.clone().union( c ).equals( c ), "Passed!" );
});
test( "translate", function() {
var compareBox = function ( a, b, threshold ) {
threshold = threshold || 0.0001;
return ( a.min.distanceTo( b.min ) < threshold &&
a.max.distanceTo( b.max ) < threshold );
};
test( "transform", function() {
var a = new THREE.Box3( zero3, zero3 );
var b = new THREE.Box3( zero3, one3 );
var c = new THREE.Box3( one3.clone().negate(), one3 );
var d = new THREE.Box3( one3.clone().negate(), zero3 );
ok( a.clone().translate( one3 ).equals( new THREE.Box3( one3, one3 ) ), "Passed!" );
ok( a.clone().translate( one3 ).translate( one3.clone().negate() ).equals( a ), "Passed!" );
ok( d.clone().translate( one3 ).equals( b ), "Passed!" );
ok( b.clone().translate( one3.clone().negate() ).equals( d ), "Passed!" );
var m = new THREE.Matrix4();
var t1 = new THREE.Vector3( 1, -2, 1 );
m.makeTranslation( t1 );
ok( compareBox( a.clone().transform( m ), a.clone().translate( t1 ) ), "Passed!" );
ok( compareBox( b.clone().transform( m ), b.clone().translate( t1 ) ), "Passed!" );
ok( compareBox( c.clone().transform( m ), c.clone().translate( t1 ) ), "Passed!" );
ok( compareBox( d.clone().transform( m ), d.clone().translate( t1 ) ), "Passed!" );
});
test( "scale", function() {
test( "translate", function() {
var a = new THREE.Box3( zero3, zero3 );
var b = new THREE.Box3( zero3, one3 );
var c = new THREE.Box3( one3.clone().negate(), one3 );
var d = new THREE.Box3( one3.clone().negate(), zero3 );
ok( a.clone().scale( 0 ).equals( a ), "Passed!" );
ok( c.clone().scale( 0 ).equals( a ), "Passed!" );
ok( b.clone().scale( 3 ).equals( new THREE.Box3( new THREE.Vector3( -1, -1, -1 ), new THREE.Vector3( 2, 2, 2 ) ) ), "Passed!" );
ok( d.clone().scale( 3 ).equals( new THREE.Box3( new THREE.Vector3( 2, 2, 2 ).negate(), new THREE.Vector3( 1, 1, 1 ) ) ), "Passed!" );
ok( a.clone().translate( one3 ).equals( new THREE.Box3( one3, one3 ) ), "Passed!" );
ok( a.clone().translate( one3 ).translate( one3.clone().negate() ).equals( a ), "Passed!" );
ok( d.clone().translate( one3 ).equals( b ), "Passed!" );
ok( b.clone().translate( one3.clone().negate() ).equals( d ), "Passed!" );
});
......@@ -4,9 +4,16 @@
module( "Plane" );
var comparePlane = function ( a, b, threshold ) {
threshold = threshold || 0.0001;
return ( a.normal.distanceTo( b.normal ) < threshold &&
Math.abs( a.constant - b.constant ) < threshold );
};
test( "constructor", function() {
var a = new THREE.Plane();
ok( a.normal.x == 0, "Passed!" );
ok( a.normal.x == 1, "Passed!" );
ok( a.normal.y == 0, "Passed!" );
ok( a.normal.z == 0, "Passed!" );
ok( a.constant == 0, "Passed!" );
......@@ -45,7 +52,7 @@ test( "copy", function() {
test( "set", function() {
var a = new THREE.Plane();
ok( a.normal.x == 0, "Passed!" );
ok( a.normal.x == 1, "Passed!" );
ok( a.normal.y == 0, "Passed!" );
ok( a.normal.z == 0, "Passed!" );
ok( a.constant == 0, "Passed!" );
......@@ -59,7 +66,7 @@ test( "set", function() {
test( "setComponents", function() {
var a = new THREE.Plane();
ok( a.normal.x == 0, "Passed!" );
ok( a.normal.x == 1, "Passed!" );
ok( a.normal.y == 0, "Passed!" );
ok( a.normal.z == 0, "Passed!" );
ok( a.constant == 0, "Passed!" );
......@@ -74,7 +81,7 @@ test( "setComponents", function() {
test( "setFromNormalAndCoplanarPoint", function() {
var a = new THREE.Plane().setFromNormalAndCoplanarPoint( one3, zero3 );
ok( a.normal.equals( one3 ), "Passed!" );
ok( a.normal.equals( one3.clone().normalize() ), "Passed!" );
ok( a.constant == 0, "Passed!" );
});
......@@ -86,3 +93,72 @@ test( "normalize", function() {
ok( a.normal.equals( new THREE.Vector3( 1, 0, 0 ) ), "Passed!" );
ok( a.constant == 1, "Passed!" );
});
test( "distanceToPoint", function() {
var a = new THREE.Plane( new THREE.Vector3( 2, 0, 0 ), -2 );
a.normalize();
ok( a.distanceToPoint( a.projectPoint( zero3.clone() ) ) === 0, "Passed!" );
ok( a.distanceToPoint( new THREE.Vector3( 4, 0, 0 ) ) === 3, "Passed!" );
});
test( "distanceToSphere", function() {
var a = new THREE.Plane( new THREE.Vector3( 1, 0, 0 ), 0 );
var b = new THREE.Sphere( new THREE.Vector3( 2, 0, 0 ), 1 );
ok( a.distanceToSphere( b ) === 1, "Passed!" );
a.set( new THREE.Vector3( 1, 0, 0 ), 2 );
ok( a.distanceToSphere( b ) === 3, "Passed!" );
a.set( new THREE.Vector3( 1, 0, 0 ), -2 );
ok( a.distanceToSphere( b ) === -1, "Passed!" );
});
test( "projectPoint", function() {
var a = new THREE.Plane( new THREE.Vector3( 1, 0, 0 ), 0 );
ok( a.projectPoint( new THREE.Vector3( 10, 0, 0 ) ).equals( zero3 ), "Passed!" );
ok( a.projectPoint( new THREE.Vector3( -10, 0, 0 ) ).equals( zero3 ), "Passed!" );
a = new THREE.Plane( new THREE.Vector3( 0, 1, 0 ), -1 );
ok( a.projectPoint( new THREE.Vector3( 0, 0, 0 ) ).equals( new THREE.Vector3( 0, 1, 0 ) ), "Passed!" );
ok( a.projectPoint( new THREE.Vector3( 0, 1, 0 ) ).equals( new THREE.Vector3( 0, 1, 0 ) ), "Passed!" );
});
test( "orthoPoint", function() {
var a = new THREE.Plane( new THREE.Vector3( 1, 0, 0 ), 0 );
ok( a.orthoPoint( new THREE.Vector3( 10, 0, 0 ) ).equals( new THREE.Vector3( 10, 0, 0 ) ), "Passed!" );
ok( a.orthoPoint( new THREE.Vector3( -10, 0, 0 ) ).equals( new THREE.Vector3( -10, 0, 0 ) ), "Passed!" );
});
/*
test( "isIntersectionLine", function() {
});
*/
test( "coplanarPoint", function() {
var a = new THREE.Plane( new THREE.Vector3( 1, 0, 0 ), 0 );
ok( a.distanceToPoint( a.coplanarPoint() ) === 0, "Passed!" );
a = new THREE.Plane( new THREE.Vector3( 0, 1, 0 ), -1 );
ok( a.distanceToPoint( a.coplanarPoint() ) === 0, "Passed!" );
});
test( "transform/translate", function() {
var a = new THREE.Plane( new THREE.Vector3( 1, 0, 0 ), 0 );
var m = new THREE.Matrix4();
m.makeRotationZ( Math.PI * 0.5 );
ok( comparePlane( a.clone().transform( m ), new THREE.Plane( new THREE.Vector3( 0, 1, 0 ), 0 ) ), "Passed!" );
a = new THREE.Plane( new THREE.Vector3( 0, 1, 0 ), -1 );
ok( comparePlane( a.clone().transform( m ), new THREE.Plane( new THREE.Vector3( -1, 0, 0 ), -1 ) ), "Passed!" );
m.makeTranslation( new THREE.Vector3( 1, 1, 1 ) );
ok( comparePlane( a.clone().transform( m ), a.clone().translate( new THREE.Vector3( 1, 1, 1 ) ) ), "Passed!" );
});
\ No newline at end of file
......@@ -149,26 +149,26 @@ test( "intersectPlane", function() {
});
test( "transformSelf", function() {
test( "transform", function() {
var a = new THREE.Ray( one3, new THREE.Vector3( 0, 0, 1 ) );
var m = new THREE.Matrix4().identity();
ok( a.clone().transformSelf( m ).equals( a ), "Passed!" );
ok( a.clone().transform( m ).equals( a ), "Passed!" );
a = new THREE.Ray( zero3, new THREE.Vector3( 0, 0, 1 ) );
m.rotateByAxis( new THREE.Vector3( 0, 0, 1 ), Math.PI );
ok( a.clone().transformSelf( m ).equals( a ), "Passed!" );
ok( a.clone().transform( m ).equals( a ), "Passed!" );
m.identity().rotateX( Math.PI );
var b = a.clone();
b.direction.negate();
var a2 = a.clone().transformSelf( m );
var a2 = a.clone().transform( m );
ok( a2.origin.distanceTo( b.origin ) < 0.0001, "Passed!" );
ok( a2.direction.distanceTo( b.direction ) < 0.0001, "Passed!" );
a.origin = new THREE.Vector3( 0, 0, 1 );
b.origin = new THREE.Vector3( 0, 0, -1 );
var a2 = a.clone().transformSelf( m );
var a2 = a.clone().transform( m );
ok( a2.origin.distanceTo( b.origin ) < 0.0001, "Passed!" );
ok( a2.direction.distanceTo( b.direction ) < 0.0001, "Passed!" );
});
......
......@@ -37,3 +37,58 @@ test( "set", function() {
ok( a.center.equals( one3 ), "Passed!" );
ok( a.radius == 1, "Passed!" );
});
test( "empty", function() {
var a = new THREE.Sphere();
ok( a.empty(), "Passed!" );
a.set( one3, 1 );
ok( ! a.empty(), "Passed!" );
});
test( "containsPoint", function() {
var a = new THREE.Sphere( one3, 1 );
ok( ! a.containsPoint( zero3 ), "Passed!" );
ok( a.containsPoint( one3 ), "Passed!" );
});
test( "distanceToPoint", function() {
var a = new THREE.Sphere( one3, 1 );
ok( ( a.distanceToPoint( zero3 ) - 0.7320 ) < 0.001, "Passed!" );
ok( a.distanceToPoint( one3 ) === -1, "Passed!" );
});
test( "clampPoint", function() {
var a = new THREE.Sphere( one3, 1 );
ok( a.clampPoint( new THREE.Vector3( 1, 1, 3 ) ).equals( new THREE.Vector3( 1, 1, 2 ) ), "Passed!" );
ok( a.clampPoint( new THREE.Vector3( 1, 1, -3 ) ).equals( new THREE.Vector3( 1, 1, 0 ) ), "Passed!" );
});
test( "bounds", function() {
var a = new THREE.Sphere( one3, 1 );
ok( a.bounds().equals( new THREE.Box3( zero3, two3 ) ), "Passed!" );
a.set( zero3, 0 )
ok( a.bounds().equals( new THREE.Box3( zero3, zero3 ) ), "Passed!" );
});
test( "transform", function() {
var a = new THREE.Sphere( one3, 1 );
var m = new THREE.Matrix4();
var t1 = new THREE.Vector3( 1, -2, 1 );
m.makeTranslation( t1 );
ok( a.clone().transform( m ).bounds().equals( a.bounds().transform( m ) ), "Passed!" );
});
test( "translate", function() {
var a = new THREE.Sphere( one3, 1 );
a.translate( one3.clone().negate() );
ok( a.center.equals( zero3 ), "Passed!" );
});
......@@ -26,16 +26,16 @@
<!-- add class-based unit tests below -->
<script src="core/Constants.js"></script>
<script src="core/Box2.js"></script>
<script src="core/Box3.js"></script>
<script src="core/Plane.js"></script>
<script src="core/Ray.js"></script>
<script src="core/Sphere.js"></script>
<script src="core/Triangle.js"></script>
<script src="core/Vector2.js"></script>
<script src="core/Vector3.js"></script>
<script src="core/Vector4.js"></script>
<script src="math/Constants.js"></script>
<script src="math/Box2.js"></script>
<script src="math/Box3.js"></script>
<script src="math/Plane.js"></script>
<script src="math/Ray.js"></script>
<script src="math/Sphere.js"></script>
<script src="math/Triangle.js"></script>
<script src="math/Vector2.js"></script>
<script src="math/Vector3.js"></script>
<script src="math/Vector4.js"></script>
</body>
</html>
\ No newline at end of file
......@@ -15,16 +15,16 @@
<!-- add class-based unit tests below -->
<script src="core/Constants.js"></script>
<script src="core/Box2.js"></script>
<script src="core/Box3.js"></script>
<script src="core/Plane.js"></script>
<script src="core/Ray.js"></script>
<script src="core/Sphere.js"></script>
<script src="core/Triangle.js"></script>
<script src="core/Vector2.js"></script>
<script src="core/Vector3.js"></script>
<script src="core/Vector4.js"></script>
<script src="math/Constants.js"></script>
<script src="math/Box2.js"></script>
<script src="math/Box3.js"></script>
<script src="math/Plane.js"></script>
<script src="math/Ray.js"></script>
<script src="math/Sphere.js"></script>
<script src="math/Triangle.js"></script>
<script src="math/Vector2.js"></script>
<script src="math/Vector3.js"></script>
<script src="math/Vector4.js"></script>
</body>
</html>
......@@ -15,16 +15,16 @@
<!-- add class-based unit tests below -->
<script src="core/Constants.js"></script>
<script src="core/Box2.js"></script>
<script src="core/Box3.js"></script>
<script src="core/Plane.js"></script>
<script src="core/Ray.js"></script>
<script src="core/Sphere.js"></script>
<script src="core/Triangle.js"></script>
<script src="core/Vector2.js"></script>
<script src="core/Vector3.js"></script>
<script src="core/Vector4.js"></script>
<script src="math/Constants.js"></script>
<script src="math/Box2.js"></script>
<script src="math/Box3.js"></script>
<script src="math/Plane.js"></script>
<script src="math/Ray.js"></script>
<script src="math/Sphere.js"></script>
<script src="math/Triangle.js"></script>
<script src="math/Vector2.js"></script>
<script src="math/Vector3.js"></script>
<script src="math/Vector4.js"></script>
</body>
</html>
......@@ -15,16 +15,16 @@
<!-- add class-based unit tests below -->
<script src="core/Constants.js"></script>
<script src="core/Box2.js"></script>
<script src="core/Box3.js"></script>
<script src="core/Plane.js"></script>
<script src="core/Ray.js"></script>
<script src="core/Sphere.js"></script>
<script src="core/Triangle.js"></script>
<script src="core/Vector2.js"></script>
<script src="core/Vector3.js"></script>
<script src="core/Vector4.js"></script>
<script src="math/Constants.js"></script>
<script src="math/Box2.js"></script>
<script src="math/Box3.js"></script>
<script src="math/Plane.js"></script>
<script src="math/Ray.js"></script>
<script src="math/Sphere.js"></script>
<script src="math/Triangle.js"></script>
<script src="math/Vector2.js"></script>
<script src="math/Vector3.js"></script>
<script src="math/Vector4.js"></script>
</body>
</html>
......@@ -4,4 +4,5 @@ python build.py --include canvas --minify --output ../build/three-canvas.min.js
python build.py --include css3d --minify --output ../build/three-css3d.min.js
python build.py --include webgl --minify --output ../build/three-webgl.min.js
python build.py --include extras --externs externs/extras.js --minify --output ../build/three-extras.min.js
python build.py --include math --output ../build/three-math.js
python build.py --include math --minify --output ../build/three-math.min.js
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册