Quellcode durchsuchen

SpotLightHelper: Fix offset when adjusting the scene / parent position (#27487)

* SpotLightHelper: Fix offset when adjusting the scene / parent position

* Ensure children matrices are up to date

* move matrix update to update function, simplify

* Formatting

* Ensure parent matrix is up to date

* Remove use of decompose
Garrett Johnson vor 1 Jahr
Ursprung
Commit
1d2ab56161
1 geänderte Dateien mit 18 neuen und 1 gelöschten Zeilen
  1. 18 1
      src/helpers/SpotLightHelper.js

+ 18 - 1
src/helpers/SpotLightHelper.js

@@ -15,7 +15,6 @@ class SpotLightHelper extends Object3D {
 
 		this.light = light;
 
-		this.matrix = light.matrixWorld;
 		this.matrixAutoUpdate = false;
 
 		this.color = color;
@@ -67,6 +66,24 @@ class SpotLightHelper extends Object3D {
 		this.light.updateWorldMatrix( true, false );
 		this.light.target.updateWorldMatrix( true, false );
 
+		// update the local matrix based on the parent and light target transforms
+		if ( this.parent ) {
+
+			this.parent.updateWorldMatrix( true );
+
+			this.matrix
+				.copy( this.parent.matrixWorld )
+				.invert()
+				.multiply( this.light.matrixWorld );
+
+		} else {
+
+			this.matrix.copy( this.light.matrixWorld );
+
+		}
+
+		this.matrixWorld.copy( this.light.matrixWorld );
+
 		const coneLength = this.light.distance ? this.light.distance : 1000;
 		const coneWidth = coneLength * Math.tan( this.light.angle );