From a1e48a7545d7a403793a89f34cc564c0f7e62b63 Mon Sep 17 00:00:00 2001 From: zhouhang95 <765229842@qq.com> Date: Wed, 6 Nov 2024 20:16:53 +0800 Subject: [PATCH] PrimsFilterInUserdataMultiTags --- projects/Alembic/ReadAlembic.cpp | 84 +++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 2 deletions(-) diff --git a/projects/Alembic/ReadAlembic.cpp b/projects/Alembic/ReadAlembic.cpp index 9bc1cd6cd7..993ce171a6 100644 --- a/projects/Alembic/ReadAlembic.cpp +++ b/projects/Alembic/ReadAlembic.cpp @@ -1430,8 +1430,8 @@ struct PrimsFilterInUserdata: INode { ZENDEFNODE(PrimsFilterInUserdata, { { {"list", "list"}, - {"string", "name", ""}, - {"string", "filters"}, + {"string", "name"}, + {"multiline_string", "filters"}, {"bool", "contain", "1"}, {"bool", "fuzzy", "0"}, }, @@ -1442,6 +1442,86 @@ ZENDEFNODE(PrimsFilterInUserdata, { {"alembic"}, }); +struct PrimsFilterInUserdataMultiTags: INode { + void apply() override { + auto prims = get_input("list")->get(); + auto filter_str = get_input2("filters"); + std::vector filters = zeno::split_str(filter_str, {' ', '\n'}); + std::vector filters_; + auto output = std::make_shared(); + + for (auto &s: filters) { + if (s.length() > 0) { + filters_.push_back(s); + } + } + + auto name = get_input2("name"); + auto fuzzy = get_input2("fuzzy"); + for (auto p: prims) { + auto &ud = p->userData(); + if (ud.has(name)) { + if (fuzzy) { + for (auto & filter: filters_) { + if (ud.get2(name).find(filter) != std::string::npos) { + if (!output->lut.count(filter)) { + output->lut[filter] = std::make_shared(); + } + auto ptr = std::dynamic_pointer_cast(output->lut[filter]); + ptr->arr.push_back(p); + } + } + } + else { + auto value = ud.get2(name); + if (std::count(filters_.begin(), filters_.end(), value)) { + if (!output->lut.count(value)) { + output->lut[value] = std::make_shared(); + } + auto ptr = std::dynamic_pointer_cast(output->lut[value]); + ptr->arr.push_back(p); + } + } + } + else if (ud.has(name)) { + auto value = std::to_string(ud.get2(name)); + if (std::count(filters_.begin(), filters_.end(), value)) { + if (!output->lut.count(value)) { + output->lut[value] = std::make_shared(); + } + auto ptr = std::dynamic_pointer_cast(output->lut[value]); + ptr->arr.push_back(p); + } + } + else if (ud.has(name)) { + auto value = std::to_string(ud.get2(name)); + if (std::count(filters_.begin(), filters_.end(), value)) { + if (!output->lut.count(value)) { + output->lut[value] = std::make_shared(); + } + auto ptr = std::dynamic_pointer_cast(output->lut[value]); + ptr->arr.push_back(p); + } + } + } + set_output("out", output); + } +}; + +ZENDEFNODE(PrimsFilterInUserdataMultiTags, { + { + {"list", "list"}, + {"string", "name"}, + {"multiline_string", "filters"}, + {"bool", "fuzzy", "0"}, + }, + { + {"DictObject", "out"}, + }, + {}, + {"alembic"}, +}); + #ifdef ZENO_WITH_PYTHON3 static PyObject * pycheck(PyObject *pResult) { if (pResult == nullptr) {