2010-06-18 17:36:46 +00:00
|
|
|
/*
|
2012-02-03 03:38:30 +00:00
|
|
|
Open Asset Import Library (assimp)
|
2010-07-08 21:25:48 +00:00
|
|
|
---------------------------------------------------------------------------------------------------
|
2010-06-18 17:36:46 +00:00
|
|
|
|
2012-02-03 03:38:30 +00:00
|
|
|
Copyright (c) 2006-2008, assimp team
|
2010-06-18 17:36:46 +00:00
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the
|
|
|
|
following conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer.
|
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer in the documentation and/or other
|
|
|
|
materials provided with the distribution.
|
|
|
|
|
2012-02-03 03:38:30 +00:00
|
|
|
* Neither the name of the assimp team, nor the names of its
|
2010-06-18 17:36:46 +00:00
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
2012-02-03 03:38:30 +00:00
|
|
|
written permission of the assimp team.
|
2010-06-18 17:36:46 +00:00
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
2010-07-08 21:25:48 +00:00
|
|
|
---------------------------------------------------------------------------------------------------
|
2010-06-18 17:36:46 +00:00
|
|
|
*/
|
|
|
|
#include "AssimpPCH.h"
|
|
|
|
#ifndef ASSIMP_BUILD_NO_Q3BSP_IMPORTER
|
|
|
|
|
2010-10-18 22:19:39 +00:00
|
|
|
//#include <windows.h>
|
2010-06-18 17:36:46 +00:00
|
|
|
#include "DefaultIOSystem.h"
|
|
|
|
#include "Q3BSPFileImporter.h"
|
|
|
|
#include "Q3BSPZipArchive.h"
|
|
|
|
#include "Q3BSPFileParser.h"
|
2010-07-08 21:25:48 +00:00
|
|
|
#include "Q3BSPFileData.h"
|
2010-07-16 17:49:04 +00:00
|
|
|
|
2010-09-26 15:56:52 +00:00
|
|
|
#ifdef ASSIMP_BUILD_NO_OWN_ZLIB
|
|
|
|
# include <zlib.h>
|
|
|
|
#else
|
|
|
|
# include "../contrib/zlib/zlib.h"
|
|
|
|
#endif
|
2010-07-16 17:49:04 +00:00
|
|
|
|
2012-02-03 17:04:06 +00:00
|
|
|
#include "../include/assimp/types.h"
|
|
|
|
#include "../include/assimp/mesh.h"
|
2010-06-18 17:36:46 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2012-04-22 22:26:26 +00:00
|
|
|
|
|
|
|
static const aiImporterDesc desc = {
|
|
|
|
"Quake III BSP Importer",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
aiImporterFlags_SupportBinaryFlavour,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
"pk3"
|
|
|
|
};
|
|
|
|
|
2014-03-27 19:33:08 +00:00
|
|
|
namespace Assimp {
|
2010-06-18 17:36:46 +00:00
|
|
|
|
2014-08-17 21:28:00 +00:00
|
|
|
/*
|
2014-03-27 19:33:08 +00:00
|
|
|
static void getSupportedExtensions(std::vector<std::string> &supportedExtensions) {
|
|
|
|
supportedExtensions.push_back( ".jpg" );
|
|
|
|
supportedExtensions.push_back( ".png" );
|
|
|
|
supportedExtensions.push_back( ".tga" );
|
|
|
|
}
|
2014-08-17 21:28:00 +00:00
|
|
|
*/
|
2014-03-27 19:33:08 +00:00
|
|
|
|
2010-06-18 17:36:46 +00:00
|
|
|
using namespace Q3BSP;
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2011-03-31 21:38:18 +00:00
|
|
|
// Local function to create a material key name.
|
2010-07-08 21:25:48 +00:00
|
|
|
static void createKey( int id1, int id2, std::string &rKey )
|
|
|
|
{
|
2011-04-03 15:12:05 +00:00
|
|
|
std::ostringstream str;
|
2010-07-08 21:25:48 +00:00
|
|
|
str << id1 << "." << id2;
|
|
|
|
rKey = str.str();
|
|
|
|
}
|
|
|
|
|
2010-08-07 15:10:27 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2014-03-27 19:33:08 +00:00
|
|
|
// Local function to extract the texture ids from a material key-name.
|
2010-08-07 15:10:27 +00:00
|
|
|
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;
|
|
|
|
|
2010-10-18 19:18:28 +00:00
|
|
|
std::string tmp1 = rKey.substr( 0, pos );
|
2010-08-07 15:10:27 +00:00
|
|
|
std::string tmp2 = rKey.substr( pos + 1, rKey.size() - pos - 1 );
|
|
|
|
rId1 = atoi( tmp1.c_str() );
|
|
|
|
rId2 = atoi( tmp2.c_str() );
|
|
|
|
}
|
|
|
|
|
2010-09-29 19:42:50 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2011-04-03 17:22:36 +00:00
|
|
|
// Local helper function to normalize filenames.
|
2010-09-29 19:42:50 +00:00
|
|
|
static void normalizePathName( const std::string &rPath, std::string &rNormalizedPath )
|
|
|
|
{
|
|
|
|
rNormalizedPath = "";
|
|
|
|
if ( rPath.empty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
std::string sep = "\\";
|
|
|
|
#else
|
|
|
|
std::string sep = "/";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static const unsigned int numDelimiters = 2;
|
|
|
|
const char delimiters[ numDelimiters ] = { '/', '\\' };
|
|
|
|
rNormalizedPath = rPath;
|
|
|
|
for ( unsigned int i=0; i<numDelimiters; i++ )
|
|
|
|
{
|
|
|
|
for ( size_t j=0; j<rNormalizedPath.size(); j++ )
|
|
|
|
{
|
|
|
|
if ( rNormalizedPath[j] == delimiters[ i ] )
|
|
|
|
{
|
2010-11-05 18:45:42 +00:00
|
|
|
rNormalizedPath[ j ] = sep[ 0 ];
|
2010-09-29 19:42:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-08 21:25:48 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2010-09-26 15:56:52 +00:00
|
|
|
// Constructor.
|
2010-07-08 21:25:48 +00:00
|
|
|
Q3BSPFileImporter::Q3BSPFileImporter() :
|
2010-09-26 15:56:52 +00:00
|
|
|
m_pCurrentMesh( NULL ),
|
|
|
|
m_pCurrentFace( NULL ),
|
2010-11-05 18:45:42 +00:00
|
|
|
m_MaterialLookupMap(),
|
|
|
|
mTextures()
|
2010-06-18 17:36:46 +00:00
|
|
|
{
|
2010-08-07 15:10:27 +00:00
|
|
|
// empty
|
2010-06-18 17:36:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2010-09-26 15:56:52 +00:00
|
|
|
// Destructor.
|
2014-03-27 19:33:08 +00:00
|
|
|
Q3BSPFileImporter::~Q3BSPFileImporter() {
|
2010-09-26 15:56:52 +00:00
|
|
|
m_pCurrentMesh = NULL;
|
|
|
|
m_pCurrentFace = NULL;
|
|
|
|
|
|
|
|
// Clear face-to-material map
|
2014-03-27 19:33:08 +00:00
|
|
|
for ( FaceMap::iterator it = m_MaterialLookupMap.begin(); it != m_MaterialLookupMap.end(); ++it ) {
|
|
|
|
const std::string &matName = it->first;
|
|
|
|
if ( !matName.empty() ) {
|
|
|
|
delete it->second;
|
2010-10-18 19:18:28 +00:00
|
|
|
}
|
2010-09-26 15:56:52 +00:00
|
|
|
}
|
|
|
|
m_MaterialLookupMap.clear();
|
2010-06-18 17:36:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2010-09-26 15:56:52 +00:00
|
|
|
// Returns true, if the loader can read this.
|
2011-06-09 14:29:32 +00:00
|
|
|
bool Q3BSPFileImporter::CanRead( const std::string& rFile, IOSystem* /*pIOHandler*/, bool checkSig ) const
|
2010-06-18 17:36:46 +00:00
|
|
|
{
|
2011-04-22 16:08:31 +00:00
|
|
|
if(!checkSig) {
|
2012-04-22 22:26:26 +00:00
|
|
|
return SimpleExtensionCheck( rFile, "pk3" );
|
2011-03-31 21:41:28 +00:00
|
|
|
}
|
2011-04-22 16:08:31 +00:00
|
|
|
// TODO perhaps add keyword based detection
|
|
|
|
return false;
|
2010-06-18 17:36:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2010-09-26 15:56:52 +00:00
|
|
|
// Adds extensions.
|
2012-04-22 22:26:26 +00:00
|
|
|
const aiImporterDesc* Q3BSPFileImporter::GetInfo () const
|
2010-06-18 17:36:46 +00:00
|
|
|
{
|
2012-04-22 22:26:26 +00:00
|
|
|
return &desc;
|
2010-06-18 17:36:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2010-09-29 19:42:50 +00:00
|
|
|
// Import method.
|
2014-03-10 16:21:17 +00:00
|
|
|
void Q3BSPFileImporter::InternReadFile(const std::string &rFile, aiScene* pScene, IOSystem* pIOHandler)
|
2010-06-18 17:36:46 +00:00
|
|
|
{
|
2014-03-10 16:21:17 +00:00
|
|
|
Q3BSPZipArchive Archive( pIOHandler, rFile );
|
2010-06-18 17:36:46 +00:00
|
|
|
if ( !Archive.isOpen() )
|
|
|
|
{
|
2010-12-06 21:34:31 +00:00
|
|
|
throw DeadlyImportError( "Failed to open file " + rFile + "." );
|
2010-06-18 17:36:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string archiveName( "" ), mapName( "" );
|
|
|
|
separateMapName( rFile, archiveName, mapName );
|
|
|
|
|
|
|
|
if ( mapName.empty() )
|
|
|
|
{
|
|
|
|
if ( !findFirstMapInArchive( Archive, mapName ) )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Q3BSPFileParser fileParser( mapName, &Archive );
|
|
|
|
Q3BSPModel *pBSPModel = fileParser.getModel();
|
|
|
|
if ( NULL != pBSPModel )
|
|
|
|
{
|
2010-11-05 18:45:42 +00:00
|
|
|
CreateDataFromImport( pBSPModel, pScene, &Archive );
|
2010-06-18 17:36:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2010-09-26 15:56:52 +00:00
|
|
|
// Separates the map name from the import name.
|
2010-06-18 17:36:46 +00:00
|
|
|
void Q3BSPFileImporter::separateMapName( const std::string &rImportName, std::string &rArchiveName,
|
|
|
|
std::string &rMapName )
|
|
|
|
{
|
|
|
|
rArchiveName = "";
|
|
|
|
rMapName = "";
|
|
|
|
if ( rImportName.empty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::string::size_type pos = rImportName.rfind( "," );
|
|
|
|
if ( std::string::npos == pos )
|
|
|
|
{
|
|
|
|
rArchiveName = rImportName;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rArchiveName = rImportName.substr( 0, pos );
|
|
|
|
rMapName = rImportName.substr( pos, rImportName.size() - pos - 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2010-09-26 15:56:52 +00:00
|
|
|
// Returns the first map in the map archive.
|
2010-06-18 17:36:46 +00:00
|
|
|
bool Q3BSPFileImporter::findFirstMapInArchive( Q3BSPZipArchive &rArchive, std::string &rMapName )
|
|
|
|
{
|
|
|
|
rMapName = "";
|
|
|
|
std::vector<std::string> fileList;
|
|
|
|
rArchive.getFileList( fileList );
|
|
|
|
if ( fileList.empty() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for ( std::vector<std::string>::iterator it = fileList.begin(); it != fileList.end();
|
|
|
|
++it )
|
|
|
|
{
|
|
|
|
std::string::size_type pos = (*it).find( "maps/" );
|
|
|
|
if ( std::string::npos != pos )
|
|
|
|
{
|
|
|
|
std::string::size_type extPos = (*it).find( ".bsp" );
|
|
|
|
if ( std::string::npos != extPos )
|
|
|
|
{
|
|
|
|
rMapName = *it;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-09-26 15:56:52 +00:00
|
|
|
|
2010-06-18 17:36:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-07-08 21:25:48 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2010-09-26 15:56:52 +00:00
|
|
|
// Creates the assimp specific data.
|
2010-11-05 18:45:42 +00:00
|
|
|
void Q3BSPFileImporter::CreateDataFromImport( const Q3BSP::Q3BSPModel *pModel, aiScene* pScene,
|
|
|
|
Q3BSPZipArchive *pArchive )
|
2010-07-08 21:25:48 +00:00
|
|
|
{
|
|
|
|
if ( NULL == pModel || NULL == pScene )
|
|
|
|
return;
|
|
|
|
|
|
|
|
pScene->mRootNode = new aiNode;
|
|
|
|
if ( !pModel->m_ModelName.empty() )
|
|
|
|
{
|
|
|
|
pScene->mRootNode->mName.Set( pModel->m_ModelName );
|
|
|
|
}
|
|
|
|
|
2010-09-26 15:56:52 +00:00
|
|
|
// Create the face to material relation map
|
2010-08-07 15:10:27 +00:00
|
|
|
createMaterialMap( pModel );
|
|
|
|
|
2010-09-26 15:56:52 +00:00
|
|
|
// Create all nodes
|
2010-07-08 21:25:48 +00:00
|
|
|
CreateNodes( pModel, pScene, pScene->mRootNode );
|
2010-09-26 15:56:52 +00:00
|
|
|
|
|
|
|
// Create the assigned materials
|
2010-11-05 18:45:42 +00:00
|
|
|
createMaterials( pModel, pScene, pArchive );
|
2010-07-08 21:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2010-09-26 15:56:52 +00:00
|
|
|
// Creates all assimp nodes.
|
|
|
|
void Q3BSPFileImporter::CreateNodes( const Q3BSP::Q3BSPModel *pModel, aiScene* pScene,
|
|
|
|
aiNode *pParent )
|
2010-07-08 21:25:48 +00:00
|
|
|
{
|
|
|
|
ai_assert( NULL != pModel );
|
|
|
|
if ( NULL == pModel )
|
2010-11-05 18:45:42 +00:00
|
|
|
{
|
2010-07-08 21:25:48 +00:00
|
|
|
return;
|
2010-11-05 18:45:42 +00:00
|
|
|
}
|
2010-07-08 21:25:48 +00:00
|
|
|
|
2010-08-07 15:10:27 +00:00
|
|
|
unsigned int matIdx = 0;
|
2010-07-08 21:25:48 +00:00
|
|
|
std::vector<aiMesh*> MeshArray;
|
|
|
|
std::vector<aiNode*> NodeArray;
|
2010-08-07 15:10:27 +00:00
|
|
|
for ( FaceMapIt it = m_MaterialLookupMap.begin(); it != m_MaterialLookupMap.end(); ++it )
|
2010-07-08 21:25:48 +00:00
|
|
|
{
|
|
|
|
std::vector<Q3BSP::sQ3BSPFace*> *pArray = (*it).second;
|
|
|
|
size_t numVerts = countData( *pArray );
|
|
|
|
if ( 0 != numVerts )
|
|
|
|
{
|
|
|
|
aiMesh* pMesh = new aiMesh;
|
2010-08-07 15:10:27 +00:00
|
|
|
aiNode *pNode = CreateTopology( pModel, matIdx, *pArray, pMesh );
|
2010-07-08 21:25:48 +00:00
|
|
|
if ( NULL != pNode )
|
|
|
|
{
|
|
|
|
NodeArray.push_back( pNode );
|
|
|
|
MeshArray.push_back( pMesh );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete pMesh;
|
|
|
|
}
|
|
|
|
}
|
2010-10-18 19:18:28 +00:00
|
|
|
matIdx++;
|
2010-07-08 21:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pScene->mNumMeshes = MeshArray.size();
|
2010-09-26 15:56:52 +00:00
|
|
|
if ( pScene->mNumMeshes > 0 )
|
2010-07-08 21:25:48 +00:00
|
|
|
{
|
2010-09-26 15:56:52 +00:00
|
|
|
pScene->mMeshes = new aiMesh*[ pScene->mNumMeshes ];
|
|
|
|
for ( size_t i = 0; i < MeshArray.size(); i++ )
|
2010-07-08 21:25:48 +00:00
|
|
|
{
|
2010-09-26 15:56:52 +00:00
|
|
|
aiMesh *pMesh = MeshArray[ i ];
|
|
|
|
if ( NULL != pMesh )
|
2010-07-08 21:25:48 +00:00
|
|
|
{
|
2010-09-26 15:56:52 +00:00
|
|
|
pScene->mMeshes[ i ] = pMesh;
|
2010-07-08 21:25:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pParent->mNumChildren = MeshArray.size();
|
|
|
|
pParent->mChildren = new aiNode*[ pScene->mRootNode->mNumChildren ];
|
|
|
|
for ( size_t i=0; i<NodeArray.size(); i++ )
|
|
|
|
{
|
|
|
|
aiNode *pNode = NodeArray[ i ];
|
|
|
|
pNode->mParent = pParent;
|
|
|
|
pParent->mChildren[ i ] = pNode;
|
|
|
|
pParent->mChildren[ i ]->mMeshes[ 0 ] = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2010-09-26 15:56:52 +00:00
|
|
|
// Creates the topology.
|
2010-07-08 21:25:48 +00:00
|
|
|
aiNode *Q3BSPFileImporter::CreateTopology( const Q3BSP::Q3BSPModel *pModel,
|
2010-08-07 15:10:27 +00:00
|
|
|
unsigned int materialIdx,
|
|
|
|
std::vector<sQ3BSPFace*> &rArray,
|
|
|
|
aiMesh* pMesh )
|
2010-07-08 21:25:48 +00:00
|
|
|
{
|
|
|
|
size_t numVerts = countData( rArray );
|
|
|
|
if ( 0 == numVerts )
|
2010-11-05 18:45:42 +00:00
|
|
|
{
|
2010-07-08 21:25:48 +00:00
|
|
|
return NULL;
|
2010-11-05 18:45:42 +00:00
|
|
|
}
|
2010-07-08 21:25:48 +00:00
|
|
|
|
|
|
|
size_t numFaces = countFaces( rArray );
|
|
|
|
if ( 0 == numFaces )
|
2010-11-05 18:45:42 +00:00
|
|
|
{
|
2010-07-08 21:25:48 +00:00
|
|
|
return NULL;
|
2010-11-05 18:45:42 +00:00
|
|
|
}
|
2010-07-08 21:25:48 +00:00
|
|
|
|
2010-09-26 15:56:52 +00:00
|
|
|
size_t numTriangles = countTriangles( rArray );
|
2010-10-18 19:18:28 +00:00
|
|
|
pMesh->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
|
2010-09-26 15:56:52 +00:00
|
|
|
|
|
|
|
pMesh->mFaces = new aiFace[ numTriangles ];
|
|
|
|
pMesh->mNumFaces = numTriangles;
|
|
|
|
|
2010-07-08 21:25:48 +00:00
|
|
|
pMesh->mNumVertices = numVerts;
|
|
|
|
pMesh->mVertices = new aiVector3D[ numVerts ];
|
|
|
|
pMesh->mNormals = new aiVector3D[ numVerts ];
|
|
|
|
pMesh->mTextureCoords[ 0 ] = new aiVector3D[ numVerts ];
|
|
|
|
pMesh->mTextureCoords[ 1 ] = new aiVector3D[ numVerts ];
|
2010-08-07 15:10:27 +00:00
|
|
|
pMesh->mMaterialIndex = materialIdx;
|
2010-07-08 21:25:48 +00:00
|
|
|
|
|
|
|
unsigned int faceIdx = 0;
|
|
|
|
unsigned int vertIdx = 0;
|
2010-09-26 15:56:52 +00:00
|
|
|
pMesh->mNumUVComponents[ 0 ] = 2;
|
|
|
|
pMesh->mNumUVComponents[ 1 ] = 2;
|
|
|
|
for ( std::vector<sQ3BSPFace*>::const_iterator it = rArray.begin(); it != rArray.end(); ++it )
|
2010-07-08 21:25:48 +00:00
|
|
|
{
|
|
|
|
Q3BSP::sQ3BSPFace *pQ3BSPFace = *it;
|
|
|
|
ai_assert( NULL != pQ3BSPFace );
|
2010-08-07 15:10:27 +00:00
|
|
|
if ( NULL == pQ3BSPFace )
|
2010-09-26 15:56:52 +00:00
|
|
|
{
|
2010-08-07 15:10:27 +00:00
|
|
|
continue;
|
2010-09-26 15:56:52 +00:00
|
|
|
}
|
2010-07-08 21:25:48 +00:00
|
|
|
|
2010-09-26 15:56:52 +00:00
|
|
|
if ( pQ3BSPFace->iNumOfFaceVerts > 0 )
|
2010-07-08 21:25:48 +00:00
|
|
|
{
|
2010-09-26 15:56:52 +00:00
|
|
|
if ( pQ3BSPFace->iType == Polygon || pQ3BSPFace->iType == TriangleMesh )
|
|
|
|
{
|
|
|
|
createTriangleTopology( pModel, pQ3BSPFace, pMesh, faceIdx, vertIdx );
|
|
|
|
}
|
|
|
|
}
|
2010-07-08 21:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
aiNode *pNode = new aiNode;
|
|
|
|
pNode->mNumMeshes = 1;
|
|
|
|
pNode->mMeshes = new unsigned int[ 1 ];
|
|
|
|
|
|
|
|
return pNode;
|
|
|
|
}
|
2010-08-07 15:10:27 +00:00
|
|
|
|
2010-07-08 21:25:48 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2010-09-26 15:56:52 +00:00
|
|
|
// Creates the triangle topology from a face array.
|
2010-07-08 21:25:48 +00:00
|
|
|
void Q3BSPFileImporter::createTriangleTopology( const Q3BSP::Q3BSPModel *pModel,
|
|
|
|
Q3BSP::sQ3BSPFace *pQ3BSPFace,
|
2010-08-07 15:10:27 +00:00
|
|
|
aiMesh* pMesh,
|
|
|
|
unsigned int &rFaceIdx,
|
2010-07-08 21:25:48 +00:00
|
|
|
unsigned int &rVertIdx )
|
|
|
|
{
|
2010-07-09 17:45:21 +00:00
|
|
|
ai_assert( rFaceIdx < pMesh->mNumFaces );
|
2010-08-07 15:10:27 +00:00
|
|
|
|
2010-09-26 15:56:52 +00:00
|
|
|
m_pCurrentFace = getNextFace( pMesh, rFaceIdx );
|
|
|
|
ai_assert( NULL != m_pCurrentFace );
|
|
|
|
if ( NULL == m_pCurrentFace )
|
2010-11-05 18:45:42 +00:00
|
|
|
{
|
2010-09-26 15:56:52 +00:00
|
|
|
return;
|
2010-11-05 18:45:42 +00:00
|
|
|
}
|
2010-09-26 15:56:52 +00:00
|
|
|
|
|
|
|
m_pCurrentFace->mNumIndices = 3;
|
|
|
|
m_pCurrentFace->mIndices = new unsigned int[ m_pCurrentFace->mNumIndices ];
|
|
|
|
|
|
|
|
size_t idx = 0;
|
2010-09-29 19:42:50 +00:00
|
|
|
for ( size_t i = 0; i < (size_t) pQ3BSPFace->iNumOfFaceVerts; i++ )
|
2010-07-08 21:25:48 +00:00
|
|
|
{
|
2010-08-07 15:10:27 +00:00
|
|
|
const size_t index = pQ3BSPFace->iVertexIndex + pModel->m_Indices[ pQ3BSPFace->iFaceVertexIndex + i ];
|
2010-07-08 21:25:48 +00:00
|
|
|
ai_assert( index < pModel->m_Vertices.size() );
|
2010-09-26 15:56:52 +00:00
|
|
|
if ( index >= pModel->m_Vertices.size() )
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-07-08 21:25:48 +00:00
|
|
|
sQ3BSPVertex *pVertex = pModel->m_Vertices[ index ];
|
|
|
|
ai_assert( NULL != pVertex );
|
2010-08-07 15:10:27 +00:00
|
|
|
if ( NULL == pVertex )
|
2010-09-26 15:56:52 +00:00
|
|
|
{
|
2010-08-07 15:10:27 +00:00
|
|
|
continue;
|
2010-09-26 15:56:52 +00:00
|
|
|
}
|
2010-07-08 21:25:48 +00:00
|
|
|
|
|
|
|
pMesh->mVertices[ rVertIdx ].Set( pVertex->vPosition.x, pVertex->vPosition.y, pVertex->vPosition.z );
|
2010-09-26 15:56:52 +00:00
|
|
|
pMesh->mNormals[ rVertIdx ].Set( pVertex->vNormal.x, pVertex->vNormal.y, pVertex->vNormal.z );
|
2010-07-08 21:25:48 +00:00
|
|
|
|
|
|
|
pMesh->mTextureCoords[ 0 ][ rVertIdx ].Set( pVertex->vTexCoord.x, pVertex->vTexCoord.y, 0.0f );
|
|
|
|
pMesh->mTextureCoords[ 1 ][ rVertIdx ].Set( pVertex->vLightmap.x, pVertex->vLightmap.y, 0.0f );
|
2010-09-26 15:56:52 +00:00
|
|
|
|
|
|
|
m_pCurrentFace->mIndices[ idx ] = rVertIdx;
|
2010-07-08 21:25:48 +00:00
|
|
|
rVertIdx++;
|
2010-09-26 15:56:52 +00:00
|
|
|
|
|
|
|
idx++;
|
|
|
|
if ( idx > 2 )
|
|
|
|
{
|
|
|
|
idx = 0;
|
|
|
|
m_pCurrentFace = getNextFace( pMesh, rFaceIdx );
|
|
|
|
if ( NULL != m_pCurrentFace )
|
|
|
|
{
|
|
|
|
m_pCurrentFace->mNumIndices = 3;
|
|
|
|
m_pCurrentFace->mIndices = new unsigned int[ 3 ];
|
|
|
|
}
|
|
|
|
}
|
2010-07-08 21:25:48 +00:00
|
|
|
}
|
2010-09-26 15:56:52 +00:00
|
|
|
rFaceIdx--;
|
2010-07-08 21:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2010-09-26 15:56:52 +00:00
|
|
|
// Creates all referenced materials.
|
2010-11-05 18:45:42 +00:00
|
|
|
void Q3BSPFileImporter::createMaterials( const Q3BSP::Q3BSPModel *pModel, aiScene* pScene,
|
|
|
|
Q3BSPZipArchive *pArchive )
|
2010-07-08 21:25:48 +00:00
|
|
|
{
|
2010-08-07 15:10:27 +00:00
|
|
|
if ( m_MaterialLookupMap.empty() )
|
2010-11-05 18:45:42 +00:00
|
|
|
{
|
2010-08-07 15:10:27 +00:00
|
|
|
return;
|
2010-11-05 18:45:42 +00:00
|
|
|
}
|
2010-08-07 15:10:27 +00:00
|
|
|
|
|
|
|
pScene->mMaterials = new aiMaterial*[ m_MaterialLookupMap.size() ];
|
2010-11-05 18:45:42 +00:00
|
|
|
aiString aiMatName;
|
|
|
|
int textureId( -1 ), lightmapId( -1 );
|
2010-08-07 15:10:27 +00:00
|
|
|
for ( FaceMapIt it = m_MaterialLookupMap.begin(); it != m_MaterialLookupMap.end();
|
|
|
|
++it )
|
|
|
|
{
|
|
|
|
const std::string matName = (*it).first;
|
|
|
|
if ( matName.empty() )
|
2010-09-29 19:42:50 +00:00
|
|
|
{
|
2010-08-07 15:10:27 +00:00
|
|
|
continue;
|
2010-09-29 19:42:50 +00:00
|
|
|
}
|
2010-08-07 15:10:27 +00:00
|
|
|
|
|
|
|
aiMatName.Set( matName );
|
2011-08-22 20:22:51 +00:00
|
|
|
aiMaterial *pMatHelper = new aiMaterial;
|
2010-08-07 15:10:27 +00:00
|
|
|
pMatHelper->AddProperty( &aiMatName, AI_MATKEY_NAME );
|
|
|
|
|
|
|
|
extractIds( matName, textureId, lightmapId );
|
|
|
|
|
|
|
|
// Adding the texture
|
|
|
|
if ( -1 != textureId )
|
|
|
|
{
|
|
|
|
sQ3BSPTexture *pTexture = pModel->m_Textures[ textureId ];
|
|
|
|
if ( NULL != pTexture )
|
|
|
|
{
|
2010-11-05 18:45:42 +00:00
|
|
|
std::string tmp( "*" ), texName( "" );
|
|
|
|
tmp += pTexture->strName;
|
2010-09-29 19:42:50 +00:00
|
|
|
tmp += ".jpg";
|
|
|
|
normalizePathName( tmp, texName );
|
2010-11-05 18:45:42 +00:00
|
|
|
|
|
|
|
if ( !importTextureFromArchive( pModel, pArchive, pScene, pMatHelper, textureId ) )
|
|
|
|
{
|
|
|
|
}
|
2010-08-07 15:10:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2010-11-05 18:45:42 +00:00
|
|
|
if ( -1 != lightmapId )
|
|
|
|
{
|
|
|
|
importLightmap( pModel, pScene, pMatHelper, lightmapId );
|
|
|
|
}
|
2010-08-07 15:10:27 +00:00
|
|
|
pScene->mMaterials[ pScene->mNumMaterials ] = pMatHelper;
|
|
|
|
pScene->mNumMaterials++;
|
|
|
|
}
|
2010-11-05 18:45:42 +00:00
|
|
|
pScene->mNumTextures = mTextures.size();
|
|
|
|
pScene->mTextures = new aiTexture*[ pScene->mNumTextures ];
|
|
|
|
std::copy( mTextures.begin(), mTextures.end(), pScene->mTextures );
|
2010-07-08 21:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2010-11-05 18:45:42 +00:00
|
|
|
// Counts the number of referenced vertices.
|
2010-07-08 21:25:48 +00:00
|
|
|
size_t Q3BSPFileImporter::countData( const std::vector<sQ3BSPFace*> &rArray ) const
|
|
|
|
{
|
|
|
|
size_t numVerts = 0;
|
|
|
|
for ( std::vector<sQ3BSPFace*>::const_iterator it = rArray.begin(); it != rArray.end();
|
|
|
|
++it )
|
|
|
|
{
|
|
|
|
sQ3BSPFace *pQ3BSPFace = *it;
|
2010-09-26 15:56:52 +00:00
|
|
|
if ( pQ3BSPFace->iType == Polygon || pQ3BSPFace->iType == TriangleMesh )
|
2010-07-08 21:25:48 +00:00
|
|
|
{
|
|
|
|
Q3BSP::sQ3BSPFace *pQ3BSPFace = *it;
|
|
|
|
ai_assert( NULL != pQ3BSPFace );
|
2010-08-07 15:10:27 +00:00
|
|
|
numVerts += pQ3BSPFace->iNumOfFaceVerts;
|
2010-07-08 21:25:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return numVerts;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2010-09-26 15:56:52 +00:00
|
|
|
// Counts the faces with vertices.
|
2010-07-08 21:25:48 +00:00
|
|
|
size_t Q3BSPFileImporter::countFaces( const std::vector<Q3BSP::sQ3BSPFace*> &rArray ) const
|
|
|
|
{
|
|
|
|
size_t numFaces = 0;
|
|
|
|
for ( std::vector<sQ3BSPFace*>::const_iterator it = rArray.begin(); it != rArray.end();
|
|
|
|
++it )
|
|
|
|
{
|
|
|
|
Q3BSP::sQ3BSPFace *pQ3BSPFace = *it;
|
2010-09-26 15:56:52 +00:00
|
|
|
if ( pQ3BSPFace->iNumOfFaceVerts > 0 )
|
2010-07-08 21:25:48 +00:00
|
|
|
{
|
|
|
|
numFaces++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return numFaces;
|
|
|
|
}
|
|
|
|
|
2010-08-07 15:10:27 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2014-03-27 19:33:08 +00:00
|
|
|
// Counts the number of triangles in a Q3-face-array.
|
2010-09-26 15:56:52 +00:00
|
|
|
size_t Q3BSPFileImporter::countTriangles( const std::vector<Q3BSP::sQ3BSPFace*> &rArray ) const
|
|
|
|
{
|
|
|
|
size_t numTriangles = 0;
|
|
|
|
for ( std::vector<Q3BSP::sQ3BSPFace*>::const_iterator it = rArray.begin(); it != rArray.end();
|
|
|
|
++it )
|
|
|
|
{
|
|
|
|
const Q3BSP::sQ3BSPFace *pQ3BSPFace = *it;
|
|
|
|
if ( NULL != pQ3BSPFace )
|
|
|
|
{
|
|
|
|
numTriangles += pQ3BSPFace->iNumOfFaceVerts / 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return numTriangles;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Creates the faces-to-material map.
|
|
|
|
void Q3BSPFileImporter::createMaterialMap( const Q3BSP::Q3BSPModel *pModel )
|
2010-08-07 15:10:27 +00:00
|
|
|
{
|
|
|
|
std::string key( "" );
|
|
|
|
std::vector<sQ3BSPFace*> *pCurFaceArray = NULL;
|
2010-09-26 15:56:52 +00:00
|
|
|
for ( size_t idx = 0; idx < pModel->m_Faces.size(); idx++ )
|
2010-08-07 15:10:27 +00:00
|
|
|
{
|
|
|
|
Q3BSP::sQ3BSPFace *pQ3BSPFace = pModel->m_Faces[ idx ];
|
2010-09-26 15:56:52 +00:00
|
|
|
const int texId = pQ3BSPFace->iTextureID;
|
|
|
|
const int lightMapId = pQ3BSPFace->iLightmapID;
|
2010-08-07 15:10:27 +00:00
|
|
|
createKey( texId, lightMapId, key );
|
|
|
|
FaceMapIt it = m_MaterialLookupMap.find( key );
|
|
|
|
if ( m_MaterialLookupMap.end() == it )
|
|
|
|
{
|
2010-09-26 15:56:52 +00:00
|
|
|
pCurFaceArray = new std::vector<Q3BSP::sQ3BSPFace*>;
|
|
|
|
m_MaterialLookupMap[ key ] = pCurFaceArray;
|
2010-08-07 15:10:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-26 15:56:52 +00:00
|
|
|
pCurFaceArray = (*it).second;
|
|
|
|
}
|
|
|
|
ai_assert( NULL != pCurFaceArray );
|
|
|
|
if ( NULL != pCurFaceArray )
|
|
|
|
{
|
|
|
|
pCurFaceArray->push_back( pQ3BSPFace );
|
2010-08-07 15:10:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-26 15:56:52 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Returns the next face.
|
|
|
|
aiFace *Q3BSPFileImporter::getNextFace( aiMesh *pMesh, unsigned int &rFaceIdx )
|
|
|
|
{
|
2014-03-27 19:33:08 +00:00
|
|
|
aiFace *pFace( NULL );
|
|
|
|
if ( rFaceIdx < pMesh->mNumFaces ) {
|
2010-09-26 15:56:52 +00:00
|
|
|
pFace = &pMesh->mFaces[ rFaceIdx ];
|
|
|
|
rFaceIdx++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pFace;
|
|
|
|
}
|
|
|
|
|
2010-11-05 18:45:42 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Imports a texture file.
|
|
|
|
bool Q3BSPFileImporter::importTextureFromArchive( const Q3BSP::Q3BSPModel *pModel,
|
2014-03-27 19:33:08 +00:00
|
|
|
Q3BSP::Q3BSPZipArchive *pArchive, aiScene*,
|
|
|
|
aiMaterial *pMatHelper, int textureId ) {
|
|
|
|
if ( NULL == pArchive || NULL == pArchive || NULL == pMatHelper ) {
|
2010-11-05 18:45:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-27 19:33:08 +00:00
|
|
|
if ( textureId < 0 || textureId >= static_cast<int>( pModel->m_Textures.size() ) ) {
|
2010-11-05 18:45:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool res = true;
|
|
|
|
sQ3BSPTexture *pTexture = pModel->m_Textures[ textureId ];
|
2014-03-27 19:33:08 +00:00
|
|
|
if ( !pTexture ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> supportedExtensions;
|
|
|
|
supportedExtensions.push_back( ".jpg" );
|
|
|
|
supportedExtensions.push_back( ".png" );
|
|
|
|
supportedExtensions.push_back( ".tga" );
|
2011-04-03 17:22:36 +00:00
|
|
|
std::string textureName, ext;
|
2014-03-27 19:33:08 +00:00
|
|
|
if ( expandFile( pArchive, pTexture->strName, supportedExtensions, textureName, ext ) ) {
|
2010-11-05 18:45:42 +00:00
|
|
|
IOStream *pTextureStream = pArchive->Open( textureName.c_str() );
|
2014-03-27 19:33:08 +00:00
|
|
|
if ( !pTextureStream ) {
|
2010-11-05 18:45:42 +00:00
|
|
|
size_t texSize = pTextureStream->FileSize();
|
|
|
|
aiTexture *pTexture = new aiTexture;
|
|
|
|
pTexture->mHeight = 0;
|
|
|
|
pTexture->mWidth = texSize;
|
|
|
|
unsigned char *pData = new unsigned char[ pTexture->mWidth ];
|
|
|
|
size_t readSize = pTextureStream->Read( pData, sizeof( unsigned char ), pTexture->mWidth );
|
2011-06-09 14:29:32 +00:00
|
|
|
(void)readSize;
|
2010-11-05 18:45:42 +00:00
|
|
|
ai_assert( readSize == pTexture->mWidth );
|
|
|
|
pTexture->pcData = reinterpret_cast<aiTexel*>( pData );
|
2012-11-05 09:13:09 +00:00
|
|
|
pTexture->achFormatHint[ 0 ] = ext[ 1 ];
|
|
|
|
pTexture->achFormatHint[ 1 ] = ext[ 2 ];
|
|
|
|
pTexture->achFormatHint[ 2 ] = ext[ 3 ];
|
|
|
|
pTexture->achFormatHint[ 3 ] = '\0';
|
2010-11-05 18:45:42 +00:00
|
|
|
res = true;
|
|
|
|
|
|
|
|
aiString name;
|
|
|
|
name.data[ 0 ] = '*';
|
|
|
|
name.length = 1 + ASSIMP_itoa10( name.data + 1, MAXLEN-1, mTextures.size() );
|
|
|
|
|
|
|
|
pArchive->Close( pTextureStream );
|
|
|
|
|
|
|
|
pMatHelper->AddProperty( &name, AI_MATKEY_TEXTURE_DIFFUSE( 0 ) );
|
|
|
|
mTextures.push_back( pTexture );
|
2014-03-27 19:33:08 +00:00
|
|
|
} else {
|
2011-04-03 17:22:36 +00:00
|
|
|
// 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 ) );
|
|
|
|
}
|
2010-11-05 18:45:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2011-03-31 21:41:28 +00:00
|
|
|
// Imports a light map file.
|
2010-11-05 18:45:42 +00:00
|
|
|
bool Q3BSPFileImporter::importLightmap( const Q3BSP::Q3BSPModel *pModel, aiScene* pScene,
|
2011-08-22 20:22:51 +00:00
|
|
|
aiMaterial *pMatHelper, int lightmapId )
|
2010-11-05 18:45:42 +00:00
|
|
|
{
|
|
|
|
if ( NULL == pModel || NULL == pScene || NULL == pMatHelper )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( lightmapId < 0 || lightmapId >= static_cast<int>( pModel->m_Lightmaps.size() ) )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
sQ3BSPLightmap *pLightMap = pModel->m_Lightmaps[ lightmapId ];
|
|
|
|
if ( NULL == pLightMap )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
aiTexture *pTexture = new aiTexture;
|
|
|
|
|
2011-04-03 17:22:36 +00:00
|
|
|
pTexture->mWidth = CE_BSP_LIGHTMAPWIDTH;
|
|
|
|
pTexture->mHeight = CE_BSP_LIGHTMAPHEIGHT;
|
|
|
|
pTexture->pcData = new aiTexel[CE_BSP_LIGHTMAPWIDTH * CE_BSP_LIGHTMAPHEIGHT];
|
2010-11-05 18:45:42 +00:00
|
|
|
|
2011-04-03 17:22:36 +00:00
|
|
|
::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;
|
|
|
|
}
|
|
|
|
|
2010-11-05 18:45:42 +00:00
|
|
|
aiString name;
|
|
|
|
name.data[ 0 ] = '*';
|
|
|
|
name.length = 1 + ASSIMP_itoa10( name.data + 1, MAXLEN-1, mTextures.size() );
|
|
|
|
|
|
|
|
pMatHelper->AddProperty( &name,AI_MATKEY_TEXTURE_LIGHTMAP( 1 ) );
|
|
|
|
mTextures.push_back( pTexture );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2011-05-11 17:28:12 +00:00
|
|
|
|
2010-11-05 18:45:42 +00:00
|
|
|
|
2011-04-03 17:22:36 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2010-06-18 17:36:46 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
} // Namespace Assimp
|
|
|
|
|
|
|
|
#endif // ASSIMP_BUILD_NO_Q3BSP_IMPORTER
|