Преглед на файлове

Fixed an issue with multimat caching

David Catuhe преди 8 години
родител
ревизия
f0515937b5

Файловите разлики са ограничени, защото са твърде много
+ 21 - 21
dist/preview release/babylon.core.js


Файловите разлики са ограничени, защото са твърде много
+ 639 - 515
dist/preview release/babylon.d.ts


Файловите разлики са ограничени, защото са твърде много
+ 31 - 31
dist/preview release/babylon.js


+ 180 - 22
dist/preview release/babylon.max.js

@@ -12864,6 +12864,71 @@ var BABYLON;
         AbstractMesh.prototype.getVerticesData = function (kind) {
             return null;
         };
+        /**
+         * Sets the vertex data of the mesh geometry for the requested `kind`.
+         * If the mesh has no geometry, a new Geometry object is set to the mesh and then passed this vertex data.
+         * The `data` are either a numeric array either a Float32Array.
+         * The parameter `updatable` is passed as is to the underlying Geometry object constructor (if initianilly none) or updater.
+         * The parameter `stride` is an optional positive integer, it is usually automatically deducted from the `kind` (3 for positions or normals, 2 for UV, etc).
+         * Note that a new underlying VertexBuffer object is created each call.
+         * If the `kind` is the `PositionKind`, the mesh BoundingInfo is renewed, so the bounding box and sphere, and the mesh World Matrix is recomputed.
+         *
+         * Possible `kind` values :
+         * - BABYLON.VertexBuffer.PositionKind
+         * - BABYLON.VertexBuffer.UVKind
+         * - BABYLON.VertexBuffer.UV2Kind
+         * - BABYLON.VertexBuffer.UV3Kind
+         * - BABYLON.VertexBuffer.UV4Kind
+         * - BABYLON.VertexBuffer.UV5Kind
+         * - BABYLON.VertexBuffer.UV6Kind
+         * - BABYLON.VertexBuffer.ColorKind
+         * - BABYLON.VertexBuffer.MatricesIndicesKind
+         * - BABYLON.VertexBuffer.MatricesIndicesExtraKind
+         * - BABYLON.VertexBuffer.MatricesWeightsKind
+         * - BABYLON.VertexBuffer.MatricesWeightsExtraKind
+         *
+         * Returns the Mesh.
+         */
+        AbstractMesh.prototype.setVerticesData = function (kind, data, updatable, stride) {
+            return null;
+        };
+        /**
+         * Updates the existing vertex data of the mesh geometry for the requested `kind`.
+         * If the mesh has no geometry, it is simply returned as it is.
+         * The `data` are either a numeric array either a Float32Array.
+         * No new underlying VertexBuffer object is created.
+         * If the `kind` is the `PositionKind` and if `updateExtends` is true, the mesh BoundingInfo is renewed, so the bounding box and sphere, and the mesh World Matrix is recomputed.
+         * If the parameter `makeItUnique` is true, a new global geometry is created from this positions and is set to the mesh.
+         *
+         * Possible `kind` values :
+         * - BABYLON.VertexBuffer.PositionKind
+         * - BABYLON.VertexBuffer.UVKind
+         * - BABYLON.VertexBuffer.UV2Kind
+         * - BABYLON.VertexBuffer.UV3Kind
+         * - BABYLON.VertexBuffer.UV4Kind
+         * - BABYLON.VertexBuffer.UV5Kind
+         * - BABYLON.VertexBuffer.UV6Kind
+         * - BABYLON.VertexBuffer.ColorKind
+         * - BABYLON.VertexBuffer.MatricesIndicesKind
+         * - BABYLON.VertexBuffer.MatricesIndicesExtraKind
+         * - BABYLON.VertexBuffer.MatricesWeightsKind
+         * - BABYLON.VertexBuffer.MatricesWeightsExtraKind
+         *
+         * Returns the Mesh.
+         */
+        AbstractMesh.prototype.updateVerticesData = function (kind, data, updateExtends, makeItUnique) {
+            return null;
+        };
+        /**
+         * Sets the mesh indices.
+         * Expects an array populated with integers or a typed array (Int32Array, Uint32Array, Uint16Array).
+         * If the mesh has no geometry, a new Geometry object is created and set to the mesh.
+         * This method creates a new index buffer each call.
+         * Returns the Mesh.
+         */
+        AbstractMesh.prototype.setIndices = function (indices, totalVertices) {
+            return null;
+        };
         /** Returns false by default, used by the class Mesh.
          *  Returns a boolean
         */
@@ -14215,6 +14280,23 @@ var BABYLON;
             }
             return this;
         };
