Skip to content

Commit b33984c

Browse files
mwestphalMeakk
andauthored
Fix Alembic xform (#2784) (#2786)
(cherry picked from commit 062965b) Co-authored-by: Michael MIGLIORE <[email protected]>
2 parents bb0702a + 755a266 commit b33984c

File tree

9 files changed

+27
-15
lines changed

9 files changed

+27
-15
lines changed

application/testing/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,7 @@ if(F3D_PLUGIN_BUILD_ALEMBIC)
787787
f3d_test(NAME TestAlembicNonFaceVarying DATA tetrahedron_non_facevarying_uv.abc ARGS -s --load-plugins=alembic)
788788
f3d_test(NAME TestAlembicAnimation DATA drop.abc ARGS --animation-time=2 --load-plugins=alembic --animation-progress)
789789
f3d_test(NAME TestAlembicAnimationXForm DATA xform_anim.abc ARGS -g --animation-time=1.5 --load-plugins=alembic --animation-progress)
790+
f3d_test(NAME TestAlembicAnimationXFormRotation DATA joint1.abc ARGS -g --animation-time=1.5 --load-plugins=alembic --animation-progress)
790791
f3d_test(NAME TestAlembicCurves DATA monkey_curves.abc ARGS --load-plugins=alembic THRESHOLD 0.07) # High threshold because of line rendering
791792

792793
if(VTK_VERSION VERSION_GREATER_EQUAL 9.3.20240707)

plugins/alembic/configs/config.d/10_alembic.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"match-type": "glob",
44
"match": "*.abc",
55
"options": {
6-
"scalar-coloring": true,
76
"load-plugins": "alembic"
87
}
98
}

plugins/alembic/configs/thumbnail.d/10_alembic.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"match-type": "glob",
44
"match": "*.abc",
55
"options": {
6-
"scalar-coloring": true,
76
"load-plugins": "alembic"
87
}
98
}

plugins/alembic/module/vtkF3DAlembicReader.cxx

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -263,18 +263,23 @@ class vtkF3DAlembicReader::vtkInternals
263263

264264
this->SetupIndicesStorage(faceVertexCounts, originalData.Indices);
265265

266+
// By default, Alembic is CW while VTK is CCW
267+
// So we need to reverse the order of indices only if the mesh is not mirrored
268+
const bool doReverseRotate = matrix.determinant() > 0;
269+
266270
// Positions
267271
{
268272
V3fContainer pV3F;
269273
for (size_t pIndex = 0; pIndex < positions->size(); pIndex++)
270274
{
271-
const Alembic::Abc::V3f tp = positions->get()[pIndex] * matrix;
275+
Alembic::Abc::V3f tp;
276+
matrix.multVecMatrix(positions->get()[pIndex], tp);
272277
pV3F.emplace_back(tp.x, tp.y, tp.z);
273278
}
274279
originalData.Attributes.insert(AttributesContainer::value_type("P", pV3F));
275280

276281
this->UpdateIndices<Alembic::AbcGeom::Int32ArraySamplePtr>(
277-
facePositionIndices, pIndicesOffset, originalData.Indices);
282+
facePositionIndices, pIndicesOffset, originalData.Indices, doReverseRotate);
278283
}
279284

280285
// Texture coordinate
@@ -297,12 +302,12 @@ class vtkF3DAlembicReader::vtkInternals
297302
{
298303
originalData.uvFaceVarying = true;
299304
this->UpdateIndices<Alembic::AbcGeom::UInt32ArraySamplePtr>(
300-
uvIndices, uvIndicesOffset, originalData.Indices);
305+
uvIndices, uvIndicesOffset, originalData.Indices, doReverseRotate);
301306
}
302307
else
303308
{
304309
this->UpdateIndices<Alembic::AbcGeom::Int32ArraySamplePtr>(
305-
facePositionIndices, uvIndicesOffset, originalData.Indices);
310+
facePositionIndices, uvIndicesOffset, originalData.Indices, doReverseRotate);
306311
}
307312
}
308313
}
@@ -319,8 +324,9 @@ class vtkF3DAlembicReader::vtkInternals
319324
Alembic::AbcGeom::UInt32ArraySamplePtr normalIndices = normalValue.getIndices();
320325
for (size_t index = 0; index < normalValue.getVals()->size(); ++index)
321326
{
322-
Alembic::AbcGeom::V3f normal = (*(normalValue.getVals()))[index];
323-
normal_v3f.emplace_back(normal[0], normal[1], normal[2]);
327+
Alembic::AbcGeom::V3f normal;
328+
matrix.multDirMatrix((*(normalValue.getVals()))[index], normal);
329+
normal_v3f.emplace_back(normal);
324330
}
325331
originalData.Attributes.insert(AttributesContainer::value_type("N", normal_v3f));
326332

@@ -329,12 +335,12 @@ class vtkF3DAlembicReader::vtkInternals
329335
originalData.nFaceVarying = true;
330336

331337
this->UpdateIndices<Alembic::AbcGeom::UInt32ArraySamplePtr>(
332-
normalIndices, nIndicesOffset, originalData.Indices);
338+
normalIndices, nIndicesOffset, originalData.Indices, doReverseRotate);
333339
}
334340
else
335341
{
336342
this->UpdateIndices<Alembic::AbcGeom::Int32ArraySamplePtr>(
337-
facePositionIndices, nIndicesOffset, originalData.Indices);
343+
facePositionIndices, nIndicesOffset, originalData.Indices, doReverseRotate);
338344
}
339345
}
340346
}
@@ -433,7 +439,7 @@ class vtkF3DAlembicReader::vtkInternals
433439
const Alembic::AbcGeom::IXformSchema& xFormSchema = xForm.getSchema();
434440
Alembic::AbcGeom::XformSample xFormSamp;
435441
xFormSchema.get(xFormSamp, selector);
436-
objMatrix = matrix * xFormSamp.getMatrix();
442+
objMatrix = xFormSamp.getMatrix() * matrix;
437443
}
438444

439445
objects.pop();
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading

testing/data/DATA_LICENSES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
- Wolf.fbx: OLEKSO: [CC-NC 4.0](http://creativecommons.org/licenses/by-nc/4.0/)
6969
- world\*: VTK Data: BSD-3-Clause
7070
- xform_anim.abc: Public Domain
71+
- joint1.abc: Public Domain
7172
- zombie\*.mdl: LibreQuake Project: BSD-3-Clause
7273

7374
All other datasets are licensed under the BSD-3-Clause F3D license.

testing/data/joint1.abc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:dd724979117dee9212eace48d49bd59d9e968a2af2991cc56d69fe76226d57d9
3+
size 40129

0 commit comments

Comments
 (0)