瀏覽代碼

Object3D: Respect matrixWorldAutoUpdate in matrix update methods (#28533)

* Object3D: respect matrixWorldAutoUpdate when updateMatrixWorld is called with force=true

* Tests: ensure state is cleaned up between passes

* Object3D: updateMatrixWorld should always reach descendants

* Object3D: respect matrixWorldAutoUpdate in updateWorldMatrix
Cody Bennett 1 年之前
父節點
當前提交
af9ffd1286
共有 2 個文件被更改,包括 25 次插入24 次删除
  1. 21 21
      src/core/Object3D.js
  2. 4 3
      test/unit/src/core/Object3D.tests.js

+ 21 - 21
src/core/Object3D.js

@@ -589,13 +589,17 @@ class Object3D extends EventDispatcher {
 
 		if ( this.matrixWorldNeedsUpdate || force ) {
 
-			if ( this.parent === null ) {
+			if ( this.matrixWorldAutoUpdate === true ) {
 
-				this.matrixWorld.copy( this.matrix );
+				if ( this.parent === null ) {
 
-			} else {
+					this.matrixWorld.copy( this.matrix );
 
-				this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
+				} else {
+
+					this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
+
+				}
 
 			}
 
@@ -605,7 +609,7 @@ class Object3D extends EventDispatcher {
 
 		}
 
-		// update children
+		// make sure descendants are updated if required
 
 		const children = this.children;
 
@@ -613,11 +617,7 @@ class Object3D extends EventDispatcher {
 
 			const child = children[ i ];
 
-			if ( child.matrixWorldAutoUpdate === true || force === true ) {
-
-				child.updateMatrixWorld( force );
-
-			}
+			child.updateMatrixWorld( force );
 
 		}
 
@@ -627,7 +627,7 @@ class Object3D extends EventDispatcher {
 
 		const parent = this.parent;
 
-		if ( updateParents === true && parent !== null && parent.matrixWorldAutoUpdate === true ) {
+		if ( updateParents === true && parent !== null ) {
 
 			parent.updateWorldMatrix( true, false );
 
@@ -635,17 +635,21 @@ class Object3D extends EventDispatcher {
 
 		if ( this.matrixAutoUpdate ) this.updateMatrix();
 
-		if ( this.parent === null ) {
+		if ( this.matrixWorldAutoUpdate === true ) {
 
-			this.matrixWorld.copy( this.matrix );
+			if ( this.parent === null ) {
 
-		} else {
+				this.matrixWorld.copy( this.matrix );
 
-			this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
+			} else {
+
+				this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
+
+			}
 
 		}
 
-		// update children
+		// make sure descendants are updated
 
 		if ( updateChildren === true ) {
 
@@ -655,11 +659,7 @@ class Object3D extends EventDispatcher {
 
 				const child = children[ i ];
 
-				if ( child.matrixWorldAutoUpdate === true ) {
-
-					child.updateWorldMatrix( false, true );
-
-				}
+				child.updateWorldMatrix( false, true );
 
 			}
 

+ 4 - 3
test/unit/src/core/Object3D.tests.js

@@ -987,8 +987,10 @@ export default QUnit.module( 'Core', () => {
 
 			parent.position.set( 3, 2, 1 );
 			parent.updateMatrix();
-			parent.matrixWorldNeedsUpdate = false;
 
+			parent.matrixAutoUpdate = true;
+			child.matrixAutoUpdate = true;
+			parent.matrixWorldNeedsUpdate = true;
 			child.matrixWorldAutoUpdate = false;
 			parent.updateMatrixWorld();
 
@@ -1004,7 +1006,6 @@ export default QUnit.module( 'Core', () => {
 			child.position.set( 0, 0, 0 );
 			parent.position.set( 1, 2, 3 );
 			child.matrixWorldAutoUpdate = true;
-			parent.matrixAutoUpdate = true;
 			parent.updateMatrixWorld();
 
 			assert.deepEqual( child.matrixWorld.elements, [
@@ -1237,7 +1238,7 @@ export default QUnit.module( 'Core', () => {
 			child.matrixWorld.identity();
 			parent.matrixWorld.identity();
 
-			object.updateWorldMatrix( true, true );
+			child.updateWorldMatrix( true, true );
 
 			assert.deepEqual( child.matrixWorld.elements,
 				m.identity().elements,