+        /**
+         * Creates new normals data for the mesh.
+         * @param updatable.
+         */
+        AbstractMesh.prototype.createNormals = function (updatable) {
+            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.setVerticesData(BABYLON.VertexBuffer.NormalKind, normals, updatable);
+        };
         return AbstractMesh;
     }(BABYLON.Node));
     // Statics
@@ -23857,6 +23939,80 @@ var BABYLON;
             return this._sourceMesh.getVerticesData(kind, copyWhenShared);
         };
         /**
+         * Sets the vertex data of the mesh geometry for the requested `kind`.
+         * If the mesh has no geometry, a new Geometry object is set to the mesh and then passed this vertex data.
+         * The `data` are either a numeric array either a Float32Array.
+         * The parameter `updatable` is passed as is to the underlying Geometry object constructor (if initianilly none) or updater.
+         * The parameter `stride` is an optional positive integer, it is usually automatically deducted from the `kind` (3 for positions or normals, 2 for UV, etc).
+         * Note that a new underlying VertexBuffer object is created each call.
+         * If the `kind` is the `PositionKind`, the mesh BoundingInfo is renewed, so the bounding box and sphere, and the mesh World Matrix is recomputed.
+         *
+         * Possible `kind` values :
+         * - BABYLON.VertexBuffer.PositionKind
+         * - BABYLON.VertexBuffer.UVKind
+         * - BABYLON.VertexBuffer.UV2Kind
+         * - BABYLON.VertexBuffer.UV3Kind
+         * - BABYLON.VertexBuffer.UV4Kind
+         * - BABYLON.VertexBuffer.UV5Kind
+         * - BABYLON.VertexBuffer.UV6Kind
+         * - BABYLON.VertexBuffer.ColorKind
+         * - BABYLON.VertexBuffer.MatricesIndicesKind
+         * - BABYLON.VertexBuffer.MatricesIndicesExtraKind
+         * - BABYLON.VertexBuffer.MatricesWeightsKind
+         * - BABYLON.VertexBuffer.MatricesWeightsExtraKind
+         *
+         * Returns the Mesh.
+         */
+        InstancedMesh.prototype.setVerticesData = function (kind, data, updatable, stride) {
+            if (this.sourceMesh) {
+                this.sourceMesh.setVerticesData(kind, data, updatable, stride);
+            }
+            return this.sourceMesh;
+        };
+        /**
+         * Updates the existing vertex data of the mesh geometry for the requested `kind`.
+         * If the mesh has no geometry, it is simply returned as it is.
+         * The `data` are either a numeric array either a Float32Array.
+         * No new underlying VertexBuffer object is created.
+         * If the `kind` is the `PositionKind` and if `updateExtends` is true, the mesh BoundingInfo is renewed, so the bounding box and sphere, and the mesh World Matrix is recomputed.
+         * If the parameter `makeItUnique` is true, a new global geometry is created from this positions and is set to the mesh.
+         *
+         * Possible `kind` values :
+         * - BABYLON.VertexBuffer.PositionKind
+         * - BABYLON.VertexBuffer.UVKind
+         * - BABYLON.VertexBuffer.UV2Kind
+         * - BABYLON.VertexBuffer.UV3Kind
+         * - BABYLON.VertexBuffer.UV4Kind
+         * - BABYLON.VertexBuffer.UV5Kind
+         * - BABYLON.VertexBuffer.UV6Kind
+         * - BABYLON.VertexBuffer.ColorKind
+         * - BABYLON.VertexBuffer.MatricesIndicesKind
+         * - BABYLON.VertexBuffer.MatricesIndicesExtraKind
+         * - BABYLON.VertexBuffer.MatricesWeightsKind
+         * - BABYLON.VertexBuffer.MatricesWeightsExtraKind
+         *
+         * Returns the Mesh.
+         */
+        InstancedMesh.prototype.updateVerticesData = function (kind, data, updateExtends, makeItUnique) {
+            if (this.sourceMesh) {
+                this.sourceMesh.updateVerticesData(kind, data, updateExtends, makeItUnique);
+            }
+            return this.sourceMesh;
+        };
+        /**
+         * Sets the mesh indices.
+         * Expects an array populated with integers or a typed array (Int32Array, Uint32Array, Uint16Array).
+         * If the mesh has no geometry, a new Geometry object is created and set to the mesh.
+         * This method creates a new index buffer each call.
+         * Returns the Mesh.
+         */
+        InstancedMesh.prototype.setIndices = function (indices, totalVertices) {
+            if (this.sourceMesh) {
+                this.sourceMesh.setIndices(indices, totalVertices);
+            }
+            return this.sourceMesh;
+        };
+        /**
          * Boolean : True if the mesh owns the requested kind of data.
          */
         InstancedMesh.prototype.isVerticesDataPresent = function (kind) {
@@ -24726,19 +24882,6 @@ var BABYLON;
             }
             return this;
         };
