Przeglądaj źródła

Object3D: Honor `matrixWorldNeedsUpdate` in `updateWorldMatrix()`. (#33746)

Michael Herzog 1 tydzień temu
rodzic
commit
dc84b87c9f

+ 2 - 2
src/cameras/Camera.js

@@ -129,9 +129,9 @@ class Camera extends Object3D {
 
 	}
 
-	updateWorldMatrix( updateParents, updateChildren ) {
+	updateWorldMatrix( updateParents, updateChildren, force = false ) {
 
-		super.updateWorldMatrix( updateParents, updateChildren );
+		super.updateWorldMatrix( updateParents, updateChildren, force );
 
 		// exclude scale from view matrix to be glTF conform
 

+ 17 - 7
src/core/Object3D.js

@@ -1208,8 +1208,10 @@ class Object3D extends EventDispatcher {
 	 *
 	 * @param {boolean} [updateParents=false] Whether ancestor nodes should be updated or not.
 	 * @param {boolean} [updateChildren=false] Whether descendant nodes should be updated or not.
+	 * @param {boolean} [force=false] - When set to `true`, a recomputation of world matrices is forced even
+	 * when {@link Object3D#matrixWorldNeedsUpdate} is `false`.
 	 */
-	updateWorldMatrix( updateParents, updateChildren ) {
+	updateWorldMatrix( updateParents, updateChildren, force = false ) {
 
 		const parent = this.parent;
 
@@ -1221,18 +1223,26 @@ class Object3D extends EventDispatcher {
 
 		if ( this.matrixAutoUpdate ) this.updateMatrix();
 
-		if ( this.matrixWorldAutoUpdate === true ) {
+		if ( this.matrixWorldNeedsUpdate || force ) {
+
+			if ( this.matrixWorldAutoUpdate === true ) {
 
-			if ( this.parent === null ) {
+				if ( this.parent === null ) {
 
-				this.matrixWorld.copy( this.matrix );
+					this.matrixWorld.copy( this.matrix );
 
-			} else {
+				} else {
+
+					this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
 
-				this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
+				}
 
 			}
 
+			this.matrixWorldNeedsUpdate = false;
+
+			force = true;
+
 		}
 
 		// make sure descendants are updated
@@ -1245,7 +1255,7 @@ class Object3D extends EventDispatcher {
 
 				const child = children[ i ];
 
-				child.updateWorldMatrix( false, true );
+				child.updateWorldMatrix( false, true, force );
 
 			}
 

+ 2 - 0
src/helpers/DirectionalLightHelper.js

@@ -116,6 +116,8 @@ class DirectionalLightHelper extends Object3D {
 	 */
 	update() {
 
+		this.matrixWorldNeedsUpdate = true;
+
 		this.light.updateWorldMatrix( true, false );
 		this.light.target.updateWorldMatrix( true, false );
 

+ 2 - 0
src/helpers/HemisphereLightHelper.js

@@ -118,6 +118,8 @@ class HemisphereLightHelper extends Object3D {
 
 		}
 
+		this.matrixWorldNeedsUpdate = true;
+
 		this.light.updateWorldMatrix( true, false );
 
 		mesh.lookAt( _vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );

+ 2 - 0
src/helpers/PointLightHelper.js

@@ -76,6 +76,8 @@ class PointLightHelper extends Mesh {
 	 */
 	update() {
 
+		this.matrixWorldNeedsUpdate = true;
+
 		this.light.updateWorldMatrix( true, false );
 
 		if ( this.color !== undefined ) {

+ 1 - 1
src/helpers/SpotLightHelper.js

@@ -125,7 +125,7 @@ class SpotLightHelper extends Object3D {
 
 		}
 
-		this.matrixWorld.copy( this.light.matrixWorld );
+		this.matrixWorldNeedsUpdate = true;
 
 		const coneLength = this.light.distance ? this.light.distance : 1000;
 		const coneWidth = coneLength * Math.tan( this.light.angle );

+ 1 - 0
test/unit/src/core/Object3D.tests.js

@@ -1033,6 +1033,7 @@ export default QUnit.module( 'Core', () => {
 			object.matrixWorld.identity();
 
 			object.matrixAutoUpdate = false;
+			object.matrixWorldNeedsUpdate = true;
 			object.updateWorldMatrix( true, false );
 
 			assert.deepEqual( object.matrix.elements,

粤ICP备19079148号