Prechádzať zdrojové kódy

clean bone matrices in geometry

László Matuska 7 rokov pred
rodič
commit
ee62ca1e09

+ 3 - 34
src/Loading/babylon.sceneLoader.ts

@@ -189,37 +189,6 @@
             }
         }
 
-        private static _CleanMatricesIndices(meshes:AbstractMesh[]): void {
-            if (!SceneLoader._CleanBoneMatrixWeights) {
-                return;
-            }
-            for (var i = 0; i < meshes.length; i++) {
-                var mesh = meshes[i];
-                if (mesh.skeleton) {
-                    var noinfluenceBoneIndex = mesh.skeleton.bones.length;
-                    var matricesIndices: number[] | Float32Array = mesh.getVerticesData(VertexBuffer.MatricesIndicesKind);
-                    var matricesIndicesExtra: number[] | Float32Array = mesh.getVerticesData(VertexBuffer.MatricesIndicesExtraKind);    
-                    if (matricesIndices) {
-                        let size = matricesIndices.length;
-                        for (var j = 0; j < size; j++) {
-                            if (matricesIndices[j] < 0) {
-                                matricesIndices[j] = noinfluenceBoneIndex;
-                            }
-                        }
-                        mesh.setVerticesData(VertexBuffer.MatricesIndicesKind, matricesIndices);
-                        if (matricesIndicesExtra) {
-                            for (var j = 0; j < size; j++) {
-                                if (matricesIndicesExtra[j] < 0.0) {
-                                    matricesIndicesExtra[j] = noinfluenceBoneIndex;
-                                }
-                            }
-                            mesh.setVerticesData(VertexBuffer.MatricesIndicesExtraKind, matricesIndicesExtra);
-                        }                    
-                    }    
-                }
-            }
-        }
-
         // Public functions
         public static GetPluginForExtension(extension: string): ISceneLoaderPlugin | ISceneLoaderPluginAsync {
             return SceneLoader._getPluginForExtension(extension).plugin;
@@ -289,7 +258,7 @@
                     if (!syncedPlugin.importMesh(meshNames, scene, data, rootUrl, meshes, particleSystems, skeletons, errorHandler)) {
                         return;
                     }
-                    SceneLoader._CleanMatricesIndices(meshes);
+
                     if (onSuccess) {
                         // wrap onSuccess with try-catch to know if something went wrong.
                         try {
@@ -305,7 +274,7 @@
                 else {
                     var asyncedPlugin = <ISceneLoaderPluginAsync>plugin;
                     asyncedPlugin.importMeshAsync(meshNames, scene, data, rootUrl, (meshes, particleSystems, skeletons) => {
-                        SceneLoader._CleanMatricesIndices(meshes);
+
                         if (onSuccess) {
                             try {
                                 scene.importedMeshesFiles.push(rootUrl + sceneFilename);
@@ -394,7 +363,7 @@
                 } else {
                     var asyncedPlugin = <ISceneLoaderPluginAsync>plugin;
                     asyncedPlugin.loadAsync(scene, data, rootUrl, () => {
-                        SceneLoader._CleanMatricesIndices(scene.meshes);
+
                         if (onSuccess) {
                             onSuccess(scene);
                         }

+ 16 - 11
src/Mesh/babylon.geometry.ts

@@ -959,14 +959,19 @@
                 }
 
                 if (parsedGeometry.matricesWeights) {
-                    var matricesIndices: number[] | Float32Array = mesh.getVerticesData(VertexBuffer.MatricesIndicesKind);
-                    var matricesIndicesExtra: number[] | Float32Array = mesh.getVerticesData(VertexBuffer.MatricesIndicesExtraKind);
-                    Geometry._CleanMatricesWeights(parsedGeometry.matricesWeights,matricesIndex,parsedGeometry.matricesWeightsExtra,matricesIndicesExtra,parsedGeometry.numBoneInfluencers);
-                    mesh.setVerticesData(VertexBuffer.MatricesWeightsKind, parsedGeometry.matricesWeights, parsedGeometry.matricesWeights._updatable);
-                    mesh.setVerticesData(VertexBuffer.MatricesIndicesKind, matricesIndices);
-                    if (parsedGeometry.matricesWeightsExtra) {       
-                        mesh.setVerticesData(VertexBuffer.MatricesWeightsExtraKind, parsedGeometry.matricesWeightsExtra, parsedGeometry.matricesWeights._updatable);
-                        mesh.setVerticesData(VertexBuffer.MatricesIndicesExtraKind, matricesIndicesExtra);
+                    var smesh: any; smesh = mesh;
+                    if (smesh.skeletonId > -1) {
+                        var skeleton = scene.getLastSkeletonByID(smesh.skeletonId);
+                        var noinfluenceBoneIndex = skeleton.bones.length;
+                        var matricesIndices: number[] | Float32Array = mesh.getVerticesData(VertexBuffer.MatricesIndicesKind);
+                        var matricesIndicesExtra: number[] | Float32Array = mesh.getVerticesData(VertexBuffer.MatricesIndicesExtraKind);
+                        Geometry._CleanMatricesWeights(parsedGeometry.matricesWeights,matricesIndex,parsedGeometry.matricesWeightsExtra,matricesIndicesExtra,noinfluenceBoneIndex,parsedGeometry.numBoneInfluencers);
+                        mesh.setVerticesData(VertexBuffer.MatricesWeightsKind, parsedGeometry.matricesWeights, parsedGeometry.matricesWeights._updatable);
+                        mesh.setVerticesData(VertexBuffer.MatricesIndicesKind, matricesIndices);
+                        if (parsedGeometry.matricesWeightsExtra) {       
+                            mesh.setVerticesData(VertexBuffer.MatricesWeightsExtraKind, parsedGeometry.matricesWeightsExtra, parsedGeometry.matricesWeights._updatable);
+                            mesh.setVerticesData(VertexBuffer.MatricesIndicesExtraKind, matricesIndicesExtra);
+                        }
                     }
                 }
 
@@ -998,7 +1003,7 @@
             }
         }
 
-        private static _CleanMatricesWeights(matricesWeights: number[] | Float32Array, matricesIndices: number[] | Float32Array, matricesWeightsExtra: number[] | Float32Array, matricesIndicesExtra: number[] | Float32Array, influencers: number): void {
+        private static _CleanMatricesWeights(matricesWeights: number[] | Float32Array, matricesIndices: number[] | Float32Array, matricesWeightsExtra: number[] | Float32Array, matricesIndicesExtra: number[] | Float32Array, noinfluenceBoneIndex:number, influencers: number): void {
             if (!SceneLoader.CleanBoneMatrixWeights) {
                 return;
             }
@@ -1038,10 +1043,10 @@
                 } else {
                     if (firstZeroWeight>=4) {
                         matricesWeightsExtra[i+firstZeroWeight-4] = 1.0 - weight;
-                        matricesIndicesExtra[i+firstZeroWeight-4] = -1.0;
+                        matricesIndicesExtra[i+firstZeroWeight-4] = noinfluenceBoneIndex;
                     } else {
                         matricesWeights[i+firstZeroWeight] = 1.0 - weight;
-                        matricesIndices[i+firstZeroWeight] = -1.0;    
+                        matricesIndices[i+firstZeroWeight] = noinfluenceBoneIndex;    
                     }
                 }
             }