cnr-isti-vclab / corto

Mesh compression library, designed for rendering and speed.
Other
196 stars 43 forks source link

PLY files with QUAD faces are not read correctly #32

Closed Rabbid76 closed 2 years ago

Rabbid76 commented 2 years ago

The PLY file below cannot be read and causes memory corruption. It seems that reading PLY files with QUAD faces is not implemented yet. See MeshLoader::loadPly:

ply.request_properties_from_element("face", { "vertex_indices" }, index, 3);

Example:

ply
format ascii 1.0
comment Created by Blender 3.0.0 - www.blender.org
element vertex 38
property float x
property float y
property float z
property float nx
property float ny
property float nz
property float s
property float t
element face 10
property list uchar uint vertex_indices
end_header
0.000000 1000.000000 371.754700 0.531974 0.000000 0.846761 0.750000 0.500000
-1000.000000 1000.000000 1000.000000 0.531974 0.000000 0.846761 0.875000 0.500000
-1000.000000 -506.694794 1000.000000 0.531974 0.000000 0.846761 0.875000 0.750000
0.000000 -1000.000000 371.754700 0.531974 0.000000 0.846761 0.750000 0.750000
0.000000 -1000.000000 -1000.000000 -0.442404 -0.896816 0.000000 0.375000 0.875000
0.000000 -1000.000000 371.754700 -0.442404 -0.896816 0.000000 0.625000 0.875000
-1000.000000 -506.694794 1000.000000 -0.442404 -0.896816 0.000000 0.625000 1.000000
-1000.000000 -506.694794 -403.351471 -0.442404 -0.896816 0.000000 0.375000 1.000000
-1000.000000 -506.694794 -403.351471 -1.000000 -0.000000 0.000000 0.375000 0.000000
-1000.000000 -506.694794 1000.000000 -1.000000 -0.000000 0.000000 0.625000 0.000000
-1000.000000 1000.000000 1000.000000 -1.000000 -0.000000 0.000000 0.625000 0.250000
-1000.000000 1000.000000 -403.351471 -1.000000 -0.000000 0.000000 0.375000 0.250000
0.000000 1000.000000 -1000.000000 0.000000 0.000000 -1.000000 0.250000 0.500000
1000.000000 1000.000000 -1000.000000 0.000000 0.000000 -1.000000 0.375000 0.500000
1000.000000 -506.694794 -1000.000000 0.000000 0.000000 -1.000000 0.375000 0.750000
0.000000 -1000.000000 -1000.000000 0.000000 0.000000 -1.000000 0.250000 0.750000
1000.000000 1000.000000 -1000.000000 1.000000 -0.000000 0.000000 0.375000 0.500000
1000.000000 1000.000000 1000.000000 1.000000 -0.000000 0.000000 0.625000 0.500000
1000.000000 -506.694794 1000.000000 1.000000 -0.000000 0.000000 0.625000 0.750000
1000.000000 -506.694794 -1000.000000 1.000000 -0.000000 0.000000 0.375000 0.750000
0.000000 1000.000000 -1000.000000 0.000000 1.000000 0.000000 0.375000 0.375000
0.000000 1000.000000 371.754700 0.000000 1.000000 0.000000 0.625000 0.375000
1000.000000 1000.000000 1000.000000 0.000000 1.000000 0.000000 0.625000 0.500000
1000.000000 1000.000000 -1000.000000 0.000000 1.000000 0.000000 0.375000 0.500000
-1000.000000 1000.000000 -403.351471 0.000000 1.000000 0.000000 0.375000 0.250000
-1000.000000 1000.000000 1000.000000 0.000000 1.000000 0.000000 0.625000 0.250000
-1000.000000 1000.000000 -403.351471 -0.512378 0.000000 -0.858760 0.125000 0.500000
0.000000 1000.000000 -1000.000000 -0.512378 0.000000 -0.858760 0.250000 0.500000
0.000000 -1000.000000 -1000.000000 -0.512378 0.000000 -0.858760 0.250000 0.750000
-1000.000000 -506.694794 -403.351471 -0.512378 0.000000 -0.858760 0.125000 0.750000
1000.000000 -506.694794 -1000.000000 0.442404 -0.896816 0.000000 0.375000 0.750000
1000.000000 -506.694794 1000.000000 0.442404 -0.896816 0.000000 0.625000 0.750000
0.000000 -1000.000000 371.754700 0.442404 -0.896816 0.000000 0.625000 0.875000
0.000000 -1000.000000 -1000.000000 0.442404 -0.896816 0.000000 0.375000 0.875000
1000.000000 1000.000000 1000.000000 -0.531974 0.000000 0.846761 0.625000 0.500000
0.000000 1000.000000 371.754700 -0.531974 0.000000 0.846761 0.750000 0.500000
0.000000 -1000.000000 371.754700 -0.531974 0.000000 0.846761 0.750000 0.750000
1000.000000 -506.694794 1000.000000 -0.531974 0.000000 0.846761 0.625000 0.750000
4 0 1 2 3
4 4 5 6 7
4 8 9 10 11
4 12 13 14 15
4 16 17 18 19
4 20 21 22 23
4 24 25 21 20
4 26 27 28 29
4 30 31 32 33
4 34 35 36 37
ponchio commented 2 years ago

I added support for quads too before realizing you made a pull request. I will try to combine the two.

Rabbid76 commented 2 years ago

Thanks for the quick reply and fix. It now works as intended.