Skip to content

Commit

Permalink
Merge pull request #1605 from zenustech/PrimsFilterInUserdata
Browse files Browse the repository at this point in the history
PrimsFilterInUserdata
  • Loading branch information
zhxx1987 authored Dec 11, 2023
2 parents c8d15f4 + 55da698 commit 57adb2f
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions projects/Alembic/ReadAlembic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <cstring>
#include <cstdio>
#include <filesystem>
#include <zeno/utils/string.h>

using namespace Alembic::AbcGeom;

Expand Down Expand Up @@ -949,6 +950,57 @@ ZENDEFNODE(CopyPosAndNrmByIndex, {
{"alembic"},
});

struct PrimsFilterInUserdata: INode {
void apply() override {
auto prims = get_input<ListObject>("list")->get<PrimitiveObject>();
auto filter_str = get_input2<std::string>("filters");
std::vector<std::string> filters = zeno::split_str(filter_str);
std::vector<std::string> filters_;
auto out_list = std::make_shared<ListObject>();

for (auto &s: filters) {
if (s.length() > 0) {
filters_.push_back(s);
}
}

auto name = get_input2<std::string>("name");
auto contain = get_input2<bool>("contain");
for (auto p: prims) {
auto &ud = p->userData();
bool this_contain = false;
if (ud.has<std::string>(name)) {
this_contain = std::count(filters_.begin(), filters_.end(), ud.get2<std::string>(name)) > 0;
}
else if (ud.has<int>(name)) {
this_contain = std::count(filters_.begin(), filters_.end(), std::to_string(ud.get2<int>(name))) > 0;
}
else if (ud.has<float>(name)) {
this_contain = std::count(filters_.begin(), filters_.end(), std::to_string(ud.get2<float>(name))) > 0;
}
bool insert = (contain && this_contain) || (!contain && !this_contain);
if (insert) {
out_list->arr.push_back(p);
}
}
set_output("out", out_list);
}
};

ZENDEFNODE(PrimsFilterInUserdata, {
{
{"list", "list"},
{"string", "name", ""},
{"string", "filters"},
{"bool", "contain", "1"},
},
{
{"out"},
},
{},
{"alembic"},
});



} // namespace zeno

0 comments on commit 57adb2f

Please sign in to comment.