Procházet zdrojové kódy

Merge pull request #7726 from bghgary/draco-fix

Fix Draco color attribute bug when using VEC3
David Catuhe před 5 roky
rodič
revize
9e0de27a4a

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

@@ -121,6 +121,7 @@
 - Added accessor functions for `SubMesh._materialDefines` ([Popov72](https://github.com/Popov72))
 - Generator type used in `TrailMesh` constructor is now `TransformNode` instead of `AbstrachMesh` ([Popov72](https://github.com/Popov72))
 - Added the `useVertexAlpha` options to `MeshBuilder.CreateDashedLines` ([Popov72](https://github.com/Popov72))
+- Fixed a bug in `DracoCompression` when loading color attributes with VEC3. ([bghgary](https://github.com/bghgary))
 
 ### Physics
 

+ 17 - 4
src/Meshes/Compression/dracoCompression.ts

@@ -71,11 +71,24 @@ function decodeMesh(decoderModule: any, dataView: ArrayBufferView, attributes: {
             const dracoData = new decoderModule.DracoFloat32Array();
             try {
                 decoder.GetAttributeFloatForAllPoints(geometry, attribute, dracoData);
-                const babylonData = new Float32Array(numPoints * attribute.num_components());
-                for (let i = 0; i < babylonData.length; i++) {
-                    babylonData[i] = dracoData.GetValue(i);
+                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;
+                    }
+                    onAttributeData(kind, babylonData);
+                }
+                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 {
                 decoderModule.destroy(dracoData);