Browse Source

Added mesh.recomputeNormals()

David Catuhe 8 years ago
parent
commit
d6d31e58c4

File diff suppressed because it is too large
+ 3483 - 3477
dist/preview release/babylon.d.ts


File diff suppressed because it is too large
+ 38 - 38
dist/preview release/babylon.js


+ 84 - 2
dist/preview release/babylon.max.js

@@ -20152,6 +20152,25 @@ var BABYLON;
             return this;
         };
         /**
+         * This method will force the computation of normals for the mesh.
+         * Please note that the mesh must have normals vertex data already.
+         * Returns the Mesh.
+         */
+        Mesh.prototype.recomputeNormals = function () {
+            var positions = this.getVerticesData(BABYLON.VertexBuffer.PositionKind);
+            var indices = this.getIndices();
+            var normals;
+            if (this.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)) {
+                normals = this.getVerticesData(BABYLON.VertexBuffer.NormalKind);
+            }
+            else {
+                normals = [];
+            }
+            BABYLON.VertexData.ComputeNormals(positions, indices, normals);
+            this.updateVerticesData(BABYLON.VertexBuffer.NormalKind, normals, false, false);
+            return this;
+        };
+        /**
          * Creates a un-shared specific occurence of the geometry for the mesh.
          * Returns the Mesh.
          */
@@ -33810,6 +33829,7 @@ var BABYLON;
          */
         function DirectionalLight(name, direction, scene) {
             var _this = _super.call(this, name, scene) || this;
+            _this._shadowFrustumSize = 0;
             _this._shadowOrthoScale = 0.5;
             _this.autoUpdateExtends = true;
             // Cache
@@ -33821,6 +33841,23 @@ var BABYLON;
             _this.direction = direction;
             return _this;
         }
