Skip to content

Commit

Permalink
Merge branch 'master' into callable
Browse files Browse the repository at this point in the history
  • Loading branch information
iaomw committed Dec 25, 2023
2 parents 037fa28 + d3ecbc5 commit 3e4f15d
Show file tree
Hide file tree
Showing 97 changed files with 4,020 additions and 689 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Release/
/.idea
/.vscode
/.cache
CMakeKits.json
CMakeSettings.json
CMakeUserPresets.json
.vim_localrc
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@
[submodule "projects/Geometry/instant_meshes"]
path = projects/Geometry/instant_meshes
url = https://github.com/seeeagull/instant-meshes.git
[submodule "projects/Geometry/fTetWild"]
path = projects/Geometry/fTetWild
url = https://github.com/seeeagull/fTetWild.git
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

Open-source node system framework, to change your algorithmic code into useful tools to create much more complicated simulations!

<img src="https://zenustech.oss-cn-beijing.aliyuncs.com/Place-in-Github/202304/zeno_screenshot.png" width="640" position="left">
<img src="https://zenustech.oss-cn-beijing.aliyuncs.com/Place-in-Github/202312/ZENO2_v2023.jpg" width="640" position="left">

ZENO is an open-source, Node based 3D system able to produce cinematic physics effects at High Efficiency, it was designed for large scale simulations and has been tested on complex setups.
Aside of its simulation Tools, ZENO provides necessary visualization nodes for users to import and run simulations if you feel that the current software you are using is too slow.
Expand Down
38 changes: 38 additions & 0 deletions projects/Alembic/GetAlembicPrim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,44 @@ ZENDEFNODE(AllAlembicPrim, {
{"alembic"},
});

struct AlembicPrimList : INode {
virtual void apply() override {
auto abctree = get_input<ABCTree>("abctree");
auto prims = std::make_shared<zeno::ListObject>();
int use_xform = get_input2<int>("use_xform");
if (use_xform) {
prims = get_xformed_prims(abctree);
} else {
abctree->visitPrims([&] (auto const &p) {
auto np = std::static_pointer_cast<PrimitiveObject>(p->clone());
prims->arr.push_back(np);
});
}
for (auto &prim: prims->arr) {
auto _prim = std::dynamic_pointer_cast<PrimitiveObject>(prim);
if (get_input2<bool>("flipFrontBack")) {
flipFrontBack(_prim);
}
if (get_input2<int>("triangulate") == 1) {
zeno::primTriangulate(_prim.get());
}
}
set_output("prims", std::move(prims));
}
};

ZENDEFNODE(AlembicPrimList, {
{
{"bool", "flipFrontBack", "1"},
{"ABCTree", "abctree"},
{"bool", "use_xform", "0"},
{"bool", "triangulate", "0"},
},
{"prims"},
{},
{"alembic"},
});

