Kaynağa Gözat

Camera: Exclude scale from view matrix. (#32805)

Michael Herzog 1 ay önce
ebeveyn
işleme
6e4cc1ed26
1 değiştirilmiş dosya ile 32 ekleme ve 2 silme
  1. 32 2
      src/cameras/Camera.js

+ 32 - 2
src/cameras/Camera.js

@@ -1,6 +1,12 @@
 import { WebGLCoordinateSystem } from '../constants.js';
 import { Matrix4 } from '../math/Matrix4.js';
 import { Object3D } from '../core/Object3D.js';
+import { Vector3 } from '../math/Vector3.js';
+import { Quaternion } from '../math/Quaternion.js';
+
+const _position = /*@__PURE__*/ new Vector3();
+const _quaternion = /*@__PURE__*/ new Quaternion();
+const _scale = /*@__PURE__*/ new Vector3();
 
 /**
  * Abstract base class for cameras. This class should always be inherited
@@ -107,7 +113,19 @@ class Camera extends Object3D {
 
 		super.updateMatrixWorld( force );
 
-		this.matrixWorldInverse.copy( this.matrixWorld ).invert();
+		// exclude scale from view matrix to be glTF conform
+
+		this.matrixWorld.decompose( _position, _quaternion, _scale );
+
+		if ( _scale.x === 1 && _scale.y === 1 && _scale.z === 1 ) {
+
+			this.matrixWorldInverse.copy( this.matrixWorld ).invert();
+
+		} else {
+
+			this.matrixWorldInverse.compose( _position, _quaternion, _scale.set( 1, 1, 1 ) ).invert();
+
+		}
 
 	}
 
@@ -115,7 +133,19 @@ class Camera extends Object3D {
 
 		super.updateWorldMatrix( updateParents, updateChildren );
 
-		this.matrixWorldInverse.copy( this.matrixWorld ).invert();
+		// exclude scale from view matrix to be glTF conform
+
+		this.matrixWorld.decompose( _position, _quaternion, _scale );
+
+		if ( _scale.x === 1 && _scale.y === 1 && _scale.z === 1 ) {
+
+			this.matrixWorldInverse.copy( this.matrixWorld ).invert();
+
+		} else {
+
+			this.matrixWorldInverse.compose( _position, _quaternion, _scale.set( 1, 1, 1 ) ).invert();
+
+		}
 
 	}
 

粤ICP备19079148号