2015-05-19 03:48:29 +00:00
|
|
|
/*
|
|
|
|
Open Asset Import Library (assimp)
|
|
|
|
---------------------------------------------------------------------------------------------------
|
|
|
|
|
2022-01-10 20:13:43 +00:00
|
|
|
Copyright (c) 2006-2022, assimp team
|
2018-01-28 18:42:05 +00:00
|
|
|
|
2017-05-09 17:57:36 +00:00
|
|
|
|
2015-05-19 03:48:29 +00:00
|
|
|
All rights reserved.
|
|
|
|
|
2015-05-19 03:52:10 +00:00
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the
|
2015-05-19 03:48:29 +00:00
|
|
|
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.
|
|
|
|
|
|
|
|
* Neither the name of the assimp team, nor the names of its
|
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
|
|
|
written permission of the assimp team.
|
|
|
|
|
2015-05-19 03:52:10 +00:00
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
2015-05-19 03:48:29 +00:00
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
2015-05-19 03:52:10 +00:00
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
2015-05-19 03:48:29 +00:00
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
2015-05-19 03:52:10 +00:00
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
2015-05-19 03:48:29 +00:00
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
2015-05-19 03:52:10 +00:00
|
|
|
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
|
2015-05-19 03:48:29 +00:00
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
---------------------------------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ASSIMP_BUILD_NO_Q3BSP_IMPORTER
|
|
|
|
|
|
|
|
#include "Q3BSPFileImporter.h"
|
|
|
|
#include "Q3BSPFileData.h"
|
2020-06-23 19:05:42 +00:00
|
|
|
#include "Q3BSPFileParser.h"
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2018-09-26 19:19:40 +00:00
|
|
|
#include <assimp/DefaultLogger.hpp>
|
|
|
|
|
2015-05-19 03:48:29 +00:00
|
|
|
#ifdef ASSIMP_BUILD_NO_OWN_ZLIB
|
2020-06-23 19:05:42 +00:00
|
|
|
#include <zlib.h>
|
2015-05-19 03:48:29 +00:00
|
|
|
#else
|
2020-06-23 19:05:42 +00:00
|
|
|
#include "../contrib/zlib/zlib.h"
|
2015-05-19 03:48:29 +00:00
|
|
|
#endif
|
|
|
|
|
2017-02-28 02:31:56 +00:00
|
|
|
#include <assimp/DefaultIOSystem.h>
|
2020-06-23 19:05:42 +00:00
|
|
|
#include <assimp/StringComparison.h>
|
2019-07-25 09:13:53 +00:00
|
|
|
#include <assimp/ZipArchiveIOSystem.h>
|
2020-06-23 19:05:42 +00:00
|
|
|
#include <assimp/ai_assert.h>
|
2017-02-22 16:20:26 +00:00
|
|
|
#include <assimp/importerdesc.h>
|
2020-06-23 19:05:42 +00:00
|
|
|
#include <assimp/mesh.h>
|
|
|
|
#include <assimp/scene.h>
|
|
|
|
#include <assimp/types.h>
|
2015-04-15 23:00:17 +00:00
|
|
|
#include <sstream>
|
2020-06-23 19:05:42 +00:00
|
|
|
#include <vector>
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
static const aiImporterDesc desc = {
|
2015-05-19 03:57:13 +00:00
|
|
|
"Quake III BSP Importer",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
aiImporterFlags_SupportBinaryFlavour,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
2021-04-23 13:05:09 +00:00
|
|
|
"bsp pk3"
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
namespace Assimp {
|
|
|
|
|
|
|
|
using namespace Q3BSP;
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:57:13 +00:00
|
|
|
// Local function to create a material key name.
|
2020-06-23 19:05:42 +00:00
|
|
|
static void createKey(int id1, int id2, std::string &key) {
|
2015-05-19 03:57:13 +00:00
|
|
|
std::ostringstream str;
|
|
|
|
str << id1 << "." << id2;
|
2018-09-22 13:50:40 +00:00
|
|
|
key = str.str();
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:57:13 +00:00
|
|
|
// Local function to extract the texture ids from a material key-name.
|
2020-06-23 19:05:42 +00:00
|
|
|
static void extractIds(const std::string &key, int &id1, int &id2) {
|
2018-09-22 13:50:40 +00:00
|
|
|
id1 = -1;
|
|
|
|
id2 = -1;
|
|
|
|
if (key.empty()) {
|
2015-05-19 03:57:13 +00:00
|
|
|
return;
|
2018-09-22 13:50:40 +00:00
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2021-06-22 16:27:15 +00:00
|
|
|
const std::string::size_type pos = key.find('.');
|
2018-09-22 13:50:40 +00:00
|
|
|
if (std::string::npos == pos) {
|
2015-05-19 03:57:13 +00:00
|
|
|
return;
|
2018-09-22 13:50:40 +00:00
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
std::string tmp1 = key.substr(0, pos);
|
|
|
|
std::string tmp2 = key.substr(pos + 1, key.size() - pos - 1);
|
|
|
|
id1 = atoi(tmp1.c_str());
|
|
|
|
id2 = atoi(tmp2.c_str());
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:57:13 +00:00
|
|
|
// Local helper function to normalize filenames.
|
2020-06-23 19:05:42 +00:00
|
|
|
static void normalizePathName(const std::string &rPath, std::string &normalizedPath) {
|
2021-04-16 21:43:56 +00:00
|
|
|
normalizedPath = std::string();
|
2018-09-22 13:50:40 +00:00
|
|
|
if (rPath.empty()) {
|
2015-05-19 03:57:13 +00:00
|
|
|
return;
|
2018-09-22 13:50:40 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
2015-05-19 03:57:13 +00:00
|
|
|
std::string sep = "\\";
|
2015-05-19 03:48:29 +00:00
|
|
|
#else
|
2015-05-19 03:57:13 +00:00
|
|
|
std::string sep = "/";
|
2015-05-19 03:48:29 +00:00
|
|
|
#endif
|
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
static const unsigned int numDelimiters = 2;
|
2020-06-23 19:05:42 +00:00
|
|
|
const char delimiters[numDelimiters] = { '/', '\\' };
|
2018-09-22 13:50:40 +00:00
|
|
|
normalizedPath = rPath;
|
|
|
|
for (const char delimiter : delimiters) {
|
2020-06-23 19:05:42 +00:00
|
|
|
for (size_t j = 0; j < normalizedPath.size(); ++j) {
|
|
|
|
if (normalizedPath[j] == delimiter) {
|
|
|
|
normalizedPath[j] = sep[0];
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:57:13 +00:00
|
|
|
// Constructor.
|
2020-06-23 19:05:42 +00:00
|
|
|
Q3BSPFileImporter::Q3BSPFileImporter() :
|
|
|
|
m_pCurrentMesh(nullptr), m_pCurrentFace(nullptr), m_MaterialLookupMap(), mTextures() {
|
2015-05-19 03:57:13 +00:00
|
|
|
// empty
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:57:13 +00:00
|
|
|
// Destructor.
|
2015-05-19 03:48:29 +00:00
|
|
|
Q3BSPFileImporter::~Q3BSPFileImporter() {
|
2015-05-19 03:57:13 +00:00
|
|
|
// Clear face-to-material map
|
2020-06-23 19:05:42 +00:00
|
|
|
for (FaceMap::iterator it = m_MaterialLookupMap.begin(); it != m_MaterialLookupMap.end(); ++it) {
|
2015-05-19 03:57:13 +00:00
|
|
|
const std::string &matName = it->first;
|
2020-06-23 19:05:42 +00:00
|
|
|
if (!matName.empty()) {
|
2015-05-19 03:48:29 +00:00
|
|
|
delete it->second;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:57:13 +00:00
|
|
|
// Returns true, if the loader can read this.
|
2020-06-23 19:05:42 +00:00
|
|
|
bool Q3BSPFileImporter::CanRead(const std::string &rFile, IOSystem * /*pIOHandler*/, bool checkSig) const {
|
|
|
|
if (!checkSig) {
|
|
|
|
return SimpleExtensionCheck(rFile, "pk3", "bsp");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2018-09-25 18:15:48 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
return false;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:57:13 +00:00
|
|
|
// Adds extensions.
|
2020-06-23 19:05:42 +00:00
|
|
|
const aiImporterDesc *Q3BSPFileImporter::GetInfo() const {
|
2015-05-19 03:57:13 +00:00
|
|
|
return &desc;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:57:13 +00:00
|
|
|
// Import method.
|
2020-06-23 19:05:42 +00:00
|
|
|
void Q3BSPFileImporter::InternReadFile(const std::string &rFile, aiScene *scene, IOSystem *ioHandler) {
|
|
|
|
ZipArchiveIOSystem Archive(ioHandler, rFile);
|
|
|
|
if (!Archive.isOpen()) {
|
2020-08-18 16:35:08 +00:00
|
|
|
throw DeadlyImportError("Failed to open file ", rFile, ".");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
2021-04-16 21:43:56 +00:00
|
|
|
std::string archiveName, mapName;
|
2020-06-23 19:05:42 +00:00
|
|
|
separateMapName(rFile, archiveName, mapName);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
if (mapName.empty()) {
|
|
|
|
if (!findFirstMapInArchive(Archive, mapName)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
Q3BSPFileParser fileParser(mapName, &Archive);
|
2015-05-19 03:57:13 +00:00
|
|
|
Q3BSPModel *pBSPModel = fileParser.getModel();
|
2020-06-23 19:05:42 +00:00
|
|
|
if (nullptr != pBSPModel) {
|
|
|
|
CreateDataFromImport(pBSPModel, scene, &Archive);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:57:13 +00:00
|
|
|
// Separates the map name from the import name.
|
2020-06-23 19:05:42 +00:00
|
|
|
void Q3BSPFileImporter::separateMapName(const std::string &importName, std::string &archiveName, std::string &mapName) {
|
2021-04-16 21:43:56 +00:00
|
|
|
archiveName = std::string();
|
|
|
|
mapName = std::string();
|
2018-09-26 19:19:40 +00:00
|
|
|
if (importName.empty()) {
|
2015-05-19 03:57:13 +00:00
|
|
|
return;
|
2018-09-26 19:19:40 +00:00
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2021-06-22 16:27:15 +00:00
|
|
|
const std::string::size_type pos = importName.rfind(',');
|
2020-06-23 19:05:42 +00:00
|
|
|
if (std::string::npos == pos) {
|
2018-09-26 19:19:40 +00:00
|
|
|
archiveName = importName;
|
2015-05-19 03:57:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
archiveName = importName.substr(0, pos);
|
|
|
|
mapName = importName.substr(pos, importName.size() - pos - 1);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:57:13 +00:00
|
|
|
// Returns the first map in the map archive.
|
2020-06-23 19:05:42 +00:00
|
|
|
bool Q3BSPFileImporter::findFirstMapInArchive(ZipArchiveIOSystem &bspArchive, std::string &mapName) {
|
2021-04-16 21:43:56 +00:00
|
|
|
mapName = std::string();
|
2015-05-19 03:57:13 +00:00
|
|
|
std::vector<std::string> fileList;
|
2020-06-23 19:05:42 +00:00
|
|
|
bspArchive.getFileListExtension(fileList, "bsp");
|
2018-09-26 19:19:40 +00:00
|
|
|
if (fileList.empty()) {
|
2015-05-19 03:57:13 +00:00
|
|
|
return false;
|
2018-09-26 19:19:40 +00:00
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
std::vector<std::string>::iterator it(fileList.begin());
|
|
|
|
for (; it != fileList.end(); ++it) {
|
|
|
|
const 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) {
|
2018-09-26 19:19:40 +00:00
|
|
|
mapName = *it;
|
2015-05-19 03:57:13 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:57:13 +00:00
|
|
|
// Creates the assimp specific data.
|
2020-06-23 19:05:42 +00:00
|
|
|
void Q3BSPFileImporter::CreateDataFromImport(const Q3BSP::Q3BSPModel *pModel, aiScene *pScene,
|
|
|
|
ZipArchiveIOSystem *pArchive) {
|
2018-09-26 18:52:59 +00:00
|
|
|
if (nullptr == pModel || nullptr == pScene) {
|
2015-05-19 03:57:13 +00:00
|
|
|
return;
|
2018-09-26 18:52:59 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
pScene->mRootNode = new aiNode;
|
2020-06-23 19:05:42 +00:00
|
|
|
if (!pModel->m_ModelName.empty()) {
|
|
|
|
pScene->mRootNode->mName.Set(pModel->m_ModelName);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// Create the face to material relation map
|
2020-06-23 19:05:42 +00:00
|
|
|
createMaterialMap(pModel);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// Create all nodes
|
2020-06-23 19:05:42 +00:00
|
|
|
CreateNodes(pModel, pScene, pScene->mRootNode);
|
2015-05-19 03:52:10 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// Create the assigned materials
|
2020-06-23 19:05:42 +00:00
|
|
|
createMaterials(pModel, pScene, pArchive);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:57:13 +00:00
|
|
|
// Creates all assimp nodes.
|
2020-06-23 19:05:42 +00:00
|
|
|
void Q3BSPFileImporter::CreateNodes(const Q3BSP::Q3BSPModel *pModel, aiScene *pScene,
|
|
|
|
aiNode *pParent) {
|
|
|
|
if (nullptr == pModel) {
|
2015-05-19 03:57:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
unsigned int matIdx(0);
|
|
|
|
std::vector<aiMesh *> MeshArray;
|
|
|
|
std::vector<aiNode *> NodeArray;
|
|
|
|
for (FaceMapIt it = m_MaterialLookupMap.begin(); it != m_MaterialLookupMap.end(); ++it) {
|
|
|
|
std::vector<Q3BSP::sQ3BSPFace *> *pArray = (*it).second;
|
|
|
|
size_t numVerts = countData(*pArray);
|
|
|
|
if (0 != numVerts) {
|
|
|
|
aiMesh *pMesh(nullptr);
|
|
|
|
aiNode *pNode = CreateTopology(pModel, matIdx, *pArray, &pMesh);
|
|
|
|
if (nullptr != pNode) {
|
|
|
|
NodeArray.push_back(pNode);
|
|
|
|
MeshArray.push_back(pMesh);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
matIdx++;
|
|
|
|
}
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
pScene->mNumMeshes = static_cast<unsigned int>(MeshArray.size());
|
|
|
|
if (pScene->mNumMeshes > 0) {
|
|
|
|
pScene->mMeshes = new aiMesh *[pScene->mNumMeshes];
|
|
|
|
for (size_t i = 0; i < MeshArray.size(); i++) {
|
|
|
|
aiMesh *pMesh = MeshArray[i];
|
|
|
|
if (nullptr != pMesh) {
|
|
|
|
pScene->mMeshes[i] = pMesh;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-20 02:30:20 +00:00
|
|
|
pParent->mNumChildren = static_cast<unsigned int>(MeshArray.size());
|
2020-06-23 19:05:42 +00:00
|
|
|
pParent->mChildren = new aiNode *[pScene->mRootNode->mNumChildren];
|
|
|
|
for (size_t i = 0; i < NodeArray.size(); i++) {
|
|
|
|
aiNode *pNode = NodeArray[i];
|
2015-05-19 03:57:13 +00:00
|
|
|
pNode->mParent = pParent;
|
2020-06-23 19:05:42 +00:00
|
|
|
pParent->mChildren[i] = pNode;
|
|
|
|
pParent->mChildren[i]->mMeshes[0] = static_cast<unsigned int>(i);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:57:13 +00:00
|
|
|
// Creates the topology.
|
2020-06-23 19:05:42 +00:00
|
|
|
aiNode *Q3BSPFileImporter::CreateTopology(const Q3BSP::Q3BSPModel *pModel, unsigned int materialIdx,
|
|
|
|
std::vector<sQ3BSPFace *> &rArray, aiMesh **pMesh) {
|
|
|
|
size_t numVerts = countData(rArray);
|
|
|
|
if (0 == numVerts) {
|
2018-09-26 19:19:40 +00:00
|
|
|
return nullptr;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
size_t numFaces = countFaces(rArray);
|
|
|
|
if (0 == numFaces) {
|
2018-09-26 19:19:40 +00:00
|
|
|
return nullptr;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
2018-09-26 19:19:40 +00:00
|
|
|
aiMesh *mesh = new aiMesh;
|
2020-06-23 19:05:42 +00:00
|
|
|
size_t numTriangles = countTriangles(rArray);
|
2018-09-26 19:19:40 +00:00
|
|
|
mesh->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
mesh->mFaces = new aiFace[numTriangles];
|
2018-09-26 19:19:40 +00:00
|
|
|
mesh->mNumFaces = static_cast<unsigned int>(numTriangles);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2018-09-26 19:19:40 +00:00
|
|
|
mesh->mNumVertices = static_cast<unsigned int>(numVerts);
|
2020-06-23 19:05:42 +00:00
|
|
|
mesh->mVertices = new aiVector3D[numVerts];
|
|
|
|
mesh->mNormals = new aiVector3D[numVerts];
|
|
|
|
mesh->mTextureCoords[0] = new aiVector3D[numVerts];
|
|
|
|
mesh->mTextureCoords[1] = new aiVector3D[numVerts];
|
2018-09-26 19:19:40 +00:00
|
|
|
mesh->mMaterialIndex = materialIdx;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
unsigned int faceIdx = 0;
|
|
|
|
unsigned int vertIdx = 0;
|
2020-06-23 19:05:42 +00:00
|
|
|
mesh->mNumUVComponents[0] = 2;
|
|
|
|
mesh->mNumUVComponents[1] = 2;
|
|
|
|
for (std::vector<sQ3BSPFace *>::const_iterator it = rArray.begin(); it != rArray.end(); ++it) {
|
2015-05-19 03:57:13 +00:00
|
|
|
Q3BSP::sQ3BSPFace *pQ3BSPFace = *it;
|
2020-06-23 19:05:42 +00:00
|
|
|
ai_assert(nullptr != pQ3BSPFace);
|
|
|
|
if (nullptr == pQ3BSPFace) {
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
if (pQ3BSPFace->iNumOfFaceVerts > 0) {
|
|
|
|
if (pQ3BSPFace->iType == Polygon || pQ3BSPFace->iType == TriangleMesh) {
|
|
|
|
createTriangleTopology(pModel, pQ3BSPFace, mesh, faceIdx, vertIdx);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aiNode *pNode = new aiNode;
|
|
|
|
pNode->mNumMeshes = 1;
|
2020-06-23 19:05:42 +00:00
|
|
|
pNode->mMeshes = new unsigned int[1];
|
2018-09-26 19:19:40 +00:00
|
|
|
*pMesh = mesh;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
return pNode;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:57:13 +00:00
|
|
|
// Creates the triangle topology from a face array.
|
2020-06-23 19:05:42 +00:00
|
|
|
void Q3BSPFileImporter::createTriangleTopology(const Q3BSP::Q3BSPModel *pModel, sQ3BSPFace *pQ3BSPFace,
|
|
|
|
aiMesh *pMesh, unsigned int &faceIdx, unsigned int &vertIdx) {
|
|
|
|
ai_assert(faceIdx < pMesh->mNumFaces);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
m_pCurrentFace = getNextFace(pMesh, faceIdx);
|
|
|
|
if (nullptr == m_pCurrentFace) {
|
2015-05-19 03:57:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pCurrentFace->mNumIndices = 3;
|
2020-06-23 19:05:42 +00:00
|
|
|
m_pCurrentFace->mIndices = new unsigned int[m_pCurrentFace->mNumIndices];
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
size_t idx(0);
|
|
|
|
for (size_t i = 0; i < (size_t)pQ3BSPFace->iNumOfFaceVerts; ++i) {
|
|
|
|
const size_t index = pQ3BSPFace->iVertexIndex + pModel->m_Indices[pQ3BSPFace->iFaceVertexIndex + i];
|
|
|
|
if (index >= pModel->m_Vertices.size()) {
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
sQ3BSPVertex *pVertex = pModel->m_Vertices[index];
|
|
|
|
if (nullptr == pVertex) {
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
2018-09-26 18:52:59 +00:00
|
|
|
if (idx > 2) {
|
|
|
|
idx = 0;
|
|
|
|
m_pCurrentFace = getNextFace(pMesh, faceIdx);
|
|
|
|
if (nullptr != m_pCurrentFace) {
|
|
|
|
m_pCurrentFace->mNumIndices = 3;
|
|
|
|
m_pCurrentFace->mIndices = new unsigned int[3];
|
2020-06-23 19:05:42 +00:00
|
|
|
m_pCurrentFace->mIndices[idx] = vertIdx;
|
2018-09-26 18:52:59 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
pMesh->mVertices[vertIdx].Set(pVertex->vPosition.x, pVertex->vPosition.y, pVertex->vPosition.z);
|
|
|
|
pMesh->mNormals[vertIdx].Set(pVertex->vNormal.x, pVertex->vNormal.y, pVertex->vNormal.z);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
pMesh->mTextureCoords[0][vertIdx].Set(pVertex->vTexCoord.x, pVertex->vTexCoord.y, 0.0f);
|
|
|
|
pMesh->mTextureCoords[1][vertIdx].Set(pVertex->vLightmap.x, pVertex->vLightmap.y, 0.0f);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2018-09-25 18:15:48 +00:00
|
|
|
vertIdx++;
|
2015-05-19 03:57:13 +00:00
|
|
|
idx++;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:57:13 +00:00
|
|
|
// Creates all referenced materials.
|
2020-06-23 19:05:42 +00:00
|
|
|
void Q3BSPFileImporter::createMaterials(const Q3BSP::Q3BSPModel *pModel, aiScene *pScene,
|
|
|
|
ZipArchiveIOSystem *pArchive) {
|
|
|
|
if (m_MaterialLookupMap.empty()) {
|
2015-05-19 03:57:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
pScene->mMaterials = new aiMaterial *[m_MaterialLookupMap.size()];
|
2015-05-19 03:57:13 +00:00
|
|
|
aiString aiMatName;
|
2020-06-23 19:05:42 +00:00
|
|
|
int textureId(-1), lightmapId(-1);
|
|
|
|
for (FaceMapIt it = m_MaterialLookupMap.begin(); it != m_MaterialLookupMap.end();
|
|
|
|
++it) {
|
|
|
|
const std::string matName(it->first);
|
|
|
|
if (matName.empty()) {
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
aiMatName.Set(matName);
|
2015-05-19 03:57:13 +00:00
|
|
|
aiMaterial *pMatHelper = new aiMaterial;
|
2020-06-23 19:05:42 +00:00
|
|
|
pMatHelper->AddProperty(&aiMatName, AI_MATKEY_NAME);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
extractIds(matName, textureId, lightmapId);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// Adding the texture
|
2020-06-23 19:05:42 +00:00
|
|
|
if (-1 != textureId) {
|
|
|
|
sQ3BSPTexture *pTexture = pModel->m_Textures[textureId];
|
|
|
|
if (nullptr != pTexture) {
|
2021-04-16 21:43:56 +00:00
|
|
|
std::string tmp("*"), texName;
|
2015-05-19 03:57:13 +00:00
|
|
|
tmp += pTexture->strName;
|
|
|
|
tmp += ".jpg";
|
2020-06-23 19:05:42 +00:00
|
|
|
normalizePathName(tmp, texName);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
if (!importTextureFromArchive(pModel, pArchive, pScene, pMatHelper, textureId)) {
|
2021-05-13 11:05:31 +00:00
|
|
|
ASSIMP_LOG_ERROR("Cannot import texture from archive ", texName);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-23 19:05:42 +00:00
|
|
|
if (-1 != lightmapId) {
|
|
|
|
importLightmap(pModel, pScene, pMatHelper, lightmapId);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2020-06-23 19:05:42 +00:00
|
|
|
pScene->mMaterials[pScene->mNumMaterials] = pMatHelper;
|
2015-05-19 03:57:13 +00:00
|
|
|
pScene->mNumMaterials++;
|
|
|
|
}
|
2016-11-20 02:30:20 +00:00
|
|
|
pScene->mNumTextures = static_cast<unsigned int>(mTextures.size());
|
2020-06-23 19:05:42 +00:00
|
|
|
pScene->mTextures = new aiTexture *[pScene->mNumTextures];
|
|
|
|
std::copy(mTextures.begin(), mTextures.end(), pScene->mTextures);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:57:13 +00:00
|
|
|
// Counts the number of referenced vertices.
|
2020-06-23 19:05:42 +00:00
|
|
|
size_t Q3BSPFileImporter::countData(const std::vector<sQ3BSPFace *> &faceArray) const {
|
|
|
|
size_t numVerts(0);
|
|
|
|
for (std::vector<sQ3BSPFace *>::const_iterator it = faceArray.begin(); it != faceArray.end();
|
|
|
|
++it) {
|
2015-05-19 03:57:13 +00:00
|
|
|
sQ3BSPFace *pQ3BSPFace = *it;
|
2020-06-23 19:05:42 +00:00
|
|
|
if (pQ3BSPFace->iType == Polygon || pQ3BSPFace->iType == TriangleMesh) {
|
2020-03-08 20:24:01 +00:00
|
|
|
Q3BSP::sQ3BSPFace *face = *it;
|
|
|
|
if (nullptr != face) {
|
|
|
|
numVerts += face->iNumOfFaceVerts;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return numVerts;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:57:13 +00:00
|
|
|
// Counts the faces with vertices.
|
2020-06-23 19:05:42 +00:00
|
|
|
size_t Q3BSPFileImporter::countFaces(const std::vector<Q3BSP::sQ3BSPFace *> &rArray) const {
|
2015-05-19 03:57:13 +00:00
|
|
|
size_t numFaces = 0;
|
2020-06-23 19:05:42 +00:00
|
|
|
for (std::vector<sQ3BSPFace *>::const_iterator it = rArray.begin(); it != rArray.end();
|
|
|
|
++it) {
|
2015-05-19 03:57:13 +00:00
|
|
|
Q3BSP::sQ3BSPFace *pQ3BSPFace = *it;
|
2020-06-23 19:05:42 +00:00
|
|
|
if (pQ3BSPFace->iNumOfFaceVerts > 0) {
|
2015-05-19 03:57:13 +00:00
|
|
|
numFaces++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return numFaces;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:57:13 +00:00
|
|
|
// Counts the number of triangles in a Q3-face-array.
|
2020-06-23 19:05:42 +00:00
|
|
|
size_t Q3BSPFileImporter::countTriangles(const std::vector<Q3BSP::sQ3BSPFace *> &rArray) const {
|
2015-05-19 03:57:13 +00:00
|
|
|
size_t numTriangles = 0;
|
2020-06-23 19:05:42 +00:00
|
|
|
for (std::vector<Q3BSP::sQ3BSPFace *>::const_iterator it = rArray.begin(); it != rArray.end();
|
|
|
|
++it) {
|
2015-05-19 03:57:13 +00:00
|
|
|
const Q3BSP::sQ3BSPFace *pQ3BSPFace = *it;
|
2020-06-23 19:05:42 +00:00
|
|
|
if (nullptr != pQ3BSPFace) {
|
2015-05-19 03:57:13 +00:00
|
|
|
numTriangles += pQ3BSPFace->iNumOfFaceVerts / 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return numTriangles;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:57:13 +00:00
|
|
|
// Creates the faces-to-material map.
|
2020-06-23 19:05:42 +00:00
|
|
|
void Q3BSPFileImporter::createMaterialMap(const Q3BSP::Q3BSPModel *pModel) {
|
2021-04-16 21:43:56 +00:00
|
|
|
std::string key;
|
2020-06-23 19:05:42 +00:00
|
|
|
std::vector<sQ3BSPFace *> *pCurFaceArray = nullptr;
|
|
|
|
for (size_t idx = 0; idx < pModel->m_Faces.size(); idx++) {
|
|
|
|
Q3BSP::sQ3BSPFace *pQ3BSPFace = pModel->m_Faces[idx];
|
2015-05-19 03:57:13 +00:00
|
|
|
const int texId = pQ3BSPFace->iTextureID;
|
|
|
|
const int lightMapId = pQ3BSPFace->iLightmapID;
|
2020-06-23 19:05:42 +00:00
|
|
|
createKey(texId, lightMapId, key);
|
|
|
|
FaceMapIt it = m_MaterialLookupMap.find(key);
|
|
|
|
if (m_MaterialLookupMap.end() == it) {
|
|
|
|
pCurFaceArray = new std::vector<Q3BSP::sQ3BSPFace *>;
|
|
|
|
m_MaterialLookupMap[key] = pCurFaceArray;
|
|
|
|
} else {
|
2015-05-19 03:57:13 +00:00
|
|
|
pCurFaceArray = (*it).second;
|
|
|
|
}
|
2020-06-23 19:05:42 +00:00
|
|
|
ai_assert(nullptr != pCurFaceArray);
|
|
|
|
if (nullptr != pCurFaceArray) {
|
|
|
|
pCurFaceArray->push_back(pQ3BSPFace);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:57:13 +00:00
|
|
|
// Returns the next face.
|
2020-06-23 19:05:42 +00:00
|
|
|
aiFace *Q3BSPFileImporter::getNextFace(aiMesh *mesh, unsigned int &faceIdx) {
|
|
|
|
aiFace *face(nullptr);
|
|
|
|
if (faceIdx < mesh->mNumFaces) {
|
|
|
|
face = &mesh->mFaces[faceIdx];
|
2018-09-25 18:15:48 +00:00
|
|
|
++faceIdx;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2018-09-25 18:15:48 +00:00
|
|
|
return face;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:57:13 +00:00
|
|
|
// Imports a texture file.
|
2020-06-23 19:05:42 +00:00
|
|
|
bool Q3BSPFileImporter::importTextureFromArchive(const Q3BSP::Q3BSPModel *model,
|
|
|
|
ZipArchiveIOSystem *archive, aiScene *,
|
|
|
|
aiMaterial *pMatHelper, int textureId) {
|
|
|
|
if (nullptr == archive || nullptr == pMatHelper) {
|
2015-05-19 03:57:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
if (textureId < 0 || textureId >= static_cast<int>(model->m_Textures.size())) {
|
2015-05-19 03:57:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool res = true;
|
2020-06-23 19:05:42 +00:00
|
|
|
sQ3BSPTexture *pTexture = model->m_Textures[textureId];
|
|
|
|
if (!pTexture) {
|
2015-05-19 03:57:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> supportedExtensions;
|
2020-06-23 19:05:42 +00:00
|
|
|
supportedExtensions.push_back(".jpg");
|
|
|
|
supportedExtensions.push_back(".png");
|
|
|
|
supportedExtensions.push_back(".tga");
|
2015-05-19 03:57:13 +00:00
|
|
|
std::string textureName, ext;
|
2020-06-23 19:05:42 +00:00
|
|
|
if (expandFile(archive, pTexture->strName, supportedExtensions, textureName, ext)) {
|
|
|
|
IOStream *pTextureStream = archive->Open(textureName.c_str());
|
|
|
|
if (pTextureStream) {
|
2015-05-19 03:57:13 +00:00
|
|
|
size_t texSize = pTextureStream->FileSize();
|
2020-03-08 20:24:01 +00:00
|
|
|
aiTexture *curTexture = new aiTexture;
|
|
|
|
curTexture->mHeight = 0;
|
|
|
|
curTexture->mWidth = static_cast<unsigned int>(texSize);
|
|
|
|
unsigned char *pData = new unsigned char[curTexture->mWidth];
|
|
|
|
size_t readSize = pTextureStream->Read(pData, sizeof(unsigned char), curTexture->mWidth);
|
2015-05-19 03:57:13 +00:00
|
|
|
(void)readSize;
|
2020-03-08 20:24:01 +00:00
|
|
|
ai_assert(readSize == curTexture->mWidth);
|
|
|
|
curTexture->pcData = reinterpret_cast<aiTexel *>(pData);
|
|
|
|
curTexture->achFormatHint[0] = ext[1];
|
|
|
|
curTexture->achFormatHint[1] = ext[2];
|
|
|
|
curTexture->achFormatHint[2] = ext[3];
|
|
|
|
curTexture->achFormatHint[3] = '\0';
|
2015-05-19 03:57:13 +00:00
|
|
|
res = true;
|
|
|
|
|
|
|
|
aiString name;
|
2020-06-23 19:05:42 +00:00
|
|
|
name.data[0] = '*';
|
|
|
|
name.length = 1 + ASSIMP_itoa10(name.data + 1, static_cast<unsigned int>(MAXLEN - 1), static_cast<int32_t>(mTextures.size()));
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
archive->Close(pTextureStream);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
pMatHelper->AddProperty(&name, AI_MATKEY_TEXTURE_DIFFUSE(0));
|
2020-03-08 20:24:01 +00:00
|
|
|
mTextures.push_back(curTexture);
|
2015-05-19 03:57:13 +00:00
|
|
|
} 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;
|
2020-06-23 19:05:42 +00:00
|
|
|
strncpy(name.data, pTexture->strName, sizeof name.data);
|
|
|
|
name.length = static_cast<ai_uint32>(strlen(name.data));
|
|
|
|
pMatHelper->AddProperty(&name, AI_MATKEY_TEXTURE_DIFFUSE(0));
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:57:13 +00:00
|
|
|
// Imports a light map file.
|
2020-06-23 19:05:42 +00:00
|
|
|
bool Q3BSPFileImporter::importLightmap(const Q3BSP::Q3BSPModel *pModel, aiScene *pScene,
|
|
|
|
aiMaterial *pMatHelper, int lightmapId) {
|
|
|
|
if (nullptr == pModel || nullptr == pScene || nullptr == pMatHelper) {
|
2015-05-19 03:57:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
if (lightmapId < 0 || lightmapId >= static_cast<int>(pModel->m_Lightmaps.size())) {
|
2015-05-19 03:57:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
sQ3BSPLightmap *pLightMap = pModel->m_Lightmaps[lightmapId];
|
|
|
|
if (nullptr == pLightMap) {
|
2015-05-19 03:57:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
aiTexture *pTexture = new aiTexture;
|
|
|
|
|
|
|
|
pTexture->mWidth = CE_BSP_LIGHTMAPWIDTH;
|
|
|
|
pTexture->mHeight = CE_BSP_LIGHTMAPHEIGHT;
|
|
|
|
pTexture->pcData = new aiTexel[CE_BSP_LIGHTMAPWIDTH * CE_BSP_LIGHTMAPHEIGHT];
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
::memcpy(pTexture->pcData, pLightMap->bLMapData, pTexture->mWidth);
|
2015-05-19 03:57:13 +00:00
|
|
|
size_t p = 0;
|
2020-06-23 19:05:42 +00:00
|
|
|
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;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
aiString name;
|
2020-06-23 19:05:42 +00:00
|
|
|
name.data[0] = '*';
|
|
|
|
name.length = 1 + ASSIMP_itoa10(name.data + 1, static_cast<unsigned int>(MAXLEN - 1), static_cast<int32_t>(mTextures.size()));
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
pMatHelper->AddProperty(&name, AI_MATKEY_TEXTURE_LIGHTMAP(1));
|
|
|
|
mTextures.push_back(pTexture);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
return true;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:57:13 +00:00
|
|
|
// Will search for a supported extension.
|
2019-07-25 09:13:53 +00:00
|
|
|
bool Q3BSPFileImporter::expandFile(ZipArchiveIOSystem *pArchive, const std::string &rFilename,
|
2020-06-23 19:05:42 +00:00
|
|
|
const std::vector<std::string> &rExtList, std::string &rFile,
|
|
|
|
std::string &rExt) {
|
|
|
|
ai_assert(nullptr != pArchive);
|
|
|
|
ai_assert(!rFilename.empty());
|
|
|
|
|
|
|
|
if (rExtList.empty()) {
|
|
|
|
rFile = rFilename;
|
2021-04-16 21:43:56 +00:00
|
|
|
rExt = std::string();
|
2015-05-19 03:57:13 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool found = false;
|
2020-06-23 19:05:42 +00:00
|
|
|
for (std::vector<std::string>::const_iterator it = rExtList.begin(); it != rExtList.end(); ++it) {
|
2015-05-19 03:57:13 +00:00
|
|
|
const std::string textureName = rFilename + *it;
|
2020-06-23 19:05:42 +00:00
|
|
|
if (pArchive->Exists(textureName.c_str())) {
|
2015-05-19 03:57:13 +00:00
|
|
|
rExt = *it;
|
|
|
|
rFile = textureName;
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return found;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
} // Namespace Assimp
|
|
|
|
|
|
|
|
#endif // ASSIMP_BUILD_NO_Q3BSP_IMPORTER
|