Explorar o código

Matrix4.makeTranslation and Matrix4.makeScale now take Vector3 instead of thee scalars per #2780

Ben Houston %!s(int64=12) %!d(string=hai) anos
pai
achega
26b57b81be

+ 1 - 1
examples/css3d_molecules.html

@@ -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 ++ ) {
 

+ 10 - 5
examples/webgl_geometry_minecraft.html

@@ -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 ) ) );
 
 				//
 

+ 10 - 5
examples/webgl_geometry_minecraft_ao.html

@@ -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 ) ) );
 
 				//
 

+ 1 - 1
examples/webgl_geometry_subdivision.html

@@ -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 ) ) );
 
 				}
 

+ 1 - 1
src/extras/GeometryUtils.js

@@ -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;

+ 9 - 9
src/math/Matrix4.js

@@ -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
 
 		);

+ 1 - 1
test/math/Box3.js

@@ -247,7 +247,7 @@ test( "transform", function() {
 	var m = new THREE.Matrix4();
 
 	var t1 = new THREE.Vector3( 1, -2, 1 );
-	m.makeTranslation( t1.x, t1.y, t1.z );
+	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!" );

+ 1 - 1
test/math/Plane.js

@@ -159,6 +159,6 @@ test( "transform/translate", function() {
 	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( 1, 1, 1 );
+	m.makeTranslation( new THREE.Vector3( 1, 1, 1 ) );
 	ok( comparePlane( a.clone().transform( m ), a.clone().translate( new THREE.Vector3( 1, 1, 1 ) ) ), "Passed!" );
 });

+ 1 - 1
test/math/Sphere.js

@@ -81,7 +81,7 @@ test( "transform", function() {
 
 	var m = new THREE.Matrix4();
 	var t1 = new THREE.Vector3( 1, -2, 1 );
-	m.makeTranslation( t1.x, t1.y, t1.z );
+	m.makeTranslation( t1 );
 
 	ok( a.clone().transform( m ).bounds().equals( a.bounds().transform( m ) ), "Passed!" );
 });

+ 1 - 0
utils/build_all.bat

@@ -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