From 696439a6406f3331fc05187cfd3ff742c2f75f6e Mon Sep 17 00:00:00 2001 From: zhouhang95 <765229842@qq.com> Date: Fri, 27 Sep 2024 16:00:54 +0800 Subject: [PATCH] NemoPrimListFilter --- projects/Nemo/node.cpp | 74 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/projects/Nemo/node.cpp b/projects/Nemo/node.cpp index 8969ba4303..fab29bbad8 100644 --- a/projects/Nemo/node.cpp +++ b/projects/Nemo/node.cpp @@ -225,5 +225,79 @@ ZENDEFNODE(NemoPlay, { {}, { "Nemo" }, }); + +struct NemoPrimListFilter : INode { + virtual void apply() override { + auto prims = get_input2("prims"); + auto pathInclude = zeno::split_str(get_input2("pathInclude"), {' ', '\n'}); + auto pathExclude = zeno::split_str(get_input2("pathExclude"), {' ', '\n'}); + auto facesetInclude = zeno::split_str(get_input2("facesetInclude"), {' ', '\n'}); + auto facesetExclude = zeno::split_str(get_input2("facesetExclude"), {' ', '\n'}); + for (auto it = prims->arr.begin(); it != prims->arr.end();) { + auto np = std::dynamic_pointer_cast(*it); + auto abc_path = np->userData().template get2("abcpath_0"); + bool contain = false; + if (pathInclude.empty()) { + contain = true; + } + else { + for (const auto & p: pathInclude) { + if (starts_with(abc_path, p)) { + contain = true; + } + } + } + if (contain) { + for (const auto & p: pathExclude) { + if (starts_with(abc_path, p)) { + contain = false; + } + } + } + if (contain && np->userData().template has("faceset_0")) { + auto faceset = np->userData().template get2("faceset_0"); + contain = false; + if (facesetInclude.empty()) { + contain = true; + } + else { + for (const auto & p: facesetInclude) { + if (starts_with(faceset, p)) { + contain = true; + } + } + } + if (contain) { + for (const auto & p: facesetExclude) { + if (starts_with(faceset, p)) { + contain = false; + } + } + } + } + if (contain) { + ++it; + } else { + it = prims->arr.erase(it); + } + } + set_output2("prims", prims); + } +}; + +ZENDEFNODE(NemoPrimListFilter, { + { + "prims", + { "string", "pathInclude", "" }, + { "string", "pathExclude", "" }, + { "string", "facesetInclude", "" }, + { "string", "facesetExclude", "" }, + }, + { + "prims", + }, + {}, + { "Nemo" }, +}); } }