|
@@ -93,7 +93,7 @@ static void extractIds( const std::string &rKey, int &rId1, int &rId2 )
|
|
|
}
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
-// Local helper fuction to normalize filenames.
|
|
|
+// Local helper function to normalize filenames.
|
|
|
static void normalizePathName( const std::string &rPath, std::string &rNormalizedPath )
|
|
|
{
|
|
|
rNormalizedPath = "";
|
|
@@ -649,9 +649,8 @@ bool Q3BSPFileImporter::importTextureFromArchive( const Q3BSP::Q3BSPModel *pMode
|
|
|
if ( NULL == pTexture )
|
|
|
return false;
|
|
|
|
|
|
- std::string textureName = pTexture->strName;
|
|
|
- textureName += ".jpg";
|
|
|
- if ( pArchive->Exists( textureName.c_str() ) )
|
|
|
+ std::string textureName, ext;
|
|
|
+ if ( expandFile( pArchive, pTexture->strName, supportedExtensions, textureName, ext ) )
|
|
|
{
|
|
|
IOStream *pTextureStream = pArchive->Open( textureName.c_str() );
|
|
|
if ( NULL != pTextureStream )
|
|
@@ -679,6 +678,15 @@ bool Q3BSPFileImporter::importTextureFromArchive( const Q3BSP::Q3BSPModel *pMode
|
|
|
pMatHelper->AddProperty( &name, AI_MATKEY_TEXTURE_DIFFUSE( 0 ) );
|
|
|
mTextures.push_back( pTexture );
|
|
|
}
|
|
|
+ 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;
|
|
|
+ strncpy( name.data, pTexture->strName, sizeof name.data );
|
|
|
+ name.length = strlen( name.data );
|
|
|
+ pMatHelper->AddProperty( &name, AI_MATKEY_TEXTURE_DIFFUSE( 0 ) );
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return res;
|
|
@@ -706,19 +714,21 @@ bool Q3BSPFileImporter::importLightmap( const Q3BSP::Q3BSPModel *pModel, aiScene
|
|
|
}
|
|
|
|
|
|
aiTexture *pTexture = new aiTexture;
|
|
|
- pTexture->mHeight = 0;
|
|
|
- pTexture->mWidth = CE_BSP_LIGHTMAPWIDTH * CE_BSP_LIGHTMAPHEIGHT;
|
|
|
-
|
|
|
- unsigned char *pData = new unsigned char[ pTexture->mWidth ];
|
|
|
- pTexture->pcData = reinterpret_cast<aiTexel*>( pData );
|
|
|
|
|
|
- pTexture->achFormatHint[ 0 ] = 'b';
|
|
|
- pTexture->achFormatHint[ 1 ] = 'm';
|
|
|
- pTexture->achFormatHint[ 2 ] = 'p';
|
|
|
- pTexture->achFormatHint[ 3 ] = '\0';
|
|
|
-
|
|
|
- memcpy( pTexture->pcData, pLightMap->bLMapData, pTexture->mWidth );
|
|
|
+ pTexture->mWidth = CE_BSP_LIGHTMAPWIDTH;
|
|
|
+ pTexture->mHeight = CE_BSP_LIGHTMAPHEIGHT;
|
|
|
+ pTexture->pcData = new aiTexel[CE_BSP_LIGHTMAPWIDTH * CE_BSP_LIGHTMAPHEIGHT];
|
|
|
|
|
|
+ ::memcpy( pTexture->pcData, pLightMap->bLMapData, pTexture->mWidth );
|
|
|
+ size_t p = 0;
|
|
|
+ for ( size_t i = 0; i < CE_BSP_LIGHTMAPWIDTH * CE_BSP_LIGHTMAPHEIGHT; ++i )
|
|
|
+ {
|
|
|
+ pTexture->pcData[ i ].r = pLightMap->bLMapData[ p++ ];
|
|
|
+ pTexture->pcData[ i ].g = pLightMap->bLMapData[ p++ ];
|
|
|
+ pTexture->pcData[ i ].b = pLightMap->bLMapData[ p++ ];
|
|
|
+ pTexture->pcData[ i ].a = 0xFF;
|
|
|
+ }
|
|
|
+
|
|
|
aiString name;
|
|
|
name.data[ 0 ] = '*';
|
|
|
name.length = 1 + ASSIMP_itoa10( name.data + 1, MAXLEN-1, mTextures.size() );
|
|
@@ -729,6 +739,38 @@ bool Q3BSPFileImporter::importLightmap( const Q3BSP::Q3BSPModel *pModel, aiScene
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+// ------------------------------------------------------------------------------------------------
|
|
|
+// Will search for a supported extension.
|
|
|
+bool Q3BSPFileImporter::expandFile( Q3BSP::Q3BSPZipArchive *pArchive, const std::string &rFilename,
|
|
|
+ const std::vector<std::string> &rExtList, std::string &rFile,
|
|
|
+ std::string &rExt )
|
|
|
+{
|
|
|
+ ai_assert( NULL != pArchive );
|
|
|
+ ai_assert( !rFilename.empty() );
|
|
|
+
|
|
|
+ if ( rExtList.empty() )
|
|
|
+ {
|
|
|
+ rFile = rFilename;
|
|
|
+ rExt = "";
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ bool found = false;
|
|
|
+ for ( std::vector<std::string>::const_iterator it = rExtList.begin(); it != rExtList.end(); ++it )
|
|
|
+ {
|
|
|
+ const std::string textureName = rFilename + *it;
|
|
|
+ if ( pArchive->Exists( textureName.c_str() ) )
|
|
|
+ {
|
|
|
+ rExt = *it;
|
|
|
+ rFile = textureName;
|
|
|
+ found = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return found;
|
|
|
+}
|
|
|
+
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
|
} // Namespace Assimp
|