Skip to content

Commit

Permalink
Merge pull request #1878 from zenustech/improve-abc-attr-write
Browse files Browse the repository at this point in the history
improve-abc-attr-write
  • Loading branch information
zhxx1987 authored Apr 10, 2024
2 parents a55abea + 2c6e56c commit d3209c6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
6 changes: 6 additions & 0 deletions projects/Alembic/ReadAlembic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ static void read_velocity(std::shared_ptr<PrimitiveObject> prim, V3fArraySampleP
template<typename T>
void attr_from_data(std::shared_ptr<PrimitiveObject> prim, GeometryScope scope, std::string attr_name, std::vector<T> &data) {
if (scope == GeometryScope::kUniformScope) {
if (zeno::ends_with(attr_name, "_polys")) {
attr_name = attr_name.substr(0, attr_name.size() - 6);
}
if (prim->polys.size() == data.size()) {
auto &attr = prim->polys.add_attr<T>(attr_name);
for (auto i = 0; i < prim->polys.size(); i++) {
Expand Down Expand Up @@ -161,6 +164,9 @@ void attr_from_data(std::shared_ptr<PrimitiveObject> prim, GeometryScope scope,
}
}
else if (scope == GeometryScope::kFacevaryingScope) {
if (zeno::ends_with(attr_name, "_loops")) {
attr_name = attr_name.substr(0, attr_name.size() - 6);
}
if (prim->loops.size() == data.size()) {
auto &attr = prim->loops.add_attr<T>(attr_name);
for (auto i = 0; i < prim->loops.size(); i++) {
Expand Down
18 changes: 14 additions & 4 deletions projects/Alembic/WriteAlembic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,16 @@ void write_attrs(
}
});
if (prim->loops.size() > 0) {
prim->loops.foreach_attr<std::variant<vec3f, float, int>>([&](auto const &key, auto &arr) {
if (key == "uvs") {
prim->loops.foreach_attr<std::variant<vec3f, float, int>>([&](auto const &_key, auto &arr) {
if (_key == "uvs") {
return;
}
std::string key = _key;
std::string full_key = path + '/' + key;
if (verts_attrs.count(full_key)) {
key += "_loops";
full_key = path + '/' + key;
}
using T = std::decay_t<decltype(arr[0])>;
if constexpr (std::is_same_v<T, zeno::vec3f>) {
if (loops_attrs.count(full_key) == 0) {
Expand Down Expand Up @@ -308,11 +313,16 @@ void write_attrs(
});
}
if (prim->polys.size() > 0) {
prim->polys.foreach_attr<std::variant<vec3f, float, int>>([&](auto const &key, auto &arr) {
if (key == "faceset" || key == "matid" || key == "abcpath") {
prim->polys.foreach_attr<std::variant<vec3f, float, int>>([&](auto const &_key, auto &arr) {
if (_key == "faceset" || _key == "matid" || _key == "abcpath") {
return;
}
std::string key = _key;
std::string full_key = path + '/' + key;
if (verts_attrs.count(full_key) || loops_attrs.count(full_key)) {
key += "_polys";
full_key = path + '/' + key;
}
using T = std::decay_t<decltype(arr[0])>;
if constexpr (std::is_same_v<T, zeno::vec3f>) {
if (polys_attrs.count(full_key) == 0) {
Expand Down

0 comments on commit d3209c6

Please sign in to comment.