Sfoglia il codice sorgente

fix possible division by zero

jbousquie 8 anni fa
parent
commit
3a92d4067b
2 ha cambiato i file con 5 aggiunte e 5 eliminazioni
  1. 2 2
      src/Mesh/babylon.mesh.vertexData.ts
  2. 3 3
      src/Mesh/babylon.meshBuilder.ts

+ 2 - 2
src/Mesh/babylon.mesh.vertexData.ts

@@ -538,8 +538,8 @@
             var v: number;
             var v: number;
             for (p = 0; p < pathArray.length; p++) {
             for (p = 0; p < pathArray.length; p++) {
                 for (i = 0; i < minlg + closePathCorr; i++) {
                 for (i = 0; i < minlg + closePathCorr; i++) {
-                    u = us[p][i] / uTotalDistance[p];
-                    v = vs[i][p] / vTotalDistance[i];
+                    u = (uTotalDistance[p] != 0.0) ? us[p][i] / uTotalDistance[p] : 0.0;
+                    v = (vTotalDistance[i] != 0.0) ? vs[i][p] / vTotalDistance[i] : 0.0;
                     if (invertUV) {
                     if (invertUV) {
                         uvs.push(v, u);
                         uvs.push(v, u);
                     } else {
                     } else {

+ 3 - 3
src/Mesh/babylon.meshBuilder.ts

@@ -1154,7 +1154,7 @@
                     for (i = 0; i < shapePath.length; i++) {
                     for (i = 0; i < shapePath.length; i++) {
                         barycenter.addInPlace(shapePath[i]);
                         barycenter.addInPlace(shapePath[i]);
                     }
                     }
-                    barycenter.scaleInPlace(1 / shapePath.length);
+                    barycenter.scaleInPlace(1.0 / shapePath.length);
                     for (i = 0; i < shapePath.length; i++) {
                     for (i = 0; i < shapePath.length; i++) {
                         pointCap.push(barycenter);
                         pointCap.push(barycenter);
                     }
                     }
@@ -1165,7 +1165,7 @@
                         break;
                         break;
                     case Mesh.CAP_START:
                     case Mesh.CAP_START:
                         shapePaths[0] = capPath(shapePaths[2]);
                         shapePaths[0] = capPath(shapePaths[2]);
-                        shapePaths[1] = shapePaths[2].slice(0);
+                        shapePaths[1] = shapePaths[2];
                         break;
                         break;
                     case Mesh.CAP_END:
                     case Mesh.CAP_END:
                         shapePaths[index] = shapePaths[index - 1];
                         shapePaths[index] = shapePaths[index - 1];
@@ -1173,7 +1173,7 @@
                         break;
                         break;
                     case Mesh.CAP_ALL:
                     case Mesh.CAP_ALL:
                         shapePaths[0] = capPath(shapePaths[2]);
                         shapePaths[0] = capPath(shapePaths[2]);
-                        shapePaths[1] = shapePaths[2].slice(0);
+                        shapePaths[1] = shapePaths[2];
                         shapePaths[index] = shapePaths[index - 1];
                         shapePaths[index] = shapePaths[index - 1];
                         shapePaths[index + 1] = capPath(shapePaths[index - 1]);
                         shapePaths[index + 1] = capPath(shapePaths[index - 1]);
                         break;
                         break;