Browse Source

Merge remote-tracking branch 'upstream/dev'

zz85 14 years ago
parent
commit
85c063dedd

+ 3 - 2
examples/canvas_geometry_cube.html

@@ -53,11 +53,12 @@
 				info.innerHTML = 'Drag to spin the cube';
 				container.appendChild( info );
 
+				scene = new THREE.Scene();
+
 				camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 1000 );
 				camera.position.y = 150;
 				camera.position.z = 500;
-
-				scene = new THREE.Scene();
+				scene.add( camera );
 
 				// Cube
 

+ 4 - 3
examples/canvas_geometry_hierarchy.html

@@ -44,10 +44,12 @@
 				container = document.createElement( 'div' );
 				document.body.appendChild( container );
 
+				scene = new THREE.Scene();
+
 				camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 10000 );
 				camera.position.z = 500;
-
-				scene = new THREE.Scene();
+				camera.target = new THREE.Vector3();
+				scene.add( camera );
 
 				var geometry = new THREE.CubeGeometry( 100, 100, 100 );
 				var material = new THREE.MeshNormalMaterial();
@@ -65,7 +67,6 @@
 					mesh.rotation.y = Math.random() * 360 * ( Math.PI / 180 );
 					mesh.matrixAutoUpdate = false;
 					mesh.updateMatrix();
-
 					group.add( mesh );
 
 				}

+ 1 - 1
examples/canvas_interactive_particles.html

@@ -133,7 +133,7 @@
 
 				// find intersections
 
-				camera.update();
+				camera.updateMatrixWorld();
 
 				var vector = new THREE.Vector3( mouse.x, mouse.y, 0.5 );
 				projector.unprojectVector( vector, camera );

+ 37 - 48
examples/canvas_materials_depth.html

@@ -26,7 +26,7 @@
 
 			var camera, scene, renderer;
 
-			var cube, plane, target = new THREE.Vector3();
+			var cube, plane, objects = [];
 
 			var targetRotation = 0;
 			var targetRotationOnMouseDown = 0;
@@ -37,19 +37,15 @@
 			var windowHalfX = window.innerWidth / 2;
 			var windowHalfY = window.innerHeight / 2;
 
-			var moveForward = false,
-			moveBackwards = false,
-			moveUp = false,
-			moveDown = false,
-			moveLeft = false,
-			moveRight = false,
+			var moveForward = false;
+			var moveBackwards = false;
+			var moveLeft = false;
+			var moveRight = false;
+			var moveUp = false;
+			var moveDown = false;
 
-			yawLeft = false,
-			yawRight = false,
-			pitchUp = false,
-			pitchDown = false,
-			rollLeft = false,
-			rollRight = false;
+			var targetMoveLeft = false;
+			var targetMoveRight = false;
 
 			var debugContext;
 
@@ -65,6 +61,7 @@
 				camera.position.x = 1000;
 				camera.position.y = 1000;
 				camera.position.z = 1000;
+				camera.target = new THREE.Vector3( 0, 150, 0 );
 
 				scene = new THREE.Scene();
 
@@ -86,7 +83,7 @@
 				geometry = new THREE.CubeGeometry( 100, 100, 100 );
 				material = new THREE.MeshDepthMaterial( { near: 1, far: 2000 } );
 
