Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into sky
Browse files Browse the repository at this point in the history
  • Loading branch information
iaomw committed Jun 3, 2024
2 parents 946a08f + f989144 commit 67a9b6b
Show file tree
Hide file tree
Showing 65 changed files with 842 additions and 148 deletions.
74 changes: 67 additions & 7 deletions projects/Alembic/ReadAlembic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <filesystem>
#include <zeno/utils/string.h>
#include <zeno/utils/scope_exit.h>
#include <numeric>

#ifdef ZENO_WITH_PYTHON3
#include <Python.h>
Expand Down Expand Up @@ -347,7 +348,7 @@ static void read_attributes2(std::shared_ptr<PrimitiveObject> prim, ICompoundPro
if (IFloatGeomParam::matches(p)) {
IFloatGeomParam param(arbattrs, p.getName());

IFloatGeomParam::Sample samp = param.getIndexedValue(iSS);
IFloatGeomParam::Sample samp = param.getExpandedValue(iSS);
std::vector<float> data;
data.resize(samp.getVals()->size());
for (auto i = 0; i < samp.getVals()->size(); i++) {
Expand All @@ -361,7 +362,7 @@ static void read_attributes2(std::shared_ptr<PrimitiveObject> prim, ICompoundPro
else if (IInt32GeomParam::matches(p)) {
IInt32GeomParam param(arbattrs, p.getName());

IInt32GeomParam::Sample samp = param.getIndexedValue(iSS);
IInt32GeomParam::Sample samp = param.getExpandedValue(iSS);
std::vector<int> data;
data.resize(samp.getVals()->size());
for (auto i = 0; i < samp.getVals()->size(); i++) {
Expand All @@ -375,7 +376,7 @@ static void read_attributes2(std::shared_ptr<PrimitiveObject> prim, ICompoundPro
else if (IV3fGeomParam::matches(p)) {
IV3fGeomParam param(arbattrs, p.getName());

IV3fGeomParam::Sample samp = param.getIndexedValue(iSS);
IV3fGeomParam::Sample samp = param.getExpandedValue(iSS);
std::vector<vec3f> data;
data.resize(samp.getVals()->size());
for (auto i = 0; i < samp.getVals()->size(); i++) {
Expand All @@ -390,7 +391,7 @@ static void read_attributes2(std::shared_ptr<PrimitiveObject> prim, ICompoundPro
else if (IN3fGeomParam::matches(p)) {
IN3fGeomParam param(arbattrs, p.getName());

IN3fGeomParam::Sample samp = param.getIndexedValue(iSS);
IN3fGeomParam::Sample samp = param.getExpandedValue(iSS);
std::vector<vec3f> data;
data.resize(samp.getVals()->size());
for (auto i = 0; i < samp.getVals()->size(); i++) {
Expand All @@ -405,7 +406,7 @@ static void read_attributes2(std::shared_ptr<PrimitiveObject> prim, ICompoundPro
else if (IC3fGeomParam::matches(p)) {
IC3fGeomParam param(arbattrs, p.getName());

IC3fGeomParam::Sample samp = param.getIndexedValue(iSS);
IC3fGeomParam::Sample samp = param.getExpandedValue(iSS);
std::vector<vec3f> data;
data.resize(samp.getVals()->size());
for (auto i = 0; i < samp.getVals()->size(); i++) {
Expand All @@ -417,6 +418,62 @@ static void read_attributes2(std::shared_ptr<PrimitiveObject> prim, ICompoundPro
}
attr_from_data_vec(prim, samp.getScope(), p.getName(), data);
}
else if (IC4fGeomParam::matches(p)) {
IC4fGeomParam param(arbattrs, p.getName());

IC4fGeomParam::Sample samp = param.getExpandedValue(iSS);
std::vector<vec4f> data;
data.resize(samp.getVals()->size());
std::vector<vec3f> data_xyz(samp.getVals()->size());
std::vector<float> data_w(samp.getVals()->size());
for (auto i = 0; i < samp.getVals()->size(); i++) {
auto v = samp.getVals()->get()[i];
data[i] = {v[0], v[1], v[2], v[3]};
data_xyz[i] = {v[0], v[1], v[2]};
data_w[i] = v[3];
}
if (!read_done) {
log_info("[alembic] C4f attr {}, len {}.", p.getName(), data.size());
}
attr_from_data_vec(prim, samp.getScope(), p.getName(), data);
attr_from_data_vec(prim, samp.getScope(), p.getName() + "_rgb", data_xyz);
attr_from_data_vec(prim, samp.getScope(), p.getName() + "_a", data_w);
}
else {
log_info("[alembic] unknown attr {}.", p.getName());
zeno::log_info("getExtent {} ", p.getDataType().getExtent());
zeno::log_info("getNumBytes {} ", p.getDataType().getNumBytes());
zeno::log_info("getPod {} ", p.getDataType().getPod());
}
}
{
if (prim->loops.attr_keys<AttrAcceptAll>().size() == 0) {
return;
}
if (prim->loops.attr_keys<AttrAcceptAll>().size() == 1 && prim->loops.has_attr("uvs")) {
return;
}
if (!prim->loops.has_attr("uvs")) {
prim->loops.add_attr<int>("uvs");
prim->uvs.emplace_back();
}
{
std::vector<vec2f> uvs(prim->loops.size());
auto &uv_index = prim->loops.attr<int>("uvs");
for (auto i = 0; i < prim->loops.size(); i++) {
uvs[i] = prim->uvs[uv_index[i]];
}
prim->uvs.values = uvs;
std::iota(uv_index.begin(), uv_index.end(), 0);
prim->loops.foreach_attr<AttrAcceptAll>([&] (auto const &key, auto &arr) {
if (key == "uvs") {
return;
}
using T = std::decay_t<decltype(arr[0])>;
auto &attr = prim->uvs.add_attr<T>(key);
std::copy(arr.begin(), arr.end(), attr.begin());
});
}
}
}

Expand Down Expand Up @@ -1161,6 +1218,10 @@ ZENDEFNODE(ReadAlembic, {
});

std::shared_ptr<ListObject> abc_split_by_name(std::shared_ptr<PrimitiveObject> prim, bool add_when_none) {
auto list = std::make_shared<ListObject>();
if (prim->verts.size() == 0) {
return list;
}
int faceset_count = prim->userData().get2<int>("faceset_count");
if (add_when_none && faceset_count == 0) {
auto name = prim->userData().get2<std::string>("_abc_name");
Expand All @@ -1171,7 +1232,6 @@ std::shared_ptr<ListObject> abc_split_by_name(std::shared_ptr<PrimitiveObject> p
for (auto f = 0; f < faceset_count; f++) {
faceset_map[f] = {};
}
auto list = std::make_shared<ListObject>();
if (prim->polys.size()) {
auto &faceset = prim->polys.add_attr<int>("faceset");
for (auto j = 0; j < faceset.size(); j++) {
Expand Down Expand Up @@ -1358,7 +1418,7 @@ ZENDEFNODE(PrimsFilterInUserdata, {
{"bool", "fuzzy", "0"},
},
{
{"out"},
{"list", "out"},
},
{},
{"alembic"},
Expand Down
52 changes: 46 additions & 6 deletions projects/Alembic/WriteAlembic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ void prim_to_poly_if_only_vertex(PrimitiveObject* p) {
struct WriteAlembic2 : INode {
OArchive archive;
OPolyMesh meshyObj;
OPoints pointsObj;
std::string usedPath;
std::map<std::string, std::any> verts_attrs;
std::map<std::string, std::any> loops_attrs;
Expand Down Expand Up @@ -582,7 +583,12 @@ struct WriteAlembic2 : INode {
"None"
);
real_frame_start = -1;
meshyObj = OPolyMesh( OObject( archive, 1 ), "mesh" );
if (get_input2<bool>("outputPoint")) {
pointsObj = OPoints (OObject( archive, 1 ), "points");
}
else {
meshyObj = OPolyMesh( OObject( archive, 1 ), "mesh" );
}
verts_attrs.clear();
loops_attrs.clear();
polys_attrs.clear();
Expand All @@ -602,7 +608,7 @@ struct WriteAlembic2 : INode {
if (flipFrontBack) {
primFlipFaces(prim.get());
}
{
if (!get_input2<bool>("outputPoint")) {
prim_to_poly_if_only_vertex(prim.get());
// Create a PolyMesh class.
OPolyMeshSchema &mesh = meshyObj.getSchema();
Expand Down Expand Up @@ -668,7 +674,9 @@ struct WriteAlembic2 : INode {
uvsamp);
write_velocity(prim, mesh_samp);
write_normal(prim, mesh_samp);
write_attrs(verts_attrs, loops_attrs, polys_attrs, "", prim, mesh, frameid, real_frame_start, prim_size_per_frame);
if (get_input2<bool>("outputToMaya") == false) {
write_attrs(verts_attrs, loops_attrs, polys_attrs, "", prim, mesh, frameid, real_frame_start, prim_size_per_frame);
}
mesh.set( mesh_samp );
}
else {
Expand All @@ -678,11 +686,36 @@ struct WriteAlembic2 : INode {
Int32ArraySample( vertex_count_per_face.data(), vertex_count_per_face.size() ));
write_velocity(prim, mesh_samp);
write_normal(prim, mesh_samp);
write_attrs(verts_attrs, loops_attrs, polys_attrs, "", prim, mesh, frameid, real_frame_start, prim_size_per_frame);
if (get_input2<bool>("outputToMaya") == false) {
write_attrs(verts_attrs, loops_attrs, polys_attrs, "", prim, mesh, frameid, real_frame_start, prim_size_per_frame);
}
mesh.set( mesh_samp );
}
}
}
else {
OPointsSchema &points = pointsObj.getSchema();
OCompoundProperty user = points.getUserProperties();
write_user_data(user_attrs, "", prim, user, frameid, real_frame_start);
points.setTimeSampling(1);
OPointsSchema::Sample samp(V3fArraySample( ( const V3f * )prim->verts.data(), prim->verts.size() ));
std::vector<uint64_t> ids(prim->verts.size());
if (prim->verts.attr_is<int>("id")) {
auto &ids_ = prim->verts.attr<int>("id");
for (auto i = 0; i < prim->verts.size(); i++) {
ids[i] = ids_[i];
}
}
else {
std::iota(ids.begin(), ids.end(), 0);
}
samp.setIds(Alembic::Abc::UInt64ArraySample(ids.data(), ids.size()));
write_velocity(prim, samp);
if (get_input2<bool>("outputToMaya") == false) {
write_attrs(verts_attrs, loops_attrs, polys_attrs, "", prim, points, frameid, real_frame_start, prim_size_per_frame);
}
points.set( samp );
}
}
};

Expand All @@ -695,6 +728,8 @@ ZENDEFNODE(WriteAlembic2, {
{"int", "frame_end", "100"},
{"float", "fps", "25"},
{"bool", "flipFrontBack", "1"},
{"bool", "outputPoint", "0"},
{"bool", "outputToMaya", "0"},
},
{
},
Expand Down Expand Up @@ -916,7 +951,9 @@ struct WriteAlembicPrims : INode {
uvsamp);
write_velocity(prim, mesh_samp);
write_normal(prim, mesh_samp);
write_attrs(verts_attrs, loops_attrs, polys_attrs, path, prim, mesh, frameid, real_frame_start, prim_size_per_frame[path]);
if (get_input2<bool>("outputToMaya") == false) {
write_attrs(verts_attrs, loops_attrs, polys_attrs, path, prim, mesh, frameid, real_frame_start, prim_size_per_frame[path]);
}
mesh.set( mesh_samp );
}
else {
Expand All @@ -926,7 +963,9 @@ struct WriteAlembicPrims : INode {
Int32ArraySample( vertex_count_per_face.data(), vertex_count_per_face.size() ));
write_velocity(prim, mesh_samp);
write_normal(prim, mesh_samp);
write_attrs(verts_attrs, loops_attrs, polys_attrs, path, prim, mesh, frameid, real_frame_start, prim_size_per_frame[path]);
if (get_input2<bool>("outputToMaya") == false) {
write_attrs(verts_attrs, loops_attrs, polys_attrs, path, prim, mesh, frameid, real_frame_start, prim_size_per_frame[path]);
}
mesh.set( mesh_samp );
}
}
Expand All @@ -945,6 +984,7 @@ ZENDEFNODE(WriteAlembicPrims, {
{"int", "frame_end", "100"},
{"float", "fps", "25"},
{"bool", "flipFrontBack", "1"},
{"bool", "outputToMaya", "0"},
},
{
},
Expand Down
1 change: 1 addition & 0 deletions projects/CUDA/remesh/simplification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <zeno/funcs/PrimitiveUtils.h>
#include <zeno/utils/log.h>
#include <zeno/zeno.h>
#include <mutex>

#include "zensim/container/Bht.hpp"
#include "zensim/omp/execution/ExecutionPolicy.hpp"
Expand Down
48 changes: 48 additions & 0 deletions projects/CUDA/utils/Primitives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4633,6 +4633,54 @@ ZENDEFNODE(AdvanceFrame, {
{"zs_geom"},
});

struct PrimAssignRefAttrib : INode {
virtual void apply() override {
auto points = get_input<PrimitiveObject>("prim");
auto prim = get_input<PrimitiveObject>("ref_prim");
auto idTag = get_input2<std::string>("pointIdTag");
auto tag = get_input2<std::string>("attribTag");

auto pointIndex = points->attr<int>(idTag);

auto assignAttrib = [&pointIndex](auto &dstAttrib, const auto &srcAttrib) {
if constexpr (zs::is_same_v<RM_CVREF_T(dstAttrib), RM_CVREF_T(srcAttrib)>) {
#pragma omp parallel for
for (auto index = 0; index < dstAttrib.size(); ++index) {
dstAttrib[index] = srcAttrib[(int)pointIndex[index]];
}
} else
throw std::runtime_error(
fmt::format("destination attrib [{}], source attrib [{}]\n",
zs::get_var_type_str(dstAttrib), zs::get_var_type_str(srcAttrib)));
};

if (tag == "pos") {
assignAttrib(points->verts.values, prim->verts.values);
} else {
zs::match([&verts = points->verts, &tag](const auto &src) {
verts.add_attr<RM_CVREF_T(src[0])>(tag);
})(prim->verts.attr(tag));
zs::match([&assignAttrib](auto &dst, const auto &src) {
assignAttrib(dst, src);
})(points->verts.attr(tag), prim->verts.attr(tag));
}

set_output("prim", get_input("prim"));
}
};

ZENDEFNODE(PrimAssignRefAttrib, {
{
"prim",
"ref_prim",
{"string", "pointIdTag", "bvh_id"},
{"string", "attribTag"},
},
{"prim"},
{},
{"primitive"},
});

struct RemovePrimitiveTopo : INode {
void apply() override {
auto prim = get_input2<PrimitiveObject>("prim");
Expand Down
13 changes: 8 additions & 5 deletions projects/FBX/FBXSDK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#include <zeno/types/DictObject.h>
#include <zeno/types/ListObject.h>

#ifdef ZENO_FBXSDK
#include <fbxsdk.h>
#include "zeno/utils/log.h"
#include <zeno/types/UserData.h>
#include "zeno/types/PrimitiveObject.h"
Expand All @@ -19,6 +17,9 @@
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>

#ifdef ZENO_FBXSDK
#include <fbxsdk.h>

namespace FBX{
void GetChildNodePathRecursive(FbxNode* node, std::string& path) {
if (node->GetParent()) {
Expand Down Expand Up @@ -1089,6 +1090,9 @@ ZENDEFNODE(NewFBXImportCamera, {
{},
{"primitive"},
});
}
#endif
namespace zeno {
struct NewFBXBoneDeform : INode {
std::vector<std::string> getBoneNames(PrimitiveObject *prim) {
auto boneName_count = prim->userData().get2<int>("boneName_count");
Expand Down Expand Up @@ -1173,7 +1177,7 @@ struct NewFBXBoneDeform : INode {
auto &bi = prim->verts.add_attr<vec4i>("boneName");
auto &bw = prim->verts.add_attr<vec4f>("boneWeight");
size_t vert_count = prim->verts.size();
#pragma omp parallel for
#pragma omp parallel for
for (auto i = 0; i < vert_count; i++) {
auto opos = prim->verts[i];
vec3f pos = {};
Expand Down Expand Up @@ -1302,5 +1306,4 @@ ZENDEFNODE(BoneTransformView, {
{},
{"debug"},
});
}
#endif
}
4 changes: 3 additions & 1 deletion ui/include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ struct RECORD_SETTING
bool bMask;
bool bExr;

RECORD_SETTING() : fps(24), bitrate(200000), numMSAA(0), numOptix(1), width(1280), height(720), bExportVideo(false), needDenoise(false), bAutoRemoveCache(true), bAov(false), bExr(false), bMask(false) {}
QString exePath;

RECORD_SETTING() : fps(24), bitrate(200000), numMSAA(0), numOptix(1), width(1280), height(720), bExportVideo(false), needDenoise(false), bAutoRemoveCache(true), bAov(false), bExr(false), bMask(false){}
};

struct LAYOUT_SETTING {
Expand Down
Loading

0 comments on commit 67a9b6b

Please sign in to comment.