Merge pull request #2254 from assimp/kimkulling-patch-3

Update XFileParser.cpp
pull/2516/head
Kim Kulling 2019-06-15 20:39:37 +02:00 committed by GitHub
commit 3929ea0644
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 20 deletions

View File

@ -332,7 +332,7 @@ void XFileImporter::CreateMeshes( aiScene* pScene, aiNode* pNode, const std::vec
// collect vertex data for indices of this face // collect vertex data for indices of this face
for( unsigned int d = 0; d < df.mNumIndices; ++d ) { for( unsigned int d = 0; d < df.mNumIndices; ++d ) {
df.mIndices[d] = newIndex; df.mIndices[ d ] = newIndex;
const unsigned int newIdx( pf.mIndices[ d ] ); const unsigned int newIdx( pf.mIndices[ d ] );
if ( newIdx > sourceMesh->mPositions.size() ) { if ( newIdx > sourceMesh->mPositions.size() ) {
continue; continue;
@ -344,7 +344,10 @@ void XFileImporter::CreateMeshes( aiScene* pScene, aiNode* pNode, const std::vec
mesh->mVertices[newIndex] = sourceMesh->mPositions[pf.mIndices[d]]; mesh->mVertices[newIndex] = sourceMesh->mPositions[pf.mIndices[d]];
// Normal, if present // Normal, if present
if ( mesh->HasNormals() ) { if ( mesh->HasNormals() ) {
mesh->mNormals[ newIndex ] = sourceMesh->mNormals[ sourceMesh->mNormFaces[ f ].mIndices[ d ] ]; if ( sourceMesh->mNormFaces[ f ].mIndices.size() > d ) {
const size_t idx( sourceMesh->mNormFaces[ f ].mIndices[ d ] );
mesh->mNormals[ newIndex ] = sourceMesh->mNormals[ idx ];
}
} }
// texture coord sets // texture coord sets

View File

@ -58,13 +58,13 @@ struct aiNode;
namespace Assimp { namespace Assimp {
namespace XFile { namespace XFile {
struct Scene; struct Scene;
struct Node; struct Node;
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
/** The XFileImporter is a worker class capable of importing a scene from a /** The XFileImporter is a worker class capable of importing a scene from a
* DirectX file .x * DirectX file .x
*/ */
class XFileImporter : public BaseImporter { class XFileImporter : public BaseImporter {
public: public:

View File

@ -583,24 +583,30 @@ void XFileParser::ParseDataObjectMeshNormals( Mesh* pMesh)
pMesh->mNormals.resize( numNormals); pMesh->mNormals.resize( numNormals);
// read normal vectors // read normal vectors
for( unsigned int a = 0; a < numNormals; a++) for( unsigned int a = 0; a < numNormals; ++a) {
pMesh->mNormals[a] = ReadVector3(); pMesh->mNormals[a] = ReadVector3();
}
// read normal indices // read normal indices
unsigned int numFaces = ReadInt(); unsigned int numFaces = ReadInt();
if( numFaces != pMesh->mPosFaces.size()) if( numFaces != pMesh->mPosFaces.size()) {
ThrowException( "Normal face count does not match vertex face count."); ThrowException( "Normal face count does not match vertex face count.");
}
for( unsigned int a = 0; a < numFaces; a++) // do not crah when no face definitions are there
{ if (numFaces > 0) {
unsigned int numIndices = ReadInt(); // normal face creation
pMesh->mNormFaces.push_back( Face()); pMesh->mNormFaces.resize( pMesh->mNormFaces.size() + numFaces );
Face& face = pMesh->mNormFaces.back(); for( unsigned int a = 0; a < numFaces; ++a ) {
unsigned int numIndices = ReadInt();
pMesh->mNormFaces.push_back( Face() );
Face& face = pMesh->mNormFaces.back();
for( unsigned int b = 0; b < numIndices; ++b ) {
face.mIndices.push_back( ReadInt());
}
for( unsigned int b = 0; b < numIndices; b++) TestForSeparator();
face.mIndices.push_back( ReadInt()); }
TestForSeparator();
} }
CheckForClosingBrace(); CheckForClosingBrace();

View File

@ -1,6 +1,6 @@
ply ply
format ascii 1.0 format ascii 1.0
comment Created by Open Asset Import Library - http://assimp.sf.net (v4.1.2760932948) comment Created by Open Asset Import Library - http://assimp.sf.net (v4.1.3945266037)
element vertex 8 element vertex 8
property float x property float x
property float y property float y

View File

@ -133,10 +133,10 @@ TEST_F(BlendImportMaterials, testImportMaterialwith2texturesAnd2TexCoordMappings
// material has 2 diffuse textures // material has 2 diffuse textures
ASSERT_TRUE(pTest->HasMaterials()); ASSERT_TRUE(pTest->HasMaterials());
EXPECT_EQ(1, pTest->mNumMaterials); EXPECT_EQ(1u, pTest->mNumMaterials);
const aiMaterial *pMat = pTest->mMaterials[0]; const aiMaterial *pMat = pTest->mMaterials[0];
ASSERT_TRUE(nullptr != pMat); ASSERT_TRUE(nullptr != pMat);
ASSERT_EQ(2, pMat->GetTextureCount(aiTextureType_DIFFUSE)); ASSERT_EQ(2u, pMat->GetTextureCount(aiTextureType_DIFFUSE));
aiString aPath; aiString aPath;
aiTextureMapping tm = aiTextureMapping::aiTextureMapping_OTHER; aiTextureMapping tm = aiTextureMapping::aiTextureMapping_OTHER;
aiReturn result = pMat->GetTexture(aiTextureType_DIFFUSE, 0, &aPath, &tm); aiReturn result = pMat->GetTexture(aiTextureType_DIFFUSE, 0, &aPath, &tm);
@ -146,7 +146,7 @@ TEST_F(BlendImportMaterials, testImportMaterialwith2texturesAnd2TexCoordMappings
// mesh has 2 texturecoord sets // mesh has 2 texturecoord sets
ASSERT_TRUE(pTest->HasMeshes()); ASSERT_TRUE(pTest->HasMeshes());
EXPECT_EQ(1, pTest->mNumMeshes); EXPECT_EQ(1u, pTest->mNumMeshes);
const aiMesh *pMesh = pTest->mMeshes[0]; const aiMesh *pMesh = pTest->mMeshes[0];
ASSERT_TRUE(nullptr != pMesh); ASSERT_TRUE(nullptr != pMesh);
ASSERT_TRUE(pMesh->HasTextureCoords(0)); ASSERT_TRUE(pMesh->HasTextureCoords(0));