Просмотр исходного кода

Fixed issues with new bones mechanism

David Catuhe 9 лет назад
Родитель
Сommit
c525dbfdf2

Разница между файлами не показана из-за своего большого размера
+ 19 - 19
dist/preview release/babylon.core.js


Разница между файлами не показана из-за своего большого размера
+ 882 - 862
dist/preview release/babylon.d.ts


Разница между файлами не показана из-за своего большого размера
+ 28 - 28
dist/preview release/babylon.js


Разница между файлами не показана из-за своего большого размера
+ 183 - 41
dist/preview release/babylon.max.js


Разница между файлами не показана из-за своего большого размера
+ 28 - 28
dist/preview release/babylon.noworker.js


+ 0 - 1
src/Audio/babylon.sound.js

@@ -443,4 +443,3 @@ var BABYLON;
     })();
     BABYLON.Sound = Sound;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.sound.js.map

+ 8 - 1
src/Lights/Shadows/babylon.shadowGenerator.js

@@ -244,9 +244,16 @@ var BABYLON;
             if (mesh.useBones && mesh.computeBonesUsingShaders) {
                 attribs.push(BABYLON.VertexBuffer.MatricesIndicesKind);
                 attribs.push(BABYLON.VertexBuffer.MatricesWeightsKind);
-                defines.push("#define BONES");
+                if (mesh.numBoneInfluencers > 4) {
+                    attribs.push(BABYLON.VertexBuffer.MatricesIndicesExtraKind);
+                    attribs.push(BABYLON.VertexBuffer.MatricesWeightsExtraKind);
+                }
+                defines.push("#define NUM_BONE_INFLUENCERS " + mesh.numBoneInfluencers);
                 defines.push("#define BonesPerMesh " + (mesh.skeleton.bones.length + 1));
             }
+            else {
+                defines.push("#define NUM_BONE_INFLUENCERS 0");
+            }
             // Instances
             if (useInstances) {
                 defines.push("#define INSTANCES");

+ 2 - 0
src/Lights/Shadows/babylon.shadowGenerator.ts

@@ -274,6 +274,8 @@
                 }
                 defines.push("#define NUM_BONE_INFLUENCERS " + mesh.numBoneInfluencers);
                 defines.push("#define BonesPerMesh " + (mesh.skeleton.bones.length + 1));
+            } else {
+                defines.push("#define NUM_BONE_INFLUENCERS 0");
             }
 
             // Instances

+ 20 - 0
src/Loading/Plugins/babylon.babylonFileLoader.js

@@ -1084,9 +1084,29 @@ var BABYLON;
                         mesh.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, parsedGeometry.matricesIndices, false);
                     }
                 }
+                if (parsedGeometry.matricesIndicesExtra) {
+                    if (!parsedGeometry.matricesIndicesExtra._isExpanded) {
+                        var floatIndices = [];
+                        for (var i = 0; i < parsedGeometry.matricesIndicesExtra.length; i++) {
+                            var matricesIndex = parsedGeometry.matricesIndicesExtra[i];
+                            floatIndices.push(matricesIndex & 0x000000FF);
+                            floatIndices.push((matricesIndex & 0x0000FF00) >> 8);
+                            floatIndices.push((matricesIndex & 0x00FF0000) >> 16);
+                            floatIndices.push(matricesIndex >> 24);
+                        }
+                        mesh.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesExtraKind, floatIndices, false);
+                    }
+                    else {
+                        delete parsedGeometry.matricesIndices._isExpanded;
+                        mesh.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesExtraKind, parsedGeometry.matricesIndicesExtra, false);
+                    }
+                }
                 if (parsedGeometry.matricesWeights) {
                     mesh.setVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind, parsedGeometry.matricesWeights, false);
                 }
+                if (parsedGeometry.matricesWeightsExtra) {
+                    mesh.setVerticesData(BABYLON.VertexBuffer.MatricesWeightsExtraKind, parsedGeometry.matricesWeightsExtra, false);
+                }
                 mesh.setIndices(parsedGeometry.indices);
             }
             // SubMeshes

+ 12 - 0
src/Materials/babylon.effect.js

@@ -18,6 +18,13 @@ var BABYLON;
             }
             this._defines[rank].push(define);
         };