struct GetAlembicCamera : INode {
virtual void apply() override {
auto abctree = get_input<ABCTree>("abctree");
Expand Down
172 changes: 168 additions & 4 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 @@ -80,9 +81,33 @@ static void read_attributes(std::shared_ptr<PrimitiveObject> prim, ICompoundProp
attr[i] = { data[ 3 * i], data[3 * i + 1], data[3 * i + 2]};
}
}
else if (prim->polys.size() == data.size()) {
auto &attr = prim->polys.add_attr<float>(p.getName());
for (auto i = 0; i < prim->polys.size(); i++) {
attr[i] = data[i];
}
}
else if (prim->polys.size() * 3 == data.size()) {
auto &attr = prim->polys.add_attr<zeno::vec3f>(p.getName());
for (auto i = 0; i < prim->polys.size(); i++) {
attr[i] = { data[ 3 * i], data[3 * i + 1], data[3 * i + 2]};
}
}
else if (prim->loops.size() == data.size()) {
auto &attr = prim->loops.add_attr<float>(p.getName());
for (auto i = 0; i < prim->loops.size(); i++) {
attr[i] = data[i];
}
}
else if (prim->loops.size() * 3 == data.size()) {
auto &attr = prim->loops.add_attr<zeno::vec3f>(p.getName());
for (auto i = 0; i < prim->loops.size(); i++) {
attr[i] = { data[ 3 * i], data[3 * i + 1], data[3 * i + 2]};
}
}
else {
if (!read_done) {
log_error("[alembic] can not load attr {}. Check if link to Points channel when exported from Houdini.", p.getName());
log_warn("[alembic] can not load float attr {}: {}.", p.getName(), data.size());
}
}
}
Expand All @@ -105,9 +130,21 @@ static void read_attributes(std::shared_ptr<PrimitiveObject> prim, ICompoundProp
attr[i] = data[i];
}
}
else if (prim->loops.size() == data.size()) {
auto &attr = prim->loops.add_attr<int>(p.getName());
for (auto i = 0; i < prim->loops.size(); i++) {
attr[i] = data[i];
}
}
else if (prim->polys.size() == data.size()) {
auto &attr = prim->polys.add_attr<int>(p.getName());
for (auto i = 0; i < prim->polys.size(); i++) {
attr[i] = data[i];
}
}
else {
if (!read_done) {
log_error("[alembic] can not load attr {}. Check if link to Points channel when exported from Houdini.", p.getName());
log_warn("[alembic] can not load int attr {}:{}.", p.getName(), data.size());
}
}
}
Expand All @@ -124,6 +161,25 @@ static void read_attributes(std::shared_ptr<PrimitiveObject> prim, ICompoundProp
attr[i] = {v[0], v[1], v[2]};
}
}
else if (prim->loops.size() == samp.getVals()->size()) {
auto &attr = prim->loops.add_attr<zeno::vec3f>(p.getName());
for (auto i = 0; i < prim->loops.size(); i++) {
auto v = samp.getVals()->get()[i];
attr[i] = {v[0], v[1], v[2]};
}
}
else if (prim->polys.size() == samp.getVals()->size()) {
auto &attr = prim->polys.add_attr<zeno::vec3f>(p.getName());
for (auto i = 0; i < prim->polys.size(); i++) {
auto v = samp.getVals()->get()[i];
attr[i] = {v[0], v[1], v[2]};
}
}
else {
if (!read_done) {
log_warn("[alembic] can not load vec3f attr {}:{}.", p.getName(), int(samp.getVals()->size()));
}
}
}
else if (IN3fGeomParam::matches(p)) {
if (!read_done) {
Expand All @@ -138,6 +194,25 @@ static void read_attributes(std::shared_ptr<PrimitiveObject> prim, ICompoundProp
attr[i] = {v[0], v[1], v[2]};
}
}
else if (prim->loops.size() == samp.getVals()->size()) {
auto &attr = prim->loops.add_attr<zeno::vec3f>(p.getName());
for (auto i = 0; i < prim->loops.size(); i++) {
auto v = samp.getVals()->get()[i];
attr[i] = {v[0], v[1], v[2]};
}
}
else if (prim->polys.size() == samp.getVals()->size()) {
auto &attr = prim->polys.add_attr<zeno::vec3f>(p.getName());
for (auto i = 0; i < prim->polys.size(); i++) {
auto v = samp.getVals()->get()[i];
attr[i] = {v[0], v[1], v[2]};
}
}
else {
if (!read_done) {
log_warn("[alembic] can not load N3f attr {}:{}.", p.getName(), int(samp.getVals()->size()));
}
}
}
else if (IC3fGeomParam::matches(p)) {
if (!read_done) {
Expand All @@ -152,10 +227,29 @@ static void read_attributes(std::shared_ptr<PrimitiveObject> prim, ICompoundProp
attr[i] = {v[0], v[1], v[2]};
}
}
else if (prim->loops.size() == samp.getVals()->size()) {
auto &attr = prim->loops.add_attr<zeno::vec3f>(p.getName());
for (auto i = 0; i < prim->loops.size(); i++) {
auto v = samp.getVals()->get()[i];
attr[i] = {v[0], v[1], v[2]};
}
}
else if (prim->polys.size() == samp.getVals()->size()) {
auto &attr = prim->polys.add_attr<zeno::vec3f>(p.getName());
for (auto i = 0; i < prim->polys.size(); i++) {
auto v = samp.getVals()->get()[i];
attr[i] = {v[0], v[1], v[2]};
}
}
else {
if (!read_done) {
log_warn("[alembic] can not load C3f attr {}:{}.", p.getName(), int(samp.getVals()->size()));
}
}
}
else {
if (!read_done) {
log_error("[alembic] can not load attr {}..", p.getName());
log_warn("[alembic] can not load attr {}..", p.getName());
}
}
}
Expand Down Expand Up @@ -210,9 +304,21 @@ static void read_user_data(std::shared_ptr<PrimitiveObject> prim, ICompoundPrope
auto value = param.getValue(iSS);
prim->userData().set2(p.getName(), value);
}
else if (IBoolProperty::matches(p)) {
IBoolProperty param(arbattrs, p.getName());

auto value = param.getValue(iSS);
prim->userData().set2(p.getName(), int(value));
}
else if (IInt16Property::matches(p)) {
IInt16Property param(arbattrs, p.getName());

auto value = param.getValue(iSS);
prim->userData().set2(p.getName(), int(value));
}
else {
if (!read_done) {
log_error("[alembic] can not load user data {}..", p.getName());
log_warn("[alembic] can not load user data {}..", p.getName());
}
}
}
Expand Down Expand Up @@ -642,6 +748,7 @@ void traverseABC(
tree.prim = foundABCPoints(points_sch, frameid, read_done);
tree.prim->userData().set2("_abc_name", obj.getName());
tree.prim->userData().set2("_abc_path", path);
tree.prim->userData().set2("faceset_count", 0);
} else if(Alembic::AbcGeom::ICurvesSchema::matches(md)) {
if (!read_done) {
log_debug("[alembic] found curves [{}]", obj.getName());
Expand All @@ -651,6 +758,7 @@ void traverseABC(
tree.prim = foundABCCurves(curves_sch, frameid, read_done);
tree.prim->userData().set2("_abc_name", obj.getName());
tree.prim->userData().set2("_abc_path", path);
tree.prim->userData().set2("faceset_count", 0);
} else if (Alembic::AbcGeom::ISubDSchema::matches(md)) {
if (!read_done) {
log_debug("[alembic] found SubD [{}]", obj.getName());
Expand Down Expand Up @@ -802,6 +910,11 @@ struct AlembicSplitByName: INode {
else {
new_prim->polys.resize(0);
}
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);
Expand Down Expand Up @@ -857,6 +970,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
Loading

0 comments on commit 3e4f15d

Please sign in to comment.