diff --git a/code/AssetLib/AMF/AMFImporter.cpp b/code/AssetLib/AMF/AMFImporter.cpp index 9c6b09025..78d9ffe25 100644 --- a/code/AssetLib/AMF/AMFImporter.cpp +++ b/code/AssetLib/AMF/AMFImporter.cpp @@ -115,10 +115,9 @@ bool AMFImporter::Find_NodeElement(const std::string &pID, const AMFNodeElementB return false; } -bool AMFImporter::Find_ConvertedNode(const std::string &pID, std::list &pNodeList, aiNode **pNode) const { +bool AMFImporter::Find_ConvertedNode(const std::string &pID, NodeArray &nodeArray, aiNode **pNode) const { aiString node_name(pID.c_str()); - - for (aiNode *node : pNodeList) { + for (aiNode *node : nodeArray) { if (node->mName == node_name) { if (pNode != nullptr) { *pNode = node; diff --git a/code/AssetLib/AMF/AMFImporter.hpp b/code/AssetLib/AMF/AMFImporter.hpp index 734cfa977..ae7b39fb7 100644 --- a/code/AssetLib/AMF/AMFImporter.hpp +++ b/code/AssetLib/AMF/AMFImporter.hpp @@ -139,6 +139,10 @@ private: const AMFTexMap *TexMap; ///< Face texture mapping data. Equal to nullptr if texture mapping is not set for the face. }; + using AMFMetaDataArray = std::vector; + using MeshArray = std::vector; + using NodeArray = std::vector; + /// Clear all temporary data. void Clear(); @@ -170,13 +174,13 @@ private: /// Check if child elements of node element is metadata and add it to scene node. /// \param [in] pMetadataList - reference to list with collected metadata. /// \param [out] pSceneNode - scene node in which metadata will be added. - void Postprocess_AddMetadata(const std::list &pMetadataList, aiNode &pSceneNode) const; + void Postprocess_AddMetadata(const AMFMetaDataArray &pMetadataList, aiNode &pSceneNode) const; /// To create aiMesh and aiNode for it from . /// \param [in] pNodeElement - reference to node element which kept data. - /// \param [out] pMeshList - reference to a list with all aiMesh of the scene. - /// \param [out] pSceneNode - pointer to place where new aiNode will be created. - void Postprocess_BuildNodeAndObject(const AMFObject &pNodeElement, std::list &pMeshList, aiNode **pSceneNode); + /// \param [out] meshList - reference to a list with all aiMesh of the scene. + /// \param [out] pSceneNode - pointer to place where new aiNode will be created. + void Postprocess_BuildNodeAndObject(const AMFObject &pNodeElement, MeshArray &meshList, aiNode **pSceneNode); /// Create mesh for every in . /// \param [in] pNodeElement - reference to node element which kept data. @@ -189,7 +193,7 @@ private: /// \param [out] pSceneNode - reference to aiNode which will own new aiMesh's. void Postprocess_BuildMeshSet(const AMFMesh &pNodeElement, const std::vector &pVertexCoordinateArray, const std::vector &pVertexColorArray, const AMFColor *pObjectColor, - std::list &pMeshList, aiNode &pSceneNode); + MeshArray &pMeshList, aiNode &pSceneNode); /// Convert material from \ref CAMFImporter_NodeElement_Material to \ref SPP_Material. /// \param [in] pMaterial - source CAMFImporter_NodeElement_Material. @@ -197,8 +201,8 @@ private: /// Create and add to aiNode's list new part of scene graph defined by . /// \param [in] pConstellation - reference to node. - /// \param [out] pNodeList - reference to aiNode's list. - void Postprocess_BuildConstellation(AMFConstellation &pConstellation, std::list &pNodeList) const; + /// \param [out] nodeArray - reference to aiNode's list. + void Postprocess_BuildConstellation(AMFConstellation &pConstellation, NodeArray &nodeArray) const; /// Build Assimp scene graph in aiScene from collected data. /// \param [out] pScene - pointer to aiScene where tree will be built. @@ -276,7 +280,7 @@ public: void InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler); const aiImporterDesc *GetInfo() const; bool Find_NodeElement(const std::string &pID, const AMFNodeElementBase::EType pType, AMFNodeElementBase **pNodeElement) const; - bool Find_ConvertedNode(const std::string &pID, std::list &pNodeList, aiNode **pNode) const; + bool Find_ConvertedNode(const std::string &pID, NodeArray &nodeArray, aiNode **pNode) const; bool Find_ConvertedMaterial(const std::string &pID, const SPP_Material **pConvertedMaterial) const; void Throw_CloseNotFound(const std::string &nodeName); void Throw_IncorrectAttr(const std::string &nodeName, const std::string &pAttrName); diff --git a/code/AssetLib/AMF/AMFImporter_Postprocess.cpp b/code/AssetLib/AMF/AMFImporter_Postprocess.cpp index 3b09af1f0..6d0ec2380 100644 --- a/code/AssetLib/AMF/AMFImporter_Postprocess.cpp +++ b/code/AssetLib/AMF/AMFImporter_Postprocess.cpp @@ -124,7 +124,7 @@ void AMFImporter::PostprocessHelper_CreateMeshDataArray(const AMFMesh &pNodeElem } } - col_idx++; + ++col_idx; } } } @@ -156,7 +156,9 @@ size_t AMFImporter::PostprocessHelper_GetTextureID_Or_Create(const std::string & // R if (!r.empty()) { - if (!Find_NodeElement(r, AMFNodeElementBase::EType::ENET_Texture, &t_tex)) Throw_ID_NotFound(r); + if (!Find_NodeElement(r, AMFNodeElementBase::EType::ENET_Texture, &t_tex)) { + Throw_ID_NotFound(r); + } src_texture[0] = (AMFTexture *)t_tex; src_texture_4check.push_back((AMFTexture *)t_tex); @@ -166,7 +168,9 @@ size_t AMFImporter::PostprocessHelper_GetTextureID_Or_Create(const std::string & // G if (!g.empty()) { - if (!Find_NodeElement(g, AMFNodeElementBase::ENET_Texture, &t_tex)) Throw_ID_NotFound(g); + if (!Find_NodeElement(g, AMFNodeElementBase::ENET_Texture, &t_tex)) { + Throw_ID_NotFound(g); + } src_texture[1] = (AMFTexture *)t_tex; src_texture_4check.push_back((AMFTexture *)t_tex); @@ -176,7 +180,9 @@ size_t AMFImporter::PostprocessHelper_GetTextureID_Or_Create(const std::string & // B if (!b.empty()) { - if (!Find_NodeElement(b, AMFNodeElementBase::ENET_Texture, &t_tex)) Throw_ID_NotFound(b); + if (!Find_NodeElement(b, AMFNodeElementBase::ENET_Texture, &t_tex)) { + Throw_ID_NotFound(b); + } src_texture[2] = (AMFTexture *)t_tex; src_texture_4check.push_back((AMFTexture *)t_tex); @@ -186,7 +192,9 @@ size_t AMFImporter::PostprocessHelper_GetTextureID_Or_Create(const std::string & // A if (!a.empty()) { - if (!Find_NodeElement(a, AMFNodeElementBase::ENET_Texture, &t_tex)) Throw_ID_NotFound(a); + if (!Find_NodeElement(a, AMFNodeElementBase::ENET_Texture, &t_tex)) { + Throw_ID_NotFound(a); + } src_texture[3] = (AMFTexture *)t_tex; src_texture_4check.push_back((AMFTexture *)t_tex); @@ -211,8 +219,9 @@ size_t AMFImporter::PostprocessHelper_GetTextureID_Or_Create(const std::string & converted_texture.Depth = src_texture_4check[0]->Depth; // if one of source texture is tiled then converted texture is tiled too. converted_texture.Tiled = false; - for (uint8_t i = 0; i < src_texture_4check.size(); i++) + for (uint8_t i = 0; i < src_texture_4check.size(); ++i) { converted_texture.Tiled |= src_texture_4check[i]->Tiled; + } // Create format hint. strcpy(converted_texture.FormatHint, "rgba0000"); // copy initial string. @@ -309,10 +318,11 @@ void AMFImporter::PostprocessHelper_SplitFacesByTextureID(std::list &metadataList, aiNode &sceneNode) const { +void AMFImporter::Postprocess_AddMetadata(const AMFMetaDataArray &metadataList, aiNode &sceneNode) const { if (metadataList.empty()) { return; } + if (sceneNode.mMetaData != nullptr) { throw DeadlyImportError("Postprocess. MetaData member in node are not nullptr. Something went wrong."); } @@ -326,7 +336,7 @@ void AMFImporter::Postprocess_AddMetadata(const std::list &metada } } -void AMFImporter::Postprocess_BuildNodeAndObject(const AMFObject &pNodeElement, std::list &pMeshList, aiNode **pSceneNode) { +void AMFImporter::Postprocess_BuildNodeAndObject(const AMFObject &pNodeElement, MeshArray &meshList, aiNode **pSceneNode) { AMFColor *object_color = nullptr; // create new aiNode and set name as has. @@ -346,14 +356,13 @@ void AMFImporter::Postprocess_BuildNodeAndObject(const AMFObject &pNodeElement, // Create arrays from children of mesh: vertices. PostprocessHelper_CreateMeshDataArray(*((AMFMesh *)ne_child), vertex_arr, color_arr); // Use this arrays as a source when creating every aiMesh - Postprocess_BuildMeshSet(*((AMFMesh *)ne_child), vertex_arr, color_arr, object_color, pMeshList, **pSceneNode); + Postprocess_BuildMeshSet(*((AMFMesh *)ne_child), vertex_arr, color_arr, object_color, meshList, **pSceneNode); } } // for(const CAMFImporter_NodeElement* ne_child: pNodeElement) } void AMFImporter::Postprocess_BuildMeshSet(const AMFMesh &pNodeElement, const std::vector &pVertexCoordinateArray, - const std::vector &pVertexColorArray, - const AMFColor *pObjectColor, std::list &pMeshList, aiNode &pSceneNode) { + const std::vector &pVertexColorArray, const AMFColor *pObjectColor, MeshArray &pMeshList, aiNode &pSceneNode) { std::list mesh_idx; // all data stored in "volume", search for it. @@ -659,7 +668,7 @@ void AMFImporter::Postprocess_BuildMaterial(const AMFMaterial &pMaterial) { mMaterial_Converted.push_back(new_mat); } -void AMFImporter::Postprocess_BuildConstellation(AMFConstellation &pConstellation, std::list &pNodeList) const { +void AMFImporter::Postprocess_BuildConstellation(AMFConstellation &pConstellation, NodeArray &nodeArray) const { aiNode *con_node; std::list ch_node; @@ -682,7 +691,7 @@ void AMFImporter::Postprocess_BuildConstellation(AMFConstellation &pConstellatio // create alias for conveniance AMFInstance &als = *((AMFInstance *)ne); // find referenced object - if (!Find_ConvertedNode(als.ObjectID, pNodeList, &found_node)) Throw_ID_NotFound(als.ObjectID); + if (!Find_ConvertedNode(als.ObjectID, nodeArray, &found_node)) Throw_ID_NotFound(als.ObjectID); // create node for applying transformation t_node = new aiNode; @@ -711,13 +720,13 @@ void AMFImporter::Postprocess_BuildConstellation(AMFConstellation &pConstellatio con_node->mChildren[ch_idx++] = node; // and place "root" of node to node list - pNodeList.push_back(con_node); + nodeArray.push_back(con_node); } void AMFImporter::Postprocess_BuildScene(aiScene *pScene) { - std::list node_list; - std::list mesh_list; - std::list meta_list; + NodeArray nodeArray; + MeshArray mesh_list; + AMFMetaDataArray meta_list; // // Because for AMF "material" is just complex colors mixing so aiMaterial will not be used. @@ -764,7 +773,9 @@ void AMFImporter::Postprocess_BuildScene(aiScene *pScene) { // for mesh and node must be built: object ID assigned to aiNode name and will be used in future for Postprocess_BuildNodeAndObject(*((AMFObject *)root_child), mesh_list, &tnode); - if (tnode != nullptr) node_list.push_back(tnode); + if (tnode != nullptr) { + nodeArray.push_back(tnode); + } } } // for(const CAMFImporter_NodeElement* root_child: root_el->Child) @@ -774,7 +785,7 @@ void AMFImporter::Postprocess_BuildScene(aiScene *pScene) { // 4. if (root_child->Type == AMFNodeElementBase::ENET_Constellation) { // and at top of self abstraction use aiNode. So we can use only aiNode list for creating new aiNode's. - Postprocess_BuildConstellation(*((AMFConstellation *)root_child), node_list); + Postprocess_BuildConstellation(*((AMFConstellation *)root_child), nodeArray); } // 5, @@ -792,17 +803,17 @@ void AMFImporter::Postprocess_BuildScene(aiScene *pScene) { // And at this step we are checking that relations. nl_clean_loop: - if (node_list.size() > 1) { + if (nodeArray.size() > 1) { // walk through all nodes - for (std::list::iterator nl_it = node_list.begin(); nl_it != node_list.end(); ++nl_it) { + for (NodeArray::iterator nl_it = nodeArray.begin(); nl_it != nodeArray.end(); ++nl_it) { // and try to find them in another top nodes. - std::list::const_iterator next_it = nl_it; + NodeArray::const_iterator next_it = nl_it; ++next_it; - for (; next_it != node_list.end(); ++next_it) { + for (; next_it != nodeArray.end(); ++next_it) { if ((*next_it)->FindNode((*nl_it)->mName) != nullptr) { // if current top node(nl_it) found in another top node then erase it from node_list and restart search loop. - node_list.erase(nl_it); + nodeArray.erase(nl_it); goto nl_clean_loop; } @@ -815,10 +826,10 @@ nl_clean_loop: // // // Nodes - if (!node_list.empty()) { - std::list::const_iterator nl_it = node_list.begin(); + if (!nodeArray.empty()) { + NodeArray::const_iterator nl_it = nodeArray.begin(); - pScene->mRootNode->mNumChildren = static_cast(node_list.size()); + pScene->mRootNode->mNumChildren = static_cast(nodeArray.size()); pScene->mRootNode->mChildren = new aiNode *[pScene->mRootNode->mNumChildren]; for (size_t i = 0; i < pScene->mRootNode->mNumChildren; i++) { // Objects and constellation that must be showed placed at top of hierarchy in node. So all aiNode's in node_list must have @@ -831,7 +842,7 @@ nl_clean_loop: // // Meshes if (!mesh_list.empty()) { - std::list::const_iterator ml_it = mesh_list.begin(); + MeshArray::const_iterator ml_it = mesh_list.begin(); pScene->mNumMeshes = static_cast(mesh_list.size()); pScene->mMeshes = new aiMesh *[pScene->mNumMeshes];