Ver código fonte

Added `DirectionalLight.autoUpdateExtends` to prevent directional lights to adapt to scene extends

David Catuhe 9 anos atrás
pai
commit
ae8c51e238

Diferenças do arquivo suprimidas por serem muito extensas
+ 12 - 12
dist/preview release/babylon.core.js


+ 58 - 53
dist/preview release/babylon.d.ts

@@ -1525,56 +1525,6 @@ declare module BABYLON {
 }
 
 declare module BABYLON {
-    class Bone extends Node {
-        name: string;
-        children: Bone[];
-        animations: Animation[];
-        private _skeleton;
-        private _matrix;
-        private _baseMatrix;
-        private _worldTransform;
-        private _absoluteTransform;
-        private _invertedAbsoluteTransform;
-        private _parent;
-        constructor(name: string, skeleton: Skeleton, parentBone: Bone, matrix: Matrix);
-        getParent(): Bone;
-        getLocalMatrix(): Matrix;
-        getBaseMatrix(): Matrix;
-        getWorldMatrix(): Matrix;
-        getInvertedAbsoluteTransform(): Matrix;
-        getAbsoluteMatrix(): Matrix;
-        updateMatrix(matrix: Matrix): void;
-        private _updateDifferenceMatrix();
-        markAsDirty(): void;
-    }
-}
-
-declare module BABYLON {
-    class Skeleton {
-        name: string;
-        id: string;
-        bones: Bone[];
-        private _scene;
-        private _isDirty;
-        private _transformMatrices;
-        private _animatables;
-        private _identity;
-        private _ranges;
-        constructor(name: string, id: string, scene: Scene);
-        getTransformMatrices(): Float32Array;
-        getScene(): Scene;
-        createAnimationRange(name: string, from: number, to: number): void;
-        deleteAnimationRange(name: string): void;
-        getAnimationRange(name: string): AnimationRange;
-        beginAnimation(name: string, loop?: boolean, speedRatio?: number, onAnimationEnd?: () => void): void;
-        _markAsDirty(): void;
-        prepare(): void;
-        getAnimatables(): IAnimatable[];
-        clone(name: string, id: string): Skeleton;
-    }
-}
-
-declare module BABYLON {
     class ArcRotateCamera extends TargetCamera {
         alpha: number;
         beta: number;
@@ -1966,6 +1916,56 @@ declare module BABYLON {
 }
 
 declare module BABYLON {
+    class Bone extends Node {
+        name: string;
+        children: Bone[];
+        animations: Animation[];
+        private _skeleton;
+        private _matrix;
+        private _baseMatrix;
+        private _worldTransform;
+        private _absoluteTransform;
+        private _invertedAbsoluteTransform;
+        private _parent;
+        constructor(name: string, skeleton: Skeleton, parentBone: Bone, matrix: Matrix);
+        getParent(): Bone;
+        getLocalMatrix(): Matrix;
+        getBaseMatrix(): Matrix;
+        getWorldMatrix(): Matrix;
+        getInvertedAbsoluteTransform(): Matrix;
+        getAbsoluteMatrix(): Matrix;
+        updateMatrix(matrix: Matrix): void;
+        private _updateDifferenceMatrix();
+        markAsDirty(): void;
+    }
+}
+
+declare module BABYLON {
+    class Skeleton {
+        name: string;
+        id: string;
+        bones: Bone[];
+        private _scene;
+        private _isDirty;
+        private _transformMatrices;
+        private _animatables;
+        private _identity;
+        private _ranges;
+        constructor(name: string, id: string, scene: Scene);
+        getTransformMatrices(): Float32Array;
+        getScene(): Scene;
+        createAnimationRange(name: string, from: number, to: number): void;
+        deleteAnimationRange(name: string): void;
+        getAnimationRange(name: string): AnimationRange;
+        beginAnimation(name: string, loop?: boolean, speedRatio?: number, onAnimationEnd?: () => void): void;
+        _markAsDirty(): void;
+        prepare(): void;
+        getAnimatables(): IAnimatable[];
+        clone(name: string, id: string): Skeleton;
+    }
+}
+
+declare module BABYLON {
     class Collider {
         radius: Vector3;
         retry: number;
@@ -2392,6 +2392,11 @@ declare module BABYLON {
         transformedPosition: Vector3;
         private _worldMatrix;
         shadowOrthoScale: number;
+        autoUpdateExtends: boolean;
+        private _orthoLeft;
+        private _orthoRight;
+        private _orthoTop;
+        private _orthoBottom;
         constructor(name: string, direction: Vector3, scene: Scene);
         getAbsolutePosition(): Vector3;
         setDirectionToTarget(target: Vector3): Vector3;
@@ -6287,6 +6292,9 @@ declare module BABYLON {
     }
 }
 
+declare module BABYLON.Internals {
+}
+
 declare module BABYLON {
     class ShadowGenerator {
         private static _FILTER_NONE;
@@ -6340,9 +6348,6 @@ declare module BABYLON {
     }
 }
 
-declare module BABYLON.Internals {
-}
-
 declare module BABYLON {
     class BaseTexture {
         name: string;

Diferenças do arquivo suprimidas por serem muito extensas
+ 12 - 12
dist/preview release/babylon.js


+ 37 - 29
dist/preview release/babylon.max.js

@@ -8509,6 +8509,12 @@ var BABYLON;
             _super.call(this, name, scene);
             this.direction = direction;
             this.shadowOrthoScale = 0.5;
+            this.autoUpdateExtends = true;
+            // Cache
+            this._orthoLeft = Number.MAX_VALUE;
+            this._orthoRight = Number.MIN_VALUE;
+            this._orthoTop = Number.MIN_VALUE;
+            this._orthoBottom = Number.MAX_VALUE;
             this.position = direction.scale(-1);
         }
         DirectionalLight.prototype.getAbsolutePosition = function () {
@@ -8519,38 +8525,40 @@ var BABYLON;
             return this.direction;
         };
         DirectionalLight.prototype.setShadowProjectionMatrix = function (matrix, viewMatrix, renderList) {
-            var orthoLeft = Number.MAX_VALUE;
-            var orthoRight = Number.MIN_VALUE;
-            var orthoTop = Number.MIN_VALUE;
-            var orthoBottom = Number.MAX_VALUE;
-            var tempVector3 = BABYLON.Vector3.Zero();
             var activeCamera = this.getScene().activeCamera;
             // Check extends
-            for (var meshIndex = 0; meshIndex < renderList.length; meshIndex++) {
-                var mesh = renderList[meshIndex];
-                if (!mesh) {
-                    continue;
-                }
-                var boundingInfo = mesh.getBoundingInfo();
-                if (!boundingInfo) {
-                    continue;
+            if (this.autoUpdateExtends || this._orthoLeft === Number.MAX_VALUE) {
+                var tempVector3 = BABYLON.Vector3.Zero();
+                this._orthoLeft = Number.MAX_VALUE;
+                this._orthoRight = Number.MIN_VALUE;
+                this._orthoTop = Number.MIN_VALUE;
+                this._orthoBottom = Number.MAX_VALUE;
+                for (var meshIndex = 0; meshIndex < renderList.length; meshIndex++) {
+                    var mesh = renderList[meshIndex];
+                    if (!mesh) {
+                        continue;
+                    }
+                    var boundingInfo = mesh.getBoundingInfo();
+                    if (!boundingInfo) {
+                        continue;
+                    }
+                    var boundingBox = boundingInfo.boundingBox;
+                    for (var index = 0; index < boundingBox.vectorsWorld.length; index++) {
+                        BABYLON.Vector3.TransformCoordinatesToRef(boundingBox.vectorsWorld[index], viewMatrix, tempVector3);
+                        if (tempVector3.x < this._orthoLeft)
+                            this._orthoLeft = tempVector3.x;
+                        if (tempVector3.y < this._orthoBottom)
+                            this._orthoBottom = tempVector3.y;
+                        if (tempVector3.x > this._orthoRight)
+                            this._orthoRight = tempVector3.x;
+                        if (tempVector3.y > this._orthoTop)
+                            this._orthoTop = tempVector3.y;
+                    }
                 }
-                var boundingBox = boundingInfo.boundingBox;
-                for (var index = 0; index < boundingBox.vectorsWorld.length; index++) {
-                    BABYLON.Vector3.TransformCoordinatesToRef(boundingBox.vectorsWorld[index], viewMatrix, tempVector3);
-                    if (tempVector3.x < orthoLeft)
-                        orthoLeft = tempVector3.x;
-                    if (tempVector3.y < orthoBottom)
-                        orthoBottom = tempVector3.y;
-                    if (tempVector3.x > orthoRight)
-                        orthoRight = tempVector3.x;
-                    if (tempVector3.y > orthoTop)
-                        orthoTop = tempVector3.y;
-                }
-            }
-            var xOffset = orthoRight - orthoLeft;
-            var yOffset = orthoTop - orthoBottom;
-            BABYLON.Matrix.OrthoOffCenterLHToRef(orthoLeft - xOffset * this.shadowOrthoScale, orthoRight + xOffset * this.shadowOrthoScale, orthoBottom - yOffset * this.shadowOrthoScale, orthoTop + yOffset * this.shadowOrthoScale, -activeCamera.maxZ, activeCamera.maxZ, matrix);
+            }
+            var xOffset = this._orthoRight - this._orthoLeft;
+            var yOffset = this._orthoTop - this._orthoBottom;
+            BABYLON.Matrix.OrthoOffCenterLHToRef(this._orthoLeft - xOffset * this.shadowOrthoScale, this._orthoRight + xOffset * this.shadowOrthoScale, this._orthoBottom - yOffset * this.shadowOrthoScale, this._orthoTop + yOffset * this.shadowOrthoScale, -activeCamera.maxZ, activeCamera.maxZ, matrix);
         };
         DirectionalLight.prototype.supportsVSM = function () {
             return true;

Diferenças do arquivo suprimidas por serem muito extensas
+ 24 - 24
dist/preview release/babylon.noworker.js


+ 1 - 0
dist/preview release/what's new.md

@@ -10,6 +10,7 @@
     - New `Mesh.CreatePolygon()` method ([jerome](https://github.com/jbousquie))
     - Introducing [babylon.core.js](http://doc.babylonjs.com/generals/Framework_versions) ([deltakosh](https://github.com/deltakosh))
   - **Updates**
+    - Added `DirectionalLight.autoUpdateExtends` to prevent directional lights to adapt to scene extends ([deltakosh](https://github.com/deltakosh))
     - Added a new parameter to `debugLayer.show()` to define root element to use ([deltakosh](https://github.com/deltakosh))
     - New `MeshBuilder` class used to create all kind of mesh shapes ([deltakosh](https://github.com/deltakosh))
     - Added `Scene.constantlyUpdateMeshUnderPointer` to improve performance when moving mouse ([deltakosh](https://github.com/deltakosh))

+ 36 - 28
src/Lights/babylon.directionalLight.js

@@ -11,6 +11,12 @@ var BABYLON;
             _super.call(this, name, scene);
             this.direction = direction;
             this.shadowOrthoScale = 0.5;
+            this.autoUpdateExtends = true;
+            // Cache
+            this._orthoLeft = Number.MAX_VALUE;
+            this._orthoRight = Number.MIN_VALUE;
+            this._orthoTop = Number.MIN_VALUE;
+            this._orthoBottom = Number.MAX_VALUE;
             this.position = direction.scale(-1);
         }
         DirectionalLight.prototype.getAbsolutePosition = function () {
@@ -21,38 +27,40 @@ var BABYLON;
             return this.direction;
         };
         DirectionalLight.prototype.setShadowProjectionMatrix = function (matrix, viewMatrix, renderList) {
-            var orthoLeft = Number.MAX_VALUE;
-            var orthoRight = Number.MIN_VALUE;
-            var orthoTop = Number.MIN_VALUE;
-            var orthoBottom = Number.MAX_VALUE;
-            var tempVector3 = BABYLON.Vector3.Zero();
             var activeCamera = this.getScene().activeCamera;
             // Check extends
-            for (var meshIndex = 0; meshIndex < renderList.length; meshIndex++) {
-                var mesh = renderList[meshIndex];
-                if (!mesh) {
-                    continue;
-                }
-                var boundingInfo = mesh.getBoundingInfo();
-                if (!boundingInfo) {
-                    continue;
-                }
-                var boundingBox = boundingInfo.boundingBox;
-                for (var index = 0; index < boundingBox.vectorsWorld.length; index++) {
-                    BABYLON.Vector3.TransformCoordinatesToRef(boundingBox.vectorsWorld[index], viewMatrix, tempVector3);
-                    if (tempVector3.x < orthoLeft)
-                        orthoLeft = tempVector3.x;
-                    if (tempVector3.y < orthoBottom)
-                        orthoBottom = tempVector3.y;
-                    if (tempVector3.x > orthoRight)
-                        orthoRight = tempVector3.x;
-                    if (tempVector3.y > orthoTop)
-                        orthoTop = tempVector3.y;
+            if (this.autoUpdateExtends || this._orthoLeft === Number.MAX_VALUE) {
+                var tempVector3 = BABYLON.Vector3.Zero();
+                this._orthoLeft = Number.MAX_VALUE;
+                this._orthoRight = Number.MIN_VALUE;
+                this._orthoTop = Number.MIN_VALUE;
+                this._orthoBottom = Number.MAX_VALUE;
+                for (var meshIndex = 0; meshIndex < renderList.length; meshIndex++) {
+                    var mesh = renderList[meshIndex];
+                    if (!mesh) {
+                        continue;
+                    }
+                    var boundingInfo = mesh.getBoundingInfo();
+                    if (!boundingInfo) {
+                        continue;
+                    }
+                    var boundingBox = boundingInfo.boundingBox;
+                    for (var index = 0; index < boundingBox.vectorsWorld.length; index++) {
+                        BABYLON.Vector3.TransformCoordinatesToRef(boundingBox.vectorsWorld[index], viewMatrix, tempVector3);
+                        if (tempVector3.x < this._orthoLeft)
+                            this._orthoLeft = tempVector3.x;
+                        if (tempVector3.y < this._orthoBottom)
+                            this._orthoBottom = tempVector3.y;
+                        if (tempVector3.x > this._orthoRight)
+                            this._orthoRight = tempVector3.x;
+                        if (tempVector3.y > this._orthoTop)
+                            this._orthoTop = tempVector3.y;
+                    }
                 }
             }
-            var xOffset = orthoRight - orthoLeft;
-            var yOffset = orthoTop - orthoBottom;
-            BABYLON.Matrix.OrthoOffCenterLHToRef(orthoLeft - xOffset * this.shadowOrthoScale, orthoRight + xOffset * this.shadowOrthoScale, orthoBottom - yOffset * this.shadowOrthoScale, orthoTop + yOffset * this.shadowOrthoScale, -activeCamera.maxZ, activeCamera.maxZ, matrix);
+            var xOffset = this._orthoRight - this._orthoLeft;
+            var yOffset = this._orthoTop - this._orthoBottom;
+            BABYLON.Matrix.OrthoOffCenterLHToRef(this._orthoLeft - xOffset * this.shadowOrthoScale, this._orthoRight + xOffset * this.shadowOrthoScale, this._orthoBottom - yOffset * this.shadowOrthoScale, this._orthoTop + yOffset * this.shadowOrthoScale, -activeCamera.maxZ, activeCamera.maxZ, matrix);
         };
         DirectionalLight.prototype.supportsVSM = function () {
             return true;

+ 43 - 33
src/Lights/babylon.directionalLight.ts

@@ -8,6 +8,14 @@
 
         public shadowOrthoScale = 0.5;
 
+        public autoUpdateExtends = true;
+
+        // Cache
+        private _orthoLeft = Number.MAX_VALUE;
+        private _orthoRight = Number.MIN_VALUE;
+        private _orthoTop = Number.MIN_VALUE;
+        private _orthoBottom = Number.MAX_VALUE;
+
         constructor(name: string, public direction: Vector3, scene: Scene) {
             super(name, scene);
 
@@ -24,54 +32,56 @@
         }
 
         public setShadowProjectionMatrix(matrix: Matrix, viewMatrix: Matrix, renderList: Array<AbstractMesh>): void {
-            var orthoLeft = Number.MAX_VALUE;
-            var orthoRight = Number.MIN_VALUE;
-            var orthoTop = Number.MIN_VALUE;
-            var orthoBottom = Number.MAX_VALUE;
-
-            var tempVector3 = Vector3.Zero();
-
             var activeCamera = this.getScene().activeCamera;
 
             // Check extends
-            for (var meshIndex = 0; meshIndex < renderList.length; meshIndex++) {
-                var mesh = renderList[meshIndex];
+            if (this.autoUpdateExtends || this._orthoLeft === Number.MAX_VALUE) {
+                var tempVector3 = Vector3.Zero();
 
-                if (!mesh) {
-                    continue;
-                }
+                this._orthoLeft = Number.MAX_VALUE;
+                this._orthoRight = Number.MIN_VALUE;
+                this._orthoTop = Number.MIN_VALUE;
+                this._orthoBottom = Number.MAX_VALUE;
 
-                var boundingInfo = mesh.getBoundingInfo();
+                for (var meshIndex = 0; meshIndex < renderList.length; meshIndex++) {
+                    var mesh = renderList[meshIndex];
 
-                if (!boundingInfo) {
-                    continue;
-                }
+                    if (!mesh) {
+                        continue;
+                    }
+
+                    var boundingInfo = mesh.getBoundingInfo();
 
-                var boundingBox = boundingInfo.boundingBox;
+                    if (!boundingInfo) {
+                        continue;
+                    }
 
-                for (var index = 0; index < boundingBox.vectorsWorld.length; index++) {
-                    Vector3.TransformCoordinatesToRef(boundingBox.vectorsWorld[index], viewMatrix, tempVector3);
+                    var boundingBox = boundingInfo.boundingBox;
 
-                    if (tempVector3.x < orthoLeft)
-                        orthoLeft = tempVector3.x;
-                    if (tempVector3.y < orthoBottom)
-                        orthoBottom = tempVector3.y;
+                    for (var index = 0; index < boundingBox.vectorsWorld.length; index++) {
+                        Vector3.TransformCoordinatesToRef(boundingBox.vectorsWorld[index], viewMatrix, tempVector3);
 
-                    if (tempVector3.x > orthoRight)
-                        orthoRight = tempVector3.x;
-                    if (tempVector3.y > orthoTop)
-                        orthoTop = tempVector3.y;
+                        if (tempVector3.x < this._orthoLeft)
+                            this._orthoLeft = tempVector3.x;
+                        if (tempVector3.y < this._orthoBottom)
+                            this._orthoBottom = tempVector3.y;
+
+                        if (tempVector3.x > this._orthoRight)
+                            this._orthoRight = tempVector3.x;
+                        if (tempVector3.y > this._orthoTop)
+                            this._orthoTop = tempVector3.y;
+                    }
                 }
             }
 
-            var xOffset = orthoRight - orthoLeft;
-            var yOffset = orthoTop - orthoBottom;
+            var xOffset = this._orthoRight - this._orthoLeft;
+            var yOffset = this._orthoTop - this._orthoBottom;
 
-            Matrix.OrthoOffCenterLHToRef(   orthoLeft - xOffset * this.shadowOrthoScale, orthoRight + xOffset * this.shadowOrthoScale,
-                                            orthoBottom - yOffset * this.shadowOrthoScale, orthoTop + yOffset * this.shadowOrthoScale,
-                                            -activeCamera.maxZ, activeCamera.maxZ, matrix);
+            Matrix.OrthoOffCenterLHToRef(this._orthoLeft - xOffset * this.shadowOrthoScale, this._orthoRight + xOffset * this.shadowOrthoScale,
+                this._orthoBottom - yOffset * this.shadowOrthoScale, this._orthoTop + yOffset * this.shadowOrthoScale,
+                -activeCamera.maxZ, activeCamera.maxZ, matrix);
         }
-        
+
         public supportsVSM(): boolean {
             return true;
         }