-        Mesh.prototype.createNormals = function (updatable) {
-            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.setVerticesData(BABYLON.VertexBuffer.NormalKind, normals, updatable);
-        };
         /**
          * Creates a un-shared specific occurence of the geometry for the mesh.
          * Returns the Mesh.
@@ -26777,7 +26920,14 @@ var BABYLON;
             var rootMaterial = this._renderingMesh.material;
             if (rootMaterial && rootMaterial instanceof BABYLON.MultiMaterial) {
                 var multiMaterial = rootMaterial;
-                return multiMaterial.getSubMaterial(this.materialIndex);
+                var effectiveMaterial = multiMaterial.getSubMaterial(this.materialIndex);
+                if (this._currentMaterial !== effectiveMaterial) {
+                    this._currentMaterial = effectiveMaterial;
+                    if (this._materialDefines) {
+                        this._materialDefines.markAllAsDirty();
+                    }
+                }
+                return effectiveMaterial;
             }
             if (!rootMaterial) {
                 return this._mesh.getScene().defaultMaterial;
@@ -31035,6 +31185,14 @@ var BABYLON;
         MaterialDefines.prototype.markAsUnprocessed = function () {
             this._isDirty = true;
         };
+        MaterialDefines.prototype.markAllAsDirty = function () {
+            this._areTexturesDirty = true;
+            this._areAttributesDirty = true;
+            this._areLightsDirty = true;
+            this._areFresnelDirty = true;
+            this._areMiscDirty = true;
+            this._isDirty = true;
+        };
         MaterialDefines.prototype.markAsLightDirty = function () {
             this._areLightsDirty = true;
             this._isDirty = true;
@@ -60054,7 +60212,7 @@ var BABYLON;
              * Debug Control allowing to overload the reflectivity color.
              * This as to be use with the overloadedReflectivityIntensity parameter.
              */
-            _this.overloadedReflectivity = new BABYLON.Color3(0.3, 0.3, 0.3);
+            _this.overloadedReflectivity = new BABYLON.Color3(0.0, 0.0, 0.0);
             /**
              * Debug Control indicating how much the overloaded reflectivity color is used against the default one.
              */
@@ -60101,7 +60259,7 @@ var BABYLON;
              * AKA Specular Color in other nomenclature.
              */
             _this.reflectivityColor = new BABYLON.Color3(1, 1, 1);
