David Catuhe %!s(int64=5) %!d(string=hai) anos
pai
achega
52cafbea09
Modificáronse 2 ficheiros con 30 adicións e 0 borrados
  1. 1 0
      loaders/src/glTF/2.0/glTFLoader.ts
  2. 29 0
      src/Cameras/targetCamera.ts

+ 1 - 0
loaders/src/glTF/2.0/glTFLoader.ts

@@ -1160,6 +1160,7 @@ export class GLTFLoader implements IGLTFLoader {
         this._babylonScene._blockEntityCollection = this._forAssetContainer;
         const babylonCamera = new FreeCamera(camera.name || `camera${camera.index}`, Vector3.Zero(), this._babylonScene, false);
         this._babylonScene._blockEntityCollection = false;
+        babylonCamera.ignoreParentScaling = true;
 
         babylonCamera.rotation = new Vector3(0, Math.PI, 0);
 

+ 29 - 0
src/Cameras/targetCamera.ts

@@ -15,6 +15,9 @@ export class TargetCamera extends Camera {
     private static _TargetTransformMatrix = new Matrix();
     private static _TargetFocalPoint = new Vector3();
 
+    private _tmpUpVector = Vector3.Zero();
+    private _tmpTargetVector = Vector3.Zero();
+
     /**
      * Define the current direction the camera is moving to
      */
@@ -23,6 +26,11 @@ export class TargetCamera extends Camera {
      * Define the current rotation the camera is rotating to
      */
     public cameraRotation = new Vector2(0, 0);
+
+
+    /** Gets or sets a boolean indicating that the scaling of the parent hierarchy will not be taken in account by the camera */
+    public ignoreParentScaling = false;
+
     /**
      * When set, the up vector of the camera will be updated by the rotation of the camera
      */
@@ -421,6 +429,27 @@ export class TargetCamera extends Camera {
     }
 
     protected _computeViewMatrix(position: Vector3, target: Vector3, up: Vector3): void {
+        if (this.ignoreParentScaling) {
+            if (this.parent) {
+                const parentWorldMatrix = this.parent.getWorldMatrix();
+                Vector3.TransformCoordinatesToRef(position, parentWorldMatrix, this._globalPosition);
+                Vector3.TransformCoordinatesToRef(target, parentWorldMatrix, this._tmpTargetVector);
+                Vector3.TransformNormalToRef(up, parentWorldMatrix, this._tmpUpVector);
+                this._markSyncedWithParent();
+            } else {
+                this._globalPosition.copyFrom(position);
+                this._tmpTargetVector.copyFrom(target);
+                this._tmpUpVector.copyFrom(up);
+            }
+
+            if (this.getScene().useRightHandedSystem) {
+                Matrix.LookAtRHToRef(this._globalPosition, this._tmpTargetVector, this._tmpUpVector, this._viewMatrix);
+            } else {
+                Matrix.LookAtLHToRef(this._globalPosition, this._tmpTargetVector, this._tmpUpVector, this._viewMatrix);
+            }
+            return;
+        }
+
         if (this.getScene().useRightHandedSystem) {
             Matrix.LookAtRHToRef(position, target, up, this._viewMatrix);
         } else {