- UPDATE : Use of correct indices in Q3BSP-loader
- UPDATE : Add enum for primitive-description in Q3BSP-loader. git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@790 67173fc5-114c-0410-ac8e-9d2fd5bffc1fpull/1/head
parent
4ad0d569f3
commit
8fef884dbc
|
@ -332,7 +332,7 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel,
|
||||||
// Copy all index arrays
|
// Copy all index arrays
|
||||||
for ( size_t vertexIndex = 0; vertexIndex < pSourceFace->m_pVertices->size(); vertexIndex++ )
|
for ( size_t vertexIndex = 0; vertexIndex < pSourceFace->m_pVertices->size(); vertexIndex++ )
|
||||||
{
|
{
|
||||||
unsigned int vertex = pSourceFace->m_pVertices->at( vertexIndex );
|
const unsigned int vertex = pSourceFace->m_pVertices->at( vertexIndex );
|
||||||
ai_assert( vertex < pModel->m_Vertices.size() );
|
ai_assert( vertex < pModel->m_Vertices.size() );
|
||||||
pMesh->mVertices[ newIndex ] = pModel->m_Vertices[ vertex ];
|
pMesh->mVertices[ newIndex ] = pModel->m_Vertices[ vertex ];
|
||||||
|
|
||||||
|
@ -405,7 +405,7 @@ void ObjFileImporter::createMaterials(const ObjFile::Model* pModel, aiScene* pSc
|
||||||
pScene->mMaterials = new aiMaterial*[ numMaterials ];
|
pScene->mMaterials = new aiMaterial*[ numMaterials ];
|
||||||
for ( unsigned int matIndex = 0; matIndex < numMaterials; matIndex++ )
|
for ( unsigned int matIndex = 0; matIndex < numMaterials; matIndex++ )
|
||||||
{
|
{
|
||||||
Assimp::MaterialHelper* mat = new Assimp::MaterialHelper();
|
Assimp::MaterialHelper* mat = new Assimp::MaterialHelper;
|
||||||
|
|
||||||
// Store material name
|
// Store material name
|
||||||
std::map<std::string, ObjFile::Material*>::const_iterator it;
|
std::map<std::string, ObjFile::Material*>::const_iterator it;
|
||||||
|
|
|
@ -50,6 +50,14 @@ namespace Q3BSP
|
||||||
static const unsigned int CE_BSP_LIGHTMAPSIZE = 128*128*3; ///< = 128( width ) * 128 ( height ) * 3 ( channels / RGB ).
|
static const unsigned int CE_BSP_LIGHTMAPSIZE = 128*128*3; ///< = 128( width ) * 128 ( height ) * 3 ( channels / RGB ).
|
||||||
static const int VERION_Q3LEVEL = 46; ///< Supported version.
|
static const int VERION_Q3LEVEL = 46; ///< Supported version.
|
||||||
|
|
||||||
|
enum Q3BSPGeoType
|
||||||
|
{
|
||||||
|
Polygon = 1,
|
||||||
|
Patch,
|
||||||
|
Mesh,
|
||||||
|
Billboard
|
||||||
|
};
|
||||||
|
|
||||||
/// Integer vector.
|
/// Integer vector.
|
||||||
struct ceVec3i
|
struct ceVec3i
|
||||||
{
|
{
|
||||||
|
@ -100,9 +108,9 @@ struct sQ3BSPFace
|
||||||
int iType; ///< 1=Polygon, 2=Patch, 3=Mesh, 4=Billboard
|
int iType; ///< 1=Polygon, 2=Patch, 3=Mesh, 4=Billboard
|
||||||
int iVertexIndex; ///< Start index of polygon
|
int iVertexIndex; ///< Start index of polygon
|
||||||
int iNumOfVerts; ///< Number of vertices
|
int iNumOfVerts; ///< Number of vertices
|
||||||
int iMeshVertexIndex; ///< Index of first mesh vertex
|
int iFaceVertexIndex; ///< Index of first mesh vertex
|
||||||
int iNumOfMeshVerts; ///< Anzahl der Meshvertices
|
int iNumOfFaceVerts; ///< Anzahl der Meshvertices
|
||||||
int iLightmapID; ///< Index in das Lightmap array
|
int iLightmapID; ///< Index to the lightmap array
|
||||||
int iLMapCorner[ 2 ]; ///< Die Ecke der Lightmap in der Textur
|
int iLMapCorner[ 2 ]; ///< Die Ecke der Lightmap in der Textur
|
||||||
int iLMapSize[ 2 ]; ///< Size of the lightmap stored on the texture
|
int iLMapSize[ 2 ]; ///< Size of the lightmap stored on the texture
|
||||||
vec3f vLMapPos; ///< 3D-Ursprung der Lightmap
|
vec3f vLMapPos; ///< 3D-Ursprung der Lightmap
|
||||||
|
@ -122,8 +130,11 @@ struct sQ3BSPTexture
|
||||||
/// A lightmap of the level, size 128 x 128, RGB components.
|
/// A lightmap of the level, size 128 x 128, RGB components.
|
||||||
struct sQ3BSPLightmap
|
struct sQ3BSPLightmap
|
||||||
{
|
{
|
||||||
unsigned char bLMapData[CE_BSP_LIGHTMAPSIZE];
|
unsigned char bLMapData[ CE_BSP_LIGHTMAPSIZE ];
|
||||||
sQ3BSPLightmap() { memset(bLMapData, 0, CE_BSP_LIGHTMAPSIZE); }
|
sQ3BSPLightmap()
|
||||||
|
{
|
||||||
|
memset(bLMapData, 0, CE_BSP_LIGHTMAPSIZE );
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sRenderVertex
|
struct sRenderVertex
|
||||||
|
|
|
@ -62,6 +62,8 @@ namespace Assimp
|
||||||
|
|
||||||
using namespace Q3BSP;
|
using namespace Q3BSP;
|
||||||
|
|
||||||
|
static const std::string Q3BSPExtention = "pk3";
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
static void createKey( int id1, int id2, std::string &rKey )
|
static void createKey( int id1, int id2, std::string &rKey )
|
||||||
{
|
{
|
||||||
|
@ -70,15 +72,35 @@ static void createKey( int id1, int id2, std::string &rKey )
|
||||||
rKey = str.str();
|
rKey = str.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
static void extractIds( const std::string &rKey, int &rId1, int &rId2 )
|
||||||
|
{
|
||||||
|
rId1 = -1;
|
||||||
|
rId2 = -1;
|
||||||
|
if ( rKey.empty() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
std::string::size_type pos = rKey.find( "." );
|
||||||
|
if ( std::string::npos == pos )
|
||||||
|
return;
|
||||||
|
|
||||||
|
std::string tmp1 = rKey.substr( 0, pos - 1 );
|
||||||
|
std::string tmp2 = rKey.substr( pos + 1, rKey.size() - pos - 1 );
|
||||||
|
rId1 = atoi( tmp1.c_str() );
|
||||||
|
rId2 = atoi( tmp2.c_str() );
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
Q3BSPFileImporter::Q3BSPFileImporter() :
|
Q3BSPFileImporter::Q3BSPFileImporter() :
|
||||||
m_pCurrentMesh( NULL )
|
m_pCurrentMesh( NULL )
|
||||||
{
|
{
|
||||||
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
Q3BSPFileImporter::~Q3BSPFileImporter()
|
Q3BSPFileImporter::~Q3BSPFileImporter()
|
||||||
{
|
{
|
||||||
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
@ -86,7 +108,7 @@ bool Q3BSPFileImporter::CanRead( const std::string& rFile, IOSystem* pIOHandler,
|
||||||
{
|
{
|
||||||
bool isBSPData = false;
|
bool isBSPData = false;
|
||||||
if ( checkSig )
|
if ( checkSig )
|
||||||
isBSPData = SimpleExtensionCheck( rFile, "pk3" );
|
isBSPData = SimpleExtensionCheck( rFile, Q3BSPExtention.c_str() );
|
||||||
|
|
||||||
return isBSPData;
|
return isBSPData;
|
||||||
}
|
}
|
||||||
|
@ -94,7 +116,7 @@ bool Q3BSPFileImporter::CanRead( const std::string& rFile, IOSystem* pIOHandler,
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void Q3BSPFileImporter::GetExtensionList(std::set<std::string>& extensions)
|
void Q3BSPFileImporter::GetExtensionList(std::set<std::string>& extensions)
|
||||||
{
|
{
|
||||||
extensions.insert( "pk3" );
|
extensions.insert( Q3BSPExtention );
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
@ -183,7 +205,11 @@ void Q3BSPFileImporter::CreateDataFromImport( const Q3BSP::Q3BSPModel *pModel, a
|
||||||
pScene->mRootNode->mName.Set( pModel->m_ModelName );
|
pScene->mRootNode->mName.Set( pModel->m_ModelName );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createMaterialMap( pModel );
|
||||||
|
|
||||||
CreateNodes( pModel, pScene, pScene->mRootNode );
|
CreateNodes( pModel, pScene, pScene->mRootNode );
|
||||||
|
|
||||||
|
createMaterials( pModel, pScene );
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
@ -193,44 +219,17 @@ void Q3BSPFileImporter::CreateNodes( const Q3BSP::Q3BSPModel *pModel, aiScene* p
|
||||||
if ( NULL == pModel )
|
if ( NULL == pModel )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
FaceMap matLookupTable;
|
unsigned int matIdx = 0;
|
||||||
std::string key( "" );
|
|
||||||
std::vector<sQ3BSPFace*> *pCurFaceArray = NULL;
|
|
||||||
FaceMap lookupMap;
|
|
||||||
for ( size_t idx=0; idx < pModel->m_Faces.size(); idx++ )
|
|
||||||
{
|
|
||||||
Q3BSP::sQ3BSPFace *pQ3BSPFace = pModel->m_Faces[ idx ];
|
|
||||||
int texId = pQ3BSPFace->iTextureID;
|
|
||||||
int lightMapId = pQ3BSPFace->iLightmapID;
|
|
||||||
createKey( texId, lightMapId, key );
|
|
||||||
FaceMapIt it = lookupMap.find( key );
|
|
||||||
if ( lookupMap.end() == it)
|
|
||||||
{
|
|
||||||
std::vector<Q3BSP::sQ3BSPFace*> *pArray = new std::vector<Q3BSP::sQ3BSPFace*>;
|
|
||||||
pArray->push_back( pQ3BSPFace );
|
|
||||||
lookupMap[ key ] = pArray;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::vector<Q3BSP::sQ3BSPFace*> *pArray = (*it).second;
|
|
||||||
ai_assert( NULL != pArray );
|
|
||||||
if ( NULL != pArray )
|
|
||||||
{
|
|
||||||
pArray->push_back( pQ3BSPFace );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<aiMesh*> MeshArray;
|
std::vector<aiMesh*> MeshArray;
|
||||||
std::vector<aiNode*> NodeArray;
|
std::vector<aiNode*> NodeArray;
|
||||||
for ( FaceMapIt it = lookupMap.begin(); it != lookupMap.end(); ++it )
|
for ( FaceMapIt it = m_MaterialLookupMap.begin(); it != m_MaterialLookupMap.end(); ++it )
|
||||||
{
|
{
|
||||||
std::vector<Q3BSP::sQ3BSPFace*> *pArray = (*it).second;
|
std::vector<Q3BSP::sQ3BSPFace*> *pArray = (*it).second;
|
||||||
size_t numVerts = countData( *pArray );
|
size_t numVerts = countData( *pArray );
|
||||||
if ( 0 != numVerts )
|
if ( 0 != numVerts )
|
||||||
{
|
{
|
||||||
aiMesh* pMesh = new aiMesh;
|
aiMesh* pMesh = new aiMesh;
|
||||||
aiNode *pNode = CreateTopology( pModel, *pArray, pMesh );
|
aiNode *pNode = CreateTopology( pModel, matIdx, *pArray, pMesh );
|
||||||
if ( NULL != pNode )
|
if ( NULL != pNode )
|
||||||
{
|
{
|
||||||
NodeArray.push_back( pNode );
|
NodeArray.push_back( pNode );
|
||||||
|
@ -240,6 +239,7 @@ void Q3BSPFileImporter::CreateNodes( const Q3BSP::Q3BSPModel *pModel, aiScene* p
|
||||||
{
|
{
|
||||||
delete pMesh;
|
delete pMesh;
|
||||||
}
|
}
|
||||||
|
matIdx++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,8 +272,11 @@ void Q3BSPFileImporter::CreateNodes( const Q3BSP::Q3BSPModel *pModel, aiScene* p
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
//
|
||||||
aiNode *Q3BSPFileImporter::CreateTopology( const Q3BSP::Q3BSPModel *pModel,
|
aiNode *Q3BSPFileImporter::CreateTopology( const Q3BSP::Q3BSPModel *pModel,
|
||||||
std::vector<sQ3BSPFace*> &rArray, aiMesh* pMesh )
|
unsigned int materialIdx,
|
||||||
|
std::vector<sQ3BSPFace*> &rArray,
|
||||||
|
aiMesh* pMesh )
|
||||||
{
|
{
|
||||||
size_t numVerts = countData( rArray );
|
size_t numVerts = countData( rArray );
|
||||||
if ( 0 == numVerts )
|
if ( 0 == numVerts )
|
||||||
|
@ -290,6 +293,7 @@ aiNode *Q3BSPFileImporter::CreateTopology( const Q3BSP::Q3BSPModel *pModel,
|
||||||
pMesh->mNormals = new aiVector3D[ numVerts ];
|
pMesh->mNormals = new aiVector3D[ numVerts ];
|
||||||
pMesh->mTextureCoords[ 0 ] = new aiVector3D[ numVerts ];
|
pMesh->mTextureCoords[ 0 ] = new aiVector3D[ numVerts ];
|
||||||
pMesh->mTextureCoords[ 1 ] = new aiVector3D[ numVerts ];
|
pMesh->mTextureCoords[ 1 ] = new aiVector3D[ numVerts ];
|
||||||
|
pMesh->mMaterialIndex = materialIdx;
|
||||||
|
|
||||||
unsigned int faceIdx = 0;
|
unsigned int faceIdx = 0;
|
||||||
unsigned int vertIdx = 0;
|
unsigned int vertIdx = 0;
|
||||||
|
@ -300,10 +304,10 @@ aiNode *Q3BSPFileImporter::CreateTopology( const Q3BSP::Q3BSPModel *pModel,
|
||||||
{
|
{
|
||||||
Q3BSP::sQ3BSPFace *pQ3BSPFace = *it;
|
Q3BSP::sQ3BSPFace *pQ3BSPFace = *it;
|
||||||
ai_assert( NULL != pQ3BSPFace );
|
ai_assert( NULL != pQ3BSPFace );
|
||||||
if ( pQ3BSPFace->iNumOfMeshVerts == 0 )
|
if ( NULL == pQ3BSPFace )
|
||||||
{
|
continue;
|
||||||
|
if ( pQ3BSPFace->iNumOfFaceVerts == 0 )
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
if ( pQ3BSPFace->iType == 1 || pQ3BSPFace->iType == 3 )
|
if ( pQ3BSPFace->iType == 1 || pQ3BSPFace->iType == 3 )
|
||||||
{
|
{
|
||||||
|
@ -317,10 +321,12 @@ aiNode *Q3BSPFileImporter::CreateTopology( const Q3BSP::Q3BSPModel *pModel,
|
||||||
|
|
||||||
return pNode;
|
return pNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void Q3BSPFileImporter::createTriangleTopology( const Q3BSP::Q3BSPModel *pModel,
|
void Q3BSPFileImporter::createTriangleTopology( const Q3BSP::Q3BSPModel *pModel,
|
||||||
Q3BSP::sQ3BSPFace *pQ3BSPFace,
|
Q3BSP::sQ3BSPFace *pQ3BSPFace,
|
||||||
aiMesh* pMesh, unsigned int &rFaceIdx,
|
aiMesh* pMesh,
|
||||||
|
unsigned int &rFaceIdx,
|
||||||
unsigned int &rVertIdx )
|
unsigned int &rVertIdx )
|
||||||
{
|
{
|
||||||
ai_assert( rFaceIdx < pMesh->mNumFaces );
|
ai_assert( rFaceIdx < pMesh->mNumFaces );
|
||||||
|
@ -328,23 +334,28 @@ void Q3BSPFileImporter::createTriangleTopology( const Q3BSP::Q3BSPModel *pModel,
|
||||||
ai_assert( NULL != pFace );
|
ai_assert( NULL != pFace );
|
||||||
rFaceIdx++;
|
rFaceIdx++;
|
||||||
|
|
||||||
pFace->mNumIndices = pQ3BSPFace->iNumOfMeshVerts;
|
pFace->mNumIndices = pQ3BSPFace->iNumOfFaceVerts;
|
||||||
pFace->mIndices = new unsigned int[ pFace->mNumIndices ];
|
pFace->mIndices = new unsigned int[ pFace->mNumIndices ];
|
||||||
aiVector3D normal;
|
aiVector3D normal;
|
||||||
normal.Set( pQ3BSPFace->vNormal.x, pQ3BSPFace->vNormal.y, pQ3BSPFace->vNormal.z );
|
normal.Set( pQ3BSPFace->vNormal.x, pQ3BSPFace->vNormal.y, pQ3BSPFace->vNormal.z );
|
||||||
|
|
||||||
for ( int i = 0; i < pQ3BSPFace->iNumOfMeshVerts; ++i )
|
for ( size_t i = 0; i < pFace->mNumIndices; ++i )
|
||||||
{
|
{
|
||||||
size_t idx = pModel->m_Indices[ pQ3BSPFace->iMeshVertexIndex + i ];;
|
const size_t index = pQ3BSPFace->iVertexIndex + pModel->m_Indices[ pQ3BSPFace->iFaceVertexIndex + i ];
|
||||||
const unsigned int index = pQ3BSPFace->iVertexIndex + pModel->m_Indices[idx];
|
|
||||||
ai_assert( index < pModel->m_Vertices.size() );
|
ai_assert( index < pModel->m_Vertices.size() );
|
||||||
sQ3BSPVertex *pVertex = pModel->m_Vertices[ index ];
|
sQ3BSPVertex *pVertex = pModel->m_Vertices[ index ];
|
||||||
ai_assert( NULL != pVertex );
|
ai_assert( NULL != pVertex );
|
||||||
|
if ( NULL == pVertex )
|
||||||
|
continue;
|
||||||
|
|
||||||
pMesh->mVertices[ rVertIdx ].Set( pVertex->vPosition.x, pVertex->vPosition.y, pVertex->vPosition.z );
|
pMesh->mVertices[ rVertIdx ].Set( pVertex->vPosition.x, pVertex->vPosition.y, pVertex->vPosition.z );
|
||||||
pMesh->mNormals[ rVertIdx ].Set( normal.x, normal.y, normal.z );
|
pMesh->mNormals[ rVertIdx ].Set( normal.x, normal.y, normal.z );
|
||||||
|
|
||||||
|
pMesh->mNumUVComponents[ 0 ] = 2;
|
||||||
pMesh->mTextureCoords[ 0 ][ rVertIdx ].Set( pVertex->vTexCoord.x, pVertex->vTexCoord.y, 0.0f );
|
pMesh->mTextureCoords[ 0 ][ rVertIdx ].Set( pVertex->vTexCoord.x, pVertex->vTexCoord.y, 0.0f );
|
||||||
|
|
||||||
|
pMesh->mNumUVComponents[ 1 ] = 2;
|
||||||
pMesh->mTextureCoords[ 1 ][ rVertIdx ].Set( pVertex->vLightmap.x, pVertex->vLightmap.y, 0.0f );
|
pMesh->mTextureCoords[ 1 ][ rVertIdx ].Set( pVertex->vLightmap.x, pVertex->vLightmap.y, 0.0f );
|
||||||
pFace->mIndices[ i ] = rVertIdx;
|
pFace->mIndices[ i ] = rVertIdx;
|
||||||
rVertIdx++;
|
rVertIdx++;
|
||||||
|
@ -352,9 +363,46 @@ void Q3BSPFileImporter::createTriangleTopology( const Q3BSP::Q3BSPModel *pModel,
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void Q3BSPFileImporter::createMaterials()
|
void Q3BSPFileImporter::createMaterials( const Q3BSP::Q3BSPModel *pModel, aiScene* pScene )
|
||||||
{
|
{
|
||||||
// TODO
|
if ( m_MaterialLookupMap.empty() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
pScene->mMaterials = new aiMaterial*[ m_MaterialLookupMap.size() ];
|
||||||
|
|
||||||
|
for ( FaceMapIt it = m_MaterialLookupMap.begin(); it != m_MaterialLookupMap.end();
|
||||||
|
++it )
|
||||||
|
{
|
||||||
|
const std::string matName = (*it).first;
|
||||||
|
if ( matName.empty() )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
aiString aiMatName;
|
||||||
|
aiMatName.Set( matName );
|
||||||
|
Assimp::MaterialHelper *pMatHelper = new Assimp::MaterialHelper;
|
||||||
|
pMatHelper->AddProperty( &aiMatName, AI_MATKEY_NAME );
|
||||||
|
|
||||||
|
int textureId, lightmapId;
|
||||||
|
extractIds( matName, textureId, lightmapId );
|
||||||
|
|
||||||
|
// Adding the texture
|
||||||
|
if ( -1 != textureId )
|
||||||
|
{
|
||||||
|
sQ3BSPTexture *pTexture = pModel->m_Textures[ textureId ];
|
||||||
|
if ( NULL != pTexture )
|
||||||
|
{
|
||||||
|
aiString textureName( pTexture->strName );
|
||||||
|
pMatHelper->AddProperty( &textureName, AI_MATKEY_TEXTURE_DIFFUSE( 0 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* if ( 0 != pCurrentMaterial->textureSpecular.length )
|
||||||
|
mat->AddProperty( &pCurrentMaterial->textureSpecular, AI_MATKEY_TEXTURE_SPECULAR(0));*/
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
pScene->mMaterials[ pScene->mNumMaterials ] = pMatHelper;
|
||||||
|
pScene->mNumMaterials++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
@ -365,11 +413,11 @@ size_t Q3BSPFileImporter::countData( const std::vector<sQ3BSPFace*> &rArray ) co
|
||||||
++it )
|
++it )
|
||||||
{
|
{
|
||||||
sQ3BSPFace *pQ3BSPFace = *it;
|
sQ3BSPFace *pQ3BSPFace = *it;
|
||||||
if ( pQ3BSPFace->iType == 1 || pQ3BSPFace->iType == 3 )
|
if ( pQ3BSPFace->iType == Polygon || pQ3BSPFace->iType == Mesh )
|
||||||
{
|
{
|
||||||
Q3BSP::sQ3BSPFace *pQ3BSPFace = *it;
|
Q3BSP::sQ3BSPFace *pQ3BSPFace = *it;
|
||||||
ai_assert( NULL != pQ3BSPFace );
|
ai_assert( NULL != pQ3BSPFace );
|
||||||
numVerts += pQ3BSPFace->iNumOfMeshVerts;
|
numVerts += pQ3BSPFace->iNumOfFaceVerts;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -384,7 +432,7 @@ size_t Q3BSPFileImporter::countFaces( const std::vector<Q3BSP::sQ3BSPFace*> &rAr
|
||||||
++it )
|
++it )
|
||||||
{
|
{
|
||||||
Q3BSP::sQ3BSPFace *pQ3BSPFace = *it;
|
Q3BSP::sQ3BSPFace *pQ3BSPFace = *it;
|
||||||
if ( pQ3BSPFace->iNumOfMeshVerts > 0)
|
if ( pQ3BSPFace->iNumOfFaceVerts > 0)
|
||||||
{
|
{
|
||||||
numFaces++;
|
numFaces++;
|
||||||
}
|
}
|
||||||
|
@ -393,6 +441,36 @@ size_t Q3BSPFileImporter::countFaces( const std::vector<Q3BSP::sQ3BSPFace*> &rAr
|
||||||
return numFaces;
|
return numFaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
void Q3BSPFileImporter::createMaterialMap( const Q3BSP::Q3BSPModel *pModel)
|
||||||
|
{
|
||||||
|
std::string key( "" );
|
||||||
|
std::vector<sQ3BSPFace*> *pCurFaceArray = NULL;
|
||||||
|
for ( size_t idx=0; idx < pModel->m_Faces.size(); idx++ )
|
||||||
|
{
|
||||||
|
Q3BSP::sQ3BSPFace *pQ3BSPFace = pModel->m_Faces[ idx ];
|
||||||
|
int texId = pQ3BSPFace->iTextureID;
|
||||||
|
int lightMapId = pQ3BSPFace->iLightmapID;
|
||||||
|
createKey( texId, lightMapId, key );
|
||||||
|
FaceMapIt it = m_MaterialLookupMap.find( key );
|
||||||
|
if ( m_MaterialLookupMap.end() == it )
|
||||||
|
{
|
||||||
|
std::vector<Q3BSP::sQ3BSPFace*> *pArray = new std::vector<Q3BSP::sQ3BSPFace*>;
|
||||||
|
pArray->push_back( pQ3BSPFace );
|
||||||
|
m_MaterialLookupMap[ key ] = pArray;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::vector<Q3BSP::sQ3BSPFace*> *pArray = (*it).second;
|
||||||
|
ai_assert( NULL != pArray );
|
||||||
|
if ( NULL != pArray )
|
||||||
|
{
|
||||||
|
pArray->push_back( pQ3BSPFace );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
} // Namespace Assimp
|
} // Namespace Assimp
|
||||||
|
|
|
@ -82,15 +82,18 @@ private:
|
||||||
bool findFirstMapInArchive( Q3BSP::Q3BSPZipArchive &rArchive, std::string &rMapName );
|
bool findFirstMapInArchive( Q3BSP::Q3BSPZipArchive &rArchive, std::string &rMapName );
|
||||||
void CreateDataFromImport( const Q3BSP::Q3BSPModel *pModel, aiScene* pScene );
|
void CreateDataFromImport( const Q3BSP::Q3BSPModel *pModel, aiScene* pScene );
|
||||||
void CreateNodes( const Q3BSP::Q3BSPModel *pModel, aiScene* pScene, aiNode *pParent );
|
void CreateNodes( const Q3BSP::Q3BSPModel *pModel, aiScene* pScene, aiNode *pParent );
|
||||||
aiNode *CreateTopology( const Q3BSP::Q3BSPModel *pModel, std::vector<Q3BSP::sQ3BSPFace*> &rArray, aiMesh* pMesh );
|
aiNode *CreateTopology( const Q3BSP::Q3BSPModel *pModel, unsigned int materialIdx,
|
||||||
|
std::vector<Q3BSP::sQ3BSPFace*> &rArray, aiMesh* pMesh );
|
||||||
void createTriangleTopology( const Q3BSP::Q3BSPModel *pModel, Q3BSP::sQ3BSPFace *pQ3BSPFace, aiMesh* pMesh, unsigned int &rFaceIdx,
|
void createTriangleTopology( const Q3BSP::Q3BSPModel *pModel, Q3BSP::sQ3BSPFace *pQ3BSPFace, aiMesh* pMesh, unsigned int &rFaceIdx,
|
||||||
unsigned int &rVertIdx );
|
unsigned int &rVertIdx );
|
||||||
void createMaterials();
|
void createMaterials( const Q3BSP::Q3BSPModel *pModel, aiScene* pScene );
|
||||||
size_t countData( const std::vector<Q3BSP::sQ3BSPFace*> &rArray ) const;
|
size_t countData( const std::vector<Q3BSP::sQ3BSPFace*> &rArray ) const;
|
||||||
size_t countFaces( const std::vector<Q3BSP::sQ3BSPFace*> &rArray ) const;
|
size_t countFaces( const std::vector<Q3BSP::sQ3BSPFace*> &rArray ) const;
|
||||||
|
void createMaterialMap( const Q3BSP::Q3BSPModel *pModel);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
aiMesh *m_pCurrentMesh;
|
aiMesh *m_pCurrentMesh;
|
||||||
|
FaceMap m_MaterialLookupMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Namespace Assimp
|
} // Namespace Assimp
|
||||||
|
|
|
@ -117,7 +117,10 @@ bool Q3BSPFileParser::parseFile()
|
||||||
if ( !validateFormat() )
|
if ( !validateFormat() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// Import the dictionary
|
||||||
getLumps();
|
getLumps();
|
||||||
|
|
||||||
|
// Conunt data and prepare model data
|
||||||
countLumps();
|
countLumps();
|
||||||
|
|
||||||
// Read in Vertices
|
// Read in Vertices
|
||||||
|
|
Loading…
Reference in New Issue