-				for (var i = 0; i < 20; i ++ ) {
+				for ( var i = 0; i < 20; i ++ ) {
 
 					cube = new THREE.Mesh( geometry, material );
 					cube.overdraw = true;
@@ -98,7 +95,9 @@
 					cube.rotation.y = Math.random() * 200 - 100;
 					cube.rotation.z = Math.random() * 200 - 100;
 
-					scene.add(cube);
+					scene.add( cube );
+
+					objects.push( cube );
 
 				}
 
@@ -146,18 +145,16 @@
 
 			function onDocumentKeyDown( event ) {
 
-				switch( event.keyCode ) {
+				switch ( event.keyCode ) {
 
 					case 38: moveForward = true; break; // up
 					case 40: moveBackwards = true; break; // down
 					case 37: moveLeft = true; break; // left
 					case 39: moveRight = true; break; // right
-					case 65: yawLeft = true; break; // a
-					case 68: yawRight = true; break; // d
-					case 87: moveUp/*pitchUp*/ = true; break; // w
-					case 83: moveDown/*pitchDown*/ = true; break; // s
-					case 90: rollLeft = true; break; // z
-					case 67: rollRight = true; break; // c
+					case 87: moveUp = true; break; // w
+					case 83: moveDown = true; break; // s
+					case 65: targetMoveLeft = true; break; // a
+					case 68: targetMoveRight = true; break; // d
 
 				}
 
@@ -165,18 +162,16 @@
 
 			function onDocumentKeyUp( event ) {
 
-				switch( event.keyCode ) {
+				switch ( event.keyCode ) {
 
 					case 38: moveForward = false; break; // up
 					case 40: moveBackwards = false; break; // down
 					case 37: moveLeft = false; break; // left
 					case 39: moveRight = false; break; // right
-					case 65: yawLeft = false; break; // a
-					case 68: yawRight = false; break; // d
-					case 87: moveUp/*pitchUp*/ = false; break; // w
-					case 83: moveDown/*pitchDown*/ = false; break; // s
-					case 90: rollLeft = false; break; // z
-					case 67: rollRight = false; break; // c
+					case 87: moveUp = false; break; // w
+					case 83: moveDown = false; break; // s
+					case 65: targetMoveLeft = false; break; // a
+					case 68: targetMoveRight = false; break; // d
 
 				}
 
@@ -195,25 +190,19 @@
 
 			function render() {
 
-				if ( moveForward ) camera.position.z -= 10; // camera.moveZ( 10 );
-				if ( moveBackwards ) camera.position.z += 10; // camera.moveZ( - 10 );
-
-				if ( moveUp ) camera.position.y += 10; // camera.moveZ( 10 );
-				if ( moveDown ) camera.position.y -= 10; // camera.moveZ( - 10 );
-
-				if ( moveLeft ) camera.position.x -= 10; // camera.moveX( - 10 );
-				if ( moveRight ) camera.position.x += 10; // camera.moveX( 10 );
+				if ( moveForward ) camera.position.z -= 10;
+				if ( moveBackwards ) camera.position.z += 10;
 
-				if ( pitchUp ) camera.rotation.x += 0.01; // camera.rotateX( 1 );
-				if ( pitchDown ) camera.rotation.x -= 0.01; // camera.rotateX( - 1 );
+				if ( moveLeft ) camera.position.x -= 10;
+				if ( moveRight ) camera.position.x += 10;
 
-				if ( yawLeft ) target.x -= 10; // camera.rotation.y += 0.01; // camera.rotateY( 1 );
-				if ( yawRight ) target.x += 10; // camera.rotation.y -= 0.01; // camera.rotateY( - 1 );
+				if ( moveUp ) camera.position.y += 10;
+				if ( moveDown ) camera.position.y -= 10;
 
-				if ( rollLeft ) camera.rotation.z += 0.01; // camera.rotateZ( 1 );
-				if ( rollRight ) camera.rotation.z -= 0.01; // camera.rotateZ( - 1 );
+				if ( targetMoveLeft ) camera.target.x -= 10;
+				if ( targetMoveRight ) camera.target.x += 10;
 
-				camera.lookAt( target );
+				camera.lookAt( camera.target );
 
 				debugContext.clearRect( - 256, - 256, 512, 512 );
 
@@ -228,14 +217,14 @@
 				// camera
 
 				debugContext.moveTo( camera.position.x * 0.1, camera.position.z * 0.1 );
-				debugContext.lineTo( target.x * 0.1, target.z * 0.1 );
+				debugContext.lineTo( camera.target.x * 0.1, camera.target.z * 0.1 );
 				debugContext.rect( camera.position.x * 0.1 - 5, camera.position.z * 0.1 - 5, 10, 10 );
-				debugContext.rect( target.x * 0.1 - 5, target.z * 0.1 - 5, 10, 10 );
+				debugContext.rect( camera.target.x * 0.1 - 5, camera.target.z * 0.1 - 5, 10, 10 );
 				debugContext.rect( - 50, - 50, 100, 100 );
 
-				for ( var i = 1; i < scene.objects.length; i++ ) {
+				for ( var i = 0; i < objects.length; i++ ) {
 
-					var object = scene.objects[i];
+					var object = objects[ i ];
 
 					object.rotation.x += 0.01;
 					object.rotation.y += 0.005;

+ 30 - 39
examples/canvas_sandbox.html

@@ -38,15 +38,15 @@
 			var windowHalfX = window.innerWidth / 2;
 			var windowHalfY = window.innerHeight / 2;
 
-			var moveForward = false, moveBackwards = false,
-			moveUp = false, moveDown = false,
-			moveLeft = false, moveRight = false,
+			var moveForward = false;
+			var moveBackwards = false;
+			var moveLeft = false;
+			var moveRight = false;
+			var moveUp = false;
+			var moveDown = false;
 
-			yawLeft = false, yawRight = false,
-			pitchUp = false, pitchDown = false,
-			rollLeft = false, rollRight = false;
-
-			var target = new THREE.Vector3( 0, 150, 0 );
+			var targetMoveLeft = false;
+			var targetMoveRight = false;
 
 			var debugContext;
 
@@ -61,6 +61,7 @@
 				camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 10000 );
 				camera.position.y = 150;
 				camera.position.z = 400;
+				camera.target = new THREE.Vector3( 0, 150, 0 );
 
 				scene = new THREE.Scene();
 
@@ -157,18 +158,16 @@
 
 			function onDocumentKeyDown( event ) {
 
-				switch( event.keyCode ) {
+				switch ( event.keyCode ) {
 
 					case 38: moveForward = true; break; // up
 					case 40: moveBackwards = true; break; // down
 					case 37: moveLeft = true; break; // left
 					case 39: moveRight = true; break; // right
-					case 65: yawLeft = true; break; // a
-					case 68: yawRight = true; break; // d
-					case 87: moveUp/*pitchUp*/ = true; break; // w
-					case 83: moveDown/*pitchDown*/ = true; break; // s
-					case 90: rollLeft = true; break; // z
-					case 67: rollRight = true; break; // c
+					case 87: moveUp = true; break; // w
+					case 83: moveDown = true; break; // s
+					case 65: targetMoveLeft = true; break; // a
+					case 68: targetMoveRight = true; break; // d
 
 				}
 
@@ -176,18 +175,16 @@
 
 			function onDocumentKeyUp( event ) {
 
-				switch( event.keyCode ) {
+				switch ( event.keyCode ) {
 
 					case 38: moveForward = false; break; // up
 					case 40: moveBackwards = false; break; // down
 					case 37: moveLeft = false; break; // left
 					case 39: moveRight = false; break; // right
-					case 65: yawLeft = false; break; // a
-					case 68: yawRight = false; break; // d
-					case 87: moveUp/*pitchUp*/ = false; break; // w
-					case 83: moveDown/*pitchDown*/ = false; break; // s
-					case 90: rollLeft = false; break; // z
-					case 67: rollRight = false; break; // c
+					case 87: moveUp = false; break; // w
+					case 83: moveDown = false; break; // s
+					case 65: targetMoveLeft = false; break; // a
+					case 68: targetMoveRight = false; break; // d
 
 				}
 
@@ -206,25 +203,19 @@
 
 			function render() {
 
-				if ( moveForward ) camera.position.z -= 5;
-				if ( moveBackwards ) camera.position.z += 5;
-
-				if ( moveUp ) camera.position.y += 5;
-				if ( moveDown ) camera.position.y -= 5;
-
-				if ( moveLeft ) camera.position.x -= 5;
-				if ( moveRight ) camera.position.x += 5;
+				if ( moveForward ) camera.position.z -= 10;
+				if ( moveBackwards ) camera.position.z += 10;
 
-				if ( pitchUp ) camera.rotation.x += 0.01;
-				if ( pitchDown ) camera.rotation.x -= 0.01;
+				if ( moveLeft ) camera.position.x -= 10;
+				if ( moveRight ) camera.position.x += 10;
 
-				if ( yawLeft ) target.x -= 5;
-				if ( yawRight ) target.x += 5;
+				if ( moveUp ) camera.position.y += 10;
+				if ( moveDown ) camera.position.y -= 10;
 
-				if ( rollLeft ) camera.rotation.z += 0.01;
-				if ( rollRight ) camera.rotation.z -= 0.01;
+				if ( targetMoveLeft ) camera.target.x -= 10;
+				if ( targetMoveRight ) camera.target.x += 10;
 
-				camera.lookAt( target );
+				camera.lookAt( camera.target );
 
 				debugContext.clearRect( -256, -256, 512, 512 );
 
@@ -239,9 +230,9 @@
 				// camera
 
 				debugContext.moveTo( camera.position.x * 0.1, camera.position.z * 0.1 );
-				debugContext.lineTo( target.x * 0.1, target.z * 0.1 );
+				debugContext.lineTo( camera.target.x * 0.1, camera.target.z * 0.1 );
 				debugContext.rect( camera.position.x * 0.1 - 5, camera.position.z * 0.1 - 5, 10, 10 );
-				debugContext.rect( target.x * 0.1 - 5, target.z * 0.1 - 5, 10, 10 );
+				debugContext.rect( camera.target.x * 0.1 - 5, camera.target.z * 0.1 - 5, 10, 10 );
 				debugContext.rect( - 50, - 50, 100, 100 );
 
 				for ( var i = 0, l = objects.length; i < l; i++ ) {

+ 4 - 1
src/cameras/Camera.js

@@ -14,9 +14,12 @@ THREE.Camera = function () {
 
 	THREE.Object3D.call( this );
 
-	this.projectionMatrix = new THREE.Matrix4();
 	this.matrixWorldInverse = new THREE.Matrix4();
 
+	this.projectionMatrix = new THREE.Matrix4();
+	this.projectionMatrixInverse = new THREE.Matrix4();
+
+
 };
 
 THREE.Camera.prototype = new THREE.Object3D();

+ 112 - 139
src/core/Matrix4.js

@@ -102,60 +102,6 @@ THREE.Matrix4.prototype = {
 
 	},
 
-	multiplyVector3: function ( v ) {
-
-		var vx = v.x, vy = v.y, vz = v.z,
-		d = 1 / ( this.n41 * vx + this.n42 * vy + this.n43 * vz + this.n44 );
-
-		v.x = ( this.n11 * vx + this.n12 * vy + this.n13 * vz + this.n14 ) * d;
-		v.y = ( this.n21 * vx + this.n22 * vy + this.n23 * vz + this.n24 ) * d;
-		v.z = ( this.n31 * vx + this.n32 * vy + this.n33 * vz + this.n34 ) * d;
-
-		return v;
-
-	},
-
-	multiplyVector4: function ( v ) {
-
-		var vx = v.x, vy = v.y, vz = v.z, vw = v.w;
-
-		v.x = this.n11 * vx + this.n12 * vy + this.n13 * vz + this.n14 * vw;
-		v.y = this.n21 * vx + this.n22 * vy + this.n23 * vz + this.n24 * vw;
-		v.z = this.n31 * vx + this.n32 * vy + this.n33 * vz + this.n34 * vw;
-		v.w = this.n41 * vx + this.n42 * vy + this.n43 * vz + this.n44 * vw;
-
-		return v;
-
-	},
-
-	rotateAxis: function ( v ) {
-
-		var vx = v.x, vy = v.y, vz = v.z;
-
-		v.x = vx * this.n11 + vy * this.n12 + vz * this.n13;
-		v.y = vx * this.n21 + vy * this.n22 + vz * this.n23;
-		v.z = vx * this.n31 + vy * this.n32 + vz * this.n33;
-
-		v.normalize();
-
-		return v;
-
-	},
-
-	crossVector: function ( a ) {
-
-		var v = new THREE.Vector4();
-
-		v.x = this.n11 * a.x + this.n12 * a.y + this.n13 * a.z + this.n14 * a.w;
-		v.y = this.n21 * a.x + this.n22 * a.y + this.n23 * a.z + this.n24 * a.w;
-		v.z = this.n31 * a.x + this.n32 * a.y + this.n33 * a.z + this.n34 * a.w;
-
-		v.w = ( a.w ) ? this.n41 * a.x + this.n42 * a.y + this.n43 * a.z + this.n44 * a.w : 1;
-
-		return v;
-
-	},
-
 	multiply: function ( a, b ) {
 
 		var a11 = a.n11, a12 = a.n12, a13 = a.n13, a14 = a.n14,
@@ -192,6 +138,12 @@ THREE.Matrix4.prototype = {
 
 	},
 
+	multiplySelf: function ( m ) {
+
+		return this.multiply( this, m );
+
+	},
+
 	multiplyToArray: function ( a, b, r ) {
 
 		this.multiply( a, b );
@@ -205,14 +157,6 @@ THREE.Matrix4.prototype = {
 
 	},
 
-	multiplySelf: function ( m ) {
-
-		this.multiply( this, m );
-
-		return this;
-
-	},
-
 	multiplyScalar: function ( s ) {
 
 		this.n11 *= s; this.n12 *= s; this.n13 *= s; this.n14 *= s;
@@ -224,6 +168,60 @@ THREE.Matrix4.prototype = {
 
 	},
 
+	multiplyVector3: function ( v ) {
+
+		var vx = v.x, vy = v.y, vz = v.z,
+		d = 1 / ( this.n41 * vx + this.n42 * vy + this.n43 * vz + this.n44 );
+
+		v.x = ( this.n11 * vx + this.n12 * vy + this.n13 * vz + this.n14 ) * d;
+		v.y = ( this.n21 * vx + this.n22 * vy + this.n23 * vz + this.n24 ) * d;
+		v.z = ( this.n31 * vx + this.n32 * vy + this.n33 * vz + this.n34 ) * d;
+
+		return v;
+
+	},
+
+	multiplyVector4: function ( v ) {
+
+		var vx = v.x, vy = v.y, vz = v.z, vw = v.w;
+
+		v.x = this.n11 * vx + this.n12 * vy + this.n13 * vz + this.n14 * vw;
+		v.y = this.n21 * vx + this.n22 * vy + this.n23 * vz + this.n24 * vw;
+		v.z = this.n31 * vx + this.n32 * vy + this.n33 * vz + this.n34 * vw;
+		v.w = this.n41 * vx + this.n42 * vy + this.n43 * vz + this.n44 * vw;
+
+		return v;
+
+	},
+
+	rotateAxis: function ( v ) {
+
+		var vx = v.x, vy = v.y, vz = v.z;
+
+		v.x = vx * this.n11 + vy * this.n12 + vz * this.n13;
+		v.y = vx * this.n21 + vy * this.n22 + vz * this.n23;
+		v.z = vx * this.n31 + vy * this.n32 + vz * this.n33;
+
+		v.normalize();
+
+		return v;
+
+	},
+
+	crossVector: function ( a ) {
+
+		var v = new THREE.Vector4();
+
+		v.x = this.n11 * a.x + this.n12 * a.y + this.n13 * a.z + this.n14 * a.w;
+		v.y = this.n21 * a.x + this.n22 * a.y + this.n23 * a.z + this.n24 * a.w;
+		v.z = this.n31 * a.x + this.n32 * a.y + this.n33 * a.z + this.n34 * a.w;
+
+		v.w = ( a.w ) ? this.n41 * a.x + this.n42 * a.y + this.n43 * a.z + this.n44 * a.w : 1;
+
+		return v;
+
+	},
+
 	determinant: function () {
 
 		var n11 = this.n11, n12 = this.n12, n13 = this.n13, n14 = this.n14,
@@ -448,7 +446,7 @@ THREE.Matrix4.prototype = {
 
 	},
 
-	setPosition: function( v ) {
+	setPosition: function ( v ) {
 
 		this.n14 = v.x;
 		this.n24 = v.y;
@@ -458,58 +456,58 @@ THREE.Matrix4.prototype = {
 
 	},
 
-	getPosition: function() {
+	getPosition: function () {
 
-		if ( ! this.position ) {
-
-			this.position = new THREE.Vector3();
-
-		}
-
-		this.position.set( this.n14, this.n24, this.n34 );
-
-		return this.position;
+		return THREE.Matrix4.__v1.set( this.n14, this.n24, this.n34 );
 
 	},
 
-	getColumnX: function() {
-
-		if ( ! this.columnX ) {
+	getColumnX: function () {
 
-			this.columnX = new THREE.Vector3();
+		return THREE.Matrix4.__v1.set( this.n11, this.n21, this.n31 );
 
-		}
-
-		this.columnX.set( this.n11, this.n21, this.n31 );
-
-		return this.columnX;
 	},
 
-	getColumnY: function() {
+	getColumnY: function () {
 
-		if ( ! this.columnY ) {
+		return THREE.Matrix4.__v1.set( this.n12, this.n22, this.n32 );
 
-			this.columnY = new THREE.Vector3();
-
-		}
+	},
 
-		this.columnY.set( this.n12, this.n22, this.n32 );
+	getColumnZ: function() {
 
-		return this.columnY;
+		return THREE.Matrix4.__v1.set( this.n13, this.n23, this.n33 );
 
 	},
 
-	getColumnZ: function() {
+	getInverse: function ( m ) {
 
-		if ( ! this.columnZ ) {
+		// based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
 
-			this.columnZ = new THREE.Vector3();
+		var n11 = m.n11, n12 = m.n12, n13 = m.n13, n14 = m.n14,
+		n21 = m.n21, n22 = m.n22, n23 = m.n23, n24 = m.n24,
+		n31 = m.n31, n32 = m.n32, n33 = m.n33, n34 = m.n34,
+		n41 = m.n41, n42 = m.n42, n43 = m.n43, n44 = m.n44;
 
-		}
+		this.n11 = n23*n34*n42 - n24*n33*n42 + n24*n32*n43 - n22*n34*n43 - n23*n32*n44 + n22*n33*n44;
+		this.n12 = n14*n33*n42 - n13*n34*n42 - n14*n32*n43 + n12*n34*n43 + n13*n32*n44 - n12*n33*n44;
+		this.n13 = n13*n24*n42 - n14*n23*n42 + n14*n22*n43 - n12*n24*n43 - n13*n22*n44 + n12*n23*n44;
+		this.n14 = n14*n23*n32 - n13*n24*n32 - n14*n22*n33 + n12*n24*n33 + n13*n22*n34 - n12*n23*n34;
+		this.n21 = n24*n33*n41 - n23*n34*n41 - n24*n31*n43 + n21*n34*n43 + n23*n31*n44 - n21*n33*n44;
+		this.n22 = n13*n34*n41 - n14*n33*n41 + n14*n31*n43 - n11*n34*n43 - n13*n31*n44 + n11*n33*n44;
+		this.n23 = n14*n23*n41 - n13*n24*n41 - n14*n21*n43 + n11*n24*n43 + n13*n21*n44 - n11*n23*n44;
+		this.n24 = n13*n24*n31 - n14*n23*n31 + n14*n21*n33 - n11*n24*n33 - n13*n21*n34 + n11*n23*n34;
+		this.n31 = n22*n34*n41 - n24*n32*n41 + n24*n31*n42 - n21*n34*n42 - n22*n31*n44 + n21*n32*n44;
+		this.n32 = n14*n32*n41 - n12*n34*n41 - n14*n31*n42 + n11*n34*n42 + n12*n31*n44 - n11*n32*n44;
+		this.n33 = n13*n24*n41 - n14*n22*n41 + n14*n21*n42 - n11*n24*n42 - n12*n21*n44 + n11*n22*n44;
+		this.n34 = n14*n22*n31 - n12*n24*n31 - n14*n21*n32 + n11*n24*n32 + n12*n21*n34 - n11*n22*n34;
+		this.n41 = n23*n32*n41 - n22*n33*n41 - n23*n31*n42 + n21*n33*n42 + n22*n31*n43 - n21*n32*n43;
+		this.n42 = n12*n33*n41 - n13*n32*n41 + n13*n31*n42 - n11*n33*n42 - n12*n31*n43 + n11*n32*n43;
+		this.n43 = n13*n22*n41 - n12*n23*n41 - n13*n21*n42 + n11*n23*n42 + n12*n21*n43 - n11*n22*n43;
+		this.n44 = n12*n23*n31 - n13*n22*n31 + n13*n21*n32 - n11*n23*n32 - n12*n21*n33 + n11*n22*n33;
+		this.multiplyScalar( 1 / m.determinant() );
 
-		this.columnZ.set( this.n13, this.n23, this.n33 );
-
-		return this.columnZ;
+		return this;
 
 	},
 
@@ -742,58 +740,33 @@ THREE.Matrix4.prototype = {
 		this.n24 = m.n24;
 		this.n34 = m.n34;
 
+		return this;
+
 	},
 
-	extractRotation: function ( m, s ) {
+	extractRotation: function ( m ) {
 
-		var invScaleX = 1 / s.x, invScaleY = 1 / s.y, invScaleZ = 1 / s.z;
+		var vector = THREE.Matrix4.__v1;
 
-		this.n11 = m.n11 * invScaleX;
-		this.n21 = m.n21 * invScaleX;
-		this.n31 = m.n31 * invScaleX;
+		var scaleX = 1 / vector.set( m.n11, m.n21, m.n31 ).length();
+		var scaleY = 1 / vector.set( m.n12, m.n22, m.n32 ).length();
+		var scaleZ = 1 / vector.set( m.n13, m.n23, m.n33 ).length();
 
-		this.n12 = m.n12 * invScaleY;
-		this.n22 = m.n22 * invScaleY;
-		this.n32 = m.n32 * invScaleY;
+		this.n11 = m.n11 * scaleX;
+		this.n21 = m.n21 * scaleX;
+		this.n31 = m.n31 * scaleX;
 
-		this.n13 = m.n13 * invScaleZ;
-		this.n23 = m.n23 * invScaleZ;
-		this.n33 = m.n33 * invScaleZ;
+		this.n12 = m.n12 * scaleY;
+		this.n22 = m.n22 * scaleY;
+		this.n32 = m.n32 * scaleY;
 
-	}
+		this.n13 = m.n13 * scaleZ;
+		this.n23 = m.n23 * scaleZ;
+		this.n33 = m.n33 * scaleZ;
 
-};
+		return this;
 
-THREE.Matrix4.makeInvert = function ( m1, m2 ) {
-
-	// based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
-
-	var n11 = m1.n11, n12 = m1.n12, n13 = m1.n13, n14 = m1.n14,
-	n21 = m1.n21, n22 = m1.n22, n23 = m1.n23, n24 = m1.n24,
-	n31 = m1.n31, n32 = m1.n32, n33 = m1.n33, n34 = m1.n34,
-	n41 = m1.n41, n42 = m1.n42, n43 = m1.n43, n44 = m1.n44;
-
-	if ( m2 === undefined ) m2 = new THREE.Matrix4();
-
-	m2.n11 = n23*n34*n42 - n24*n33*n42 + n24*n32*n43 - n22*n34*n43 - n23*n32*n44 + n22*n33*n44;
-	m2.n12 = n14*n33*n42 - n13*n34*n42 - n14*n32*n43 + n12*n34*n43 + n13*n32*n44 - n12*n33*n44;
-	m2.n13 = n13*n24*n42 - n14*n23*n42 + n14*n22*n43 - n12*n24*n43 - n13*n22*n44 + n12*n23*n44;
-	m2.n14 = n14*n23*n32 - n13*n24*n32 - n14*n22*n33 + n12*n24*n33 + n13*n22*n34 - n12*n23*n34;
-	m2.n21 = n24*n33*n41 - n23*n34*n41 - n24*n31*n43 + n21*n34*n43 + n23*n31*n44 - n21*n33*n44;
-	m2.n22 = n13*n34*n41 - n14*n33*n41 + n14*n31*n43 - n11*n34*n43 - n13*n31*n44 + n11*n33*n44;
-	m2.n23 = n14*n23*n41 - n13*n24*n41 - n14*n21*n43 + n11*n24*n43 + n13*n21*n44 - n11*n23*n44;
-	m2.n24 = n13*n24*n31 - n14*n23*n31 + n14*n21*n33 - n11*n24*n33 - n13*n21*n34 + n11*n23*n34;
-	m2.n31 = n22*n34*n41 - n24*n32*n41 + n24*n31*n42 - n21*n34*n42 - n22*n31*n44 + n21*n32*n44;
-	m2.n32 = n14*n32*n41 - n12*n34*n41 - n14*n31*n42 + n11*n34*n42 + n12*n31*n44 - n11*n32*n44;
-	m2.n33 = n13*n24*n41 - n14*n22*n41 + n14*n21*n42 - n11*n24*n42 - n12*n21*n44 + n11*n22*n44;
-	m2.n34 = n14*n22*n31 - n12*n24*n31 - n14*n21*n32 + n11*n24*n32 + n12*n21*n34 - n11*n22*n34;
-	m2.n41 = n23*n32*n41 - n22*n33*n41 - n23*n31*n42 + n21*n33*n42 + n22*n31*n43 - n21*n32*n43;
-	m2.n42 = n12*n33*n41 - n13*n32*n41 + n13*n31*n42 - n11*n33*n42 - n12*n31*n43 + n11*n32*n43;
-	m2.n43 = n13*n22*n41 - n12*n23*n41 - n13*n21*n42 + n11*n23*n42 + n12*n21*n43 - n11*n22*n43;
-	m2.n44 = n12*n23*n31 - n13*n22*n31 + n13*n21*n32 - n11*n23*n32 - n12*n21*n33 + n11*n22*n33;
-	m2.multiplyScalar( 1 / m1.determinant() );
-
-	return m2;
+	}
 
 };
 

+ 11 - 61
src/core/Object3D.js

@@ -4,7 +4,7 @@
  * @author alteredq / http://alteredqualia.com/
  */
 
-THREE.Object3D = function() {
+THREE.Object3D = function () {
 
 	this.name = '';
 
@@ -101,7 +101,7 @@ THREE.Object3D.prototype = {
 
 		if ( this.children.indexOf( object ) === - 1 ) {
 
-			if( object.parent !== undefined ) {
+			if ( object.parent !== undefined ) {
 
 				object.parent.remove( object );
 
@@ -110,50 +110,18 @@ THREE.Object3D.prototype = {
 			object.parent = this;
 			this.children.push( object );
 
-			// add to scene
-
-			var scene = this;
-
-			while ( scene.parent !== undefined ) {
-
-				scene = scene.parent;
-
-			}
-
-			if ( scene !== undefined && scene instanceof THREE.Scene )  {
-
-				scene.addChildRecurse( object );
-
-			}
-
 		}
 
 	},
 
 	remove: function ( object ) {
 
-		var scene = this;
+		var index = this.children.indexOf( object );
 
-		var childIndex = this.children.indexOf( object );
-
-		if ( childIndex !== - 1 ) {
+		if ( index !== - 1 ) {
 
 			object.parent = undefined;
-			this.children.splice( childIndex, 1 );
-
-			// remove from scene
-
-			while ( scene.parent !== undefined ) {
-
-				scene = scene.parent;
-
-			}
-
-			if ( scene !== undefined && scene instanceof THREE.Scene ) {
-
-				scene.removeChildRecurse( object );
-
-			}
+			this.children.splice( index, 1 );
 
 		}
 
@@ -216,17 +184,17 @@ THREE.Object3D.prototype = {
 
 	},
 
-	update: function ( parentMatrixWorld, forceUpdate, camera ) {
+	updateMatrixWorld: function ( force ) {
 
 		this.matrixAutoUpdate && this.updateMatrix();
 
 		// update matrixWorld
 
-		if ( this.matrixWorldNeedsUpdate || forceUpdate ) {
+		if ( this.matrixWorldNeedsUpdate || force ) {
 
-			if ( parentMatrixWorld ) {
+			if ( this.parent ) {
 
-				this.matrixWorld.multiply( parentMatrixWorld, this.matrix );
+				this.matrixWorld.multiply( this.parent.matrixWorld, this.matrix );
 
 			} else {
 
@@ -234,11 +202,9 @@ THREE.Object3D.prototype = {
 
 			}
 
-			this.matrixRotationWorld.extractRotation( this.matrixWorld, this.scale );
-
 			this.matrixWorldNeedsUpdate = false;
 
-			forceUpdate = true;
+			force = true;
 
 		}
 
@@ -246,26 +212,10 @@ THREE.Object3D.prototype = {
 
 		for ( var i = 0, l = this.children.length; i < l; i ++ ) {
 
-			this.children[ i ].update( this.matrixWorld, forceUpdate, camera );
+			this.children[ i ].updateMatrixWorld( force );
 
 		}
 
-	},
-
-	// DEPRECATED
-
-	addChild: function ( child ) {
-
-		console.warn( 'DEPRECATED: Object3D.addChild() is now Object3D.add().' );
-		this.add( child );
-
-	},
-
-	removeChild: function ( child ) {
-
-		console.warn( 'DEPRECATED: Object3D.removeChild() is now Object3D.remove().' );
-		this.remove( child );
-
 	}
 
 };

+ 45 - 51
src/core/Projector.js

@@ -6,13 +6,12 @@
 
 THREE.Projector = function() {
 
-	var _object, _objectCount, _objectPool = [],
-	_vertex, _vertexCount, _vertexPool = [],
+	var _vertex, _vertexCount, _vertexPool = [],
 	_face, _face3Count, _face3Pool = [], _face4Count, _face4Pool = [],
 	_line, _lineCount, _linePool = [],
 	_particle, _particleCount, _particlePool = [],
 
-	_objectList = [], _renderList = [],
+	_renderData = { objects: [], lights: [], elements: [] },
 
 	_vector3 = new THREE.Vector3(),
 	_vector4 = new THREE.Vector4(),
@@ -37,7 +36,7 @@ THREE.Projector = function() {
 
 	this.projectVector = function ( vector, camera ) {
 
-		THREE.Matrix4.makeInvert( camera.matrixWorld, camera.matrixWorldInverse );
+		camera.matrixWorldInverse.getInverse( camera.matrixWorld );
 
 		_projScreenMatrix.multiply( camera.projectionMatrix, camera.matrixWorldInverse );
 		_projScreenMatrix.multiplyVector3( vector );
@@ -48,7 +47,9 @@ THREE.Projector = function() {
 
 	this.unprojectVector = function ( vector, camera ) {
 
-		_projScreenMatrix.multiply( camera.matrixWorld, THREE.Matrix4.makeInvert( camera.projectionMatrix ) );
+		camera.projectionMatrixInverse.getInverse( camera.projectionMatrix );
+
+		_projScreenMatrix.multiply( camera.matrixWorld, camera.projectionMatrixInverse );
 		_projScreenMatrix.multiplyVector3( vector );
 
 		return vector;
@@ -79,77 +80,78 @@ THREE.Projector = function() {
 
 	};
 
-	this.projectObjects = function ( scene, camera, sort ) {
+	this.projectGraph = function ( object ) {
 
-		var o, ol, objects, object, matrix;
+		_renderData.objects.length = 0;
+		_renderData.lights.length = 0;
 
-		_objectList.length = 0;
-		_objectCount = 0;
+		var projectObject = function ( object ) {
 
-		objects = scene.objects;
+			if ( object.visible == false ) return;
 
-		for ( o = 0, ol = objects.length; o < ol; o ++ ) {
+			if ( object instanceof THREE.Particle || object instanceof THREE.Line ||
+			( object instanceof THREE.Mesh && ( !object.frustumCulled || isInFrustum( object ) ) ) ) {
 
-			object = objects[ o ];
+				_renderData.objects.push( object );
 
-			if ( !object.visible || ( object instanceof THREE.Mesh && ( object.frustumCulled && !isInFrustum( object ) ) ) ) continue;
+			} else if ( object instanceof THREE.Light ) {
 
-			_object = getNextObjectInPool();
+				_renderData.lights.push( object );
 
-			_vector3.copy( object.position );
-			_projScreenMatrix.multiplyVector3( _vector3 );
+			}
 
-			_object.object = object;
-			_object.z = _vector3.z;
+			for ( var c = 0, cl = object.children.length; c < cl; c ++ ) {
 
-			_objectList.push( _object );
+				projectObject( object.children[ c ] );
 
-		}
+			}
 
-		sort && _objectList.sort( painterSort );
+		};
 
-		return _objectList;
+		projectObject( object );
 
-	};
+		return _renderData;
 
-	// TODO: Rename to projectElements?
+	};
 
 	this.projectScene = function ( scene, camera, sort ) {
 
 		var near = camera.near, far = camera.far,
-		o, ol, v, vl, f, fl, n, nl, c, cl, u, ul, objects, object,
+		o, ol, v, vl, f, fl, n, nl, c, cl, u, ul, object,
 		objectMatrix, objectMatrixRotation, objectMaterials, objectOverdraw,
 		geometry, vertices, vertex, vertexPositionScreen,
 		faces, face, faceVertexNormals, normal, faceVertexUvs, uvs,
 		v1, v2, v3, v4;
 
-		_renderList.length = 0;
-
 		_face3Count = 0;
 		_face4Count = 0;
 		_lineCount = 0;
 		_particleCount = 0;
 
-		camera.matrixAutoUpdate && camera.update( undefined, true );
+		_renderData.elements.length = 0;
+
+		if ( camera.parent == null ) {
 
-		scene.update( undefined, false, camera );
+			console.warn( "Camera is not on the Scene. Adding it..." );
+			scene.add( camera );
+
+		}
 
-		THREE.Matrix4.makeInvert( camera.matrixWorld, camera.matrixWorldInverse );
+		scene.updateMatrixWorld();
+
+		camera.matrixWorldInverse.getInverse( camera.matrixWorld );
 
 		_projScreenMatrix.multiply( camera.projectionMatrix, camera.matrixWorldInverse );
 
 		computeFrustum( _projScreenMatrix );
 
-		objects = this.projectObjects( scene, camera, true );
-
-		for ( o = 0, ol = objects.length; o < ol; o++ ) {
+		_renderData = this.projectGraph( scene );
 
-			object = objects[ o ].object;
+		for ( o = 0, ol = _renderData.objects.length; o < ol; o++ ) {
 
-			if ( !object.visible ) continue;
+			object = _renderData.objects[ o ];
 
 			objectMatrix = object.matrixWorld;
-			objectMatrixRotation = object.matrixRotationWorld;
 
 			objectMaterials = object.materials;
 			objectOverdraw = object.overdraw;
@@ -163,6 +165,8 @@ THREE.Projector = function() {
 				faces = geometry.faces;
 				faceVertexUvs = geometry.faceVertexUvs;
 
+				objectMatrixRotation = object.matrixRotationWorld.extractRotation( object.matrixWorld );
+
 				for ( v = 0, vl = vertices.length; v < vl; v ++ ) {
 
 					_vertex = getNextVertexInPool();
@@ -275,7 +279,7 @@ THREE.Projector = function() {
 
 					_face.z = _face.centroidScreen.z;
 
-					_renderList.push( _face );
+					_renderData.elements.push( _face );
 
 				}
 
@@ -314,7 +318,7 @@ THREE.Projector = function() {
 
 						_line.materials = object.materials;
 
-						_renderList.push( _line );
+						_renderData.elements.push( _line );
 
 					}
 				}
@@ -340,7 +344,7 @@ THREE.Projector = function() {
 
 					_particle.materials = object.materials;
 
-					_renderList.push( _particle );
+					_renderData.elements.push( _particle );
 
 				}
 
@@ -348,24 +352,14 @@ THREE.Projector = function() {
 
 		}
 
-		sort && _renderList.sort( painterSort );
+		sort && _renderData.elements.sort( painterSort );
 
-		return _renderList;
+		return _renderData;
 
 	};
 
 	// Pools
 
-	function getNextObjectInPool() {
-
-		var object = _objectPool[ _objectCount ] = _objectPool[ _objectCount ] || new THREE.RenderableObject();
-
-		_objectCount ++;
-
-		return object;
-
-	}
-
 	function getNextVertexInPool() {
 
 		var vertex = _vertexPool[ _vertexCount ] = _vertexPool[ _vertexCount ] || new THREE.RenderableVertex();

+ 3 - 1
src/core/Ray.js

@@ -15,7 +15,7 @@ THREE.Ray.prototype = {
 
 	intersectScene: function ( scene ) {
 
-		return this.intersectObjects( scene.objects );
+		return this.intersectObjects( scene.children );
 
 	},
 
@@ -90,6 +90,8 @@ THREE.Ray.prototype = {
 			objMatrix,
 			intersectPoint;
 
+			object.matrixRotationWorld.extractRotation( object.matrixWorld );
+
 			for ( f = 0, fl = geometry.faces.length; f < fl; f ++ ) {
 
 				face = geometry.faces[ f ];

+ 45 - 42
src/renderers/CanvasRenderer.js

@@ -5,7 +5,7 @@
 THREE.CanvasRenderer = function ( parameters ) {
 
 	var _this = this,
-	_renderList = null,
+	_renderData, _elements, _lights,
 	_projector = new THREE.Projector(),
 
 	parameters = parameters || {},
@@ -33,11 +33,11 @@ THREE.CanvasRenderer = function ( parameters ) {
 	_v1x, _v1y, _v2x, _v2y, _v3x, _v3y,
 	_v4x, _v4y, _v5x, _v5y, _v6x, _v6y,
 
-	_color = new THREE.Color( 0x000000 ),
-	_color1 = new THREE.Color( 0x000000 ),
-	_color2 = new THREE.Color( 0x000000 ),
-	_color3 = new THREE.Color( 0x000000 ),
-	_color4 = new THREE.Color( 0x000000 ),
+	_color = new THREE.Color(),
+	_color1 = new THREE.Color(),
+	_color2 = new THREE.Color(),
+	_color3 = new THREE.Color(),
+	_color4 = new THREE.Color(),
 
 	_patterns = [],
 
@@ -51,7 +51,6 @@ THREE.CanvasRenderer = function ( parameters ) {
 	_bboxRect = new THREE.Rectangle(),
 
 	_enableLighting = false,
-	_light = new THREE.Color(),
 	_ambientLight = new THREE.Color(),
 	_directionalLights = new THREE.Color(),
 	_pointLights = new THREE.Color(),
@@ -181,24 +180,26 @@ THREE.CanvasRenderer = function ( parameters ) {
 		_this.info.render.vertices = 0;
 		_this.info.render.faces = 0;
 
-		_renderList = _projector.projectScene( scene, camera, this.sortElements );
+		_renderData = _projector.projectScene( scene, camera, this.sortElements );
+		_elements = _renderData.elements;
+		_lights = _renderData.lights;
 
 		/* DEBUG
 		_context.fillStyle = 'rgba( 0, 255, 255, 0.5 )';
 		_context.fillRect( _clipRect.getX(), _clipRect.getY(), _clipRect.getWidth(), _clipRect.getHeight() );
 		*/
 
-		_enableLighting = scene.lights.length > 0;
+		_enableLighting = _lights.length > 0;
 
 		if ( _enableLighting ) {
 
-			 calculateLights( scene );
+			 calculateLights( _lights );
 
 		}
 
-		for ( e = 0, el = _renderList.length; e < el; e++ ) {
+		for ( e = 0, el = _elements.length; e < el; e++ ) {
 
-			element = _renderList[ e ];
+			element = _elements[ e ];
 
 			_bboxRect.empty();
 
@@ -369,10 +370,9 @@ THREE.CanvasRenderer = function ( parameters ) {
 
 		//
 
-		function calculateLights( scene ) {
+		function calculateLights( lights ) {
 
-			var l, ll, light, lightColor,
-			lights = scene.lights;
+			var l, ll, light, lightColor;
 
 			_ambientLight.setRGB( 0, 0, 0 );
 			_directionalLights.setRGB( 0, 0, 0 );
@@ -411,10 +411,9 @@ THREE.CanvasRenderer = function ( parameters ) {
 
 		}
 
-		function calculateLight( scene, position, normal, color ) {
+		function calculateLight( lights, position, normal, color ) {
 
-			var l, ll, light, lightColor,
-			amount, lights = scene.lights;
+			var l, ll, light, lightColor, lightPosition, amount;
 
 			for ( l = 0, ll = lights.length; l < ll; l ++ ) {
 
@@ -423,7 +422,9 @@ THREE.CanvasRenderer = function ( parameters ) {
 
 				if ( light instanceof THREE.DirectionalLight ) {
 
-					amount = normal.dot( light.position );
+					lightPosition = light.matrixWorld.getPosition();
+
+					amount = normal.dot( lightPosition );
 
 					if ( amount <= 0 ) continue;
 
@@ -435,11 +436,13 @@ THREE.CanvasRenderer = function ( parameters ) {
 
 				} else if ( light instanceof THREE.PointLight ) {
 
-					amount = normal.dot( _vector3.sub( light.position, position ).normalize() );
+					lightPosition = light.matrixWorld.getPosition();
+
+					amount = normal.dot( _vector3.sub( lightPosition, position ).normalize() );
 
 					if ( amount <= 0 ) continue;
 
-					amount *= light.distance == 0 ? 1 : 1 - Math.min( position.distanceTo( light.position ) / light.distance, 1 );
+					amount *= light.distance == 0 ? 1 : 1 - Math.min( position.distanceTo( lightPosition ) / light.distance, 1 );
 
 					if ( amount == 0 ) continue;
 
@@ -645,9 +648,9 @@ THREE.CanvasRenderer = function ( parameters ) {
 						_color1.g = _color2.g = _color3.g = _ambientLight.g;
 						_color1.b = _color2.b = _color3.b = _ambientLight.b;
 
-						calculateLight( scene, element.v1.positionWorld, element.vertexNormalsWorld[ 0 ], _color1 );
-						calculateLight( scene, element.v2.positionWorld, element.vertexNormalsWorld[ 1 ], _color2 );
-						calculateLight( scene, element.v3.positionWorld, element.vertexNormalsWorld[ 2 ], _color3 );
+						calculateLight( _lights, element.v1.positionWorld, element.vertexNormalsWorld[ 0 ], _color1 );
+						calculateLight( _lights, element.v2.positionWorld, element.vertexNormalsWorld[ 1 ], _color2 );
+						calculateLight( _lights, element.v3.positionWorld, element.vertexNormalsWorld[ 2 ], _color3 );
 
 						_color1.r = Math.max( 0, Math.min( material.color.r * _color1.r, 1 ) );
 						_color1.g = Math.max( 0, Math.min( material.color.g * _color1.g, 1 ) );
@@ -671,15 +674,15 @@ THREE.CanvasRenderer = function ( parameters ) {
 
 					} else {
 
-						_light.r = _ambientLight.r;
-						_light.g = _ambientLight.g;
-						_light.b = _ambientLight.b;
+						_color.r = _ambientLight.r;
+						_color.g = _ambientLight.g;
+						_color.b = _ambientLight.b;
 
-						calculateLight( scene, element.centroidWorld, element.normalWorld, _light );
+						calculateLight( _lights, element.centroidWorld, element.normalWorld, _color );
 
-						_color.r = Math.max( 0, Math.min( material.color.r * _light.r, 1 ) );
-						_color.g = Math.max( 0, Math.min( material.color.g * _light.g, 1 ) );
-						_color.b = Math.max( 0, Math.min( material.color.b * _light.b, 1 ) );
+						_color.r = Math.max( 0, Math.min( material.color.r * _color.r, 1 ) );
+						_color.g = Math.max( 0, Math.min( material.color.g * _color.g, 1 ) );
+						_color.b = Math.max( 0, Math.min( material.color.b * _color.b, 1 ) );
 
 						material.wireframe ? strokePath( _color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) : fillPath( _color );
 
@@ -762,10 +765,10 @@ THREE.CanvasRenderer = function ( parameters ) {
 						_color1.g = _color2.g = _color3.g = _color4.g = _ambientLight.g;
 						_color1.b = _color2.b = _color3.b = _color4.b = _ambientLight.b;
 
-						calculateLight( scene, element.v1.positionWorld, element.vertexNormalsWorld[ 0 ], _color1 );
-						calculateLight( scene, element.v2.positionWorld, element.vertexNormalsWorld[ 1 ], _color2 );
-						calculateLight( scene, element.v4.positionWorld, element.vertexNormalsWorld[ 3 ], _color3 );
-						calculateLight( scene, element.v3.positionWorld, element.vertexNormalsWorld[ 2 ], _color4 );
+						calculateLight( _lights, element.v1.positionWorld, element.vertexNormalsWorld[ 0 ], _color1 );
+						calculateLight( _lights, element.v2.positionWorld, element.vertexNormalsWorld[ 1 ], _color2 );
+						calculateLight( _lights, element.v4.positionWorld, element.vertexNormalsWorld[ 3 ], _color3 );
+						calculateLight( _lights, element.v3.positionWorld, element.vertexNormalsWorld[ 2 ], _color4 );
 
 						_color1.r = Math.max( 0, Math.min( material.color.r * _color1.r, 1 ) );
 						_color1.g = Math.max( 0, Math.min( material.color.g * _color1.g, 1 ) );
@@ -795,15 +798,15 @@ THREE.CanvasRenderer = function ( parameters ) {
 
 					} else {
 
-						_light.r = _ambientLight.r;
-						_light.g = _ambientLight.g;
-						_light.b = _ambientLight.b;
+						_color.r = _ambientLight.r;
+						_color.g = _ambientLight.g;
+						_color.b = _ambientLight.b;
 
-						calculateLight( scene, element.centroidWorld, element.normalWorld, _light );
+						calculateLight( _lights, element.centroidWorld, element.normalWorld, _color );
 
-						_color.r = Math.max( 0, Math.min( material.color.r * _light.r, 1 ) );
-						_color.g = Math.max( 0, Math.min( material.color.g * _light.g, 1 ) );
-						_color.b = Math.max( 0, Math.min( material.color.b * _light.b, 1 ) );
+						_color.r = Math.max( 0, Math.min( material.color.r * _color.r, 1 ) );
+						_color.g = Math.max( 0, Math.min( material.color.g * _color.g, 1 ) );
+						_color.b = Math.max( 0, Math.min( material.color.b * _color.b, 1 ) );
 
 						drawQuad( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _v4x, _v4y );
 

+ 59 - 53
src/renderers/SVGRenderer.js

@@ -5,7 +5,7 @@
 THREE.SVGRenderer = function () {
 
 	var _this = this,
-	_renderList = null,
+	_renderData, _elements, _lights,
 	_projector = new THREE.Projector(),
 	_svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'),
 	_svgWidth, _svgHeight, _svgWidthHalf, _svgHeightHalf,
@@ -16,11 +16,10 @@ THREE.SVGRenderer = function () {
 	_bboxRect = new THREE.Rectangle(),
 
 	_enableLighting = false,
-	_color = new THREE.Color( 0xffffff ),
-	_light = new THREE.Color( 0xffffff ),
-	_ambientLight = new THREE.Color( 0x000000 ),
-	_directionalLights = new THREE.Color( 0x000000 ),
-	_pointLights = new THREE.Color( 0x000000 ),
+	_color = new THREE.Color(),
+	_ambientLight = new THREE.Color(),
+	_directionalLights = new THREE.Color(),
+	_pointLights = new THREE.Color(),
 
 	_w, // z-buffer to w-buffer
 	_vector3 = new THREE.Vector3(), // Needed for PointLight
@@ -80,7 +79,7 @@ THREE.SVGRenderer = function () {
 
 	};
 
-	this.render = function( scene, camera ) {
+	this.render = function ( scene, camera ) {
 
 		var e, el, m, ml, fm, fml, element, material;
 
@@ -89,21 +88,23 @@ THREE.SVGRenderer = function () {
 		_this.info.render.vertices = 0;
 		_this.info.render.faces = 0;
 
-		_renderList = _projector.projectScene( scene, camera, this.sortElements );
+		_renderData = _projector.projectScene( scene, camera, this.sortElements );
+		_elements = _renderData.elements;
+		_lights = _renderData.lights;
 
 		_pathCount = 0; _circleCount = 0; _lineCount = 0;
 
-		_enableLighting = scene.lights.length > 0;
+		_enableLighting = _lights.length > 0;
 
 		if ( _enableLighting ) {
 
-			calculateLights( scene );
+			 calculateLights( _lights );
 
 		}
 
-		for ( e = 0, el = _renderList.length; e < el; e ++ ) {
+		for ( e = 0, el = _elements.length; e < el; e ++ ) {
 
-			element = _renderList[ e ];
+			element = _elements[ e ];
 
 			_bboxRect.empty();
 
@@ -240,10 +241,9 @@ THREE.SVGRenderer = function () {
 
 	};
 
-	function calculateLights( scene ) {
+	function calculateLights( lights ) {
 
-		var l, ll, light, lightColor,
-		lights = scene.lights;
+		var l, ll, light, lightColor;
 
 		_ambientLight.setRGB( 0, 0, 0 );
 		_directionalLights.setRGB( 0, 0, 0 );
@@ -278,40 +278,46 @@ THREE.SVGRenderer = function () {
 
 	}
 
-	function calculateFaceLight( scene, element, color ) {
+	function calculateLight( lights, position, normal, color ) {
 
-		var l, ll, light, amount;
+		var l, ll, light, lightColor, lightPosition, amount;
 
-		for ( l = 0, ll = scene.lights.length; l < ll; l++ ) {
+		for ( l = 0, ll = lights.length; l < ll; l ++ ) {
 
-			light = scene.lights[ l ];
+			light = lights[ l ];
+			lightColor = light.color;
 
 			if ( light instanceof THREE.DirectionalLight ) {
 
-				amount = element.normalWorld.dot( light.position ) * light.intensity;
+				lightPosition = light.matrixWorld.getPosition();
 
-				if ( amount > 0 ) {
+				amount = normal.dot( lightPosition );
 
-					color.r += light.color.r * amount;
-					color.g += light.color.g * amount;
-					color.b += light.color.b * amount;
+				if ( amount <= 0 ) continue;
 
-				}
+				amount *= light.intensity;
+
+				color.r += lightColor.r * amount;
+				color.g += lightColor.g * amount;
+				color.b += lightColor.b * amount;
 
 			} else if ( light instanceof THREE.PointLight ) {
 
-				_vector3.sub( light.position, element.centroidWorld );
-				_vector3.normalize();
+				lightPosition = light.matrixWorld.getPosition();
 
-				amount = element.normalWorld.dot( _vector3 ) * light.intensity;
+				amount = normal.dot( _vector3.sub( lightPosition, position ).normalize() );
 
-				if ( amount > 0 ) {
+				if ( amount <= 0 ) continue;
 
-					color.r += light.color.r * amount;
-					color.g += light.color.g * amount;
-					color.b += light.color.b * amount;
+				amount *= light.distance == 0 ? 1 : 1 - Math.min( position.distanceTo( lightPosition ) / light.distance, 1 );
 
-				}
+				if ( amount == 0 ) continue;
+
+				amount *= light.intensity;
+
+				color.r += lightColor.r * amount;
+				color.g += lightColor.g * amount;
+				color.b += lightColor.b * amount;
 
 			}
 
@@ -331,13 +337,13 @@ THREE.SVGRenderer = function () {
 
 			if ( _enableLighting ) {
 
-				_light.r = _ambientLight.r + _directionalLights.r + _pointLights.r;
-				_light.g = _ambientLight.g + _directionalLights.g + _pointLights.g;
-				_light.b = _ambientLight.b + _directionalLights.b + _pointLights.b;
+				_color.r = _ambientLight.r + _directionalLights.r + _pointLights.r;
+				_color.g = _ambientLight.g + _directionalLights.g + _pointLights.g;
+				_color.b = _ambientLight.b + _directionalLights.b + _pointLights.b;
 
-				_color.r = material.color.r * _light.r;
-				_color.g = material.color.g * _light.g;
-				_color.b = material.color.b * _light.b;
+				_color.r = material.color.r * _color.r;
+				_color.g = material.color.g * _color.g;
+				_color.b = material.color.b * _color.b;
 
 				_color.updateStyleString();
 
@@ -391,15 +397,15 @@ THREE.SVGRenderer = function () {
 
 			if ( _enableLighting ) {
 
-				_light.r = _ambientLight.r;
-				_light.g = _ambientLight.g;
-				_light.b = _ambientLight.b;
+				_color.r = _ambientLight.r;
+				_color.g = _ambientLight.g;
+				_color.b = _ambientLight.b;
 
-				calculateFaceLight( scene, element, _light );
+				calculateLight( _lights, element.centroidWorld, element.normalWorld, _color );
 
-				_color.r = Math.max( 0, Math.min( material.color.r * _light.r, 1 ) );
-				_color.g = Math.max( 0, Math.min( material.color.g * _light.g, 1 ) );
-				_color.b = Math.max( 0, Math.min( material.color.b * _light.b, 1 ) );
+				_color.r = Math.max( 0, Math.min( material.color.r * _color.r, 1 ) );
+				_color.g = Math.max( 0, Math.min( material.color.g * _color.g, 1 ) );
+				_color.b = Math.max( 0, Math.min( material.color.b * _color.b, 1 ) );
 
 			} else {
 
@@ -448,15 +454,15 @@ THREE.SVGRenderer = function () {
 
 			if ( _enableLighting ) {
 
-				_light.r = _ambientLight.r;
-				_light.g = _ambientLight.g;
-				_light.b = _ambientLight.b;
+				_color.r = _ambientLight.r;
+				_color.g = _ambientLight.g;
+				_color.b = _ambientLight.b;
 
-				calculateFaceLight( scene, element, _light );
+				calculateLight( _lights, element.centroidWorld, element.normalWorld, _color );
 
-				_color.r = Math.max( 0, Math.min( material.color.r * _light.r, 1 ) );
-				_color.g = Math.max( 0, Math.min( material.color.g * _light.g, 1 ) );
-				_color.b = Math.max( 0, Math.min( material.color.b * _light.b, 1 ) );
+				_color.r = Math.max( 0, Math.min( material.color.r * _color.r, 1 ) );
+				_color.g = Math.max( 0, Math.min( material.color.g * _color.g, 1 ) );
+				_color.b = Math.max( 0, Math.min( material.color.b * _color.b, 1 ) );
 
 			} else {
 

+ 0 - 10
src/renderers/renderables/RenderableObject.js

@@ -1,10 +0,0 @@
-/**
- * @author mr.doob / http://mrdoob.com/
- */
-
-THREE.RenderableObject = function () {
-
-	this.object = null;
-	this.z = null;
-
-};

+ 1 - 151
src/scenes/Scene.js

@@ -1,6 +1,5 @@
 /**
  * @author mr.doob / http://mrdoob.com/
- * @author mikael emtinger / http://gomo.se/
  */
 
 THREE.Scene = function () {
@@ -8,160 +7,11 @@ THREE.Scene = function () {
 	THREE.Object3D.call( this );
 
 	this.fog = null;
-
-	this.matrixAutoUpdate = false;
-
 	this.overrideMaterial = null;
 
-	this.collisions = null;
-
-	this.objects = [];
-	this.lights = [];
-
-	this.__objectsAdded = [];
-	this.__objectsRemoved = [];
+	this.matrixAutoUpdate = false;
 
 };
 
 THREE.Scene.prototype = new THREE.Object3D();
 THREE.Scene.prototype.constructor = THREE.Scene;
-THREE.Scene.prototype.supr = THREE.Object3D.prototype;
-
-THREE.Scene.prototype.add = function ( object ) {
-
-	this.supr.add.call( this, object );
-	this.addChildRecurse( object );
-
-}
-
-THREE.Scene.prototype.addChildRecurse = function ( child ) {
-
-	if ( child instanceof THREE.Light ) {
-
-		if ( this.lights.indexOf( child ) === - 1 ) {
-
-			this.lights.push( child );
-
-		}
-
-	} else if ( !( child instanceof THREE.Camera || child instanceof THREE.Bone ) ) {
-
-		if ( this.objects.indexOf( child ) === - 1 ) {
-
-			this.objects.push( child );
-			this.__objectsAdded.push( child );
-
-			// check if previously removed
-
-			var i = this.__objectsRemoved.indexOf( child );
-
-			if ( i !== -1 ) {
-
-				this.__objectsRemoved.splice( i, 1 );
-
-			}
-
-		}
-
-	}
-
-	for ( var c = 0; c < child.children.length; c ++ ) {
-
-		this.addChildRecurse( child.children[ c ] );
-
-	}
-
-}
-
-THREE.Scene.prototype.remove = function ( object ) {
-
-	this.supr.remove.call( this, object );
-	this.removeChildRecurse( object );
-
-}
-
-THREE.Scene.prototype.removeChildRecurse = function ( child ) {
-
-	if ( child instanceof THREE.Light ) {
-
-		var i = this.lights.indexOf( child );
-
-		if ( i !== -1 ) {
-
-			this.lights.splice( i, 1 );
-
-		}
-
-	} else if ( !( child instanceof THREE.Camera ) ) {
-
-		var i = this.objects.indexOf( child );
-
-		if( i !== -1 ) {
-
-			this.objects.splice( i, 1 );
-			this.__objectsRemoved.push( child );
-
-			// check if previously added
-
-			var ai = this.__objectsAdded.indexOf( child );
-
-			if ( ai !== -1 ) {
-
-				this.__objectsAdded.splice( ai, 1 );
-
-			}
-		}
-
-	}
-
-	for ( var c = 0; c < child.children.length; c ++ ) {
-
-		this.removeChildRecurse( child.children[ c ] );
-
-	}
-
-}
-
-// DEPRECATED
-
-THREE.Scene.prototype.addChild = function ( child ) {
-
-	console.warn( 'DEPRECATED: Scene.addChild() is now Scene.add().' );
-	this.add( child );
-
-}
-
-THREE.Scene.prototype.addObject = function ( child ) {
-
-	console.warn( 'DEPRECATED: Scene.addObject() is now Scene.add().' );
-	this.add( child );
-
-}
-
-THREE.Scene.prototype.addLight = function ( child ) {
-
-	console.warn( 'DEPRECATED: Scene.addLight() is now Scene.add().' );
-	this.add( child );
-
-}
-
-THREE.Scene.prototype.removeChild = function ( child ) {
-
-	console.warn( 'DEPRECATED: Scene.removeChild() is now Scene.remove().' );
-	this.remove( child );
-
-}
-
-THREE.Scene.prototype.removeObject = function ( child ) {
-
-	console.warn( 'DEPRECATED: Scene.removeObject() is now Scene.remove().' );
-	this.remove( child );
-
-}
-
-THREE.Scene.prototype.removeLight = function ( child ) {
-
-	console.warn( 'DEPRECATED: Scene.removeLight() is now Scene.remove().' );
-	this.remove( child );
-
-}

+ 0 - 3
utils/build.py

@@ -76,7 +76,6 @@ COMMON_FILES = [
 'renderers/renderables/RenderableVertex.js',
 'renderers/renderables/RenderableFace3.js',
 'renderers/renderables/RenderableFace4.js',
-'renderers/renderables/RenderableObject.js',
 'renderers/renderables/RenderableParticle.js',
 'renderers/renderables/RenderableLine.js'
 ]
@@ -177,7 +176,6 @@ CANVAS_FILES = [
 'renderers/renderables/RenderableVertex.js',
 'renderers/renderables/RenderableFace3.js',
 'renderers/renderables/RenderableFace4.js',
-'renderers/renderables/RenderableObject.js',
 'renderers/renderables/RenderableParticle.js',
 'renderers/renderables/RenderableLine.js'
 ]
@@ -253,7 +251,6 @@ SVG_FILES = [
 'renderers/renderables/RenderableVertex.js',
 'renderers/renderables/RenderableFace3.js',
 'renderers/renderables/RenderableFace4.js',
-'renderers/renderables/RenderableObject.js',
 'renderers/renderables/RenderableParticle.js',
 'renderers/renderables/RenderableLine.js'
 ]