Skip to content

Commit

Permalink
Merge branch 'master' into remove-unused-texure
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouhang95 committed Apr 1, 2024
2 parents c99892d + 0111edd commit 9170a8e
Show file tree
Hide file tree
Showing 9 changed files with 928 additions and 356 deletions.
394 changes: 236 additions & 158 deletions projects/Alembic/ReadAlembic.cpp

Large diffs are not rendered by default.

376 changes: 196 additions & 180 deletions projects/Alembic/WriteAlembic.cpp

Large diffs are not rendered by default.

382 changes: 380 additions & 2 deletions projects/FBX/FBXSDK.cpp

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion ui/zenoedit/launch/serialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ void resolveOutputSocket(
AddStringList({"addNodeOutput", mockNode, outSock}, writer);

//add link from source output node to mockNode(ExtractDict).
AddStringList({"bindNodeInput", mockNode, mockSocket, outNodeId, dictlistName}, writer);
const QString& mockOutNode = nameMangling(graphIdPrefix, outNodeId);
AddStringList({"bindNodeInput", mockNode, mockSocket, mockOutNode, dictlistName}, writer);

realOutputId = mockNode;
realOutputSock = outSock;
Expand Down
4 changes: 4 additions & 0 deletions zeno/include/zeno/types/AttrVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,10 @@ struct AttrVector {
std::visit([&](auto &val) { val.clear(); }, val);
}
}
void clear_with_attr() {
values.clear();
attrs = {};
}
};

}
74 changes: 74 additions & 0 deletions zeno/src/nodes/neo/PrimCodecUVs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include <zeno/funcs/PrimitiveUtils.h>
#include <zeno/para/parallel_for.h>
#include <zeno/utils/log.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>

namespace zeno {

Expand Down Expand Up @@ -175,6 +178,77 @@ ZENO_DEFNODE(PrimUVEdgeDuplicate)({
{"primitive"},
});

struct PrimSplitVertexForSharedNormal : INode {
virtual void apply() override {
auto prim = get_input<PrimitiveObject>("prim");
if (prim->loops.attr_is<vec3f>("nrm")) {
std::vector<int> indexs;
indexs.reserve(prim->loops.size());
std::map<std::tuple<float, float, float>, int> mapping;
{
auto &nrm = prim->loops.attr<vec3f>("nrm");
for (auto i = 0; i < prim->loops.size(); i++) {
std::tuple<float, float, float> n = {nrm[i][0], nrm[i][1], nrm[i][2]};
if (mapping.count(n) == 0) {
int count = mapping.size();
mapping[n] = count;
}
indexs.push_back(mapping[n]);
}
prim->loops.erase_attr("nrm");
}
std::map<int, vec3f> revert_mapping;
for (auto [k, v]: mapping) {
revert_mapping[v] = {std::get<0>(k), std::get<1>(k), std::get<2>(k)};
}
std::map<std::pair<int, int>, int> new_mapping;
std::vector<int> new_indexs;
for (auto i = 0; i < prim->loops.size(); i++) {
std::pair<int, int> new_index = {prim->loops[i], indexs[i]};
if (new_mapping.count(new_index) == 0) {
int count = new_mapping.size();
new_mapping[new_index] = count;
}
new_indexs.push_back(new_mapping[new_index]);
}
std::map<int, std::pair<int, int>> revert_new_mapping;
for (auto [k, v]: new_mapping) {
revert_new_mapping[v] = k;
}
AttrVector<vec3f> verts(new_mapping.size());
auto &nrm = verts.add_attr<vec3f>("nrm");
for (auto i = 0; i < verts.size(); i++) {
verts[i] = prim->verts[revert_new_mapping[i].first];
nrm[i] = revert_mapping[revert_new_mapping[i].second];
}
prim->verts.foreach_attr<AttrAcceptAll>([&](auto const &key, auto &arr) {
using T = std::decay_t<decltype(arr[0])>;
zeno::log_info("key: {}", key);
auto &attr = verts.add_attr<T>(key);
for (auto i = 0; i < attr.size(); i++) {
attr[i] = arr[revert_new_mapping[i].first];
}
});

prim->verts = verts;
for (auto i = 0; i < prim->loops.size(); i++) {
prim->loops[i] = new_indexs[i];
}
}
set_output("prim", std::move(prim));
}
};

ZENO_DEFNODE(PrimSplitVertexForSharedNormal)({
{
"prim",
},
{
"prim",
},
{},
{"primitive"},
});
}

}
4 changes: 2 additions & 2 deletions zeno/src/nodes/neo/PrimFlipFaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ ZENO_API void primFlipFaces(PrimitiveObject *prim) {
std::swap(tri[2], tri[0]);
});
if (prim->tris.attr_is<vec3f>("uv0")) {
auto &uv1 = prim->tris.add_attr<vec3f>("uv1");
auto &uv0 = prim->tris.add_attr<vec3f>("uv0");
auto &uv2 = prim->tris.add_attr<vec3f>("uv2");
for (auto i = 0; i < prim->tris.size(); i++) {
std::swap(uv1[i], uv2[i]);
std::swap(uv0[i], uv2[i]);
}
}
}
Expand Down
37 changes: 28 additions & 9 deletions zeno/src/nodes/prim/PrimitivePolygonate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ ZENO_API void primPolygonate(PrimitiveObject *prim, bool with_uv) {
prim->loops.push_back(ind[2]);
prim->polys.push_back({base + i * 3, 3});
}
prim->polys.update();

