- UPDATE : VArious Bugfixes from rdb in the PK3BSP-Loader: fix lightmap copying, fix a typo, offer a way to get texture names from external, if they a re not part of the archive.

- UPDATE : Make the loading of several formats for textures more generic, thanks to rdb for the idea.

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@940 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/1/head
kimmi 2011-04-03 17:22:36 +00:00
parent 85cd9be46d
commit 1c37910f5f
3 changed files with 68 additions and 17 deletions

View File

@ -108,4 +108,7 @@ Contributes a Android-specific build issue: log the hardware architecture for AR
Contributes a obj-fileparser fix: missing tokens in the obj-token list.
- Roman Kharitonov
Contributes a fix for the configure script environment.
Contributes a fix for the configure script environment.
-rdb
Contributes a bundle of fixes and improvments for the bsp-importer.

View File

@ -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->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;
}
pTexture->achFormatHint[ 0 ] = 'b';
pTexture->achFormatHint[ 1 ] = 'm';
pTexture->achFormatHint[ 2 ] = 'p';
pTexture->achFormatHint[ 3 ] = '\0';
memcpy( pTexture->pcData, pLightMap->bLMapData, pTexture->mWidth );
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

View File

@ -54,9 +54,10 @@ struct Q3BSPModel;
struct sQ3BSPFace;
}
// ------------------------------------------------------------------------------------------------
/** Loader to import BSP-levels from a PK3 archive or from a unpacked BSP-level.
*/
// ------------------------------------------------------------------------------------------------
class Q3BSPFileImporter : BaseImporter
{
friend class Importer;
@ -97,6 +98,8 @@ private:
bool importTextureFromArchive( const Q3BSP::Q3BSPModel *pModel, Q3BSP::Q3BSPZipArchive *pArchive, aiScene* pScene,
Assimp::MaterialHelper *pMatHelper, int textureId );
bool importLightmap( const Q3BSP::Q3BSPModel *pModel, aiScene* pScene, Assimp::MaterialHelper *pMatHelper, int lightmapId );
bool expandFile( Q3BSP::Q3BSPZipArchive *pArchive, const std::string &rFilename, const std::vector<std::string> &rExtList,
std::string &rFile, std::string &rExt );
private:
aiMesh *m_pCurrentMesh;
@ -105,6 +108,9 @@ private:
std::vector<aiTexture*> mTextures;
};
// ------------------------------------------------------------------------------------------------
} // Namespace Assimp
#endif // ASSIMP_Q3BSPFILEIMPORTER_H_INC