mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-11 14:44:36 +00:00
Update Assimp from 5.2.3 to 5.2.5
This commit is contained in:
parent
ea7ca63301
commit
16f3710058
379 changed files with 14469 additions and 47175 deletions
|
|
@ -137,9 +137,7 @@ ObjExporter::ObjExporter(const char* _filename, const aiScene* pScene, bool noMt
|
|||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
ObjExporter::~ObjExporter() {
|
||||
// empty
|
||||
}
|
||||
ObjExporter::~ObjExporter() = default;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
std::string ObjExporter::GetMaterialLibName() {
|
||||
|
|
@ -271,12 +269,12 @@ void ObjExporter::WriteGeometryFile(bool noMtl) {
|
|||
if ( !useVc ) {
|
||||
mOutput << "# " << vp.size() << " vertex positions" << endl;
|
||||
for ( const vertexData& v : vp ) {
|
||||
mOutput << "v " << v.vp.x << " " << v.vp.y << " " << v.vp.z << endl;
|
||||
mOutput << "v " << v.vp.x << " " << v.vp.y << " " << v.vp.z << endl;
|
||||
}
|
||||
} else {
|
||||
mOutput << "# " << vp.size() << " vertex positions and colors" << endl;
|
||||
for ( const vertexData& v : vp ) {
|
||||
mOutput << "v " << v.vp.x << " " << v.vp.y << " " << v.vp.z << " " << v.vc.r << " " << v.vc.g << " " << v.vc.b << endl;
|
||||
mOutput << "v " << v.vp.x << " " << v.vp.y << " " << v.vp.z << " " << v.vc.r << " " << v.vc.g << " " << v.vc.b << endl;
|
||||
}
|
||||
}
|
||||
mOutput << endl;
|
||||
|
|
@ -333,7 +331,7 @@ void ObjExporter::WriteGeometryFile(bool noMtl) {
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ObjExporter::AddMesh(const aiString& name, const aiMesh* m, const aiMatrix4x4& mat) {
|
||||
mMeshes.push_back(MeshInstance() );
|
||||
mMeshes.emplace_back();
|
||||
MeshInstance& mesh = mMeshes.back();
|
||||
|
||||
if ( nullptr != m->mColors[ 0 ] ) {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
Copyright (c) 2006-2022, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -47,6 +47,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <assimp/types.h>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include "Common/Maybe.h"
|
||||
|
||||
namespace Assimp {
|
||||
namespace ObjFile {
|
||||
|
|
@ -63,7 +64,7 @@ struct Face {
|
|||
using IndexArray = std::vector<unsigned int>;
|
||||
|
||||
//! Primitive type
|
||||
aiPrimitiveType m_PrimitiveType;
|
||||
aiPrimitiveType mPrimitiveType;
|
||||
//! Vertex indices
|
||||
IndexArray m_vertices;
|
||||
//! Normal indices
|
||||
|
|
@ -75,14 +76,12 @@ struct Face {
|
|||
|
||||
//! \brief Default constructor
|
||||
Face(aiPrimitiveType pt = aiPrimitiveType_POLYGON) :
|
||||
m_PrimitiveType(pt), m_vertices(), m_normals(), m_texturCoords(), m_pMaterial(0L) {
|
||||
mPrimitiveType(pt), m_vertices(), m_normals(), m_texturCoords(), m_pMaterial(nullptr) {
|
||||
// empty
|
||||
}
|
||||
|
||||
//! \brief Destructor
|
||||
~Face() {
|
||||
// empty
|
||||
}
|
||||
~Face() = default;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
|
@ -183,15 +182,15 @@ struct Material {
|
|||
aiColor3D transparent;
|
||||
|
||||
//! PBR Roughness
|
||||
ai_real roughness;
|
||||
Maybe<ai_real> roughness;
|
||||
//! PBR Metallic
|
||||
ai_real metallic;
|
||||
Maybe<ai_real> metallic;
|
||||
//! PBR Metallic
|
||||
aiColor3D sheen;
|
||||
Maybe<aiColor3D> sheen;
|
||||
//! PBR Clearcoat Thickness
|
||||
ai_real clearcoat_thickness;
|
||||
Maybe<ai_real> clearcoat_thickness;
|
||||
//! PBR Clearcoat Rougness
|
||||
ai_real clearcoat_roughness;
|
||||
Maybe<ai_real> clearcoat_roughness;
|
||||
//! PBR Anisotropy
|
||||
ai_real anisotropy;
|
||||
|
||||
|
|
@ -206,11 +205,11 @@ struct Material {
|
|||
illumination_model(1),
|
||||
ior(ai_real(1.0)),
|
||||
transparent(ai_real(1.0), ai_real(1.0), ai_real(1.0)),
|
||||
roughness(ai_real(1.0)),
|
||||
metallic(ai_real(0.0)),
|
||||
sheen(ai_real(1.0), ai_real(1.0), ai_real(1.0)),
|
||||
clearcoat_thickness(ai_real(0.0)),
|
||||
clearcoat_roughness(ai_real(0.0)),
|
||||
roughness(),
|
||||
metallic(),
|
||||
sheen(),
|
||||
clearcoat_thickness(),
|
||||
clearcoat_roughness(),
|
||||
anisotropy(ai_real(0.0)),
|
||||
bump_multiplier(ai_real(1.0)) {
|
||||
std::fill_n(clamp, static_cast<unsigned int>(TextureTypeCount), false);
|
||||
|
|
@ -229,7 +228,7 @@ struct Mesh {
|
|||
/// The name for the mesh
|
||||
std::string m_name;
|
||||
/// Array with pointer to all stored faces
|
||||
std::vector<Face *> m_Faces;
|
||||
std::vector<Face*> m_Faces;
|
||||
/// Assigned material
|
||||
Material *m_pMaterial;
|
||||
/// Number of stored indices.
|
||||
|
|
@ -272,65 +271,65 @@ struct Model {
|
|||
using ConstGroupMapIt = std::map<std::string, std::vector<unsigned int> *>::const_iterator;
|
||||
|
||||
//! Model name
|
||||
std::string m_ModelName;
|
||||
std::string mModelName;
|
||||
//! List ob assigned objects
|
||||
std::vector<Object *> m_Objects;
|
||||
std::vector<Object *> mObjects;
|
||||
//! Pointer to current object
|
||||
ObjFile::Object *m_pCurrent;
|
||||
ObjFile::Object *mCurrentObject;
|
||||
//! Pointer to current material
|
||||
ObjFile::Material *m_pCurrentMaterial;
|
||||
ObjFile::Material *mCurrentMaterial;
|
||||
//! Pointer to default material
|
||||
ObjFile::Material *m_pDefaultMaterial;
|
||||
ObjFile::Material *mDefaultMaterial;
|
||||
//! Vector with all generated materials
|
||||
std::vector<std::string> m_MaterialLib;
|
||||
std::vector<std::string> mMaterialLib;
|
||||
//! Vector with all generated vertices
|
||||
std::vector<aiVector3D> m_Vertices;
|
||||
std::vector<aiVector3D> mVertices;
|
||||
//! vector with all generated normals
|
||||
std::vector<aiVector3D> m_Normals;
|
||||
std::vector<aiVector3D> mNormals;
|
||||
//! vector with all vertex colors
|
||||
std::vector<aiVector3D> m_VertexColors;
|
||||
std::vector<aiVector3D> mVertexColors;
|
||||
//! Group map
|
||||
GroupMap m_Groups;
|
||||
GroupMap mGroups;
|
||||
//! Group to face id assignment
|
||||
std::vector<unsigned int> *m_pGroupFaceIDs;
|
||||
std::vector<unsigned int> *mGroupFaceIDs;
|
||||
//! Active group
|
||||
std::string m_strActiveGroup;
|
||||
std::string mActiveGroup;
|
||||
//! Vector with generated texture coordinates
|
||||
std::vector<aiVector3D> m_TextureCoord;
|
||||
std::vector<aiVector3D> mTextureCoord;
|
||||
//! Maximum dimension of texture coordinates
|
||||
unsigned int m_TextureCoordDim;
|
||||
unsigned int mTextureCoordDim;
|
||||
//! Current mesh instance
|
||||
Mesh *m_pCurrentMesh;
|
||||
Mesh *mCurrentMesh;
|
||||
//! Vector with stored meshes
|
||||
std::vector<Mesh *> m_Meshes;
|
||||
std::vector<Mesh *> mMeshes;
|
||||
//! Material map
|
||||
std::map<std::string, Material *> m_MaterialMap;
|
||||
std::map<std::string, Material*> mMaterialMap;
|
||||
|
||||
//! \brief The default class constructor
|
||||
Model() :
|
||||
m_ModelName(),
|
||||
m_pCurrent(nullptr),
|
||||
m_pCurrentMaterial(nullptr),
|
||||
m_pDefaultMaterial(nullptr),
|
||||
m_pGroupFaceIDs(nullptr),
|
||||
m_strActiveGroup(),
|
||||
m_TextureCoordDim(0),
|
||||
m_pCurrentMesh(nullptr) {
|
||||
mModelName(),
|
||||
mCurrentObject(nullptr),
|
||||
mCurrentMaterial(nullptr),
|
||||
mDefaultMaterial(nullptr),
|
||||
mGroupFaceIDs(nullptr),
|
||||
mActiveGroup(),
|
||||
mTextureCoordDim(0),
|
||||
mCurrentMesh(nullptr) {
|
||||
// empty
|
||||
}
|
||||
|
||||
//! \brief The class destructor
|
||||
~Model() {
|
||||
for (auto & it : m_Objects) {
|
||||
for (auto & it : mObjects) {
|
||||
delete it;
|
||||
}
|
||||
for (auto & Meshe : m_Meshes) {
|
||||
for (auto & Meshe : mMeshes) {
|
||||
delete Meshe;
|
||||
}
|
||||
for (auto & Group : m_Groups) {
|
||||
for (auto & Group : mGroups) {
|
||||
delete Group.second;
|
||||
}
|
||||
for (auto & it : m_MaterialMap) {
|
||||
for (auto & it : mMaterialMap) {
|
||||
delete it.second;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -163,20 +163,20 @@ void ObjFileImporter::CreateDataFromImport(const ObjFile::Model *pModel, aiScene
|
|||
|
||||
// Create the root node of the scene
|
||||
pScene->mRootNode = new aiNode;
|
||||
if (!pModel->m_ModelName.empty()) {
|
||||
if (!pModel->mModelName.empty()) {
|
||||
// Set the name of the scene
|
||||
pScene->mRootNode->mName.Set(pModel->m_ModelName);
|
||||
pScene->mRootNode->mName.Set(pModel->mModelName);
|
||||
} else {
|
||||
// This is a fatal error, so break down the application
|
||||
ai_assert(false);
|
||||
}
|
||||
|
||||
if (!pModel->m_Objects.empty()) {
|
||||
if (!pModel->mObjects.empty()) {
|
||||
|
||||
unsigned int meshCount = 0;
|
||||
unsigned int childCount = 0;
|
||||
|
||||
for (auto object : pModel->m_Objects) {
|
||||
for (auto object : pModel->mObjects) {
|
||||
if (object) {
|
||||
++childCount;
|
||||
meshCount += (unsigned int)object->m_Meshes.size();
|
||||
|
|
@ -189,8 +189,8 @@ void ObjFileImporter::CreateDataFromImport(const ObjFile::Model *pModel, aiScene
|
|||
// Create nodes for the whole scene
|
||||
std::vector<aiMesh *> MeshArray;
|
||||
MeshArray.reserve(meshCount);
|
||||
for (size_t index = 0; index < pModel->m_Objects.size(); ++index) {
|
||||
createNodes(pModel, pModel->m_Objects[index], pScene->mRootNode, pScene, MeshArray);
|
||||
for (size_t index = 0; index < pModel->mObjects.size(); ++index) {
|
||||
createNodes(pModel, pModel->mObjects[index], pScene->mRootNode, pScene, MeshArray);
|
||||
}
|
||||
|
||||
ai_assert(pScene->mRootNode->mNumChildren == childCount);
|
||||
|
|
@ -206,31 +206,31 @@ void ObjFileImporter::CreateDataFromImport(const ObjFile::Model *pModel, aiScene
|
|||
// Create all materials
|
||||
createMaterials(pModel, pScene);
|
||||
} else {
|
||||
if (pModel->m_Vertices.empty()) {
|
||||
if (pModel->mVertices.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr<aiMesh> mesh(new aiMesh);
|
||||
mesh->mPrimitiveTypes = aiPrimitiveType_POINT;
|
||||
unsigned int n = (unsigned int)pModel->m_Vertices.size();
|
||||
unsigned int n = (unsigned int)pModel->mVertices.size();
|
||||
mesh->mNumVertices = n;
|
||||
|
||||
mesh->mVertices = new aiVector3D[n];
|
||||
memcpy(mesh->mVertices, pModel->m_Vertices.data(), n * sizeof(aiVector3D));
|
||||
memcpy(mesh->mVertices, pModel->mVertices.data(), n * sizeof(aiVector3D));
|
||||
|
||||
if (!pModel->m_Normals.empty()) {
|
||||
if (!pModel->mNormals.empty()) {
|
||||
mesh->mNormals = new aiVector3D[n];
|
||||
if (pModel->m_Normals.size() < n) {
|
||||
if (pModel->mNormals.size() < n) {
|
||||
throw DeadlyImportError("OBJ: vertex normal index out of range");
|
||||
}
|
||||
memcpy(mesh->mNormals, pModel->m_Normals.data(), n * sizeof(aiVector3D));
|
||||
memcpy(mesh->mNormals, pModel->mNormals.data(), n * sizeof(aiVector3D));
|
||||
}
|
||||
|
||||
if (!pModel->m_VertexColors.empty()) {
|
||||
if (!pModel->mVertexColors.empty()) {
|
||||
mesh->mColors[0] = new aiColor4D[mesh->mNumVertices];
|
||||
for (unsigned int i = 0; i < n; ++i) {
|
||||
if (i < pModel->m_VertexColors.size()) {
|
||||
const aiVector3D &color = pModel->m_VertexColors[i];
|
||||
if (i < pModel->mVertexColors.size()) {
|
||||
const aiVector3D &color = pModel->mVertexColors[i];
|
||||
mesh->mColors[0][i] = aiColor4D(color.x, color.y, color.z, 1.0);
|
||||
} else {
|
||||
throw DeadlyImportError("OBJ: vertex color index out of range");
|
||||
|
|
@ -315,7 +315,7 @@ aiMesh *ObjFileImporter::createTopology(const ObjFile::Model *pModel, const ObjF
|
|||
}
|
||||
|
||||
// Create faces
|
||||
ObjFile::Mesh *pObjMesh = pModel->m_Meshes[meshIndex];
|
||||
ObjFile::Mesh *pObjMesh = pModel->mMeshes[meshIndex];
|
||||
if (!pObjMesh) {
|
||||
return nullptr;
|
||||
}
|
||||
|
|
@ -330,13 +330,13 @@ aiMesh *ObjFileImporter::createTopology(const ObjFile::Model *pModel, const ObjF
|
|||
}
|
||||
|
||||
for (size_t index = 0; index < pObjMesh->m_Faces.size(); index++) {
|
||||
ObjFile::Face *const inp = pObjMesh->m_Faces[index];
|
||||
ai_assert(nullptr != inp);
|
||||
const ObjFile::Face *inp = pObjMesh->m_Faces[index];
|
||||
//ai_assert(nullptr != inp);
|
||||
|
||||
if (inp->m_PrimitiveType == aiPrimitiveType_LINE) {
|
||||
if (inp->mPrimitiveType == aiPrimitiveType_LINE) {
|
||||
pMesh->mNumFaces += static_cast<unsigned int>(inp->m_vertices.size() - 1);
|
||||
pMesh->mPrimitiveTypes |= aiPrimitiveType_LINE;
|
||||
} else if (inp->m_PrimitiveType == aiPrimitiveType_POINT) {
|
||||
} else if (inp->mPrimitiveType == aiPrimitiveType_POINT) {
|
||||
pMesh->mNumFaces += static_cast<unsigned int>(inp->m_vertices.size());
|
||||
pMesh->mPrimitiveTypes |= aiPrimitiveType_POINT;
|
||||
} else {
|
||||
|
|
@ -360,15 +360,15 @@ aiMesh *ObjFileImporter::createTopology(const ObjFile::Model *pModel, const ObjF
|
|||
|
||||
// Copy all data from all stored meshes
|
||||
for (auto &face : pObjMesh->m_Faces) {
|
||||
ObjFile::Face *const inp = face;
|
||||
if (inp->m_PrimitiveType == aiPrimitiveType_LINE) {
|
||||
const ObjFile::Face *inp = face;
|
||||
if (inp->mPrimitiveType == aiPrimitiveType_LINE) {
|
||||
for (size_t i = 0; i < inp->m_vertices.size() - 1; ++i) {
|
||||
aiFace &f = pMesh->mFaces[outIndex++];
|
||||
uiIdxCount += f.mNumIndices = 2;
|
||||
f.mIndices = new unsigned int[2];
|
||||
}
|
||||
continue;
|
||||
} else if (inp->m_PrimitiveType == aiPrimitiveType_POINT) {
|
||||
} else if (inp->mPrimitiveType == aiPrimitiveType_POINT) {
|
||||
for (size_t i = 0; i < inp->m_vertices.size(); ++i) {
|
||||
aiFace &f = pMesh->mFaces[outIndex++];
|
||||
uiIdxCount += f.mNumIndices = 1;
|
||||
|
|
@ -407,7 +407,7 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model *pModel,
|
|||
return;
|
||||
|
||||
// Get current mesh
|
||||
ObjFile::Mesh *pObjMesh = pModel->m_Meshes[uiMeshIndex];
|
||||
ObjFile::Mesh *pObjMesh = pModel->mMeshes[uiMeshIndex];
|
||||
if (nullptr == pObjMesh || pObjMesh->m_uiNumIndices < 1) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -422,16 +422,16 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model *pModel,
|
|||
pMesh->mVertices = new aiVector3D[pMesh->mNumVertices];
|
||||
|
||||
// Allocate buffer for normal vectors
|
||||
if (!pModel->m_Normals.empty() && pObjMesh->m_hasNormals)
|
||||
if (!pModel->mNormals.empty() && pObjMesh->m_hasNormals)
|
||||
pMesh->mNormals = new aiVector3D[pMesh->mNumVertices];
|
||||
|
||||
// Allocate buffer for vertex-color vectors
|
||||
if (!pModel->m_VertexColors.empty())
|
||||
if (!pModel->mVertexColors.empty())
|
||||
pMesh->mColors[0] = new aiColor4D[pMesh->mNumVertices];
|
||||
|
||||
// Allocate buffer for texture coordinates
|
||||
if (!pModel->m_TextureCoord.empty() && pObjMesh->m_uiUVCoordinates[0]) {
|
||||
pMesh->mNumUVComponents[0] = pModel->m_TextureCoordDim;
|
||||
if (!pModel->mTextureCoord.empty() && pObjMesh->m_uiUVCoordinates[0]) {
|
||||
pMesh->mNumUVComponents[0] = pModel->mTextureCoordDim;
|
||||
pMesh->mTextureCoords[0] = new aiVector3D[pMesh->mNumVertices];
|
||||
}
|
||||
|
||||
|
|
@ -442,7 +442,7 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model *pModel,
|
|||
// Copy all index arrays
|
||||
for (size_t vertexIndex = 0, outVertexIndex = 0; vertexIndex < sourceFace->m_vertices.size(); vertexIndex++) {
|
||||
const unsigned int vertex = sourceFace->m_vertices.at(vertexIndex);
|
||||
if (vertex >= pModel->m_Vertices.size()) {
|
||||
if (vertex >= pModel->mVertices.size()) {
|
||||
throw DeadlyImportError("OBJ: vertex index out of range");
|
||||
}
|
||||
|
||||
|
|
@ -450,32 +450,32 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model *pModel,
|
|||
throw DeadlyImportError("OBJ: bad vertex index");
|
||||
}
|
||||
|
||||
pMesh->mVertices[newIndex] = pModel->m_Vertices[vertex];
|
||||
pMesh->mVertices[newIndex] = pModel->mVertices[vertex];
|
||||
|
||||
// Copy all normals
|
||||
if (normalsok && !pModel->m_Normals.empty() && vertexIndex < sourceFace->m_normals.size()) {
|
||||
if (normalsok && !pModel->mNormals.empty() && vertexIndex < sourceFace->m_normals.size()) {
|
||||
const unsigned int normal = sourceFace->m_normals.at(vertexIndex);
|
||||
if (normal >= pModel->m_Normals.size()) {
|
||||
if (normal >= pModel->mNormals.size()) {
|
||||
normalsok = false;
|
||||
} else {
|
||||
pMesh->mNormals[newIndex] = pModel->m_Normals[normal];
|
||||
pMesh->mNormals[newIndex] = pModel->mNormals[normal];
|
||||
}
|
||||
}
|
||||
|
||||
// Copy all vertex colors
|
||||
if (vertex < pModel->m_VertexColors.size()) {
|
||||
const aiVector3D &color = pModel->m_VertexColors[vertex];
|
||||
if (vertex < pModel->mVertexColors.size()) {
|
||||
const aiVector3D &color = pModel->mVertexColors[vertex];
|
||||
pMesh->mColors[0][newIndex] = aiColor4D(color.x, color.y, color.z, 1.0);
|
||||
}
|
||||
|
||||
// Copy all texture coordinates
|
||||
if (uvok && !pModel->m_TextureCoord.empty() && vertexIndex < sourceFace->m_texturCoords.size()) {
|
||||
if (uvok && !pModel->mTextureCoord.empty() && vertexIndex < sourceFace->m_texturCoords.size()) {
|
||||
const unsigned int tex = sourceFace->m_texturCoords.at(vertexIndex);
|
||||
|
||||
if (tex >= pModel->m_TextureCoord.size()) {
|
||||
if (tex >= pModel->mTextureCoord.size()) {
|
||||
uvok = false;
|
||||
} else {
|
||||
const aiVector3D &coord3d = pModel->m_TextureCoord[tex];
|
||||
const aiVector3D &coord3d = pModel->mTextureCoord[tex];
|
||||
pMesh->mTextureCoords[0][newIndex] = aiVector3D(coord3d.x, coord3d.y, coord3d.z);
|
||||
}
|
||||
}
|
||||
|
|
@ -484,15 +484,15 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model *pModel,
|
|||
aiFace *pDestFace = &pMesh->mFaces[outIndex];
|
||||
|
||||
const bool last = (vertexIndex == sourceFace->m_vertices.size() - 1);
|
||||
if (sourceFace->m_PrimitiveType != aiPrimitiveType_LINE || !last) {
|
||||
if (sourceFace->mPrimitiveType != aiPrimitiveType_LINE || !last) {
|
||||
pDestFace->mIndices[outVertexIndex] = newIndex;
|
||||
outVertexIndex++;
|
||||
}
|
||||
|
||||
if (sourceFace->m_PrimitiveType == aiPrimitiveType_POINT) {
|
||||
if (sourceFace->mPrimitiveType == aiPrimitiveType_POINT) {
|
||||
outIndex++;
|
||||
outVertexIndex = 0;
|
||||
} else if (sourceFace->m_PrimitiveType == aiPrimitiveType_LINE) {
|
||||
} else if (sourceFace->mPrimitiveType == aiPrimitiveType_LINE) {
|
||||
outVertexIndex = 0;
|
||||
|
||||
if (!last)
|
||||
|
|
@ -501,10 +501,10 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model *pModel,
|
|||
if (vertexIndex) {
|
||||
if (!last) {
|
||||
pMesh->mVertices[newIndex + 1] = pMesh->mVertices[newIndex];
|
||||
if (!sourceFace->m_normals.empty() && !pModel->m_Normals.empty()) {
|
||||
if (!sourceFace->m_normals.empty() && !pModel->mNormals.empty()) {
|
||||
pMesh->mNormals[newIndex + 1] = pMesh->mNormals[newIndex];
|
||||
}
|
||||
if (!pModel->m_TextureCoord.empty()) {
|
||||
if (!pModel->mTextureCoord.empty()) {
|
||||
for (size_t i = 0; i < pMesh->GetNumUVChannels(); i++) {
|
||||
pMesh->mTextureCoords[i][newIndex + 1] = pMesh->mTextureCoords[i][newIndex];
|
||||
}
|
||||
|
|
@ -565,9 +565,9 @@ void ObjFileImporter::createMaterials(const ObjFile::Model *pModel, aiScene *pSc
|
|||
return;
|
||||
}
|
||||
|
||||
const unsigned int numMaterials = (unsigned int)pModel->m_MaterialLib.size();
|
||||
const unsigned int numMaterials = (unsigned int)pModel->mMaterialLib.size();
|
||||
pScene->mNumMaterials = 0;
|
||||
if (pModel->m_MaterialLib.empty()) {
|
||||
if (pModel->mMaterialLib.empty()) {
|
||||
ASSIMP_LOG_DEBUG("OBJ: no materials specified");
|
||||
return;
|
||||
}
|
||||
|
|
@ -576,10 +576,10 @@ void ObjFileImporter::createMaterials(const ObjFile::Model *pModel, aiScene *pSc
|
|||
for (unsigned int matIndex = 0; matIndex < numMaterials; matIndex++) {
|
||||
// Store material name
|
||||
std::map<std::string, ObjFile::Material *>::const_iterator it;
|
||||
it = pModel->m_MaterialMap.find(pModel->m_MaterialLib[matIndex]);
|
||||
it = pModel->mMaterialMap.find(pModel->mMaterialLib[matIndex]);
|
||||
|
||||
// No material found, use the default material
|
||||
if (pModel->m_MaterialMap.end() == it)
|
||||
if (pModel->mMaterialMap.end() == it)
|
||||
continue;
|
||||
|
||||
aiMaterial *mat = new aiMaterial;
|
||||
|
|
@ -616,11 +616,16 @@ void ObjFileImporter::createMaterials(const ObjFile::Model *pModel, aiScene *pSc
|
|||
mat->AddProperty(&pCurrentMaterial->shineness, 1, AI_MATKEY_SHININESS);
|
||||
mat->AddProperty(&pCurrentMaterial->alpha, 1, AI_MATKEY_OPACITY);
|
||||
mat->AddProperty(&pCurrentMaterial->transparent, 1, AI_MATKEY_COLOR_TRANSPARENT);
|
||||
mat->AddProperty(&pCurrentMaterial->roughness, 1, AI_MATKEY_ROUGHNESS_FACTOR);
|
||||
mat->AddProperty(&pCurrentMaterial->metallic, 1, AI_MATKEY_METALLIC_FACTOR);
|
||||
mat->AddProperty(&pCurrentMaterial->sheen, 1, AI_MATKEY_SHEEN_COLOR_FACTOR);
|
||||
mat->AddProperty(&pCurrentMaterial->clearcoat_thickness, 1, AI_MATKEY_CLEARCOAT_FACTOR);
|
||||
mat->AddProperty(&pCurrentMaterial->clearcoat_roughness, 1, AI_MATKEY_CLEARCOAT_ROUGHNESS_FACTOR);
|
||||
if (pCurrentMaterial->roughness)
|
||||
mat->AddProperty(&pCurrentMaterial->roughness.Get(), 1, AI_MATKEY_ROUGHNESS_FACTOR);
|
||||
if (pCurrentMaterial->metallic)
|
||||
mat->AddProperty(&pCurrentMaterial->metallic.Get(), 1, AI_MATKEY_METALLIC_FACTOR);
|
||||
if (pCurrentMaterial->sheen)
|
||||
mat->AddProperty(&pCurrentMaterial->sheen.Get(), 1, AI_MATKEY_SHEEN_COLOR_FACTOR);
|
||||
if (pCurrentMaterial->clearcoat_thickness)
|
||||
mat->AddProperty(&pCurrentMaterial->clearcoat_thickness.Get(), 1, AI_MATKEY_CLEARCOAT_FACTOR);
|
||||
if (pCurrentMaterial->clearcoat_roughness)
|
||||
mat->AddProperty(&pCurrentMaterial->clearcoat_roughness.Get(), 1, AI_MATKEY_CLEARCOAT_ROUGHNESS_FACTOR);
|
||||
mat->AddProperty(&pCurrentMaterial->anisotropy, 1, AI_MATKEY_ANISOTROPY_FACTOR);
|
||||
|
||||
// Adding refraction index
|
||||
|
|
|
|||
|
|
@ -99,18 +99,16 @@ ObjFileMtlImporter::ObjFileMtlImporter(std::vector<char> &buffer,
|
|||
ai_assert(nullptr != m_pModel);
|
||||
m_buffer.resize(BUFFERSIZE);
|
||||
std::fill(m_buffer.begin(), m_buffer.end(), '\0');
|
||||
if (nullptr == m_pModel->m_pDefaultMaterial) {
|
||||
m_pModel->m_pDefaultMaterial = new ObjFile::Material;
|
||||
m_pModel->m_pDefaultMaterial->MaterialName.Set("default");
|
||||
if (nullptr == m_pModel->mDefaultMaterial) {
|
||||
m_pModel->mDefaultMaterial = new ObjFile::Material;
|
||||
m_pModel->mDefaultMaterial->MaterialName.Set("default");
|
||||
}
|
||||
load();
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Destructor
|
||||
ObjFileMtlImporter::~ObjFileMtlImporter() {
|
||||
// empty
|
||||
}
|
||||
ObjFileMtlImporter::~ObjFileMtlImporter() = default;
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Loads the material description
|
||||
|
|
@ -126,17 +124,21 @@ void ObjFileMtlImporter::load() {
|
|||
if (*m_DataIt == 'a') // Ambient color
|
||||
{
|
||||
++m_DataIt;
|
||||
getColorRGBA(&m_pModel->m_pCurrentMaterial->ambient);
|
||||
if (m_pModel->mCurrentMaterial != nullptr)
|
||||
getColorRGBA(&m_pModel->mCurrentMaterial->ambient);
|
||||
} else if (*m_DataIt == 'd') {
|
||||
// Diffuse color
|
||||
++m_DataIt;
|
||||
getColorRGBA(&m_pModel->m_pCurrentMaterial->diffuse);
|
||||
if (m_pModel->mCurrentMaterial != nullptr)
|
||||
getColorRGBA(&m_pModel->mCurrentMaterial->diffuse);
|
||||
} else if (*m_DataIt == 's') {
|
||||
++m_DataIt;
|
||||
getColorRGBA(&m_pModel->m_pCurrentMaterial->specular);
|
||||
if (m_pModel->mCurrentMaterial != nullptr)
|
||||
getColorRGBA(&m_pModel->mCurrentMaterial->specular);
|
||||
} else if (*m_DataIt == 'e') {
|
||||
++m_DataIt;
|
||||
getColorRGBA(&m_pModel->m_pCurrentMaterial->emissive);
|
||||
if (m_pModel->mCurrentMaterial != nullptr)
|
||||
getColorRGBA(&m_pModel->mCurrentMaterial->emissive);
|
||||
}
|
||||
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||
} break;
|
||||
|
|
@ -145,13 +147,15 @@ void ObjFileMtlImporter::load() {
|
|||
// Material transmission color
|
||||
if (*m_DataIt == 'f') {
|
||||
++m_DataIt;
|
||||
getColorRGBA(&m_pModel->m_pCurrentMaterial->transparent);
|
||||
if (m_pModel->mCurrentMaterial != nullptr)
|
||||
getColorRGBA(&m_pModel->mCurrentMaterial->transparent);
|
||||
} else if (*m_DataIt == 'r') {
|
||||
// Material transmission alpha value
|
||||
++m_DataIt;
|
||||
ai_real d;
|
||||
getFloatValue(d);
|
||||
m_pModel->m_pCurrentMaterial->alpha = static_cast<ai_real>(1.0) - d;
|
||||
if (m_pModel->mCurrentMaterial != nullptr)
|
||||
m_pModel->mCurrentMaterial->alpha = static_cast<ai_real>(1.0) - d;
|
||||
}
|
||||
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||
} break;
|
||||
|
|
@ -162,7 +166,8 @@ void ObjFileMtlImporter::load() {
|
|||
} else {
|
||||
// Alpha value
|
||||
++m_DataIt;
|
||||
getFloatValue(m_pModel->m_pCurrentMaterial->alpha);
|
||||
if (m_pModel->mCurrentMaterial != nullptr)
|
||||
getFloatValue(m_pModel->mCurrentMaterial->alpha);
|
||||
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||
}
|
||||
} break;
|
||||
|
|
@ -173,11 +178,13 @@ void ObjFileMtlImporter::load() {
|
|||
switch (*m_DataIt) {
|
||||
case 's': // Specular exponent
|
||||
++m_DataIt;
|
||||
getFloatValue(m_pModel->m_pCurrentMaterial->shineness);
|
||||
if (m_pModel->mCurrentMaterial != nullptr)
|
||||
getFloatValue(m_pModel->mCurrentMaterial->shineness);
|
||||
break;
|
||||
case 'i': // Index Of refraction
|
||||
++m_DataIt;
|
||||
getFloatValue(m_pModel->m_pCurrentMaterial->ior);
|
||||
if (m_pModel->mCurrentMaterial != nullptr)
|
||||
getFloatValue(m_pModel->mCurrentMaterial->ior);
|
||||
break;
|
||||
case 'e': // New material
|
||||
createMaterial();
|
||||
|
|
@ -197,23 +204,28 @@ void ObjFileMtlImporter::load() {
|
|||
{
|
||||
case 'r':
|
||||
++m_DataIt;
|
||||
getFloatValue(m_pModel->m_pCurrentMaterial->roughness);
|
||||
if (m_pModel->mCurrentMaterial != nullptr)
|
||||
getFloatValue(m_pModel->mCurrentMaterial->roughness);
|
||||
break;
|
||||
case 'm':
|
||||
++m_DataIt;
|
||||
getFloatValue(m_pModel->m_pCurrentMaterial->metallic);
|
||||
if (m_pModel->mCurrentMaterial != nullptr)
|
||||
getFloatValue(m_pModel->mCurrentMaterial->metallic);
|
||||
break;
|
||||
case 's':
|
||||
++m_DataIt;
|
||||
getColorRGBA(&m_pModel->m_pCurrentMaterial->sheen);
|
||||
if (m_pModel->mCurrentMaterial != nullptr)
|
||||
getColorRGBA(m_pModel->mCurrentMaterial->sheen);
|
||||
break;
|
||||
case 'c':
|
||||
++m_DataIt;
|
||||
if (*m_DataIt == 'r') {
|
||||
++m_DataIt;
|
||||
getFloatValue(m_pModel->m_pCurrentMaterial->clearcoat_roughness);
|
||||
if (m_pModel->mCurrentMaterial != nullptr)
|
||||
getFloatValue(m_pModel->mCurrentMaterial->clearcoat_roughness);
|
||||
} else {
|
||||
getFloatValue(m_pModel->m_pCurrentMaterial->clearcoat_thickness);
|
||||
if (m_pModel->mCurrentMaterial != nullptr)
|
||||
getFloatValue(m_pModel->mCurrentMaterial->clearcoat_thickness);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -232,15 +244,17 @@ void ObjFileMtlImporter::load() {
|
|||
case 'i': // Illumination model
|
||||
{
|
||||
m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
||||
getIlluminationModel(m_pModel->m_pCurrentMaterial->illumination_model);
|
||||
if (m_pModel->mCurrentMaterial != nullptr)
|
||||
getIlluminationModel(m_pModel->mCurrentMaterial->illumination_model);
|
||||
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||
} break;
|
||||
|
||||
case 'a': // Anisotropy
|
||||
{
|
||||
++m_DataIt;
|
||||
getFloatValue(m_pModel->m_pCurrentMaterial->anisotropy);
|
||||
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||
getFloatValue(m_pModel->mCurrentMaterial->anisotropy);
|
||||
if (m_pModel->mCurrentMaterial != nullptr)
|
||||
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||
} break;
|
||||
|
||||
default: {
|
||||
|
|
@ -268,6 +282,12 @@ void ObjFileMtlImporter::getColorRGBA(aiColor3D *pColor) {
|
|||
pColor->b = b;
|
||||
}
|
||||
|
||||
void ObjFileMtlImporter::getColorRGBA(Maybe<aiColor3D> &value) {
|
||||
aiColor3D v;
|
||||
getColorRGBA(&v);
|
||||
value = Maybe<aiColor3D>(v);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Loads the kind of illumination model.
|
||||
void ObjFileMtlImporter::getIlluminationModel(int &illum_model) {
|
||||
|
|
@ -275,6 +295,7 @@ void ObjFileMtlImporter::getIlluminationModel(int &illum_model) {
|
|||
illum_model = atoi(&m_buffer[0]);
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Loads a single float value.
|
||||
void ObjFileMtlImporter::getFloatValue(ai_real &value) {
|
||||
|
|
@ -284,10 +305,19 @@ void ObjFileMtlImporter::getFloatValue(ai_real &value) {
|
|||
value = 0.0f;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
value = (ai_real)fast_atof(&m_buffer[0]);
|
||||
}
|
||||
|
||||
void ObjFileMtlImporter::getFloatValue(Maybe<ai_real> &value) {
|
||||
m_DataIt = CopyNextWord<DataArrayIt>(m_DataIt, m_DataItEnd, &m_buffer[0], BUFFERSIZE);
|
||||
size_t len = std::strlen(&m_buffer[0]);
|
||||
if (len)
|
||||
value = Maybe<ai_real>(fast_atof(&m_buffer[0]));
|
||||
else
|
||||
value = Maybe<ai_real>();
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Creates a material from loaded data.
|
||||
void ObjFileMtlImporter::createMaterial() {
|
||||
|
|
@ -313,20 +343,20 @@ void ObjFileMtlImporter::createMaterial() {
|
|||
|
||||
name = trim_whitespaces(name);
|
||||
|
||||
std::map<std::string, ObjFile::Material *>::iterator it = m_pModel->m_MaterialMap.find(name);
|
||||
if (m_pModel->m_MaterialMap.end() == it) {
|
||||
std::map<std::string, ObjFile::Material *>::iterator it = m_pModel->mMaterialMap.find(name);
|
||||
if (m_pModel->mMaterialMap.end() == it) {
|
||||
// New Material created
|
||||
m_pModel->m_pCurrentMaterial = new ObjFile::Material();
|
||||
m_pModel->m_pCurrentMaterial->MaterialName.Set(name);
|
||||
m_pModel->m_MaterialLib.push_back(name);
|
||||
m_pModel->m_MaterialMap[name] = m_pModel->m_pCurrentMaterial;
|
||||
m_pModel->mCurrentMaterial = new ObjFile::Material();
|
||||
m_pModel->mCurrentMaterial->MaterialName.Set(name);
|
||||
m_pModel->mMaterialLib.push_back(name);
|
||||
m_pModel->mMaterialMap[name] = m_pModel->mCurrentMaterial;
|
||||
|
||||
if (m_pModel->m_pCurrentMesh) {
|
||||
m_pModel->m_pCurrentMesh->m_uiMaterialIndex = static_cast<unsigned int>(m_pModel->m_MaterialLib.size() - 1);
|
||||
if (m_pModel->mCurrentMesh) {
|
||||
m_pModel->mCurrentMesh->m_uiMaterialIndex = static_cast<unsigned int>(m_pModel->mMaterialLib.size() - 1);
|
||||
}
|
||||
} else {
|
||||
// Use older material
|
||||
m_pModel->m_pCurrentMaterial = (*it).second;
|
||||
m_pModel->mCurrentMaterial = (*it).second;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -339,38 +369,38 @@ void ObjFileMtlImporter::getTexture() {
|
|||
const char *pPtr(&(*m_DataIt));
|
||||
if (!ASSIMP_strincmp(pPtr, DiffuseTexture.c_str(), static_cast<unsigned int>(DiffuseTexture.size()))) {
|
||||
// Diffuse texture
|
||||
out = &m_pModel->m_pCurrentMaterial->texture;
|
||||
out = &m_pModel->mCurrentMaterial->texture;
|
||||
clampIndex = ObjFile::Material::TextureDiffuseType;
|
||||
} else if (!ASSIMP_strincmp(pPtr, AmbientTexture.c_str(), static_cast<unsigned int>(AmbientTexture.size()))) {
|
||||
// Ambient texture
|
||||
out = &m_pModel->m_pCurrentMaterial->textureAmbient;
|
||||
out = &m_pModel->mCurrentMaterial->textureAmbient;
|
||||
clampIndex = ObjFile::Material::TextureAmbientType;
|
||||
} else if (!ASSIMP_strincmp(pPtr, SpecularTexture.c_str(), static_cast<unsigned int>(SpecularTexture.size()))) {
|
||||
// Specular texture
|
||||
out = &m_pModel->m_pCurrentMaterial->textureSpecular;
|
||||
out = &m_pModel->mCurrentMaterial->textureSpecular;
|
||||
clampIndex = ObjFile::Material::TextureSpecularType;
|
||||
} else if (!ASSIMP_strincmp(pPtr, DisplacementTexture1.c_str(), static_cast<unsigned int>(DisplacementTexture1.size())) ||
|
||||
!ASSIMP_strincmp(pPtr, DisplacementTexture2.c_str(), static_cast<unsigned int>(DisplacementTexture2.size()))) {
|
||||
// Displacement texture
|
||||
out = &m_pModel->m_pCurrentMaterial->textureDisp;
|
||||
out = &m_pModel->mCurrentMaterial->textureDisp;
|
||||
clampIndex = ObjFile::Material::TextureDispType;
|
||||
} else if (!ASSIMP_strincmp(pPtr, OpacityTexture.c_str(), static_cast<unsigned int>(OpacityTexture.size()))) {
|
||||
// Opacity texture
|
||||
out = &m_pModel->m_pCurrentMaterial->textureOpacity;
|
||||
out = &m_pModel->mCurrentMaterial->textureOpacity;
|
||||
clampIndex = ObjFile::Material::TextureOpacityType;
|
||||
} else if (!ASSIMP_strincmp(pPtr, EmissiveTexture1.c_str(), static_cast<unsigned int>(EmissiveTexture1.size())) ||
|
||||
!ASSIMP_strincmp(pPtr, EmissiveTexture2.c_str(), static_cast<unsigned int>(EmissiveTexture2.size()))) {
|
||||
// Emissive texture
|
||||
out = &m_pModel->m_pCurrentMaterial->textureEmissive;
|
||||
out = &m_pModel->mCurrentMaterial->textureEmissive;
|
||||
clampIndex = ObjFile::Material::TextureEmissiveType;
|
||||
} else if (!ASSIMP_strincmp(pPtr, BumpTexture1.c_str(), static_cast<unsigned int>(BumpTexture1.size())) ||
|
||||
!ASSIMP_strincmp(pPtr, BumpTexture2.c_str(), static_cast<unsigned int>(BumpTexture2.size()))) {
|
||||
// Bump texture
|
||||
out = &m_pModel->m_pCurrentMaterial->textureBump;
|
||||
out = &m_pModel->mCurrentMaterial->textureBump;
|
||||
clampIndex = ObjFile::Material::TextureBumpType;
|
||||
} else if (!ASSIMP_strincmp(pPtr, NormalTextureV1.c_str(), static_cast<unsigned int>(NormalTextureV1.size())) || !ASSIMP_strincmp(pPtr, NormalTextureV2.c_str(), static_cast<unsigned int>(NormalTextureV2.size()))) {
|
||||
// Normal map
|
||||
out = &m_pModel->m_pCurrentMaterial->textureNormal;
|
||||
out = &m_pModel->mCurrentMaterial->textureNormal;
|
||||
clampIndex = ObjFile::Material::TextureNormalType;
|
||||
} else if (!ASSIMP_strincmp(pPtr, ReflectionTexture.c_str(), static_cast<unsigned int>(ReflectionTexture.size()))) {
|
||||
// Reflection texture(s)
|
||||
|
|
@ -378,23 +408,23 @@ void ObjFileMtlImporter::getTexture() {
|
|||
return;
|
||||
} else if (!ASSIMP_strincmp(pPtr, SpecularityTexture.c_str(), static_cast<unsigned int>(SpecularityTexture.size()))) {
|
||||
// Specularity scaling (glossiness)
|
||||
out = &m_pModel->m_pCurrentMaterial->textureSpecularity;
|
||||
out = &m_pModel->mCurrentMaterial->textureSpecularity;
|
||||
clampIndex = ObjFile::Material::TextureSpecularityType;
|
||||
} else if ( !ASSIMP_strincmp( pPtr, RoughnessTexture.c_str(), static_cast<unsigned int>(RoughnessTexture.size()))) {
|
||||
// PBR Roughness texture
|
||||
out = & m_pModel->m_pCurrentMaterial->textureRoughness;
|
||||
out = & m_pModel->mCurrentMaterial->textureRoughness;
|
||||
clampIndex = ObjFile::Material::TextureRoughnessType;
|
||||
} else if ( !ASSIMP_strincmp( pPtr, MetallicTexture.c_str(), static_cast<unsigned int>(MetallicTexture.size()))) {
|
||||
// PBR Metallic texture
|
||||
out = & m_pModel->m_pCurrentMaterial->textureMetallic;
|
||||
out = & m_pModel->mCurrentMaterial->textureMetallic;
|
||||
clampIndex = ObjFile::Material::TextureMetallicType;
|
||||
} else if (!ASSIMP_strincmp( pPtr, SheenTexture.c_str(), static_cast<unsigned int>(SheenTexture.size()))) {
|
||||
// PBR Sheen (reflectance) texture
|
||||
out = & m_pModel->m_pCurrentMaterial->textureSheen;
|
||||
out = & m_pModel->mCurrentMaterial->textureSheen;
|
||||
clampIndex = ObjFile::Material::TextureSheenType;
|
||||
} else if (!ASSIMP_strincmp( pPtr, RMATexture.c_str(), static_cast<unsigned int>(RMATexture.size()))) {
|
||||
// PBR Rough/Metal/AO texture
|
||||
out = & m_pModel->m_pCurrentMaterial->textureRMA;
|
||||
out = & m_pModel->mCurrentMaterial->textureRMA;
|
||||
clampIndex = ObjFile::Material::TextureRMAType;
|
||||
} else {
|
||||
ASSIMP_LOG_ERROR("OBJ/MTL: Encountered unknown texture type");
|
||||
|
|
@ -403,7 +433,7 @@ void ObjFileMtlImporter::getTexture() {
|
|||
|
||||
bool clamp = false;
|
||||
getTextureOption(clamp, clampIndex, out);
|
||||
m_pModel->m_pCurrentMaterial->clamp[clampIndex] = clamp;
|
||||
m_pModel->mCurrentMaterial->clamp[clampIndex] = clamp;
|
||||
|
||||
std::string texture;
|
||||
m_DataIt = getName<DataArrayIt>(m_DataIt, m_DataItEnd, texture);
|
||||
|
|
@ -451,31 +481,31 @@ void ObjFileMtlImporter::getTextureOption(bool &clamp, int &clampIndex, aiString
|
|||
CopyNextWord(it, m_DataItEnd, value, sizeof(value) / sizeof(*value));
|
||||
if (!ASSIMP_strincmp(value, "cube_top", 8)) {
|
||||
clampIndex = ObjFile::Material::TextureReflectionCubeTopType;
|
||||
out = &m_pModel->m_pCurrentMaterial->textureReflection[0];
|
||||
out = &m_pModel->mCurrentMaterial->textureReflection[0];
|
||||
} else if (!ASSIMP_strincmp(value, "cube_bottom", 11)) {
|
||||
clampIndex = ObjFile::Material::TextureReflectionCubeBottomType;
|
||||
out = &m_pModel->m_pCurrentMaterial->textureReflection[1];
|
||||
out = &m_pModel->mCurrentMaterial->textureReflection[1];
|
||||
} else if (!ASSIMP_strincmp(value, "cube_front", 10)) {
|
||||
clampIndex = ObjFile::Material::TextureReflectionCubeFrontType;
|
||||
out = &m_pModel->m_pCurrentMaterial->textureReflection[2];
|
||||
out = &m_pModel->mCurrentMaterial->textureReflection[2];
|
||||
} else if (!ASSIMP_strincmp(value, "cube_back", 9)) {
|
||||
clampIndex = ObjFile::Material::TextureReflectionCubeBackType;
|
||||
out = &m_pModel->m_pCurrentMaterial->textureReflection[3];
|
||||
out = &m_pModel->mCurrentMaterial->textureReflection[3];
|
||||
} else if (!ASSIMP_strincmp(value, "cube_left", 9)) {
|
||||
clampIndex = ObjFile::Material::TextureReflectionCubeLeftType;
|
||||
out = &m_pModel->m_pCurrentMaterial->textureReflection[4];
|
||||
out = &m_pModel->mCurrentMaterial->textureReflection[4];
|
||||
} else if (!ASSIMP_strincmp(value, "cube_right", 10)) {
|
||||
clampIndex = ObjFile::Material::TextureReflectionCubeRightType;
|
||||
out = &m_pModel->m_pCurrentMaterial->textureReflection[5];
|
||||
out = &m_pModel->mCurrentMaterial->textureReflection[5];
|
||||
} else if (!ASSIMP_strincmp(value, "sphere", 6)) {
|
||||
clampIndex = ObjFile::Material::TextureReflectionSphereType;
|
||||
out = &m_pModel->m_pCurrentMaterial->textureReflection[0];
|
||||
out = &m_pModel->mCurrentMaterial->textureReflection[0];
|
||||
}
|
||||
|
||||
skipToken = 2;
|
||||
} else if (!ASSIMP_strincmp(pPtr, BumpOption.c_str(), static_cast<unsigned int>(BumpOption.size()))) {
|
||||
DataArrayIt it = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
||||
getFloat(it, m_DataItEnd, m_pModel->m_pCurrentMaterial->bump_multiplier);
|
||||
getFloat(it, m_DataItEnd, m_pModel->mCurrentMaterial->bump_multiplier);
|
||||
skipToken = 2;
|
||||
} else if (!ASSIMP_strincmp(pPtr, BlendUOption.c_str(), static_cast<unsigned int>(BlendUOption.size())) || !ASSIMP_strincmp(pPtr, BlendVOption.c_str(), static_cast<unsigned int>(BlendVOption.size())) || !ASSIMP_strincmp(pPtr, BoostOption.c_str(), static_cast<unsigned int>(BoostOption.size())) || !ASSIMP_strincmp(pPtr, ResolutionOption.c_str(), static_cast<unsigned int>(ResolutionOption.size())) || !ASSIMP_strincmp(pPtr, ChannelOption.c_str(), static_cast<unsigned int>(ChannelOption.size()))) {
|
||||
skipToken = 2;
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <assimp/defs.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "Common/Maybe.h"
|
||||
|
||||
struct aiColor3D;
|
||||
struct aiString;
|
||||
|
|
@ -81,10 +82,12 @@ private:
|
|||
void load();
|
||||
/// Get color data.
|
||||
void getColorRGBA(aiColor3D *pColor);
|
||||
void getColorRGBA(Maybe<aiColor3D> &value);
|
||||
/// Get illumination model from loaded data
|
||||
void getIlluminationModel(int &illum_model);
|
||||
/// Gets a float value from data.
|
||||
void getFloatValue(ai_real &value);
|
||||
void getFloatValue(Maybe<ai_real> &value);
|
||||
/// Creates a new material from loaded data.
|
||||
void createMaterial();
|
||||
/// Get texture name from loaded data.
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
Copyright (c) 2006-2022, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -52,10 +52,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <cstdlib>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <string_view>
|
||||
|
||||
namespace Assimp {
|
||||
|
||||
constexpr char ObjFileParser::DEFAULT_MATERIAL[];
|
||||
constexpr const char ObjFileParser::DEFAULT_MATERIAL[];
|
||||
|
||||
ObjFileParser::ObjFileParser() :
|
||||
m_DataIt(),
|
||||
|
|
@ -84,20 +85,19 @@ ObjFileParser::ObjFileParser(IOStreamBuffer<char> &streamBuffer, const std::stri
|
|||
|
||||
// Create the model instance to store all the data
|
||||
m_pModel.reset(new ObjFile::Model());
|
||||
m_pModel->m_ModelName = modelName;
|
||||
m_pModel->mModelName = modelName;
|
||||
|
||||
// create default material and store it
|
||||
m_pModel->m_pDefaultMaterial = new ObjFile::Material;
|
||||
m_pModel->m_pDefaultMaterial->MaterialName.Set(DEFAULT_MATERIAL);
|
||||
m_pModel->m_MaterialLib.push_back(DEFAULT_MATERIAL);
|
||||
m_pModel->m_MaterialMap[DEFAULT_MATERIAL] = m_pModel->m_pDefaultMaterial;
|
||||
m_pModel->mDefaultMaterial = new ObjFile::Material;
|
||||
m_pModel->mDefaultMaterial->MaterialName.Set(DEFAULT_MATERIAL);
|
||||
m_pModel->mMaterialLib.emplace_back(DEFAULT_MATERIAL);
|
||||
m_pModel->mMaterialMap[DEFAULT_MATERIAL] = m_pModel->mDefaultMaterial;
|
||||
|
||||
// Start parsing the file
|
||||
parseFile(streamBuffer);
|
||||
}
|
||||
|
||||
ObjFileParser::~ObjFileParser() {
|
||||
}
|
||||
ObjFileParser::~ObjFileParser() = default;
|
||||
|
||||
void ObjFileParser::setBuffer(std::vector<char> &buffer) {
|
||||
m_DataIt = buffer.begin();
|
||||
|
|
@ -111,7 +111,6 @@ ObjFile::Model *ObjFileParser::GetModel() const {
|
|||
void ObjFileParser::parseFile(IOStreamBuffer<char> &streamBuffer) {
|
||||
// only update every 100KB or it'll be too slow
|
||||
//const unsigned int updateProgressEveryBytes = 100 * 1024;
|
||||
unsigned int progressCounter = 0;
|
||||
const unsigned int bytesToProcess = static_cast<unsigned int>(streamBuffer.size());
|
||||
const unsigned int progressTotal = bytesToProcess;
|
||||
unsigned int processed = 0;
|
||||
|
|
@ -128,7 +127,6 @@ void ObjFileParser::parseFile(IOStreamBuffer<char> &streamBuffer) {
|
|||
if (lastFilePos < filePos) {
|
||||
processed = static_cast<unsigned int>(filePos);
|
||||
lastFilePos = filePos;
|
||||
progressCounter++;
|
||||
m_progress->UpdateFileRead(processed, progressTotal);
|
||||
}
|
||||
|
||||
|
|
@ -153,23 +151,23 @@ void ObjFileParser::parseFile(IOStreamBuffer<char> &streamBuffer) {
|
|||
size_t numComponents = getNumComponentsInDataDefinition();
|
||||
if (numComponents == 3) {
|
||||
// read in vertex definition
|
||||
getVector3(m_pModel->m_Vertices);
|
||||
getVector3(m_pModel->mVertices);
|
||||
} else if (numComponents == 4) {
|
||||
// read in vertex definition (homogeneous coords)
|
||||
getHomogeneousVector3(m_pModel->m_Vertices);
|
||||
getHomogeneousVector3(m_pModel->mVertices);
|
||||
} else if (numComponents == 6) {
|
||||
// read vertex and vertex-color
|
||||
getTwoVectors3(m_pModel->m_Vertices, m_pModel->m_VertexColors);
|
||||
getTwoVectors3(m_pModel->mVertices, m_pModel->mVertexColors);
|
||||
}
|
||||
} else if (*m_DataIt == 't') {
|
||||
// read in texture coordinate ( 2D or 3D )
|
||||
++m_DataIt;
|
||||
size_t dim = getTexCoordVector(m_pModel->m_TextureCoord);
|
||||
m_pModel->m_TextureCoordDim = std::max(m_pModel->m_TextureCoordDim, (unsigned int)dim);
|
||||
size_t dim = getTexCoordVector(m_pModel->mTextureCoord);
|
||||
m_pModel->mTextureCoordDim = std::max(m_pModel->mTextureCoordDim, (unsigned int)dim);
|
||||
} else if (*m_DataIt == 'n') {
|
||||
// Read in normal vector definition
|
||||
++m_DataIt;
|
||||
getVector3(m_pModel->m_Normals);
|
||||
getVector3(m_pModel->mNormals);
|
||||
}
|
||||
} break;
|
||||
|
||||
|
|
@ -424,7 +422,7 @@ void ObjFileParser::getVector2(std::vector<aiVector2D> &point2d_array) {
|
|||
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||
}
|
||||
|
||||
static const std::string DefaultObjName = "defaultobject";
|
||||
static constexpr char DefaultObjName[] = "defaultobject";
|
||||
|
||||
void ObjFileParser::getFace(aiPrimitiveType type) {
|
||||
m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
||||
|
|
@ -435,12 +433,12 @@ void ObjFileParser::getFace(aiPrimitiveType type) {
|
|||
ObjFile::Face *face = new ObjFile::Face(type);
|
||||
bool hasNormal = false;
|
||||
|
||||
const int vSize = static_cast<unsigned int>(m_pModel->m_Vertices.size());
|
||||
const int vtSize = static_cast<unsigned int>(m_pModel->m_TextureCoord.size());
|
||||
const int vnSize = static_cast<unsigned int>(m_pModel->m_Normals.size());
|
||||
const int vSize = static_cast<unsigned int>(m_pModel->mVertices.size());
|
||||
const int vtSize = static_cast<unsigned int>(m_pModel->mTextureCoord.size());
|
||||
const int vnSize = static_cast<unsigned int>(m_pModel->mNormals.size());
|
||||
|
||||
const bool vt = (!m_pModel->m_TextureCoord.empty());
|
||||
const bool vn = (!m_pModel->m_Normals.empty());
|
||||
const bool vt = (!m_pModel->mTextureCoord.empty());
|
||||
const bool vn = (!m_pModel->mNormals.empty());
|
||||
int iPos = 0;
|
||||
while (m_DataIt != m_DataItEnd) {
|
||||
int iStep = 1;
|
||||
|
|
@ -458,8 +456,9 @@ void ObjFileParser::getFace(aiPrimitiveType type) {
|
|||
iPos = 0;
|
||||
} else {
|
||||
//OBJ USES 1 Base ARRAYS!!!!
|
||||
const int iVal(::atoi(&(*m_DataIt)));
|
||||
|
||||
const char *token = &(*m_DataIt);
|
||||
const int iVal = ::atoi(token);
|
||||
|
||||
// increment iStep position based off of the sign and # of digits
|
||||
int tmp = iVal;
|
||||
if (iVal < 0) {
|
||||
|
|
@ -499,7 +498,7 @@ void ObjFileParser::getFace(aiPrimitiveType type) {
|
|||
} else {
|
||||
//On error, std::atoi will return 0 which is not a valid value
|
||||
delete face;
|
||||
throw DeadlyImportError("OBJ: Invalid face indice");
|
||||
throw DeadlyImportError("OBJ: Invalid face index.");
|
||||
}
|
||||
}
|
||||
m_DataIt += iStep;
|
||||
|
|
@ -514,28 +513,28 @@ void ObjFileParser::getFace(aiPrimitiveType type) {
|
|||
}
|
||||
|
||||
// Set active material, if one set
|
||||
if (nullptr != m_pModel->m_pCurrentMaterial) {
|
||||
face->m_pMaterial = m_pModel->m_pCurrentMaterial;
|
||||
if (nullptr != m_pModel->mCurrentMaterial) {
|
||||
face->m_pMaterial = m_pModel->mCurrentMaterial;
|
||||
} else {
|
||||
face->m_pMaterial = m_pModel->m_pDefaultMaterial;
|
||||
face->m_pMaterial = m_pModel->mDefaultMaterial;
|
||||
}
|
||||
|
||||
// Create a default object, if nothing is there
|
||||
if (nullptr == m_pModel->m_pCurrent) {
|
||||
if (nullptr == m_pModel->mCurrentObject) {
|
||||
createObject(DefaultObjName);
|
||||
}
|
||||
|
||||
// Assign face to mesh
|
||||
if (nullptr == m_pModel->m_pCurrentMesh) {
|
||||
if (nullptr == m_pModel->mCurrentMesh) {
|
||||
createMesh(DefaultObjName);
|
||||
}
|
||||
|
||||
// Store the face
|
||||
m_pModel->m_pCurrentMesh->m_Faces.push_back(face);
|
||||
m_pModel->m_pCurrentMesh->m_uiNumIndices += (unsigned int)face->m_vertices.size();
|
||||
m_pModel->m_pCurrentMesh->m_uiUVCoordinates[0] += (unsigned int)face->m_texturCoords.size();
|
||||
if (!m_pModel->m_pCurrentMesh->m_hasNormals && hasNormal) {
|
||||
m_pModel->m_pCurrentMesh->m_hasNormals = true;
|
||||
m_pModel->mCurrentMesh->m_Faces.emplace_back(face);
|
||||
m_pModel->mCurrentMesh->m_uiNumIndices += static_cast<unsigned int>(face->m_vertices.size());
|
||||
m_pModel->mCurrentMesh->m_uiUVCoordinates[0] += static_cast<unsigned int>(face->m_texturCoords.size());
|
||||
if (!m_pModel->mCurrentMesh->m_hasNormals && hasNormal) {
|
||||
m_pModel->mCurrentMesh->m_hasNormals = true;
|
||||
}
|
||||
// Skip the rest of the line
|
||||
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||
|
|
@ -564,33 +563,33 @@ void ObjFileParser::getMaterialDesc() {
|
|||
|
||||
// If the current mesh has the same material, we simply ignore that 'usemtl' command
|
||||
// There is no need to create another object or even mesh here
|
||||
if (m_pModel->m_pCurrentMaterial && m_pModel->m_pCurrentMaterial->MaterialName == aiString(strName)) {
|
||||
if (m_pModel->mCurrentMaterial && m_pModel->mCurrentMaterial->MaterialName == aiString(strName)) {
|
||||
skip = true;
|
||||
}
|
||||
|
||||
if (!skip) {
|
||||
// Search for material
|
||||
std::map<std::string, ObjFile::Material *>::iterator it = m_pModel->m_MaterialMap.find(strName);
|
||||
if (it == m_pModel->m_MaterialMap.end()) {
|
||||
std::map<std::string, ObjFile::Material *>::iterator it = m_pModel->mMaterialMap.find(strName);
|
||||
if (it == m_pModel->mMaterialMap.end()) {
|
||||
// Not found, so we don't know anything about the material except for its name.
|
||||
// This may be the case if the material library is missing. We don't want to lose all
|
||||
// materials if that happens, so create a new named material instead of discarding it
|
||||
// completely.
|
||||
ASSIMP_LOG_ERROR("OBJ: failed to locate material ", strName, ", creating new material");
|
||||
m_pModel->m_pCurrentMaterial = new ObjFile::Material();
|
||||
m_pModel->m_pCurrentMaterial->MaterialName.Set(strName);
|
||||
m_pModel->m_MaterialLib.push_back(strName);
|
||||
m_pModel->m_MaterialMap[strName] = m_pModel->m_pCurrentMaterial;
|
||||
m_pModel->mCurrentMaterial = new ObjFile::Material();
|
||||
m_pModel->mCurrentMaterial->MaterialName.Set(strName);
|
||||
m_pModel->mMaterialLib.push_back(strName);
|
||||
m_pModel->mMaterialMap[strName] = m_pModel->mCurrentMaterial;
|
||||
} else {
|
||||
// Found, using detected material
|
||||
m_pModel->m_pCurrentMaterial = (*it).second;
|
||||
m_pModel->mCurrentMaterial = (*it).second;
|
||||
}
|
||||
|
||||
if (needsNewMesh(strName)) {
|
||||
createMesh(strName);
|
||||
}
|
||||
|
||||
m_pModel->m_pCurrentMesh->m_uiMaterialIndex = getMaterialIndex(strName);
|
||||
m_pModel->mCurrentMesh->m_uiMaterialIndex = getMaterialIndex(strName);
|
||||
}
|
||||
|
||||
// Skip rest of line
|
||||
|
|
@ -677,17 +676,17 @@ void ObjFileParser::getNewMaterial() {
|
|||
while (m_DataIt != m_DataItEnd && IsSpaceOrNewLine(*m_DataIt)) {
|
||||
++m_DataIt;
|
||||
}
|
||||
std::map<std::string, ObjFile::Material *>::iterator it = m_pModel->m_MaterialMap.find(strMat);
|
||||
if (it == m_pModel->m_MaterialMap.end()) {
|
||||
std::map<std::string, ObjFile::Material *>::iterator it = m_pModel->mMaterialMap.find(strMat);
|
||||
if (it == m_pModel->mMaterialMap.end()) {
|
||||
// Show a warning, if material was not found
|
||||
ASSIMP_LOG_WARN("OBJ: Unsupported material requested: ", strMat);
|
||||
m_pModel->m_pCurrentMaterial = m_pModel->m_pDefaultMaterial;
|
||||
m_pModel->mCurrentMaterial = m_pModel->mDefaultMaterial;
|
||||
} else {
|
||||
// Set new material
|
||||
if (needsNewMesh(strMat)) {
|
||||
createMesh(strMat);
|
||||
}
|
||||
m_pModel->m_pCurrentMesh->m_uiMaterialIndex = getMaterialIndex(strMat);
|
||||
m_pModel->mCurrentMesh->m_uiMaterialIndex = getMaterialIndex(strMat);
|
||||
}
|
||||
|
||||
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||
|
|
@ -699,8 +698,8 @@ int ObjFileParser::getMaterialIndex(const std::string &strMaterialName) {
|
|||
if (strMaterialName.empty()) {
|
||||
return mat_index;
|
||||
}
|
||||
for (size_t index = 0; index < m_pModel->m_MaterialLib.size(); ++index) {
|
||||
if (strMaterialName == m_pModel->m_MaterialLib[index]) {
|
||||
for (size_t index = 0; index < m_pModel->mMaterialLib.size(); ++index) {
|
||||
if (strMaterialName == m_pModel->mMaterialLib[index]) {
|
||||
mat_index = (int)index;
|
||||
break;
|
||||
}
|
||||
|
|
@ -721,22 +720,22 @@ void ObjFileParser::getGroupName() {
|
|||
}
|
||||
|
||||
// Change active group, if necessary
|
||||
if (m_pModel->m_strActiveGroup != groupName) {
|
||||
if (m_pModel->mActiveGroup != groupName) {
|
||||
// Search for already existing entry
|
||||
ObjFile::Model::ConstGroupMapIt it = m_pModel->m_Groups.find(groupName);
|
||||
ObjFile::Model::ConstGroupMapIt it = m_pModel->mGroups.find(groupName);
|
||||
|
||||
// We are mapping groups into the object structure
|
||||
createObject(groupName);
|
||||
|
||||
// New group name, creating a new entry
|
||||
if (it == m_pModel->m_Groups.end()) {
|
||||
if (it == m_pModel->mGroups.end()) {
|
||||
std::vector<unsigned int> *pFaceIDArray = new std::vector<unsigned int>;
|
||||
m_pModel->m_Groups[groupName] = pFaceIDArray;
|
||||
m_pModel->m_pGroupFaceIDs = (pFaceIDArray);
|
||||
m_pModel->mGroups[groupName] = pFaceIDArray;
|
||||
m_pModel->mGroupFaceIDs = (pFaceIDArray);
|
||||
} else {
|
||||
m_pModel->m_pGroupFaceIDs = (*it).second;
|
||||
m_pModel->mGroupFaceIDs = (*it).second;
|
||||
}
|
||||
m_pModel->m_strActiveGroup = groupName;
|
||||
m_pModel->mActiveGroup = groupName;
|
||||
}
|
||||
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||
}
|
||||
|
|
@ -773,20 +772,20 @@ void ObjFileParser::getObjectName() {
|
|||
std::string strObjectName(pStart, &(*m_DataIt));
|
||||
if (!strObjectName.empty()) {
|
||||
// Reset current object
|
||||
m_pModel->m_pCurrent = nullptr;
|
||||
m_pModel->mCurrentObject = nullptr;
|
||||
|
||||
// Search for actual object
|
||||
for (std::vector<ObjFile::Object *>::const_iterator it = m_pModel->m_Objects.begin();
|
||||
it != m_pModel->m_Objects.end();
|
||||
for (std::vector<ObjFile::Object *>::const_iterator it = m_pModel->mObjects.begin();
|
||||
it != m_pModel->mObjects.end();
|
||||
++it) {
|
||||
if ((*it)->m_strObjName == strObjectName) {
|
||||
m_pModel->m_pCurrent = *it;
|
||||
m_pModel->mCurrentObject = *it;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Allocate a new object, if current one was not found before
|
||||
if (nullptr == m_pModel->m_pCurrent) {
|
||||
if (nullptr == m_pModel->mCurrentObject) {
|
||||
createObject(strObjectName);
|
||||
}
|
||||
}
|
||||
|
|
@ -797,16 +796,16 @@ void ObjFileParser::getObjectName() {
|
|||
void ObjFileParser::createObject(const std::string &objName) {
|
||||
ai_assert(nullptr != m_pModel);
|
||||
|
||||
m_pModel->m_pCurrent = new ObjFile::Object;
|
||||
m_pModel->m_pCurrent->m_strObjName = objName;
|
||||
m_pModel->m_Objects.push_back(m_pModel->m_pCurrent);
|
||||
m_pModel->mCurrentObject = new ObjFile::Object;
|
||||
m_pModel->mCurrentObject->m_strObjName = objName;
|
||||
m_pModel->mObjects.push_back(m_pModel->mCurrentObject);
|
||||
|
||||
createMesh(objName);
|
||||
|
||||
if (m_pModel->m_pCurrentMaterial) {
|
||||
m_pModel->m_pCurrentMesh->m_uiMaterialIndex =
|
||||
getMaterialIndex(m_pModel->m_pCurrentMaterial->MaterialName.data);
|
||||
m_pModel->m_pCurrentMesh->m_pMaterial = m_pModel->m_pCurrentMaterial;
|
||||
if (m_pModel->mCurrentMaterial) {
|
||||
m_pModel->mCurrentMesh->m_uiMaterialIndex =
|
||||
getMaterialIndex(m_pModel->mCurrentMaterial->MaterialName.data);
|
||||
m_pModel->mCurrentMesh->m_pMaterial = m_pModel->mCurrentMaterial;
|
||||
}
|
||||
}
|
||||
// -------------------------------------------------------------------
|
||||
|
|
@ -814,11 +813,11 @@ void ObjFileParser::createObject(const std::string &objName) {
|
|||
void ObjFileParser::createMesh(const std::string &meshName) {
|
||||
ai_assert(nullptr != m_pModel);
|
||||
|
||||
m_pModel->m_pCurrentMesh = new ObjFile::Mesh(meshName);
|
||||
m_pModel->m_Meshes.push_back(m_pModel->m_pCurrentMesh);
|
||||
unsigned int meshId = static_cast<unsigned int>(m_pModel->m_Meshes.size() - 1);
|
||||
if (nullptr != m_pModel->m_pCurrent) {
|
||||
m_pModel->m_pCurrent->m_Meshes.push_back(meshId);
|
||||
m_pModel->mCurrentMesh = new ObjFile::Mesh(meshName);
|
||||
m_pModel->mMeshes.push_back(m_pModel->mCurrentMesh);
|
||||
unsigned int meshId = static_cast<unsigned int>(m_pModel->mMeshes.size() - 1);
|
||||
if (nullptr != m_pModel->mCurrentObject) {
|
||||
m_pModel->mCurrentObject->m_Meshes.push_back(meshId);
|
||||
} else {
|
||||
ASSIMP_LOG_ERROR("OBJ: No object detected to attach a new mesh instance.");
|
||||
}
|
||||
|
|
@ -828,16 +827,16 @@ void ObjFileParser::createMesh(const std::string &meshName) {
|
|||
// Returns true, if a new mesh must be created.
|
||||
bool ObjFileParser::needsNewMesh(const std::string &materialName) {
|
||||
// If no mesh data yet
|
||||
if (m_pModel->m_pCurrentMesh == nullptr) {
|
||||
if (m_pModel->mCurrentMesh == nullptr) {
|
||||
return true;
|
||||
}
|
||||
bool newMat = false;
|
||||
int matIdx = getMaterialIndex(materialName);
|
||||
int curMatIdx = m_pModel->m_pCurrentMesh->m_uiMaterialIndex;
|
||||
int curMatIdx = m_pModel->mCurrentMesh->m_uiMaterialIndex;
|
||||
if (curMatIdx != int(ObjFile::Mesh::NoMaterial) && curMatIdx != matIdx
|
||||
// no need create a new mesh if no faces in current
|
||||
// lets say 'usemtl' goes straight after 'g'
|
||||
&& !m_pModel->m_pCurrentMesh->m_Faces.empty()) {
|
||||
&& !m_pModel->mCurrentMesh->m_Faces.empty()) {
|
||||
// New material -> only one material per mesh, so we need to create a new
|
||||
// material
|
||||
newMat = true;
|
||||
|
|
|
|||
|
|
@ -137,11 +137,8 @@ protected:
|
|||
void reportErrorTokenInFace();
|
||||
|
||||
private:
|
||||
// Copy and assignment constructor should be private
|
||||
// because the class contains pointer to allocated memory
|
||||
|
||||
/// Default material name
|
||||
static constexpr char DEFAULT_MATERIAL[] = AI_DEFAULT_MATERIAL_NAME;
|
||||
static constexpr const char DEFAULT_MATERIAL[] = AI_DEFAULT_MATERIAL_NAME;
|
||||
//! Iterator to current position in buffer
|
||||
DataArrayIt m_DataIt;
|
||||
//! Iterator to end position of buffer
|
||||
|
|
|
|||
|
|
@ -236,7 +236,7 @@ inline char_t CopyNextWord(char_t it, char_t end, char *pBuffer, size_t length)
|
|||
template <class char_t>
|
||||
inline char_t getFloat(char_t it, char_t end, ai_real &value) {
|
||||
static const size_t BUFFERSIZE = 1024;
|
||||
char buffer[BUFFERSIZE];
|
||||
char buffer[BUFFERSIZE] = {};
|
||||
it = CopyNextWord<char_t>(it, end, buffer, BUFFERSIZE);
|
||||
value = (ai_real)fast_atof(buffer);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue