Browse Source

fix three missed conversions to closures. switch to extending math prototypes rather than replacing them. This is to ensure that types created in closures within a type's prototype definition get their prototype updated with the full definition.

Ben Houston 12 years ago
parent
commit
e2df06e005

+ 22 - 0
src/Three.js

@@ -46,6 +46,28 @@ String.prototype.trim = String.prototype.trim || function () {
 };
 
 
+THREE.extend = function ( target, other ) {
+
+	target = target || {};
+
+	for (var prop in other) {
+
+		if ( typeof other[prop] === 'object' ) {
+
+			target[prop] = THREE.extend( target[prop], other[prop] );
+
+		} else {
+
+			target[prop] = other[prop];
+
+		}
+
+	}
+
+	return target;
+	
+};
+
 // http://paulirish.com/2011/requestanimationframe-for-smart-animating/
 // http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
 

+ 2 - 2
src/math/Box2.js

@@ -9,7 +9,7 @@ THREE.Box2 = function ( min, max ) {
 
 };
 
-THREE.Box2.prototype = {
+THREE.extend( THREE.Box2.prototype, {
 
 	constructor: THREE.Box2,
 
@@ -259,4 +259,4 @@ THREE.Box2.prototype = {
 
 	}
 
-};
+} );

+ 2 - 2
src/math/Box3.js

@@ -9,7 +9,7 @@ THREE.Box3 = function ( min, max ) {
 
 };
 
-THREE.Box3.prototype = {
+THREE.extend( THREE.Box3.prototype, {
 
 	constructor: THREE.Box3,
 
@@ -328,4 +328,4 @@ THREE.Box3.prototype = {
 
 	}
 
-};
+} );

+ 2 - 2
src/math/Color.js

@@ -10,7 +10,7 @@ THREE.Color = function ( value ) {
 
 };
 
-THREE.Color.prototype = {
+THREE.extend( THREE.Color.prototype, {
 
 	constructor: THREE.Color,
 
@@ -390,7 +390,7 @@ THREE.Color.prototype = {
 
 	}
 
-};
+} );
 
 THREE.ColorKeywords = { "aliceblue": 0xF0F8FF, "antiquewhite": 0xFAEBD7, "aqua": 0x00FFFF, "aquamarine": 0x7FFFD4, "azure": 0xF0FFFF,
 "beige": 0xF5F5DC, "bisque": 0xFFE4C4, "black": 0x000000, "blanchedalmond": 0xFFEBCD, "blue": 0x0000FF, "blueviolet": 0x8A2BE2,

+ 2 - 2
src/math/Frustum.js

@@ -19,7 +19,7 @@ THREE.Frustum = function ( p0, p1, p2, p3, p4, p5 ) {
 
 };
 
-THREE.Frustum.prototype = {
+THREE.extend( THREE.Frustum.prototype, {
 
 	set: function ( p0, p1, p2, p3, p4, p5 ) {
 
@@ -140,4 +140,4 @@ THREE.Frustum.prototype = {
 
 	}
 
-};
+} );

+ 18 - 9
src/math/Math.js

@@ -67,19 +67,28 @@ THREE.Math = {
 
 	},
 
-	degToRad: function ( degrees ) {
+	degToRad: function() {
 
-		return degrees * THREE.Math.__d2r;
+		var degreeToRadiansFactor = Math.PI / 180;
 
-	},
+		return function ( degrees ) {
+
+			return degrees * degreeToRadiansFactor;
+
+		};
+
+	}(),
+
+	radToDeg: function() {
+		
+		var radianToDegreesFactor = 180 / Math.PI;
 
-	radToDeg: function ( radians ) {
+		return function ( radians ) {
 
-		return radians * THREE.Math.__r2d;
+			return radians * radianToDegreesFactor;
 
-	}
+		};
 
-};
+	}()
 
-THREE.Math.__d2r =  Math.PI / 180;
-THREE.Math.__r2d =  180 / Math.PI;
+};

+ 2 - 2
src/math/Matrix3.js

@@ -17,7 +17,7 @@ THREE.Matrix3 = function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
 	);
 };
 
-THREE.Matrix3.prototype = {
+THREE.extend( THREE.Matrix3.prototype, {
 
 	constructor: THREE.Matrix3,
 
@@ -214,4 +214,4 @@ THREE.Matrix3.prototype = {
 
 	}
 
-};
+} );

+ 5 - 6
src/math/Matrix4.js

@@ -25,7 +25,7 @@ THREE.Matrix4 = function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33
 
 };
 
