From 42a075135c9238af8ccad0f920d13742fba17cb2 Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Thu, 7 Oct 2010 19:14:09 +0200 Subject: [PATCH] extension to make the PLY loader handle some files extended by blender --- src/shapes/ply/ply.cpp | 61 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 5 deletions(-) diff --git a/src/shapes/ply/ply.cpp b/src/shapes/ply/ply.cpp index 82e405f9..f3d84209 100644 --- a/src/shapes/ply/ply.cpp +++ b/src/shapes/ply/ply.cpp @@ -165,16 +165,24 @@ public: void face_end_callback() { } void face_vertex_indices_begin_uint8(ply::uint8 size) { - AssertEx(size == 3, "Only triangle PLY meshes are supported for now."); + if (size != 3) + Log(EError, "Only triangle PLY meshes are supported for now."); m_triangleIdxCtr = 0; } void face_vertex_indices_begin_uint32(ply::uint32 size) { - AssertEx(size == 3, "Only triangle PLY meshes are supported for now."); + if (size != 3) + Log(EError, "Only triangle PLY meshes are supported for now."); m_triangleIdxCtr = 0; } - void face_vertex_indices_element(ply::int32 element) { + void face_vertex_indices_element_int32(ply::int32 element) { + Assert(m_triangleIdxCtr < 3); + Assert((size_t) element < m_vertexCount); + m_triangle.idx[m_triangleIdxCtr++] = element; + } + + void face_vertex_indices_element_uint32(ply::uint32 element) { Assert(m_triangleIdxCtr < 3); Assert((size_t) element < m_vertexCount); m_triangle.idx[m_triangleIdxCtr++] = element; @@ -253,7 +261,7 @@ template<> std::tr1::tuple, return std::tr1::tuple, std::tr1::function, std::tr1::function >( std::tr1::bind(&PLYLoader::face_vertex_indices_begin_uint8, this, _1), - std::tr1::bind(&PLYLoader::face_vertex_indices_element, this, _1), + std::tr1::bind(&PLYLoader::face_vertex_indices_element_int32, this, _1), std::tr1::bind(&PLYLoader::face_vertex_indices_end, this) ); } else { @@ -271,7 +279,7 @@ template<> std::tr1::tuple, return std::tr1::tuple, std::tr1::function, std::tr1::function >( std::tr1::bind(&PLYLoader::face_vertex_indices_begin_uint32, this, _1), - std::tr1::bind(&PLYLoader::face_vertex_indices_element, this, _1), + std::tr1::bind(&PLYLoader::face_vertex_indices_element_int32, this, _1), std::tr1::bind(&PLYLoader::face_vertex_indices_end, this) ); } else { @@ -281,6 +289,43 @@ template<> std::tr1::tuple, } } +template<> std::tr1::tuple, + std::tr1::function, std::tr1::function > + PLYLoader::list_property_definition_callback(const std::string& element_name, + const std::string& property_name) { + if ((element_name == "face") && (property_name == "vertex_indices")) { + return std::tr1::tuple, + std::tr1::function, std::tr1::function >( + std::tr1::bind(&PLYLoader::face_vertex_indices_begin_uint8, this, _1), + std::tr1::bind(&PLYLoader::face_vertex_indices_element_uint32, this, _1), + std::tr1::bind(&PLYLoader::face_vertex_indices_end, this) + ); + } else { + return std::tr1::tuple, + std::tr1::function, + std::tr1::function >(0, 0, 0); + } +} + +template<> std::tr1::tuple, + std::tr1::function, std::tr1::function > + PLYLoader::list_property_definition_callback(const std::string& element_name, + const std::string& property_name) { + if ((element_name == "face") && (property_name == "vertex_indices")) { + return std::tr1::tuple, + std::tr1::function, std::tr1::function >( + std::tr1::bind(&PLYLoader::face_vertex_indices_begin_uint32, this, _1), + std::tr1::bind(&PLYLoader::face_vertex_indices_element_uint32, this, _1), + std::tr1::bind(&PLYLoader::face_vertex_indices_end, this) + ); + } else { + return std::tr1::tuple, + std::tr1::function, + std::tr1::function >(0, 0, 0); + } +} + + void PLYLoader::loadPLY(const fs::path &path) { ply::ply_parser ply_parser; ply_parser.info_callback(std::tr1::bind(&PLYLoader::info_callback, @@ -307,6 +352,12 @@ void PLYLoader::loadPLY(const fs::path &path) { ply::at(list_property_definition_callbacks) = std::tr1::bind( &PLYLoader::list_property_definition_callback, this, _1, _2); + + ply::at(list_property_definition_callbacks) = std::tr1::bind( + &PLYLoader::list_property_definition_callback, this, _1, _2); + + ply::at(list_property_definition_callbacks) = std::tr1::bind( + &PLYLoader::list_property_definition_callback, this, _1, _2); ply_parser.scalar_property_definition_callbacks(scalar_property_definition_callbacks); ply_parser.list_property_definition_callbacks(list_property_definition_callbacks);