From 85f86ec076dfaec16fc30d98d5894d80a7d1deb4 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sat, 30 Jul 2022 21:52:33 +0200 Subject: [PATCH] Revert using face as pod type --- code/AssetLib/Obj/ObjFileData.h | 6 ++-- code/AssetLib/Obj/ObjFileImporter.cpp | 48 +++++++++++++-------------- code/AssetLib/Obj/ObjFileParser.cpp | 26 +++++++-------- 3 files changed, 40 insertions(+), 40 deletions(-) diff --git a/code/AssetLib/Obj/ObjFileData.h b/code/AssetLib/Obj/ObjFileData.h index c7e8ea09d..f8b68d45f 100644 --- a/code/AssetLib/Obj/ObjFileData.h +++ b/code/AssetLib/Obj/ObjFileData.h @@ -64,7 +64,7 @@ struct Face { using IndexArray = std::vector; //! Primitive type - aiPrimitiveType m_PrimitiveType; + aiPrimitiveType mPrimitiveType; //! Vertex indices IndexArray m_vertices; //! Normal indices @@ -76,7 +76,7 @@ struct Face { //! \brief Default constructor Face(aiPrimitiveType pt = aiPrimitiveType_POLYGON) : - m_PrimitiveType(pt), m_vertices(), m_normals(), m_texturCoords(), m_pMaterial(0L) { + mPrimitiveType(pt), m_vertices(), m_normals(), m_texturCoords(), m_pMaterial(nullptr) { // empty } @@ -228,7 +228,7 @@ struct Mesh { /// The name for the mesh std::string m_name; /// Array with pointer to all stored faces - std::vector m_Faces; + std::vector m_Faces; /// Assigned material Material *m_pMaterial; /// Number of stored indices. diff --git a/code/AssetLib/Obj/ObjFileImporter.cpp b/code/AssetLib/Obj/ObjFileImporter.cpp index 43dfa008b..3c8f3b6c8 100644 --- a/code/AssetLib/Obj/ObjFileImporter.cpp +++ b/code/AssetLib/Obj/ObjFileImporter.cpp @@ -330,18 +330,18 @@ aiMesh *ObjFileImporter::createTopology(const ObjFile::Model *pModel, const ObjF } for (size_t index = 0; index < pObjMesh->m_Faces.size(); index++) { - const ObjFile::Face &inp = pObjMesh->m_Faces[index]; + const ObjFile::Face *inp = pObjMesh->m_Faces[index]; //ai_assert(nullptr != inp); - if (inp.m_PrimitiveType == aiPrimitiveType_LINE) { - pMesh->mNumFaces += static_cast(inp.m_vertices.size() - 1); + if (inp->mPrimitiveType == aiPrimitiveType_LINE) { + pMesh->mNumFaces += static_cast(inp->m_vertices.size() - 1); pMesh->mPrimitiveTypes |= aiPrimitiveType_LINE; - } else if (inp.m_PrimitiveType == aiPrimitiveType_POINT) { - pMesh->mNumFaces += static_cast(inp.m_vertices.size()); + } else if (inp->mPrimitiveType == aiPrimitiveType_POINT) { + pMesh->mNumFaces += static_cast(inp->m_vertices.size()); pMesh->mPrimitiveTypes |= aiPrimitiveType_POINT; } else { ++pMesh->mNumFaces; - if (inp.m_vertices.size() > 3) { + if (inp->m_vertices.size() > 3) { pMesh->mPrimitiveTypes |= aiPrimitiveType_POLYGON; } else { pMesh->mPrimitiveTypes |= aiPrimitiveType_TRIANGLE; @@ -360,16 +360,16 @@ aiMesh *ObjFileImporter::createTopology(const ObjFile::Model *pModel, const ObjF // Copy all data from all stored meshes for (auto &face : pObjMesh->m_Faces) { - const ObjFile::Face &inp = face; - if (inp.m_PrimitiveType == aiPrimitiveType_LINE) { - for (size_t i = 0; i < inp.m_vertices.size() - 1; ++i) { + const ObjFile::Face *inp = face; + if (inp->mPrimitiveType == aiPrimitiveType_LINE) { + for (size_t i = 0; i < inp->m_vertices.size() - 1; ++i) { aiFace &f = pMesh->mFaces[outIndex++]; uiIdxCount += f.mNumIndices = 2; f.mIndices = new unsigned int[2]; } continue; - } else if (inp.m_PrimitiveType == aiPrimitiveType_POINT) { - for (size_t i = 0; i < inp.m_vertices.size(); ++i) { + } else if (inp->mPrimitiveType == aiPrimitiveType_POINT) { + for (size_t i = 0; i < inp->m_vertices.size(); ++i) { aiFace &f = pMesh->mFaces[outIndex++]; uiIdxCount += f.mNumIndices = 1; f.mIndices = new unsigned int[1]; @@ -378,7 +378,7 @@ aiMesh *ObjFileImporter::createTopology(const ObjFile::Model *pModel, const ObjF } aiFace *pFace = &pMesh->mFaces[outIndex++]; - const unsigned int uiNumIndices = (unsigned int)face.m_vertices.size(); + const unsigned int uiNumIndices = (unsigned int)face->m_vertices.size(); uiIdxCount += pFace->mNumIndices = (unsigned int)uiNumIndices; if (pFace->mNumIndices > 0) { pFace->mIndices = new unsigned int[uiNumIndices]; @@ -438,10 +438,10 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model *pModel, // Copy vertices, normals and textures into aiMesh instance bool normalsok = true, uvok = true; unsigned int newIndex = 0, outIndex = 0; - for (auto &sourceFace : pObjMesh->m_Faces) { + for (auto sourceFace : pObjMesh->m_Faces) { // Copy all index arrays - for (size_t vertexIndex = 0, outVertexIndex = 0; vertexIndex < sourceFace.m_vertices.size(); vertexIndex++) { - const unsigned int vertex = sourceFace.m_vertices.at(vertexIndex); + for (size_t vertexIndex = 0, outVertexIndex = 0; vertexIndex < sourceFace->m_vertices.size(); vertexIndex++) { + const unsigned int vertex = sourceFace->m_vertices.at(vertexIndex); if (vertex >= pModel->m_Vertices.size()) { throw DeadlyImportError("OBJ: vertex index out of range"); } @@ -453,8 +453,8 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model *pModel, pMesh->mVertices[newIndex] = pModel->m_Vertices[vertex]; // Copy all normals - if (normalsok && !pModel->m_Normals.empty() && vertexIndex < sourceFace.m_normals.size()) { - const unsigned int normal = sourceFace.m_normals.at(vertexIndex); + if (normalsok && !pModel->m_Normals.empty() && vertexIndex < sourceFace->m_normals.size()) { + const unsigned int normal = sourceFace->m_normals.at(vertexIndex); if (normal >= pModel->m_Normals.size()) { normalsok = false; } else { @@ -469,8 +469,8 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model *pModel, } // Copy all texture coordinates - if (uvok && !pModel->m_TextureCoord.empty() && vertexIndex < sourceFace.m_texturCoords.size()) { - const unsigned int tex = sourceFace.m_texturCoords.at(vertexIndex); + if (uvok && !pModel->m_TextureCoord.empty() && vertexIndex < sourceFace->m_texturCoords.size()) { + const unsigned int tex = sourceFace->m_texturCoords.at(vertexIndex); if (tex >= pModel->m_TextureCoord.size()) { uvok = false; @@ -483,16 +483,16 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model *pModel, // Get destination face aiFace *pDestFace = &pMesh->mFaces[outIndex]; - const bool last = (vertexIndex == sourceFace.m_vertices.size() - 1); - if (sourceFace.m_PrimitiveType != aiPrimitiveType_LINE || !last) { + const bool last = (vertexIndex == sourceFace->m_vertices.size() - 1); + if (sourceFace->mPrimitiveType != aiPrimitiveType_LINE || !last) { pDestFace->mIndices[outVertexIndex] = newIndex; outVertexIndex++; } - if (sourceFace.m_PrimitiveType == aiPrimitiveType_POINT) { + if (sourceFace->mPrimitiveType == aiPrimitiveType_POINT) { outIndex++; outVertexIndex = 0; - } else if (sourceFace.m_PrimitiveType == aiPrimitiveType_LINE) { + } else if (sourceFace->mPrimitiveType == aiPrimitiveType_LINE) { outVertexIndex = 0; if (!last) @@ -501,7 +501,7 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model *pModel, if (vertexIndex) { if (!last) { pMesh->mVertices[newIndex + 1] = pMesh->mVertices[newIndex]; - if (!sourceFace.m_normals.empty() && !pModel->m_Normals.empty()) { + if (!sourceFace->m_normals.empty() && !pModel->m_Normals.empty()) { pMesh->mNormals[newIndex + 1] = pMesh->mNormals[newIndex]; } if (!pModel->m_TextureCoord.empty()) { diff --git a/code/AssetLib/Obj/ObjFileParser.cpp b/code/AssetLib/Obj/ObjFileParser.cpp index ce65b8b8a..5ef3f7139 100644 --- a/code/AssetLib/Obj/ObjFileParser.cpp +++ b/code/AssetLib/Obj/ObjFileParser.cpp @@ -434,7 +434,7 @@ void ObjFileParser::getFace(aiPrimitiveType type) { } //ObjFile::Face *face = new ObjFile::Face(type); - ObjFile::Face face(type); + ObjFile::Face *face = new ObjFile::Face(type); bool hasNormal = false; const int vSize = static_cast(m_pModel->m_Vertices.size()); @@ -478,11 +478,11 @@ void ObjFileParser::getFace(aiPrimitiveType type) { if (iVal > 0) { // Store parsed index if (0 == iPos) { - face.m_vertices.push_back(iVal - 1); + face->m_vertices.push_back(iVal - 1); } else if (1 == iPos) { - face.m_texturCoords.push_back(iVal - 1); + face->m_texturCoords.push_back(iVal - 1); } else if (2 == iPos) { - face.m_normals.push_back(iVal - 1); + face->m_normals.push_back(iVal - 1); hasNormal = true; } else { reportErrorTokenInFace(); @@ -490,11 +490,11 @@ void ObjFileParser::getFace(aiPrimitiveType type) { } else if (iVal < 0) { // Store relatively index if (0 == iPos) { - face.m_vertices.push_back(vSize + iVal); + face->m_vertices.push_back(vSize + iVal); } else if (1 == iPos) { - face.m_texturCoords.push_back(vtSize + iVal); + face->m_texturCoords.push_back(vtSize + iVal); } else if (2 == iPos) { - face.m_normals.push_back(vnSize + iVal); + face->m_normals.push_back(vnSize + iVal); hasNormal = true; } else { reportErrorTokenInFace(); @@ -508,7 +508,7 @@ void ObjFileParser::getFace(aiPrimitiveType type) { m_DataIt += iStep; } - if (face.m_vertices.empty()) { + if (face->m_vertices.empty()) { ASSIMP_LOG_ERROR("Obj: Ignoring empty face"); // skip line and clean up m_DataIt = skipLine(m_DataIt, m_DataItEnd, m_uiLine); @@ -518,9 +518,9 @@ void ObjFileParser::getFace(aiPrimitiveType type) { // Set active material, if one set if (nullptr != m_pModel->m_pCurrentMaterial) { - face.m_pMaterial = m_pModel->m_pCurrentMaterial; + face->m_pMaterial = m_pModel->m_pCurrentMaterial; } else { - face.m_pMaterial = m_pModel->m_pDefaultMaterial; + face->m_pMaterial = m_pModel->m_pDefaultMaterial; } // Create a default object, if nothing is there @@ -534,9 +534,9 @@ void ObjFileParser::getFace(aiPrimitiveType type) { } // Store the face - m_pModel->m_pCurrentMesh->m_Faces.push_back(face); - m_pModel->m_pCurrentMesh->m_uiNumIndices += (unsigned int)face.m_vertices.size(); - m_pModel->m_pCurrentMesh->m_uiUVCoordinates[0] += (unsigned int)face.m_texturCoords.size(); + m_pModel->m_pCurrentMesh->m_Faces.emplace_back(face); + m_pModel->m_pCurrentMesh->m_uiNumIndices += static_cast(face->m_vertices.size()); + m_pModel->m_pCurrentMesh->m_uiUVCoordinates[0] += static_cast(face->m_texturCoords.size()); if (!m_pModel->m_pCurrentMesh->m_hasNormals && hasNormal) { m_pModel->m_pCurrentMesh->m_hasNormals = true; }