Bläddra i källkod

Bone Influencers varied by mesh, stage 1

only cpu skinning so far, with FileLoader change thrown in if
others wish to start to edit non Blender exporters.
jeff 9 år sedan
förälder
incheckning
90ec834d15

+ 3 - 0
src/Loading/Plugins/babylon.babylonFileLoader.ts

@@ -821,6 +821,9 @@
         // Skeleton
         if (parsedMesh.skeletonId > -1) {
             mesh.skeleton = scene.getLastSkeletonByID(parsedMesh.skeletonId);
+            if (parsedMesh.numBoneInfluencers){
+                mesh.numBoneInfluencers = parsedMesh.numBoneInfluencers;
+            }
         }
 
         // Physics

+ 1 - 0
src/Mesh/babylon.abstractMesh.ts

@@ -58,6 +58,7 @@
         public useVertexColors = true;
         public applyFog = true;
         public computeBonesUsingShaders = true;
+        public numBoneInfluencers = 4;
         public scalingDeterminant = 1;
 
         public useOctreeForRenderingSelection = true;

+ 9 - 24
src/Mesh/babylon.mesh.ts

@@ -1562,32 +1562,17 @@
             var finalMatrix = new Matrix();
             var tempMatrix = new Matrix();
 
+            var matWeightIdx = 0;
             for (var index = 0; index < positionsData.length; index += 3) {
-                var index4 = (index / 3) * 4;
-                var matricesWeight0 = matricesWeightsData[index4];
-                var matricesWeight1 = matricesWeightsData[index4 + 1];
-                var matricesWeight2 = matricesWeightsData[index4 + 2];
-                var matricesWeight3 = matricesWeightsData[index4 + 3];
-
-                if (matricesWeight0 > 0) {
-                    Matrix.FromFloat32ArrayToRefScaled(skeletonMatrices, matricesIndicesData[index4] * 16, matricesWeight0, tempMatrix);
-                    finalMatrix.addToSelf(tempMatrix);
-                }
-
-                if (matricesWeight1 > 0) {
-                    Matrix.FromFloat32ArrayToRefScaled(skeletonMatrices, matricesIndicesData[index4 + 1] * 16, matricesWeight1, tempMatrix);
-                    finalMatrix.addToSelf(tempMatrix);
-                }
-
-                if (matricesWeight2 > 0) {
-                    Matrix.FromFloat32ArrayToRefScaled(skeletonMatrices, matricesIndicesData[index4 + 2] * 16, matricesWeight2, tempMatrix);
-                    finalMatrix.addToSelf(tempMatrix);
-                }
-
-                if (matricesWeight3 > 0) {
-                    Matrix.FromFloat32ArrayToRefScaled(skeletonMatrices, matricesIndicesData[index4 + 3] * 16, matricesWeight3, tempMatrix);
-                    finalMatrix.addToSelf(tempMatrix);
+                for (var inf = 0; inf < this.numBoneInfluencers; inf++){
+                    var weight = matricesWeightsData[matWeightIdx + inf];
+                    if (weight > 0) {
+                        Matrix.FromFloat32ArrayToRefScaled(skeletonMatrices, matricesIndicesData[matWeightIdx + inf] * 16, weight, tempMatrix);
+                        finalMatrix.addToSelf(tempMatrix);
+                        
+                    }else break;           
                 }
+                matWeightIdx += this.numBoneInfluencers;
 
                 Vector3.TransformCoordinatesFromFloatsToRef(this._sourcePositions[index], this._sourcePositions[index + 1], this._sourcePositions[index + 2], finalMatrix, tempVector3);
                 tempVector3.toArray(positionsData, index);