Browse Source

Merge pull request #8281 from bghgary/draco-fix

Don't load empty data into attributes for Draco
David Catuhe 5 năm trước cách đây
mục cha
commit
d62cee30ec

+ 2 - 1
dist/preview release/what's new.md

@@ -213,7 +213,8 @@
 - Fix bug when using `ShadowOnlyMaterial` with Cascaded Shadow Map and `autoCalcDepthBounds` is `true` ([Popov72](https://github.com/Popov72))
 - Fix OBJ serializer default scene scene handedness causing [OBJ Mirror export](https://forum.babylonjs.com/t/obj-export-mirrored/10835/10)
 - Fix bug when using shadows + instances + transparent meshes + `transparencyShadow = false` ([Popov72](https://github.com/Popov72))
-- Incorrect initialization when reattaching XR pointer selection ([#8227](https://github.com/BabylonJS/Babylon.js/issues/8227)) ([RaananW](https://github.com/RaananW))
+- Incorrect initialization when reattaching XR pointer selection  ([#8227](https://github.com/BabylonJS/Babylon.js/issues/8227)) ([RaananW](https://github.com/RaananW))
+- Fixed `DracoCompression` to not load empty data into attributes ([bghgary](https://github.com/bghgary))
 
 ## Breaking changes
 

+ 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;