+        EffectFallbacks.prototype.addCPUSkinningFallback = function (rank, mesh) {
+            this._meshRank = rank;
+            this._mesh = mesh;
+            if (rank > this._maxRank) {
+                this._maxRank = rank;
+            }
+        };
         Object.defineProperty(EffectFallbacks.prototype, "isMoreFallbacks", {
             get: function () {
                 return this._currentRank <= this._maxRank;
@@ -30,6 +37,11 @@ var BABYLON;
             for (var index = 0; index < currentFallbacks.length; index++) {
                 currentDefines = currentDefines.replace("#define " + currentFallbacks[index], "");
             }
+            if (this._mesh && this._currentRank === this._meshRank) {
+                this._mesh.computeBonesUsingShaders = false;
+                currentDefines = currentDefines.replace("#define NUM_BONE_INFLUENCERS " + this._mesh.numBoneInfluencers, "#define NUM_BONE_INFLUENCERS 0");
+                BABYLON.Tools.Log("Falling back to CPU skinning for " + this._mesh.name);
+            }
             this._currentRank++;
             return currentDefines;
         };

+ 7 - 7
src/Materials/babylon.material.js

@@ -21,22 +21,22 @@ var BABYLON;
         MaterialDefines.prototype.reset = function () {
             for (var index = 0; index < this._keys.length; index++) {
                 var prop = this._keys[index];
-                if (prop === "BonesPerMesh") {
+                if (typeof (this[prop]) === "number") {
                     this[prop] = 0;
-                    continue;
                 }
-                this[prop] = false;
+                else {
+                    this[prop] = false;
+                }
             }
         };
         MaterialDefines.prototype.toString = function () {
             var result = "";
             for (var index = 0; index < this._keys.length; index++) {
                 var prop = this._keys[index];
-                if (prop === "BonesPerMesh" && this[prop] > 0) {
-                    result += "#define BonesPerMesh " + this[prop] + "\n";
-                    continue;
+                if (typeof (this[prop]) === "number") {
+                    result += "#define " + prop + " " + this[prop] + "\n";
                 }
-                if (this[prop]) {
+                else if (this[prop]) {
                     result += "#define " + prop + "\n";
                 }
             }

+ 7 - 8
src/Materials/babylon.pbrMaterial.js

@@ -19,8 +19,7 @@ var BABYLON;
             this.UV2 = false;
             this.VERTEXCOLOR = false;
             this.VERTEXALPHA = false;
-            this.BONES = false;
-            this.BONES4 = false;
+            this.NUM_BONE_INFLUENCERS = 0;
             this.BonesPerMesh = 0;
             this.INSTANCES = false;
             this.POINTSIZE = false;
@@ -106,9 +105,8 @@ var BABYLON;
                     }
                 }
                 if (mesh.useBones && mesh.computeBonesUsingShaders) {
-                    this._defines.BONES = true;
+                    this._defines.NUM_BONE_INFLUENCERS = mesh.numBoneInfluencers;
                     this._defines.BonesPerMesh = (mesh.skeleton.bones.length + 1);
-                    this._defines.BONES4 = true;
                 }
                 // Instances
                 if (useInstances) {
@@ -124,9 +122,6 @@ var BABYLON;
                 if (this._defines.FOG) {
                     fallbacks.addFallback(1, "FOG");
                 }
-                if (this._defines.BONES4) {
-                    fallbacks.addFallback(0, "BONES4");
-                }
                 //Attributes
                 var attribs = [BABYLON.VertexBuffer.PositionKind];
                 if (this._defines.NORMAL) {
@@ -141,9 +136,13 @@ var BABYLON;
                 if (this._defines.VERTEXCOLOR) {
                     attribs.push(BABYLON.VertexBuffer.ColorKind);
                 }
-                if (this._defines.BONES) {
+                if (this._defines.NUM_BONE_INFLUENCERS > 0) {
                     attribs.push(BABYLON.VertexBuffer.MatricesIndicesKind);
                     attribs.push(BABYLON.VertexBuffer.MatricesWeightsKind);
+                    if (this._defines.NUM_BONE_INFLUENCERS > 4) {
+                        attribs.push(BABYLON.VertexBuffer.MatricesIndicesExtraKind);
+                        attribs.push(BABYLON.VertexBuffer.MatricesWeightsExtraKind);
+                    }
                 }
                 if (this._defines.INSTANCES) {
                     attribs.push("world0");

+ 2 - 3
src/Materials/babylon.shaderMaterial.js

@@ -117,10 +117,9 @@ var BABYLON;
             }
             // Bones
             if (mesh && mesh.useBones && mesh.computeBonesUsingShaders) {
-                defines.push("#define BONES");
+                defines.push("#define NUM_BONE_INFLUENCERS " + mesh.numBoneInfluencers);
                 defines.push("#define BonesPerMesh " + (mesh.skeleton.bones.length + 1));
-                defines.push("#define BONES4");
-                fallbacks.addFallback(0, "BONES4");
+                fallbacks.addCPUSkinningFallback(0, mesh);
             }
             // Alpha test
             if (engine.getAlphaTesting()) {

+ 9 - 7
src/Materials/babylon.standardMaterial.js

@@ -84,8 +84,7 @@ var BABYLON;
             this.UV2 = false;
             this.VERTEXCOLOR = false;
             this.VERTEXALPHA = false;
-            this.BONES = false;
-            this.BONES4 = false;
+            this.NUM_BONE_INFLUENCERS = 0;
             this.BonesPerMesh = 0;
             this.INSTANCES = false;
             this.GLOSSINESS = false;
@@ -489,9 +488,8 @@ var BABYLON;
                     }
                 }
                 if (mesh.useBones && mesh.computeBonesUsingShaders) {
-                    this._defines.BONES = true;
+                    this._defines.NUM_BONE_INFLUENCERS = mesh.numBoneInfluencers;
                     this._defines.BonesPerMesh = (mesh.skeleton.bones.length + 1);
-                    this._defines.BONES4 = true;
                 }
                 // Instances
                 if (useInstances) {
@@ -554,8 +552,8 @@ var BABYLON;
                 if (this._defines.FRESNEL) {
                     fallbacks.addFallback(4, "FRESNEL");
                 }
-                if (this._defines.BONES4) {
-                    fallbacks.addFallback(0, "BONES4");
+                if (this._defines.NUM_BONE_INFLUENCERS > 0) {
+                    fallbacks.addCPUSkinningFallback(0, mesh);
                 }
                 //Attributes
                 var attribs = [BABYLON.VertexBuffer.PositionKind];
@@ -571,9 +569,13 @@ var BABYLON;
                 if (this._defines.VERTEXCOLOR) {
                     attribs.push(BABYLON.VertexBuffer.ColorKind);
                 }
-                if (this._defines.BONES) {
+                if (this._defines.NUM_BONE_INFLUENCERS > 0) {
                     attribs.push(BABYLON.VertexBuffer.MatricesIndicesKind);
                     attribs.push(BABYLON.VertexBuffer.MatricesWeightsKind);
+                    if (this._defines.NUM_BONE_INFLUENCERS > 4) {
+                        attribs.push(BABYLON.VertexBuffer.MatricesIndicesExtraKind);
+                        attribs.push(BABYLON.VertexBuffer.MatricesWeightsExtraKind);
+                    }
                 }
                 if (this._defines.INSTANCES) {
                     attribs.push("world0");

+ 17 - 3
src/Mesh/babylon.mesh.js

@@ -1333,13 +1333,17 @@ var BABYLON;
             }
             var matricesIndicesData = this.getVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind);
             var matricesWeightsData = this.getVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind);
+            var needExtras = this.numBoneInfluencers > 4;
+            var matricesIndicesExtraData = needExtras ? this.getVerticesData(BABYLON.VertexBuffer.MatricesIndicesExtraKind) : null;
+            var matricesWeightsExtraData = needExtras ? this.getVerticesData(BABYLON.VertexBuffer.MatricesWeightsExtraKind) : null;
             var skeletonMatrices = skeleton.getTransformMatrices();
             var tempVector3 = BABYLON.Vector3.Zero();
             var finalMatrix = new BABYLON.Matrix();
             var tempMatrix = new BABYLON.Matrix();
             var matWeightIdx = 0;
-            for (var index = 0; index < positionsData.length; index += 3) {
-                for (var inf = 0; inf < this.numBoneInfluencers; inf++) {
+            var inf;
+            for (var index = 0; index < positionsData.length; index += 3, matWeightIdx += 4) {
+                for (inf = 0; inf < 4; inf++) {
                     var weight = matricesWeightsData[matWeightIdx + inf];
                     if (weight > 0) {
                         BABYLON.Matrix.FromFloat32ArrayToRefScaled(skeletonMatrices, matricesIndicesData[matWeightIdx + inf] * 16, weight, tempMatrix);
@@ -1348,7 +1352,17 @@ var BABYLON;
                     else
                         break;
                 }
-                matWeightIdx += this.numBoneInfluencers;
+                if (needExtras) {
+                    for (inf = 0; inf < 4; inf++) {
+                        var weight = matricesWeightsExtraData[matWeightIdx + inf];
+                        if (weight > 0) {
+                            BABYLON.Matrix.FromFloat32ArrayToRefScaled(skeletonMatrices, matricesIndicesExtraData[matWeightIdx + inf] * 16, weight, tempMatrix);
+                            finalMatrix.addToSelf(tempMatrix);
+                        }
+                        else
+                            break;
+                    }
+                }
                 BABYLON.Vector3.TransformCoordinatesFromFloatsToRef(this._sourcePositions[index], this._sourcePositions[index + 1], this._sourcePositions[index + 2], finalMatrix, tempVector3);
                 tempVector3.toArray(positionsData, index);
                 BABYLON.Vector3.TransformNormalFromFloatsToRef(this._sourceNormals[index], this._sourceNormals[index + 1], this._sourceNormals[index + 2], finalMatrix, tempVector3);

+ 53 - 7
src/Mesh/babylon.mesh.vertexData.js

@@ -38,6 +38,12 @@ var BABYLON;
                 case BABYLON.VertexBuffer.MatricesWeightsKind:
                     this.matricesWeights = data;
                     break;
+                case BABYLON.VertexBuffer.MatricesIndicesExtraKind:
+                    this.matricesIndicesExtra = data;
+                    break;
+                case BABYLON.VertexBuffer.MatricesWeightsExtraKind:
+                    this.matricesWeightsExtra = data;
+                    break;
             }
         };
         VertexData.prototype.applyToMesh = function (mesh, updatable) {
@@ -86,6 +92,12 @@ var BABYLON;
             if (this.matricesWeights) {
                 meshOrGeometry.setVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind, this.matricesWeights, updatable);
             }
+            if (this.matricesIndicesExtra) {
+                meshOrGeometry.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesExtraKind, this.matricesIndicesExtra, updatable);
+            }
+            if (this.matricesWeightsExtra) {
+                meshOrGeometry.setVerticesData(BABYLON.VertexBuffer.MatricesWeightsExtraKind, this.matricesWeightsExtra, updatable);
+            }
             if (this.indices) {
                 meshOrGeometry.setIndices(this.indices);
             }
@@ -124,6 +136,12 @@ var BABYLON;
             if (this.matricesWeights) {
                 meshOrGeometry.updateVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind, this.matricesWeights, updateExtends, makeItUnique);
             }
+            if (this.matricesIndicesExtra) {
+                meshOrGeometry.updateVerticesData(BABYLON.VertexBuffer.MatricesIndicesExtraKind, this.matricesIndicesExtra, updateExtends, makeItUnique);
+            }
+            if (this.matricesWeightsExtra) {
+                meshOrGeometry.updateVerticesData(BABYLON.VertexBuffer.MatricesWeightsExtraKind, this.matricesWeightsExtra, updateExtends, makeItUnique);
+            }
             if (this.indices) {
                 meshOrGeometry.setIndices(this.indices);
             }
@@ -243,6 +261,22 @@ var BABYLON;
                     this.matricesWeights.push(other.matricesWeights[index]);
                 }
             }
+            if (other.matricesIndicesExtra) {
+                if (!this.matricesIndicesExtra) {
+                    this.matricesIndicesExtra = [];
+                }
+                for (index = 0; index < other.matricesIndicesExtra.length; index++) {
+                    this.matricesIndicesExtra.push(other.matricesIndicesExtra[index]);
+                }
+            }
+            if (other.matricesWeightsExtra) {
+                if (!this.matricesWeightsExtra) {
+                    this.matricesWeightsExtra = [];
+                }
+                for (index = 0; index < other.matricesWeightsExtra.length; index++) {
+                    this.matricesWeightsExtra.push(other.matricesWeightsExtra[index]);
+                }
+            }
             if (other.colors) {
                 if (!this.colors) {
                     this.colors = [];
@@ -294,6 +328,12 @@ var BABYLON;
             if (meshOrGeometry.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesWeightsKind)) {
                 result.matricesWeights = meshOrGeometry.getVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind, copyWhenShared);
             }
+            if (meshOrGeometry.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesIndicesExtraKind)) {
+                result.matricesIndicesExtra = meshOrGeometry.getVerticesData(BABYLON.VertexBuffer.MatricesIndicesExtraKind, copyWhenShared);
+            }
+            if (meshOrGeometry.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesWeightsExtraKind)) {
+                result.matricesWeightsExtra = meshOrGeometry.getVerticesData(BABYLON.VertexBuffer.MatricesWeightsExtraKind, copyWhenShared);
+            }
             result.indices = meshOrGeometry.getIndices(copyWhenShared);
             return result;
         };
@@ -1095,8 +1135,11 @@ var BABYLON;
         VertexData.CreateIcoSphere = function (options) {
             var sideOrientation = options.sideOrientation || BABYLON.Mesh.DEFAULTSIDE;
             var radius = options.radius || 1;
-            var flat = options.flat || false;
-            var subdivisions = options.subdivisions || 1;
+            var flat = (options.flat === undefined) ? true : options.flat;
+            var subdivisions = options.subdivisions || 4;
+            var radiusX = options.radiusX || radius;
+            var radiusY = options.radiusY || radius;
+            var radiusZ = options.radiusZ || radius;
             var t = (1 + Math.sqrt(5)) / 2;
             // 12 vertex x,y,z
             var ico_vertices = [
@@ -1245,7 +1288,10 @@ var BABYLON;
                     var pos_x0 = BABYLON.Vector3.Lerp(face_vertex_pos[0], face_vertex_pos[2], i2 / subdivisions);
                     var pos_x1 = BABYLON.Vector3.Lerp(face_vertex_pos[1], face_vertex_pos[2], i2 / subdivisions);
                     var pos_interp = (subdivisions === i2) ? face_vertex_pos[2] : BABYLON.Vector3.Lerp(pos_x0, pos_x1, i1 / (subdivisions - i2));
-                    pos_interp.normalize().scaleInPlace(radius);
+                    pos_interp.normalize();
+                    pos_interp.x *= radiusX;
+                    pos_interp.y *= radiusY;
+                    pos_interp.z *= radiusZ;
                     var vertex_normal;
                     if (flat) {
                         // in flat mode, recalculate normal as face centroid normal
@@ -1338,7 +1384,7 @@ var BABYLON;
             var nbfaces = data.face.length;
             var faceUV = options.faceUV || new Array(nbfaces);
             var faceColors = options.faceColors;
-            var singleFace = options.singleFace;
+            var flat = (options.flat === undefined) ? true : options.flat;
             var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || BABYLON.Mesh.DEFAULTSIDE;
             var positions = [];
             var indices = [];
@@ -1352,7 +1398,7 @@ var BABYLON;
             var f = 0;
             var u, v, ang, x, y, tmp;
             // default face colors and UV if undefined
-            if (!singleFace) {
+            if (flat) {
                 for (f = 0; f < nbfaces; f++) {
                     if (faceColors && faceColors[f] === undefined) {
                         faceColors[f] = new BABYLON.Color4(1, 1, 1, 1);
@@ -1362,7 +1408,7 @@ var BABYLON;
                     }
                 }
             }
-            if (singleFace) {
+            if (!flat) {
                 for (i = 0; i < data.vertex.length; i++) {
                     positions.push(data.vertex[i][0] * sizeX, data.vertex[i][1] * sizeY, data.vertex[i][2] * sizeZ);
                     uvs.push(0, 0);
@@ -1411,7 +1457,7 @@ var BABYLON;
             vertexData.indices = indices;
             vertexData.normals = normals;
             vertexData.uvs = uvs;
-            if (faceColors && !singleFace) {
+            if (faceColors && flat) {
                 vertexData.colors = colors;
             }
             return vertexData;

+ 18 - 0
src/Mesh/babylon.vertexBuffer.js

@@ -38,9 +38,11 @@ var BABYLON;
                     this._strideSize = 4;
                     break;
                 case VertexBuffer.MatricesIndicesKind:
+                case VertexBuffer.MatricesIndicesExtraKind:
                     this._strideSize = 4;
                     break;
                 case VertexBuffer.MatricesWeightsKind:
+                case VertexBuffer.MatricesWeightsExtraKind:
                     this._strideSize = 4;
                     break;
             }
@@ -174,6 +176,20 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+        Object.defineProperty(VertexBuffer, "MatricesIndicesExtraKind", {
+            get: function () {
+                return VertexBuffer._MatricesIndicesExtraKind;
+            },
+            enumerable: true,
+            configurable: true
+        });
+        Object.defineProperty(VertexBuffer, "MatricesWeightsExtraKind", {
+            get: function () {
+                return VertexBuffer._MatricesWeightsExtraKind;
+            },
+            enumerable: true,
+            configurable: true
+        });
         // Enums
         VertexBuffer._PositionKind = "position";
         VertexBuffer._NormalKind = "normal";
@@ -186,6 +202,8 @@ var BABYLON;
         VertexBuffer._ColorKind = "color";
         VertexBuffer._MatricesIndicesKind = "matricesIndices";
         VertexBuffer._MatricesWeightsKind = "matricesWeights";
+        VertexBuffer._MatricesIndicesExtraKind = "matricesIndicesExtra";
+        VertexBuffer._MatricesWeightsExtraKind = "matricesWeightsExtra";
         return VertexBuffer;
     })();
     BABYLON.VertexBuffer = VertexBuffer;

+ 8 - 1
src/Particles/babylon.solidParticleSystem.js

@@ -7,6 +7,7 @@ var BABYLON;
             this.nbParticles = 0;
             this.billboard = false;
             this.counter = 0;
+            this.vars = {};
             this._positions = new Array();
             this._indices = new Array();
             this._normals = new Array();
@@ -45,6 +46,7 @@ var BABYLON;
             this._cosPitch = 0.0;
             this._sinYaw = 0.0;
             this._cosYaw = 0.0;
+            this._w = 0.0;
             this.name = name;
             this._scene = scene;
             this._camera = scene.activeCamera;
@@ -348,7 +350,11 @@ var BABYLON;
                     this._vertex.x *= this._particle.scale.x;
                     this._vertex.y *= this._particle.scale.y;
                     this._vertex.z *= this._particle.scale.z;
-                    BABYLON.Vector3.TransformCoordinatesToRef(this._vertex, this._rotMatrix, this._rotated);
+                    //Vector3.TransformCoordinatesToRef(this._vertex, this._rotMatrix, this._rotated);
+                    this._w = (this._vertex.x * this._rotMatrix.m[3]) + (this._vertex.y * this._rotMatrix.m[7]) + (this._vertex.z * this._rotMatrix.m[11]) + this._rotMatrix.m[15];
+                    this._rotated.x = ((this._vertex.x * this._rotMatrix.m[0]) + (this._vertex.y * this._rotMatrix.m[4]) + (this._vertex.z * this._rotMatrix.m[8]) + this._rotMatrix.m[12]) / this._w;
+                    this._rotated.y = ((this._vertex.x * this._rotMatrix.m[1]) + (this._vertex.y * this._rotMatrix.m[5]) + (this._vertex.z * this._rotMatrix.m[9]) + this._rotMatrix.m[13]) / this._w;
+                    this._rotated.z = ((this._vertex.x * this._rotMatrix.m[2]) + (this._vertex.y * this._rotMatrix.m[6]) + (this._vertex.z * this._rotMatrix.m[10]) + this._rotMatrix.m[14]) / this._w;
                     this._positions32[idx] = this._particle.position.x + this._cam_axisX.x * this._rotated.x + this._cam_axisY.x * this._rotated.y + this._cam_axisZ.x * this._rotated.z;
                     this._positions32[idx + 1] = this._particle.position.y + this._cam_axisX.y * this._rotated.x + this._cam_axisY.y * this._rotated.y + this._cam_axisZ.y * this._rotated.z;
                     this._positions32[idx + 2] = this._particle.position.z + this._cam_axisX.z * this._rotated.x + this._cam_axisY.z * this._rotated.y + this._cam_axisZ.z * this._rotated.z;
@@ -418,6 +424,7 @@ var BABYLON;
         // dispose the SPS
         SolidParticleSystem.prototype.dispose = function () {
             this.mesh.dispose();
+            this.vars = null;
             // drop references to internal big arrays for the GC
             this._positions = null;
             this._indices = null;

+ 4 - 1
src/PostProcess/babylon.volumetricLightScatteringPostProcess.js

@@ -130,9 +130,12 @@ var BABYLON;
             if (mesh.useBones && mesh.computeBonesUsingShaders) {
                 attribs.push(BABYLON.VertexBuffer.MatricesIndicesKind);
                 attribs.push(BABYLON.VertexBuffer.MatricesWeightsKind);
-                defines.push("#define BONES");
+                defines.push("#define NUM_BONE_INFLUENCERS " + mesh.numBoneInfluencers);
                 defines.push("#define BonesPerMesh " + (mesh.skeleton.bones.length + 1));
             }
+            else {
+                defines.push("#define NUM_BONE_INFLUENCERS 0");
+            }
             // Instances
             if (useInstances) {
                 defines.push("#define INSTANCES");

+ 3 - 0
src/PostProcess/babylon.volumetricLightScatteringPostProcess.ts

@@ -148,7 +148,10 @@
                 attribs.push(VertexBuffer.MatricesWeightsKind);
                 defines.push("#define NUM_BONE_INFLUENCERS " + mesh.numBoneInfluencers);
                 defines.push("#define BonesPerMesh " + (mesh.skeleton.bones.length + 1));
+            } else {
+                defines.push("#define NUM_BONE_INFLUENCERS 0"); 
             }
+            
 
             // Instances
             if (useInstances) {

+ 8 - 1
src/Rendering/babylon.depthRenderer.js

@@ -86,9 +86,16 @@ var BABYLON;
             if (mesh.useBones && mesh.computeBonesUsingShaders) {
                 attribs.push(BABYLON.VertexBuffer.MatricesIndicesKind);
                 attribs.push(BABYLON.VertexBuffer.MatricesWeightsKind);
-                defines.push("#define BONES");
+                if (mesh.numBoneInfluencers > 4) {
+                    attribs.push(BABYLON.VertexBuffer.MatricesIndicesExtraKind);
+                    attribs.push(BABYLON.VertexBuffer.MatricesWeightsExtraKind);
+                }
+                defines.push("#define NUM_BONE_INFLUENCERS " + mesh.numBoneInfluencers);
                 defines.push("#define BonesPerMesh " + (mesh.skeleton.bones.length + 1));
             }
+            else {
+                defines.push("#define NUM_BONE_INFLUENCERS 0");
+            }
             // Instances
             if (useInstances) {
                 defines.push("#define INSTANCES");

+ 2 - 0
src/Rendering/babylon.depthRenderer.ts

@@ -118,6 +118,8 @@
                 }
                 defines.push("#define NUM_BONE_INFLUENCERS " + mesh.numBoneInfluencers);
                 defines.push("#define BonesPerMesh " + (mesh.skeleton.bones.length + 1));
+            } else {
+                defines.push("#define NUM_BONE_INFLUENCERS 0");
             }
 
             // Instances

+ 8 - 1
src/Rendering/babylon.outlineRenderer.js

@@ -53,9 +53,16 @@ var BABYLON;
             if (mesh.useBones && mesh.computeBonesUsingShaders) {
                 attribs.push(BABYLON.VertexBuffer.MatricesIndicesKind);
                 attribs.push(BABYLON.VertexBuffer.MatricesWeightsKind);
-                defines.push("#define BONES");
+                if (mesh.numBoneInfluencers > 4) {
+                    attribs.push(BABYLON.VertexBuffer.MatricesIndicesExtraKind);
+                    attribs.push(BABYLON.VertexBuffer.MatricesWeightsExtraKind);
+                }
+                defines.push("#define NUM_BONE_INFLUENCERS " + mesh.numBoneInfluencers);
                 defines.push("#define BonesPerMesh " + (mesh.skeleton.bones.length + 1));
             }
+            else {
+                defines.push("#define NUM_BONE_INFLUENCERS 0");
+            }
             // Instances
             if (useInstances) {
                 defines.push("#define INSTANCES");

+ 2 - 0
src/Rendering/babylon.outlineRenderer.ts

@@ -74,6 +74,8 @@
                 }
                 defines.push("#define NUM_BONE_INFLUENCERS " + mesh.numBoneInfluencers);
                 defines.push("#define BonesPerMesh " + (mesh.skeleton.bones.length + 1));
+            } else {
+                defines.push("#define NUM_BONE_INFLUENCERS 0");
             }
 
             // Instances

+ 33 - 33
src/Shaders/outline.vertex.fx

@@ -5,16 +5,14 @@ attribute vec3 position;
 attribute vec3 normal;
 
 #if NUM_BONE_INFLUENCERS > 0
+uniform mat4 mBones[BonesPerMesh];
 
-	// having bone influencers implies you have bones
-	uniform mat4 mBones[BonesPerMesh];
-
-	attribute vec4 matricesIndices;
-	attribute vec4 matricesWeights;
-	#if NUM_BONE_INFLUENCERS > 4
-		attribute vec4 matricesIndicesExtra;
-		attribute vec4 matricesWeightsExtra;
-	#endif
+attribute vec4 matricesIndices;
+attribute vec4 matricesWeights;
+#if NUM_BONE_INFLUENCERS > 4
+attribute vec4 matricesIndicesExtra;
+attribute vec4 matricesWeightsExtra;
+#endif
 #endif
 
 // Uniform
@@ -44,6 +42,8 @@ attribute vec2 uv2;
 
 void main(void)
 {
+	vec3 offsetPosition = position + normal * offset;
+
 #ifdef INSTANCES
 	mat4 finalWorld = mat4(world0, world1, world2, world3);
 #else
@@ -54,32 +54,32 @@ void main(void)
 	mat4 influence;
 	influence = mBones[int(matricesIndices[0])] * matricesWeights[0];
 
-	#if NUM_BONE_INFLUENCERS > 1
-		influence += mBones[int(matricesIndices[1])] * matricesWeights[1];
-	#endif	
-	#if NUM_BONE_INFLUENCERS > 2
-		influence += mBones[int(matricesIndices[2])] * matricesWeights[2];
-	#endif	
-	#if NUM_BONE_INFLUENCERS > 3
-		influence += mBones[int(matricesIndices[3])] * matricesWeights[3];
-	#endif	
-	
-	#if NUM_BONE_INFLUENCERS > 4
-		influence += mBones[int(matricesIndicesExtra[0])] * matricesWeightsExtra[0];
-	#endif	
-	#if NUM_BONE_INFLUENCERS > 5
-		influence += mBones[int(matricesIndicesExtra[1])] * matricesWeightsExtra[1];
-	#endif	
-	#if NUM_BONE_INFLUENCERS > 6
-		influence += mBones[int(matricesIndicesExtra[2])] * matricesWeightsExtra[2];
-	#endif	
-	#if NUM_BONE_INFLUENCERS > 7
-		influence += mBones[int(matricesIndicesExtra[3])] * matricesWeightsExtra[3];
-	#endif	
+#if NUM_BONE_INFLUENCERS > 1
+	influence += mBones[int(matricesIndices[1])] * matricesWeights[1];
+#endif	
+#if NUM_BONE_INFLUENCERS > 2
+	influence += mBones[int(matricesIndices[2])] * matricesWeights[2];
+#endif	
+#if NUM_BONE_INFLUENCERS > 3
+	influence += mBones[int(matricesIndices[3])] * matricesWeights[3];
+#endif	
+
+#if NUM_BONE_INFLUENCERS > 4
+	influence += mBones[int(matricesIndicesExtra[0])] * matricesWeightsExtra[0];
+#endif	
+#if NUM_BONE_INFLUENCERS > 5
+	influence += mBones[int(matricesIndicesExtra[1])] * matricesWeightsExtra[1];
+#endif	
+#if NUM_BONE_INFLUENCERS > 6
+	influence += mBones[int(matricesIndicesExtra[2])] * matricesWeightsExtra[2];
+#endif	
+#if NUM_BONE_INFLUENCERS > 7
+	influence += mBones[int(matricesIndicesExtra[3])] * matricesWeightsExtra[3];
+#endif	
 
 	finalWorld = finalWorld * influence;
 #endif
-	gl_Position = viewProjection * finalWorld * vec4(position, 1.0);
+	gl_Position = viewProjection * finalWorld * vec4(offsetPosition, 1.0);
 
 #ifdef ALPHATEST
 #ifdef UV1
@@ -89,4 +89,4 @@ void main(void)
 	vUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));
 #endif
 #endif
-}
+}

+ 32 - 31
src/Shaders/shadowMap.vertex.fx

@@ -4,15 +4,15 @@
 attribute vec3 position;
 #if NUM_BONE_INFLUENCERS > 0
 
-	// having bone influencers implies you have bones
-	uniform mat4 mBones[BonesPerMesh];
+// having bone influencers implies you have bones
+uniform mat4 mBones[BonesPerMesh];
 
-	attribute vec4 matricesIndices;
-	attribute vec4 matricesWeights;
-	#if NUM_BONE_INFLUENCERS > 4
-		attribute vec4 matricesIndicesExtra;
-		attribute vec4 matricesWeightsExtra;
-	#endif
+attribute vec4 matricesIndices;
+attribute vec4 matricesWeights;
+#if NUM_BONE_INFLUENCERS > 4
+attribute vec4 matricesIndicesExtra;
+attribute vec4 matricesWeightsExtra;
+#endif
 #endif
 
 // Uniform
@@ -52,32 +52,33 @@ void main(void)
 	mat4 influence;
 	influence = mBones[int(matricesIndices[0])] * matricesWeights[0];
 
-	#if NUM_BONE_INFLUENCERS > 1
-		influence += mBones[int(matricesIndices[1])] * matricesWeights[1];
-	#endif	
-	#if NUM_BONE_INFLUENCERS > 2
-		influence += mBones[int(matricesIndices[2])] * matricesWeights[2];
-	#endif	
-	#if NUM_BONE_INFLUENCERS > 3
-		influence += mBones[int(matricesIndices[3])] * matricesWeights[3];
-	#endif	
-	
-	#if NUM_BONE_INFLUENCERS > 4
-		influence += mBones[int(matricesIndicesExtra[0])] * matricesWeightsExtra[0];
-	#endif	
-	#if NUM_BONE_INFLUENCERS > 5
-		influence += mBones[int(matricesIndicesExtra[1])] * matricesWeightsExtra[1];
-	#endif	
-	#if NUM_BONE_INFLUENCERS > 6
-		influence += mBones[int(matricesIndicesExtra[2])] * matricesWeightsExtra[2];
-	#endif	
-	#if NUM_BONE_INFLUENCERS > 7
-		influence += mBones[int(matricesIndicesExtra[3])] * matricesWeightsExtra[3];
-	#endif	
+#if NUM_BONE_INFLUENCERS > 1
+	influence += mBones[int(matricesIndices[1])] * matricesWeights[1];
+#endif	
+#if NUM_BONE_INFLUENCERS > 2
+	influence += mBones[int(matricesIndices[2])] * matricesWeights[2];
+#endif	
+#if NUM_BONE_INFLUENCERS > 3
+	influence += mBones[int(matricesIndices[3])] * matricesWeights[3];
+#endif	
+
+#if NUM_BONE_INFLUENCERS > 4
+	influence += mBones[int(matricesIndicesExtra[0])] * matricesWeightsExtra[0];
+#endif	
+#if NUM_BONE_INFLUENCERS > 5
+	influence += mBones[int(matricesIndicesExtra[1])] * matricesWeightsExtra[1];
+#endif	
+#if NUM_BONE_INFLUENCERS > 6
+	influence += mBones[int(matricesIndicesExtra[2])] * matricesWeightsExtra[2];
+#endif	
+#if NUM_BONE_INFLUENCERS > 7
+	influence += mBones[int(matricesIndicesExtra[3])] * matricesWeightsExtra[3];
+#endif	
 
 	finalWorld = finalWorld * influence;
 #endif
-	gl_Position = viewProjection * finalWorld * vec4(position, 1.0);
+	vPosition = viewProjection * finalWorld * vec4(position, 1.0);
+	gl_Position = vPosition;
 
 #ifdef ALPHATEST
 #ifdef UV1

+ 1 - 1
src/babylon.mixins.js

@@ -1 +1 @@
-//# sourceMappingURL=babylon.mixins.js.map
+