+        Object.defineProperty(DirectionalLight.prototype, "shadowFrustumSize", {
+            /**
+             * Fix frustum size for the shadow generation. This is disabled if the value is 0.
+             */
+            get: function () {
+                return this._shadowFrustumSize;
+            },
+            /**
+             * Specifies a fix frustum size for the shadow generation.
+             */
+            set: function (value) {
+                this._shadowFrustumSize = value;
+                this.forceProjectionMatrixCompute();
+            },
+            enumerable: true,
+            configurable: true
+        });
         Object.defineProperty(DirectionalLight.prototype, "shadowOrthoScale", {
             get: function () {
                 return this._shadowOrthoScale;
@@ -33846,9 +33883,29 @@ var BABYLON;
         };
         /**
          * Sets the passed matrix "matrix" as projection matrix for the shadows cast by the light according to the passed view matrix.
-         * Returns the DirectionalLight.
+         * Returns the DirectionalLight Shadow projection matrix.
          */
         DirectionalLight.prototype._setDefaultShadowProjectionMatrix = function (matrix, viewMatrix, renderList) {
+            if (this.shadowFrustumSize > 0) {
+                this._setDefaultFixedFrustumShadowProjectionMatrix(matrix, viewMatrix);
+            }
+            else {
+                this._setDefaultAutoExtendShadowProjectionMatrix(matrix, viewMatrix, renderList);
+            }
+        };
+        /**
+         * Sets the passed matrix "matrix" as fixed frustum projection matrix for the shadows cast by the light according to the passed view matrix.
+         * Returns the DirectionalLight Shadow projection matrix.
+         */
+        DirectionalLight.prototype._setDefaultFixedFrustumShadowProjectionMatrix = function (matrix, viewMatrix) {
+            var activeCamera = this.getScene().activeCamera;
+            BABYLON.Matrix.OrthoLHToRef(this.shadowFrustumSize, this.shadowFrustumSize, this.shadowMinZ !== undefined ? this.shadowMinZ : activeCamera.minZ, this.shadowMaxZ !== undefined ? this.shadowMaxZ : activeCamera.maxZ, matrix);
+        };
+        /**
+         * Sets the passed matrix "matrix" as auto extend projection matrix for the shadows cast by the light according to the passed view matrix.
+         * Returns the DirectionalLight Shadow projection matrix.
+         */
+        DirectionalLight.prototype._setDefaultAutoExtendShadowProjectionMatrix = function (matrix, viewMatrix, renderList) {
             var activeCamera = this.getScene().activeCamera;
             // Check extends
             if (this.autoUpdateExtends || this._orthoLeft === Number.MAX_VALUE) {
@@ -33907,6 +33964,9 @@ var BABYLON;
     }(BABYLON.ShadowLight));
     __decorate([
         BABYLON.serialize()
+    ], DirectionalLight.prototype, "shadowFrustumSize", null);
+    __decorate([
+        BABYLON.serialize()
     ], DirectionalLight.prototype, "shadowOrthoScale", null);
     __decorate([
         BABYLON.serialize()
@@ -33955,6 +34015,20 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+        Object.defineProperty(SpotLight.prototype, "shadowAngleScale", {
+            get: function () {
+                return this._shadowAngleScale;
+            },
+            /**
+             * Allows scaling the angle of the light for shadow generation only.
+             */
+            set: function (value) {
+                this._shadowAngleScale = value;
+                this.forceProjectionMatrixCompute();
+            },
+            enumerable: true,
+            configurable: true
+        });
         /**
          * Returns the string "SpotLight".
          */
@@ -33973,7 +34047,9 @@ var BABYLON;
          */
         SpotLight.prototype._setDefaultShadowProjectionMatrix = function (matrix, viewMatrix, renderList) {
             var activeCamera = this.getScene().activeCamera;
-            BABYLON.Matrix.PerspectiveFovLHToRef(this.angle, 1.0, this.shadowMinZ !== undefined ? this.shadowMinZ : activeCamera.minZ, this.shadowMaxZ !== undefined ? this.shadowMaxZ : activeCamera.maxZ, matrix);
+            this._shadowAngleScale = this._shadowAngleScale || 1;
+            var angle = this._shadowAngleScale * this._angle;
+            BABYLON.Matrix.PerspectiveFovLHToRef(angle, 1.0, this.shadowMinZ !== undefined ? this.shadowMinZ : activeCamera.minZ, this.shadowMaxZ !== undefined ? this.shadowMaxZ : activeCamera.maxZ, matrix);
         };
         SpotLight.prototype._buildUniformLayout = function () {
             this._uniformBuffer.addUniform("vLightData", 4);
@@ -34007,6 +34083,12 @@ var BABYLON;
     ], SpotLight.prototype, "angle", null);
     __decorate([
         BABYLON.serialize()
+        /**
+         * Allows scaling the angle of the light for shadow generation only.
+         */
+    ], SpotLight.prototype, "shadowAngleScale", null);
+    __decorate([
+        BABYLON.serialize()
     ], SpotLight.prototype, "exponent", void 0);
     BABYLON.SpotLight = SpotLight;
 })(BABYLON || (BABYLON = {}));

File diff suppressed because it is too large
+ 3483 - 3477
dist/preview release/babylon.module.d.ts


File diff suppressed because it is too large
+ 39 - 39
dist/preview release/babylon.worker.js


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

@@ -26,6 +26,7 @@
  - Sepctor.js New WebGL debugger: [more info here](http://spector.babylonjs.com) ([Sebastien Vandenberghe](https://github.com/sebavan))
 
 ### Updates
+- New `mesh.recomputeNormals` function ([deltakosh](https://github.com/deltakosh))
 - New helpers to use ExtrudePolygon. [Demo](http://www.babylonjs-playground.com/#RNCYVM#10) ([Cubees](https://github.com/Cubees))
 - PostProcess can now use alpha blending and share outputs ([deltakosh](https://github.com/deltakosh))
 - Added `ArcRotateCamera.panningInertia` to decouple inertia from panning inertia ([deltakosh](https://github.com/deltakosh))

+ 21 - 0
src/Mesh/babylon.mesh.ts

@@ -805,6 +805,27 @@
         }
 
         /**
+         * This method will force the computation of normals for the mesh.
+         * Please note that the mesh must have normals vertex data already.
+         * Returns the Mesh. 
+         */
+        public recomputeNormals(): Mesh {
+            var positions = this.getVerticesData(VertexBuffer.PositionKind);
+            var indices = this.getIndices();
+            var normals: number[] | Float32Array;
+            
+            if (this.isVerticesDataPresent(VertexBuffer.NormalKind)) {
+                normals = this.getVerticesData(VertexBuffer.NormalKind);
+            } else {
+                normals = [];
+            }
+            VertexData.ComputeNormals(positions, indices, normals);
+            this.updateVerticesData(VertexBuffer.NormalKind, normals, false, false);
+
+            return this;
+        }
+
+        /**
          * Creates a un-shared specific occurence of the geometry for the mesh.  
          * Returns the Mesh.  
          */