prim->tris.foreach_attr<AttrAcceptAll>([&](auto const &key, auto const &arr) {
if (key == "uv0" || key == "uv1" || key == "uv2") {
return;
}
using T = std::decay_t<decltype(arr[0])>;
auto &newarr = prim->polys.add_attr<T>(key);
newarr.insert(newarr.end(), arr.begin(), arr.end());
for (auto i = 0; i < arr.size(); i++) {
newarr[polynum + i] = arr[i];
}
});
}

Expand All @@ -46,17 +49,21 @@ ZENO_API void primPolygonate(PrimitiveObject *prim, bool with_uv) {
prim->loops.push_back(ind[3]);
prim->polys.push_back({base + i * 4, 4});
}
prim->polys.update();

prim->quads.foreach_attr<AttrAcceptAll>([&](auto const &key, auto const &arr) {
if (key == "uv0" || key == "uv1" || key == "uv2" || key == "uv3") {
return;
}
using T = std::decay_t<decltype(arr[0])>;
auto &newarr = prim->polys.add_attr<T>(key);
newarr.insert(newarr.end(), arr.begin(), arr.end());
for (auto i = 0; i < arr.size(); i++) {
newarr[polynum + i] = arr[i];
}
});
}

polynum = prim->polys.size();
if (prim->lines.size()) {
int base = prim->loops.size();
for (int i = 0; i < prim->lines.size(); i++) {
Expand All @@ -65,26 +72,33 @@ ZENO_API void primPolygonate(PrimitiveObject *prim, bool with_uv) {
prim->loops.push_back(ind[1]);
prim->polys.push_back({base + i * 2, 2});
}
prim->polys.update();

prim->lines.foreach_attr([&](auto const &key, auto const &arr) {
using T = std::decay_t<decltype(arr[0])>;
auto &newarr = prim->polys.add_attr<T>(key);
newarr.insert(newarr.end(), arr.begin(), arr.end());
for (auto i = 0; i < arr.size(); i++) {
newarr[polynum + i] = arr[i];
}
});
}

polynum = prim->polys.size();
if (prim->points.size()) {
int base = prim->loops.size();
for (int i = 0; i < prim->points.size(); i++) {
auto ind = prim->points[i];
prim->loops.push_back(ind);
prim->polys.push_back({base + i, 1});
}
prim->polys.update();

prim->points.foreach_attr([&](auto const &key, auto const &arr) {
using T = std::decay_t<decltype(arr[0])>;
auto &newarr = prim->polys.add_attr<T>(key);
newarr.insert(newarr.end(), arr.begin(), arr.end());
for (auto i = 0; i < arr.size(); i++) {
newarr[polynum + i] = arr[i];
}
});
}

Expand Down Expand Up @@ -113,17 +127,22 @@ ZENO_API void primPolygonate(PrimitiveObject *prim, bool with_uv) {
for (auto i = 0; i < prim->loops.size(); i++) {
vec2f uv = prim->uvs[loopsuv[i]];
if (mapping.count({uv[0], uv[1]}) == false) {
mapping[{uv[0], uv[1]}] = loopsuv[i];
auto index = mapping.size();
mapping[{uv[0], uv[1]}] = index;
}
loopsuv[i] = mapping[{uv[0], uv[1]}];
}
prim->uvs.resize(mapping.size());
for (auto const&[uv, index]: mapping) {
prim->uvs[index] = {std::get<0>(uv), std::get<1>(uv)};
}
}
}

prim->tris.clear();
prim->quads.clear();
prim->lines.clear();
prim->points.clear();
prim->tris.clear_with_attr();
prim->quads.clear_with_attr();
prim->lines.clear_with_attr();
prim->points.clear_with_attr();
}

namespace {
Expand Down
10 changes: 6 additions & 4 deletions zeno/src/nodes/prim/PrimitiveTriangulate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
namespace zeno {

ZENO_API void primTriangulateQuads(PrimitiveObject *prim) {
if (prim->quads.size() == 0) {
return;
}
auto base = prim->tris.size();
prim->tris.resize(base + prim->quads.size() * 2);
bool hasmat = prim->quads.has_attr("matid");
Expand Down Expand Up @@ -160,10 +163,9 @@ ZENO_API void primTriangulate(PrimitiveObject *prim, bool with_uv, bool has_line
}
});
}
prim->loops.clear();
prim->polys.clear();
prim->loops.erase_attr("uvs");
prim->uvs.clear();
prim->loops.clear_with_attr();
prim->polys.clear_with_attr();
prim->uvs.clear_with_attr();
});
}

Expand Down

0 comments on commit 9170a8e

Please sign in to comment.