-            _this.reflectionColor = new BABYLON.Color3(0.5, 0.5, 0.5);
+            _this.reflectionColor = new BABYLON.Color3(0.0, 0.0, 0.0);
             _this.emissiveColor = new BABYLON.Color3(0, 0, 0);
             /**
              * AKA Glossiness in other nomenclature.
@@ -60318,11 +60476,10 @@ var BABYLON;
             }
             var scene = this.getScene();
             var engine = scene.getEngine();
-            var needNormals = false;
             var needUVs = false;
             this._defines.reset();
             if (scene.lightsEnabled && !this.disableLighting) {
-                needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, true, this.maxSimultaneousLights) || needNormals;
+                BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, true, this.maxSimultaneousLights);
             }
             if (!this.checkReadyOnEveryCall) {
                 if (this._renderId === scene.getRenderId()) {
@@ -60363,7 +60520,6 @@ var BABYLON;
                     if (!this.reflectionTexture.isReady()) {
                         return false;
                     }
-                    needNormals = true;
                     this._defines.REFLECTION = true;
                     if (this.reflectionTexture.coordinatesMode === BABYLON.Texture.INVCUBIC_MODE) {
                         this._defines.INVERTCUBICMAP = true;
@@ -60401,7 +60557,6 @@ var BABYLON;
                     }
                     if (this.reflectionTexture instanceof BABYLON.HDRCubeTexture && this.reflectionTexture) {
                         this._defines.USESPHERICALFROMREFLECTIONMAP = true;
-                        needNormals = true;
                         if (this.reflectionTexture.isPMREM) {
                             this._defines.USEPMREMREFLECTION = true;
                         }
@@ -60560,7 +60715,6 @@ var BABYLON;
                     if (this.emissiveFresnelParameters && this.emissiveFresnelParameters.isEnabled) {
                         this._defines.EMISSIVEFRESNEL = true;
                     }
-                    needNormals = true;
                     this._defines.FRESNEL = true;
                 }
             }
@@ -60578,7 +60732,11 @@ var BABYLON;
             }
             // Attribs
             if (mesh) {
-                if (needNormals && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)) {
+                if (!mesh.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)) {
+                    mesh.createNormals(true);
+                    BABYLON.Tools.Warn("PBRMaterial: Normals have been created for the mesh: " + mesh.name);
+                }
+                if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)) {
                     this._defines.NORMAL = true;
                     if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.TangentKind)) {
                         this._defines.TANGENT = true;

Файловите разлики са ограничени, защото са твърде много
+ 639 - 515
dist/preview release/babylon.module.d.ts


Файловите разлики са ограничени, защото са твърде много
+ 31 - 31
dist/preview release/babylon.noworker.js


+ 5 - 5
localDev/src/index.js

@@ -49,20 +49,20 @@ var createScene = function()
     sphere.subMeshes.push(new BABYLON.SubMesh(1, 0, verticesCount, 900, 900, sphere));
     sphere.subMeshes.push(new BABYLON.SubMesh(2, 0, verticesCount, 1800, 2088, sphere));
 
-  //  material0.diffuseTexture = new BABYLON.Texture("textures/misc.jpg", scene, true, true, BABYLON.Texture.BILINEAR_SAMPLINGMODE); 
+ //   material0.diffuseTexture = new BABYLON.Texture("/assets/textures/leopard_fur.jpg", scene, true, true, BABYLON.Texture.BILINEAR_SAMPLINGMODE); 
 
     scene.actionManager = new BABYLON.ActionManager(scene);
     scene.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnKeyUpTrigger, function (evt) {
         if (evt.sourceEvent.key == "t")
         {
-          //  globals.multimat.subMaterials[0].diffuseColor = new BABYLON.Color3(1, 1, 1);
-            globals.multimat.subMaterials[0].diffuseTexture = new BABYLON.Texture("/assets/textures/amiga.jpg", scene, true, true, BABYLON.Texture.BILINEAR_SAMPLINGMODE);
+            globals.multimat.subMaterials[0].diffuseColor = new BABYLON.Color3(1, 1, 1);
+            globals.multimat.subMaterials[0].diffuseTexture = new BABYLON.Texture("/assets/textures/leopard_fur.jpg", scene, true, true, BABYLON.Texture.BILINEAR_SAMPLINGMODE);
         }
         else if (evt.sourceEvent.key == "m")
         {
             var material0 = new BABYLON.StandardMaterial("mat0", scene);
-          //  material0.diffuseColor = new BABYLON.Color3(0, 1, 0);
-            material0.diffuseTexture = new BABYLON.Texture("/assets/textures/amiga.jpg", scene, true, true, BABYLON.Texture.BILINEAR_SAMPLINGMODE);
+            material0.diffuseColor = new BABYLON.Color3(0, 1, 0);
+            material0.diffuseTexture = new BABYLON.Texture("/assets/textures/leopard_fur.jpg", scene, true, true, BABYLON.Texture.BILINEAR_SAMPLINGMODE);
 
             globals.multimat.subMaterials[0] = material0; 
         }

+ 9 - 0
src/Materials/babylon.material.ts

@@ -33,6 +33,15 @@
             this._isDirty = true;
         }
 
+        public markAllAsDirty() {
+            this._areTexturesDirty = true;
+            this._areAttributesDirty = true;
+            this._areLightsDirty = true;
+            this._areFresnelDirty = true;
+            this._areMiscDirty = true;
+            this._isDirty = true;
+        }
+
         public markAsLightDirty() {
             this._areLightsDirty = true;
             this._isDirty = true;

+ 11 - 1
src/Mesh/babylon.subMesh.ts

@@ -17,6 +17,7 @@
 
         public _materialDefines: MaterialDefines;
         private _materialEffect: Effect;
+        private _currentMaterial: Material;
 
         public get effect(): Effect {
             return this._materialEffect;
@@ -91,7 +92,16 @@
 
             if (rootMaterial && rootMaterial instanceof MultiMaterial) {
                 var multiMaterial = <MultiMaterial>rootMaterial;
-                return multiMaterial.getSubMaterial(this.materialIndex);
+                var effectiveMaterial = multiMaterial.getSubMaterial(this.materialIndex);
+
+                if (this._currentMaterial !== effectiveMaterial) {
+                    this._currentMaterial = effectiveMaterial;
+                    if (this._materialDefines) {
+                        this._materialDefines.markAllAsDirty();
+                    }
+                }
+
+                return effectiveMaterial;
             }
 
             if (!rootMaterial) {