Merge branch 'master' into fix-obj-line-continuation

pull/2550/head
Kim Kulling 2019-07-20 12:07:49 +02:00 committed by GitHub
commit ff7ec7e454
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 218 additions and 237 deletions

View File

@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2019, assimp team Copyright (c) 2006-2019, assimp team
All rights reserved. All rights reserved.
Redistribution and use of this software in source and binary forms, Redistribution and use of this software in source and binary forms,
@ -43,7 +41,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/** @file Implementation of the Collada loader */ /** @file Implementation of the Collada loader */
#ifndef ASSIMP_BUILD_NO_COLLADA_IMPORTER #ifndef ASSIMP_BUILD_NO_COLLADA_IMPORTER
#include "ColladaLoader.h" #include "ColladaLoader.h"
@ -67,7 +64,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <numeric> #include <numeric>
#include <memory> #include <memory>
using namespace Assimp; namespace Assimp {
using namespace Assimp::Formatter; using namespace Assimp::Formatter;
static const aiImporterDesc desc = { static const aiImporterDesc desc = {
@ -112,7 +110,7 @@ ColladaLoader::~ColladaLoader() {
// Returns whether the class can handle the format of the given file. // Returns whether the class can handle the format of the given file.
bool ColladaLoader::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const { bool ColladaLoader::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const {
// check file extension // check file extension
std::string extension = GetExtension(pFile); const std::string extension = GetExtension(pFile);
if (extension == "dae") { if (extension == "dae") {
return true; return true;
@ -166,12 +164,13 @@ void ColladaLoader::InternReadFile( const std::string& pFile, aiScene* pScene, I
// parse the input file // parse the input file
ColladaParser parser( pIOHandler, pFile); ColladaParser parser( pIOHandler, pFile);
if( !parser.mRootNode) if( !parser.mRootNode) {
throw DeadlyImportError( "Collada: File came out empty. Something is wrong here."); throw DeadlyImportError( "Collada: File came out empty. Something is wrong here.");
}
// reserve some storage to avoid unnecessary reallocs // reserve some storage to avoid unnecessary reallocs
newMats.reserve(parser.mMaterialLibrary.size()*2); newMats.reserve(parser.mMaterialLibrary.size()*2u);
mMeshes.reserve(parser.mMeshLibrary.size()*2); mMeshes.reserve(parser.mMeshLibrary.size()*2u);
mCameras.reserve(parser.mCameraLibrary.size()); mCameras.reserve(parser.mCameraLibrary.size());
mLights.reserve(parser.mLightLibrary.size()); mLights.reserve(parser.mLightLibrary.size());
@ -192,27 +191,27 @@ void ColladaLoader::InternReadFile( const std::string& pFile, aiScene* pScene, I
0, 0, 0, 1); 0, 0, 0, 1);
if( !ignoreUpDirection ) { if( !ignoreUpDirection ) {
// Convert to Y_UP, if different orientation // Convert to Y_UP, if different orientation
if( parser.mUpDirection == ColladaParser::UP_X) if( parser.mUpDirection == ColladaParser::UP_X) {
pScene->mRootNode->mTransformation *= aiMatrix4x4( pScene->mRootNode->mTransformation *= aiMatrix4x4(
0, -1, 0, 0, 0, -1, 0, 0,
1, 0, 0, 0, 1, 0, 0, 0,
0, 0, 1, 0, 0, 0, 1, 0,
0, 0, 0, 1); 0, 0, 0, 1);
else if( parser.mUpDirection == ColladaParser::UP_Z) } else if( parser.mUpDirection == ColladaParser::UP_Z) {
pScene->mRootNode->mTransformation *= aiMatrix4x4( pScene->mRootNode->mTransformation *= aiMatrix4x4(
1, 0, 0, 0, 1, 0, 0, 0,
0, 0, 1, 0, 0, 0, 1, 0,
0, -1, 0, 0, 0, -1, 0, 0,
0, 0, 0, 1); 0, 0, 0, 1);
} }
}
// Store scene metadata // Store scene metadata
if (!parser.mAssetMetaData.empty()) { if (!parser.mAssetMetaData.empty()) {
const size_t numMeta(parser.mAssetMetaData.size()); const size_t numMeta(parser.mAssetMetaData.size());
pScene->mMetaData = aiMetadata::Alloc(static_cast<unsigned int>(numMeta)); pScene->mMetaData = aiMetadata::Alloc(static_cast<unsigned int>(numMeta));
size_t i = 0; size_t i = 0;
for (auto it = parser.mAssetMetaData.cbegin(); it != parser.mAssetMetaData.cend(); ++it, ++i) for (auto it = parser.mAssetMetaData.cbegin(); it != parser.mAssetMetaData.cend(); ++it, ++i) {
{
pScene->mMetaData->Set(static_cast<unsigned int>(i), (*it).first, (*it).second); pScene->mMetaData->Set(static_cast<unsigned int>(i), (*it).first, (*it).second);
} }
} }
@ -232,9 +231,8 @@ void ColladaLoader::InternReadFile( const std::string& pFile, aiScene* pScene, I
// store all animations // store all animations
StoreAnimations( pScene, parser); StoreAnimations( pScene, parser);
// If no meshes have been loaded, it's probably just an animated skeleton. // If no meshes have been loaded, it's probably just an animated skeleton.
if (!pScene->mNumMeshes) { if ( 0u == pScene->mNumMeshes) {
if (!noSkeletonMesh) { if (!noSkeletonMesh) {
SkeletonMeshBuilder hero(pScene); SkeletonMeshBuilder hero(pScene);
@ -302,13 +300,12 @@ void ColladaLoader::ResolveNodeInstances( const ColladaParser& pParser, const Co
// FIX for http://sourceforge.net/tracker/?func=detail&aid=3054873&group_id=226462&atid=1067632 // FIX for http://sourceforge.net/tracker/?func=detail&aid=3054873&group_id=226462&atid=1067632
// need to check for both name and ID to catch all. To avoid breaking valid files, // need to check for both name and ID to catch all. To avoid breaking valid files,
// the workaround is only enabled when the first attempt to resolve the node has failed. // the workaround is only enabled when the first attempt to resolve the node has failed.
if (!nd) { if (nullptr == nd) {
nd = FindNode(pParser.mRootNode, nodeInst.mNode); nd = FindNode(pParser.mRootNode, nodeInst.mNode);
} }
if (!nd) if (nullptr == nd) {
ASSIMP_LOG_ERROR_F("Collada: Unable to resolve reference to instanced node ", nodeInst.mNode); ASSIMP_LOG_ERROR_F("Collada: Unable to resolve reference to instanced node ", nodeInst.mNode);
} else {
else {
// attach this node to the list of children // attach this node to the list of children
resolved.push_back(nd); resolved.push_back(nd);
} }
@ -431,8 +428,7 @@ void ColladaLoader::BuildCamerasForNode( const ColladaParser& pParser, const Col
out->mAspect = std::tan(AI_DEG_TO_RAD(srcCamera->mHorFov)) / out->mAspect = std::tan(AI_DEG_TO_RAD(srcCamera->mHorFov)) /
std::tan(AI_DEG_TO_RAD(srcCamera->mVerFov)); std::tan(AI_DEG_TO_RAD(srcCamera->mVerFov));
} }
} } else if (srcCamera->mAspect != 10e10f && srcCamera->mVerFov != 10e10f) {
else if (srcCamera->mAspect != 10e10f && srcCamera->mVerFov != 10e10f) {
out->mHorizontalFOV = 2.0f * AI_RAD_TO_DEG(std::atan(srcCamera->mAspect * out->mHorizontalFOV = 2.0f * AI_RAD_TO_DEG(std::atan(srcCamera->mAspect *
std::tan(AI_DEG_TO_RAD(srcCamera->mVerFov) * 0.5f))); std::tan(AI_DEG_TO_RAD(srcCamera->mVerFov) * 0.5f)));
} }
@ -470,7 +466,7 @@ void ColladaLoader::BuildMeshesForNode( const ColladaParser& pParser, const Coll
} }
} }
if( !srcMesh) { if( nullptr == srcMesh) {
ASSIMP_LOG_WARN_F( "Collada: Unable to find geometry for ID \"", mid.mMeshOrController, "\". Skipping." ); ASSIMP_LOG_WARN_F( "Collada: Unable to find geometry for ID \"", mid.mMeshOrController, "\". Skipping." );
continue; continue;
} }
@ -770,9 +766,7 @@ aiMesh* ColladaLoader::CreateMesh( const ColladaParser& pParser, const Collada::
IndexPairVector::const_iterator iit = weightStartPerVertex[orgIndex]; IndexPairVector::const_iterator iit = weightStartPerVertex[orgIndex];
size_t pairCount = pSrcController->mWeightCounts[orgIndex]; size_t pairCount = pSrcController->mWeightCounts[orgIndex];
for( size_t b = 0; b < pairCount; ++b, ++iit) for( size_t b = 0; b < pairCount; ++b, ++iit) {
{
const size_t jointIndex = iit->first; const size_t jointIndex = iit->first;
const size_t vertexIndex = iit->second; const size_t vertexIndex = iit->second;
ai_real weight = 1.0f; ai_real weight = 1.0f;
@ -780,7 +774,6 @@ aiMesh* ColladaLoader::CreateMesh( const ColladaParser& pParser, const Collada::
weight = ReadFloat(weightsAcc, weights, vertexIndex, 0); weight = ReadFloat(weightsAcc, weights, vertexIndex, 0);
} }
// one day I gonna kill that XSI Collada exporter // one day I gonna kill that XSI Collada exporter
if( weight > 0.0f) if( weight > 0.0f)
{ {
@ -794,19 +787,21 @@ aiMesh* ColladaLoader::CreateMesh( const ColladaParser& pParser, const Collada::
// count the number of bones which influence vertices of the current submesh // count the number of bones which influence vertices of the current submesh
size_t numRemainingBones = 0; size_t numRemainingBones = 0;
for( std::vector<std::vector<aiVertexWeight> >::const_iterator it = dstBones.begin(); it != dstBones.end(); ++it) for( std::vector<std::vector<aiVertexWeight> >::const_iterator it = dstBones.begin(); it != dstBones.end(); ++it) {
if( it->size() > 0) if( it->size() > 0) {
numRemainingBones++; ++numRemainingBones;
}
}
// create bone array and copy bone weights one by one // create bone array and copy bone weights one by one
dstMesh->mNumBones = static_cast<unsigned int>(numRemainingBones); dstMesh->mNumBones = static_cast<unsigned int>(numRemainingBones);
dstMesh->mBones = new aiBone*[numRemainingBones]; dstMesh->mBones = new aiBone*[numRemainingBones];
size_t boneCount = 0; size_t boneCount = 0;
for( size_t a = 0; a < numBones; ++a) for( size_t a = 0; a < numBones; ++a) {
{
// omit bones without weights // omit bones without weights
if( dstBones[a].size() == 0) if( dstBones[a].empty() ) {
continue; continue;
}
// create bone with its weights // create bone with its weights
aiBone* bone = new aiBone; aiBone* bone = new aiBone;
@ -852,14 +847,16 @@ aiMesh* ColladaLoader::CreateMesh( const ColladaParser& pParser, const Collada::
// and replace the bone's name by the node's name so that the user can use the standard // and replace the bone's name by the node's name so that the user can use the standard
// find-by-name method to associate nodes with bones. // find-by-name method to associate nodes with bones.
const Collada::Node* bnode = FindNode( pParser.mRootNode, bone->mName.data); const Collada::Node* bnode = FindNode( pParser.mRootNode, bone->mName.data);
if( !bnode) if( !bnode) {
bnode = FindNodeBySID( pParser.mRootNode, bone->mName.data); bnode = FindNodeBySID( pParser.mRootNode, bone->mName.data);
}
// assign the name that we would have assigned for the source node // assign the name that we would have assigned for the source node
if( bnode) if( bnode) {
bone->mName.Set( FindNameForNode( bnode)); bone->mName.Set( FindNameForNode( bnode));
else } else {
ASSIMP_LOG_WARN_F( "ColladaLoader::CreateMesh(): could not find corresponding node for joint \"", bone->mName.data, "\"." ); ASSIMP_LOG_WARN_F( "ColladaLoader::CreateMesh(): could not find corresponding node for joint \"", bone->mName.data, "\"." );
}
// and insert bone // and insert bone
dstMesh->mBones[boneCount++] = bone; dstMesh->mBones[boneCount++] = bone;
@ -871,89 +868,80 @@ aiMesh* ColladaLoader::CreateMesh( const ColladaParser& pParser, const Collada::
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Stores all meshes in the given scene // Stores all meshes in the given scene
void ColladaLoader::StoreSceneMeshes( aiScene* pScene) void ColladaLoader::StoreSceneMeshes( aiScene* pScene) {
{
pScene->mNumMeshes = static_cast<unsigned int>(mMeshes.size()); pScene->mNumMeshes = static_cast<unsigned int>(mMeshes.size());
if( mMeshes.size() > 0) if( mMeshes.empty() ) {
{ return;
}
pScene->mMeshes = new aiMesh*[mMeshes.size()]; pScene->mMeshes = new aiMesh*[mMeshes.size()];
std::copy( mMeshes.begin(), mMeshes.end(), pScene->mMeshes); std::copy( mMeshes.begin(), mMeshes.end(), pScene->mMeshes);
mMeshes.clear(); mMeshes.clear();
}
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Stores all cameras in the given scene // Stores all cameras in the given scene
void ColladaLoader::StoreSceneCameras( aiScene* pScene) void ColladaLoader::StoreSceneCameras( aiScene* pScene) {
{
pScene->mNumCameras = static_cast<unsigned int>(mCameras.size()); pScene->mNumCameras = static_cast<unsigned int>(mCameras.size());
if( mCameras.size() > 0) if( mCameras.empty() ) {
{ return;
}
pScene->mCameras = new aiCamera*[mCameras.size()]; pScene->mCameras = new aiCamera*[mCameras.size()];
std::copy( mCameras.begin(), mCameras.end(), pScene->mCameras); std::copy( mCameras.begin(), mCameras.end(), pScene->mCameras);
mCameras.clear(); mCameras.clear();
}
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Stores all lights in the given scene // Stores all lights in the given scene
void ColladaLoader::StoreSceneLights( aiScene* pScene) void ColladaLoader::StoreSceneLights( aiScene* pScene) {
{
pScene->mNumLights = static_cast<unsigned int>(mLights.size()); pScene->mNumLights = static_cast<unsigned int>(mLights.size());
if( mLights.size() > 0) if( mLights.empty() ) {
{ return;
}
pScene->mLights = new aiLight*[mLights.size()]; pScene->mLights = new aiLight*[mLights.size()];
std::copy( mLights.begin(), mLights.end(), pScene->mLights); std::copy( mLights.begin(), mLights.end(), pScene->mLights);
mLights.clear(); mLights.clear();
}
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Stores all textures in the given scene // Stores all textures in the given scene
void ColladaLoader::StoreSceneTextures( aiScene* pScene) void ColladaLoader::StoreSceneTextures( aiScene* pScene) {
{
pScene->mNumTextures = static_cast<unsigned int>(mTextures.size()); pScene->mNumTextures = static_cast<unsigned int>(mTextures.size());
if( mTextures.size() > 0) if( mTextures.empty() ) {
{ return;
}
pScene->mTextures = new aiTexture*[mTextures.size()]; pScene->mTextures = new aiTexture*[mTextures.size()];
std::copy( mTextures.begin(), mTextures.end(), pScene->mTextures); std::copy( mTextures.begin(), mTextures.end(), pScene->mTextures);
mTextures.clear(); mTextures.clear();
}
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Stores all materials in the given scene // Stores all materials in the given scene
void ColladaLoader::StoreSceneMaterials( aiScene* pScene) void ColladaLoader::StoreSceneMaterials( aiScene* pScene) {
{
pScene->mNumMaterials = static_cast<unsigned int>(newMats.size()); pScene->mNumMaterials = static_cast<unsigned int>(newMats.size());
if (newMats.empty() ) {
if (newMats.size() > 0) { return;
pScene->mMaterials = new aiMaterial*[newMats.size()];
for (unsigned int i = 0; i < newMats.size();++i)
pScene->mMaterials[i] = newMats[i].second;
newMats.clear();
} }
pScene->mMaterials = new aiMaterial*[newMats.size()];
for (unsigned int i = 0; i < newMats.size();++i) {
pScene->mMaterials[i] = newMats[i].second;
}
newMats.clear();
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Stores all animations // Stores all animations
void ColladaLoader::StoreAnimations( aiScene* pScene, const ColladaParser& pParser) void ColladaLoader::StoreAnimations( aiScene* pScene, const ColladaParser& pParser) {
{
// recursively collect all animations from the collada scene // recursively collect all animations from the collada scene
StoreAnimations( pScene, pParser, &pParser.mAnims, ""); StoreAnimations( pScene, pParser, &pParser.mAnims, "");
// catch special case: many animations with the same length, each affecting only a single node. // catch special case: many animations with the same length, each affecting only a single node.
// we need to unite all those single-node-anims to a proper combined animation // we need to unite all those single-node-anims to a proper combined animation
for( size_t a = 0; a < mAnims.size(); ++a) for( size_t a = 0; a < mAnims.size(); ++a) {
{
aiAnimation* templateAnim = mAnims[a]; aiAnimation* templateAnim = mAnims[a];
if( templateAnim->mNumChannels == 1) if( templateAnim->mNumChannels == 1) {
{
// search for other single-channel-anims with the same duration // search for other single-channel-anims with the same duration
std::vector<size_t> collectedAnimIndices; std::vector<size_t> collectedAnimIndices;
for( size_t b = a+1; b < mAnims.size(); ++b) for( size_t b = a+1; b < mAnims.size(); ++b) {
{
aiAnimation* other = mAnims[b]; aiAnimation* other = mAnims[b];
if( other->mNumChannels == 1 && other->mDuration == templateAnim->mDuration && if( other->mNumChannels == 1 && other->mDuration == templateAnim->mDuration &&
other->mTicksPerSecond == templateAnim->mTicksPerSecond ) other->mTicksPerSecond == templateAnim->mTicksPerSecond )
@ -1884,19 +1872,23 @@ const Collada::Node* ColladaLoader::FindNode( const Collada::Node* pNode, const
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Finds a node in the collada scene by the given SID // Finds a node in the collada scene by the given SID
const Collada::Node* ColladaLoader::FindNodeBySID( const Collada::Node* pNode, const std::string& pSID) const const Collada::Node* ColladaLoader::FindNodeBySID( const Collada::Node* pNode, const std::string& pSID) const {
{ if (nullptr == pNode) {
if( pNode->mSID == pSID) return nullptr;
return pNode;
for( size_t a = 0; a < pNode->mChildren.size(); ++a)
{
const Collada::Node* node = FindNodeBySID( pNode->mChildren[a], pSID);
if( node)
return node;
} }
return NULL; if (pNode->mSID == pSID) {
return pNode;
}
for( size_t a = 0; a < pNode->mChildren.size(); ++a) {
const Collada::Node* node = FindNodeBySID( pNode->mChildren[a], pSID);
if (node) {
return node;
}
}
return nullptr;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -1930,4 +1922,6 @@ std::string ColladaLoader::FindNameForNode( const Collada::Node* pNode)
} }
} }
} // Namespace Assimp
#endif // !! ASSIMP_BUILD_NO_DAE_IMPORTER #endif // !! ASSIMP_BUILD_NO_DAE_IMPORTER

View File

@ -127,7 +127,8 @@ inline void CompressVertex(const aiVector3D& v, uint32_t& out)
n.X = (int32_t)v.x; n.X = (int32_t)v.x;
n.Y = (int32_t)v.y; n.Y = (int32_t)v.y;
n.Z = (int32_t)v.z; n.Z = (int32_t)v.z;
out = t; ::memcpy( &out, &t, sizeof(int32_t));
//out = t;
} }
// UNREAL vertex decompression // UNREAL vertex decompression

View File

@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2019, assimp team Copyright (c) 2006-2019, assimp team
All rights reserved. All rights reserved.
Redistribution and use of this software in source and binary forms, Redistribution and use of this software in source and binary forms,
@ -73,11 +71,6 @@ TEST_F(BlenderWorkTest,work_279) {
ASSERT_TRUE(pTest->HasMaterials()); ASSERT_TRUE(pTest->HasMaterials());
ASSERT_TRUE(pTest->HasMeshes()); ASSERT_TRUE(pTest->HasMeshes());
ASSERT_TRUE(pTest->mMeshes[0]->mNumVertices > 0); ASSERT_TRUE(pTest->mMeshes[0]->mNumVertices > 0);
ASSERT_EQ(44, pTest->mMeshes[0]->mNumFaces); ASSERT_EQ(44u, pTest->mMeshes[0]->mNumFaces);
EXPECT_EQ(1, pTest->mNumMaterials); EXPECT_EQ(1u, pTest->mNumMaterials);
} }

View File

@ -70,10 +70,10 @@ TEST_F( utFBXImporterExporter, importBareBoxWithoutColorsAndTextureCoords ) {
Assimp::Importer importer; Assimp::Importer importer;
const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/FBX/box.fbx", aiProcess_ValidateDataStructure ); const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/FBX/box.fbx", aiProcess_ValidateDataStructure );
EXPECT_NE( nullptr, scene ); EXPECT_NE( nullptr, scene );
EXPECT_EQ(scene->mNumMeshes, 1); EXPECT_EQ(scene->mNumMeshes, 1u);
aiMesh* mesh = scene->mMeshes[0]; aiMesh* mesh = scene->mMeshes[0];
EXPECT_EQ(mesh->mNumFaces, 12); EXPECT_EQ(mesh->mNumFaces, 12u);
EXPECT_EQ(mesh->mNumVertices, 36); EXPECT_EQ(mesh->mNumVertices, 36u);
} }
TEST_F(utFBXImporterExporter, importCubesWithNoNames) { TEST_F(utFBXImporterExporter, importCubesWithNoNames) {
@ -85,13 +85,13 @@ TEST_F(utFBXImporterExporter, importCubesWithNoNames) {
const auto root = scene->mRootNode; const auto root = scene->mRootNode;
ASSERT_STREQ(root->mName.C_Str(), "RootNode"); ASSERT_STREQ(root->mName.C_Str(), "RootNode");
ASSERT_TRUE(root->mChildren); ASSERT_TRUE(root->mChildren);
ASSERT_EQ(root->mNumChildren, 2); ASSERT_EQ(root->mNumChildren, 2u);
const auto child0 = root->mChildren[0]; const auto child0 = root->mChildren[0];
ASSERT_TRUE(child0); ASSERT_TRUE(child0);
ASSERT_STREQ(child0->mName.C_Str(), "RootNode001"); ASSERT_STREQ(child0->mName.C_Str(), "RootNode001");
ASSERT_TRUE(child0->mChildren); ASSERT_TRUE(child0->mChildren);
ASSERT_EQ(child0->mNumChildren, 1); ASSERT_EQ(child0->mNumChildren, 1u);
const auto child00 = child0->mChildren[0]; const auto child00 = child0->mChildren[0];
ASSERT_TRUE(child00); ASSERT_TRUE(child00);
@ -101,7 +101,7 @@ TEST_F(utFBXImporterExporter, importCubesWithNoNames) {
ASSERT_TRUE(child1); ASSERT_TRUE(child1);
ASSERT_STREQ(child1->mName.C_Str(), "RootNode002"); ASSERT_STREQ(child1->mName.C_Str(), "RootNode002");
ASSERT_TRUE(child1->mChildren); ASSERT_TRUE(child1->mChildren);
ASSERT_EQ(child1->mNumChildren, 1); ASSERT_EQ(child1->mNumChildren, 1u);
const auto child10 = child1->mChildren[0]; const auto child10 = child1->mChildren[0];
ASSERT_TRUE(child10); ASSERT_TRUE(child10);
@ -117,13 +117,13 @@ TEST_F(utFBXImporterExporter, importCubesWithUnicodeDuplicatedNames) {
const auto root = scene->mRootNode; const auto root = scene->mRootNode;
ASSERT_STREQ(root->mName.C_Str(), "RootNode"); ASSERT_STREQ(root->mName.C_Str(), "RootNode");
ASSERT_TRUE(root->mChildren); ASSERT_TRUE(root->mChildren);
ASSERT_EQ(root->mNumChildren, 2); ASSERT_EQ(root->mNumChildren, 2u);
const auto child0 = root->mChildren[0]; const auto child0 = root->mChildren[0];
ASSERT_TRUE(child0); ASSERT_TRUE(child0);
ASSERT_STREQ(child0->mName.C_Str(), "Cube2"); ASSERT_STREQ(child0->mName.C_Str(), "Cube2");
ASSERT_TRUE(child0->mChildren); ASSERT_TRUE(child0->mChildren);
ASSERT_EQ(child0->mNumChildren, 1); ASSERT_EQ(child0->mNumChildren, 1u);
const auto child00 = child0->mChildren[0]; const auto child00 = child0->mChildren[0];
ASSERT_TRUE(child00); ASSERT_TRUE(child00);
@ -133,7 +133,7 @@ TEST_F(utFBXImporterExporter, importCubesWithUnicodeDuplicatedNames) {
ASSERT_TRUE(child1); ASSERT_TRUE(child1);
ASSERT_STREQ(child1->mName.C_Str(), "Cube3"); ASSERT_STREQ(child1->mName.C_Str(), "Cube3");
ASSERT_TRUE(child1->mChildren); ASSERT_TRUE(child1->mChildren);
ASSERT_EQ(child1->mNumChildren, 1); ASSERT_EQ(child1->mNumChildren, 1u);
const auto child10 = child1->mChildren[0]; const auto child10 = child1->mChildren[0];
ASSERT_TRUE(child10); ASSERT_TRUE(child10);
@ -149,13 +149,13 @@ TEST_F(utFBXImporterExporter, importCubesComplexTransform) {
const auto root = scene->mRootNode; const auto root = scene->mRootNode;
ASSERT_STREQ(root->mName.C_Str(), "RootNode"); ASSERT_STREQ(root->mName.C_Str(), "RootNode");
ASSERT_TRUE(root->mChildren); ASSERT_TRUE(root->mChildren);
ASSERT_EQ(root->mNumChildren, 2); ASSERT_EQ(root->mNumChildren, 2u);
const auto child0 = root->mChildren[0]; const auto child0 = root->mChildren[0];
ASSERT_TRUE(child0); ASSERT_TRUE(child0);
ASSERT_STREQ(child0->mName.C_Str(), "Cube2"); ASSERT_STREQ(child0->mName.C_Str(), "Cube2");
ASSERT_TRUE(child0->mChildren); ASSERT_TRUE(child0->mChildren);
ASSERT_EQ(child0->mNumChildren, 1); ASSERT_EQ(child0->mNumChildren, 1u);
const auto child00 = child0->mChildren[0]; const auto child00 = child0->mChildren[0];
ASSERT_TRUE(child00); ASSERT_TRUE(child00);
@ -177,35 +177,36 @@ TEST_F(utFBXImporterExporter, importCubesComplexTransform) {
"Cube1001_$AssimpFbx$_ScalingPivotInverse", "Cube1001_$AssimpFbx$_ScalingPivotInverse",
"Cube1001" "Cube1001"
}; };
for (size_t i = 0; i < chain_length; ++i) for (size_t i = 0; i < chain_length; ++i) {
{
ASSERT_TRUE(parent->mChildren); ASSERT_TRUE(parent->mChildren);
ASSERT_EQ(parent->mNumChildren, 1); ASSERT_EQ(parent->mNumChildren, 1u);
auto node = parent->mChildren[0]; auto node = parent->mChildren[0];
ASSERT_TRUE(node); ASSERT_TRUE(node);
ASSERT_STREQ(node->mName.C_Str(), chainStr[i]); ASSERT_STREQ(node->mName.C_Str(), chainStr[i]);
parent = node; parent = node;
} }
ASSERT_EQ(0, parent->mNumChildren) << "Leaf node"; ASSERT_EQ(0u, parent->mNumChildren) << "Leaf node";
} }
TEST_F( utFBXImporterExporter, importPhongMaterial ) { TEST_F( utFBXImporterExporter, importPhongMaterial ) {
Assimp::Importer importer; Assimp::Importer importer;
const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/FBX/phong_cube.fbx", aiProcess_ValidateDataStructure ); const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/FBX/phong_cube.fbx", aiProcess_ValidateDataStructure );
EXPECT_NE( nullptr, scene ); EXPECT_NE( nullptr, scene );
EXPECT_EQ( (unsigned int)1, scene->mNumMaterials ); EXPECT_EQ( 1u, scene->mNumMaterials );
const aiMaterial *mat = scene->mMaterials[0]; const aiMaterial *mat = scene->mMaterials[0];
EXPECT_NE( nullptr, mat ); EXPECT_NE( nullptr, mat );
float f; aiColor3D c; float f;
aiColor3D c;
// phong_cube.fbx has all properties defined // phong_cube.fbx has all properties defined
EXPECT_EQ( mat->Get(AI_MATKEY_COLOR_DIFFUSE, c), aiReturn_SUCCESS ); EXPECT_EQ( mat->Get(AI_MATKEY_COLOR_DIFFUSE, c), aiReturn_SUCCESS );
EXPECT_EQ( c, aiColor3D(0.5, 0.25, 0.25) ); EXPECT_EQ( c, aiColor3D(0.5, 0.25, 0.25) );
EXPECT_EQ( mat->Get(AI_MATKEY_COLOR_SPECULAR, c), aiReturn_SUCCESS ); EXPECT_EQ( mat->Get(AI_MATKEY_COLOR_SPECULAR, c), aiReturn_SUCCESS );
EXPECT_EQ( c, aiColor3D(0.25, 0.25, 0.5) ); EXPECT_EQ( c, aiColor3D(0.25, 0.25, 0.5) );
EXPECT_EQ( mat->Get(AI_MATKEY_SHININESS_STRENGTH, f), aiReturn_SUCCESS ); EXPECT_EQ( mat->Get(AI_MATKEY_SHININESS_STRENGTH, f), aiReturn_SUCCESS );
EXPECT_EQ( f, 0.5 ); EXPECT_EQ( f, 0.5f );
EXPECT_EQ( mat->Get(AI_MATKEY_SHININESS, f), aiReturn_SUCCESS ); EXPECT_EQ( mat->Get(AI_MATKEY_SHININESS, f), aiReturn_SUCCESS );
EXPECT_EQ( f, 10.0 ); EXPECT_EQ( f, 10.0f );
EXPECT_EQ( mat->Get(AI_MATKEY_COLOR_AMBIENT, c), aiReturn_SUCCESS ); EXPECT_EQ( mat->Get(AI_MATKEY_COLOR_AMBIENT, c), aiReturn_SUCCESS );
EXPECT_EQ( c, aiColor3D(0.125, 0.25, 0.25) ); EXPECT_EQ( c, aiColor3D(0.125, 0.25, 0.25) );
EXPECT_EQ( mat->Get(AI_MATKEY_COLOR_EMISSIVE, c), aiReturn_SUCCESS ); EXPECT_EQ( mat->Get(AI_MATKEY_COLOR_EMISSIVE, c), aiReturn_SUCCESS );
@ -213,7 +214,7 @@ TEST_F( utFBXImporterExporter, importPhongMaterial ) {
EXPECT_EQ( mat->Get(AI_MATKEY_COLOR_TRANSPARENT, c), aiReturn_SUCCESS ); EXPECT_EQ( mat->Get(AI_MATKEY_COLOR_TRANSPARENT, c), aiReturn_SUCCESS );
EXPECT_EQ( c, aiColor3D(0.75, 0.5, 0.25) ); EXPECT_EQ( c, aiColor3D(0.75, 0.5, 0.25) );
EXPECT_EQ( mat->Get(AI_MATKEY_OPACITY, f), aiReturn_SUCCESS ); EXPECT_EQ( mat->Get(AI_MATKEY_OPACITY, f), aiReturn_SUCCESS );
EXPECT_EQ( f, 0.5 ); EXPECT_EQ( f, 0.5f );
} }
TEST_F(utFBXImporterExporter, importUnitScaleFactor) { TEST_F(utFBXImporterExporter, importUnitScaleFactor) {
@ -234,7 +235,7 @@ TEST_F(utFBXImporterExporter, importEmbeddedAsciiTest) {
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/FBX/embedded_ascii/box.FBX", aiProcess_ValidateDataStructure); const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/FBX/embedded_ascii/box.FBX", aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene); EXPECT_NE(nullptr, scene);
EXPECT_EQ(1, scene->mNumMaterials); EXPECT_EQ(1u, scene->mNumMaterials);
aiMaterial *mat = scene->mMaterials[0]; aiMaterial *mat = scene->mMaterials[0];
ASSERT_NE(nullptr, mat); ASSERT_NE(nullptr, mat);
@ -243,7 +244,7 @@ TEST_F(utFBXImporterExporter, importEmbeddedAsciiTest) {
EXPECT_EQ(aiReturn_SUCCESS, mat->GetTexture(aiTextureType_DIFFUSE, 0, &path, nullptr, nullptr, nullptr, nullptr, modes)); EXPECT_EQ(aiReturn_SUCCESS, mat->GetTexture(aiTextureType_DIFFUSE, 0, &path, nullptr, nullptr, nullptr, nullptr, modes));
ASSERT_STREQ(path.C_Str(), "..\\..\\..\\Desktop\\uv_test.png"); ASSERT_STREQ(path.C_Str(), "..\\..\\..\\Desktop\\uv_test.png");
ASSERT_EQ(1, scene->mNumTextures); ASSERT_EQ(1u, scene->mNumTextures);
ASSERT_TRUE(scene->mTextures[0]->pcData); ASSERT_TRUE(scene->mTextures[0]->pcData);
ASSERT_EQ(439176u, scene->mTextures[0]->mWidth) << "FBX ASCII base64 compression splits data by 512Kb, it should be two parts for this texture"; ASSERT_EQ(439176u, scene->mTextures[0]->mWidth) << "FBX ASCII base64 compression splits data by 512Kb, it should be two parts for this texture";
} }
@ -254,7 +255,7 @@ TEST_F(utFBXImporterExporter, importEmbeddedFragmentedAsciiTest) {
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/FBX/embedded_ascii/box_embedded_texture_fragmented.fbx", aiProcess_ValidateDataStructure); const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/FBX/embedded_ascii/box_embedded_texture_fragmented.fbx", aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene); EXPECT_NE(nullptr, scene);
EXPECT_EQ(1, scene->mNumMaterials); EXPECT_EQ(1u, scene->mNumMaterials);
aiMaterial *mat = scene->mMaterials[0]; aiMaterial *mat = scene->mMaterials[0];
ASSERT_NE(nullptr, mat); ASSERT_NE(nullptr, mat);
@ -263,7 +264,7 @@ TEST_F(utFBXImporterExporter, importEmbeddedFragmentedAsciiTest) {
ASSERT_EQ(aiReturn_SUCCESS, mat->GetTexture(aiTextureType_DIFFUSE, 0, &path, nullptr, nullptr, nullptr, nullptr, modes)); ASSERT_EQ(aiReturn_SUCCESS, mat->GetTexture(aiTextureType_DIFFUSE, 0, &path, nullptr, nullptr, nullptr, nullptr, modes));
ASSERT_STREQ(path.C_Str(), "paper.png"); ASSERT_STREQ(path.C_Str(), "paper.png");
ASSERT_EQ(1, scene->mNumTextures); ASSERT_EQ(1u, scene->mNumTextures);
ASSERT_TRUE(scene->mTextures[0]->pcData); ASSERT_TRUE(scene->mTextures[0]->pcData);
ASSERT_EQ(968029u, scene->mTextures[0]->mWidth) << "FBX ASCII base64 compression splits data by 512Kb, it should be two parts for this texture"; ASSERT_EQ(968029u, scene->mTextures[0]->mWidth) << "FBX ASCII base64 compression splits data by 512Kb, it should be two parts for this texture";
} }

View File

@ -183,8 +183,7 @@ TEST_F(SortByPTypeProcessTest, SortByPTypeStep) {
unsigned int idx = 0; unsigned int idx = 0;
for (unsigned int m = 0,real = 0; m< 10;++m) { for (unsigned int m = 0,real = 0; m< 10;++m) {
for (unsigned int n = 0; n < 4;++n) { for (unsigned int n = 0; n < 4;++n) {
if ((idx = num[m][n])) if ((idx = num[m][n])) {
{
EXPECT_TRUE(real < mScene->mNumMeshes); EXPECT_TRUE(real < mScene->mNumMeshes);
aiMesh* mesh = mScene->mMeshes[real]; aiMesh* mesh = mScene->mMeshes[real];

View File

@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2019, assimp team Copyright (c) 2006-2019, assimp team
All rights reserved. All rights reserved.
Redistribution and use of this software in source and binary forms, Redistribution and use of this software in source and binary forms,
@ -55,17 +53,23 @@ class utglTF2ImportExport : public AbstractImportExportBase {
public: public:
virtual bool importerTest() { virtual bool importerTest() {
Assimp::Importer importer; Assimp::Importer importer;
const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/glTF2/BoxTextured-glTF/BoxTextured.gltf", aiProcess_ValidateDataStructure); const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/glTF2/BoxTextured-glTF/BoxTextured.gltf",
aiProcess_ValidateDataStructure);
EXPECT_NE( scene, nullptr ); EXPECT_NE( scene, nullptr );
if ( !scene ) return false; if (!scene) {
return false;
}
EXPECT_TRUE( scene->HasMaterials() ); EXPECT_TRUE( scene->HasMaterials() );
if ( !scene->HasMaterials() ) return false; if (!scene->HasMaterials()) {
return false;
}
const aiMaterial *material = scene->mMaterials[0]; const aiMaterial *material = scene->mMaterials[0];
aiString path; aiString path;
aiTextureMapMode modes[2]; aiTextureMapMode modes[2];
EXPECT_EQ( aiReturn_SUCCESS, material->GetTexture(aiTextureType_DIFFUSE, 0, &path, nullptr, nullptr, nullptr, nullptr, modes) ); EXPECT_EQ( aiReturn_SUCCESS, material->GetTexture(aiTextureType_DIFFUSE, 0, &path, nullptr, nullptr,
nullptr, nullptr, modes) );
EXPECT_STREQ( path.C_Str(), "CesiumLogoFlat.png" ); EXPECT_STREQ( path.C_Str(), "CesiumLogoFlat.png" );
EXPECT_EQ( modes[0], aiTextureMapMode_Mirror ); EXPECT_EQ( modes[0], aiTextureMapMode_Mirror );
EXPECT_EQ( modes[1], aiTextureMapMode_Clamp ); EXPECT_EQ( modes[1], aiTextureMapMode_Clamp );
@ -75,7 +79,8 @@ public:
virtual bool binaryImporterTest() { virtual bool binaryImporterTest() {
Assimp::Importer importer; Assimp::Importer importer;
const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/glTF2/2CylinderEngine-glTF-Binary/2CylinderEngine.glb", aiProcess_ValidateDataStructure); const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/glTF2/2CylinderEngine-glTF-Binary/2CylinderEngine.glb",
aiProcess_ValidateDataStructure);
return nullptr != scene; return nullptr != scene;
} }
@ -83,7 +88,8 @@ public:
virtual bool exporterTest() { virtual bool exporterTest() {
Assimp::Importer importer; Assimp::Importer importer;
Assimp::Exporter exporter; Assimp::Exporter exporter;
const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/glTF2/BoxTextured-glTF/BoxTextured.gltf", aiProcess_ValidateDataStructure ); const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/glTF2/BoxTextured-glTF/BoxTextured.gltf",
aiProcess_ValidateDataStructure );
EXPECT_NE( nullptr, scene ); EXPECT_NE( nullptr, scene );
EXPECT_EQ( aiReturn_SUCCESS, exporter.Export( scene, "gltf2", ASSIMP_TEST_MODELS_DIR "/glTF2/BoxTextured-glTF/BoxTextured_out.gltf" ) ); EXPECT_EQ( aiReturn_SUCCESS, exporter.Export( scene, "gltf2", ASSIMP_TEST_MODELS_DIR "/glTF2/BoxTextured-glTF/BoxTextured_out.gltf" ) );
@ -105,7 +111,8 @@ TEST_F( utglTF2ImportExport, importBinaryglTF2FromFileTest ) {
TEST_F(utglTF2ImportExport, importglTF2AndExportToOBJ) { TEST_F(utglTF2ImportExport, importglTF2AndExportToOBJ) {
Assimp::Importer importer; Assimp::Importer importer;
Assimp::Exporter exporter; Assimp::Exporter exporter;
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/BoxTextured-glTF/BoxTextured.gltf", aiProcess_ValidateDataStructure); const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/BoxTextured-glTF/BoxTextured.gltf",
aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene); EXPECT_NE(nullptr, scene);
EXPECT_EQ(aiReturn_SUCCESS, exporter.Export(scene, "obj", ASSIMP_TEST_MODELS_DIR "/glTF2/BoxTextured-glTF/BoxTextured_out.obj")); EXPECT_EQ(aiReturn_SUCCESS, exporter.Export(scene, "obj", ASSIMP_TEST_MODELS_DIR "/glTF2/BoxTextured-glTF/BoxTextured_out.obj"));
} }
@ -113,7 +120,8 @@ TEST_F(utglTF2ImportExport, importglTF2AndExportToOBJ) {
TEST_F(utglTF2ImportExport, importglTF2EmbeddedAndExportToOBJ) { TEST_F(utglTF2ImportExport, importglTF2EmbeddedAndExportToOBJ) {
Assimp::Importer importer; Assimp::Importer importer;
Assimp::Exporter exporter; Assimp::Exporter exporter;
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/BoxTextured-glTF-Embedded/BoxTextured.gltf", aiProcess_ValidateDataStructure); const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/BoxTextured-glTF-Embedded/BoxTextured.gltf",
aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene); EXPECT_NE(nullptr, scene);
EXPECT_EQ(aiReturn_SUCCESS, exporter.Export(scene, "obj", ASSIMP_TEST_MODELS_DIR "/glTF2/BoxTextured-glTF-Embedded/BoxTextured_out.obj")); EXPECT_EQ(aiReturn_SUCCESS, exporter.Export(scene, "obj", ASSIMP_TEST_MODELS_DIR "/glTF2/BoxTextured-glTF-Embedded/BoxTextured_out.obj"));
} }
@ -124,10 +132,9 @@ TEST_F(utglTF2ImportExport, importglTF2PrimitiveModePointsWithoutIndices) {
//Points without indices //Points without indices
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/glTF-Asset-Generator/Mesh_PrimitiveMode/Mesh_PrimitiveMode_00.gltf", aiProcess_ValidateDataStructure); const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/glTF-Asset-Generator/Mesh_PrimitiveMode/Mesh_PrimitiveMode_00.gltf", aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene); EXPECT_NE(nullptr, scene);
EXPECT_EQ(scene->mMeshes[0]->mNumVertices, 1024); EXPECT_EQ(scene->mMeshes[0]->mNumVertices, 1024u);
for (unsigned int i = 0; i < scene->mMeshes[0]->mNumFaces; ++i) for (unsigned int i = 0; i < scene->mMeshes[0]->mNumFaces; ++i) {
{ EXPECT_EQ(scene->mMeshes[0]->mFaces[i].mNumIndices, 1u);
EXPECT_EQ(scene->mMeshes[0]->mFaces[i].mNumIndices, 1);
EXPECT_EQ(scene->mMeshes[0]->mFaces[i].mIndices[0], i); EXPECT_EQ(scene->mMeshes[0]->mFaces[i].mIndices[0], i);
} }
} }
@ -137,12 +144,11 @@ TEST_F(utglTF2ImportExport, importglTF2PrimitiveModeLinesWithoutIndices) {
//Lines without indices //Lines without indices
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/glTF-Asset-Generator/Mesh_PrimitiveMode/Mesh_PrimitiveMode_01.gltf", aiProcess_ValidateDataStructure); const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/glTF-Asset-Generator/Mesh_PrimitiveMode/Mesh_PrimitiveMode_01.gltf", aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene); EXPECT_NE(nullptr, scene);
EXPECT_EQ(scene->mMeshes[0]->mNumVertices, 8); EXPECT_EQ(scene->mMeshes[0]->mNumVertices, 8u);
for (unsigned int i = 0; i < scene->mMeshes[0]->mNumFaces; ++i) for (unsigned int i = 0; i < scene->mMeshes[0]->mNumFaces; ++i) {
{ EXPECT_EQ(scene->mMeshes[0]->mFaces[i].mNumIndices, 2u);
EXPECT_EQ(scene->mMeshes[0]->mFaces[i].mNumIndices, 2); EXPECT_EQ(scene->mMeshes[0]->mFaces[i].mIndices[0], i*2u);
EXPECT_EQ(scene->mMeshes[0]->mFaces[i].mIndices[0], i*2); EXPECT_EQ(scene->mMeshes[0]->mFaces[i].mIndices[1], i*2u + 1u);
EXPECT_EQ(scene->mMeshes[0]->mFaces[i].mIndices[1], i*2 + 1);
} }
} }
@ -151,15 +157,14 @@ TEST_F(utglTF2ImportExport, importglTF2PrimitiveModeLinesLoopWithoutIndices) {
//Lines loop without indices //Lines loop without indices
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/glTF-Asset-Generator/Mesh_PrimitiveMode/Mesh_PrimitiveMode_02.gltf", aiProcess_ValidateDataStructure); const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/glTF-Asset-Generator/Mesh_PrimitiveMode/Mesh_PrimitiveMode_02.gltf", aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene); EXPECT_NE(nullptr, scene);
EXPECT_EQ(scene->mMeshes[0]->mNumVertices, 4); EXPECT_EQ(scene->mMeshes[0]->mNumVertices, 4u);
std::array<int, 5> l1 = {{ 0, 1, 2, 3, 0 }}; std::array<unsigned int, 5> l1 = {{ 0u, 1u, 2u, 3u, 0u }};
EXPECT_EQ(scene->mMeshes[0]->mFaces[0].mNumIndices, 2); EXPECT_EQ(scene->mMeshes[0]->mFaces[0].mNumIndices, 2u);
for (unsigned int i = 0; i < scene->mMeshes[0]->mNumFaces; ++i) for (unsigned int i = 0; i < scene->mMeshes[0]->mNumFaces; ++i) {
{ EXPECT_EQ(scene->mMeshes[0]->mFaces[i].mNumIndices, 2u);
EXPECT_EQ(scene->mMeshes[0]->mFaces[i].mNumIndices, 2);
EXPECT_EQ(scene->mMeshes[0]->mFaces[i].mIndices[0], l1[i]); EXPECT_EQ(scene->mMeshes[0]->mFaces[i].mIndices[0], l1[i]);
EXPECT_EQ(scene->mMeshes[0]->mFaces[i].mIndices[1], l1[i + 1]); EXPECT_EQ(scene->mMeshes[0]->mFaces[i].mIndices[1], l1[i + 1u]);
} }
} }
@ -168,14 +173,13 @@ TEST_F(utglTF2ImportExport, importglTF2PrimitiveModeLinesStripWithoutIndices) {
//Lines strip without indices //Lines strip without indices
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/glTF-Asset-Generator/Mesh_PrimitiveMode/Mesh_PrimitiveMode_03.gltf", aiProcess_ValidateDataStructure); const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/glTF-Asset-Generator/Mesh_PrimitiveMode/Mesh_PrimitiveMode_03.gltf", aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene); EXPECT_NE(nullptr, scene);
EXPECT_EQ(scene->mMeshes[0]->mNumVertices, 5); EXPECT_EQ(scene->mMeshes[0]->mNumVertices, 5u);
EXPECT_EQ(scene->mMeshes[0]->mFaces[0].mNumIndices, 2); EXPECT_EQ(scene->mMeshes[0]->mFaces[0].mNumIndices, 2u);
for (unsigned int i = 0; i < scene->mMeshes[0]->mNumFaces; ++i) for (unsigned int i = 0; i < scene->mMeshes[0]->mNumFaces; ++i) {
{ EXPECT_EQ(scene->mMeshes[0]->mFaces[i].mNumIndices, 2u);
EXPECT_EQ(scene->mMeshes[0]->mFaces[i].mNumIndices, 2);
EXPECT_EQ(scene->mMeshes[0]->mFaces[i].mIndices[0], i); EXPECT_EQ(scene->mMeshes[0]->mFaces[i].mIndices[0], i);
EXPECT_EQ(scene->mMeshes[0]->mFaces[i].mIndices[1], i + 1); EXPECT_EQ(scene->mMeshes[0]->mFaces[i].mIndices[1], i + 1u);
} }
} }
@ -184,19 +188,17 @@ TEST_F(utglTF2ImportExport, importglTF2PrimitiveModeTrianglesStripWithoutIndices
//Triangles strip without indices //Triangles strip without indices
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/glTF-Asset-Generator/Mesh_PrimitiveMode/Mesh_PrimitiveMode_04.gltf", aiProcess_ValidateDataStructure); const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/glTF-Asset-Generator/Mesh_PrimitiveMode/Mesh_PrimitiveMode_04.gltf", aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene); EXPECT_NE(nullptr, scene);
EXPECT_EQ(scene->mMeshes[0]->mNumFaces, 2); EXPECT_EQ(scene->mMeshes[0]->mNumFaces, 2u);
EXPECT_EQ(scene->mMeshes[0]->mNumVertices, 4); EXPECT_EQ(scene->mMeshes[0]->mNumVertices, 4u);
std::array<int, 3> f1 = {{ 0, 1, 2 }}; std::array<unsigned int, 3> f1 = {{ 0u, 1u, 2u }};
EXPECT_EQ(scene->mMeshes[0]->mFaces[0].mNumIndices, 3); EXPECT_EQ(scene->mMeshes[0]->mFaces[0].mNumIndices, 3u);
for (int i = 0; i < 3; ++i) for (unsigned int i = 0; i < 3; ++i) {
{
EXPECT_EQ(scene->mMeshes[0]->mFaces[0].mIndices[i], f1[i]); EXPECT_EQ(scene->mMeshes[0]->mFaces[0].mIndices[i], f1[i]);
} }
std::array<int, 3> f2 = {{ 2, 1, 3 }}; std::array<unsigned int, 3> f2 = {{ 2u, 1u, 3u }};
EXPECT_EQ(scene->mMeshes[0]->mFaces[1].mNumIndices, 3); EXPECT_EQ(scene->mMeshes[0]->mFaces[1].mNumIndices, 3u);
for (int i = 0; i < 3; ++i) for (size_t i = 0; i < 3; ++i) {
{
EXPECT_EQ(scene->mMeshes[0]->mFaces[1].mIndices[i], f2[i]); EXPECT_EQ(scene->mMeshes[0]->mFaces[1].mIndices[i], f2[i]);
} }
} }
@ -206,19 +208,17 @@ TEST_F(utglTF2ImportExport, importglTF2PrimitiveModeTrianglesFanWithoutIndices)
//Triangles fan without indices //Triangles fan without indices
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/glTF-Asset-Generator/Mesh_PrimitiveMode/Mesh_PrimitiveMode_05.gltf", aiProcess_ValidateDataStructure); const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/glTF-Asset-Generator/Mesh_PrimitiveMode/Mesh_PrimitiveMode_05.gltf", aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene); EXPECT_NE(nullptr, scene);
EXPECT_EQ(scene->mMeshes[0]->mNumFaces, 2); EXPECT_EQ(scene->mMeshes[0]->mNumFaces, 2u);
EXPECT_EQ(scene->mMeshes[0]->mNumVertices, 4); EXPECT_EQ(scene->mMeshes[0]->mNumVertices, 4u);
std::array<int, 3> f1 = {{ 0, 1, 2 }}; std::array<unsigned int, 3> f1 = {{ 0u, 1u, 2u }};
EXPECT_EQ(scene->mMeshes[0]->mFaces[0].mNumIndices, 3); EXPECT_EQ(scene->mMeshes[0]->mFaces[0].mNumIndices, 3u);
for (int i = 0; i < 3; ++i) for (size_t i = 0; i < 3; ++i) {
{
EXPECT_EQ(scene->mMeshes[0]->mFaces[0].mIndices[i], f1[i]); EXPECT_EQ(scene->mMeshes[0]->mFaces[0].mIndices[i], f1[i]);
} }
std::array<int, 3> f2 = {{ 0, 2, 3 }}; std::array<unsigned int, 3> f2 = {{ 0u, 2u, 3u }};
EXPECT_EQ(scene->mMeshes[0]->mFaces[1].mNumIndices, 3); EXPECT_EQ(scene->mMeshes[0]->mFaces[1].mNumIndices, 3u);
for (int i = 0; i < 3; ++i) for (size_t i = 0; i < 3; ++i) {
{
EXPECT_EQ(scene->mMeshes[0]->mFaces[1].mIndices[i], f2[i]); EXPECT_EQ(scene->mMeshes[0]->mFaces[1].mIndices[i], f2[i]);
} }
} }
@ -228,19 +228,17 @@ TEST_F(utglTF2ImportExport, importglTF2PrimitiveModeTrianglesWithoutIndices) {
//Triangles without indices //Triangles without indices
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/glTF-Asset-Generator/Mesh_PrimitiveMode/Mesh_PrimitiveMode_06.gltf", aiProcess_ValidateDataStructure); const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/glTF-Asset-Generator/Mesh_PrimitiveMode/Mesh_PrimitiveMode_06.gltf", aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene); EXPECT_NE(nullptr, scene);
EXPECT_EQ(scene->mMeshes[0]->mNumFaces, 2); EXPECT_EQ(scene->mMeshes[0]->mNumFaces, 2u);
EXPECT_EQ(scene->mMeshes[0]->mNumVertices, 6); EXPECT_EQ(scene->mMeshes[0]->mNumVertices, 6u);
std::array<int, 3> f1 = {{ 0, 1, 2 }}; std::array<unsigned int, 3> f1 = {{ 0u, 1u, 2u }};
EXPECT_EQ(scene->mMeshes[0]->mFaces[0].mNumIndices, 3); EXPECT_EQ(scene->mMeshes[0]->mFaces[0].mNumIndices, 3u);
for (int i = 0; i < 3; ++i) for (size_t i = 0; i < 3; ++i) {
{
EXPECT_EQ(scene->mMeshes[0]->mFaces[0].mIndices[i], f1[i]); EXPECT_EQ(scene->mMeshes[0]->mFaces[0].mIndices[i], f1[i]);
} }
std::array<int, 3> f2 = {{ 3, 4, 5 }}; std::array<unsigned int, 3> f2 = {{ 3u, 4u, 5u }};
EXPECT_EQ(scene->mMeshes[0]->mFaces[1].mNumIndices, 3); EXPECT_EQ(scene->mMeshes[0]->mFaces[1].mNumIndices, 3u);
for (int i = 0; i < 3; ++i) for (size_t i = 0; i < 3; ++i) {
{
EXPECT_EQ(scene->mMeshes[0]->mFaces[1].mIndices[i], f2[i]); EXPECT_EQ(scene->mMeshes[0]->mFaces[1].mIndices[i], f2[i]);
} }
} }
@ -250,10 +248,9 @@ TEST_F(utglTF2ImportExport, importglTF2PrimitiveModePoints) {
//Line loop //Line loop
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/glTF-Asset-Generator/Mesh_PrimitiveMode/Mesh_PrimitiveMode_07.gltf", aiProcess_ValidateDataStructure); const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/glTF-Asset-Generator/Mesh_PrimitiveMode/Mesh_PrimitiveMode_07.gltf", aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene); EXPECT_NE(nullptr, scene);
EXPECT_EQ(scene->mMeshes[0]->mNumVertices, 1024); EXPECT_EQ(scene->mMeshes[0]->mNumVertices, 1024u);
for (unsigned int i = 0; i < scene->mMeshes[0]->mNumFaces; ++i) for (unsigned int i = 0; i < scene->mMeshes[0]->mNumFaces; ++i) {
{ EXPECT_EQ(scene->mMeshes[0]->mFaces[i].mNumIndices, 1u);
EXPECT_EQ(scene->mMeshes[0]->mFaces[i].mNumIndices, 1);
EXPECT_EQ(scene->mMeshes[0]->mFaces[i].mIndices[0], i); EXPECT_EQ(scene->mMeshes[0]->mFaces[i].mIndices[0], i);
} }
} }
@ -263,9 +260,9 @@ TEST_F(utglTF2ImportExport, importglTF2PrimitiveModeLines) {
//Lines //Lines
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/glTF-Asset-Generator/Mesh_PrimitiveMode/Mesh_PrimitiveMode_08.gltf", aiProcess_ValidateDataStructure); const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/glTF-Asset-Generator/Mesh_PrimitiveMode/Mesh_PrimitiveMode_08.gltf", aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene); EXPECT_NE(nullptr, scene);
EXPECT_EQ(scene->mMeshes[0]->mNumVertices, 4); EXPECT_EQ(scene->mMeshes[0]->mNumVertices, 4u);
std::array<int, 5> l1 = {{ 0, 3, 2, 1, 0 }}; std::array<unsigned int, 5> l1 = {{ 0u, 3u, 2u, 1u, 0u }};
EXPECT_EQ(scene->mMeshes[0]->mFaces[0].mNumIndices, 2); EXPECT_EQ(scene->mMeshes[0]->mFaces[0].mNumIndices, 2u);
for (unsigned int i = 0; i < scene->mMeshes[0]->mNumFaces; ++i) for (unsigned int i = 0; i < scene->mMeshes[0]->mNumFaces; ++i)
{ {
EXPECT_EQ(scene->mMeshes[0]->mFaces[i].mIndices[0], l1[i]); EXPECT_EQ(scene->mMeshes[0]->mFaces[i].mIndices[0], l1[i]);
@ -278,9 +275,9 @@ TEST_F(utglTF2ImportExport, importglTF2PrimitiveModeLineLoop) {
//Line loop //Line loop
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/glTF-Asset-Generator/Mesh_PrimitiveMode/Mesh_PrimitiveMode_09.gltf", aiProcess_ValidateDataStructure); const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/glTF-Asset-Generator/Mesh_PrimitiveMode/Mesh_PrimitiveMode_09.gltf", aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene); EXPECT_NE(nullptr, scene);
EXPECT_EQ(scene->mMeshes[0]->mNumVertices, 4); EXPECT_EQ(scene->mMeshes[0]->mNumVertices, 4u);
std::array<int, 5> l1 = {{ 0, 3, 2, 1, 0 }}; std::array<unsigned int, 5> l1 = {{ 0, 3u, 2u, 1u, 0u }};
EXPECT_EQ(scene->mMeshes[0]->mFaces[0].mNumIndices, 2); EXPECT_EQ(scene->mMeshes[0]->mFaces[0].mNumIndices, 2u);
for (unsigned int i = 0; i < scene->mMeshes[0]->mNumFaces; ++i) for (unsigned int i = 0; i < scene->mMeshes[0]->mNumFaces; ++i)
{ {
EXPECT_EQ(scene->mMeshes[0]->mFaces[i].mIndices[0], l1[i]); EXPECT_EQ(scene->mMeshes[0]->mFaces[i].mIndices[0], l1[i]);
@ -293,11 +290,10 @@ TEST_F(utglTF2ImportExport, importglTF2PrimitiveModeLineStrip) {
//Lines Strip //Lines Strip
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/glTF-Asset-Generator/Mesh_PrimitiveMode/Mesh_PrimitiveMode_10.gltf", aiProcess_ValidateDataStructure); const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/glTF-Asset-Generator/Mesh_PrimitiveMode/Mesh_PrimitiveMode_10.gltf", aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene); EXPECT_NE(nullptr, scene);
EXPECT_EQ(scene->mMeshes[0]->mNumVertices, 4); EXPECT_EQ(scene->mMeshes[0]->mNumVertices, 4u);
std::array<int, 5> l1 = {{ 0, 3, 2, 1, 0 }}; std::array<unsigned int, 5> l1 = {{ 0u, 3u, 2u, 1u, 0u }};
EXPECT_EQ(scene->mMeshes[0]->mFaces[0].mNumIndices, 2); EXPECT_EQ(scene->mMeshes[0]->mFaces[0].mNumIndices, 2u);
for (unsigned int i = 0; i < scene->mMeshes[0]->mNumFaces; ++i) for (unsigned int i = 0; i < scene->mMeshes[0]->mNumFaces; ++i) {
{
EXPECT_EQ(scene->mMeshes[0]->mFaces[i].mIndices[0], l1[i]); EXPECT_EQ(scene->mMeshes[0]->mFaces[i].mIndices[0], l1[i]);
EXPECT_EQ(scene->mMeshes[0]->mFaces[i].mIndices[1], l1[i + 1]); EXPECT_EQ(scene->mMeshes[0]->mFaces[i].mIndices[1], l1[i + 1]);
} }
@ -308,19 +304,17 @@ TEST_F(utglTF2ImportExport, importglTF2PrimitiveModeTrianglesStrip) {
//Triangles strip //Triangles strip
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/glTF-Asset-Generator/Mesh_PrimitiveMode/Mesh_PrimitiveMode_11.gltf", aiProcess_ValidateDataStructure); const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/glTF-Asset-Generator/Mesh_PrimitiveMode/Mesh_PrimitiveMode_11.gltf", aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene); EXPECT_NE(nullptr, scene);
EXPECT_EQ(scene->mMeshes[0]->mNumFaces, 2); EXPECT_EQ(scene->mMeshes[0]->mNumFaces, 2u);
EXPECT_EQ(scene->mMeshes[0]->mNumVertices, 4); EXPECT_EQ(scene->mMeshes[0]->mNumVertices, 4u);
std::array<int, 3> f1 = {{ 0, 3, 1 }}; std::array<unsigned int, 3> f1 = {{ 0u, 3u, 1u }};
EXPECT_EQ(scene->mMeshes[0]->mFaces[0].mNumIndices, 3); EXPECT_EQ(scene->mMeshes[0]->mFaces[0].mNumIndices, 3u);
for (int i = 0; i < 3; ++i) for (size_t i = 0; i < 3; ++i) {
{
EXPECT_EQ(scene->mMeshes[0]->mFaces[0].mIndices[i], f1[i]); EXPECT_EQ(scene->mMeshes[0]->mFaces[0].mIndices[i], f1[i]);
} }
std::array<int, 3> f2 = {{ 1, 3, 2 }}; std::array<unsigned int, 3> f2 = {{ 1u, 3u, 2u }};
EXPECT_EQ(scene->mMeshes[0]->mFaces[1].mNumIndices, 3); EXPECT_EQ(scene->mMeshes[0]->mFaces[1].mNumIndices, 3u);
for (int i = 0; i < 3; ++i) for (size_t i = 0; i < 3; ++i) {
{
EXPECT_EQ(scene->mMeshes[0]->mFaces[1].mIndices[i], f2[i]); EXPECT_EQ(scene->mMeshes[0]->mFaces[1].mIndices[i], f2[i]);
} }
} }
@ -330,19 +324,17 @@ TEST_F(utglTF2ImportExport, importglTF2PrimitiveModeTrianglesFan) {
//Triangles fan //Triangles fan
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/glTF-Asset-Generator/Mesh_PrimitiveMode/Mesh_PrimitiveMode_12.gltf", aiProcess_ValidateDataStructure); const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/glTF-Asset-Generator/Mesh_PrimitiveMode/Mesh_PrimitiveMode_12.gltf", aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene); EXPECT_NE(nullptr, scene);
EXPECT_EQ(scene->mMeshes[0]->mNumVertices, 4); EXPECT_EQ(scene->mMeshes[0]->mNumVertices, 4u);
EXPECT_EQ(scene->mMeshes[0]->mNumFaces, 2); EXPECT_EQ(scene->mMeshes[0]->mNumFaces, 2u);
std::array<int, 3> f1 = {{ 0, 3, 2 }}; std::array<unsigned int, 3> f1 = {{ 0u, 3u, 2u }};
EXPECT_EQ(scene->mMeshes[0]->mFaces[0].mNumIndices, 3); EXPECT_EQ(scene->mMeshes[0]->mFaces[0].mNumIndices, 3u );
for (int i = 0; i < 3; ++i) for (size_t i = 0; i < 3; ++i) {
{
EXPECT_EQ(scene->mMeshes[0]->mFaces[0].mIndices[i], f1[i]); EXPECT_EQ(scene->mMeshes[0]->mFaces[0].mIndices[i], f1[i]);
} }
std::array<int, 3> f2 = {{ 0, 2, 1 }}; std::array<unsigned int, 3> f2 = {{ 0u, 2u, 1u }};
EXPECT_EQ(scene->mMeshes[0]->mFaces[1].mNumIndices, 3); EXPECT_EQ(scene->mMeshes[0]->mFaces[1].mNumIndices, 3u );
for (int i = 0; i < 3; ++i) for (size_t i = 0; i < 3; ++i) {
{
EXPECT_EQ(scene->mMeshes[0]->mFaces[1].mIndices[i], f2[i]); EXPECT_EQ(scene->mMeshes[0]->mFaces[1].mIndices[i], f2[i]);
} }
} }
@ -378,7 +370,8 @@ TEST_F(utglTF2ImportExport, importglTF2FromMemory) {
TEST_F( utglTF2ImportExport, bug_import_simple_skin ) { TEST_F( utglTF2ImportExport, bug_import_simple_skin ) {
Assimp::Importer importer; Assimp::Importer importer;
const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/glTF2/simple_skin/simple_skin.gltf", aiProcess_ValidateDataStructure ); const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/glTF2/simple_skin/simple_skin.gltf",
aiProcess_ValidateDataStructure );
EXPECT_NE( nullptr, scene ); EXPECT_NE( nullptr, scene );
} }