Kaynağa Gözat

Don't load empty data into attributes for Draco

Gary Hsu 5 yıl önce
ebeveyn
işleme
55df3d5cb6

+ 16 - 14
src/Meshes/Compression/dracoCompression.ts

@@ -72,22 +72,24 @@ function decodeMesh(decoderModule: any, dataView: ArrayBufferView, attributes: {
             try {
                 decoder.GetAttributeFloatForAllPoints(geometry, attribute, dracoData);
                 const numComponents = attribute.num_components();
-                if (kind === "color" && numComponents === 3) {
-                    const babylonData = new Float32Array(numPoints * 4);
-                    for (let i = 0, j = 0; i < babylonData.length; i += 4, j += numComponents) {
-                        babylonData[i + 0] = dracoData.GetValue(j + 0);
-                        babylonData[i + 1] = dracoData.GetValue(j + 1);
-                        babylonData[i + 2] = dracoData.GetValue(j + 2);
-                        babylonData[i + 3] = 1;
+                if (numComponents) {
+                    if (kind === "color" && numComponents === 3) {
+                        const babylonData = new Float32Array(numPoints * 4);
+                        for (let i = 0, j = 0; i < babylonData.length; i += 4, j += numComponents) {
+                            babylonData[i + 0] = dracoData.GetValue(j + 0);
+                            babylonData[i + 1] = dracoData.GetValue(j + 1);
+                            babylonData[i + 2] = dracoData.GetValue(j + 2);
+                            babylonData[i + 3] = 1;
+                        }
+                        onAttributeData(kind, babylonData);
                     }
-                    onAttributeData(kind, babylonData);
-                }
-                else {
-                    const babylonData = new Float32Array(numPoints * numComponents);
-                    for (let i = 0; i < babylonData.length; i++) {
-                        babylonData[i] = dracoData.GetValue(i);
+                    else {
+                        const babylonData = new Float32Array(numPoints * numComponents);
+                        for (let i = 0; i < babylonData.length; i++) {
+                            babylonData[i] = dracoData.GetValue(i);
+                        }
+                        onAttributeData(kind, babylonData);
                     }
-                    onAttributeData(kind, babylonData);
                 }
             }
             finally {

+ 5 - 0
src/Meshes/mesh.vertexData.ts

@@ -3,6 +3,7 @@ import { Matrix, Vector3, Vector2, Vector4 } from "../Maths/math.vector";
 import { VertexBuffer } from "../Meshes/buffer";
 import { _DevTools } from '../Misc/devTools';
 import { Color4, Color3 } from '../Maths/math.color';
+import { Logger } from '../Misc/logger';
 
 declare type Geometry = import("../Meshes/geometry").Geometry;
 declare type Mesh = import("../Meshes/mesh").Mesh;
@@ -171,6 +172,10 @@ export class VertexData {
      * @param kind the type of data that is being set, eg positions, colors etc
      */
     public set(data: FloatArray, kind: string) {
+        if (!data.length) {
+            Logger.Warn(`Setting vertex data kind '${kind}' with an empty array`);
+        }
+
         switch (kind) {
             case VertexBuffer.PositionKind:
                 this.positions = data;