-THREE.Matrix4.prototype = {
+THREE.extend( THREE.Matrix4.prototype, {
 
 	constructor: THREE.Matrix4,
 
@@ -657,7 +657,8 @@ THREE.Matrix4.prototype = {
 
 		var x = new THREE.Vector3(),
 			y = new THREE.Vector3(),
-			z = new THREE.Vector3();
+			z = new THREE.Vector3(),
+			matrix = new THREE.Matrix4();
 		
 		return function ( translation, rotation, scale ) {
 
@@ -681,9 +682,7 @@ THREE.Matrix4.prototype = {
 			translation.z = te[14];
 
 			// scale the rotation part
-
-			var matrix = THREE.Matrix4.__m1;
-
+		
 			matrix.copy( this );
 
 			matrix.elements[0] /= scale.x;
@@ -1116,4 +1115,4 @@ THREE.Matrix4.prototype = {
 
 	}
 
-};
+} );

+ 2 - 2
src/math/Plane.js

@@ -9,7 +9,7 @@ THREE.Plane = function ( normal, constant ) {
 
 };
 
-THREE.Plane.prototype = {
+THREE.extend( THREE.Plane.prototype, {
 
 	constructor: THREE.Plane,
 
@@ -219,4 +219,4 @@ THREE.Plane.prototype = {
 
 	}
 
-};
+} );

+ 2 - 2
src/math/Quaternion.js

@@ -14,7 +14,7 @@ THREE.Quaternion = function( x, y, z, w ) {
 
 };
 
-THREE.Quaternion.prototype = {
+THREE.extend( THREE.Quaternion.prototype, {
 
 	constructor: THREE.Quaternion,
 
@@ -339,7 +339,7 @@ THREE.Quaternion.prototype = {
 
 	}
 
-}
+} );
 
 THREE.Quaternion.slerp = function ( qa, qb, qm, t ) {
 

+ 12 - 6
src/math/Ray.js

@@ -9,7 +9,7 @@ THREE.Ray = function ( origin, direction ) {
 
 };
 
-THREE.Ray.prototype = {
+THREE.extend( THREE.Ray.prototype, {
 
 	constructor: THREE.Ray,
 
@@ -39,13 +39,19 @@ THREE.Ray.prototype = {
 
 	},
 
-	recast: function ( t ) {
+	recast: function() {
 
-		this.origin.copy( this.at( t, THREE.Ray.__v1 ) );
+		var v1 = new THREE.Vector3();
 
-		return this;
+		return function ( t ) {
 
-	},
+			this.origin.copy( this.at( t, v1 ) );
+
+			return this;
+
+		};
+
+	}(),
 
 	closestPointToPoint: function ( point, optionalTarget ) {
 
@@ -157,4 +163,4 @@ THREE.Ray.prototype = {
 
 	}
 
-};
+} );

+ 2 - 2
src/math/Sphere.js

@@ -10,7 +10,7 @@ THREE.Sphere = function ( center, radius ) {
 
 };
 
-THREE.Sphere.prototype = {
+THREE.extend( THREE.Sphere.prototype, {
 
 	constructor: THREE.Sphere,
 
@@ -133,4 +133,4 @@ THREE.Sphere.prototype = {
 
 	}
 
-};
+} );

+ 2 - 2
src/math/Triangle.js

@@ -92,7 +92,7 @@ THREE.Triangle.containsPoint = function() {
 
 }();
 
-THREE.Triangle.prototype = {
+THREE.extend( THREE.Triangle.prototype, {
 
 	constructor: THREE.Triangle,
 
@@ -187,4 +187,4 @@ THREE.Triangle.prototype = {
 
 	}
 
-};
+} );

+ 2 - 2
src/math/Vector2.js

@@ -12,7 +12,7 @@ THREE.Vector2 = function ( x, y ) {
 
 };
 
-THREE.Vector2.prototype = {
+THREE.extend( THREE.Vector2.prototype, {
 
 	constructor: THREE.Vector2,
 
@@ -301,4 +301,4 @@ THREE.Vector2.prototype = {
 
 	}
 
-};
+} );

+ 2 - 4
src/math/Vector3.js

@@ -15,8 +15,7 @@ THREE.Vector3 = function ( x, y, z ) {
 
 };
 
-
-THREE.Vector3.prototype = {
+THREE.extend( THREE.Vector3.prototype, {
 
 	constructor: THREE.Vector3,
 
@@ -741,5 +740,4 @@ THREE.Vector3.prototype = {
 
 	}
 
-};
-
+} );

+ 2 - 2
src/math/Vector4.js

@@ -15,7 +15,7 @@ THREE.Vector4 = function ( x, y, z, w ) {
 
 };
 
-THREE.Vector4.prototype = {
+THREE.extend( THREE.Vector4.prototype, {
 
 	constructor: THREE.Vector4,
 
@@ -553,4 +553,4 @@ THREE.Vector4.prototype = {
 
 	}
 
-};
+} );