Skip to content

Commit

Permalink
Merge pull request #1973 from zenustech/improve-abc-import
Browse files Browse the repository at this point in the history
abc skipInvisibleObject
  • Loading branch information
ShuliangLu authored Aug 5, 2024
2 parents 124f6f4 + 25fea65 commit 8887230
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 64 deletions.
1 change: 1 addition & 0 deletions projects/Alembic/ABCCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ extern void traverseABC(
std::string path,
const TimeAndSamplesMap & iTimeMap,
ObjectVisibility parent_visible,
bool skipInvisibleObject,
bool outOfRangeAsEmpty
);

Expand Down
4 changes: 2 additions & 2 deletions projects/Alembic/AlembicVAT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ struct AlembicToSoftBodyVAT: public INode {
const int32_t frameIndex = frameEnd - idx - 1;
auto abctree = std::make_shared<ABCTree>();
auto prims = std::make_shared<zeno::ListObject>();
traverseABC(obj, *abctree, idx, read_done, false, "", timeMap, ObjectVisibility::kVisibilityDeferred, false);
traverseABC(obj, *abctree, idx, read_done, false, "", timeMap, ObjectVisibility::kVisibilityDeferred, false, false);
if (use_xform) {
prims = get_xformed_prims(abctree);
} else {
Expand Down Expand Up @@ -403,7 +403,7 @@ struct AlembicToDynamicRemeshVAT : public INode {
const int32_t frameIndex = frameEnd - idx - 1;
auto abctree = std::make_shared<ABCTree>();
auto prims = std::make_shared<zeno::ListObject>();
traverseABC(obj, *abctree, idx, read_done, false, "", timeMap, ObjectVisibility::kVisibilityDeferred, false);
traverseABC(obj, *abctree, idx, read_done, false, "", timeMap, ObjectVisibility::kVisibilityDeferred, false, false);
if (use_xform) {
prims = get_xformed_prims(abctree);
} else {
Expand Down
2 changes: 1 addition & 1 deletion projects/Alembic/GetAlembicPrim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ struct ImportAlembicPrim : INode {
auto obj = archive.getTop();
bool read_face_set = get_input2<bool>("read_face_set");
bool outOfRangeAsEmpty = get_input2<bool>("outOfRangeAsEmpty");
traverseABC(obj, *abctree, frameid, read_done, read_face_set, "", timeMap, ObjectVisibility::kVisibilityDeferred, outOfRangeAsEmpty);
traverseABC(obj, *abctree, frameid, read_done, read_face_set, "", timeMap, ObjectVisibility::kVisibilityDeferred, false, outOfRangeAsEmpty);
}
bool use_xform = get_input2<bool>("use_xform");
auto index = get_input2<int>("index");
Expand Down
127 changes: 66 additions & 61 deletions projects/Alembic/ReadAlembic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,7 @@ void traverseABC(
std::string path,
const TimeAndSamplesMap & iTimeMap,
ObjectVisibility parent_visible,
bool skipInvisibleObject,
bool outOfRangeAsEmpty
) {
{
Expand Down Expand Up @@ -1037,66 +1038,67 @@ void traverseABC(
else {
tree.visible = parent_visible;
}
if (!(tree.visible == ObjectVisibility::kVisibilityHidden && skipInvisibleObject)) {
if (Alembic::AbcGeom::IPolyMesh::matches(md)) {
if (!read_done) {
log_debug("[alembic] found a mesh [{}]", obj.getName());
}

if (Alembic::AbcGeom::IPolyMesh::matches(md)) {
if (!read_done) {
log_debug("[alembic] found a mesh [{}]", obj.getName());
}

Alembic::AbcGeom::IPolyMesh meshy(obj);
auto &mesh = meshy.getSchema();
tree.prim = foundABCMesh(mesh, frameid, read_done, read_face_set, outOfRangeAsEmpty, obj.getName());
tree.prim->userData().set2("_abc_name", obj.getName());
prim_set_abcpath(tree.prim.get(), path);
} else if (Alembic::AbcGeom::IXformSchema::matches(md)) {
if (!read_done) {
log_debug("[alembic] found a Xform [{}]", obj.getName());
}
Alembic::AbcGeom::IXform xfm(obj);
auto &cam_sch = xfm.getSchema();
tree.xform = foundABCXform(cam_sch, frameid);
} else if (Alembic::AbcGeom::ICameraSchema::matches(md)) {
if (!read_done) {
log_debug("[alembic] found a Camera [{}]", obj.getName());
}
Alembic::AbcGeom::ICamera cam(obj);
auto &cam_sch = cam.getSchema();
tree.camera_info = foundABCCamera(cam_sch, frameid);
} else if(Alembic::AbcGeom::IPointsSchema::matches(md)) {
if (!read_done) {
log_debug("[alembic] found points [{}]", obj.getName());
}
Alembic::AbcGeom::IPoints points(obj);
auto &points_sch = points.getSchema();
tree.prim = foundABCPoints(points_sch, frameid, read_done, outOfRangeAsEmpty);
tree.prim->userData().set2("_abc_name", obj.getName());
prim_set_abcpath(tree.prim.get(), path);
tree.prim->userData().set2("faceset_count", 0);
} else if(Alembic::AbcGeom::ICurvesSchema::matches(md)) {
if (!read_done) {
log_debug("[alembic] found curves [{}]", obj.getName());
}
Alembic::AbcGeom::ICurves curves(obj);
auto &curves_sch = curves.getSchema();
tree.prim = foundABCCurves(curves_sch, frameid, read_done, outOfRangeAsEmpty);
tree.prim->userData().set2("_abc_name", obj.getName());
prim_set_abcpath(tree.prim.get(), path);
tree.prim->userData().set2("faceset_count", 0);
} else if (Alembic::AbcGeom::ISubDSchema::matches(md)) {
if (!read_done) {
log_debug("[alembic] found SubD [{}]", obj.getName());
}
Alembic::AbcGeom::ISubD subd(obj);
auto &subd_sch = subd.getSchema();
tree.prim = foundABCSubd(subd_sch, frameid, read_done, read_face_set, outOfRangeAsEmpty);
tree.prim->userData().set2("_abc_name", obj.getName());
prim_set_abcpath(tree.prim.get(), path);
}
if (tree.prim) {
tree.prim->userData().set2("vis", tree.visible);
if (tree.visible == 0) {
for (auto i = 0; i < tree.prim->verts.size(); i++) {
tree.prim->verts[i] = {};
Alembic::AbcGeom::IPolyMesh meshy(obj);
auto &mesh = meshy.getSchema();
tree.prim = foundABCMesh(mesh, frameid, read_done, read_face_set, outOfRangeAsEmpty, obj.getName());
tree.prim->userData().set2("_abc_name", obj.getName());
prim_set_abcpath(tree.prim.get(), path);
} else if (Alembic::AbcGeom::IXformSchema::matches(md)) {
if (!read_done) {
log_debug("[alembic] found a Xform [{}]", obj.getName());
}
Alembic::AbcGeom::IXform xfm(obj);
auto &cam_sch = xfm.getSchema();
tree.xform = foundABCXform(cam_sch, frameid);
} else if (Alembic::AbcGeom::ICameraSchema::matches(md)) {
if (!read_done) {
log_debug("[alembic] found a Camera [{}]", obj.getName());
}
Alembic::AbcGeom::ICamera cam(obj);
auto &cam_sch = cam.getSchema();
tree.camera_info = foundABCCamera(cam_sch, frameid);
} else if(Alembic::AbcGeom::IPointsSchema::matches(md)) {
if (!read_done) {
log_debug("[alembic] found points [{}]", obj.getName());
}
Alembic::AbcGeom::IPoints points(obj);
auto &points_sch = points.getSchema();
tree.prim = foundABCPoints(points_sch, frameid, read_done, outOfRangeAsEmpty);
tree.prim->userData().set2("_abc_name", obj.getName());
prim_set_abcpath(tree.prim.get(), path);
tree.prim->userData().set2("faceset_count", 0);
} else if(Alembic::AbcGeom::ICurvesSchema::matches(md)) {
if (!read_done) {
log_debug("[alembic] found curves [{}]", obj.getName());
}
Alembic::AbcGeom::ICurves curves(obj);
auto &curves_sch = curves.getSchema();
tree.prim = foundABCCurves(curves_sch, frameid, read_done, outOfRangeAsEmpty);
tree.prim->userData().set2("_abc_name", obj.getName());
prim_set_abcpath(tree.prim.get(), path);
tree.prim->userData().set2("faceset_count", 0);
} else if (Alembic::AbcGeom::ISubDSchema::matches(md)) {
if (!read_done) {
log_debug("[alembic] found SubD [{}]", obj.getName());
}
Alembic::AbcGeom::ISubD subd(obj);
auto &subd_sch = subd.getSchema();
tree.prim = foundABCSubd(subd_sch, frameid, read_done, read_face_set, outOfRangeAsEmpty);
tree.prim->userData().set2("_abc_name", obj.getName());
prim_set_abcpath(tree.prim.get(), path);
}
if (tree.prim) {
tree.prim->userData().set2("vis", tree.visible);
if (tree.visible == 0) {
for (auto i = 0; i < tree.prim->verts.size(); i++) {
tree.prim->verts[i] = {};
}
}
}
}
Expand All @@ -1116,7 +1118,7 @@ void traverseABC(
Alembic::AbcGeom::IObject child(obj, name);

auto childTree = std::make_shared<ABCTree>();
traverseABC(child, *childTree, frameid, read_done, read_face_set, path, iTimeMap, tree.visible, outOfRangeAsEmpty);
traverseABC(child, *childTree, frameid, read_done, read_face_set, path, iTimeMap, tree.visible, skipInvisibleObject, outOfRangeAsEmpty);
tree.children.push_back(std::move(childTree));
}
}
Expand Down Expand Up @@ -1172,14 +1174,16 @@ struct ReadAlembic : INode {
auto obj = archive.getTop();
bool read_face_set = get_input2<bool>("read_face_set");
bool outOfRangeAsEmpty = get_input2<bool>("outOfRangeAsEmpty");
bool skipInvisibleObject = get_input2<bool>("skipInvisibleObject");
Alembic::Util::uint32_t numSamplings = archive.getNumTimeSamplings();
TimeAndSamplesMap timeMap;
for (Alembic::Util::uint32_t s = 0; s < numSamplings; ++s) {
timeMap.add(archive.getTimeSampling(s),
archive.getMaxNumSamplesForTimeSamplingIndex(s));
}

traverseABC(obj, *abctree, frameid, read_done, read_face_set, "", timeMap, ObjectVisibility::kVisibilityDeferred, outOfRangeAsEmpty);
traverseABC(obj, *abctree, frameid, read_done, read_face_set, "", timeMap, ObjectVisibility::kVisibilityDeferred,
skipInvisibleObject, outOfRangeAsEmpty);
read_done = true;
usedPath = path;
}
Expand Down Expand Up @@ -1207,6 +1211,7 @@ ZENDEFNODE(ReadAlembic, {
{"readpath", "path"},
{"bool", "read_face_set", "1"},
{"bool", "outOfRangeAsEmpty", "0"},
{"bool", "skipInvisibleObject", "1"},
{"frameid"},
},
{
Expand Down

0 comments on commit 8887230

Please sign in to comment.