X3D importer: Fixed import of normals for the single index / normal per vertex case

pull/1321/head
Patrick Dähne 2017-06-22 18:54:03 +02:00
parent 6118f77d3b
commit 855589d2a1
1 changed files with 21 additions and 20 deletions

View File

@ -1140,22 +1140,13 @@ void X3DImporter::MeshGeometry_AddNormal(aiMesh& pMesh, const std::list<int32_t>
if(pNormalPerVertex) if(pNormalPerVertex)
{ {
const std::list<int32_t>* srcidx;
if(pNormalIdx.size() > 0) if(pNormalIdx.size() > 0)
{ {
// check indices array count. // check indices array count.
if(pNormalIdx.size() != pCoordIdx.size()) throw DeadlyImportError("Normals and Coords inidces count must be equal."); if(pNormalIdx.size() != pCoordIdx.size()) throw DeadlyImportError("Normals and Coords inidces count must be equal.");
srcidx = &pNormalIdx; tind.reserve(pNormalIdx.size());
} for(std::list<int32_t>::const_iterator it = pNormalIdx.begin(); it != pNormalIdx.end(); it++)
else
{
srcidx = &pCoordIdx;
}
tind.reserve(srcidx->size());
for(std::list<int32_t>::const_iterator it = srcidx->begin(); it != srcidx->end(); it++)
{ {
if(*it != (-1)) tind.push_back(*it); if(*it != (-1)) tind.push_back(*it);
} }
@ -1170,6 +1161,16 @@ void X3DImporter::MeshGeometry_AddNormal(aiMesh& pMesh, const std::list<int32_t>
pMesh.mNormals[i] = norm_arr_copy[tind[i]]; pMesh.mNormals[i] = norm_arr_copy[tind[i]];
} }
}
else
{
if(pNormals.size() != pMesh.mNumVertices) throw DeadlyImportError("MeshGeometry_AddNormal. Normals and vertices count must be equal.");
// copy normals to mesh
pMesh.mNormals = new aiVector3D[pMesh.mNumVertices];
std::list<aiVector3D>::const_iterator norm_it = pNormals.begin();
for(size_t i = 0; i < pMesh.mNumVertices; i++) pMesh.mNormals[i] = *norm_it++;
}
}// if(pNormalPerVertex) }// if(pNormalPerVertex)
else else
{ {