diff --git a/projects/CalcGeometryUV/PrimitivePlyIO.cpp b/projects/CalcGeometryUV/PrimitivePlyIO.cpp index 08d3427b38..c81433bf4d 100644 --- a/projects/CalcGeometryUV/PrimitivePlyIO.cpp +++ b/projects/CalcGeometryUV/PrimitivePlyIO.cpp @@ -1,3 +1,10 @@ +#include +#include +#include +#include +#include +#include +#include #include #include #include @@ -16,6 +23,7 @@ #include "primplyio_tinyply.h" +/* static void readply( std::vector &verts, std::vector &color, @@ -99,10 +107,7 @@ static void readply( std::memcpy(zfaces.data(), faces->buffer.get(), numFacesBytes); } else if (faces->t == tinyply::Type::INT16 || faces->t == tinyply::Type::UINT16) { std::vector zfaces_uint16; - zfaces_uint16.resize(faces->count); - std::memcpy(zfaces_uint16.data(), faces->buffer.get(), numFacesBytes); - for (const auto& f: zfaces_uint16) { - zfaces.emplace_back(f[0], f[1], f[2]); + zfaces_uint16.res(ce_back(f[0], f[1], f[2]); } } else if (faces->t == tinyply::Type::INT8 || faces->t == tinyply::Type::UINT8) { std::vector zfaces_uint8; @@ -117,16 +122,100 @@ static void readply( std::cerr << "Caught tinyply exception: " << e.what() << std::endl; } } +*/ +static void ReadAllAttrFromPlyFile(std::string &ply_file, std::shared_ptr prim){ + std::filesystem::path file_path(ply_file); + if(!std::filesystem::exists(file_path)){ + throw std::runtime_error(ply_file + " not exsit"); + return; + } + std::ifstream file_stream; + file_stream.open(file_path); + if(!file_stream.is_open()){ + throw std::runtime_error("fail to open "+ply_file); + return; + } + tinyply::PlyFile ply_obj; + if(!ply_obj.parse_header(file_stream)){ + throw std::runtime_error("fail to parse ply header"); + return; + } + std::vector elements = ply_obj.get_elements(); + bool found_vertex = false; + tinyply::PlyElement *vertex_element = nullptr; + + std::vector need_properties; + std::vector> data_list; + + int element_size = 0; + + for(tinyply::PlyElement element : elements){ + if(element.name == "vertex"){ + found_vertex = true; + vertex_element = &element; + element_size = element.size; + std::cout << "Name: " <verts.resize(element_size); + + for(int i=0;iadd_attr(property.name); + unsigned char *buffer = data_list[i]->buffer.get(); + + float value = 0.0f; + tinyply::PropertyInfo info = tinyply::PropertyTable[property.propertyType]; + + for(int j=0; j("path")->get(); auto prim = std::make_shared(); - auto &pos = prim->verts; - auto &clr = prim->add_attr("clr"); - auto &tris = prim->tris; - readply(pos, clr, tris, path); - prim->resize(pos.size()); + ReadAllAttrFromPlyFile(path, prim); set_output("prim", std::move(prim)); } };