atteneder / DracoUnity

Draco 3D Data Compression Unity Package
Apache License 2.0
247 stars 39 forks source link

Point cloud import is kinda all over the place #70

Closed dganzella closed 9 months ago

dganzella commented 1 year ago

Hey!

Point cloud importing is kinda not working. After running draco.ConvertDracoMeshToUnity, I needed to make a few adjustments

Both the Index format is wrong, and no submesh is being created

so here is how to solve it for now:

            var mesh = await draco.ConvertDracoMeshToUnity(data);

            mesh.indexFormat = mesh.vertexCount > 65535 ?
                IndexFormat.UInt32 : IndexFormat.UInt16;

            mesh.SetIndices(
                Enumerable.Range(0, mesh.vertexCount).ToArray(),
                MeshTopology.Points, 0
            );

            mesh.UploadMeshData(true);
dganzella commented 1 year ago

I still have no idea what was happening to the Poor mesh inside ConvertDracoMeshToUnity

but I had an issue which was noticed by our QA analyst that it was randomly disappearing then moving the camera

here is the fixed code, I could onlu fix it my making a copy ,


            var data = File.ReadAllBytes(filepath);

            var draco = new DracoMeshLoader();

            var mesh = await draco.ConvertDracoMeshToUnity(data);

            var mesh_not_broken = new Mesh();

            mesh_not_broken.SetVertices(mesh.vertices);
            mesh_not_broken.SetColors(mesh.colors);

            mesh_not_broken.indexFormat = mesh.vertexCount > 65535 ?
                IndexFormat.UInt32 : IndexFormat.UInt16;

            mesh_not_broken.SetIndices(
                Enumerable.Range(0, mesh.vertexCount).ToArray(),
                MeshTopology.Points, 0
            );

            mesh_not_broken.UploadMeshData(true);

            setupPointCloud(mesh_not_broken);
atteneder commented 12 months ago

Hi @dganzella,

Thanks for reporting. I could not reproduce that behavior with stock test files and custom created ones. Can you give me a sample .drc file that reproduces this error.

Also, which version of Unity and DracoUnity are you using?

Thanks

atteneder commented 12 months ago

Might be related to #64

atteneder commented 12 months ago

Or maybe even #63 . The lack of correct bounds might confuse the culling, so point clouds are (not) rendered when they shouldn't. Can you try replacing your fix with a Mesh.RecalculateBounds.?

atteneder commented 9 months ago

Both #63 and #64 have been fixed in Draco for Unity, the successor of this repository/package.