From 25fea6522437fcb147075818e34a90da35e9fc97 Mon Sep 17 00:00:00 2001 From: zhouhang95 <765229842@qq.com> Date: Sat, 3 Aug 2024 15:54:31 +0800 Subject: [PATCH] abc skipInvisibleObject --- projects/Alembic/ABCCommon.h | 1 + projects/Alembic/AlembicVAT.cpp | 4 +- projects/Alembic/GetAlembicPrim.cpp | 2 +- projects/Alembic/ReadAlembic.cpp | 127 +++++++++++++++------------- 4 files changed, 70 insertions(+), 64 deletions(-) diff --git a/projects/Alembic/ABCCommon.h b/projects/Alembic/ABCCommon.h index f71fcfa8b3..0db4219060 100644 --- a/projects/Alembic/ABCCommon.h +++ b/projects/Alembic/ABCCommon.h @@ -35,6 +35,7 @@ extern void traverseABC( std::string path, const TimeAndSamplesMap & iTimeMap, ObjectVisibility parent_visible, + bool skipInvisibleObject, bool outOfRangeAsEmpty ); diff --git a/projects/Alembic/AlembicVAT.cpp b/projects/Alembic/AlembicVAT.cpp index 80da750420..b502b11b33 100644 --- a/projects/Alembic/AlembicVAT.cpp +++ b/projects/Alembic/AlembicVAT.cpp @@ -203,7 +203,7 @@ struct AlembicToSoftBodyVAT: public INode { const int32_t frameIndex = frameEnd - idx - 1; auto abctree = std::make_shared(); auto prims = std::make_shared(); - 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 { @@ -403,7 +403,7 @@ struct AlembicToDynamicRemeshVAT : public INode { const int32_t frameIndex = frameEnd - idx - 1; auto abctree = std::make_shared(); auto prims = std::make_shared(); - 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 { diff --git a/projects/Alembic/GetAlembicPrim.cpp b/projects/Alembic/GetAlembicPrim.cpp index 636e88411a..a8304e82a8 100644 --- a/projects/Alembic/GetAlembicPrim.cpp +++ b/projects/Alembic/GetAlembicPrim.cpp @@ -433,7 +433,7 @@ struct ImportAlembicPrim : INode { auto obj = archive.getTop(); bool read_face_set = get_input2("read_face_set"); bool outOfRangeAsEmpty = get_input2("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("use_xform"); auto index = get_input2("index"); diff --git a/projects/Alembic/ReadAlembic.cpp b/projects/Alembic/ReadAlembic.cpp index 9f2a75c8cf..3cba387f0b 100644 --- a/projects/Alembic/ReadAlembic.cpp +++ b/projects/Alembic/ReadAlembic.cpp @@ -1006,6 +1006,7 @@ void traverseABC( std::string path, const TimeAndSamplesMap & iTimeMap, ObjectVisibility parent_visible, + bool skipInvisibleObject, bool outOfRangeAsEmpty ) { { @@ -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] = {}; + } } } } @@ -1116,7 +1118,7 @@ void traverseABC( Alembic::AbcGeom::IObject child(obj, name); auto childTree = std::make_shared(); - 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)); } } @@ -1172,6 +1174,7 @@ struct ReadAlembic : INode { auto obj = archive.getTop(); bool read_face_set = get_input2("read_face_set"); bool outOfRangeAsEmpty = get_input2("outOfRangeAsEmpty"); + bool skipInvisibleObject = get_input2("skipInvisibleObject"); Alembic::Util::uint32_t numSamplings = archive.getNumTimeSamplings(); TimeAndSamplesMap timeMap; for (Alembic::Util::uint32_t s = 0; s < numSamplings; ++s) { @@ -1179,7 +1182,8 @@ struct ReadAlembic : INode { 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; } @@ -1207,6 +1211,7 @@ ZENDEFNODE(ReadAlembic, { {"readpath", "path"}, {"bool", "read_face_set", "1"}, {"bool", "outOfRangeAsEmpty", "0"}, + {"bool", "skipInvisibleObject", "1"}, {"frameid"}, }, {