Selaa lähdekoodia

Merge pull request #8816 from Popov72/fix-parse-bones

Fix invalid bone index when parsing mesh data
David Catuhe 5 vuotta sitten
vanhempi
commit
19f7d12d3b
1 muutettua tiedostoa jossa 16 lisäystä ja 3 poistoa
  1. 16 3
      src/Meshes/geometry.ts

+ 16 - 3
src/Meshes/geometry.ts

@@ -1217,11 +1217,24 @@ export class Geometry implements IGetSetVerticesData {
                     floatIndices.push(index & 0x000000FF);
                     floatIndices.push((index & 0x0000FF00) >> 8);
                     floatIndices.push((index & 0x00FF0000) >> 16);
-                    floatIndices.push(index >> 24);
+                    floatIndices.push((index >> 24) & 0xFF); // & 0xFF to convert to v + 256 if v < 0
                 }
                 mesh.setVerticesData(VertexBuffer.MatricesIndicesKind, floatIndices, false);
             }
 
+            if (binaryInfo.matricesIndicesExtraAttrDesc && binaryInfo.matricesIndicesExtraAttrDesc.count > 0) {
+                var matricesIndicesData = new Int32Array(parsedGeometry, binaryInfo.matricesIndicesExtraAttrDesc.offset, binaryInfo.matricesIndicesExtraAttrDesc.count);
+                var floatIndices = [];
+                for (var i = 0; i < matricesIndicesData.length; i++) {
+                    var index = matricesIndicesData[i];
+                    floatIndices.push(index & 0x000000FF);
+                    floatIndices.push((index & 0x0000FF00) >> 8);
+                    floatIndices.push((index & 0x00FF0000) >> 16);
+                    floatIndices.push((index >> 24) & 0xFF); // & 0xFF to convert to v + 256 if v < 0
+                }
+                mesh.setVerticesData(VertexBuffer.MatricesIndicesExtraKind, floatIndices, false);
+            }
+
             if (binaryInfo.matricesWeightsAttrDesc && binaryInfo.matricesWeightsAttrDesc.count > 0) {
                 var matricesWeightsData = new Float32Array(parsedGeometry, binaryInfo.matricesWeightsAttrDesc.offset, binaryInfo.matricesWeightsAttrDesc.count);
                 mesh.setVerticesData(VertexBuffer.MatricesWeightsKind, matricesWeightsData, false);
@@ -1293,7 +1306,7 @@ export class Geometry implements IGetSetVerticesData {
                         floatIndices.push(matricesIndex & 0x000000FF);
                         floatIndices.push((matricesIndex & 0x0000FF00) >> 8);
                         floatIndices.push((matricesIndex & 0x00FF0000) >> 16);
-                        floatIndices.push(matricesIndex >> 24);
+                        floatIndices.push((matricesIndex >> 24) & 0xFF); // & 0xFF to convert to v + 256 if v < 0
                     }
 
                     mesh.setVerticesData(VertexBuffer.MatricesIndicesKind, floatIndices, parsedGeometry.matricesIndices._updatable);
@@ -1313,7 +1326,7 @@ export class Geometry implements IGetSetVerticesData {
                         floatIndices.push(matricesIndex & 0x000000FF);
                         floatIndices.push((matricesIndex & 0x0000FF00) >> 8);
                         floatIndices.push((matricesIndex & 0x00FF0000) >> 16);
-                        floatIndices.push(matricesIndex >> 24);
+                        floatIndices.push((matricesIndex >> 24) & 0xFF); // & 0xFF to convert to v + 256 if v < 0
                     }
 
                     mesh.setVerticesData(VertexBuffer.MatricesIndicesExtraKind, floatIndices, parsedGeometry.matricesIndicesExtra._updatable);