Revert using face as pod type
parent
0513eff44f
commit
85f86ec076
|
@ -64,7 +64,7 @@ struct Face {
|
||||||
using IndexArray = std::vector<unsigned int>;
|
using IndexArray = std::vector<unsigned int>;
|
||||||
|
|
||||||
//! Primitive type
|
//! Primitive type
|
||||||
aiPrimitiveType m_PrimitiveType;
|
aiPrimitiveType mPrimitiveType;
|
||||||
//! Vertex indices
|
//! Vertex indices
|
||||||
IndexArray m_vertices;
|
IndexArray m_vertices;
|
||||||
//! Normal indices
|
//! Normal indices
|
||||||
|
@ -76,7 +76,7 @@ struct Face {
|
||||||
|
|
||||||
//! \brief Default constructor
|
//! \brief Default constructor
|
||||||
Face(aiPrimitiveType pt = aiPrimitiveType_POLYGON) :
|
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
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,7 +228,7 @@ struct Mesh {
|
||||||
/// The name for the mesh
|
/// The name for the mesh
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
/// Array with pointer to all stored faces
|
/// Array with pointer to all stored faces
|
||||||
std::vector<Face> m_Faces;
|
std::vector<Face*> m_Faces;
|
||||||
/// Assigned material
|
/// Assigned material
|
||||||
Material *m_pMaterial;
|
Material *m_pMaterial;
|
||||||
/// Number of stored indices.
|
/// Number of stored indices.
|
||||||
|
|
|
@ -330,18 +330,18 @@ aiMesh *ObjFileImporter::createTopology(const ObjFile::Model *pModel, const ObjF
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t index = 0; index < pObjMesh->m_Faces.size(); index++) {
|
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);
|
//ai_assert(nullptr != inp);
|
||||||
|
|
||||||
if (inp.m_PrimitiveType == aiPrimitiveType_LINE) {
|
if (inp->mPrimitiveType == aiPrimitiveType_LINE) {
|
||||||
pMesh->mNumFaces += static_cast<unsigned int>(inp.m_vertices.size() - 1);
|
pMesh->mNumFaces += static_cast<unsigned int>(inp->m_vertices.size() - 1);
|
||||||
pMesh->mPrimitiveTypes |= aiPrimitiveType_LINE;
|
pMesh->mPrimitiveTypes |= aiPrimitiveType_LINE;
|
||||||
} else if (inp.m_PrimitiveType == aiPrimitiveType_POINT) {
|
} else if (inp->mPrimitiveType == aiPrimitiveType_POINT) {
|
||||||
pMesh->mNumFaces += static_cast<unsigned int>(inp.m_vertices.size());
|
pMesh->mNumFaces += static_cast<unsigned int>(inp->m_vertices.size());
|
||||||
pMesh->mPrimitiveTypes |= aiPrimitiveType_POINT;
|
pMesh->mPrimitiveTypes |= aiPrimitiveType_POINT;
|
||||||
} else {
|
} else {
|
||||||
++pMesh->mNumFaces;
|
++pMesh->mNumFaces;
|
||||||
if (inp.m_vertices.size() > 3) {
|
if (inp->m_vertices.size() > 3) {
|
||||||
pMesh->mPrimitiveTypes |= aiPrimitiveType_POLYGON;
|
pMesh->mPrimitiveTypes |= aiPrimitiveType_POLYGON;
|
||||||
} else {
|
} else {
|
||||||
pMesh->mPrimitiveTypes |= aiPrimitiveType_TRIANGLE;
|
pMesh->mPrimitiveTypes |= aiPrimitiveType_TRIANGLE;
|
||||||
|
@ -360,16 +360,16 @@ aiMesh *ObjFileImporter::createTopology(const ObjFile::Model *pModel, const ObjF
|
||||||
|
|
||||||
// Copy all data from all stored meshes
|
// Copy all data from all stored meshes
|
||||||
for (auto &face : pObjMesh->m_Faces) {
|
for (auto &face : pObjMesh->m_Faces) {
|
||||||
const ObjFile::Face &inp = face;
|
const ObjFile::Face *inp = face;
|
||||||
if (inp.m_PrimitiveType == aiPrimitiveType_LINE) {
|
if (inp->mPrimitiveType == aiPrimitiveType_LINE) {
|
||||||
for (size_t i = 0; i < inp.m_vertices.size() - 1; ++i) {
|
for (size_t i = 0; i < inp->m_vertices.size() - 1; ++i) {
|
||||||
aiFace &f = pMesh->mFaces[outIndex++];
|
aiFace &f = pMesh->mFaces[outIndex++];
|
||||||
uiIdxCount += f.mNumIndices = 2;
|
uiIdxCount += f.mNumIndices = 2;
|
||||||
f.mIndices = new unsigned int[2];
|
f.mIndices = new unsigned int[2];
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
} else if (inp.m_PrimitiveType == aiPrimitiveType_POINT) {
|
} else if (inp->mPrimitiveType == aiPrimitiveType_POINT) {
|
||||||
for (size_t i = 0; i < inp.m_vertices.size(); ++i) {
|
for (size_t i = 0; i < inp->m_vertices.size(); ++i) {
|
||||||
aiFace &f = pMesh->mFaces[outIndex++];
|
aiFace &f = pMesh->mFaces[outIndex++];
|
||||||
uiIdxCount += f.mNumIndices = 1;
|
uiIdxCount += f.mNumIndices = 1;
|
||||||
f.mIndices = new unsigned int[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++];
|
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;
|
uiIdxCount += pFace->mNumIndices = (unsigned int)uiNumIndices;
|
||||||
if (pFace->mNumIndices > 0) {
|
if (pFace->mNumIndices > 0) {
|
||||||
pFace->mIndices = new unsigned int[uiNumIndices];
|
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
|
// Copy vertices, normals and textures into aiMesh instance
|
||||||
bool normalsok = true, uvok = true;
|
bool normalsok = true, uvok = true;
|
||||||
unsigned int newIndex = 0, outIndex = 0;
|
unsigned int newIndex = 0, outIndex = 0;
|
||||||
for (auto &sourceFace : pObjMesh->m_Faces) {
|
for (auto sourceFace : pObjMesh->m_Faces) {
|
||||||
// Copy all index arrays
|
// Copy all index arrays
|
||||||
for (size_t vertexIndex = 0, outVertexIndex = 0; vertexIndex < sourceFace.m_vertices.size(); vertexIndex++) {
|
for (size_t vertexIndex = 0, outVertexIndex = 0; vertexIndex < sourceFace->m_vertices.size(); vertexIndex++) {
|
||||||
const unsigned int vertex = sourceFace.m_vertices.at(vertexIndex);
|
const unsigned int vertex = sourceFace->m_vertices.at(vertexIndex);
|
||||||
if (vertex >= pModel->m_Vertices.size()) {
|
if (vertex >= pModel->m_Vertices.size()) {
|
||||||
throw DeadlyImportError("OBJ: vertex index out of range");
|
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];
|
pMesh->mVertices[newIndex] = pModel->m_Vertices[vertex];
|
||||||
|
|
||||||
// Copy all normals
|
// Copy all normals
|
||||||
if (normalsok && !pModel->m_Normals.empty() && vertexIndex < sourceFace.m_normals.size()) {
|
if (normalsok && !pModel->m_Normals.empty() && vertexIndex < sourceFace->m_normals.size()) {
|
||||||
const unsigned int normal = sourceFace.m_normals.at(vertexIndex);
|
const unsigned int normal = sourceFace->m_normals.at(vertexIndex);
|
||||||
if (normal >= pModel->m_Normals.size()) {
|
if (normal >= pModel->m_Normals.size()) {
|
||||||
normalsok = false;
|
normalsok = false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -469,8 +469,8 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model *pModel,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy all texture coordinates
|
// Copy all texture coordinates
|
||||||
if (uvok && !pModel->m_TextureCoord.empty() && vertexIndex < sourceFace.m_texturCoords.size()) {
|
if (uvok && !pModel->m_TextureCoord.empty() && vertexIndex < sourceFace->m_texturCoords.size()) {
|
||||||
const unsigned int tex = sourceFace.m_texturCoords.at(vertexIndex);
|
const unsigned int tex = sourceFace->m_texturCoords.at(vertexIndex);
|
||||||
|
|
||||||
if (tex >= pModel->m_TextureCoord.size()) {
|
if (tex >= pModel->m_TextureCoord.size()) {
|
||||||
uvok = false;
|
uvok = false;
|
||||||
|
@ -483,16 +483,16 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model *pModel,
|
||||||
// Get destination face
|
// Get destination face
|
||||||
aiFace *pDestFace = &pMesh->mFaces[outIndex];
|
aiFace *pDestFace = &pMesh->mFaces[outIndex];
|
||||||
|
|
||||||
const bool last = (vertexIndex == sourceFace.m_vertices.size() - 1);
|
const bool last = (vertexIndex == sourceFace->m_vertices.size() - 1);
|
||||||
if (sourceFace.m_PrimitiveType != aiPrimitiveType_LINE || !last) {
|
if (sourceFace->mPrimitiveType != aiPrimitiveType_LINE || !last) {
|
||||||
pDestFace->mIndices[outVertexIndex] = newIndex;
|
pDestFace->mIndices[outVertexIndex] = newIndex;
|
||||||
outVertexIndex++;
|
outVertexIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sourceFace.m_PrimitiveType == aiPrimitiveType_POINT) {
|
if (sourceFace->mPrimitiveType == aiPrimitiveType_POINT) {
|
||||||
outIndex++;
|
outIndex++;
|
||||||
outVertexIndex = 0;
|
outVertexIndex = 0;
|
||||||
} else if (sourceFace.m_PrimitiveType == aiPrimitiveType_LINE) {
|
} else if (sourceFace->mPrimitiveType == aiPrimitiveType_LINE) {
|
||||||
outVertexIndex = 0;
|
outVertexIndex = 0;
|
||||||
|
|
||||||
if (!last)
|
if (!last)
|
||||||
|
@ -501,7 +501,7 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model *pModel,
|
||||||
if (vertexIndex) {
|
if (vertexIndex) {
|
||||||
if (!last) {
|
if (!last) {
|
||||||
pMesh->mVertices[newIndex + 1] = pMesh->mVertices[newIndex];
|
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];
|
pMesh->mNormals[newIndex + 1] = pMesh->mNormals[newIndex];
|
||||||
}
|
}
|
||||||
if (!pModel->m_TextureCoord.empty()) {
|
if (!pModel->m_TextureCoord.empty()) {
|
||||||
|
|
|
@ -434,7 +434,7 @@ void ObjFileParser::getFace(aiPrimitiveType type) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//ObjFile::Face *face = new ObjFile::Face(type);
|
//ObjFile::Face *face = new ObjFile::Face(type);
|
||||||
ObjFile::Face face(type);
|
ObjFile::Face *face = new ObjFile::Face(type);
|
||||||
bool hasNormal = false;
|
bool hasNormal = false;
|
||||||
|
|
||||||
const int vSize = static_cast<unsigned int>(m_pModel->m_Vertices.size());
|
const int vSize = static_cast<unsigned int>(m_pModel->m_Vertices.size());
|
||||||
|
@ -478,11 +478,11 @@ void ObjFileParser::getFace(aiPrimitiveType type) {
|
||||||
if (iVal > 0) {
|
if (iVal > 0) {
|
||||||
// Store parsed index
|
// Store parsed index
|
||||||
if (0 == iPos) {
|
if (0 == iPos) {
|
||||||
face.m_vertices.push_back(iVal - 1);
|
face->m_vertices.push_back(iVal - 1);
|
||||||
} else if (1 == iPos) {
|
} else if (1 == iPos) {
|
||||||
face.m_texturCoords.push_back(iVal - 1);
|
face->m_texturCoords.push_back(iVal - 1);
|
||||||
} else if (2 == iPos) {
|
} else if (2 == iPos) {
|
||||||
face.m_normals.push_back(iVal - 1);
|
face->m_normals.push_back(iVal - 1);
|
||||||
hasNormal = true;
|
hasNormal = true;
|
||||||
} else {
|
} else {
|
||||||
reportErrorTokenInFace();
|
reportErrorTokenInFace();
|
||||||
|
@ -490,11 +490,11 @@ void ObjFileParser::getFace(aiPrimitiveType type) {
|
||||||
} else if (iVal < 0) {
|
} else if (iVal < 0) {
|
||||||
// Store relatively index
|
// Store relatively index
|
||||||
if (0 == iPos) {
|
if (0 == iPos) {
|
||||||
face.m_vertices.push_back(vSize + iVal);
|
face->m_vertices.push_back(vSize + iVal);
|
||||||
} else if (1 == iPos) {
|
} else if (1 == iPos) {
|
||||||
face.m_texturCoords.push_back(vtSize + iVal);
|
face->m_texturCoords.push_back(vtSize + iVal);
|
||||||
} else if (2 == iPos) {
|
} else if (2 == iPos) {
|
||||||
face.m_normals.push_back(vnSize + iVal);
|
face->m_normals.push_back(vnSize + iVal);
|
||||||
hasNormal = true;
|
hasNormal = true;
|
||||||
} else {
|
} else {
|
||||||
reportErrorTokenInFace();
|
reportErrorTokenInFace();
|
||||||
|
@ -508,7 +508,7 @@ void ObjFileParser::getFace(aiPrimitiveType type) {
|
||||||
m_DataIt += iStep;
|
m_DataIt += iStep;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (face.m_vertices.empty()) {
|
if (face->m_vertices.empty()) {
|
||||||
ASSIMP_LOG_ERROR("Obj: Ignoring empty face");
|
ASSIMP_LOG_ERROR("Obj: Ignoring empty face");
|
||||||
// skip line and clean up
|
// skip line and clean up
|
||||||
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||||
|
@ -518,9 +518,9 @@ void ObjFileParser::getFace(aiPrimitiveType type) {
|
||||||
|
|
||||||
// Set active material, if one set
|
// Set active material, if one set
|
||||||
if (nullptr != m_pModel->m_pCurrentMaterial) {
|
if (nullptr != m_pModel->m_pCurrentMaterial) {
|
||||||
face.m_pMaterial = m_pModel->m_pCurrentMaterial;
|
face->m_pMaterial = m_pModel->m_pCurrentMaterial;
|
||||||
} else {
|
} else {
|
||||||
face.m_pMaterial = m_pModel->m_pDefaultMaterial;
|
face->m_pMaterial = m_pModel->m_pDefaultMaterial;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a default object, if nothing is there
|
// Create a default object, if nothing is there
|
||||||
|
@ -534,9 +534,9 @@ void ObjFileParser::getFace(aiPrimitiveType type) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store the face
|
// Store the face
|
||||||
m_pModel->m_pCurrentMesh->m_Faces.push_back(face);
|
m_pModel->m_pCurrentMesh->m_Faces.emplace_back(face);
|
||||||
m_pModel->m_pCurrentMesh->m_uiNumIndices += (unsigned int)face.m_vertices.size();
|
m_pModel->m_pCurrentMesh->m_uiNumIndices += static_cast<unsigned int>(face->m_vertices.size());
|
||||||
m_pModel->m_pCurrentMesh->m_uiUVCoordinates[0] += (unsigned int)face.m_texturCoords.size();
|
m_pModel->m_pCurrentMesh->m_uiUVCoordinates[0] += static_cast<unsigned int>(face->m_texturCoords.size());
|
||||||
if (!m_pModel->m_pCurrentMesh->m_hasNormals && hasNormal) {
|
if (!m_pModel->m_pCurrentMesh->m_hasNormals && hasNormal) {
|
||||||
m_pModel->m_pCurrentMesh->m_hasNormals = true;
|
m_pModel->m_pCurrentMesh->m_hasNormals = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue