Browse Source

Fixing bug with debugLayer and textures

David Catuhe 9 years ago
parent
commit
3ac091f1bc

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


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


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


+ 86 - 76
dist/preview release/babylon.max.js

@@ -19507,51 +19507,53 @@ var BABYLON;
                         this._effect.setColor4("emissiveRightColor", this.emissiveFresnelParameters.rightColor, this.emissiveFresnelParameters.bias);
                     }
                 }
-                // Textures        
-                if (this.diffuseTexture && StandardMaterial.DiffuseTextureEnabled) {
-                    this._effect.setTexture("diffuseSampler", this.diffuseTexture);
-                    this._effect.setFloat2("vDiffuseInfos", this.diffuseTexture.coordinatesIndex, this.diffuseTexture.level);
-                    this._effect.setMatrix("diffuseMatrix", this.diffuseTexture.getTextureMatrix());
-                }
-                if (this.ambientTexture && StandardMaterial.AmbientTextureEnabled) {
-                    this._effect.setTexture("ambientSampler", this.ambientTexture);
-                    this._effect.setFloat2("vAmbientInfos", this.ambientTexture.coordinatesIndex, this.ambientTexture.level);
-                    this._effect.setMatrix("ambientMatrix", this.ambientTexture.getTextureMatrix());
-                }
-                if (this.opacityTexture && StandardMaterial.OpacityTextureEnabled) {
-                    this._effect.setTexture("opacitySampler", this.opacityTexture);
-                    this._effect.setFloat2("vOpacityInfos", this.opacityTexture.coordinatesIndex, this.opacityTexture.level);
-                    this._effect.setMatrix("opacityMatrix", this.opacityTexture.getTextureMatrix());
-                }
-                if (this.reflectionTexture && StandardMaterial.ReflectionTextureEnabled) {
-                    if (this.reflectionTexture.isCube) {
-                        this._effect.setTexture("reflectionCubeSampler", this.reflectionTexture);
+                // Textures     
+                if (scene.texturesEnabled) {
+                    if (this.diffuseTexture && StandardMaterial.DiffuseTextureEnabled) {
+                        this._effect.setTexture("diffuseSampler", this.diffuseTexture);
+                        this._effect.setFloat2("vDiffuseInfos", this.diffuseTexture.coordinatesIndex, this.diffuseTexture.level);
+                        this._effect.setMatrix("diffuseMatrix", this.diffuseTexture.getTextureMatrix());
+                    }
+                    if (this.ambientTexture && StandardMaterial.AmbientTextureEnabled) {
+                        this._effect.setTexture("ambientSampler", this.ambientTexture);
+                        this._effect.setFloat2("vAmbientInfos", this.ambientTexture.coordinatesIndex, this.ambientTexture.level);
+                        this._effect.setMatrix("ambientMatrix", this.ambientTexture.getTextureMatrix());
+                    }
+                    if (this.opacityTexture && StandardMaterial.OpacityTextureEnabled) {
+                        this._effect.setTexture("opacitySampler", this.opacityTexture);
+                        this._effect.setFloat2("vOpacityInfos", this.opacityTexture.coordinatesIndex, this.opacityTexture.level);
+                        this._effect.setMatrix("opacityMatrix", this.opacityTexture.getTextureMatrix());
+                    }
+                    if (this.reflectionTexture && StandardMaterial.ReflectionTextureEnabled) {
+                        if (this.reflectionTexture.isCube) {
+                            this._effect.setTexture("reflectionCubeSampler", this.reflectionTexture);
+                        }
+                        else {
+                            this._effect.setTexture("reflection2DSampler", this.reflectionTexture);
+                        }
+                        this._effect.setMatrix("reflectionMatrix", this.reflectionTexture.getReflectionTextureMatrix());
+                        this._effect.setFloat2("vReflectionInfos", this.reflectionTexture.level, this.roughness);
                     }
-                    else {
-                        this._effect.setTexture("reflection2DSampler", this.reflectionTexture);
+                    if (this.emissiveTexture && StandardMaterial.EmissiveTextureEnabled) {
+                        this._effect.setTexture("emissiveSampler", this.emissiveTexture);
+                        this._effect.setFloat2("vEmissiveInfos", this.emissiveTexture.coordinatesIndex, this.emissiveTexture.level);
+                        this._effect.setMatrix("emissiveMatrix", this.emissiveTexture.getTextureMatrix());
+                    }
+                    if (this.lightmapTexture && StandardMaterial.LightmapEnabled) {
+                        this._effect.setTexture("lightmapSampler", this.lightmapTexture);
+                        this._effect.setFloat2("vLightmapInfos", this.lightmapTexture.coordinatesIndex, this.lightmapTexture.level);
+                        this._effect.setMatrix("lightmapMatrix", this.lightmapTexture.getTextureMatrix());
+                    }
+                    if (this.specularTexture && StandardMaterial.SpecularTextureEnabled) {
+                        this._effect.setTexture("specularSampler", this.specularTexture);
+                        this._effect.setFloat2("vSpecularInfos", this.specularTexture.coordinatesIndex, this.specularTexture.level);
+                        this._effect.setMatrix("specularMatrix", this.specularTexture.getTextureMatrix());
+                    }
+                    if (this.bumpTexture && scene.getEngine().getCaps().standardDerivatives && StandardMaterial.BumpTextureEnabled) {
+                        this._effect.setTexture("bumpSampler", this.bumpTexture);
+                        this._effect.setFloat2("vBumpInfos", this.bumpTexture.coordinatesIndex, 1.0 / this.bumpTexture.level);
+                        this._effect.setMatrix("bumpMatrix", this.bumpTexture.getTextureMatrix());
                     }
-                    this._effect.setMatrix("reflectionMatrix", this.reflectionTexture.getReflectionTextureMatrix());
-                    this._effect.setFloat2("vReflectionInfos", this.reflectionTexture.level, this.roughness);
-                }
-                if (this.emissiveTexture && StandardMaterial.EmissiveTextureEnabled) {
-                    this._effect.setTexture("emissiveSampler", this.emissiveTexture);
-                    this._effect.setFloat2("vEmissiveInfos", this.emissiveTexture.coordinatesIndex, this.emissiveTexture.level);
-                    this._effect.setMatrix("emissiveMatrix", this.emissiveTexture.getTextureMatrix());
-                }
-                if (this.lightmapTexture && StandardMaterial.LightmapEnabled) {
-                    this._effect.setTexture("lightmapSampler", this.lightmapTexture);
-                    this._effect.setFloat2("vLightmapInfos", this.lightmapTexture.coordinatesIndex, this.lightmapTexture.level);
-                    this._effect.setMatrix("lightmapMatrix", this.lightmapTexture.getTextureMatrix());
-                }
-                if (this.specularTexture && StandardMaterial.SpecularTextureEnabled) {
-                    this._effect.setTexture("specularSampler", this.specularTexture);
-                    this._effect.setFloat2("vSpecularInfos", this.specularTexture.coordinatesIndex, this.specularTexture.level);
-                    this._effect.setMatrix("specularMatrix", this.specularTexture.getTextureMatrix());
-                }
-                if (this.bumpTexture && scene.getEngine().getCaps().standardDerivatives && StandardMaterial.BumpTextureEnabled) {
-                    this._effect.setTexture("bumpSampler", this.bumpTexture);
-                    this._effect.setFloat2("vBumpInfos", this.bumpTexture.coordinatesIndex, 1.0 / this.bumpTexture.level);
-                    this._effect.setMatrix("bumpMatrix", this.bumpTexture.getTextureMatrix());
                 }
                 // Clip plane
                 if (scene.clipPlane) {
@@ -19855,10 +19857,16 @@ var BABYLON;
             }
             return true;
         };
-        MultiMaterial.prototype.clone = function (name) {
+        MultiMaterial.prototype.clone = function (name, cloneChildren) {
             var newMultiMaterial = new MultiMaterial(name, this.getScene());
             for (var index = 0; index < this.subMaterials.length; index++) {
-                var subMaterial = this.subMaterials[index];
+                var subMaterial = null;
+                if (cloneChildren) {
+                    subMaterial = this.subMaterials[index].clone(name + "-" + this.subMaterials[index].name);
+                }
+                else {
+                    subMaterial = this.subMaterials[index];
+                }
                 newMultiMaterial.subMaterials.push(subMaterial);
             }
             return newMultiMaterial;
@@ -20067,7 +20075,7 @@ var BABYLON;
     var Internals;
     (function (Internals) {
         var parseMaterialById = function (id, parsedData, scene, rootUrl) {
-            for (var index = 0; index < parsedData.materials.length; index++) {
+            for (var index = 0, cache = parsedData.materials.length; index < cache; index++) {
                 var parsedMaterial = parsedData.materials[index];
                 if (parsedMaterial.id === id) {
                     return BABYLON.Material.Parse(parsedMaterial, scene, rootUrl);
@@ -20097,7 +20105,8 @@ var BABYLON;
                 var loadedMaterialsIds = [];
                 var hierarchyIds = [];
                 var index;
-                for (index = 0; index < parsedData.meshes.length; index++) {
+                var cache;
+                for (index = 0, cache = parsedData.meshes.length; index < cache; index++) {
                     var parsedMesh = parsedData.meshes[index];
                     if (!meshesNames || isDescendantOf(parsedMesh, meshesNames, hierarchyIds)) {
                         if (meshesNames instanceof Array) {
@@ -20157,10 +20166,10 @@ var BABYLON;
                         if (parsedMesh.materialId) {
                             var materialFound = (loadedMaterialsIds.indexOf(parsedMesh.materialId) !== -1);
                             if (!materialFound && parsedData.multiMaterials) {
-                                for (var multimatIndex = 0; multimatIndex < parsedData.multiMaterials.length; multimatIndex++) {
+                                for (var multimatIndex = 0, multimatCache = parsedData.multiMaterials.length; multimatIndex < multimatCache; multimatIndex++) {
                                     var parsedMultiMaterial = parsedData.multiMaterials[multimatIndex];
                                     if (parsedMultiMaterial.id === parsedMesh.materialId) {
-                                        for (var matIndex = 0; matIndex < parsedMultiMaterial.materials.length; matIndex++) {
+                                        for (var matIndex = 0, matCache = parsedMultiMaterial.materials.length; matIndex < matCache; matIndex++) {
                                             var subMatId = parsedMultiMaterial.materials[matIndex];
                                             loadedMaterialsIds.push(subMatId);
                                             parseMaterialById(subMatId, parsedData, scene, rootUrl);
@@ -20183,7 +20192,7 @@ var BABYLON;
                         if (parsedMesh.skeletonId > -1 && scene.skeletons) {
                             var skeletonAlreadyLoaded = (loadedSkeletonsIds.indexOf(parsedMesh.skeletonId) > -1);
                             if (!skeletonAlreadyLoaded) {
-                                for (var skeletonIndex = 0; skeletonIndex < parsedData.skeletons.length; skeletonIndex++) {
+                                for (var skeletonIndex = 0, skeletonCache = parsedData.skeletons.length; skeletonIndex < skeletonCache; skeletonIndex++) {
                                     var parsedSkeleton = parsedData.skeletons[skeletonIndex];
                                     if (parsedSkeleton.id === parsedMesh.skeletonId) {
                                         skeletons.push(BABYLON.Skeleton.Parse(parsedSkeleton, scene));
@@ -20198,7 +20207,7 @@ var BABYLON;
                 }
                 // Connecting parents
                 var currentMesh;
-                for (index = 0; index < scene.meshes.length; index++) {
+                for (index = 0, cache = scene.meshes.length; index < cache; index++) {
                     currentMesh = scene.meshes[index];
                     if (currentMesh._waitingParentId) {
                         currentMesh.parent = scene.getLastEntryByID(currentMesh._waitingParentId);
@@ -20206,7 +20215,7 @@ var BABYLON;
                     }
                 }
                 // freeze world matrix application
-                for (index = 0; index < scene.meshes.length; index++) {
+                for (index = 0, cache = scene.meshes.length; index < cache; index++) {
                     currentMesh = scene.meshes[index];
                     if (currentMesh._waitingFreezeWorldMatrix) {
                         currentMesh.freezeWorldMatrix();
@@ -20215,7 +20224,7 @@ var BABYLON;
                 }
                 // Particles
                 if (parsedData.particleSystems) {
-                    for (index = 0; index < parsedData.particleSystems.length; index++) {
+                    for (index = 0, cache = parsedData.particleSystems.length; index < cache; index++) {
                         var parsedParticleSystem = parsedData.particleSystems[index];
                         if (hierarchyIds.indexOf(parsedParticleSystem.emitterId) !== -1) {
                             particleSystems.push(BABYLON.ParticleSystem.Parse(parsedParticleSystem, scene, rootUrl));
@@ -20260,28 +20269,29 @@ var BABYLON;
                     scene.collisionsEnabled = parsedData.collisionsEnabled;
                 }
                 scene.workerCollisions = !!parsedData.workerCollisions;
-                // Lights
                 var index;
-                for (index = 0; index < parsedData.lights.length; index++) {
+                var cache;
+                // Lights
+                for (index = 0, cache = parsedData.lights.length; index < cache; index++) {
                     var parsedLight = parsedData.lights[index];
                     BABYLON.Light.Parse(parsedLight, scene);
                 }
                 // Materials
                 if (parsedData.materials) {
-                    for (index = 0; index < parsedData.materials.length; index++) {
+                    for (index = 0, cache = parsedData.materials.length; index < cache; index++) {
                         var parsedMaterial = parsedData.materials[index];
                         BABYLON.Material.Parse(parsedMaterial, scene, rootUrl);
                     }
                 }
                 if (parsedData.multiMaterials) {
-                    for (index = 0; index < parsedData.multiMaterials.length; index++) {
+                    for (index = 0, cache = parsedData.multiMaterials.length; index < cache; index++) {
                         var parsedMultiMaterial = parsedData.multiMaterials[index];
                         BABYLON.Material.ParseMultiMaterial(parsedMultiMaterial, scene);
                     }
                 }
                 // Skeletons
                 if (parsedData.skeletons) {
-                    for (index = 0; index < parsedData.skeletons.length; index++) {
+                    for (index = 0, cache = parsedData.skeletons.length; index < cache; index++) {
                         var parsedSkeleton = parsedData.skeletons[index];
                         BABYLON.Skeleton.Parse(parsedSkeleton, scene);
                     }
@@ -20292,7 +20302,7 @@ var BABYLON;
                     // Boxes
                     var boxes = geometries.boxes;
                     if (boxes) {
-                        for (index = 0; index < boxes.length; index++) {
+                        for (index = 0, cache = boxes.length; index < cache; index++) {
                             var parsedBox = boxes[index];
                             BABYLON.Geometry.Primitives.Box.Parse(parsedBox, scene);
                         }
@@ -20300,7 +20310,7 @@ var BABYLON;
                     // Spheres
                     var spheres = geometries.spheres;
                     if (spheres) {
-                        for (index = 0; index < spheres.length; index++) {
+                        for (index = 0, cache = spheres.length; index < cache; index++) {
                             var parsedSphere = spheres[index];
                             BABYLON.Geometry.Primitives.Sphere.Parse(parsedSphere, scene);
                         }
@@ -20308,7 +20318,7 @@ var BABYLON;
                     // Cylinders
                     var cylinders = geometries.cylinders;
                     if (cylinders) {
-                        for (index = 0; index < cylinders.length; index++) {
+                        for (index = 0, cache = cylinders.length; index < cache; index++) {
                             var parsedCylinder = cylinders[index];
                             BABYLON.Geometry.Primitives.Cylinder.Parse(parsedCylinder, scene);
                         }
@@ -20316,7 +20326,7 @@ var BABYLON;
                     // Toruses
                     var toruses = geometries.toruses;
                     if (toruses) {
-                        for (index = 0; index < toruses.length; index++) {
+                        for (index = 0, cache = toruses.length; index < cache; index++) {
                             var parsedTorus = toruses[index];
                             BABYLON.Geometry.Primitives.Torus.Parse(parsedTorus, scene);
                         }
@@ -20324,7 +20334,7 @@ var BABYLON;
                     // Grounds
                     var grounds = geometries.grounds;
                     if (grounds) {
-                        for (index = 0; index < grounds.length; index++) {
+                        for (index = 0, cache = grounds.length; index < cache; index++) {
                             var parsedGround = grounds[index];
                             BABYLON.Geometry.Primitives.Ground.Parse(parsedGround, scene);
                         }
@@ -20332,7 +20342,7 @@ var BABYLON;
                     // Planes
                     var planes = geometries.planes;
                     if (planes) {
-                        for (index = 0; index < planes.length; index++) {
+                        for (index = 0, cache = planes.length; index < cache; index++) {
                             var parsedPlane = planes[index];
                             BABYLON.Geometry.Primitives.Plane.Parse(parsedPlane, scene);
                         }
@@ -20340,7 +20350,7 @@ var BABYLON;
                     // TorusKnots
                     var torusKnots = geometries.torusKnots;
                     if (torusKnots) {
-                        for (index = 0; index < torusKnots.length; index++) {
+                        for (index = 0, cache = torusKnots.length; index < cache; index++) {
                             var parsedTorusKnot = torusKnots[index];
                             BABYLON.Geometry.Primitives.TorusKnot.Parse(parsedTorusKnot, scene);
                         }
@@ -20348,19 +20358,19 @@ var BABYLON;
                     // VertexData
                     var vertexData = geometries.vertexData;
                     if (vertexData) {
-                        for (index = 0; index < vertexData.length; index++) {
+                        for (index = 0, cache = vertexData.length; index < cache; index++) {
                             var parsedVertexData = vertexData[index];
                             BABYLON.Geometry.Parse(parsedVertexData, scene, rootUrl);
                         }
                     }
                 }
                 // Meshes
-                for (index = 0; index < parsedData.meshes.length; index++) {
+                for (index = 0, cache = parsedData.meshes.length; index < cache; index++) {
                     var parsedMesh = parsedData.meshes[index];
                     BABYLON.Mesh.Parse(parsedMesh, scene, rootUrl);
                 }
                 // Cameras
-                for (index = 0; index < parsedData.cameras.length; index++) {
+                for (index = 0, cache = parsedData.cameras.length; index < cache; index++) {
                     var parsedCamera = parsedData.cameras[index];
                     BABYLON.Camera.Parse(parsedCamera, scene);
                 }
@@ -20368,14 +20378,14 @@ var BABYLON;
                     scene.setActiveCameraByID(parsedData.activeCameraID);
                 }
                 // Browsing all the graph to connect the dots
-                for (index = 0; index < scene.cameras.length; index++) {
+                for (index = 0, cache = scene.cameras.length; index < cache; index++) {
                     var camera = scene.cameras[index];
                     if (camera._waitingParentId) {
                         camera.parent = scene.getLastEntryByID(camera._waitingParentId);
                         camera._waitingParentId = undefined;
                     }
                 }
-                for (index = 0; index < scene.lights.length; index++) {
+                for (index = 0, cache = scene.lights.length; index < cache; index++) {
                     var light = scene.lights[index];
                     if (light._waitingParentId) {
                         light.parent = scene.getLastEntryByID(light._waitingParentId);
@@ -20384,7 +20394,7 @@ var BABYLON;
                 }
                 // Sounds
                 if (BABYLON.AudioEngine && parsedData.sounds) {
-                    for (index = 0; index < parsedData.sounds.length; index++) {
+                    for (index = 0, cache = parsedData.sounds.length; index < cache; index++) {
                         var parsedSound = parsedData.sounds[index];
                         if (BABYLON.Engine.audioEngine.canUseWebAudio) {
                             BABYLON.Sound.Parse(parsedSound, scene, rootUrl);
@@ -20395,7 +20405,7 @@ var BABYLON;
                     }
                 }
                 // Connect parents & children and parse actions
-                for (index = 0; index < scene.meshes.length; index++) {
+                for (index = 0, cache = scene.meshes.length; index < cache; index++) {
                     var mesh = scene.meshes[index];
                     if (mesh._waitingParentId) {
                         mesh.parent = scene.getLastEntryByID(mesh._waitingParentId);
@@ -20407,7 +20417,7 @@ var BABYLON;
                     }
                 }
                 // freeze world matrix application
-                for (index = 0; index < scene.meshes.length; index++) {
+                for (index = 0, cache = scene.meshes.length; index < cache; index++) {
                     var currentMesh = scene.meshes[index];
                     if (currentMesh._waitingFreezeWorldMatrix) {
                         currentMesh.freezeWorldMatrix();
@@ -20416,21 +20426,21 @@ var BABYLON;
                 }
                 // Particles Systems
                 if (parsedData.particleSystems) {
-                    for (index = 0; index < parsedData.particleSystems.length; index++) {
+                    for (index = 0, cache = parsedData.particleSystems.length; index < cache; index++) {
                         var parsedParticleSystem = parsedData.particleSystems[index];
                         BABYLON.ParticleSystem.Parse(parsedParticleSystem, scene, rootUrl);
                     }
                 }
                 // Lens flares
                 if (parsedData.lensFlareSystems) {
-                    for (index = 0; index < parsedData.lensFlareSystems.length; index++) {
+                    for (index = 0, cache = parsedData.lensFlareSystems.length; index < cache; index++) {
                         var parsedLensFlareSystem = parsedData.lensFlareSystems[index];
                         BABYLON.LensFlareSystem.Parse(parsedLensFlareSystem, scene, rootUrl);
                     }
                 }
                 // Shadows
                 if (parsedData.shadowGenerators) {
-                    for (index = 0; index < parsedData.shadowGenerators.length; index++) {
+                    for (index = 0, cache = parsedData.shadowGenerators.length; index < cache; index++) {
                         var parsedShadowGenerator = parsedData.shadowGenerators[index];
                         BABYLON.ShadowGenerator.Parse(parsedShadowGenerator, scene);
                     }

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


+ 33 - 31
src/Loading/Plugins/babylon.babylonFileLoader.js

@@ -3,7 +3,7 @@ var BABYLON;
     var Internals;
     (function (Internals) {
         var parseMaterialById = function (id, parsedData, scene, rootUrl) {
-            for (var index = 0; index < parsedData.materials.length; index++) {
+            for (var index = 0, cache = parsedData.materials.length; index < cache; index++) {
                 var parsedMaterial = parsedData.materials[index];
                 if (parsedMaterial.id === id) {
                     return BABYLON.Material.Parse(parsedMaterial, scene, rootUrl);
@@ -33,7 +33,8 @@ var BABYLON;
                 var loadedMaterialsIds = [];
                 var hierarchyIds = [];
                 var index;
-                for (index = 0; index < parsedData.meshes.length; index++) {
+                var cache;
+                for (index = 0, cache = parsedData.meshes.length; index < cache; index++) {
                     var parsedMesh = parsedData.meshes[index];
                     if (!meshesNames || isDescendantOf(parsedMesh, meshesNames, hierarchyIds)) {
                         if (meshesNames instanceof Array) {
@@ -93,10 +94,10 @@ var BABYLON;
                         if (parsedMesh.materialId) {
                             var materialFound = (loadedMaterialsIds.indexOf(parsedMesh.materialId) !== -1);
                             if (!materialFound && parsedData.multiMaterials) {
-                                for (var multimatIndex = 0; multimatIndex < parsedData.multiMaterials.length; multimatIndex++) {
+                                for (var multimatIndex = 0, multimatCache = parsedData.multiMaterials.length; multimatIndex < multimatCache; multimatIndex++) {
                                     var parsedMultiMaterial = parsedData.multiMaterials[multimatIndex];
                                     if (parsedMultiMaterial.id === parsedMesh.materialId) {
-                                        for (var matIndex = 0; matIndex < parsedMultiMaterial.materials.length; matIndex++) {
+                                        for (var matIndex = 0, matCache = parsedMultiMaterial.materials.length; matIndex < matCache; matIndex++) {
                                             var subMatId = parsedMultiMaterial.materials[matIndex];
                                             loadedMaterialsIds.push(subMatId);
                                             parseMaterialById(subMatId, parsedData, scene, rootUrl);
@@ -119,7 +120,7 @@ var BABYLON;
                         if (parsedMesh.skeletonId > -1 && scene.skeletons) {
                             var skeletonAlreadyLoaded = (loadedSkeletonsIds.indexOf(parsedMesh.skeletonId) > -1);
                             if (!skeletonAlreadyLoaded) {
-                                for (var skeletonIndex = 0; skeletonIndex < parsedData.skeletons.length; skeletonIndex++) {
+                                for (var skeletonIndex = 0, skeletonCache = parsedData.skeletons.length; skeletonIndex < skeletonCache; skeletonIndex++) {
                                     var parsedSkeleton = parsedData.skeletons[skeletonIndex];
                                     if (parsedSkeleton.id === parsedMesh.skeletonId) {
                                         skeletons.push(BABYLON.Skeleton.Parse(parsedSkeleton, scene));
@@ -134,7 +135,7 @@ var BABYLON;
                 }
                 // Connecting parents
                 var currentMesh;
-                for (index = 0; index < scene.meshes.length; index++) {
+                for (index = 0, cache = scene.meshes.length; index < cache; index++) {
                     currentMesh = scene.meshes[index];
                     if (currentMesh._waitingParentId) {
                         currentMesh.parent = scene.getLastEntryByID(currentMesh._waitingParentId);
@@ -142,7 +143,7 @@ var BABYLON;
                     }
                 }
                 // freeze world matrix application
-                for (index = 0; index < scene.meshes.length; index++) {
+                for (index = 0, cache = scene.meshes.length; index < cache; index++) {
                     currentMesh = scene.meshes[index];
                     if (currentMesh._waitingFreezeWorldMatrix) {
                         currentMesh.freezeWorldMatrix();
@@ -151,7 +152,7 @@ var BABYLON;
                 }
                 // Particles
                 if (parsedData.particleSystems) {
-                    for (index = 0; index < parsedData.particleSystems.length; index++) {
+                    for (index = 0, cache = parsedData.particleSystems.length; index < cache; index++) {
                         var parsedParticleSystem = parsedData.particleSystems[index];
                         if (hierarchyIds.indexOf(parsedParticleSystem.emitterId) !== -1) {
                             particleSystems.push(BABYLON.ParticleSystem.Parse(parsedParticleSystem, scene, rootUrl));
@@ -196,28 +197,29 @@ var BABYLON;
                     scene.collisionsEnabled = parsedData.collisionsEnabled;
                 }
                 scene.workerCollisions = !!parsedData.workerCollisions;
-                // Lights
                 var index;
-                for (index = 0; index < parsedData.lights.length; index++) {
+                var cache;
+                // Lights
+                for (index = 0, cache = parsedData.lights.length; index < cache; index++) {
                     var parsedLight = parsedData.lights[index];
                     BABYLON.Light.Parse(parsedLight, scene);
                 }
                 // Materials
                 if (parsedData.materials) {
-                    for (index = 0; index < parsedData.materials.length; index++) {
+                    for (index = 0, cache = parsedData.materials.length; index < cache; index++) {
                         var parsedMaterial = parsedData.materials[index];
                         BABYLON.Material.Parse(parsedMaterial, scene, rootUrl);
                     }
                 }
                 if (parsedData.multiMaterials) {
-                    for (index = 0; index < parsedData.multiMaterials.length; index++) {
+                    for (index = 0, cache = parsedData.multiMaterials.length; index < cache; index++) {
                         var parsedMultiMaterial = parsedData.multiMaterials[index];
                         BABYLON.Material.ParseMultiMaterial(parsedMultiMaterial, scene);
                     }
                 }
                 // Skeletons
                 if (parsedData.skeletons) {
-                    for (index = 0; index < parsedData.skeletons.length; index++) {
+                    for (index = 0, cache = parsedData.skeletons.length; index < cache; index++) {
                         var parsedSkeleton = parsedData.skeletons[index];
                         BABYLON.Skeleton.Parse(parsedSkeleton, scene);
                     }
@@ -228,7 +230,7 @@ var BABYLON;
                     // Boxes
                     var boxes = geometries.boxes;
                     if (boxes) {
-                        for (index = 0; index < boxes.length; index++) {
+                        for (index = 0, cache = boxes.length; index < cache; index++) {
                             var parsedBox = boxes[index];
                             BABYLON.Geometry.Primitives.Box.Parse(parsedBox, scene);
                         }
@@ -236,7 +238,7 @@ var BABYLON;
                     // Spheres
                     var spheres = geometries.spheres;
                     if (spheres) {
-                        for (index = 0; index < spheres.length; index++) {
+                        for (index = 0, cache = spheres.length; index < cache; index++) {
                             var parsedSphere = spheres[index];
                             BABYLON.Geometry.Primitives.Sphere.Parse(parsedSphere, scene);
                         }
@@ -244,7 +246,7 @@ var BABYLON;
                     // Cylinders
                     var cylinders = geometries.cylinders;
                     if (cylinders) {
-                        for (index = 0; index < cylinders.length; index++) {
+                        for (index = 0, cache = cylinders.length; index < cache; index++) {
                             var parsedCylinder = cylinders[index];
                             BABYLON.Geometry.Primitives.Cylinder.Parse(parsedCylinder, scene);
                         }
@@ -252,7 +254,7 @@ var BABYLON;
                     // Toruses
                     var toruses = geometries.toruses;
                     if (toruses) {
-                        for (index = 0; index < toruses.length; index++) {
+                        for (index = 0, cache = toruses.length; index < cache; index++) {
                             var parsedTorus = toruses[index];
                             BABYLON.Geometry.Primitives.Torus.Parse(parsedTorus, scene);
                         }
@@ -260,7 +262,7 @@ var BABYLON;
                     // Grounds
                     var grounds = geometries.grounds;
                     if (grounds) {
-                        for (index = 0; index < grounds.length; index++) {
+                        for (index = 0, cache = grounds.length; index < cache; index++) {
                             var parsedGround = grounds[index];
                             BABYLON.Geometry.Primitives.Ground.Parse(parsedGround, scene);
                         }
@@ -268,7 +270,7 @@ var BABYLON;
                     // Planes
                     var planes = geometries.planes;
                     if (planes) {
-                        for (index = 0; index < planes.length; index++) {
+                        for (index = 0, cache = planes.length; index < cache; index++) {
                             var parsedPlane = planes[index];
                             BABYLON.Geometry.Primitives.Plane.Parse(parsedPlane, scene);
                         }
@@ -276,7 +278,7 @@ var BABYLON;
                     // TorusKnots
                     var torusKnots = geometries.torusKnots;
                     if (torusKnots) {
-                        for (index = 0; index < torusKnots.length; index++) {
+                        for (index = 0, cache = torusKnots.length; index < cache; index++) {
                             var parsedTorusKnot = torusKnots[index];
                             BABYLON.Geometry.Primitives.TorusKnot.Parse(parsedTorusKnot, scene);
                         }
@@ -284,19 +286,19 @@ var BABYLON;
                     // VertexData
                     var vertexData = geometries.vertexData;
                     if (vertexData) {
-                        for (index = 0; index < vertexData.length; index++) {
+                        for (index = 0, cache = vertexData.length; index < cache; index++) {
                             var parsedVertexData = vertexData[index];
                             BABYLON.Geometry.Parse(parsedVertexData, scene, rootUrl);
                         }
                     }
                 }
                 // Meshes
-                for (index = 0; index < parsedData.meshes.length; index++) {
+                for (index = 0, cache = parsedData.meshes.length; index < cache; index++) {
                     var parsedMesh = parsedData.meshes[index];
                     BABYLON.Mesh.Parse(parsedMesh, scene, rootUrl);
                 }
                 // Cameras
-                for (index = 0; index < parsedData.cameras.length; index++) {
+                for (index = 0, cache = parsedData.cameras.length; index < cache; index++) {
                     var parsedCamera = parsedData.cameras[index];
                     BABYLON.Camera.Parse(parsedCamera, scene);
                 }
@@ -304,14 +306,14 @@ var BABYLON;
                     scene.setActiveCameraByID(parsedData.activeCameraID);
                 }
                 // Browsing all the graph to connect the dots
-                for (index = 0; index < scene.cameras.length; index++) {
+                for (index = 0, cache = scene.cameras.length; index < cache; index++) {
                     var camera = scene.cameras[index];
                     if (camera._waitingParentId) {
                         camera.parent = scene.getLastEntryByID(camera._waitingParentId);
                         camera._waitingParentId = undefined;
                     }
                 }
-                for (index = 0; index < scene.lights.length; index++) {
+                for (index = 0, cache = scene.lights.length; index < cache; index++) {
                     var light = scene.lights[index];
                     if (light._waitingParentId) {
                         light.parent = scene.getLastEntryByID(light._waitingParentId);
@@ -320,7 +322,7 @@ var BABYLON;
                 }
                 // Sounds
                 if (BABYLON.AudioEngine && parsedData.sounds) {
-                    for (index = 0; index < parsedData.sounds.length; index++) {
+                    for (index = 0, cache = parsedData.sounds.length; index < cache; index++) {
                         var parsedSound = parsedData.sounds[index];
                         if (BABYLON.Engine.audioEngine.canUseWebAudio) {
                             BABYLON.Sound.Parse(parsedSound, scene, rootUrl);
@@ -331,7 +333,7 @@ var BABYLON;
                     }
                 }
                 // Connect parents & children and parse actions
-                for (index = 0; index < scene.meshes.length; index++) {
+                for (index = 0, cache = scene.meshes.length; index < cache; index++) {
                     var mesh = scene.meshes[index];
                     if (mesh._waitingParentId) {
                         mesh.parent = scene.getLastEntryByID(mesh._waitingParentId);
@@ -343,7 +345,7 @@ var BABYLON;
                     }
                 }
                 // freeze world matrix application
-                for (index = 0; index < scene.meshes.length; index++) {
+                for (index = 0, cache = scene.meshes.length; index < cache; index++) {
                     var currentMesh = scene.meshes[index];
                     if (currentMesh._waitingFreezeWorldMatrix) {
                         currentMesh.freezeWorldMatrix();
@@ -352,21 +354,21 @@ var BABYLON;
                 }
                 // Particles Systems
                 if (parsedData.particleSystems) {
-                    for (index = 0; index < parsedData.particleSystems.length; index++) {
+                    for (index = 0, cache = parsedData.particleSystems.length; index < cache; index++) {
                         var parsedParticleSystem = parsedData.particleSystems[index];
                         BABYLON.ParticleSystem.Parse(parsedParticleSystem, scene, rootUrl);
                     }
                 }
                 // Lens flares
                 if (parsedData.lensFlareSystems) {
-                    for (index = 0; index < parsedData.lensFlareSystems.length; index++) {
+                    for (index = 0, cache = parsedData.lensFlareSystems.length; index < cache; index++) {
                         var parsedLensFlareSystem = parsedData.lensFlareSystems[index];
                         BABYLON.LensFlareSystem.Parse(parsedLensFlareSystem, scene, rootUrl);
                     }
                 }
                 // Shadows
                 if (parsedData.shadowGenerators) {
-                    for (index = 0; index < parsedData.shadowGenerators.length; index++) {
+                    for (index = 0, cache = parsedData.shadowGenerators.length; index < cache; index++) {
                         var parsedShadowGenerator = parsedData.shadowGenerators[index];
                         BABYLON.ShadowGenerator.Parse(parsedShadowGenerator, scene);
                     }

+ 5 - 5
src/Loading/Plugins/babylon.babylonFileLoader.ts

@@ -1,4 +1,4 @@
-module BABYLON.Internals {
+module BABYLON.Internals {
 
     var parseMaterialById = (id, parsedData, scene, rootUrl) => {
         for (var index = 0, cache = parsedData.materials.length; index < cache; index++) {
@@ -34,7 +34,7 @@ module BABYLON.Internals {
             var loadedMaterialsIds = [];
             var hierarchyIds = [];
             var index: number;
-			var cache: number;
+            var cache: number;
             for (index = 0, cache = parsedData.meshes.length; index < cache; index++) {
                 var parsedMesh = parsedData.meshes[index];
 
@@ -210,11 +210,11 @@ module BABYLON.Internals {
             if (parsedData.collisionsEnabled != undefined) {
                 scene.collisionsEnabled = parsedData.collisionsEnabled;
             }
-            scene.workerCollisions = !!parsedData.workerCollisions;            
+            scene.workerCollisions = !!parsedData.workerCollisions;
 
             var index: number;
             var cache: number;
-			// Lights
+            // Lights
             for (index = 0, cache = parsedData.lights.length; index < cache; index++) {
                 var parsedLight = parsedData.lights[index];
                 Light.Parse(parsedLight, scene);
@@ -418,4 +418,4 @@ module BABYLON.Internals {
             return true;
         }
     });
-}
+}

+ 3 - 3
src/Materials/babylon.multiMaterial.ts

@@ -31,13 +31,13 @@
             return true;
         }
 
-        public clone(name: string, cloneChildren?:boolean): MultiMaterial {
+        public clone(name: string, cloneChildren?: boolean): MultiMaterial {
             var newMultiMaterial = new MultiMaterial(name, this.getScene());
 
             for (var index = 0; index < this.subMaterials.length; index++) {
-                var subMaterial : Material = null;
+                var subMaterial: Material = null;
                 if (cloneChildren) {
-                    subMaterial = this.subMaterials[index].clone(name+"-"+this.subMaterials[index].name);
+                    subMaterial = this.subMaterials[index].clone(name + "-" + this.subMaterials[index].name);
                 } else {
                     subMaterial = this.subMaterials[index];
                 }

+ 45 - 43
src/Materials/babylon.standardMaterial.js

@@ -697,51 +697,53 @@ var BABYLON;
                         this._effect.setColor4("emissiveRightColor", this.emissiveFresnelParameters.rightColor, this.emissiveFresnelParameters.bias);
                     }
                 }
-                // Textures        
-                if (this.diffuseTexture && StandardMaterial.DiffuseTextureEnabled) {
-                    this._effect.setTexture("diffuseSampler", this.diffuseTexture);
-                    this._effect.setFloat2("vDiffuseInfos", this.diffuseTexture.coordinatesIndex, this.diffuseTexture.level);
-                    this._effect.setMatrix("diffuseMatrix", this.diffuseTexture.getTextureMatrix());
-                }
-                if (this.ambientTexture && StandardMaterial.AmbientTextureEnabled) {
-                    this._effect.setTexture("ambientSampler", this.ambientTexture);
-                    this._effect.setFloat2("vAmbientInfos", this.ambientTexture.coordinatesIndex, this.ambientTexture.level);
-                    this._effect.setMatrix("ambientMatrix", this.ambientTexture.getTextureMatrix());
-                }
-                if (this.opacityTexture && StandardMaterial.OpacityTextureEnabled) {
-                    this._effect.setTexture("opacitySampler", this.opacityTexture);
-                    this._effect.setFloat2("vOpacityInfos", this.opacityTexture.coordinatesIndex, this.opacityTexture.level);
-                    this._effect.setMatrix("opacityMatrix", this.opacityTexture.getTextureMatrix());
-                }
-                if (this.reflectionTexture && StandardMaterial.ReflectionTextureEnabled) {
-                    if (this.reflectionTexture.isCube) {
-                        this._effect.setTexture("reflectionCubeSampler", this.reflectionTexture);
+                // Textures     
+                if (scene.texturesEnabled) {
+                    if (this.diffuseTexture && StandardMaterial.DiffuseTextureEnabled) {
+                        this._effect.setTexture("diffuseSampler", this.diffuseTexture);
+                        this._effect.setFloat2("vDiffuseInfos", this.diffuseTexture.coordinatesIndex, this.diffuseTexture.level);
+                        this._effect.setMatrix("diffuseMatrix", this.diffuseTexture.getTextureMatrix());
+                    }
+                    if (this.ambientTexture && StandardMaterial.AmbientTextureEnabled) {
+                        this._effect.setTexture("ambientSampler", this.ambientTexture);
+                        this._effect.setFloat2("vAmbientInfos", this.ambientTexture.coordinatesIndex, this.ambientTexture.level);
+                        this._effect.setMatrix("ambientMatrix", this.ambientTexture.getTextureMatrix());
+                    }
+                    if (this.opacityTexture && StandardMaterial.OpacityTextureEnabled) {
+                        this._effect.setTexture("opacitySampler", this.opacityTexture);
+                        this._effect.setFloat2("vOpacityInfos", this.opacityTexture.coordinatesIndex, this.opacityTexture.level);
+                        this._effect.setMatrix("opacityMatrix", this.opacityTexture.getTextureMatrix());
+                    }
+                    if (this.reflectionTexture && StandardMaterial.ReflectionTextureEnabled) {
+                        if (this.reflectionTexture.isCube) {
+                            this._effect.setTexture("reflectionCubeSampler", this.reflectionTexture);
+                        }
+                        else {
+                            this._effect.setTexture("reflection2DSampler", this.reflectionTexture);
+                        }
+                        this._effect.setMatrix("reflectionMatrix", this.reflectionTexture.getReflectionTextureMatrix());
+                        this._effect.setFloat2("vReflectionInfos", this.reflectionTexture.level, this.roughness);
                     }
-                    else {
-                        this._effect.setTexture("reflection2DSampler", this.reflectionTexture);
+                    if (this.emissiveTexture && StandardMaterial.EmissiveTextureEnabled) {
+                        this._effect.setTexture("emissiveSampler", this.emissiveTexture);
+                        this._effect.setFloat2("vEmissiveInfos", this.emissiveTexture.coordinatesIndex, this.emissiveTexture.level);
+                        this._effect.setMatrix("emissiveMatrix", this.emissiveTexture.getTextureMatrix());
+                    }
+                    if (this.lightmapTexture && StandardMaterial.LightmapEnabled) {
+                        this._effect.setTexture("lightmapSampler", this.lightmapTexture);
+                        this._effect.setFloat2("vLightmapInfos", this.lightmapTexture.coordinatesIndex, this.lightmapTexture.level);
+                        this._effect.setMatrix("lightmapMatrix", this.lightmapTexture.getTextureMatrix());
+                    }
+                    if (this.specularTexture && StandardMaterial.SpecularTextureEnabled) {
+                        this._effect.setTexture("specularSampler", this.specularTexture);
+                        this._effect.setFloat2("vSpecularInfos", this.specularTexture.coordinatesIndex, this.specularTexture.level);
+                        this._effect.setMatrix("specularMatrix", this.specularTexture.getTextureMatrix());
+                    }
+                    if (this.bumpTexture && scene.getEngine().getCaps().standardDerivatives && StandardMaterial.BumpTextureEnabled) {
+                        this._effect.setTexture("bumpSampler", this.bumpTexture);
+                        this._effect.setFloat2("vBumpInfos", this.bumpTexture.coordinatesIndex, 1.0 / this.bumpTexture.level);
+                        this._effect.setMatrix("bumpMatrix", this.bumpTexture.getTextureMatrix());
                     }
-                    this._effect.setMatrix("reflectionMatrix", this.reflectionTexture.getReflectionTextureMatrix());
-                    this._effect.setFloat2("vReflectionInfos", this.reflectionTexture.level, this.roughness);
-                }
-                if (this.emissiveTexture && StandardMaterial.EmissiveTextureEnabled) {
-                    this._effect.setTexture("emissiveSampler", this.emissiveTexture);
-                    this._effect.setFloat2("vEmissiveInfos", this.emissiveTexture.coordinatesIndex, this.emissiveTexture.level);
-                    this._effect.setMatrix("emissiveMatrix", this.emissiveTexture.getTextureMatrix());
-                }
-                if (this.lightmapTexture && StandardMaterial.LightmapEnabled) {
-                    this._effect.setTexture("lightmapSampler", this.lightmapTexture);
-                    this._effect.setFloat2("vLightmapInfos", this.lightmapTexture.coordinatesIndex, this.lightmapTexture.level);
-                    this._effect.setMatrix("lightmapMatrix", this.lightmapTexture.getTextureMatrix());
-                }
-                if (this.specularTexture && StandardMaterial.SpecularTextureEnabled) {
-                    this._effect.setTexture("specularSampler", this.specularTexture);
-                    this._effect.setFloat2("vSpecularInfos", this.specularTexture.coordinatesIndex, this.specularTexture.level);
-                    this._effect.setMatrix("specularMatrix", this.specularTexture.getTextureMatrix());
-                }
-                if (this.bumpTexture && scene.getEngine().getCaps().standardDerivatives && StandardMaterial.BumpTextureEnabled) {
-                    this._effect.setTexture("bumpSampler", this.bumpTexture);
-                    this._effect.setFloat2("vBumpInfos", this.bumpTexture.coordinatesIndex, 1.0 / this.bumpTexture.level);
-                    this._effect.setMatrix("bumpMatrix", this.bumpTexture.getTextureMatrix());
                 }
                 // Clip plane
                 if (scene.clipPlane) {

+ 46 - 44
src/Materials/babylon.standardMaterial.ts

@@ -831,65 +831,67 @@
                     }
                 }
 
-                // Textures        
-                if (this.diffuseTexture && StandardMaterial.DiffuseTextureEnabled) {
-                    this._effect.setTexture("diffuseSampler", this.diffuseTexture);
-
-                    this._effect.setFloat2("vDiffuseInfos", this.diffuseTexture.coordinatesIndex, this.diffuseTexture.level);
-                    this._effect.setMatrix("diffuseMatrix", this.diffuseTexture.getTextureMatrix());
-                }
+                // Textures     
+                if (scene.texturesEnabled) {
+                    if (this.diffuseTexture && StandardMaterial.DiffuseTextureEnabled) {
+                        this._effect.setTexture("diffuseSampler", this.diffuseTexture);
 
-                if (this.ambientTexture && StandardMaterial.AmbientTextureEnabled) {
-                    this._effect.setTexture("ambientSampler", this.ambientTexture);
+                        this._effect.setFloat2("vDiffuseInfos", this.diffuseTexture.coordinatesIndex, this.diffuseTexture.level);
+                        this._effect.setMatrix("diffuseMatrix", this.diffuseTexture.getTextureMatrix());
+                    }
 
-                    this._effect.setFloat2("vAmbientInfos", this.ambientTexture.coordinatesIndex, this.ambientTexture.level);
-                    this._effect.setMatrix("ambientMatrix", this.ambientTexture.getTextureMatrix());
-                }
+                    if (this.ambientTexture && StandardMaterial.AmbientTextureEnabled) {
+                        this._effect.setTexture("ambientSampler", this.ambientTexture);
 
-                if (this.opacityTexture && StandardMaterial.OpacityTextureEnabled) {
-                    this._effect.setTexture("opacitySampler", this.opacityTexture);
+                        this._effect.setFloat2("vAmbientInfos", this.ambientTexture.coordinatesIndex, this.ambientTexture.level);
+                        this._effect.setMatrix("ambientMatrix", this.ambientTexture.getTextureMatrix());
+                    }
 
-                    this._effect.setFloat2("vOpacityInfos", this.opacityTexture.coordinatesIndex, this.opacityTexture.level);
-                    this._effect.setMatrix("opacityMatrix", this.opacityTexture.getTextureMatrix());
-                }
+                    if (this.opacityTexture && StandardMaterial.OpacityTextureEnabled) {
+                        this._effect.setTexture("opacitySampler", this.opacityTexture);
 
-                if (this.reflectionTexture && StandardMaterial.ReflectionTextureEnabled) {
-                    if (this.reflectionTexture.isCube) {
-                        this._effect.setTexture("reflectionCubeSampler", this.reflectionTexture);
-                    } else {
-                        this._effect.setTexture("reflection2DSampler", this.reflectionTexture);
+                        this._effect.setFloat2("vOpacityInfos", this.opacityTexture.coordinatesIndex, this.opacityTexture.level);
+                        this._effect.setMatrix("opacityMatrix", this.opacityTexture.getTextureMatrix());
                     }
 
-                    this._effect.setMatrix("reflectionMatrix", this.reflectionTexture.getReflectionTextureMatrix());
-                    this._effect.setFloat2("vReflectionInfos", this.reflectionTexture.level, this.roughness);
-                }
+                    if (this.reflectionTexture && StandardMaterial.ReflectionTextureEnabled) {
+                        if (this.reflectionTexture.isCube) {
+                            this._effect.setTexture("reflectionCubeSampler", this.reflectionTexture);
+                        } else {
+                            this._effect.setTexture("reflection2DSampler", this.reflectionTexture);
+                        }
 
-                if (this.emissiveTexture && StandardMaterial.EmissiveTextureEnabled) {
-                    this._effect.setTexture("emissiveSampler", this.emissiveTexture);
+                        this._effect.setMatrix("reflectionMatrix", this.reflectionTexture.getReflectionTextureMatrix());
+                        this._effect.setFloat2("vReflectionInfos", this.reflectionTexture.level, this.roughness);
+                    }
 
-                    this._effect.setFloat2("vEmissiveInfos", this.emissiveTexture.coordinatesIndex, this.emissiveTexture.level);
-                    this._effect.setMatrix("emissiveMatrix", this.emissiveTexture.getTextureMatrix());
-                }
+                    if (this.emissiveTexture && StandardMaterial.EmissiveTextureEnabled) {
+                        this._effect.setTexture("emissiveSampler", this.emissiveTexture);
 
-                if (this.lightmapTexture && StandardMaterial.LightmapEnabled) {
-                    this._effect.setTexture("lightmapSampler", this.lightmapTexture);
+                        this._effect.setFloat2("vEmissiveInfos", this.emissiveTexture.coordinatesIndex, this.emissiveTexture.level);
+                        this._effect.setMatrix("emissiveMatrix", this.emissiveTexture.getTextureMatrix());
+                    }
 
-                    this._effect.setFloat2("vLightmapInfos", this.lightmapTexture.coordinatesIndex, this.lightmapTexture.level);
-                    this._effect.setMatrix("lightmapMatrix", this.lightmapTexture.getTextureMatrix());
-                }
+                    if (this.lightmapTexture && StandardMaterial.LightmapEnabled) {
+                        this._effect.setTexture("lightmapSampler", this.lightmapTexture);
 
-                if (this.specularTexture && StandardMaterial.SpecularTextureEnabled) {
-                    this._effect.setTexture("specularSampler", this.specularTexture);
+                        this._effect.setFloat2("vLightmapInfos", this.lightmapTexture.coordinatesIndex, this.lightmapTexture.level);
+                        this._effect.setMatrix("lightmapMatrix", this.lightmapTexture.getTextureMatrix());
+                    }
 
-                    this._effect.setFloat2("vSpecularInfos", this.specularTexture.coordinatesIndex, this.specularTexture.level);
-                    this._effect.setMatrix("specularMatrix", this.specularTexture.getTextureMatrix());
-                }
+                    if (this.specularTexture && StandardMaterial.SpecularTextureEnabled) {
+                        this._effect.setTexture("specularSampler", this.specularTexture);
 
-                if (this.bumpTexture && scene.getEngine().getCaps().standardDerivatives && StandardMaterial.BumpTextureEnabled) {
-                    this._effect.setTexture("bumpSampler", this.bumpTexture);
+                        this._effect.setFloat2("vSpecularInfos", this.specularTexture.coordinatesIndex, this.specularTexture.level);
+                        this._effect.setMatrix("specularMatrix", this.specularTexture.getTextureMatrix());
+                    }
+
+                    if (this.bumpTexture && scene.getEngine().getCaps().standardDerivatives && StandardMaterial.BumpTextureEnabled) {
+                        this._effect.setTexture("bumpSampler", this.bumpTexture);
 
-                    this._effect.setFloat2("vBumpInfos", this.bumpTexture.coordinatesIndex, 1.0 / this.bumpTexture.level);
-                    this._effect.setMatrix("bumpMatrix", this.bumpTexture.getTextureMatrix());
+                        this._effect.setFloat2("vBumpInfos", this.bumpTexture.coordinatesIndex, 1.0 / this.bumpTexture.level);
+                        this._effect.setMatrix("bumpMatrix", this.bumpTexture.getTextureMatrix());
+                    }
                 }
 
                 // Clip plane