Browse Source

Merge remote-tracking branch 'alteredq/dev' into dev

Mr.doob 13 years ago
parent
commit
212506bce4

+ 0 - 1
examples/webgl_animation_skinning.html

@@ -39,7 +39,6 @@
 		click to start animation
 		</div>
 
-
 		<script src="../build/Three.js"></script>
 
 		<script src="js/RequestAnimationFrame.js"></script>

+ 6 - 1
examples/webgl_lod.html

@@ -98,7 +98,7 @@
 
 					lod = new THREE.LOD();
 
-					for ( i = 0; i < geometry.length; i++ ) {
+					for ( i = 0; i < geometry.length; i ++ ) {
 
 						mesh = new THREE.Mesh( geometry[ i ][ 0 ], material );
 						mesh.scale.set( 1.5, 1.5, 1.5 );
@@ -121,7 +121,9 @@
 
 				renderer = new THREE.WebGLRenderer( { clearColor: 0x000000, clearAlpha: 1 } );
 				renderer.setSize( window.innerWidth, window.innerHeight );
+
 				renderer.sortObjects = false;
+				renderer.autoUpdateScene = false;
 
 				container.appendChild( renderer.domElement );
 
@@ -148,6 +150,9 @@
 
 				camera.lookAt( scene.position );
 
+				scene.updateMatrixWorld();
+				THREE.SceneUtils.traverseHierarchy( scene, function ( node ) { if ( node instanceof THREE.LOD ) node.update( camera ) } );
+
 				renderer.render( scene, camera );
 
 			}

+ 6 - 8
examples/webgl_lod_text.html

@@ -131,7 +131,7 @@
 
 					lod = new THREE.LOD();
 
-					for ( i = 0; i < geometry.length; i++ ) {
+					for ( i = 0; i < geometry.length; i ++ ) {
 
 						mesh = new THREE.Mesh( geometry[ i ][ 0 ], geometry[ i ][ 2 ][ 1 ] );
 						mesh.scale.set( 1.5, 1.5, 1.5 );
@@ -154,7 +154,9 @@
 
 				renderer = new THREE.WebGLRenderer( { clearColor: 0x000000, clearAlpha: 1 } );
 				renderer.setSize( window.innerWidth, window.innerHeight );
+
 				renderer.sortObjects = false;
+				renderer.autoUpdateScene = false;
 
 				container.appendChild( renderer.domElement );
 
@@ -181,14 +183,10 @@
 
 				camera.lookAt( scene.position );
 
-				renderer.render( scene, camera );
-
-			}
-
-			function log( text ) {
+				scene.updateMatrixWorld();
+				THREE.SceneUtils.traverseHierarchy( scene, function ( node ) { if ( node instanceof THREE.LOD ) node.update( camera ) } );
 
-				var e = document.getElementById("log");
-				e.innerHTML = text + "<br/>" + e.innerHTML;
+				renderer.render( scene, camera );
 
 			}
 

+ 2 - 0
examples/webgl_materials_cars_anaglyph.html

@@ -164,6 +164,8 @@
 
 				scene = new THREE.Scene();
 
+				scene.add( camera );
+
 				// LIGHTS
 
 				var ambient = new THREE.AmbientLight( 0x555555 );

+ 3 - 0
examples/webgl_materials_cars_parallaxbarrier.html

@@ -56,6 +56,7 @@
 		</div>
 
 		<script src="../build/Three.js"></script>
+
 		<script src="../src/extras/renderers/ParallaxBarrierWebGLRenderer.js"></script>
 
 		<script src="js/Detector.js"></script>
@@ -165,6 +166,8 @@
 
 				scene = new THREE.Scene();
 
+				scene.add( camera );
+
 				// LIGHTS
 
 				var ambient = new THREE.AmbientLight( 0x555555 );

+ 2 - 0
examples/webgl_materials_cubemap_balls_reflection_anaglyph.html

@@ -74,6 +74,8 @@
 
 				scene = new THREE.Scene();
 
+				scene.add( camera );
+
 				var geometry = new THREE.SphereGeometry( 100, 32, 16 );
 
 				var path = "textures/cube/pisa/";

+ 46 - 20
examples/webgl_multiple_canvases_circle.html

@@ -152,11 +152,13 @@
 
 			function init() {
 
-        function degToRad(d) {
-          return d * Math.PI / 180;
-        }
+				function degToRad( d ) {
 
-				var rot = degToRad(30);
+					return d * Math.PI / 180;
+
+				}
+
+				var rot = degToRad( 30 );
 
 				var fudge = 0.45; // I don't know why this is needed :-(
 
@@ -165,20 +167,22 @@
 				apps.push( new App( 'container3', rot *  0 * fudge ) );
 				apps.push( new App( 'container4', rot *  1 * fudge ) );
 				apps.push( new App( 'container5', rot *  2 * fudge ) );
+
 			}
 
 			function animate() {
 
-				for ( var i = 0; i < apps.length; ++i ) {
+				for ( var i = 0; i < apps.length; ++ i ) {
 
 					apps[ i ].animate();
 
 				}
 
 				requestAnimationFrame( animate );
+
 			}
 
-			function App( containerId, rotateY) {
+			function App( containerId, rotateY ) {
 
 				var container;
 
@@ -199,19 +203,21 @@
 					container = document.getElementById( containerId );
 
 					camera = new THREE.PerspectiveCamera( 20, container.clientWidth / container.clientHeight, 1, 20000 );
-					camera.rotation.setY(rotateY);
+					camera.rotation.setY( rotateY );
 
 					// Think of the virtual camera as a post with 5 cameras on it (even though those cameras happen to live in difference scenes)
 					// You need to move the post (ie, the virtualCamera) to move all 5 cameras together.
+
 					virtualCamera = new THREE.Camera();
-					virtualCamera.add(camera);
+					virtualCamera.add( camera );
 					virtualCamera.position.z = cameraZ;
 
 					scene = new THREE.Scene();
 
+					scene.add( virtualCamera );
+
 					light = new THREE.DirectionalLight( 0xffffff );
-					light.position.set( 0, 0, 1 );
-					light.position.normalize();
+					light.position.set( 0, 0, 1 ).normalize();
 					scene.add( light );
 
 					var noof_balls = 51;
@@ -223,7 +229,7 @@
 
 						var mesh = new THREE.Mesh( shadowGeo, shadowMaterial );
 						mesh.position.y = - 250;
-						mesh.position.x = - (noof_balls - 1) /2 *400 + i * 400;
+						mesh.position.x = - ( noof_balls - 1 ) / 2 *400 + i * 400;
 						mesh.rotation.x = - 90 * Math.PI / 180;
 						scene.add( mesh );
 
@@ -273,7 +279,7 @@
 
 						var mesh = THREE.SceneUtils.createMultiMaterialObject( geometry1, materials );
 
-						mesh.position.x = - (noof_balls - 1) /2 *400 + i *400;
+						mesh.position.x = - ( noof_balls - 1 ) / 2 *400 + i *400;
 						mesh.rotation.x = i * 0.5;
 						scene.add( mesh );
 
@@ -286,33 +292,51 @@
 
 					document.addEventListener( 'mousemove', onDocumentMouseMove, false );
 					document.addEventListener( 'mousewheel', onDocumentMouseWheel, false );
+
 				}
 
-				function onDocumentMouseMove( event ) {
+				function onDocumentMouseMove ( event ) {
+
 					mouseX = ( event.clientX - windowHalfX );
 					mouseY = ( event.clientY - windowHalfY );
+
 				}
 
-				function onDocumentMouseWheel (event ) {
+				function onDocumentMouseWheel ( event ) {
 
 					var delta = 0;
-					if (event.wheelDelta) {
+
+					if ( event.wheelDelta ) {
+
 						delta = event.wheelDelta / 120;
-						if (window.opera) delta = -delta;
-					} else if (event.detail) {
+						if ( window.opera ) delta = -delta;
+
+					} else if ( event.detail ) {
+
 						delta = -event.detail / 3;
+
 					}
-					if (delta) {
-						if (delta < 0) {
-    							cameraZ -= 200;
+
+					if ( delta ) {
+
+						if ( delta < 0 ) {
+
+							cameraZ -= 200;
+
 						} else {
+
 							cameraZ += 200;
+
 						}
+
 					}
+
 				}
 
 				this.animate = function() {
+
 					render();
+
 				};
 
 				function render() {
@@ -324,7 +348,9 @@
 					virtualCamera.lookAt( scene.position );
 
 					renderer.render( scene, camera );
+
 				}
+
 			}
 
 		</script>

+ 1 - 1
src/extras/animation/Animation.js

@@ -361,7 +361,7 @@ THREE.Animation.prototype.update = function( deltaTimeMS ) {
 
 		if ( JIThierarchy[ 0 ][ frame ] === undefined ) {
 
-			this.hierarchy[ 0 ].update( undefined, true );
+			this.hierarchy[ 0 ].update( null, true );
 
 			for ( var h = 0; h < this.hierarchy.length; h++ ) {
 

+ 15 - 15
src/extras/physics/Collisions.js

@@ -162,13 +162,13 @@ THREE.CollisionSystem.prototype.rayMesh = function( r, me ) {
                 me.normal.normalize();
 
             }
-        
+
         }
-        
+
         else if (face instanceof THREE.Face4) {
-            
+
             var nd = this.rayTriangle( rt, p0, p1, p3, d, this.collisionNormal, me.mesh );
-            
+
             if( nd < d ) {
 
                 d = nd;
@@ -177,9 +177,9 @@ THREE.CollisionSystem.prototype.rayMesh = function( r, me ) {
                 me.normal.normalize();
 
             }
-            
+
             nd = this.rayTriangle( rt, p1, p2, p3, d, this.collisionNormal, me.mesh );
-            
+
             if( nd < d ) {
 
                 d = nd;
@@ -188,7 +188,7 @@ THREE.CollisionSystem.prototype.rayMesh = function( r, me ) {
                 me.normal.normalize();
 
             }
-            
+
         }
 
 	}
@@ -201,7 +201,7 @@ THREE.CollisionSystem.prototype.rayTriangle = function( ray, p0, p1, p2, mind, n
 
 	var e1 = THREE.CollisionSystem.__v1,
 		e2 = THREE.CollisionSystem.__v2;
-	
+
 	n.set( 0, 0, 0 );
 
 	// do not crash on quads, fail instead
@@ -212,18 +212,18 @@ THREE.CollisionSystem.prototype.rayTriangle = function( ray, p0, p1, p2, mind, n
 
 	var dot = n.dot( ray.direction );
 	if ( !( dot < 0 ) ) {
-		
+
 		if ( mesh.doubleSided || mesh.flipSided ) {
-		
+
 			n.multiplyScalar (-1.0);
 			dot *= -1.0;
-		
+
 		} else {
-			
+
 			return Number.MAX_VALUE;
-		
+
 		}
-	
+
 	}
 
 	var d = n.dot( p0 );
@@ -316,7 +316,7 @@ THREE.CollisionSystem.prototype.rayTriangle = function( ray, p0, p1, p2, mind, n
 THREE.CollisionSystem.prototype.makeRayLocal = function( ray, m ) {
 
 	var mt = THREE.CollisionSystem.__m;
-	THREE.Matrix4.makeInvert( m.matrixWorld, mt );
+	mt.getInverse( m.matrixWorld );
 
 	var rt = THREE.CollisionSystem.__r;
 	rt.origin.copy( ray.origin );

+ 36 - 25
src/extras/renderers/AnaglyphWebGLRenderer.js

@@ -1,6 +1,7 @@
 /**
  * @author mrdoob / http://mrdoob.com/
  * @author marklundin / http://mark-lundin.com/
+ * @author alteredq / http://alteredqualia.com/
  */
 
 if ( THREE.WebGLRenderer ) {
@@ -9,6 +10,8 @@ if ( THREE.WebGLRenderer ) {
 
 		THREE.WebGLRenderer.call( this, parameters );
 
+		this.autoUpdateScene = false;
+
 		var _this = this, _setSize = this.setSize, _render = this.render;
 
 		var _cameraL = new THREE.PerspectiveCamera(),
@@ -17,7 +20,7 @@ if ( THREE.WebGLRenderer ) {
 		var eyeRight = new THREE.Matrix4(),
 			eyeLeft = new THREE.Matrix4(),
 			focalLength = 125,
-			aspect, near, fov;
+			_aspect, _near, _far, _fov;
 
 		_cameraL.matrixAutoUpdate = _cameraR.matrixAutoUpdate = false;
 
@@ -78,6 +81,8 @@ if ( THREE.WebGLRenderer ) {
 		var _scene = new THREE.Scene();
 		_scene.add( new THREE.Mesh( new THREE.PlaneGeometry( 2, 2 ), _material ) );
 
+		_scene.add( _camera );
+
 		this.setSize = function ( width, height ) {
 
 			_setSize.call( _this, width, height );
@@ -98,59 +103,65 @@ if ( THREE.WebGLRenderer ) {
 
 		this.render = function ( scene, camera, renderTarget, forceClear ) {
 
-			//camera.update( null, true );
+			scene.updateMatrixWorld();
 
-			var hasCameraChanged = aspect !== camera.aspect || near !== camera.near || fov !== camera.fov;
+			var hasCameraChanged = ( _aspect !== camera.aspect ) || ( _near !== camera.near ) || ( _far !== camera.far ) || ( _fov !== camera.fov );
 
 			if( hasCameraChanged ) {
 
-				aspect = camera.aspect;
-				near = camera.near;
-				fov = camera.fov;
+				_aspect = camera.aspect;
+				_near = camera.near;
+				_far = camera.far;
+				_fov = camera.fov;
 
 				var projectionMatrix = camera.projectionMatrix.clone(),
 					eyeSep = focalLength / 30 * 0.5,
-					eyeSepOnProjection = eyeSep * near / focalLength,
-					ymax = near * Math.tan( fov * Math.PI / 360 ),
+					eyeSepOnProjection = eyeSep * _near / focalLength,
+					ymax = _near * Math.tan( _fov * Math.PI / 360 ),
 					xmin, xmax;
 
-				//translate xOffset
+				// translate xOffset
 
 				eyeRight.n14 = eyeSep;
 				eyeLeft.n14 = -eyeSep;
 
-				//For left eye
+				// for left eye
 
-				xmin = -ymax * aspect + eyeSepOnProjection;
-				xmax = ymax * aspect + eyeSepOnProjection;
-				projectionMatrix.n11 = 2 * near / ( xmax - xmin );
+				xmin = -ymax * _aspect + eyeSepOnProjection;
+				xmax = ymax * _aspect + eyeSepOnProjection;
+
+				projectionMatrix.n11 = 2 * _near / ( xmax - xmin );
 				projectionMatrix.n13 = ( xmax + xmin ) / ( xmax - xmin );
-				_cameraL.projectionMatrix = projectionMatrix.clone();
 
-				//for right eye
+				_cameraL.projectionMatrix.copy( projectionMatrix );
+
+				// for right eye
 
-				xmin = -ymax * aspect - eyeSepOnProjection;
-				xmax = ymax * aspect - eyeSepOnProjection;
-				projectionMatrix.n11 = 2 * near / ( xmax - xmin );
+				xmin = -ymax * _aspect - eyeSepOnProjection;
+				xmax = ymax * _aspect - eyeSepOnProjection;
+
+				projectionMatrix.n11 = 2 * _near / ( xmax - xmin );
 				projectionMatrix.n13 = ( xmax + xmin ) / ( xmax - xmin );
-				_cameraR.projectionMatrix = projectionMatrix.clone();
+
+				_cameraR.projectionMatrix.copy( projectionMatrix );
 
 			}
 
-			_cameraL.matrix = camera.matrixWorld.clone().multiplySelf( eyeLeft );
-			//_cameraL.update( null, true );
+			_cameraL.matrixWorld.copy( camera.matrixWorld ).multiplySelf( eyeLeft );
 			_cameraL.position.copy( camera.position );
-			_cameraL.near = near;
+			_cameraL.near = camera.near;
 			_cameraL.far = camera.far;
+
 			_render.call( _this, scene, _cameraL, _renderTargetL, true );
 
-			_cameraR.matrix = camera.matrixWorld.clone().multiplySelf( eyeRight );
-			//_cameraR.update( null, true );
+			_cameraR.matrixWorld.copy( camera.matrixWorld ).multiplySelf( eyeRight );
 			_cameraR.position.copy( camera.position );
-			_cameraR.near = near;
+			_cameraR.near = camera.near;
 			_cameraR.far = camera.far;
+
 			_render.call( _this, scene, _cameraR, _renderTargetR, true );
 
+			_scene.updateMatrixWorld();
 			_render.call( _this, _scene, _camera );
 
 		};

+ 36 - 25
src/extras/renderers/ParallaxBarrierWebGLRenderer.js

@@ -1,6 +1,7 @@
 /**
  * @author mrdoob / http://mrdoob.com/
  * @author marklundin / http://mark-lundin.com/
+ * @author alteredq / http://alteredqualia.com/
  */
 
 if ( THREE.WebGLRenderer ) {
@@ -9,6 +10,8 @@ if ( THREE.WebGLRenderer ) {
 
 		THREE.WebGLRenderer.call( this, parameters );
 
+		this.autoUpdateScene = false;
+
 		var _this = this, _setSize = this.setSize, _render = this.render;
 
 		var _cameraL = new THREE.PerspectiveCamera(),
@@ -17,7 +20,7 @@ if ( THREE.WebGLRenderer ) {
 		var eyeRight = new THREE.Matrix4(),
 			eyeLeft = new THREE.Matrix4(),
 			focalLength = 125,
-			aspect, near, fov;
+			_aspect, _near, _far, _fov;
 
 		_cameraL.matrixAutoUpdate = _cameraR.matrixAutoUpdate = false;
 
@@ -80,6 +83,8 @@ if ( THREE.WebGLRenderer ) {
 		var _scene = new THREE.Scene();
 		_scene.add( new THREE.Mesh( new THREE.PlaneGeometry( 2, 2 ), _material ) );
 
+		_scene.add( _camera );
+
 		this.setSize = function ( width, height ) {
 
 			_setSize.call( _this, width, height );
@@ -100,59 +105,65 @@ if ( THREE.WebGLRenderer ) {
 
 		this.render = function ( scene, camera, renderTarget, forceClear ) {
 
-			//camera.update( null, true );
+			scene.updateMatrixWorld();
 
-			var hasCameraChanged = aspect !== camera.aspect || near !== camera.near || fov !== camera.fov;
+			var hasCameraChanged = ( _aspect !== camera.aspect ) || ( _near !== camera.near ) || ( _far !== camera.far ) || ( _fov !== camera.fov );
 
 			if( hasCameraChanged ) {
 
-				aspect = camera.aspect;
-				near = camera.near;
-				fov = camera.fov;
+				_aspect = camera.aspect;
+				_near = camera.near;
+				_far = camera.far;
+				_fov = camera.fov;
 
 				var projectionMatrix = camera.projectionMatrix.clone(),
 					eyeSep = focalLength / 30 * 0.5,
-					eyeSepOnProjection = eyeSep * near / focalLength,
-					ymax = near * Math.tan( fov * Math.PI / 360 ),
+					eyeSepOnProjection = eyeSep * _near / focalLength,
+					ymax = _near * Math.tan( _fov * Math.PI / 360 ),
 					xmin, xmax;
 
-				//translate xOffset
+				// translate xOffset
 
 				eyeRight.n14 = eyeSep;
 				eyeLeft.n14 = -eyeSep;
 
-				//For left eye
+				// for left eye
 
-				xmin = -ymax * aspect + eyeSepOnProjection;
-				xmax = ymax * aspect + eyeSepOnProjection;
-				projectionMatrix.n11 = 2 * near / ( xmax - xmin );
+				xmin = -ymax * _aspect + eyeSepOnProjection;
+				xmax = ymax * _aspect + eyeSepOnProjection;
+
+				projectionMatrix.n11 = 2 * _near / ( xmax - xmin );
 				projectionMatrix.n13 = ( xmax + xmin ) / ( xmax - xmin );
-				_cameraL.projectionMatrix = projectionMatrix.clone();
 
-				//for right eye
+				_cameraL.projectionMatrix.copy( projectionMatrix );
+
+				// for right eye
 
-				xmin = -ymax * aspect - eyeSepOnProjection;
-				xmax = ymax * aspect - eyeSepOnProjection;
-				projectionMatrix.n11 = 2 * near / ( xmax - xmin );
+				xmin = -ymax * _aspect - eyeSepOnProjection;
+				xmax = ymax * _aspect - eyeSepOnProjection;
+
+				projectionMatrix.n11 = 2 * _near / ( xmax - xmin );
 				projectionMatrix.n13 = ( xmax + xmin ) / ( xmax - xmin );
-				_cameraR.projectionMatrix = projectionMatrix.clone();
+
+				_cameraR.projectionMatrix.copy( projectionMatrix );
 
 			}
 
-			_cameraL.matrix = camera.matrixWorld.clone().multiplySelf( eyeLeft );
-			//_cameraL.update( null, true );
+			_cameraL.matrixWorld.copy( camera.matrixWorld ).multiplySelf( eyeLeft );
 			_cameraL.position.copy( camera.position );
-			_cameraL.near = near;
+			_cameraL.near = camera.near;
 			_cameraL.far = camera.far;
+
 			_render.call( _this, scene, _cameraL, _renderTargetL, true );
 
-			_cameraR.matrix = camera.matrixWorld.clone().multiplySelf( eyeRight );
-			//_cameraR.update( null, true );
+			_cameraR.matrixWorld.copy( camera.matrixWorld ).multiplySelf( eyeRight );
 			_cameraR.position.copy( camera.position );
-			_cameraR.near = near;
+			_cameraR.near = camera.near;
 			_cameraR.far = camera.far;
+
 			_render.call( _this, scene, _cameraR, _renderTargetR, true );
 
+			_scene.updateMatrixWorld();
 			_render.call( _this, _scene, _camera );
 
 		};

+ 4 - 64
src/objects/Bone.js

@@ -1,5 +1,6 @@
 /**
  * @author mikael emtinger / http://gomo.se/
+ * @author alteredq / http://alteredqualia.com/
  */
 
 THREE.Bone = function( belongsToSkin ) {
@@ -8,7 +9,6 @@ THREE.Bone = function( belongsToSkin ) {
 
 	this.skin = belongsToSkin;
 	this.skinMatrix = new THREE.Matrix4();
-	this.hasNoneBoneChildren = false;
 
 };
 
@@ -17,11 +17,7 @@ THREE.Bone.prototype.constructor = THREE.Bone;
 THREE.Bone.prototype.supr = THREE.Object3D.prototype;
 
 
-/*
- * Update
- */
-
-THREE.Bone.prototype.update = function( parentSkinMatrix, forceUpdate, camera ) {
+THREE.Bone.prototype.update = function( parentSkinMatrix, forceUpdate ) {
 
 	// update local
 
@@ -54,67 +50,11 @@ THREE.Bone.prototype.update = function( parentSkinMatrix, forceUpdate, camera )
 
 	var child, i, l = this.children.length;
 
-	if ( this.hasNoneBoneChildren ) {
-
-		this.matrixWorld.multiply( this.skin.matrixWorld, this.skinMatrix );
-
-
-		for ( i = 0; i < l; i ++ ) {
-
-			child = this.children[ i ];
-
-			if ( ! ( child instanceof THREE.Bone ) ) {
-
-				child.update( this.matrixWorld, true, camera );
-
-			} else {
-
-				child.update( this.skinMatrix, forceUpdate, camera );
-
-			}
-
-		}
-
-	} else {
-
-		for ( i = 0; i < l; i ++ ) {
-
-			this.children[ i ].update( this.skinMatrix, forceUpdate, camera );
-
-		}
-
-	}
-
-};
-
-
-/*
- * Add child
- */
-
-THREE.Bone.prototype.add = function( child ) {
-
-	if ( this.children.indexOf( child ) === - 1 ) {
+	for ( i = 0; i < l; i ++ ) {
 
-		if ( child.parent !== undefined ) {
-
-			child.parent.removeChild( child );
-
-		}
-
-		child.parent = this;
-		this.children.push( child );
-
-		if ( ! ( child instanceof THREE.Bone ) ) {
-
-			this.hasNoneBoneChildren = true;
-
-		}
+		this.children[ i ].update( this.skinMatrix, forceUpdate );
 
 	}
 
 };
 
-/*
- * TODO: Remove Children: see if any remaining are none-Bone
- */

+ 6 - 51
src/objects/LOD.js

@@ -1,5 +1,7 @@
 /**
  * @author mikael emtinger / http://gomo.se/
+ * @author alteredq / http://alteredqualia.com/
+ * @author mr.doob / http://mrdoob.com/
  */
 
 THREE.LOD = function () {
@@ -14,10 +16,6 @@ THREE.LOD.prototype = new THREE.Object3D();
 THREE.LOD.prototype.constructor = THREE.LOD;
 THREE.LOD.prototype.supr = THREE.Object3D.prototype;
 
-/*
- * Add
- */
-
 THREE.LOD.prototype.addLevel = function ( object3D, visibleAtDistance ) {
 
 	if ( visibleAtDistance === undefined ) {
@@ -43,45 +41,11 @@ THREE.LOD.prototype.addLevel = function ( object3D, visibleAtDistance ) {
 
 };
 
-
-/*
- * Update
- */
-
-THREE.LOD.prototype.update = function ( parentMatrixWorld, forceUpdate, camera ) {
-
-	// update local
-
-	if ( this.matrixAutoUpdate ) {
-
-		forceUpdate |= this.updateMatrix();
-
-	}
-
-	// update global
-
-	if ( forceUpdate || this.matrixWorldNeedsUpdate ) {
-
-		if ( parentMatrixWorld ) {
-
-			this.matrixWorld.multiply( parentMatrixWorld, this.matrix );
-
-		} else {
-
-			this.matrixWorld.copy( this.matrix );
-
-		}
-
-		this.matrixWorldNeedsUpdate = false;
-		forceUpdate = true;
-
-	}
-
-
-	// update LODs
+THREE.LOD.prototype.update = function ( camera ) {
 
 	if ( this.LODs.length > 1 ) {
 
+		camera.matrixWorldInverse.getInverse( camera.matrixWorld );
 
 		var inverse  = camera.matrixWorldInverse;
 		var radius   = this.boundRadius * this.boundRadiusScale;
@@ -89,7 +53,7 @@ THREE.LOD.prototype.update = function ( parentMatrixWorld, forceUpdate, camera )
 
 		this.LODs[ 0 ].object3D.visible = true;
 
-		for ( var l = 1; l < this.LODs.length; l++ ) {
+		for ( var l = 1; l < this.LODs.length; l ++ ) {
 
 			if( distance >= this.LODs[ l ].visibleAtDistance ) {
 
@@ -104,7 +68,7 @@ THREE.LOD.prototype.update = function ( parentMatrixWorld, forceUpdate, camera )
 
 		}
 
-		for( ; l < this.LODs.length; l++ ) {
+		for( ; l < this.LODs.length; l ++ ) {
 
 			this.LODs[ l ].object3D.visible = false;
 
@@ -112,13 +76,4 @@ THREE.LOD.prototype.update = function ( parentMatrixWorld, forceUpdate, camera )
 
 	}
 
-	// update children
-
-	for ( var c = 0; c < this.children.length; c++ ) {
-
-		this.children[ c ].update( this.matrixWorld, forceUpdate, camera );
-
-	}
-
-
 };

+ 39 - 60
src/objects/SkinnedMesh.js

@@ -1,5 +1,6 @@
 /**
  * @author mikael emtinger / http://gomo.se/
+ * @author alteredq / http://alteredqualia.com/
  */
 
 THREE.SkinnedMesh = function( geometry, material ) {
@@ -9,6 +10,7 @@ THREE.SkinnedMesh = function( geometry, material ) {
 	// init bones
 
 	this.identityMatrix = new THREE.Matrix4();
+
 	this.bones = [];
 	this.boneMatrices = [];
 
@@ -71,100 +73,74 @@ THREE.SkinnedMesh = function( geometry, material ) {
 THREE.SkinnedMesh.prototype = new THREE.Mesh();
 THREE.SkinnedMesh.prototype.constructor = THREE.SkinnedMesh;
 
+THREE.SkinnedMesh.prototype.addBone = function( bone ) {
 
-/*
- * Update
- */
-
-THREE.SkinnedMesh.prototype.update = function ( parentMatrixWorld, forceUpdate, camera ) {
-
-	// visible?
-
-	if ( this.visible ) {
+	if ( bone === undefined ) {
 
-		// update local
+		bone = new THREE.Bone( this );
 
-		if ( this.matrixAutoUpdate ) {
+	}
 
-			forceUpdate |= this.updateMatrix();
+	this.bones.push( bone );
 
-		}
+	return bone;
 
+};
 
-		// update global
+THREE.SkinnedMesh.prototype.updateMatrixWorld = function ( force ) {
 
-		if ( forceUpdate || this.matrixWorldNeedsUpdate ) {
+	this.matrixAutoUpdate && this.updateMatrix();
 
-			if ( parentMatrixWorld ) {
+	// update matrixWorld
 
-				this.matrixWorld.multiply( parentMatrixWorld, this.matrix );
+	if ( this.matrixWorldNeedsUpdate || force ) {
 
-			} else {
+		if ( this.parent ) {
 
-				this.matrixWorld.copy( this.matrix );
+			this.matrixWorld.multiply( this.parent.matrixWorld, this.matrix );
 
-			}
+		} else {
 
-			this.matrixWorldNeedsUpdate = false;
-			forceUpdate = true;
+			this.matrixWorld.copy( this.matrix );
 
 		}
 
+		this.matrixWorldNeedsUpdate = false;
 
-		// update children
-
-		var child, i, l = this.children.length;
-
-		for ( i = 0; i < l; i ++ ) {
-
-			child = this.children[ i ];
-
-			if ( child instanceof THREE.Bone ) {
+		force = true;
 
-				child.update( this.identityMatrix, false, camera );
-
-			} else {
-
-				child.update( this.matrixWorld, forceUpdate, camera );
+	}
 
-			}
+	// update children
 
-		}
+	for ( var i = 0, l = this.children.length; i < l; i ++ ) {
 
+		var child = this.children[ i ];
 
-		// flatten to array
+		if ( child instanceof THREE.Bone ) {
 
-		var b, bl = this.bones.length;
-			ba = this.bones;
-			bm = this.boneMatrices;
+			child.update( this.identityMatrix, false );
 
-		for ( b = 0; b < bl; b ++ ) {
+		} else {
 
-			ba[ b ].skinMatrix.flattenToArrayOffset( bm, b * 16 );
+			child.updateMatrixWorld( true );
 
 		}
 
 	}
 
-};
+	// flatten bone matrices to array
 
+	var b, bl = this.bones.length;
+		ba = this.bones;
+		bm = this.boneMatrices;
 
-/*
- * Add
- */
+	for ( b = 0; b < bl; b ++ ) {
 
-THREE.SkinnedMesh.prototype.addBone = function( bone ) {
-
-	if ( bone === undefined ) {
-
-		bone = new THREE.Bone( this );
+		ba[ b ].skinMatrix.flattenToArrayOffset( bm, b * 16 );
 
 	}
 
-	this.bones.push( bone );
-
-	return bone;
-
 };
 
 /*
@@ -173,7 +149,7 @@ THREE.SkinnedMesh.prototype.addBone = function( bone ) {
 
 THREE.SkinnedMesh.prototype.pose = function() {
 
-	this.update( undefined, true );
+	this.updateMatrixWorld( true );
 
 	var bim, bone, boneInverses = [];
 
@@ -181,7 +157,10 @@ THREE.SkinnedMesh.prototype.pose = function() {
 
 		bone = this.bones[ b ];
 
-		boneInverses.push( THREE.Matrix4.makeInvert( bone.skinMatrix ) );
+		var inverseMatrix = new THREE.Matrix4();
+		inverseMatrix.getInverse( bone.skinMatrix );
+
+		boneInverses.push( inverseMatrix );
 
 		bone.skinMatrix.flattenToArrayOffset( this.boneMatrices, b * 16 );
 
@@ -215,7 +194,7 @@ THREE.SkinnedMesh.prototype.pose = function() {
 
 			if ( this.geometry.skinWeights[ i ].x + this.geometry.skinWeights[ i ].y !== 1 ) {
 
-				var len = ( 1.0 - ( this.geometry.skinWeights[ i ].x + this.geometry.skinWeights[ i ].y )) * 0.5;
+				var len = ( 1.0 - ( this.geometry.skinWeights[ i ].x + this.geometry.skinWeights[ i ].y ) ) * 0.5;
 				this.geometry.skinWeights[ i ].x += len;
 				this.geometry.skinWeights[ i ].y += len;
 

+ 3 - 3
src/renderers/WebGLRenderer.js

@@ -106,6 +106,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 	this.sortObjects = true;
 
 	this.autoUpdateObjects = true;
+	this.autoUpdateScene = true;
 
 	// physically based shading
 
@@ -3616,7 +3617,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 				}
 
-				scene.updateMatrixWorld();
+				if ( this.autoUpdateScene ) scene.updateMatrixWorld();
 
 				_cameraLight.matrixWorldInverse.getInverse( _cameraLight.matrixWorld );
 
@@ -3804,10 +3805,9 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 		}
 
-		scene.updateMatrixWorld();
+		if ( this.autoUpdateScene )	scene.updateMatrixWorld();
 
 		camera.matrixWorldInverse.getInverse( camera.matrixWorld );
-
 		camera.matrixWorldInverse.flattenToArray( _viewMatrixArray );
 		camera.projectionMatrix.flattenToArray( _projectionMatrixArray );