- 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-9d2fd5bffc1fpull/1/head
parent
85cd9be46d
commit
1c37910f5f
3
CREDITS
3
CREDITS
|
@ -109,3 +109,6 @@ Contributes a obj-fileparser fix: missing tokens in the obj-token list.
|
||||||
|
|
||||||
- Roman Kharitonov
|
- 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.
|
||||||
|
|
|
@ -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 )
|
static void normalizePathName( const std::string &rPath, std::string &rNormalizedPath )
|
||||||
{
|
{
|
||||||
rNormalizedPath = "";
|
rNormalizedPath = "";
|
||||||
|
@ -649,9 +649,8 @@ bool Q3BSPFileImporter::importTextureFromArchive( const Q3BSP::Q3BSPModel *pMode
|
||||||
if ( NULL == pTexture )
|
if ( NULL == pTexture )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
std::string textureName = pTexture->strName;
|
std::string textureName, ext;
|
||||||
textureName += ".jpg";
|
if ( expandFile( pArchive, pTexture->strName, supportedExtensions, textureName, ext ) )
|
||||||
if ( pArchive->Exists( textureName.c_str() ) )
|
|
||||||
{
|
{
|
||||||
IOStream *pTextureStream = pArchive->Open( textureName.c_str() );
|
IOStream *pTextureStream = pArchive->Open( textureName.c_str() );
|
||||||
if ( NULL != pTextureStream )
|
if ( NULL != pTextureStream )
|
||||||
|
@ -679,6 +678,15 @@ bool Q3BSPFileImporter::importTextureFromArchive( const Q3BSP::Q3BSPModel *pMode
|
||||||
pMatHelper->AddProperty( &name, AI_MATKEY_TEXTURE_DIFFUSE( 0 ) );
|
pMatHelper->AddProperty( &name, AI_MATKEY_TEXTURE_DIFFUSE( 0 ) );
|
||||||
mTextures.push_back( pTexture );
|
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;
|
return res;
|
||||||
|
@ -706,18 +714,20 @@ bool Q3BSPFileImporter::importLightmap( const Q3BSP::Q3BSPModel *pModel, aiScene
|
||||||
}
|
}
|
||||||
|
|
||||||
aiTexture *pTexture = new aiTexture;
|
aiTexture *pTexture = new aiTexture;
|
||||||
pTexture->mHeight = 0;
|
|
||||||
pTexture->mWidth = CE_BSP_LIGHTMAPWIDTH * CE_BSP_LIGHTMAPHEIGHT;
|
|
||||||
|
|
||||||
unsigned char *pData = new unsigned char[ pTexture->mWidth ];
|
pTexture->mWidth = CE_BSP_LIGHTMAPWIDTH;
|
||||||
pTexture->pcData = reinterpret_cast<aiTexel*>( pData );
|
pTexture->mHeight = CE_BSP_LIGHTMAPHEIGHT;
|
||||||
|
pTexture->pcData = new aiTexel[CE_BSP_LIGHTMAPWIDTH * CE_BSP_LIGHTMAPHEIGHT];
|
||||||
|
|
||||||
pTexture->achFormatHint[ 0 ] = 'b';
|
::memcpy( pTexture->pcData, pLightMap->bLMapData, pTexture->mWidth );
|
||||||
pTexture->achFormatHint[ 1 ] = 'm';
|
size_t p = 0;
|
||||||
pTexture->achFormatHint[ 2 ] = 'p';
|
for ( size_t i = 0; i < CE_BSP_LIGHTMAPWIDTH * CE_BSP_LIGHTMAPHEIGHT; ++i )
|
||||||
pTexture->achFormatHint[ 3 ] = '\0';
|
{
|
||||||
|
pTexture->pcData[ i ].r = pLightMap->bLMapData[ p++ ];
|
||||||
memcpy( pTexture->pcData, pLightMap->bLMapData, pTexture->mWidth );
|
pTexture->pcData[ i ].g = pLightMap->bLMapData[ p++ ];
|
||||||
|
pTexture->pcData[ i ].b = pLightMap->bLMapData[ p++ ];
|
||||||
|
pTexture->pcData[ i ].a = 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
aiString name;
|
aiString name;
|
||||||
name.data[ 0 ] = '*';
|
name.data[ 0 ] = '*';
|
||||||
|
@ -729,6 +739,38 @@ bool Q3BSPFileImporter::importLightmap( const Q3BSP::Q3BSPModel *pModel, aiScene
|
||||||
return true;
|
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
|
} // Namespace Assimp
|
||||||
|
|
|
@ -54,9 +54,10 @@ struct Q3BSPModel;
|
||||||
struct sQ3BSPFace;
|
struct sQ3BSPFace;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
/** Loader to import BSP-levels from a PK3 archive or from a unpacked BSP-level.
|
/** Loader to import BSP-levels from a PK3 archive or from a unpacked BSP-level.
|
||||||
*/
|
*/
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
class Q3BSPFileImporter : BaseImporter
|
class Q3BSPFileImporter : BaseImporter
|
||||||
{
|
{
|
||||||
friend class Importer;
|
friend class Importer;
|
||||||
|
@ -97,6 +98,8 @@ private:
|
||||||
bool importTextureFromArchive( const Q3BSP::Q3BSPModel *pModel, Q3BSP::Q3BSPZipArchive *pArchive, aiScene* pScene,
|
bool importTextureFromArchive( const Q3BSP::Q3BSPModel *pModel, Q3BSP::Q3BSPZipArchive *pArchive, aiScene* pScene,
|
||||||
Assimp::MaterialHelper *pMatHelper, int textureId );
|
Assimp::MaterialHelper *pMatHelper, int textureId );
|
||||||
bool importLightmap( const Q3BSP::Q3BSPModel *pModel, aiScene* pScene, Assimp::MaterialHelper *pMatHelper, int lightmapId );
|
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:
|
private:
|
||||||
aiMesh *m_pCurrentMesh;
|
aiMesh *m_pCurrentMesh;
|
||||||
|
@ -105,6 +108,9 @@ private:
|
||||||
std::vector<aiTexture*> mTextures;
|
std::vector<aiTexture*> mTextures;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
} // Namespace Assimp
|
} // Namespace Assimp
|
||||||
|
|
||||||
|
|
||||||
#endif // ASSIMP_Q3BSPFILEIMPORTER_H_INC
|
#endif // ASSIMP_Q3BSPFILEIMPORTER_H_INC
|
||||||
|
|
Loading…
Reference in New Issue