summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/assimp/code/Q3BSPFileImporter.cpp
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2014-05-26 10:35:32 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-06-04 10:09:11 +0200
commit1cb807d440cc0d434bfd02fd0c699447b788b8ba (patch)
treef28f64fba6ebb30449c3301a75bba2b233b1f34e /src/3rdparty/assimp/code/Q3BSPFileImporter.cpp
parenta45b8308ada361872502a678a12f08cff1760c64 (diff)
Upgrade to Assimp 3.1
https://github.com/assimp/assimp/releases/tag/v3.1 This commit imports assimp 3.1, including CHANGES, CREDITS, LICENSE, README, Readme.md, revision.h and code, contrib, include directories. contrib/zlib was excluded. assimp.pri was also updated. Uses zlib from system or qt instead of contrib/zlib. Task-number: QTBUG-39251 Change-Id: Ia0b446dcd9bc867d65897b9e2b157f6544ccaeac Reviewed-by: Liang Qi <liang.qi@digia.com> Reviewed-by: Sean Harmer <sean.harmer@kdab.com> Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/3rdparty/assimp/code/Q3BSPFileImporter.cpp')
-rw-r--r--src/3rdparty/assimp/code/Q3BSPFileImporter.cpp87
1 files changed, 37 insertions, 50 deletions
diff --git a/src/3rdparty/assimp/code/Q3BSPFileImporter.cpp b/src/3rdparty/assimp/code/Q3BSPFileImporter.cpp
index 44d8d7b11..81a770261 100644
--- a/src/3rdparty/assimp/code/Q3BSPFileImporter.cpp
+++ b/src/3rdparty/assimp/code/Q3BSPFileImporter.cpp
@@ -71,9 +71,14 @@ static const aiImporterDesc desc = {
"pk3"
};
-namespace Assimp
-{
+namespace Assimp {
+static void getSupportedExtensions(std::vector<std::string> &supportedExtensions) {
+ supportedExtensions.push_back( ".jpg" );
+ supportedExtensions.push_back( ".png" );
+ supportedExtensions.push_back( ".tga" );
+}
+
using namespace Q3BSP;
// ------------------------------------------------------------------------------------------------
@@ -86,7 +91,7 @@ static void createKey( int id1, int id2, std::string &rKey )
}
// ------------------------------------------------------------------------------------------------
-// Local function to extract the texture ids from a material keyname.
+// Local function to extract the texture ids from a material key-name.
static void extractIds( const std::string &rKey, int &rId1, int &rId2 )
{
rId1 = -1;
@@ -146,24 +151,16 @@ Q3BSPFileImporter::Q3BSPFileImporter() :
// ------------------------------------------------------------------------------------------------
// Destructor.
-Q3BSPFileImporter::~Q3BSPFileImporter()
-{
- // For lint
+Q3BSPFileImporter::~Q3BSPFileImporter() {
m_pCurrentMesh = NULL;
m_pCurrentFace = NULL;
// Clear face-to-material map
- for ( FaceMap::iterator it = m_MaterialLookupMap.begin(); it != m_MaterialLookupMap.end();
- ++it )
- {
- const std::string matName = (*it).first;
- if ( matName.empty() )
- {
- continue;
+ for ( FaceMap::iterator it = m_MaterialLookupMap.begin(); it != m_MaterialLookupMap.end(); ++it ) {
+ const std::string &matName = it->first;
+ if ( !matName.empty() ) {
+ delete it->second;
}
-
- std::vector<Q3BSP::sQ3BSPFace*> *pCurFaceArray = (*it).second;
- delete pCurFaceArray;
}
m_MaterialLookupMap.clear();
}
@@ -188,9 +185,9 @@ const aiImporterDesc* Q3BSPFileImporter::GetInfo () const
// ------------------------------------------------------------------------------------------------
// Import method.
-void Q3BSPFileImporter::InternReadFile(const std::string &rFile, aiScene* pScene, IOSystem* /*pIOHandler*/)
+void Q3BSPFileImporter::InternReadFile(const std::string &rFile, aiScene* pScene, IOSystem* pIOHandler)
{
- Q3BSPZipArchive Archive( rFile );
+ Q3BSPZipArchive Archive( pIOHandler, rFile );
if ( !Archive.isOpen() )
{
throw DeadlyImportError( "Failed to open file " + rFile + "." );
@@ -566,7 +563,7 @@ size_t Q3BSPFileImporter::countFaces( const std::vector<Q3BSP::sQ3BSPFace*> &rAr
}
// ------------------------------------------------------------------------------------------------
-// Counts the number of triangles in a Q3-facearray.
+// Counts the number of triangles in a Q3-face-array.
size_t Q3BSPFileImporter::countTriangles( const std::vector<Q3BSP::sQ3BSPFace*> &rArray ) const
{
size_t numTriangles = 0;
@@ -617,16 +614,11 @@ void Q3BSPFileImporter::createMaterialMap( const Q3BSP::Q3BSPModel *pModel )
// Returns the next face.
aiFace *Q3BSPFileImporter::getNextFace( aiMesh *pMesh, unsigned int &rFaceIdx )
{
- aiFace *pFace = NULL;
- if ( rFaceIdx < pMesh->mNumFaces )
- {
+ aiFace *pFace( NULL );
+ if ( rFaceIdx < pMesh->mNumFaces ) {
pFace = &pMesh->mFaces[ rFaceIdx ];
rFaceIdx++;
}
- else
- {
- pFace = NULL;
- }
return pFace;
}
@@ -634,33 +626,30 @@ aiFace *Q3BSPFileImporter::getNextFace( aiMesh *pMesh, unsigned int &rFaceIdx )
// ------------------------------------------------------------------------------------------------
// Imports a texture file.
bool Q3BSPFileImporter::importTextureFromArchive( const Q3BSP::Q3BSPModel *pModel,
- Q3BSP::Q3BSPZipArchive *pArchive, aiScene* /*pScene*/,
- aiMaterial *pMatHelper, int textureId )
-{
- std::vector<std::string> supportedExtensions;
- supportedExtensions.push_back( ".jpg" );
- supportedExtensions.push_back( ".png" );
- if ( NULL == pArchive || NULL == pArchive || NULL == pMatHelper )
- {
+ Q3BSP::Q3BSPZipArchive *pArchive, aiScene*,
+ aiMaterial *pMatHelper, int textureId ) {
+ if ( NULL == pArchive || NULL == pArchive || NULL == pMatHelper ) {
return false;
}
- if ( textureId < 0 || textureId >= static_cast<int>( pModel->m_Textures.size() ) )
- {
+ if ( textureId < 0 || textureId >= static_cast<int>( pModel->m_Textures.size() ) ) {
return false;
}
bool res = true;
sQ3BSPTexture *pTexture = pModel->m_Textures[ textureId ];
- if ( NULL == pTexture )
- return false;
-
+ if ( !pTexture ) {
+ return false;
+ }
+
+ std::vector<std::string> supportedExtensions;
+ supportedExtensions.push_back( ".jpg" );
+ supportedExtensions.push_back( ".png" );
+ supportedExtensions.push_back( ".tga" );
std::string textureName, ext;
- if ( expandFile( pArchive, pTexture->strName, supportedExtensions, textureName, ext ) )
- {
+ if ( expandFile( pArchive, pTexture->strName, supportedExtensions, textureName, ext ) ) {
IOStream *pTextureStream = pArchive->Open( textureName.c_str() );
- if ( NULL != pTextureStream )
- {
+ if ( !pTextureStream ) {
size_t texSize = pTextureStream->FileSize();
aiTexture *pTexture = new aiTexture;
pTexture->mHeight = 0;
@@ -670,10 +659,10 @@ bool Q3BSPFileImporter::importTextureFromArchive( const Q3BSP::Q3BSPModel *pMode
(void)readSize;
ai_assert( readSize == pTexture->mWidth );
pTexture->pcData = reinterpret_cast<aiTexel*>( pData );
- pTexture->achFormatHint[ 0 ] = ext[ 0 ];
- pTexture->achFormatHint[ 1 ] = ext[ 1 ];
- pTexture->achFormatHint[ 2 ] = ext[ 2 ];
- pTexture->achFormatHint[ 2 ] = '\0';
+ pTexture->achFormatHint[ 0 ] = ext[ 1 ];
+ pTexture->achFormatHint[ 1 ] = ext[ 2 ];
+ pTexture->achFormatHint[ 2 ] = ext[ 3 ];
+ pTexture->achFormatHint[ 3 ] = '\0';
res = true;
aiString name;
@@ -684,9 +673,7 @@ bool Q3BSPFileImporter::importTextureFromArchive( const Q3BSP::Q3BSPModel *pMode
pMatHelper->AddProperty( &name, AI_MATKEY_TEXTURE_DIFFUSE( 0 ) );
mTextures.push_back( pTexture );
- }
- else
- {
+ } else {
// If it doesn't exist in the archive, it is probably just a reference to an external file.
// We'll leave it up to the user to figure out which extension the file has.
aiString name;