From a2aa6ff055403ecf75a7691c64fc0a3b3e73e4ee Mon Sep 17 00:00:00 2001 From: zhouhang95 <765229842@qq.com> Date: Wed, 6 Dec 2023 14:33:50 +0800 Subject: [PATCH 1/3] abc write faceset --- projects/Alembic/WriteAlembic.cpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/projects/Alembic/WriteAlembic.cpp b/projects/Alembic/WriteAlembic.cpp index 93b97d924b..bae07d777a 100644 --- a/projects/Alembic/WriteAlembic.cpp +++ b/projects/Alembic/WriteAlembic.cpp @@ -10,6 +10,8 @@ #include #include #include "ABCTree.h" +#include "zeno/utils/format.h" +#include "zeno/utils/string.h" #include #include @@ -211,7 +213,7 @@ struct WriteAlembic2 : INode { void write_attrs(std::shared_ptr prim, T1& schema, T2& samp) { OCompoundProperty arbAttrs = schema.getArbGeomParams(); prim->verts.foreach_attr([&](auto const &key, auto &arr) { - if (key == "v" || key == "nrm") { + if (key == "v" || key == "nrm" || key == "faceset") { return; } using T = std::decay_t; @@ -241,6 +243,9 @@ struct WriteAlembic2 : INode { void write_user_data(std::shared_ptr prim, OCompoundProperty& user) { auto &ud = prim->userData(); for (const auto& [key, value] : ud.m_data) { + if (key == "faceset_count" || zeno::starts_with(key, "faceset_")) { + continue; + } if (ud.has(key)) { if (user_attrs.count(key) == 0) { auto p = OInt32Property(user, key); @@ -343,6 +348,28 @@ struct WriteAlembic2 : INode { if (prim->polys.size() || prim->tris.size()) { // Create a PolyMesh class. OPolyMeshSchema &mesh = meshyObj.getSchema(); + auto &ud = prim->userData(); + std::vector faceSetNames; + std::vector> faceset_idxs; + if (ud.has("faceset_count")) { + int faceset_count = ud.get2("faceset_count"); + for (auto i = 0; i < faceset_count; i++) { + faceSetNames.emplace_back(ud.get2(zeno::format("faceset_{:04}", i))); + } + faceset_idxs.resize(faceset_count); + auto &faceset = prim->polys.attr("faceset"); + for (auto i = 0; i < faceset.size(); i++) { + faceset_idxs[faceset[i]].push_back(i); + } + for (auto i = 0; i < faceset_count; i++) { + OFaceSet faceset = mesh.createFaceSet(faceSetNames[i]); + OFaceSetSchema facesetSchema = faceset.getSchema (); + OFaceSetSchema::Sample my_face_set_samp ( faceset_idxs[i] ); + // faceset is visible, doesn't change. + facesetSchema.set ( my_face_set_samp ); + facesetSchema.setFaceExclusivity ( kFaceSetExclusive ); + } + } OCompoundProperty user = mesh.getUserProperties(); write_user_data(prim, user); From a01057c9443b031b9d76ff060a0c65f2b46e24da Mon Sep 17 00:00:00 2001 From: zhouhang95 <765229842@qq.com> Date: Wed, 6 Dec 2023 21:04:36 +0800 Subject: [PATCH 2/3] CopyPosAndNrmByIndex --- projects/Alembic/ReadAlembic.cpp | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/projects/Alembic/ReadAlembic.cpp b/projects/Alembic/ReadAlembic.cpp index dd556589f0..371e302238 100644 --- a/projects/Alembic/ReadAlembic.cpp +++ b/projects/Alembic/ReadAlembic.cpp @@ -822,5 +822,41 @@ ZENDEFNODE(AlembicSplitByName, { {"alembic"}, }); +struct CopyPosAndNrmByIndex: INode { + void apply() override { + auto prim = get_input("prim"); + auto prims = get_input("list")->get(); + for (auto p: prims) { + size_t size = p->size(); + auto index = p->add_attr("index"); + for (auto i = 0; i < size; i++) { + prim->verts[index[i]] = p->verts[i]; + } + if (prim->verts.attr_is("nrm")) { + auto &nrm = prim->verts.attr("nrm"); + auto &nrm_sub = p->verts.attr("nrm"); + for (auto i = 0; i < size; i++) { + nrm[index[i]] = nrm_sub[i]; + } + } + } + + set_output("out", prim); + } +}; + +ZENDEFNODE(CopyPosAndNrmByIndex, { + { + {"prim"}, + {"list", "list"}, + }, + { + {"out"}, + }, + {}, + {"alembic"}, +}); + + } // namespace zeno From 98a7bc56b2d91128e555c293beda850b1f00d2db Mon Sep 17 00:00:00 2001 From: zhouhang95 <765229842@qq.com> Date: Wed, 6 Dec 2023 21:07:24 +0800 Subject: [PATCH 3/3] fix --- projects/Alembic/ReadAlembic.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/Alembic/ReadAlembic.cpp b/projects/Alembic/ReadAlembic.cpp index 371e302238..8852f0acd9 100644 --- a/projects/Alembic/ReadAlembic.cpp +++ b/projects/Alembic/ReadAlembic.cpp @@ -828,7 +828,7 @@ struct CopyPosAndNrmByIndex: INode { auto prims = get_input("list")->get(); for (auto p: prims) { size_t size = p->size(); - auto index = p->add_attr("index"); + auto index = p->attr("index"); for (auto i = 0; i < size; i++) { prim->verts[index[i]] = p->verts[i]; }