Skip to content

Commit

Permalink
load_object2
Browse files Browse the repository at this point in the history
  • Loading branch information
zhxx1987 committed Sep 6, 2024
1 parent 5e42239 commit 3dfd43d
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 4 deletions.
40 changes: 36 additions & 4 deletions zenovis/src/optx/RenderEngineOptx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct CppTimer {
};

static CppTimer timer, localTimer;
void cleanMesh(std::shared_ptr<zeno::PrimitiveObject> prim,
static void cleanMesh(zeno::PrimitiveObject* prim,
std::vector<zeno::vec3f> &verts,
std::vector<zeno::vec3f> &nrm,
std::vector<zeno::vec3f> &clr,
Expand Down Expand Up @@ -672,7 +672,40 @@ struct GraphicsManager {
vtab[key] = {(float const *)arr.data(), sizeof(arr[0]) / sizeof(float)};
});
auto ts = (int const *)prim->tris.data();
auto matids = (int const *)prim_in->tris.attr<int>("matid").data();
auto nvs = prim->verts.size();
auto nts = prim->tris.size();
// std::vector<zeno::vec3f> verts;
// std::vector<zeno::vec3f> nrm;
// std::vector<zeno::vec3f> clr;
// std::vector<zeno::vec3f> tang;
// std::vector<zeno::vec3f> uv;
// std::vector<zeno::vec3i> idxBuffer;
// cleanMesh(prim_in, verts, nrm, clr, tang, uv, idxBuffer);
// auto oPrim = std::make_shared<zeno::PrimitiveObject>();
// oPrim->verts.resize(verts.size());
// oPrim->add_attr<zeno::vec3f>("nrm");
// oPrim->add_attr<zeno::vec3f>("clr");
// oPrim->add_attr<zeno::vec3f>("uv");
// oPrim->add_attr<zeno::vec3f>("atang");
// oPrim->tris.resize(idxBuffer.size());
//
//
// oPrim->verts.attr<zeno::vec3f>("pos") = verts;
// oPrim->verts.attr<zeno::vec3f>("nrm") = nrm;
// oPrim->verts.attr<zeno::vec3f>("clr") = clr;
// oPrim->verts.attr<zeno::vec3f>("uv") = uv;
// oPrim->verts.attr<zeno::vec3f>("atang") = tang;
// oPrim->tris = idxBuffer;
//
// auto vs = (float const *)oPrim->verts.data();
// std::map<std::string, std::pair<float const *, size_t>> vtab;
// oPrim->verts.foreach_attr([&] (auto const &key, auto const &arr) {
// vtab[key] = {(float const *)arr.data(), sizeof(arr[0]) / sizeof(float)};
// });
// auto ts = (int const *)oPrim->tris.data();
// auto nvs = oPrim->verts.size();
// auto nts = oPrim->tris.size();

std::vector<std::string> matNameList(0);
if(matNum>0)
{
Expand All @@ -683,10 +716,9 @@ struct GraphicsManager {
matNameList.emplace_back(matName);
}
}
auto nvs = prim->verts.size();
auto nts = prim->tris.size();
auto mtlid = prim_in->userData().get2<std::string>("mtlid", "Default");
auto instID = prim_in->userData().get2<std::string>("instID", "Default");
auto matids = (int const *)prim_in->tris.attr<int>("matid").data();
xinxinoptix::load_object(key, mtlid, instID, vs, nvs, ts, nts, vtab, matids, matNameList);
}
}
Expand Down
30 changes: 30 additions & 0 deletions zenovis/xinxinoptix/optixPathTracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2846,6 +2846,20 @@ struct DrawDat {
};
static std::map<std::string, DrawDat> drawdats;

struct DrawDat2 {
std::vector<std::string> mtlidList;
std::string mtlid;
std::string instID;
std::vector<zeno::vec3f> pos;
std::vector<zeno::vec3f> nrm;
std::vector<zeno::vec3f> tang;
std::vector<zeno::vec3f> clr;
std::vector<zeno::vec3f> uv;
std::vector<int> triMats;
std::vector<zeno::vec3i> triIdx;
};
static std::map<std::string, DrawDat2> drawdats2;

std::set<std::string> uniqueMatsForMesh() {

std::set<std::string> result;
Expand Down Expand Up @@ -3496,6 +3510,22 @@ static void updateDynamicDrawInstObjects()
}
}
}
void load_object2(std::string const &key, std::string const &mtlid, const std::string &instID,
zeno::PrimitiveObject* prim, std::vector<int> &matids,
std::vector<std::string> const &matNameList)
{
DrawDat2 &dat = drawdats2[key];
dat.triMats = matids;
dat.mtlidList = matNameList;
dat.mtlid = mtlid;
dat.instID = instID;
dat.pos = prim->verts;
dat.nrm = prim->verts.attr<zeno::vec3f>("nrm");
dat.uv = prim->verts.attr<zeno::vec3f>("uv");
dat.clr = prim->verts.attr<zeno::vec3f>("clr");
dat.tang = prim->verts.attr<zeno::vec3f>("atang");
dat.triIdx = prim->tris;
}

void load_object(std::string const &key, std::string const &mtlid, const std::string &instID,
float const *verts, size_t numverts, int const *tris, size_t numtris,
Expand Down

0 comments on commit 3dfd43d

Please sign in to comment.