From 5e42239475848f0a45e26d31cd78d3e2918d427a Mon Sep 17 00:00:00 2001 From: zhxx1987 Date: Fri, 6 Sep 2024 00:41:37 +0800 Subject: [PATCH 1/3] clean mesh for rendering, read ply color --- projects/CalcGeometryUV/PrimitivePlyIO.cpp | 39 ++- zeno/src/nodes/neo/PrimUnmerge.cpp | 281 +++++++++++++++++++++ zenovis/src/optx/RenderEngineOptx.cpp | 120 ++++++++- 3 files changed, 437 insertions(+), 3 deletions(-) diff --git a/projects/CalcGeometryUV/PrimitivePlyIO.cpp b/projects/CalcGeometryUV/PrimitivePlyIO.cpp index 26c94a90cf..08d3427b38 100644 --- a/projects/CalcGeometryUV/PrimitivePlyIO.cpp +++ b/projects/CalcGeometryUV/PrimitivePlyIO.cpp @@ -18,6 +18,7 @@ static void readply( std::vector &verts, + std::vector &color, std::vector &zfaces, const std::string & filepath ) { @@ -36,11 +37,20 @@ static void readply( tinyply::PlyFile file; file.parse_header(*file_stream); - std::shared_ptr vertices, faces; + std::shared_ptr vertices, r,g,b, faces; try { vertices = file.request_properties_from_element("vertex", { "x", "y", "z" }); } catch (const std::exception & e) { std::cerr << "tinyply exception: " << e.what() << std::endl; } + try { r = file.request_properties_from_element("vertex", {"red"}); } + catch (const std::exception & e) { std::cerr << "tinyply exception: " << e.what() << std::endl; } + + try { g = file.request_properties_from_element("vertex", {"green"}); } + catch (const std::exception & e) { std::cerr << "tinyply exception: " << e.what() << std::endl; } + + try { b = file.request_properties_from_element("vertex", {"blue"}); } + catch (const std::exception & e) { std::cerr << "tinyply exception: " << e.what() << std::endl; } + try { faces = file.request_properties_from_element("face", { "vertex_indices" }, 3); } catch (const std::exception & e) { std::cerr << "tinyply exception: " << e.what() << std::endl; } @@ -59,6 +69,30 @@ static void readply( verts.emplace_back(v[0], v[1], v[2]); } } + + if(r->count>0) + { + color.resize(verts.size()); + if(r->t == tinyply::Type::UINT8 || r->t == tinyply::Type::INT8) + { + std::vector rr; + std::vector gg; + std::vector bb; + rr.resize(r->count); + gg.resize(g->count); + bb.resize(b->count); + std::memcpy(rr.data(), r->buffer.get(), r->count ); + std::memcpy(gg.data(), g->buffer.get(), g->count ); + std::memcpy(bb.data(), b->buffer.get(), b->count ); + + for(size_t i=0;ibuffer.size_bytes(); if (faces->t == tinyply::Type::INT32 || faces->t == tinyply::Type::UINT32) { zfaces.resize(faces->count); @@ -89,8 +123,9 @@ struct ReadPlyPrimitive : zeno::INode { auto path = get_input("path")->get(); auto prim = std::make_shared(); auto &pos = prim->verts; + auto &clr = prim->add_attr("clr"); auto &tris = prim->tris; - readply(pos, tris, path); + readply(pos, clr, tris, path); prim->resize(pos.size()); set_output("prim", std::move(prim)); } diff --git a/zeno/src/nodes/neo/PrimUnmerge.cpp b/zeno/src/nodes/neo/PrimUnmerge.cpp index 1f547ef195..8d906dc216 100644 --- a/zeno/src/nodes/neo/PrimUnmerge.cpp +++ b/zeno/src/nodes/neo/PrimUnmerge.cpp @@ -352,5 +352,286 @@ ZENDEFNODE(PrimUnmerge, { {"primitive"}, }); +void cleanMesh(std::shared_ptr prim, + std::vector &verts, + std::vector &nrm, + std::vector &clr, + std::vector &tang, + std::vector &uv, + std::vector &idxBuffer) +{ + //first pass, scan the prim to see if verts require duplication + std::vector> vert_uv; + std::vector> idx_mapping; + vert_uv.resize(prim->verts.size()); + idx_mapping.resize(prim->verts.size()); + int count = 0; + for(int i=0;itris.size();i++) + { + //so far, all value has already averaged on verts, except uv + zeno::vec3i idx = prim->tris[i]; + for(int j=0;j<3;j++) + { + std::string uv_name; + uv_name = "uv" + std::to_string(j); + auto vid = idx[j]; + if(vert_uv[vid].size()==0) + { + vert_uv[vid].push_back(prim->tris.attr(uv_name)[i]); + //idx_mapping[vid].push_back(zeno::vec2i(vid,count)); + //count++; + } + else + { + zeno::vec3f uv = prim->tris.attr(uv_name)[i]; + bool have = false; + for(int k=0;ktris.attr(uv_name)[i]); + //idx_mapping[vid].push_back(zeno::vec2i(vid,count)); + //count++; + } + } + } + } + count = 0; + for(int i=0;iverts[vid]; + auto n = prim->verts.attr("nrm")[vid]; + auto c = prim->verts.attr("clr")[vid]; + auto t = prim->verts.attr("atang")[vid]; + verts.push_back(v); + nrm.push_back(n); + clr.push_back(c); + tang.push_back(t); + uv.push_back(uvt); + } + } + + idxBuffer.resize(prim->tris.size()); + //third pass: assemble new idx map + for(int i=0;itris.size();i++) + { + zeno::vec3i idx = prim->tris[i]; + for(int j=0;j<3;j++) { + + auto old_vid = idx[j]; + if(idx_mapping[old_vid].size()==1) + { + idxBuffer[i][j] = idx_mapping[old_vid][0][1]; + } + else + { + std::string uv_name = "uv" + std::to_string(j); + auto &tuv = prim->tris.attr(uv_name)[i]; + for(int k=0;kadd_attr("atang"); + auto &tang = prim->tris.attr("tang"); + atang.assign(atang.size(), zeno::vec3f(0)); + const auto &pos = prim->attr("pos"); + for(size_t i=0;itris.size();++i) + { + + auto vidx = prim->tris[i]; + zeno::vec3f v0 = pos[vidx[0]]; + zeno::vec3f v1 = pos[vidx[1]]; + zeno::vec3f v2 = pos[vidx[2]]; + auto e1 = v1-v0, e2=v2-v0; + float area = zeno::length(zeno::cross(e1, e2)) * 0.5; + atang[vidx[0]] += area * tang[i]; + atang[vidx[1]] += area * tang[i]; + atang[vidx[2]] += area * tang[i]; + } +#pragma omp parallel for + for(auto i=0;itris; + const auto &pos = prim->attr("pos"); + auto const &nrm = prim->add_attr("nrm"); + auto &tang = prim->tris.add_attr("tang"); + bool has_uv = tris.has_attr("uv0")&&tris.has_attr("uv1")&&tris.has_attr("uv2"); + //printf("!!has_uv = %d\n", has_uv); + if(has_uv) { + const auto &uv0data = tris.attr("uv0"); + const auto &uv1data = tris.attr("uv1"); + const auto &uv2data = tris.attr("uv2"); +#pragma omp parallel for + for (auto i = 0; i < prim->tris.size(); ++i) { + const auto &pos0 = pos[tris[i][0]]; + const auto &pos1 = pos[tris[i][1]]; + const auto &pos2 = pos[tris[i][2]]; + zeno::vec3f uv0; + zeno::vec3f uv1; + zeno::vec3f uv2; + + uv0 = uv0data[i]; + uv1 = uv1data[i]; + uv2 = uv2data[i]; + + auto edge0 = pos1 - pos0; + auto edge1 = pos2 - pos0; + auto deltaUV0 = uv1 - uv0; + auto deltaUV1 = uv2 - uv0; + + auto f = 1.0f / (deltaUV0[0] * deltaUV1[1] - deltaUV1[0] * deltaUV0[1] + 1e-5); + + zeno::vec3f tangent; + tangent[0] = f * (deltaUV1[1] * edge0[0] - deltaUV0[1] * edge1[0]); + tangent[1] = f * (deltaUV1[1] * edge0[1] - deltaUV0[1] * edge1[1]); + tangent[2] = f * (deltaUV1[1] * edge0[2] - deltaUV0[1] * edge1[2]); + //printf("tangent:%f %f %f\n", tangent[0], tangent[1], tangent[2]); + //zeno::log_info("tangent {} {} {}",tangent[0], tangent[1], tangent[2]); + auto tanlen = zeno::length(tangent); + tangent *(1.f / (tanlen + 1e-8)); + /*if (std::abs(tanlen) < 1e-8) {//fix by BATE + zeno::vec3f n = nrm[tris[i][0]], unused; + zeno::pixarONB(n, tang[i], unused);//TODO calc this in shader? + } else { + tang[i] = tangent * (1.f / tanlen); + }*/ + tang[i] = tangent; + } + } else { + const auto &uvarray = prim->attr("uv"); +#pragma omp parallel for + for (auto i = 0; i < prim->tris.size(); ++i) { + const auto &pos0 = pos[tris[i][0]]; + const auto &pos1 = pos[tris[i][1]]; + const auto &pos2 = pos[tris[i][2]]; + zeno::vec3f uv0; + zeno::vec3f uv1; + zeno::vec3f uv2; + + uv0 = uvarray[tris[i][0]]; + uv1 = uvarray[tris[i][1]]; + uv2 = uvarray[tris[i][2]]; + + auto edge0 = pos1 - pos0; + auto edge1 = pos2 - pos0; + auto deltaUV0 = uv1 - uv0; + auto deltaUV1 = uv2 - uv0; + + auto f = 1.0f / (deltaUV0[0] * deltaUV1[1] - deltaUV1[0] * deltaUV0[1] + 1e-5); + + zeno::vec3f tangent; + tangent[0] = f * (deltaUV1[1] * edge0[0] - deltaUV0[1] * edge1[0]); + tangent[1] = f * (deltaUV1[1] * edge0[1] - deltaUV0[1] * edge1[1]); + tangent[2] = f * (deltaUV1[1] * edge0[2] - deltaUV0[1] * edge1[2]); + //printf("tangent:%f %f %f\n", tangent[0], tangent[1], tangent[2]); + //zeno::log_info("tangent {} {} {}",tangent[0], tangent[1], tangent[2]); + auto tanlen = zeno::length(tangent); + tangent *(1.f / (tanlen + 1e-8)); + /*if (std::abs(tanlen) < 1e-8) {//fix by BATE + zeno::vec3f n = nrm[tris[i][0]], unused; + zeno::pixarONB(n, tang[i], unused);//TODO calc this in shader? + } else { + tang[i] = tangent * (1.f / tanlen); + }*/ + tang[i] = tangent; + } + } +} +struct primClean : INode { + virtual void apply() override { + auto prim = get_input("prim"); + std::vector verts; + std::vector nrm; + std::vector clr; + std::vector tang; + std::vector uv; + std::vector idxBuffer; + computeTrianglesTangent(prim.get()); + computeVertexTangent(prim.get()); + cleanMesh(prim, verts, nrm, clr, tang, uv, idxBuffer); + auto oPrim = std::make_shared(); + oPrim->verts.resize(verts.size()); + oPrim->add_attr("nrm"); + oPrim->add_attr("clr"); + oPrim->add_attr("uv"); + oPrim->add_attr("atang"); + oPrim->tris.resize(idxBuffer.size()); + + + oPrim->verts.attr("pos") = verts; + oPrim->verts.attr("nrm") = nrm; + oPrim->verts.attr("clr") = clr; + oPrim->verts.attr("uv") = uv; + oPrim->verts.attr("atang") = tang; + + + oPrim->tris = idxBuffer; + + + set_output("prim", std::move(oPrim)); + } +}; + +ZENDEFNODE(primClean, { + { + {"primitive", "prim"} + }, + { + {"primitive", "prim"}, + }, + { + }, + {"primitive"}, + }); + + } } diff --git a/zenovis/src/optx/RenderEngineOptx.cpp b/zenovis/src/optx/RenderEngineOptx.cpp index a511fb76d1..5effeb93ac 100644 --- a/zenovis/src/optx/RenderEngineOptx.cpp +++ b/zenovis/src/optx/RenderEngineOptx.cpp @@ -66,7 +66,125 @@ struct CppTimer { }; static CppTimer timer, localTimer; - +void cleanMesh(std::shared_ptr prim, + std::vector &verts, + std::vector &nrm, + std::vector &clr, + std::vector &tang, + std::vector &uv, + std::vector &idxBuffer) +{ + //first pass, scan the prim to see if verts require duplication + std::vector> vert_uv; + std::vector> idx_mapping; + vert_uv.resize(prim->verts.size()); + idx_mapping.resize(prim->verts.size()); + int count = 0; + for(int i=0;itris.size();i++) + { + //so far, all value has already averaged on verts, except uv + zeno::vec3i idx = prim->tris[i]; + for(int j=0;j<3;j++) + { + std::string uv_name; + uv_name = "uv" + std::to_string(j); + auto vid = idx[j]; + if(vert_uv[vid].size()==0) + { + vert_uv[vid].push_back(prim->tris.attr(uv_name)[i]); + //idx_mapping[vid].push_back(zeno::vec2i(vid,count)); + //count++; + } + else + { + zeno::vec3f uv = prim->tris.attr(uv_name)[i]; + bool have = false; + for(int k=0;ktris.attr(uv_name)[i]); + //idx_mapping[vid].push_back(zeno::vec2i(vid,count)); + //count++; + } + } + } + } + count = 0; + for(int i=0;iverts[vid]; + auto n = prim->verts.attr("nrm")[vid]; + auto c = prim->verts.attr("clr")[vid]; + auto t = prim->verts.attr("atang")[vid]; + verts.push_back(v); + nrm.push_back(n); + clr.push_back(c); + tang.push_back(t); + uv.push_back(uvt); + } + } + + idxBuffer.resize(prim->tris.size()); + //third pass: assemble new idx map + for(int i=0;itris.size();i++) + { + zeno::vec3i idx = prim->tris[i]; + for(int j=0;j<3;j++) { + + auto old_vid = idx[j]; + if(idx_mapping[old_vid].size()==1) + { + idxBuffer[i][j] = idx_mapping[old_vid][0][1]; + } + else + { + std::string uv_name = "uv" + std::to_string(j); + auto &tuv = prim->tris.attr(uv_name)[i]; + for(int k=0;k Date: Fri, 6 Sep 2024 11:56:13 +0800 Subject: [PATCH 2/3] load_object2 --- zenovis/src/optx/RenderEngineOptx.cpp | 40 ++++++++++++++++++++++--- zenovis/xinxinoptix/optixPathTracer.cpp | 30 +++++++++++++++++++ 2 files changed, 66 insertions(+), 4 deletions(-) diff --git a/zenovis/src/optx/RenderEngineOptx.cpp b/zenovis/src/optx/RenderEngineOptx.cpp index 5effeb93ac..02e5c9c667 100644 --- a/zenovis/src/optx/RenderEngineOptx.cpp +++ b/zenovis/src/optx/RenderEngineOptx.cpp @@ -66,7 +66,7 @@ struct CppTimer { }; static CppTimer timer, localTimer; -void cleanMesh(std::shared_ptr prim, +static void cleanMesh(zeno::PrimitiveObject* prim, std::vector &verts, std::vector &nrm, std::vector &clr, @@ -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("matid").data(); + auto nvs = prim->verts.size(); + auto nts = prim->tris.size(); +// std::vector verts; +// std::vector nrm; +// std::vector clr; +// std::vector tang; +// std::vector uv; +// std::vector idxBuffer; +// cleanMesh(prim_in, verts, nrm, clr, tang, uv, idxBuffer); +// auto oPrim = std::make_shared(); +// oPrim->verts.resize(verts.size()); +// oPrim->add_attr("nrm"); +// oPrim->add_attr("clr"); +// oPrim->add_attr("uv"); +// oPrim->add_attr("atang"); +// oPrim->tris.resize(idxBuffer.size()); +// +// +// oPrim->verts.attr("pos") = verts; +// oPrim->verts.attr("nrm") = nrm; +// oPrim->verts.attr("clr") = clr; +// oPrim->verts.attr("uv") = uv; +// oPrim->verts.attr("atang") = tang; +// oPrim->tris = idxBuffer; +// +// auto vs = (float const *)oPrim->verts.data(); +// std::map> 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 matNameList(0); if(matNum>0) { @@ -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("mtlid", "Default"); auto instID = prim_in->userData().get2("instID", "Default"); + auto matids = (int const *)prim_in->tris.attr("matid").data(); xinxinoptix::load_object(key, mtlid, instID, vs, nvs, ts, nts, vtab, matids, matNameList); } } diff --git a/zenovis/xinxinoptix/optixPathTracer.cpp b/zenovis/xinxinoptix/optixPathTracer.cpp index 1e83a43d8c..ca3eb01910 100644 --- a/zenovis/xinxinoptix/optixPathTracer.cpp +++ b/zenovis/xinxinoptix/optixPathTracer.cpp @@ -2846,6 +2846,20 @@ struct DrawDat { }; static std::map drawdats; +struct DrawDat2 { + std::vector mtlidList; + std::string mtlid; + std::string instID; + std::vector pos; + std::vector nrm; + std::vector tang; + std::vector clr; + std::vector uv; + std::vector triMats; + std::vector triIdx; +}; +static std::map drawdats2; + std::set uniqueMatsForMesh() { std::set result; @@ -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 &matids, + std::vector 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("nrm"); + dat.uv = prim->verts.attr("uv"); + dat.clr = prim->verts.attr("clr"); + dat.tang = prim->verts.attr("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, From 9de610f92c8fbedc11147184a04b8c6feac79a11 Mon Sep 17 00:00:00 2001 From: zhxx1987 Date: Thu, 12 Sep 2024 15:28:02 +0800 Subject: [PATCH 3/3] vtk --- projects/CuLagrange/geometry/MeshIO.cu | 34 +-- .../geometry/file_parser/read_vtk_mesh.hpp | 195 ++++++++++++++++++ 2 files changed, 216 insertions(+), 13 deletions(-) diff --git a/projects/CuLagrange/geometry/MeshIO.cu b/projects/CuLagrange/geometry/MeshIO.cu index e0fadc23fe..78630ef0f6 100644 --- a/projects/CuLagrange/geometry/MeshIO.cu +++ b/projects/CuLagrange/geometry/MeshIO.cu @@ -12,7 +12,7 @@ #include #include #include - +#include namespace zeno { @@ -21,24 +21,31 @@ struct ReadVTKMesh : INode { void apply() override { auto view_interior = get_param("view_interior"); auto path = get_input("path")->get(); + auto type = get_input("method")->get(); auto prim = std::make_shared(); - bool ret = load_vtk_data(path,prim,0); + bool ret; + + if(type == "mesh") + ret = load_vtk_data(path,prim,0); + else + ret = read_unstructured_grid_to_points(path, prim); - if(view_interior && prim->quads.size() > 0){ + if(type == "mesh") { + if (view_interior && prim->quads.size() > 0) { prim->tris.resize(prim->quads.size() * 4); - + constexpr auto space = zs::execspace_e::openmp; auto ompExec = zs::omp_exec(); - ompExec(zs::range(prim->quads.size()), - [prim] (int ei) mutable { - const auto& tet = prim->quads[ei]; - // for(int i = 0;i < 4;++i) - prim->tris[ei * 4 + 0] = zeno::vec3i{tet[0],tet[1],tet[2]}; - prim->tris[ei * 4 + 1] = zeno::vec3i{tet[1],tet[3],tet[2]}; - prim->tris[ei * 4 + 2] = zeno::vec3i{tet[0],tet[2],tet[3]}; - prim->tris[ei * 4 + 3] = zeno::vec3i{tet[0],tet[3],tet[1]}; - }); + ompExec(zs::range(prim->quads.size()), [prim](int ei) mutable { + const auto &tet = prim->quads[ei]; + // for(int i = 0;i < 4;++i) + prim->tris[ei * 4 + 0] = zeno::vec3i{tet[0], tet[1], tet[2]}; + prim->tris[ei * 4 + 1] = zeno::vec3i{tet[1], tet[3], tet[2]}; + prim->tris[ei * 4 + 2] = zeno::vec3i{tet[0], tet[2], tet[3]}; + prim->tris[ei * 4 + 3] = zeno::vec3i{tet[0], tet[3], tet[1]}; + }); + } } set_output("prim",std::move(prim)); @@ -47,6 +54,7 @@ struct ReadVTKMesh : INode { ZENDEFNODE(ReadVTKMesh, {/* inputs: */ { {"readpath", "path"}, + {"enum verts mesh", "method", "verts"}, }, /* outputs: */ { diff --git a/projects/CuLagrange/geometry/file_parser/read_vtk_mesh.hpp b/projects/CuLagrange/geometry/file_parser/read_vtk_mesh.hpp index bc03a2fc2f..b7198d5dad 100644 --- a/projects/CuLagrange/geometry/file_parser/read_vtk_mesh.hpp +++ b/projects/CuLagrange/geometry/file_parser/read_vtk_mesh.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -543,7 +544,200 @@ namespace zeno { printf("finish reading polydata\n"); return true; } + bool stringReplace(std::string &in, std::string del, std::string add) + { + size_t start_pos = in.find(del); + if(start_pos == std::string::npos) + return false; + in.replace(start_pos, del.length(), add); + return true; + } + bool read_unstructured_grid_to_points(std::string file_name, std::shared_ptr& prim) + { + std::ifstream file; + file.open(file_name.c_str()); + int num_points; + int num_field_data; + std::string readtype; + while(!file.eof()) + { + std::string line_str; + std::getline(file,line_str); + if(line_str == "BINARY") + { + readtype = "BINARY"; + } + if(line_str == "ASCII") + { + readtype = "ASCII"; + } + if(line_str.find("POINTS ")!=std::string::npos) + { + std::string a; + std::string type; + std::stringstream ss; + ss<>a>>num_points>>type; + prim->verts.resize(num_points); + if(readtype == "ASCII") { + for (int i = 0; i < num_points; i++) { + for (int j = 0; j < 3; j++) + file >> prim->verts[i][j]; + } + }else if(readtype == "BINARY") + { + //read chunck of buffer + } + } + else if(line_str.find("Velocity ")!=std::string::npos) + { + prim->verts.add_attr("Velocity"); + if(readtype == "ASCII") { + for (int i = 0; i < num_points; i++) { + for (int j = 0; j < 3; j++) + file >> prim->verts.attr("Velocity")[i][j]; + } + }else if(readtype == "BINARY"){ + } + } + else if(line_str.find("FieldData ")) + { + std::string a; + std::string b; + std::stringstream ss; + ss<>a>>b>>num_field_data; + } + if(num_field_data>0) { + std::vector strs; + std::string a; + std::stringstream ss; + ss<>a) + { + strs.push_back(a); + } + std::string varname; + if(strs.size()==4 && std::stoi(strs[2]) == num_points) + { + varname = strs[0]; + while(stringReplace(varname, ".", "_")); + while(stringReplace(varname, "-", "_")); + if(strs[1] == "1") { + prim->verts.add_attr(varname); + if(readtype == "ASCII") { + for (int i = 0; i < num_points; i++) { + file >> prim->verts.attr(varname)[i]; + } + }else if(readtype == "BINARY") + { + + } + }else if(strs[1] == "3") + { + prim->verts.add_attr(varname); + if(readtype == "ASCII") { + for (int i = 0; i < num_points; i++) { + for (int j = 0; j < 3; j++) + file >> prim->verts.attr(varname)[i][j]; + } + }else if(readtype == "BINARY") + { + + } + } + } + + +// if (line_str.find("SpeciesDensity ") != std::string::npos) { +// prim->verts.add_attr("SpeciesDensity"); +// for (int i = 0; i < num_points; i++) { +// file >> prim->verts.attr("SpeciesDensity")[i]; +// } +// } +// else if (line_str.find("ViscosityEddy ") != std::string::npos) { +// prim->verts.add_attr("ViscosityEddy"); +// for (int i = 0; i < num_points; i++) { +// file >> prim->verts.attr("ViscosityEddy")[i]; +// } +// } +// else if (line_str.find("Mach ") != std::string::npos) { +// prim->verts.add_attr("Mach"); +// for (int i = 0; i < num_points; i++) { +// file >> prim->verts.attr("Mach")[i]; +// } +// } +// else if (line_str.find("MachNumberinStnFrame ") != +// std::string::npos) { +// prim->verts.add_attr("MachNumberinStnFrame"); +// for (int i = 0; i < num_points; i++) { +// file >> prim->verts.attr("MachNumberinStnFrame")[i]; +// } +// } +// else if (line_str.find("Pressure ") != std::string::npos) { +// prim->verts.add_attr("Pressure"); +// for (int i = 0; i < num_points; i++) { +// file >> prim->verts.attr("Pressure")[i]; +// } +// } +// else if (line_str.find("Temperature ") != std::string::npos) { +// prim->verts.add_attr("Temperature"); +// for (int i = 0; i < num_points; i++) { +// file >> prim->verts.attr("Temperature")[i]; +// } +// } +// else if (line_str.find("PressureStagnation ") != std::string::npos) { +// prim->verts.add_attr("PressureStagnation"); +// for (int i = 0; i < num_points; i++) { +// file >> prim->verts.attr("PressureStagnation")[i]; +// } +// } +// else if (line_str.find("TotalPressureinStnFrame ") != +// std::string::npos) { +// prim->verts.add_attr("TotalPressureinStnFrame"); +// for (int i = 0; i < num_points; i++) { +// file >> prim->verts.attr("TotalPressureinStnFrame")[i]; +// } +// } +// else if (line_str.find("TemperatureStagnation ") != +// std::string::npos) { +// prim->verts.add_attr("TemperatureStagnation"); +// for (int i = 0; i < num_points; i++) { +// file >> prim->verts.attr("TemperatureStagnation")[i]; +// } +// } +// else if (line_str.find("TotalTemperatureinStnFrame ") != +// std::string::npos) { +// prim->verts.add_attr("TotalTemperatureinStnFrame"); +// for (int i = 0; i < num_points; i++) { +// file >> prim->verts.attr("TotalTemperatureinStnFrame")[i]; +// } +// } +// else if (line_str.find("TurbulenceEddyFrequency ") != +// std::string::npos) { +// prim->verts.add_attr("TurbulenceEddyFrequency"); +// for (int i = 0; i < num_points; i++) { +// file >> prim->verts.attr("TurbulenceEddyFrequency")[i]; +// } +// } +// else if (line_str.find("TurbulentEnergyKinetic ") != +// std::string::npos) { +// prim->verts.add_attr("TurbulentEnergyKinetic"); +// for (int i = 0; i < num_points; i++) { +// file >> prim->verts.attr("TurbulentEnergyKinetic")[i]; +// } +// } +// else if (line_str.find("VelocityinStnFrame ") != std::string::npos) { +// prim->verts.add_attr("VelocityinStnFrame"); +// for (int i = 0; i < num_points; i++) { +// file >> prim->verts.attr("VelocityinStnFrame")[i]; +// } +// } + } + } + file.close(); + } // DATASET UNSTRUCTURED_GRID // POINTS n dataType // p0x p0y p0z @@ -564,6 +758,7 @@ namespace zeno { // type2 // ... // typen-1 + constexpr char unstructured_grid[] = "UNSTRUCTURED_GRID"; bool read_unstructured_grid(FILE *fp,std::shared_ptr& prim,int& line_count) { char *bufferp;