Radium-Engine: Attribute handling for duplicated vertices
Context
When loading meshes, Radium may merge (or not) duplicated vertices. For instance, a mesh composed by two triangles shared by an edge can be represented either with
- Duplicate vertices handling: 4 vertices: one edge is implicitely shared between the two triangles. Vertices of that edges are stored once, and referenced twice, one time by connected face.
- NoDuplicate handling: 2x3 vertices: no connectivity information, the vertices are stored two times.
If there is no problem with the second case, the attribute management is misleading in the first case.
To handle duplicated vertices, a duplicate table of size n stores the indices of the vertices defining the mesh. When a vertex is duplicated, it appears 2 times or more in the duplicate table. Note that the number of vertices m (size of the vertex container) always satisfies m <= n, with n-m being the number of duplications.
Why is this a problem
The main problem is related to the attribute management of duplicated vertices:
- for normal vectors, we have one vector for all the occurrence of a vertex. The size of the normal container is alway
m. - for other attributes (e.g. color, texture coordinates,), we have one attribute per occurrence, so the size of the other attributes containers is
n.
Impact on loops
For the sake of clarity, here is an example of two different ways to loop over the Mesh vertices.
First, I want to iterate over the original mesh vertices (assuming I don’t care about the loading options), which leads to:
for (uint id : *( component->getDuplicateTableOutput())) {
auto & v = component->getVerticesRw()[id];
// do stuff
}
Second, If I want to skip the duplicates, I need to do:
for ( auto & v : *(component->getVerticesRw())) {
// do stuff
}
This can be ok, however we need to provide access to the attributes whatever the loop is, and in a consistent way. This is not the case today, and only the first loop provide access to the normals of the vertex v in the loop (even if we use index-based loop in the second case).
Suggestions and fixes
- Mandatory: Normal and other attributes must be accessed in the same way, using the same consistent metaphor.
- Advanced: One may be able to chose which attribute is duplicated or not. And this should be handled by the Mesh class, by providing methods to factorize duplicated data or explicitly duplicate them. In that case robust getters need to be provided.
- Suggestions: Iterators can also do the job.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 22 (18 by maintainers)
I will fix it ! but it will take some time