Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

abc-tris-faceset-support #1677

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 46 additions & 10 deletions projects/Alembic/ReadAlembic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -890,36 +890,72 @@ struct AlembicSplitByName: INode {
set_output("namelist", namelist);
}

{
std::map<int, AttrVector<vec2i>> faceset_map;
auto dict = std::make_shared<zeno::DictObject>();
if (prim->polys.size()) {
std::map<int, std::vector<int>> faceset_map;
for (auto f = 0; f < faceset_count; f++) {
faceset_map[f] = {};
}
auto &faceset = prim->polys.add_attr<int>("faceset");
for (auto j = 0; j < faceset.size(); j++) {
auto f = faceset[j];
faceset_map[f].push_back(prim->polys[j]);
faceset_map[f].push_back(j);
}
auto dict = std::make_shared<zeno::DictObject>();
for (auto f = 0; f < faceset_count; f++) {
auto name = prim->userData().get2<std::string>(zeno::format("faceset_{:04}", f));
auto new_prim = std::dynamic_pointer_cast<PrimitiveObject>(prim->clone());
if (faceset_map.count(f)) {
new_prim->polys = faceset_map[f];
new_prim->polys.resize(faceset_map[f].size());
for (auto i = 0; i < faceset_map[f].size(); i++) {
new_prim->polys[i] = prim->polys[faceset_map[f][i]];
}
else {
new_prim->polys.resize(0);
new_prim->polys.foreach_attr<AttrAcceptAll>([&](auto const &key, auto &arr) {
using T = std::decay_t<decltype(arr[0])>;
auto &attr = prim->polys.attr<T>(key);
for (auto i = 0; i < arr.size(); i++) {
arr[i] = attr[faceset_map[f][i]];
}
});
new_prim->userData().del("faceset_count");
for (auto j = 0; j < faceset_count; j++) {
new_prim->userData().del(zeno::format("faceset_{:04}", j));
}
new_prim->userData().set2("_abc_faceset", name);
dict->lut[name] = std::move(new_prim);
}
}
else if (prim->tris.size()) {
std::map<int, std::vector<int>> faceset_map;
for (auto f = 0; f < faceset_count; f++) {
faceset_map[f] = {};
}
auto &faceset = prim->tris.add_attr<int>("faceset");
for (auto j = 0; j < faceset.size(); j++) {
auto f = faceset[j];
faceset_map[f].push_back(j);
}
for (auto f = 0; f < faceset_count; f++) {
auto name = prim->userData().get2<std::string>(zeno::format("faceset_{:04}", f));
auto new_prim = std::dynamic_pointer_cast<PrimitiveObject>(prim->clone());
new_prim->tris.resize(faceset_map[f].size());
for (auto i = 0; i < faceset_map[f].size(); i++) {
new_prim->tris[i] = prim->tris[faceset_map[f][i]];
}
new_prim->tris.foreach_attr<AttrAcceptAll>([&](auto const &key, auto &arr) {
using T = std::decay_t<decltype(arr[0])>;
auto &attr = prim->tris.attr<T>(key);
for (auto i = 0; i < arr.size(); i++) {
arr[i] = attr[faceset_map[f][i]];
}
});
new_prim->userData().del("faceset_count");
for (auto j = 0; j < faceset_count; j++) {
new_prim->userData().del(zeno::format("faceset_{:04}", j));
}
new_prim->userData().set2("_abc_faceset", name);
dict->lut[name] = std::move(new_prim);
}
set_output("dict", dict);

}
set_output("dict", dict);
}
};

Expand Down
21 changes: 21 additions & 0 deletions zeno/src/nodes/prim/PrimitiveTriangulate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ ZENO_API void primTriangulate(PrimitiveObject *prim, bool with_uv, bool has_line
} else {
prim->tris.add_attr<int>("matid");
}
bool has_faceset = prim->polys.has_attr("faceset");
if (has_faceset) {
auto &tris_faceset = prim->tris.add_attr<int>("faceset");
std::fill(tris_faceset.begin(), tris_faceset.end(), -1);
}


if (!(prim->loops.has_attr("uvs") && prim->uvs.size() > 0) || !with_uv) {
Expand All @@ -90,13 +95,21 @@ ZENO_API void primTriangulate(PrimitiveObject *prim, bool with_uv, bool has_line
prim->loops[start + 1],
prim->loops[start + 2]);
prim->tris.attr<int>("matid")[scanbase] = matidx;
int faceset_idx = -1;
if (has_faceset) {
faceset_idx = prim->polys.attr<int>("faceset")[i];
prim->tris.attr<int>("faceset")[scanbase] = faceset_idx;
}
scanbase++;
for (int j = 3; j < len; j++) {
prim->tris[scanbase] = vec3i(
prim->loops[start],
prim->loops[start + j - 1],
prim->loops[start + j]);
prim->tris.attr<int>("matid")[scanbase] = matidx;
if (has_faceset) {
prim->tris.attr<int>("faceset")[scanbase] = faceset_idx;
}
scanbase++;
}
}
Expand Down Expand Up @@ -135,6 +148,11 @@ ZENO_API void primTriangulate(PrimitiveObject *prim, bool with_uv, bool has_line
prim->loops[start + 1],
prim->loops[start + 2]);
prim->tris.attr<int>("matid")[scanbase] = matidx;
int faceset_idx = -1;
if (has_faceset) {
faceset_idx = prim->polys.attr<int>("faceset")[i];
prim->tris.attr<int>("faceset")[scanbase] = faceset_idx;
}
scanbase++;
for (int j = 3; j < len; j++) {
uv0[scanbase] = {uvs[loop_uv[start]][0], uvs[loop_uv[start]][1], 0};
Expand All @@ -145,6 +163,9 @@ ZENO_API void primTriangulate(PrimitiveObject *prim, bool with_uv, bool has_line
prim->loops[start + j - 1],
prim->loops[start + j]);
prim->tris.attr<int>("matid")[scanbase] = matidx;
if (has_faceset) {
prim->tris.attr<int>("faceset")[scanbase] = faceset_idx;
}
scanbase++;
}
}
Expand Down
Loading