Fix T70021: Alembic incomplete crease import

Creases are stored by the vertex indices of the edges. Sometimes they
were stored with (v1, v2) when the edge itself was stored with (v2, v1).
We now search for both orientations.

Sorting the vertex indices before searching avoids the second search
altogether when loading the example file of T70021.
This commit is contained in:
Sybren A. Stüvel 2019-09-19 17:30:52 +02:00
parent c1612ca114
commit 5883b6fde2
Notes: blender-bot 2023-02-14 09:34:18 +01:00
Referenced by issue #70021, Alembic incomplete crease import
1 changed files with 16 additions and 3 deletions

View File

@ -1414,11 +1414,24 @@ void AbcSubDReader::readObjectData(Main *bmain, const Alembic::Abc::ISampleSelec
Int32ArraySamplePtr indices = sample.getCreaseIndices();
Alembic::Abc::FloatArraySamplePtr sharpnesses = sample.getCreaseSharpnesses();
MEdge *edges = mesh->medge;
if (indices && sharpnesses) {
MEdge *edges = mesh->medge;
int totedge = mesh->totedge;
for (int i = 0, s = 0, e = indices->size(); i < e; i += 2, s++) {
MEdge *edge = find_edge(edges, mesh->totedge, (*indices)[i], (*indices)[i + 1]);
int v1 = (*indices)[i];
int v2 = (*indices)[i + 1];
if (v2 < v1) {
/* It appears to be common to store edges with the smallest index first, in which case this
* prevents us from doing the second search below. */
std::swap(v1, v2);
}
MEdge *edge = find_edge(edges, totedge, v1, v2);
if (edge == NULL) {
edge = find_edge(edges, totedge, v2, v1);
}
if (edge) {
edge->crease = unit_float_to_uchar_clamp((*sharpnesses)[s]);