From 2180b4311d364e2834cace3d1d1dff97d2ffcf8e Mon Sep 17 00:00:00 2001 From: alemuntoni Date: Wed, 30 Jun 2021 12:56:22 +0200 Subject: [PATCH] move declarations in header file --- src/meshlabplugins/io_gltf/gltf_loader.cpp | 131 +++++---------------- src/meshlabplugins/io_gltf/gltf_loader.h | 69 +++++++++++ 2 files changed, 101 insertions(+), 99 deletions(-) diff --git a/src/meshlabplugins/io_gltf/gltf_loader.cpp b/src/meshlabplugins/io_gltf/gltf_loader.cpp index 1d4c369ed..57636e4df 100644 --- a/src/meshlabplugins/io_gltf/gltf_loader.cpp +++ b/src/meshlabplugins/io_gltf/gltf_loader.cpp @@ -3,79 +3,7 @@ #include #include -/*************** -* Declarations * -***************/ - -void visitNode( - const tinygltf::Model& model, - unsigned int i, - Matrix44m m, - std::vector& visited, - std::vector& trm); - -enum GLTF_ATTR_TYPE {POSITION, NORMAL, COLOR_0, TEXCOORD_0, INDICES}; -const std::array GLTF_ATTR_STR {"POSITION", "NORMAL", "COLOR_0", "TEXCOORD_0"}; - -void loadMeshPrimitive( - MeshModel& m, - const tinygltf::Model& model, - const tinygltf::Primitive& p); - -void loadAttribute( - MeshModel& m, - std::vector& ivp, - const tinygltf::Model& model, - const tinygltf::Primitive& p, - GLTF_ATTR_TYPE attr, - int textID = -1); - -template -void populateAttr( - GLTF_ATTR_TYPE attr, - MeshModel&m, - std::vector& ivp, - const Scalar* array, - unsigned int number, - int textID = -1); - -template -void populateVertices( - MeshModel& m, - std::vector& ivp, - const Scalar* posArray, - unsigned int vertNumber); - -template -void populateVNormals( - const std::vector& ivp, - const Scalar* normArray, - unsigned int vertNumber); - -template -void populateVColors( - const std::vector& ivp, - const Scalar* colorArray, - unsigned int vertNumber, - int nElemns); - -template -void populateVTextCoords( - const std::vector& ivp, - const Scalar* textCoordArray, - unsigned int vertNumber, - int textID); - -template -void populateTriangles( - MeshModel&m, - const std::vector& ivp, - const Scalar* triArray, - unsigned int triNumber); - -/************** -* Definitions * -**************/ +namespace gltf { /** * @brief Loads the list of rotation matrices for each mesh contained in the @@ -83,7 +11,7 @@ void populateTriangles( * @param model * @return a vector containing N 4x4 matrices */ -std::vector gltf::loadTrMatrices( +std::vector loadTrMatrices( const tinygltf::Model& model) { std::vector trm(model.meshes.size()); @@ -95,12 +23,36 @@ std::vector gltf::loadTrMatrices( Matrix44m startM = Matrix44m::Identity(); //recursive call: it will visit all the children of ith node - visitNode(model, i, startM, visited, trm); + internal::visitNodeAndGetTrMatrix(model, i, startM, visited, trm); } } return trm; } +/** + * @brief loads a mesh from gltf file. + * It merges all the primitives in the loaded mesh. + * + * @param m: the mesh that will contain the loaded mesh + * @param tm: tinygltf structure of the mesh to load + * @param model: tinygltf file + */ +void loadMesh( + MeshModel& m, + const tinygltf::Mesh& tm, + const tinygltf::Model& model) +{ + if (!tm.name.empty()) + m.setLabel(QString::fromStdString(tm.name)); + + //for each primitive, load it into the mesh + for (const tinygltf::Primitive& p : tm.primitives){ + internal::loadMeshPrimitive(m, model, p); + } +} + +namespace internal { + /** * @brief Recursive function that visits a node and calls the visit on all its * children nodes. @@ -113,7 +65,7 @@ std::vector gltf::loadTrMatrices( * @param visited: vector of visited flags * @param trm: vector of matrices: it will be updated when a mesh node is found */ -void visitNode( +void visitNodeAndGetTrMatrix( const tinygltf::Model& model, unsigned int i, Matrix44m m, @@ -179,33 +131,11 @@ void visitNode( for (int c : model.nodes[i].children){ if (c>=0){ //if it is valid //visit child, passing the current matrix - visitNode(model, c, m, visited, trm); + visitNodeAndGetTrMatrix(model, c, m, visited, trm); } } } -/** - * @brief loads a mesh from gltf file. - * It merges all the primitives in the loaded mesh. - * - * @param m: the mesh that will contain the loaded mesh - * @param tm: tinygltf structure of the mesh to load - * @param model: tinygltf file - */ -void gltf::loadMesh( - MeshModel& m, - const tinygltf::Mesh& tm, - const tinygltf::Model& model) -{ - if (!tm.name.empty()) - m.setLabel(QString::fromStdString(tm.name)); - - //for each primitive, load it into the mesh - for (const tinygltf::Primitive& p : tm.primitives){ - loadMeshPrimitive(m, model, p); - } -} - /** * @brief loads the given primitive into the mesh * @param m @@ -503,3 +433,6 @@ void populateTriangles( } } } + +} //namespace gltf::internal +} //namespace gltf diff --git a/src/meshlabplugins/io_gltf/gltf_loader.h b/src/meshlabplugins/io_gltf/gltf_loader.h index 458d1f480..c04ef8114 100644 --- a/src/meshlabplugins/io_gltf/gltf_loader.h +++ b/src/meshlabplugins/io_gltf/gltf_loader.h @@ -18,6 +18,75 @@ void loadMesh( const tinygltf::Mesh& tm, const tinygltf::Model& model); +namespace internal { + +enum GLTF_ATTR_TYPE {POSITION, NORMAL, COLOR_0, TEXCOORD_0, INDICES}; +const std::array GLTF_ATTR_STR {"POSITION", "NORMAL", "COLOR_0", "TEXCOORD_0"}; + +void visitNodeAndGetTrMatrix( + const tinygltf::Model& model, + unsigned int i, + Matrix44m m, + std::vector& visited, + std::vector& trm); + +void loadMeshPrimitive( + MeshModel& m, + const tinygltf::Model& model, + const tinygltf::Primitive& p); + +void loadAttribute( + MeshModel& m, + std::vector& ivp, + const tinygltf::Model& model, + const tinygltf::Primitive& p, + GLTF_ATTR_TYPE attr, + int textID = -1); + +template +void populateAttr( + GLTF_ATTR_TYPE attr, + MeshModel&m, + std::vector& ivp, + const Scalar* array, + unsigned int number, + int textID = -1); + +template +void populateVertices( + MeshModel& m, + std::vector& ivp, + const Scalar* posArray, + unsigned int vertNumber); + +template +void populateVNormals( + const std::vector& ivp, + const Scalar* normArray, + unsigned int vertNumber); + +template +void populateVColors( + const std::vector& ivp, + const Scalar* colorArray, + unsigned int vertNumber, + int nElemns); + +template +void populateVTextCoords( + const std::vector& ivp, + const Scalar* textCoordArray, + unsigned int vertNumber, + int textID); + +template +void populateTriangles( + MeshModel&m, + const std::vector& ivp, + const Scalar* triArray, + unsigned int triNumber); +} + }