point-cloud-utils
point-cloud-utils copied to clipboard
Fix obj file loading
Fixes https://github.com/fwilliams/point-cloud-utils/issues/83.
When loading obj files, the attrib.normals vector only contains the unique normals present in the mesh. To associate a normal to a vertex you have to use the face indices structure. In the current code, the following obj file causes an out of bounds array access:
o Plane
v 0.000000 0.000000 0.000000
v 0.353553 0.353553 0.000000
v 0.353553 -0.353553 0.000000
vn -0.0000 -0.0000 1.0000
s 0
f 2//1 1//1 3//1
I think this issue is present with UV coordinate loading as well.
One thing missing from this is how to deal with vertices with multiple normals, for example:
o Plane
v 0.000000 0.000000 0.000000
v 0.353553 0.353553 0.000000
v 0.353553 -0.353553 0.000000
v 0.044583 -0.475301 0.307226
vn -0.0000 -0.0000 1.0000
vn 0.5022 0.5022 0.7040
s 0
f 2//1 1//1 3//1
f 1//2 4//2 3//2
Here vertex 1 and 3 have two normals, and I think only face or averaged normals make sense here?