JuliaIO / MeshIO.jl

IO for Meshes
Other
79 stars 33 forks source link

Information are lost when mesh has different normals per position #80

Closed felipeek closed 1 day ago

felipeek commented 1 year ago

When a mesh is loaded using load("..."), the faces are represented "directly" as 3 points, instead of being references to the position array. This makes impossible to distinguish the attributes of different vertices that have the same positions (e.g. normals and uv coords).

A simple cube is a good example of such object:

# cube.obj
#

g cube

v  0.0  0.0  0.0
v  0.0  0.0  1.0
v  0.0  1.0  0.0
v  0.0  1.0  1.0
v  1.0  0.0  0.0
v  1.0  0.0  1.0
v  1.0  1.0  0.0
v  1.0  1.0  1.0

vn  0.0  0.0  1.0
vn  0.0  0.0 -1.0
vn  0.0  1.0  0.0
vn  0.0 -1.0  0.0
vn  1.0  0.0  0.0
vn -1.0  0.0  0.0

f  1//2  7//2  5//2
f  1//2  3//2  7//2 
f  1//6  4//6  3//6 
f  1//6  2//6  4//6 
f  3//3  8//3  7//3 
f  3//3  4//3  8//3 
f  5//5  7//5  8//5 
f  5//5  8//5  6//5 
f  1//4  5//4  6//4 
f  1//4  6//4  2//4 
f  2//1  6//1  8//1 
f  2//1  8//1  4//1 

Note that the positions appear with different attributes per face. When this mesh is loaded with this library, I don't see a way to properly retrieve the correct attributes per vertex.

IMO, each triangle should be represented by 3 vertices (instead of 3 positions), whereas each vertex is composed by references to the positions, normals and uv vectors, which already exist.

This change would make this library suitable for general use in mesh processing