Obj: apply clang format.
parent
0357333c81
commit
8b6f95ec30
|
@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
|
||||||
|
|
||||||
Copyright (c) 2006-2020, assimp team
|
Copyright (c) 2006-2020, assimp team
|
||||||
|
|
||||||
|
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use of this software in source and binary forms,
|
Redistribution and use of this software in source and binary forms,
|
||||||
|
@ -44,10 +43,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#ifndef OBJ_FILEDATA_H_INC
|
#ifndef OBJ_FILEDATA_H_INC
|
||||||
#define OBJ_FILEDATA_H_INC
|
#define OBJ_FILEDATA_H_INC
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <map>
|
|
||||||
#include <assimp/types.h>
|
|
||||||
#include <assimp/mesh.h>
|
#include <assimp/mesh.h>
|
||||||
|
#include <assimp/types.h>
|
||||||
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
namespace ObjFile {
|
namespace ObjFile {
|
||||||
|
@ -75,12 +74,8 @@ struct Face {
|
||||||
Material *m_pMaterial;
|
Material *m_pMaterial;
|
||||||
|
|
||||||
//! \brief Default constructor
|
//! \brief Default constructor
|
||||||
Face( aiPrimitiveType pt = aiPrimitiveType_POLYGON)
|
Face(aiPrimitiveType pt = aiPrimitiveType_POLYGON) :
|
||||||
: m_PrimitiveType( pt )
|
m_PrimitiveType(pt), m_vertices(), m_normals(), m_texturCoords(), m_pMaterial(0L) {
|
||||||
, m_vertices()
|
|
||||||
, m_normals()
|
|
||||||
, m_texturCoords()
|
|
||||||
, m_pMaterial( 0L ) {
|
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,19 +100,19 @@ struct Object {
|
||||||
//! Transformation matrix, stored in OpenGL format
|
//! Transformation matrix, stored in OpenGL format
|
||||||
aiMatrix4x4 m_Transformation;
|
aiMatrix4x4 m_Transformation;
|
||||||
//! All sub-objects referenced by this object
|
//! All sub-objects referenced by this object
|
||||||
std::vector<Object*> m_SubObjects;
|
std::vector<Object *> m_SubObjects;
|
||||||
/// Assigned meshes
|
/// Assigned meshes
|
||||||
std::vector<unsigned int> m_Meshes;
|
std::vector<unsigned int> m_Meshes;
|
||||||
|
|
||||||
//! \brief Default constructor
|
//! \brief Default constructor
|
||||||
Object()
|
Object() :
|
||||||
: m_strObjName("") {
|
m_strObjName("") {
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \brief Destructor
|
//! \brief Destructor
|
||||||
~Object() {
|
~Object() {
|
||||||
for ( std::vector<Object*>::iterator it = m_SubObjects.begin(); it != m_SubObjects.end(); ++it) {
|
for (std::vector<Object *>::iterator it = m_SubObjects.begin(); it != m_SubObjects.end(); ++it) {
|
||||||
delete *it;
|
delete *it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -184,16 +179,11 @@ struct Material {
|
||||||
aiColor3D transparent;
|
aiColor3D transparent;
|
||||||
|
|
||||||
//! Constructor
|
//! Constructor
|
||||||
Material()
|
Material() :
|
||||||
: diffuse ( ai_real( 0.6 ), ai_real( 0.6 ), ai_real( 0.6 ) )
|
diffuse(ai_real(0.6), ai_real(0.6), ai_real(0.6)), alpha(ai_real(1.0)), shineness(ai_real(0.0)), illumination_model(1), ior(ai_real(1.0)), transparent(ai_real(1.0), ai_real(1.0), ai_real(1.0)) {
|
||||||
, alpha (ai_real( 1.0 ) )
|
|
||||||
, shineness ( ai_real( 0.0) )
|
|
||||||
, illumination_model (1)
|
|
||||||
, ior ( ai_real( 1.0 ) )
|
|
||||||
, transparent( ai_real( 1.0), ai_real (1.0), ai_real(1.0)) {
|
|
||||||
// empty
|
// empty
|
||||||
for (size_t i = 0; i < TextureTypeCount; ++i) {
|
for (size_t i = 0; i < TextureTypeCount; ++i) {
|
||||||
clamp[ i ] = false;
|
clamp[i] = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,13 +202,13 @@ struct Mesh {
|
||||||
/// The name for the mesh
|
/// The name for the mesh
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
/// Array with pointer to all stored faces
|
/// Array with pointer to all stored faces
|
||||||
std::vector<Face*> m_Faces;
|
std::vector<Face *> m_Faces;
|
||||||
/// Assigned material
|
/// Assigned material
|
||||||
Material *m_pMaterial;
|
Material *m_pMaterial;
|
||||||
/// Number of stored indices.
|
/// Number of stored indices.
|
||||||
unsigned int m_uiNumIndices;
|
unsigned int m_uiNumIndices;
|
||||||
/// Number of UV
|
/// Number of UV
|
||||||
unsigned int m_uiUVCoordinates[ AI_MAX_NUMBER_OF_TEXTURECOORDS ];
|
unsigned int m_uiUVCoordinates[AI_MAX_NUMBER_OF_TEXTURECOORDS];
|
||||||
/// Material index.
|
/// Material index.
|
||||||
unsigned int m_uiMaterialIndex;
|
unsigned int m_uiMaterialIndex;
|
||||||
/// True, if normals are stored.
|
/// True, if normals are stored.
|
||||||
|
@ -227,20 +217,15 @@ struct Mesh {
|
||||||
bool m_hasVertexColors;
|
bool m_hasVertexColors;
|
||||||
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
explicit Mesh( const std::string &name )
|
explicit Mesh(const std::string &name) :
|
||||||
: m_name( name )
|
m_name(name), m_pMaterial(NULL), m_uiNumIndices(0), m_uiMaterialIndex(NoMaterial), m_hasNormals(false) {
|
||||||
, m_pMaterial(NULL)
|
memset(m_uiUVCoordinates, 0, sizeof(unsigned int) * AI_MAX_NUMBER_OF_TEXTURECOORDS);
|
||||||
, m_uiNumIndices(0)
|
|
||||||
, m_uiMaterialIndex( NoMaterial )
|
|
||||||
, m_hasNormals(false) {
|
|
||||||
memset(m_uiUVCoordinates, 0, sizeof( unsigned int ) * AI_MAX_NUMBER_OF_TEXTURECOORDS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Destructor
|
/// Destructor
|
||||||
~Mesh() {
|
~Mesh() {
|
||||||
for (std::vector<Face*>::iterator it = m_Faces.begin();
|
for (std::vector<Face *>::iterator it = m_Faces.begin();
|
||||||
it != m_Faces.end(); ++it)
|
it != m_Faces.end(); ++it) {
|
||||||
{
|
|
||||||
delete *it;
|
delete *it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -251,14 +236,14 @@ struct Mesh {
|
||||||
//! \brief Data structure to store all obj-specific model datas
|
//! \brief Data structure to store all obj-specific model datas
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
struct Model {
|
struct Model {
|
||||||
typedef std::map<std::string, std::vector<unsigned int>* > GroupMap;
|
typedef std::map<std::string, std::vector<unsigned int> *> GroupMap;
|
||||||
typedef std::map<std::string, std::vector<unsigned int>* >::iterator GroupMapIt;
|
typedef std::map<std::string, std::vector<unsigned int> *>::iterator GroupMapIt;
|
||||||
typedef std::map<std::string, std::vector<unsigned int>* >::const_iterator ConstGroupMapIt;
|
typedef std::map<std::string, std::vector<unsigned int> *>::const_iterator ConstGroupMapIt;
|
||||||
|
|
||||||
//! Model name
|
//! Model name
|
||||||
std::string m_ModelName;
|
std::string m_ModelName;
|
||||||
//! List ob assigned objects
|
//! List ob assigned objects
|
||||||
std::vector<Object*> m_Objects;
|
std::vector<Object *> m_Objects;
|
||||||
//! Pointer to current object
|
//! Pointer to current object
|
||||||
ObjFile::Object *m_pCurrent;
|
ObjFile::Object *m_pCurrent;
|
||||||
//! Pointer to current material
|
//! Pointer to current material
|
||||||
|
@ -286,9 +271,9 @@ struct Model {
|
||||||
//! Current mesh instance
|
//! Current mesh instance
|
||||||
Mesh *m_pCurrentMesh;
|
Mesh *m_pCurrentMesh;
|
||||||
//! Vector with stored meshes
|
//! Vector with stored meshes
|
||||||
std::vector<Mesh*> m_Meshes;
|
std::vector<Mesh *> m_Meshes;
|
||||||
//! Material map
|
//! Material map
|
||||||
std::map<std::string, Material*> m_MaterialMap;
|
std::map<std::string, Material *> m_MaterialMap;
|
||||||
|
|
||||||
//! \brief The default class constructor
|
//! \brief The default class constructor
|
||||||
Model() :
|
Model() :
|
||||||
|
@ -299,33 +284,32 @@ struct Model {
|
||||||
m_pGroupFaceIDs(NULL),
|
m_pGroupFaceIDs(NULL),
|
||||||
m_strActiveGroup(""),
|
m_strActiveGroup(""),
|
||||||
m_TextureCoordDim(0),
|
m_TextureCoordDim(0),
|
||||||
m_pCurrentMesh(NULL)
|
m_pCurrentMesh(NULL) {
|
||||||
{
|
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \brief The class destructor
|
//! \brief The class destructor
|
||||||
~Model() {
|
~Model() {
|
||||||
// Clear all stored object instances
|
// Clear all stored object instances
|
||||||
for (std::vector<Object*>::iterator it = m_Objects.begin();
|
for (std::vector<Object *>::iterator it = m_Objects.begin();
|
||||||
it != m_Objects.end(); ++it) {
|
it != m_Objects.end(); ++it) {
|
||||||
delete *it;
|
delete *it;
|
||||||
}
|
}
|
||||||
m_Objects.clear();
|
m_Objects.clear();
|
||||||
|
|
||||||
// Clear all stored mesh instances
|
// Clear all stored mesh instances
|
||||||
for (std::vector<Mesh*>::iterator it = m_Meshes.begin();
|
for (std::vector<Mesh *>::iterator it = m_Meshes.begin();
|
||||||
it != m_Meshes.end(); ++it) {
|
it != m_Meshes.end(); ++it) {
|
||||||
delete *it;
|
delete *it;
|
||||||
}
|
}
|
||||||
m_Meshes.clear();
|
m_Meshes.clear();
|
||||||
|
|
||||||
for(GroupMapIt it = m_Groups.begin(); it != m_Groups.end(); ++it) {
|
for (GroupMapIt it = m_Groups.begin(); it != m_Groups.end(); ++it) {
|
||||||
delete it->second;
|
delete it->second;
|
||||||
}
|
}
|
||||||
m_Groups.clear();
|
m_Groups.clear();
|
||||||
|
|
||||||
for ( std::map<std::string, Material*>::iterator it = m_MaterialMap.begin(); it != m_MaterialMap.end(); ++it ) {
|
for (std::map<std::string, Material *>::iterator it = m_MaterialMap.begin(); it != m_MaterialMap.end(); ++it) {
|
||||||
delete it->second;
|
delete it->second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
|
||||||
|
|
||||||
Copyright (c) 2006-2020, assimp team
|
Copyright (c) 2006-2020, assimp team
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use of this software in source and binary forms,
|
Redistribution and use of this software in source and binary forms,
|
||||||
|
@ -44,16 +42,16 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#ifndef ASSIMP_BUILD_NO_OBJ_IMPORTER
|
#ifndef ASSIMP_BUILD_NO_OBJ_IMPORTER
|
||||||
|
|
||||||
#include "ObjFileImporter.h"
|
#include "ObjFileImporter.h"
|
||||||
#include "ObjFileParser.h"
|
|
||||||
#include "ObjFileData.h"
|
#include "ObjFileData.h"
|
||||||
#include <assimp/IOStreamBuffer.h>
|
#include "ObjFileParser.h"
|
||||||
#include <memory>
|
|
||||||
#include <assimp/DefaultIOSystem.h>
|
#include <assimp/DefaultIOSystem.h>
|
||||||
#include <assimp/Importer.hpp>
|
#include <assimp/IOStreamBuffer.h>
|
||||||
#include <assimp/scene.h>
|
|
||||||
#include <assimp/ai_assert.h>
|
#include <assimp/ai_assert.h>
|
||||||
#include <assimp/DefaultLogger.hpp>
|
|
||||||
#include <assimp/importerdesc.h>
|
#include <assimp/importerdesc.h>
|
||||||
|
#include <assimp/scene.h>
|
||||||
|
#include <assimp/DefaultLogger.hpp>
|
||||||
|
#include <assimp/Importer.hpp>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
static const aiImporterDesc desc = {
|
static const aiImporterDesc desc = {
|
||||||
"Wavefront Object Importer",
|
"Wavefront Object Importer",
|
||||||
|
@ -76,10 +74,8 @@ using namespace std;
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Default constructor
|
// Default constructor
|
||||||
ObjFileImporter::ObjFileImporter()
|
ObjFileImporter::ObjFileImporter() :
|
||||||
: m_Buffer()
|
m_Buffer(), m_pRootObject(nullptr), m_strAbsPath(std::string(1, DefaultIOSystem().getOsSeparator())) {}
|
||||||
, m_pRootObject( nullptr )
|
|
||||||
, m_strAbsPath( std::string(1, DefaultIOSystem().getOsSeparator()) ) {}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Destructor.
|
// Destructor.
|
||||||
|
@ -90,59 +86,59 @@ ObjFileImporter::~ObjFileImporter() {
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Returns true, if file is an obj file.
|
// Returns true, if file is an obj file.
|
||||||
bool ObjFileImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler , bool checkSig ) const {
|
bool ObjFileImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool checkSig) const {
|
||||||
if(!checkSig) {
|
if (!checkSig) {
|
||||||
//Check File Extension
|
//Check File Extension
|
||||||
return SimpleExtensionCheck(pFile,"obj");
|
return SimpleExtensionCheck(pFile, "obj");
|
||||||
} else {
|
} else {
|
||||||
// Check file Header
|
// Check file Header
|
||||||
static const char *pTokens[] = { "mtllib", "usemtl", "v ", "vt ", "vn ", "o ", "g ", "s ", "f " };
|
static const char *pTokens[] = { "mtllib", "usemtl", "v ", "vt ", "vn ", "o ", "g ", "s ", "f " };
|
||||||
return BaseImporter::SearchFileHeaderForToken(pIOHandler, pFile, pTokens, 9, 200, false, true );
|
return BaseImporter::SearchFileHeaderForToken(pIOHandler, pFile, pTokens, 9, 200, false, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
const aiImporterDesc* ObjFileImporter::GetInfo() const {
|
const aiImporterDesc *ObjFileImporter::GetInfo() const {
|
||||||
return &desc;
|
return &desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Obj-file import implementation
|
// Obj-file import implementation
|
||||||
void ObjFileImporter::InternReadFile( const std::string &file, aiScene* pScene, IOSystem* pIOHandler) {
|
void ObjFileImporter::InternReadFile(const std::string &file, aiScene *pScene, IOSystem *pIOHandler) {
|
||||||
// Read file into memory
|
// Read file into memory
|
||||||
static const std::string mode = "rb";
|
static const std::string mode = "rb";
|
||||||
std::unique_ptr<IOStream> fileStream( pIOHandler->Open( file, mode));
|
std::unique_ptr<IOStream> fileStream(pIOHandler->Open(file, mode));
|
||||||
if( !fileStream.get() ) {
|
if (!fileStream.get()) {
|
||||||
throw DeadlyImportError( "Failed to open file " + file + "." );
|
throw DeadlyImportError("Failed to open file " + file + ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the file-size and validate it, throwing an exception when fails
|
// Get the file-size and validate it, throwing an exception when fails
|
||||||
size_t fileSize = fileStream->FileSize();
|
size_t fileSize = fileStream->FileSize();
|
||||||
if( fileSize < ObjMinSize ) {
|
if (fileSize < ObjMinSize) {
|
||||||
throw DeadlyImportError( "OBJ-file is too small.");
|
throw DeadlyImportError("OBJ-file is too small.");
|
||||||
}
|
}
|
||||||
|
|
||||||
IOStreamBuffer<char> streamedBuffer;
|
IOStreamBuffer<char> streamedBuffer;
|
||||||
streamedBuffer.open( fileStream.get() );
|
streamedBuffer.open(fileStream.get());
|
||||||
|
|
||||||
// Allocate buffer and read file into it
|
// Allocate buffer and read file into it
|
||||||
//TextFileToBuffer( fileStream.get(),m_Buffer);
|
//TextFileToBuffer( fileStream.get(),m_Buffer);
|
||||||
|
|
||||||
// Get the model name
|
// Get the model name
|
||||||
std::string modelName, folderName;
|
std::string modelName, folderName;
|
||||||
std::string::size_type pos = file.find_last_of( "\\/" );
|
std::string::size_type pos = file.find_last_of("\\/");
|
||||||
if ( pos != std::string::npos ) {
|
if (pos != std::string::npos) {
|
||||||
modelName = file.substr(pos+1, file.size() - pos - 1);
|
modelName = file.substr(pos + 1, file.size() - pos - 1);
|
||||||
folderName = file.substr( 0, pos );
|
folderName = file.substr(0, pos);
|
||||||
if ( !folderName.empty() ) {
|
if (!folderName.empty()) {
|
||||||
pIOHandler->PushDirectory( folderName );
|
pIOHandler->PushDirectory(folderName);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
modelName = file;
|
modelName = file;
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse the file into a temporary representation
|
// parse the file into a temporary representation
|
||||||
ObjFileParser parser( streamedBuffer, modelName, pIOHandler, m_progress, file);
|
ObjFileParser parser(streamedBuffer, modelName, pIOHandler, m_progress, file);
|
||||||
|
|
||||||
// And create the proper return structures out of it
|
// And create the proper return structures out of it
|
||||||
CreateDataFromImport(parser.GetModel(), pScene);
|
CreateDataFromImport(parser.GetModel(), pScene);
|
||||||
|
@ -153,21 +149,21 @@ void ObjFileImporter::InternReadFile( const std::string &file, aiScene* pScene,
|
||||||
m_Buffer.clear();
|
m_Buffer.clear();
|
||||||
|
|
||||||
// Pop directory stack
|
// Pop directory stack
|
||||||
if ( pIOHandler->StackSize() > 0 ) {
|
if (pIOHandler->StackSize() > 0) {
|
||||||
pIOHandler->PopDirectory();
|
pIOHandler->PopDirectory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Create the data from parsed obj-file
|
// Create the data from parsed obj-file
|
||||||
void ObjFileImporter::CreateDataFromImport(const ObjFile::Model* pModel, aiScene* pScene) {
|
void ObjFileImporter::CreateDataFromImport(const ObjFile::Model *pModel, aiScene *pScene) {
|
||||||
if( 0L == pModel ) {
|
if (0L == pModel) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the root node of the scene
|
// Create the root node of the scene
|
||||||
pScene->mRootNode = new aiNode;
|
pScene->mRootNode = new aiNode;
|
||||||
if ( !pModel->m_ModelName.empty() ) {
|
if (!pModel->m_ModelName.empty()) {
|
||||||
// Set the name of the scene
|
// Set the name of the scene
|
||||||
pScene->mRootNode->mName.Set(pModel->m_ModelName);
|
pScene->mRootNode->mName.Set(pModel->m_ModelName);
|
||||||
} else {
|
} else {
|
||||||
|
@ -181,17 +177,17 @@ void ObjFileImporter::CreateDataFromImport(const ObjFile::Model* pModel, aiScene
|
||||||
unsigned int childCount = 0;
|
unsigned int childCount = 0;
|
||||||
|
|
||||||
for (auto object : pModel->m_Objects) {
|
for (auto object : pModel->m_Objects) {
|
||||||
if(object) {
|
if (object) {
|
||||||
++childCount;
|
++childCount;
|
||||||
meshCount += (unsigned int)object->m_Meshes.size();
|
meshCount += (unsigned int)object->m_Meshes.size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allocate space for the child nodes on the root node
|
// Allocate space for the child nodes on the root node
|
||||||
pScene->mRootNode->mChildren = new aiNode*[ childCount ];
|
pScene->mRootNode->mChildren = new aiNode *[childCount];
|
||||||
|
|
||||||
// Create nodes for the whole scene
|
// Create nodes for the whole scene
|
||||||
std::vector<aiMesh*> MeshArray;
|
std::vector<aiMesh *> MeshArray;
|
||||||
MeshArray.reserve(meshCount);
|
MeshArray.reserve(meshCount);
|
||||||
for (size_t index = 0; index < pModel->m_Objects.size(); ++index) {
|
for (size_t index = 0; index < pModel->m_Objects.size(); ++index) {
|
||||||
createNodes(pModel, pModel->m_Objects[index], pScene->mRootNode, pScene, MeshArray);
|
createNodes(pModel, pModel->m_Objects[index], pScene->mRootNode, pScene, MeshArray);
|
||||||
|
@ -201,7 +197,7 @@ void ObjFileImporter::CreateDataFromImport(const ObjFile::Model* pModel, aiScene
|
||||||
|
|
||||||
// Create mesh pointer buffer for this scene
|
// Create mesh pointer buffer for this scene
|
||||||
if (pScene->mNumMeshes > 0) {
|
if (pScene->mNumMeshes > 0) {
|
||||||
pScene->mMeshes = new aiMesh*[MeshArray.size()];
|
pScene->mMeshes = new aiMesh *[MeshArray.size()];
|
||||||
for (size_t index = 0; index < MeshArray.size(); ++index) {
|
for (size_t index = 0; index < MeshArray.size(); ++index) {
|
||||||
pScene->mMeshes[index] = MeshArray[index];
|
pScene->mMeshes[index] = MeshArray[index];
|
||||||
}
|
}
|
||||||
|
@ -209,34 +205,34 @@ void ObjFileImporter::CreateDataFromImport(const ObjFile::Model* pModel, aiScene
|
||||||
|
|
||||||
// Create all materials
|
// Create all materials
|
||||||
createMaterials(pModel, pScene);
|
createMaterials(pModel, pScene);
|
||||||
}else {
|
} else {
|
||||||
if (pModel->m_Vertices.empty()){
|
if (pModel->m_Vertices.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<aiMesh> mesh( new aiMesh );
|
std::unique_ptr<aiMesh> mesh(new aiMesh);
|
||||||
mesh->mPrimitiveTypes = aiPrimitiveType_POINT;
|
mesh->mPrimitiveTypes = aiPrimitiveType_POINT;
|
||||||
unsigned int n = (unsigned int)pModel->m_Vertices.size();
|
unsigned int n = (unsigned int)pModel->m_Vertices.size();
|
||||||
mesh->mNumVertices = n;
|
mesh->mNumVertices = n;
|
||||||
|
|
||||||
mesh->mVertices = new aiVector3D[n];
|
mesh->mVertices = new aiVector3D[n];
|
||||||
memcpy(mesh->mVertices, pModel->m_Vertices.data(), n*sizeof(aiVector3D) );
|
memcpy(mesh->mVertices, pModel->m_Vertices.data(), n * sizeof(aiVector3D));
|
||||||
|
|
||||||
if ( !pModel->m_Normals.empty() ) {
|
if (!pModel->m_Normals.empty()) {
|
||||||
mesh->mNormals = new aiVector3D[n];
|
mesh->mNormals = new aiVector3D[n];
|
||||||
if (pModel->m_Normals.size() < n) {
|
if (pModel->m_Normals.size() < n) {
|
||||||
throw DeadlyImportError("OBJ: vertex normal index out of range");
|
throw DeadlyImportError("OBJ: vertex normal index out of range");
|
||||||
}
|
}
|
||||||
memcpy(mesh->mNormals, pModel->m_Normals.data(), n*sizeof(aiVector3D));
|
memcpy(mesh->mNormals, pModel->m_Normals.data(), n * sizeof(aiVector3D));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !pModel->m_VertexColors.empty() ){
|
if (!pModel->m_VertexColors.empty()) {
|
||||||
mesh->mColors[0] = new aiColor4D[mesh->mNumVertices];
|
mesh->mColors[0] = new aiColor4D[mesh->mNumVertices];
|
||||||
for (unsigned int i = 0; i < n; ++i) {
|
for (unsigned int i = 0; i < n; ++i) {
|
||||||
if (i < pModel->m_VertexColors.size() ) {
|
if (i < pModel->m_VertexColors.size()) {
|
||||||
const aiVector3D& color = pModel->m_VertexColors[i];
|
const aiVector3D &color = pModel->m_VertexColors[i];
|
||||||
mesh->mColors[0][i] = aiColor4D(color.x, color.y, color.z, 1.0);
|
mesh->mColors[0][i] = aiColor4D(color.x, color.y, color.z, 1.0);
|
||||||
}else {
|
} else {
|
||||||
throw DeadlyImportError("OBJ: vertex color index out of range");
|
throw DeadlyImportError("OBJ: vertex color index out of range");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -245,7 +241,7 @@ void ObjFileImporter::CreateDataFromImport(const ObjFile::Model* pModel, aiScene
|
||||||
pScene->mRootNode->mNumMeshes = 1;
|
pScene->mRootNode->mNumMeshes = 1;
|
||||||
pScene->mRootNode->mMeshes = new unsigned int[1];
|
pScene->mRootNode->mMeshes = new unsigned int[1];
|
||||||
pScene->mRootNode->mMeshes[0] = 0;
|
pScene->mRootNode->mMeshes[0] = 0;
|
||||||
pScene->mMeshes = new aiMesh*[1];
|
pScene->mMeshes = new aiMesh *[1];
|
||||||
pScene->mNumMeshes = 1;
|
pScene->mNumMeshes = 1;
|
||||||
pScene->mMeshes[0] = mesh.release();
|
pScene->mMeshes[0] = mesh.release();
|
||||||
}
|
}
|
||||||
|
@ -253,12 +249,11 @@ void ObjFileImporter::CreateDataFromImport(const ObjFile::Model* pModel, aiScene
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Creates all nodes of the model
|
// Creates all nodes of the model
|
||||||
aiNode *ObjFileImporter::createNodes(const ObjFile::Model* pModel, const ObjFile::Object* pObject,
|
aiNode *ObjFileImporter::createNodes(const ObjFile::Model *pModel, const ObjFile::Object *pObject,
|
||||||
aiNode *pParent, aiScene* pScene,
|
aiNode *pParent, aiScene *pScene,
|
||||||
std::vector<aiMesh*> &MeshArray )
|
std::vector<aiMesh *> &MeshArray) {
|
||||||
{
|
ai_assert(NULL != pModel);
|
||||||
ai_assert( NULL != pModel );
|
if (NULL == pObject) {
|
||||||
if( NULL == pObject ) {
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,15 +264,15 @@ aiNode *ObjFileImporter::createNodes(const ObjFile::Model* pModel, const ObjFile
|
||||||
pNode->mName = pObject->m_strObjName;
|
pNode->mName = pObject->m_strObjName;
|
||||||
|
|
||||||
// If we have a parent node, store it
|
// If we have a parent node, store it
|
||||||
ai_assert( NULL != pParent );
|
ai_assert(NULL != pParent);
|
||||||
appendChildToParentNode( pParent, pNode );
|
appendChildToParentNode(pParent, pNode);
|
||||||
|
|
||||||
for ( size_t i=0; i< pObject->m_Meshes.size(); ++i ) {
|
for (size_t i = 0; i < pObject->m_Meshes.size(); ++i) {
|
||||||
unsigned int meshId = pObject->m_Meshes[ i ];
|
unsigned int meshId = pObject->m_Meshes[i];
|
||||||
aiMesh *pMesh = createTopology( pModel, pObject, meshId );
|
aiMesh *pMesh = createTopology(pModel, pObject, meshId);
|
||||||
if( pMesh ) {
|
if (pMesh) {
|
||||||
if (pMesh->mNumFaces > 0) {
|
if (pMesh->mNumFaces > 0) {
|
||||||
MeshArray.push_back( pMesh );
|
MeshArray.push_back(pMesh);
|
||||||
} else {
|
} else {
|
||||||
delete pMesh;
|
delete pMesh;
|
||||||
}
|
}
|
||||||
|
@ -285,22 +280,22 @@ aiNode *ObjFileImporter::createNodes(const ObjFile::Model* pModel, const ObjFile
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create all nodes from the sub-objects stored in the current object
|
// Create all nodes from the sub-objects stored in the current object
|
||||||
if ( !pObject->m_SubObjects.empty() ) {
|
if (!pObject->m_SubObjects.empty()) {
|
||||||
size_t numChilds = pObject->m_SubObjects.size();
|
size_t numChilds = pObject->m_SubObjects.size();
|
||||||
pNode->mNumChildren = static_cast<unsigned int>( numChilds );
|
pNode->mNumChildren = static_cast<unsigned int>(numChilds);
|
||||||
pNode->mChildren = new aiNode*[ numChilds ];
|
pNode->mChildren = new aiNode *[numChilds];
|
||||||
pNode->mNumMeshes = 1;
|
pNode->mNumMeshes = 1;
|
||||||
pNode->mMeshes = new unsigned int[ 1 ];
|
pNode->mMeshes = new unsigned int[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set mesh instances into scene- and node-instances
|
// Set mesh instances into scene- and node-instances
|
||||||
const size_t meshSizeDiff = MeshArray.size()- oldMeshSize;
|
const size_t meshSizeDiff = MeshArray.size() - oldMeshSize;
|
||||||
if ( meshSizeDiff > 0 ) {
|
if (meshSizeDiff > 0) {
|
||||||
pNode->mMeshes = new unsigned int[ meshSizeDiff ];
|
pNode->mMeshes = new unsigned int[meshSizeDiff];
|
||||||
pNode->mNumMeshes = static_cast<unsigned int>( meshSizeDiff );
|
pNode->mNumMeshes = static_cast<unsigned int>(meshSizeDiff);
|
||||||
size_t index = 0;
|
size_t index = 0;
|
||||||
for (size_t i = oldMeshSize; i < MeshArray.size(); ++i ) {
|
for (size_t i = oldMeshSize; i < MeshArray.size(); ++i) {
|
||||||
pNode->mMeshes[ index ] = pScene->mNumMeshes;
|
pNode->mMeshes[index] = pScene->mNumMeshes;
|
||||||
pScene->mNumMeshes++;
|
pScene->mNumMeshes++;
|
||||||
++index;
|
++index;
|
||||||
}
|
}
|
||||||
|
@ -311,33 +306,32 @@ aiNode *ObjFileImporter::createNodes(const ObjFile::Model* pModel, const ObjFile
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Create topology data
|
// Create topology data
|
||||||
aiMesh *ObjFileImporter::createTopology( const ObjFile::Model* pModel, const ObjFile::Object* pData, unsigned int meshIndex ) {
|
aiMesh *ObjFileImporter::createTopology(const ObjFile::Model *pModel, const ObjFile::Object *pData, unsigned int meshIndex) {
|
||||||
// Checking preconditions
|
// Checking preconditions
|
||||||
ai_assert( NULL != pModel );
|
ai_assert(NULL != pModel);
|
||||||
|
|
||||||
if( NULL == pData ) {
|
if (NULL == pData) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create faces
|
// Create faces
|
||||||
ObjFile::Mesh *pObjMesh = pModel->m_Meshes[ meshIndex ];
|
ObjFile::Mesh *pObjMesh = pModel->m_Meshes[meshIndex];
|
||||||
if( !pObjMesh ) {
|
if (!pObjMesh) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( pObjMesh->m_Faces.empty() ) {
|
if (pObjMesh->m_Faces.empty()) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<aiMesh> pMesh(new aiMesh);
|
std::unique_ptr<aiMesh> pMesh(new aiMesh);
|
||||||
if( !pObjMesh->m_name.empty() ) {
|
if (!pObjMesh->m_name.empty()) {
|
||||||
pMesh->mName.Set( pObjMesh->m_name );
|
pMesh->mName.Set(pObjMesh->m_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t index = 0; index < pObjMesh->m_Faces.size(); index++)
|
for (size_t index = 0; index < pObjMesh->m_Faces.size(); index++) {
|
||||||
{
|
ObjFile::Face *const inp = pObjMesh->m_Faces[index];
|
||||||
ObjFile::Face *const inp = pObjMesh->m_Faces[ index ];
|
ai_assert(NULL != inp);
|
||||||
ai_assert( NULL != inp );
|
|
||||||
|
|
||||||
if (inp->m_PrimitiveType == aiPrimitiveType_LINE) {
|
if (inp->m_PrimitiveType == aiPrimitiveType_LINE) {
|
||||||
pMesh->mNumFaces += static_cast<unsigned int>(inp->m_vertices.size() - 1);
|
pMesh->mNumFaces += static_cast<unsigned int>(inp->m_vertices.size() - 1);
|
||||||
|
@ -355,40 +349,39 @@ aiMesh *ObjFileImporter::createTopology( const ObjFile::Model* pModel, const Obj
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int uiIdxCount( 0u );
|
unsigned int uiIdxCount(0u);
|
||||||
if ( pMesh->mNumFaces > 0 ) {
|
if (pMesh->mNumFaces > 0) {
|
||||||
pMesh->mFaces = new aiFace[ pMesh->mNumFaces ];
|
pMesh->mFaces = new aiFace[pMesh->mNumFaces];
|
||||||
if ( pObjMesh->m_uiMaterialIndex != ObjFile::Mesh::NoMaterial ) {
|
if (pObjMesh->m_uiMaterialIndex != ObjFile::Mesh::NoMaterial) {
|
||||||
pMesh->mMaterialIndex = pObjMesh->m_uiMaterialIndex;
|
pMesh->mMaterialIndex = pObjMesh->m_uiMaterialIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int outIndex( 0 );
|
unsigned int outIndex(0);
|
||||||
|
|
||||||
// Copy all data from all stored meshes
|
// Copy all data from all stored meshes
|
||||||
for (auto& face : pObjMesh->m_Faces) {
|
for (auto &face : pObjMesh->m_Faces) {
|
||||||
ObjFile::Face* const inp = face;
|
ObjFile::Face *const inp = face;
|
||||||
if (inp->m_PrimitiveType == aiPrimitiveType_LINE) {
|
if (inp->m_PrimitiveType == aiPrimitiveType_LINE) {
|
||||||
for(size_t i = 0; i < inp->m_vertices.size() - 1; ++i) {
|
for (size_t i = 0; i < inp->m_vertices.size() - 1; ++i) {
|
||||||
aiFace& f = pMesh->mFaces[ outIndex++ ];
|
aiFace &f = pMesh->mFaces[outIndex++];
|
||||||
uiIdxCount += f.mNumIndices = 2;
|
uiIdxCount += f.mNumIndices = 2;
|
||||||
f.mIndices = new unsigned int[2];
|
f.mIndices = new unsigned int[2];
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
} else if (inp->m_PrimitiveType == aiPrimitiveType_POINT) {
|
||||||
else if (inp->m_PrimitiveType == aiPrimitiveType_POINT) {
|
for (size_t i = 0; i < inp->m_vertices.size(); ++i) {
|
||||||
for(size_t i = 0; i < inp->m_vertices.size(); ++i) {
|
aiFace &f = pMesh->mFaces[outIndex++];
|
||||||
aiFace& f = pMesh->mFaces[ outIndex++ ];
|
|
||||||
uiIdxCount += f.mNumIndices = 1;
|
uiIdxCount += f.mNumIndices = 1;
|
||||||
f.mIndices = new unsigned int[1];
|
f.mIndices = new unsigned int[1];
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
aiFace *pFace = &pMesh->mFaces[ outIndex++ ];
|
aiFace *pFace = &pMesh->mFaces[outIndex++];
|
||||||
const unsigned int uiNumIndices = (unsigned int) face->m_vertices.size();
|
const unsigned int uiNumIndices = (unsigned int)face->m_vertices.size();
|
||||||
uiIdxCount += pFace->mNumIndices = (unsigned int) uiNumIndices;
|
uiIdxCount += pFace->mNumIndices = (unsigned int)uiNumIndices;
|
||||||
if (pFace->mNumIndices > 0) {
|
if (pFace->mNumIndices > 0) {
|
||||||
pFace->mIndices = new unsigned int[ uiNumIndices ];
|
pFace->mIndices = new unsigned int[uiNumIndices];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -401,46 +394,45 @@ aiMesh *ObjFileImporter::createTopology( const ObjFile::Model* pModel, const Obj
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Creates a vertex array
|
// Creates a vertex array
|
||||||
void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel,
|
void ObjFileImporter::createVertexArray(const ObjFile::Model *pModel,
|
||||||
const ObjFile::Object* pCurrentObject,
|
const ObjFile::Object *pCurrentObject,
|
||||||
unsigned int uiMeshIndex,
|
unsigned int uiMeshIndex,
|
||||||
aiMesh* pMesh,
|
aiMesh *pMesh,
|
||||||
unsigned int numIndices) {
|
unsigned int numIndices) {
|
||||||
// Checking preconditions
|
// Checking preconditions
|
||||||
ai_assert( NULL != pCurrentObject );
|
ai_assert(NULL != pCurrentObject);
|
||||||
|
|
||||||
// Break, if no faces are stored in object
|
// Break, if no faces are stored in object
|
||||||
if ( pCurrentObject->m_Meshes.empty() )
|
if (pCurrentObject->m_Meshes.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Get current mesh
|
// Get current mesh
|
||||||
ObjFile::Mesh *pObjMesh = pModel->m_Meshes[ uiMeshIndex ];
|
ObjFile::Mesh *pObjMesh = pModel->m_Meshes[uiMeshIndex];
|
||||||
if ( NULL == pObjMesh || pObjMesh->m_uiNumIndices < 1 ) {
|
if (NULL == pObjMesh || pObjMesh->m_uiNumIndices < 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy vertices of this mesh instance
|
// Copy vertices of this mesh instance
|
||||||
pMesh->mNumVertices = numIndices;
|
pMesh->mNumVertices = numIndices;
|
||||||
if (pMesh->mNumVertices == 0) {
|
if (pMesh->mNumVertices == 0) {
|
||||||
throw DeadlyImportError( "OBJ: no vertices" );
|
throw DeadlyImportError("OBJ: no vertices");
|
||||||
} else if (pMesh->mNumVertices > AI_MAX_VERTICES) {
|
} else if (pMesh->mNumVertices > AI_MAX_VERTICES) {
|
||||||
throw DeadlyImportError( "OBJ: Too many vertices" );
|
throw DeadlyImportError("OBJ: Too many vertices");
|
||||||
}
|
}
|
||||||
pMesh->mVertices = new aiVector3D[ pMesh->mNumVertices ];
|
pMesh->mVertices = new aiVector3D[pMesh->mNumVertices];
|
||||||
|
|
||||||
// Allocate buffer for normal vectors
|
// Allocate buffer for normal vectors
|
||||||
if ( !pModel->m_Normals.empty() && pObjMesh->m_hasNormals )
|
if (!pModel->m_Normals.empty() && pObjMesh->m_hasNormals)
|
||||||
pMesh->mNormals = new aiVector3D[ pMesh->mNumVertices ];
|
pMesh->mNormals = new aiVector3D[pMesh->mNumVertices];
|
||||||
|
|
||||||
// Allocate buffer for vertex-color vectors
|
// Allocate buffer for vertex-color vectors
|
||||||
if ( !pModel->m_VertexColors.empty() )
|
if (!pModel->m_VertexColors.empty())
|
||||||
pMesh->mColors[0] = new aiColor4D[ pMesh->mNumVertices ];
|
pMesh->mColors[0] = new aiColor4D[pMesh->mNumVertices];
|
||||||
|
|
||||||
// Allocate buffer for texture coordinates
|
// Allocate buffer for texture coordinates
|
||||||
if ( !pModel->m_TextureCoord.empty() && pObjMesh->m_uiUVCoordinates[0] )
|
if (!pModel->m_TextureCoord.empty() && pObjMesh->m_uiUVCoordinates[0]) {
|
||||||
{
|
pMesh->mNumUVComponents[0] = pModel->m_TextureCoordDim;
|
||||||
pMesh->mNumUVComponents[ 0 ] = pModel->m_TextureCoordDim;
|
pMesh->mTextureCoords[0] = new aiVector3D[pMesh->mNumVertices];
|
||||||
pMesh->mTextureCoords[ 0 ] = new aiVector3D[ pMesh->mNumVertices ];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy vertices, normals and textures into aiMesh instance
|
// Copy vertices, normals and textures into aiMesh instance
|
||||||
|
@ -448,60 +440,52 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel,
|
||||||
unsigned int newIndex = 0, outIndex = 0;
|
unsigned int newIndex = 0, outIndex = 0;
|
||||||
for (auto sourceFace : pObjMesh->m_Faces) {
|
for (auto sourceFace : pObjMesh->m_Faces) {
|
||||||
// Copy all index arrays
|
// Copy all index arrays
|
||||||
for (size_t vertexIndex = 0, outVertexIndex = 0; vertexIndex < sourceFace->m_vertices.size(); vertexIndex++ ) {
|
for (size_t vertexIndex = 0, outVertexIndex = 0; vertexIndex < sourceFace->m_vertices.size(); vertexIndex++) {
|
||||||
const unsigned int vertex = sourceFace->m_vertices.at(vertexIndex );
|
const unsigned int vertex = sourceFace->m_vertices.at(vertexIndex);
|
||||||
if ( vertex >= pModel->m_Vertices.size() ) {
|
if (vertex >= pModel->m_Vertices.size()) {
|
||||||
throw DeadlyImportError( "OBJ: vertex index out of range" );
|
throw DeadlyImportError("OBJ: vertex index out of range");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( pMesh->mNumVertices <= newIndex ) {
|
if (pMesh->mNumVertices <= newIndex) {
|
||||||
throw DeadlyImportError("OBJ: bad vertex index");
|
throw DeadlyImportError("OBJ: bad vertex index");
|
||||||
}
|
}
|
||||||
|
|
||||||
pMesh->mVertices[ newIndex ] = pModel->m_Vertices[ vertex ];
|
pMesh->mVertices[newIndex] = pModel->m_Vertices[vertex];
|
||||||
|
|
||||||
// Copy all normals
|
// Copy all normals
|
||||||
if ( normalsok && !pModel->m_Normals.empty() && vertexIndex < sourceFace->m_normals.size()) {
|
if (normalsok && !pModel->m_Normals.empty() && vertexIndex < sourceFace->m_normals.size()) {
|
||||||
const unsigned int normal = sourceFace->m_normals.at(vertexIndex );
|
const unsigned int normal = sourceFace->m_normals.at(vertexIndex);
|
||||||
if ( normal >= pModel->m_Normals.size() )
|
if (normal >= pModel->m_Normals.size()) {
|
||||||
{
|
|
||||||
normalsok = false;
|
normalsok = false;
|
||||||
}
|
} else {
|
||||||
else
|
pMesh->mNormals[newIndex] = pModel->m_Normals[normal];
|
||||||
{
|
|
||||||
pMesh->mNormals[ newIndex ] = pModel->m_Normals[ normal ];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy all vertex colors
|
// Copy all vertex colors
|
||||||
if ( !pModel->m_VertexColors.empty())
|
if (!pModel->m_VertexColors.empty()) {
|
||||||
{
|
const aiVector3D &color = pModel->m_VertexColors[vertex];
|
||||||
const aiVector3D& color = pModel->m_VertexColors[ vertex ];
|
pMesh->mColors[0][newIndex] = aiColor4D(color.x, color.y, color.z, 1.0);
|
||||||
pMesh->mColors[0][ newIndex ] = aiColor4D(color.x, color.y, color.z, 1.0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy all texture coordinates
|
// Copy all texture coordinates
|
||||||
if ( uvok && !pModel->m_TextureCoord.empty() && vertexIndex < sourceFace->m_texturCoords.size())
|
if (uvok && !pModel->m_TextureCoord.empty() && vertexIndex < sourceFace->m_texturCoords.size()) {
|
||||||
{
|
const unsigned int tex = sourceFace->m_texturCoords.at(vertexIndex);
|
||||||
const unsigned int tex = sourceFace->m_texturCoords.at(vertexIndex );
|
|
||||||
|
|
||||||
if ( tex >= pModel->m_TextureCoord.size() )
|
if (tex >= pModel->m_TextureCoord.size()) {
|
||||||
{
|
|
||||||
uvok = false;
|
uvok = false;
|
||||||
}
|
} else {
|
||||||
else
|
const aiVector3D &coord3d = pModel->m_TextureCoord[tex];
|
||||||
{
|
pMesh->mTextureCoords[0][newIndex] = aiVector3D(coord3d.x, coord3d.y, coord3d.z);
|
||||||
const aiVector3D &coord3d = pModel->m_TextureCoord[ tex ];
|
|
||||||
pMesh->mTextureCoords[ 0 ][ newIndex ] = aiVector3D( coord3d.x, coord3d.y, coord3d.z );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get destination face
|
// Get destination face
|
||||||
aiFace *pDestFace = &pMesh->mFaces[ outIndex ];
|
aiFace *pDestFace = &pMesh->mFaces[outIndex];
|
||||||
|
|
||||||
const bool last = (vertexIndex == sourceFace->m_vertices.size() - 1 );
|
const bool last = (vertexIndex == sourceFace->m_vertices.size() - 1);
|
||||||
if (sourceFace->m_PrimitiveType != aiPrimitiveType_LINE || !last) {
|
if (sourceFace->m_PrimitiveType != aiPrimitiveType_LINE || !last) {
|
||||||
pDestFace->mIndices[ outVertexIndex ] = newIndex;
|
pDestFace->mIndices[outVertexIndex] = newIndex;
|
||||||
outVertexIndex++;
|
outVertexIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -511,18 +495,18 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel,
|
||||||
} else if (sourceFace->m_PrimitiveType == aiPrimitiveType_LINE) {
|
} else if (sourceFace->m_PrimitiveType == aiPrimitiveType_LINE) {
|
||||||
outVertexIndex = 0;
|
outVertexIndex = 0;
|
||||||
|
|
||||||
if(!last)
|
if (!last)
|
||||||
outIndex++;
|
outIndex++;
|
||||||
|
|
||||||
if (vertexIndex) {
|
if (vertexIndex) {
|
||||||
if(!last) {
|
if (!last) {
|
||||||
pMesh->mVertices[ newIndex+1 ] = pMesh->mVertices[ newIndex ];
|
pMesh->mVertices[newIndex + 1] = pMesh->mVertices[newIndex];
|
||||||
if (!sourceFace->m_normals.empty() && !pModel->m_Normals.empty()) {
|
if (!sourceFace->m_normals.empty() && !pModel->m_Normals.empty()) {
|
||||||
pMesh->mNormals[ newIndex+1 ] = pMesh->mNormals[newIndex ];
|
pMesh->mNormals[newIndex + 1] = pMesh->mNormals[newIndex];
|
||||||
}
|
}
|
||||||
if ( !pModel->m_TextureCoord.empty() ) {
|
if (!pModel->m_TextureCoord.empty()) {
|
||||||
for ( size_t i=0; i < pMesh->GetNumUVChannels(); i++ ) {
|
for (size_t i = 0; i < pMesh->GetNumUVChannels(); i++) {
|
||||||
pMesh->mTextureCoords[ i ][ newIndex+1 ] = pMesh->mTextureCoords[ i ][ newIndex ];
|
pMesh->mTextureCoords[i][newIndex + 1] = pMesh->mTextureCoords[i][newIndex];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
++newIndex;
|
++newIndex;
|
||||||
|
@ -530,40 +514,34 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel,
|
||||||
|
|
||||||
pDestFace[-1].mIndices[1] = newIndex;
|
pDestFace[-1].mIndices[1] = newIndex;
|
||||||
}
|
}
|
||||||
}
|
} else if (last) {
|
||||||
else if (last) {
|
|
||||||
outIndex++;
|
outIndex++;
|
||||||
}
|
}
|
||||||
++newIndex;
|
++newIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!normalsok)
|
if (!normalsok) {
|
||||||
{
|
delete[] pMesh->mNormals;
|
||||||
delete [] pMesh->mNormals;
|
|
||||||
pMesh->mNormals = nullptr;
|
pMesh->mNormals = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!uvok)
|
if (!uvok) {
|
||||||
{
|
delete[] pMesh->mTextureCoords[0];
|
||||||
delete [] pMesh->mTextureCoords[0];
|
|
||||||
pMesh->mTextureCoords[0] = nullptr;
|
pMesh->mTextureCoords[0] = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Counts all stored meshes
|
// Counts all stored meshes
|
||||||
void ObjFileImporter::countObjects(const std::vector<ObjFile::Object*> &rObjects, int &iNumMeshes)
|
void ObjFileImporter::countObjects(const std::vector<ObjFile::Object *> &rObjects, int &iNumMeshes) {
|
||||||
{
|
|
||||||
iNumMeshes = 0;
|
iNumMeshes = 0;
|
||||||
if ( rObjects.empty() )
|
if (rObjects.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
iNumMeshes += static_cast<unsigned int>( rObjects.size() );
|
iNumMeshes += static_cast<unsigned int>(rObjects.size());
|
||||||
for (auto object: rObjects)
|
for (auto object : rObjects) {
|
||||||
{
|
if (!object->m_SubObjects.empty()) {
|
||||||
if (!object->m_SubObjects.empty())
|
|
||||||
{
|
|
||||||
countObjects(object->m_SubObjects, iNumMeshes);
|
countObjects(object->m_SubObjects, iNumMeshes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -571,48 +549,46 @@ void ObjFileImporter::countObjects(const std::vector<ObjFile::Object*> &rObjects
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Add clamp mode property to material if necessary
|
// Add clamp mode property to material if necessary
|
||||||
void ObjFileImporter::addTextureMappingModeProperty( aiMaterial* mat, aiTextureType type, int clampMode, int index) {
|
void ObjFileImporter::addTextureMappingModeProperty(aiMaterial *mat, aiTextureType type, int clampMode, int index) {
|
||||||
if ( nullptr == mat ) {
|
if (nullptr == mat) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mat->AddProperty<int>( &clampMode, 1, AI_MATKEY_MAPPINGMODE_U( type, index ) );
|
mat->AddProperty<int>(&clampMode, 1, AI_MATKEY_MAPPINGMODE_U(type, index));
|
||||||
mat->AddProperty<int>( &clampMode, 1, AI_MATKEY_MAPPINGMODE_V( type, index ) );
|
mat->AddProperty<int>(&clampMode, 1, AI_MATKEY_MAPPINGMODE_V(type, index));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Creates the material
|
// Creates the material
|
||||||
void ObjFileImporter::createMaterials(const ObjFile::Model* pModel, aiScene* pScene ) {
|
void ObjFileImporter::createMaterials(const ObjFile::Model *pModel, aiScene *pScene) {
|
||||||
if ( NULL == pScene ) {
|
if (NULL == pScene) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const unsigned int numMaterials = (unsigned int) pModel->m_MaterialLib.size();
|
const unsigned int numMaterials = (unsigned int)pModel->m_MaterialLib.size();
|
||||||
pScene->mNumMaterials = 0;
|
pScene->mNumMaterials = 0;
|
||||||
if ( pModel->m_MaterialLib.empty() ) {
|
if (pModel->m_MaterialLib.empty()) {
|
||||||
ASSIMP_LOG_DEBUG("OBJ: no materials specified");
|
ASSIMP_LOG_DEBUG("OBJ: no materials specified");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pScene->mMaterials = new aiMaterial*[ numMaterials ];
|
pScene->mMaterials = new aiMaterial *[numMaterials];
|
||||||
for ( unsigned int matIndex = 0; matIndex < numMaterials; matIndex++ )
|
for (unsigned int matIndex = 0; matIndex < numMaterials; matIndex++) {
|
||||||
{
|
|
||||||
// Store material name
|
// Store material name
|
||||||
std::map<std::string, ObjFile::Material*>::const_iterator it;
|
std::map<std::string, ObjFile::Material *>::const_iterator it;
|
||||||
it = pModel->m_MaterialMap.find( pModel->m_MaterialLib[ matIndex ] );
|
it = pModel->m_MaterialMap.find(pModel->m_MaterialLib[matIndex]);
|
||||||
|
|
||||||
// No material found, use the default material
|
// No material found, use the default material
|
||||||
if ( pModel->m_MaterialMap.end() == it )
|
if (pModel->m_MaterialMap.end() == it)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
aiMaterial* mat = new aiMaterial;
|
aiMaterial *mat = new aiMaterial;
|
||||||
ObjFile::Material *pCurrentMaterial = (*it).second;
|
ObjFile::Material *pCurrentMaterial = (*it).second;
|
||||||
mat->AddProperty( &pCurrentMaterial->MaterialName, AI_MATKEY_NAME );
|
mat->AddProperty(&pCurrentMaterial->MaterialName, AI_MATKEY_NAME);
|
||||||
|
|
||||||
// convert illumination model
|
// convert illumination model
|
||||||
int sm = 0;
|
int sm = 0;
|
||||||
switch (pCurrentMaterial->illumination_model)
|
switch (pCurrentMaterial->illumination_model) {
|
||||||
{
|
|
||||||
case 0:
|
case 0:
|
||||||
sm = aiShadingMode_NoShading;
|
sm = aiShadingMode_NoShading;
|
||||||
break;
|
break;
|
||||||
|
@ -627,149 +603,129 @@ void ObjFileImporter::createMaterials(const ObjFile::Model* pModel, aiScene* pSc
|
||||||
ASSIMP_LOG_ERROR("OBJ: unexpected illumination model (0-2 recognized)");
|
ASSIMP_LOG_ERROR("OBJ: unexpected illumination model (0-2 recognized)");
|
||||||
}
|
}
|
||||||
|
|
||||||
mat->AddProperty<int>( &sm, 1, AI_MATKEY_SHADING_MODEL);
|
mat->AddProperty<int>(&sm, 1, AI_MATKEY_SHADING_MODEL);
|
||||||
|
|
||||||
// Adding material colors
|
// Adding material colors
|
||||||
mat->AddProperty( &pCurrentMaterial->ambient, 1, AI_MATKEY_COLOR_AMBIENT );
|
mat->AddProperty(&pCurrentMaterial->ambient, 1, AI_MATKEY_COLOR_AMBIENT);
|
||||||
mat->AddProperty( &pCurrentMaterial->diffuse, 1, AI_MATKEY_COLOR_DIFFUSE );
|
mat->AddProperty(&pCurrentMaterial->diffuse, 1, AI_MATKEY_COLOR_DIFFUSE);
|
||||||
mat->AddProperty( &pCurrentMaterial->specular, 1, AI_MATKEY_COLOR_SPECULAR );
|
mat->AddProperty(&pCurrentMaterial->specular, 1, AI_MATKEY_COLOR_SPECULAR);
|
||||||
mat->AddProperty( &pCurrentMaterial->emissive, 1, AI_MATKEY_COLOR_EMISSIVE );
|
mat->AddProperty(&pCurrentMaterial->emissive, 1, AI_MATKEY_COLOR_EMISSIVE);
|
||||||
mat->AddProperty( &pCurrentMaterial->shineness, 1, AI_MATKEY_SHININESS );
|
mat->AddProperty(&pCurrentMaterial->shineness, 1, AI_MATKEY_SHININESS);
|
||||||
mat->AddProperty( &pCurrentMaterial->alpha, 1, AI_MATKEY_OPACITY );
|
mat->AddProperty(&pCurrentMaterial->alpha, 1, AI_MATKEY_OPACITY);
|
||||||
mat->AddProperty( &pCurrentMaterial->transparent,1,AI_MATKEY_COLOR_TRANSPARENT);
|
mat->AddProperty(&pCurrentMaterial->transparent, 1, AI_MATKEY_COLOR_TRANSPARENT);
|
||||||
|
|
||||||
// Adding refraction index
|
// Adding refraction index
|
||||||
mat->AddProperty( &pCurrentMaterial->ior, 1, AI_MATKEY_REFRACTI );
|
mat->AddProperty(&pCurrentMaterial->ior, 1, AI_MATKEY_REFRACTI);
|
||||||
|
|
||||||
// Adding textures
|
// Adding textures
|
||||||
const int uvwIndex = 0;
|
const int uvwIndex = 0;
|
||||||
|
|
||||||
if ( 0 != pCurrentMaterial->texture.length )
|
if (0 != pCurrentMaterial->texture.length) {
|
||||||
{
|
mat->AddProperty(&pCurrentMaterial->texture, AI_MATKEY_TEXTURE_DIFFUSE(0));
|
||||||
mat->AddProperty( &pCurrentMaterial->texture, AI_MATKEY_TEXTURE_DIFFUSE(0));
|
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_DIFFUSE(0));
|
||||||
mat->AddProperty( &uvwIndex, 1, AI_MATKEY_UVWSRC_DIFFUSE(0) );
|
if (pCurrentMaterial->clamp[ObjFile::Material::TextureDiffuseType]) {
|
||||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureDiffuseType])
|
|
||||||
{
|
|
||||||
addTextureMappingModeProperty(mat, aiTextureType_DIFFUSE);
|
addTextureMappingModeProperty(mat, aiTextureType_DIFFUSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( 0 != pCurrentMaterial->textureAmbient.length )
|
if (0 != pCurrentMaterial->textureAmbient.length) {
|
||||||
{
|
mat->AddProperty(&pCurrentMaterial->textureAmbient, AI_MATKEY_TEXTURE_AMBIENT(0));
|
||||||
mat->AddProperty( &pCurrentMaterial->textureAmbient, AI_MATKEY_TEXTURE_AMBIENT(0));
|
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_AMBIENT(0));
|
||||||
mat->AddProperty( &uvwIndex, 1, AI_MATKEY_UVWSRC_AMBIENT(0) );
|
if (pCurrentMaterial->clamp[ObjFile::Material::TextureAmbientType]) {
|
||||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureAmbientType])
|
|
||||||
{
|
|
||||||
addTextureMappingModeProperty(mat, aiTextureType_AMBIENT);
|
addTextureMappingModeProperty(mat, aiTextureType_AMBIENT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( 0 != pCurrentMaterial->textureEmissive.length )
|
if (0 != pCurrentMaterial->textureEmissive.length) {
|
||||||
{
|
mat->AddProperty(&pCurrentMaterial->textureEmissive, AI_MATKEY_TEXTURE_EMISSIVE(0));
|
||||||
mat->AddProperty( &pCurrentMaterial->textureEmissive, AI_MATKEY_TEXTURE_EMISSIVE(0));
|
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_EMISSIVE(0));
|
||||||
mat->AddProperty( &uvwIndex, 1, AI_MATKEY_UVWSRC_EMISSIVE(0) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( 0 != pCurrentMaterial->textureSpecular.length )
|
if (0 != pCurrentMaterial->textureSpecular.length) {
|
||||||
{
|
mat->AddProperty(&pCurrentMaterial->textureSpecular, AI_MATKEY_TEXTURE_SPECULAR(0));
|
||||||
mat->AddProperty( &pCurrentMaterial->textureSpecular, AI_MATKEY_TEXTURE_SPECULAR(0));
|
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_SPECULAR(0));
|
||||||
mat->AddProperty( &uvwIndex, 1, AI_MATKEY_UVWSRC_SPECULAR(0) );
|
if (pCurrentMaterial->clamp[ObjFile::Material::TextureSpecularType]) {
|
||||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureSpecularType])
|
|
||||||
{
|
|
||||||
addTextureMappingModeProperty(mat, aiTextureType_SPECULAR);
|
addTextureMappingModeProperty(mat, aiTextureType_SPECULAR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( 0 != pCurrentMaterial->textureBump.length )
|
if (0 != pCurrentMaterial->textureBump.length) {
|
||||||
{
|
mat->AddProperty(&pCurrentMaterial->textureBump, AI_MATKEY_TEXTURE_HEIGHT(0));
|
||||||
mat->AddProperty( &pCurrentMaterial->textureBump, AI_MATKEY_TEXTURE_HEIGHT(0));
|
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_HEIGHT(0));
|
||||||
mat->AddProperty( &uvwIndex, 1, AI_MATKEY_UVWSRC_HEIGHT(0) );
|
if (pCurrentMaterial->clamp[ObjFile::Material::TextureBumpType]) {
|
||||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureBumpType])
|
|
||||||
{
|
|
||||||
addTextureMappingModeProperty(mat, aiTextureType_HEIGHT);
|
addTextureMappingModeProperty(mat, aiTextureType_HEIGHT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( 0 != pCurrentMaterial->textureNormal.length )
|
if (0 != pCurrentMaterial->textureNormal.length) {
|
||||||
{
|
mat->AddProperty(&pCurrentMaterial->textureNormal, AI_MATKEY_TEXTURE_NORMALS(0));
|
||||||
mat->AddProperty( &pCurrentMaterial->textureNormal, AI_MATKEY_TEXTURE_NORMALS(0));
|
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_NORMALS(0));
|
||||||
mat->AddProperty( &uvwIndex, 1, AI_MATKEY_UVWSRC_NORMALS(0) );
|
if (pCurrentMaterial->clamp[ObjFile::Material::TextureNormalType]) {
|
||||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureNormalType])
|
|
||||||
{
|
|
||||||
addTextureMappingModeProperty(mat, aiTextureType_NORMALS);
|
addTextureMappingModeProperty(mat, aiTextureType_NORMALS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( 0 != pCurrentMaterial->textureReflection[0].length )
|
if (0 != pCurrentMaterial->textureReflection[0].length) {
|
||||||
{
|
|
||||||
ObjFile::Material::TextureType type = 0 != pCurrentMaterial->textureReflection[1].length ?
|
ObjFile::Material::TextureType type = 0 != pCurrentMaterial->textureReflection[1].length ?
|
||||||
ObjFile::Material::TextureReflectionCubeTopType :
|
ObjFile::Material::TextureReflectionCubeTopType :
|
||||||
ObjFile::Material::TextureReflectionSphereType;
|
ObjFile::Material::TextureReflectionSphereType;
|
||||||
|
|
||||||
unsigned count = type == ObjFile::Material::TextureReflectionSphereType ? 1 : 6;
|
unsigned count = type == ObjFile::Material::TextureReflectionSphereType ? 1 : 6;
|
||||||
for( unsigned i = 0; i < count; i++ )
|
for (unsigned i = 0; i < count; i++) {
|
||||||
{
|
|
||||||
mat->AddProperty(&pCurrentMaterial->textureReflection[i], AI_MATKEY_TEXTURE_REFLECTION(i));
|
mat->AddProperty(&pCurrentMaterial->textureReflection[i], AI_MATKEY_TEXTURE_REFLECTION(i));
|
||||||
mat->AddProperty( &uvwIndex, 1, AI_MATKEY_UVWSRC_REFLECTION(i) );
|
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_REFLECTION(i));
|
||||||
|
|
||||||
if(pCurrentMaterial->clamp[type])
|
if (pCurrentMaterial->clamp[type])
|
||||||
addTextureMappingModeProperty(mat, aiTextureType_REFLECTION, 1, i);
|
addTextureMappingModeProperty(mat, aiTextureType_REFLECTION, 1, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( 0 != pCurrentMaterial->textureDisp.length )
|
if (0 != pCurrentMaterial->textureDisp.length) {
|
||||||
{
|
mat->AddProperty(&pCurrentMaterial->textureDisp, AI_MATKEY_TEXTURE_DISPLACEMENT(0));
|
||||||
mat->AddProperty( &pCurrentMaterial->textureDisp, AI_MATKEY_TEXTURE_DISPLACEMENT(0) );
|
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_DISPLACEMENT(0));
|
||||||
mat->AddProperty( &uvwIndex, 1, AI_MATKEY_UVWSRC_DISPLACEMENT(0) );
|
if (pCurrentMaterial->clamp[ObjFile::Material::TextureDispType]) {
|
||||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureDispType])
|
|
||||||
{
|
|
||||||
addTextureMappingModeProperty(mat, aiTextureType_DISPLACEMENT);
|
addTextureMappingModeProperty(mat, aiTextureType_DISPLACEMENT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( 0 != pCurrentMaterial->textureOpacity.length )
|
if (0 != pCurrentMaterial->textureOpacity.length) {
|
||||||
{
|
mat->AddProperty(&pCurrentMaterial->textureOpacity, AI_MATKEY_TEXTURE_OPACITY(0));
|
||||||
mat->AddProperty( &pCurrentMaterial->textureOpacity, AI_MATKEY_TEXTURE_OPACITY(0));
|
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_OPACITY(0));
|
||||||
mat->AddProperty( &uvwIndex, 1, AI_MATKEY_UVWSRC_OPACITY(0) );
|
if (pCurrentMaterial->clamp[ObjFile::Material::TextureOpacityType]) {
|
||||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureOpacityType])
|
|
||||||
{
|
|
||||||
addTextureMappingModeProperty(mat, aiTextureType_OPACITY);
|
addTextureMappingModeProperty(mat, aiTextureType_OPACITY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( 0 != pCurrentMaterial->textureSpecularity.length )
|
if (0 != pCurrentMaterial->textureSpecularity.length) {
|
||||||
{
|
mat->AddProperty(&pCurrentMaterial->textureSpecularity, AI_MATKEY_TEXTURE_SHININESS(0));
|
||||||
mat->AddProperty( &pCurrentMaterial->textureSpecularity, AI_MATKEY_TEXTURE_SHININESS(0));
|
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_SHININESS(0));
|
||||||
mat->AddProperty( &uvwIndex, 1, AI_MATKEY_UVWSRC_SHININESS(0) );
|
if (pCurrentMaterial->clamp[ObjFile::Material::TextureSpecularityType]) {
|
||||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureSpecularityType])
|
|
||||||
{
|
|
||||||
addTextureMappingModeProperty(mat, aiTextureType_SHININESS);
|
addTextureMappingModeProperty(mat, aiTextureType_SHININESS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store material property info in material array in scene
|
// Store material property info in material array in scene
|
||||||
pScene->mMaterials[ pScene->mNumMaterials ] = mat;
|
pScene->mMaterials[pScene->mNumMaterials] = mat;
|
||||||
pScene->mNumMaterials++;
|
pScene->mNumMaterials++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test number of created materials.
|
// Test number of created materials.
|
||||||
ai_assert( pScene->mNumMaterials == numMaterials );
|
ai_assert(pScene->mNumMaterials == numMaterials);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Appends this node to the parent node
|
// Appends this node to the parent node
|
||||||
void ObjFileImporter::appendChildToParentNode(aiNode *pParent, aiNode *pChild)
|
void ObjFileImporter::appendChildToParentNode(aiNode *pParent, aiNode *pChild) {
|
||||||
{
|
|
||||||
// Checking preconditions
|
// Checking preconditions
|
||||||
ai_assert( NULL != pParent );
|
ai_assert(NULL != pParent);
|
||||||
ai_assert( NULL != pChild );
|
ai_assert(NULL != pChild);
|
||||||
|
|
||||||
// Assign parent to child
|
// Assign parent to child
|
||||||
pChild->mParent = pParent;
|
pChild->mParent = pParent;
|
||||||
|
|
||||||
// Copy node instances into parent node
|
// Copy node instances into parent node
|
||||||
pParent->mNumChildren++;
|
pParent->mNumChildren++;
|
||||||
pParent->mChildren[ pParent->mNumChildren-1 ] = pChild;
|
pParent->mChildren[pParent->mNumChildren - 1] = pChild;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
|
||||||
|
|
||||||
Copyright (c) 2006-2020, assimp team
|
Copyright (c) 2006-2020, assimp team
|
||||||
|
|
||||||
|
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use of this software in source and binary forms,
|
Redistribution and use of this software in source and binary forms,
|
||||||
|
@ -52,9 +51,9 @@ struct aiNode;
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
|
|
||||||
namespace ObjFile {
|
namespace ObjFile {
|
||||||
struct Object;
|
struct Object;
|
||||||
struct Model;
|
struct Model;
|
||||||
}
|
} // namespace ObjFile
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
/// \class ObjFileImporter
|
/// \class ObjFileImporter
|
||||||
|
@ -71,38 +70,38 @@ public:
|
||||||
public:
|
public:
|
||||||
/// \brief Returns whether the class can handle the format of the given file.
|
/// \brief Returns whether the class can handle the format of the given file.
|
||||||
/// \remark See BaseImporter::CanRead() for details.
|
/// \remark See BaseImporter::CanRead() for details.
|
||||||
bool CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const;
|
bool CanRead(const std::string &pFile, IOSystem *pIOHandler, bool checkSig) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! \brief Appends the supported extension.
|
//! \brief Appends the supported extension.
|
||||||
const aiImporterDesc* GetInfo () const;
|
const aiImporterDesc *GetInfo() const;
|
||||||
|
|
||||||
//! \brief File import implementation.
|
//! \brief File import implementation.
|
||||||
void InternReadFile(const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler);
|
void InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler);
|
||||||
|
|
||||||
//! \brief Create the data from imported content.
|
//! \brief Create the data from imported content.
|
||||||
void CreateDataFromImport(const ObjFile::Model* pModel, aiScene* pScene);
|
void CreateDataFromImport(const ObjFile::Model *pModel, aiScene *pScene);
|
||||||
|
|
||||||
//! \brief Creates all nodes stored in imported content.
|
//! \brief Creates all nodes stored in imported content.
|
||||||
aiNode *createNodes(const ObjFile::Model* pModel, const ObjFile::Object* pData,
|
aiNode *createNodes(const ObjFile::Model *pModel, const ObjFile::Object *pData,
|
||||||
aiNode *pParent, aiScene* pScene, std::vector<aiMesh*> &MeshArray);
|
aiNode *pParent, aiScene *pScene, std::vector<aiMesh *> &MeshArray);
|
||||||
|
|
||||||
//! \brief Creates topology data like faces and meshes for the geometry.
|
//! \brief Creates topology data like faces and meshes for the geometry.
|
||||||
aiMesh *createTopology( const ObjFile::Model* pModel, const ObjFile::Object* pData,
|
aiMesh *createTopology(const ObjFile::Model *pModel, const ObjFile::Object *pData,
|
||||||
unsigned int uiMeshIndex );
|
unsigned int uiMeshIndex);
|
||||||
|
|
||||||
//! \brief Creates vertices from model.
|
//! \brief Creates vertices from model.
|
||||||
void createVertexArray(const ObjFile::Model* pModel, const ObjFile::Object* pCurrentObject,
|
void createVertexArray(const ObjFile::Model *pModel, const ObjFile::Object *pCurrentObject,
|
||||||
unsigned int uiMeshIndex, aiMesh* pMesh, unsigned int numIndices );
|
unsigned int uiMeshIndex, aiMesh *pMesh, unsigned int numIndices);
|
||||||
|
|
||||||
//! \brief Object counter helper method.
|
//! \brief Object counter helper method.
|
||||||
void countObjects(const std::vector<ObjFile::Object*> &rObjects, int &iNumMeshes);
|
void countObjects(const std::vector<ObjFile::Object *> &rObjects, int &iNumMeshes);
|
||||||
|
|
||||||
//! \brief Material creation.
|
//! \brief Material creation.
|
||||||
void createMaterials(const ObjFile::Model* pModel, aiScene* pScene);
|
void createMaterials(const ObjFile::Model *pModel, aiScene *pScene);
|
||||||
|
|
||||||
/// @brief Adds special property for the used texture mapping mode of the model.
|
/// @brief Adds special property for the used texture mapping mode of the model.
|
||||||
void addTextureMappingModeProperty(aiMaterial* mat, aiTextureType type, int clampMode = 1, int index = 0);
|
void addTextureMappingModeProperty(aiMaterial *mat, aiTextureType type, int clampMode = 1, int index = 0);
|
||||||
|
|
||||||
//! \brief Appends a child node to a parent node and updates the data structures.
|
//! \brief Appends a child node to a parent node and updates the data structures.
|
||||||
void appendChildToParentNode(aiNode *pParent, aiNode *pChild);
|
void appendChildToParentNode(aiNode *pParent, aiNode *pChild);
|
||||||
|
|
|
@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
|
||||||
|
|
||||||
Copyright (c) 2006-2020, assimp team
|
Copyright (c) 2006-2020, assimp team
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use of this software in source and binary forms,
|
Redistribution and use of this software in source and binary forms,
|
||||||
|
@ -41,16 +39,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef ASSIMP_BUILD_NO_OBJ_IMPORTER
|
#ifndef ASSIMP_BUILD_NO_OBJ_IMPORTER
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include "ObjFileMtlImporter.h"
|
#include "ObjFileMtlImporter.h"
|
||||||
#include "ObjTools.h"
|
|
||||||
#include "ObjFileData.h"
|
#include "ObjFileData.h"
|
||||||
#include <assimp/fast_atof.h>
|
#include "ObjTools.h"
|
||||||
#include <assimp/ParsingUtils.h>
|
#include <assimp/ParsingUtils.h>
|
||||||
|
#include <assimp/fast_atof.h>
|
||||||
#include <assimp/material.h>
|
#include <assimp/material.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <assimp/DefaultLogger.hpp>
|
#include <assimp/DefaultLogger.hpp>
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
|
@ -86,113 +83,92 @@ static const std::string TypeOption = "-type";
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
// Constructor
|
// Constructor
|
||||||
ObjFileMtlImporter::ObjFileMtlImporter( std::vector<char> &buffer,
|
ObjFileMtlImporter::ObjFileMtlImporter(std::vector<char> &buffer,
|
||||||
const std::string &,
|
const std::string &,
|
||||||
ObjFile::Model *pModel ) :
|
ObjFile::Model *pModel) :
|
||||||
m_DataIt( buffer.begin() ),
|
m_DataIt(buffer.begin()),
|
||||||
m_DataItEnd( buffer.end() ),
|
m_DataItEnd(buffer.end()),
|
||||||
m_pModel( pModel ),
|
m_pModel(pModel),
|
||||||
m_uiLine( 0 )
|
m_uiLine(0) {
|
||||||
{
|
ai_assert(NULL != m_pModel);
|
||||||
ai_assert( NULL != m_pModel );
|
if (NULL == m_pModel->m_pDefaultMaterial) {
|
||||||
if ( NULL == m_pModel->m_pDefaultMaterial )
|
|
||||||
{
|
|
||||||
m_pModel->m_pDefaultMaterial = new ObjFile::Material;
|
m_pModel->m_pDefaultMaterial = new ObjFile::Material;
|
||||||
m_pModel->m_pDefaultMaterial->MaterialName.Set( "default" );
|
m_pModel->m_pDefaultMaterial->MaterialName.Set("default");
|
||||||
}
|
}
|
||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
// Destructor
|
// Destructor
|
||||||
ObjFileMtlImporter::~ObjFileMtlImporter()
|
ObjFileMtlImporter::~ObjFileMtlImporter() {
|
||||||
{
|
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
// Private copy constructor
|
// Private copy constructor
|
||||||
ObjFileMtlImporter::ObjFileMtlImporter(const ObjFileMtlImporter & )
|
ObjFileMtlImporter::ObjFileMtlImporter(const ObjFileMtlImporter &) {
|
||||||
{
|
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
// Private copy constructor
|
// Private copy constructor
|
||||||
ObjFileMtlImporter &ObjFileMtlImporter::operator = ( const ObjFileMtlImporter & )
|
ObjFileMtlImporter &ObjFileMtlImporter::operator=(const ObjFileMtlImporter &) {
|
||||||
{
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
// Loads the material description
|
// Loads the material description
|
||||||
void ObjFileMtlImporter::load()
|
void ObjFileMtlImporter::load() {
|
||||||
{
|
if (m_DataIt == m_DataItEnd)
|
||||||
if ( m_DataIt == m_DataItEnd )
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
while ( m_DataIt != m_DataItEnd )
|
while (m_DataIt != m_DataItEnd) {
|
||||||
{
|
switch (*m_DataIt) {
|
||||||
switch (*m_DataIt)
|
|
||||||
{
|
|
||||||
case 'k':
|
case 'k':
|
||||||
case 'K':
|
case 'K': {
|
||||||
{
|
|
||||||
++m_DataIt;
|
++m_DataIt;
|
||||||
if (*m_DataIt == 'a') // Ambient color
|
if (*m_DataIt == 'a') // Ambient color
|
||||||
{
|
{
|
||||||
++m_DataIt;
|
++m_DataIt;
|
||||||
getColorRGBA( &m_pModel->m_pCurrentMaterial->ambient );
|
getColorRGBA(&m_pModel->m_pCurrentMaterial->ambient);
|
||||||
}
|
} else if (*m_DataIt == 'd') // Diffuse color
|
||||||
else if (*m_DataIt == 'd') // Diffuse color
|
|
||||||
{
|
{
|
||||||
++m_DataIt;
|
++m_DataIt;
|
||||||
getColorRGBA( &m_pModel->m_pCurrentMaterial->diffuse );
|
getColorRGBA(&m_pModel->m_pCurrentMaterial->diffuse);
|
||||||
}
|
} else if (*m_DataIt == 's') {
|
||||||
else if (*m_DataIt == 's')
|
|
||||||
{
|
|
||||||
++m_DataIt;
|
++m_DataIt;
|
||||||
getColorRGBA( &m_pModel->m_pCurrentMaterial->specular );
|
getColorRGBA(&m_pModel->m_pCurrentMaterial->specular);
|
||||||
}
|
} else if (*m_DataIt == 'e') {
|
||||||
else if (*m_DataIt == 'e')
|
|
||||||
{
|
|
||||||
++m_DataIt;
|
++m_DataIt;
|
||||||
getColorRGBA( &m_pModel->m_pCurrentMaterial->emissive );
|
getColorRGBA(&m_pModel->m_pCurrentMaterial->emissive);
|
||||||
}
|
}
|
||||||
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||||
}
|
} break;
|
||||||
break;
|
case 'T': {
|
||||||
case 'T':
|
|
||||||
{
|
|
||||||
++m_DataIt;
|
++m_DataIt;
|
||||||
if (*m_DataIt == 'f') // Material transmission
|
if (*m_DataIt == 'f') // Material transmission
|
||||||
{
|
{
|
||||||
++m_DataIt;
|
++m_DataIt;
|
||||||
getColorRGBA( &m_pModel->m_pCurrentMaterial->transparent);
|
getColorRGBA(&m_pModel->m_pCurrentMaterial->transparent);
|
||||||
}
|
}
|
||||||
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||||
}
|
} break;
|
||||||
break;
|
case 'd': {
|
||||||
case 'd':
|
if (*(m_DataIt + 1) == 'i' && *(m_DataIt + 2) == 's' && *(m_DataIt + 3) == 'p') {
|
||||||
{
|
|
||||||
if( *(m_DataIt+1) == 'i' && *( m_DataIt + 2 ) == 's' && *( m_DataIt + 3 ) == 'p' ) {
|
|
||||||
// A displacement map
|
// A displacement map
|
||||||
getTexture();
|
getTexture();
|
||||||
} else {
|
} else {
|
||||||
// Alpha value
|
// Alpha value
|
||||||
++m_DataIt;
|
++m_DataIt;
|
||||||
getFloatValue( m_pModel->m_pCurrentMaterial->alpha );
|
getFloatValue(m_pModel->m_pCurrentMaterial->alpha);
|
||||||
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||||
}
|
}
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case 'N':
|
case 'N':
|
||||||
case 'n':
|
case 'n': {
|
||||||
{
|
|
||||||
++m_DataIt;
|
++m_DataIt;
|
||||||
switch(*m_DataIt)
|
switch (*m_DataIt) {
|
||||||
{
|
|
||||||
case 's': // Specular exponent
|
case 's': // Specular exponent
|
||||||
++m_DataIt;
|
++m_DataIt;
|
||||||
getFloatValue(m_pModel->m_pCurrentMaterial->shineness);
|
getFloatValue(m_pModel->m_pCurrentMaterial->shineness);
|
||||||
|
@ -205,50 +181,44 @@ void ObjFileMtlImporter::load()
|
||||||
createMaterial();
|
createMaterial();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case 'm': // Texture
|
case 'm': // Texture
|
||||||
case 'b': // quick'n'dirty - for 'bump' sections
|
case 'b': // quick'n'dirty - for 'bump' sections
|
||||||
case 'r': // quick'n'dirty - for 'refl' sections
|
case 'r': // quick'n'dirty - for 'refl' sections
|
||||||
{
|
{
|
||||||
getTexture();
|
getTexture();
|
||||||
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case 'i': // Illumination model
|
case 'i': // Illumination model
|
||||||
{
|
{
|
||||||
m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
||||||
getIlluminationModel( m_pModel->m_pCurrentMaterial->illumination_model );
|
getIlluminationModel(m_pModel->m_pCurrentMaterial->illumination_model);
|
||||||
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default: {
|
||||||
{
|
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||||
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
} break;
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
// Loads a color definition
|
// Loads a color definition
|
||||||
void ObjFileMtlImporter::getColorRGBA( aiColor3D *pColor )
|
void ObjFileMtlImporter::getColorRGBA(aiColor3D *pColor) {
|
||||||
{
|
ai_assert(NULL != pColor);
|
||||||
ai_assert( NULL != pColor );
|
|
||||||
|
|
||||||
ai_real r( 0.0 ), g( 0.0 ), b( 0.0 );
|
ai_real r(0.0), g(0.0), b(0.0);
|
||||||
m_DataIt = getFloat<DataArrayIt>( m_DataIt, m_DataItEnd, r );
|
m_DataIt = getFloat<DataArrayIt>(m_DataIt, m_DataItEnd, r);
|
||||||
pColor->r = r;
|
pColor->r = r;
|
||||||
|
|
||||||
// we have to check if color is default 0 with only one token
|
// we have to check if color is default 0 with only one token
|
||||||
if( !IsLineEnd( *m_DataIt ) ) {
|
if (!IsLineEnd(*m_DataIt)) {
|
||||||
m_DataIt = getFloat<DataArrayIt>( m_DataIt, m_DataItEnd, g );
|
m_DataIt = getFloat<DataArrayIt>(m_DataIt, m_DataItEnd, g);
|
||||||
m_DataIt = getFloat<DataArrayIt>( m_DataIt, m_DataItEnd, b );
|
m_DataIt = getFloat<DataArrayIt>(m_DataIt, m_DataItEnd, b);
|
||||||
}
|
}
|
||||||
pColor->g = g;
|
pColor->g = g;
|
||||||
pColor->b = b;
|
pColor->b = b;
|
||||||
|
@ -256,34 +226,31 @@ void ObjFileMtlImporter::getColorRGBA( aiColor3D *pColor )
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
// Loads the kind of illumination model.
|
// Loads the kind of illumination model.
|
||||||
void ObjFileMtlImporter::getIlluminationModel( int &illum_model )
|
void ObjFileMtlImporter::getIlluminationModel(int &illum_model) {
|
||||||
{
|
m_DataIt = CopyNextWord<DataArrayIt>(m_DataIt, m_DataItEnd, m_buffer, BUFFERSIZE);
|
||||||
m_DataIt = CopyNextWord<DataArrayIt>( m_DataIt, m_DataItEnd, m_buffer, BUFFERSIZE );
|
|
||||||
illum_model = atoi(m_buffer);
|
illum_model = atoi(m_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
// Loads a single float value.
|
// Loads a single float value.
|
||||||
void ObjFileMtlImporter::getFloatValue( ai_real &value )
|
void ObjFileMtlImporter::getFloatValue(ai_real &value) {
|
||||||
{
|
m_DataIt = CopyNextWord<DataArrayIt>(m_DataIt, m_DataItEnd, m_buffer, BUFFERSIZE);
|
||||||
m_DataIt = CopyNextWord<DataArrayIt>( m_DataIt, m_DataItEnd, m_buffer, BUFFERSIZE );
|
value = (ai_real)fast_atof(m_buffer);
|
||||||
value = (ai_real) fast_atof(m_buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
// Creates a material from loaded data.
|
// Creates a material from loaded data.
|
||||||
void ObjFileMtlImporter::createMaterial()
|
void ObjFileMtlImporter::createMaterial() {
|
||||||
{
|
|
||||||
std::string line;
|
std::string line;
|
||||||
while( !IsLineEnd( *m_DataIt ) ) {
|
while (!IsLineEnd(*m_DataIt)) {
|
||||||
line += *m_DataIt;
|
line += *m_DataIt;
|
||||||
++m_DataIt;
|
++m_DataIt;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> token;
|
std::vector<std::string> token;
|
||||||
const unsigned int numToken = tokenize<std::string>( line, token, " \t" );
|
const unsigned int numToken = tokenize<std::string>(line, token, " \t");
|
||||||
std::string name;
|
std::string name;
|
||||||
if ( numToken == 1 ) {
|
if (numToken == 1) {
|
||||||
name = AI_DEFAULT_MATERIAL_NAME;
|
name = AI_DEFAULT_MATERIAL_NAME;
|
||||||
} else {
|
} else {
|
||||||
// skip newmtl and all following white spaces
|
// skip newmtl and all following white spaces
|
||||||
|
@ -296,13 +263,13 @@ void ObjFileMtlImporter::createMaterial()
|
||||||
|
|
||||||
name = trim_whitespaces(name);
|
name = trim_whitespaces(name);
|
||||||
|
|
||||||
std::map<std::string, ObjFile::Material*>::iterator it = m_pModel->m_MaterialMap.find( name );
|
std::map<std::string, ObjFile::Material *>::iterator it = m_pModel->m_MaterialMap.find(name);
|
||||||
if ( m_pModel->m_MaterialMap.end() == it) {
|
if (m_pModel->m_MaterialMap.end() == it) {
|
||||||
// New Material created
|
// New Material created
|
||||||
m_pModel->m_pCurrentMaterial = new ObjFile::Material();
|
m_pModel->m_pCurrentMaterial = new ObjFile::Material();
|
||||||
m_pModel->m_pCurrentMaterial->MaterialName.Set( name );
|
m_pModel->m_pCurrentMaterial->MaterialName.Set(name);
|
||||||
m_pModel->m_MaterialLib.push_back( name );
|
m_pModel->m_MaterialLib.push_back(name);
|
||||||
m_pModel->m_MaterialMap[ name ] = m_pModel->m_pCurrentMaterial;
|
m_pModel->m_MaterialMap[name] = m_pModel->m_pCurrentMaterial;
|
||||||
|
|
||||||
if (m_pModel->m_pCurrentMesh) {
|
if (m_pModel->m_pCurrentMesh) {
|
||||||
m_pModel->m_pCurrentMesh->m_uiMaterialIndex = static_cast<unsigned int>(m_pModel->m_MaterialLib.size() - 1);
|
m_pModel->m_pCurrentMesh->m_uiMaterialIndex = static_cast<unsigned int>(m_pModel->m_MaterialLib.size() - 1);
|
||||||
|
@ -316,52 +283,52 @@ void ObjFileMtlImporter::createMaterial()
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
// Gets a texture name from data.
|
// Gets a texture name from data.
|
||||||
void ObjFileMtlImporter::getTexture() {
|
void ObjFileMtlImporter::getTexture() {
|
||||||
aiString *out( NULL );
|
aiString *out(NULL);
|
||||||
int clampIndex = -1;
|
int clampIndex = -1;
|
||||||
|
|
||||||
const char *pPtr( &(*m_DataIt) );
|
const char *pPtr(&(*m_DataIt));
|
||||||
if ( !ASSIMP_strincmp( pPtr, DiffuseTexture.c_str(), static_cast<unsigned int>(DiffuseTexture.size()) ) ) {
|
if (!ASSIMP_strincmp(pPtr, DiffuseTexture.c_str(), static_cast<unsigned int>(DiffuseTexture.size()))) {
|
||||||
// Diffuse texture
|
// Diffuse texture
|
||||||
out = & m_pModel->m_pCurrentMaterial->texture;
|
out = &m_pModel->m_pCurrentMaterial->texture;
|
||||||
clampIndex = ObjFile::Material::TextureDiffuseType;
|
clampIndex = ObjFile::Material::TextureDiffuseType;
|
||||||
} else if ( !ASSIMP_strincmp( pPtr,AmbientTexture.c_str(), static_cast<unsigned int>(AmbientTexture.size()) ) ) {
|
} else if (!ASSIMP_strincmp(pPtr, AmbientTexture.c_str(), static_cast<unsigned int>(AmbientTexture.size()))) {
|
||||||
// Ambient texture
|
// Ambient texture
|
||||||
out = & m_pModel->m_pCurrentMaterial->textureAmbient;
|
out = &m_pModel->m_pCurrentMaterial->textureAmbient;
|
||||||
clampIndex = ObjFile::Material::TextureAmbientType;
|
clampIndex = ObjFile::Material::TextureAmbientType;
|
||||||
} else if ( !ASSIMP_strincmp( pPtr, SpecularTexture.c_str(), static_cast<unsigned int>(SpecularTexture.size()) ) ) {
|
} else if (!ASSIMP_strincmp(pPtr, SpecularTexture.c_str(), static_cast<unsigned int>(SpecularTexture.size()))) {
|
||||||
// Specular texture
|
// Specular texture
|
||||||
out = & m_pModel->m_pCurrentMaterial->textureSpecular;
|
out = &m_pModel->m_pCurrentMaterial->textureSpecular;
|
||||||
clampIndex = ObjFile::Material::TextureSpecularType;
|
clampIndex = ObjFile::Material::TextureSpecularType;
|
||||||
} else if ( !ASSIMP_strincmp( pPtr, DisplacementTexture1.c_str(), static_cast<unsigned int>(DisplacementTexture1.size()) ) ||
|
} 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()) ) ) {
|
!ASSIMP_strincmp(pPtr, DisplacementTexture2.c_str(), static_cast<unsigned int>(DisplacementTexture2.size()))) {
|
||||||
// Displacement texture
|
// Displacement texture
|
||||||
out = &m_pModel->m_pCurrentMaterial->textureDisp;
|
out = &m_pModel->m_pCurrentMaterial->textureDisp;
|
||||||
clampIndex = ObjFile::Material::TextureDispType;
|
clampIndex = ObjFile::Material::TextureDispType;
|
||||||
} else if ( !ASSIMP_strincmp( pPtr, OpacityTexture.c_str(), static_cast<unsigned int>(OpacityTexture.size()) ) ) {
|
} else if (!ASSIMP_strincmp(pPtr, OpacityTexture.c_str(), static_cast<unsigned int>(OpacityTexture.size()))) {
|
||||||
// Opacity texture
|
// Opacity texture
|
||||||
out = & m_pModel->m_pCurrentMaterial->textureOpacity;
|
out = &m_pModel->m_pCurrentMaterial->textureOpacity;
|
||||||
clampIndex = ObjFile::Material::TextureOpacityType;
|
clampIndex = ObjFile::Material::TextureOpacityType;
|
||||||
} else if ( !ASSIMP_strincmp( pPtr, EmissiveTexture1.c_str(), static_cast<unsigned int>(EmissiveTexture1.size()) ) ||
|
} 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()) ) ) {
|
!ASSIMP_strincmp(pPtr, EmissiveTexture2.c_str(), static_cast<unsigned int>(EmissiveTexture2.size()))) {
|
||||||
// Emissive texture
|
// Emissive texture
|
||||||
out = & m_pModel->m_pCurrentMaterial->textureEmissive;
|
out = &m_pModel->m_pCurrentMaterial->textureEmissive;
|
||||||
clampIndex = ObjFile::Material::TextureEmissiveType;
|
clampIndex = ObjFile::Material::TextureEmissiveType;
|
||||||
} else if ( !ASSIMP_strincmp( pPtr, BumpTexture1.c_str(), static_cast<unsigned int>(BumpTexture1.size()) ) ||
|
} 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()) ) ) {
|
!ASSIMP_strincmp(pPtr, BumpTexture2.c_str(), static_cast<unsigned int>(BumpTexture2.size()))) {
|
||||||
// Bump texture
|
// Bump texture
|
||||||
out = & m_pModel->m_pCurrentMaterial->textureBump;
|
out = &m_pModel->m_pCurrentMaterial->textureBump;
|
||||||
clampIndex = ObjFile::Material::TextureBumpType;
|
clampIndex = ObjFile::Material::TextureBumpType;
|
||||||
} else if ( !ASSIMP_strincmp( pPtr,NormalTexture.c_str(), static_cast<unsigned int>(NormalTexture.size()) ) ) {
|
} else if (!ASSIMP_strincmp(pPtr, NormalTexture.c_str(), static_cast<unsigned int>(NormalTexture.size()))) {
|
||||||
// Normal map
|
// Normal map
|
||||||
out = & m_pModel->m_pCurrentMaterial->textureNormal;
|
out = &m_pModel->m_pCurrentMaterial->textureNormal;
|
||||||
clampIndex = ObjFile::Material::TextureNormalType;
|
clampIndex = ObjFile::Material::TextureNormalType;
|
||||||
} else if( !ASSIMP_strincmp( pPtr, ReflectionTexture.c_str(), static_cast<unsigned int>(ReflectionTexture.size()) ) ) {
|
} else if (!ASSIMP_strincmp(pPtr, ReflectionTexture.c_str(), static_cast<unsigned int>(ReflectionTexture.size()))) {
|
||||||
// Reflection texture(s)
|
// Reflection texture(s)
|
||||||
//Do nothing here
|
//Do nothing here
|
||||||
return;
|
return;
|
||||||
} else if ( !ASSIMP_strincmp( pPtr, SpecularityTexture.c_str(), static_cast<unsigned int>(SpecularityTexture.size()) ) ) {
|
} else if (!ASSIMP_strincmp(pPtr, SpecularityTexture.c_str(), static_cast<unsigned int>(SpecularityTexture.size()))) {
|
||||||
// Specularity scaling (glossiness)
|
// Specularity scaling (glossiness)
|
||||||
out = & m_pModel->m_pCurrentMaterial->textureSpecularity;
|
out = &m_pModel->m_pCurrentMaterial->textureSpecularity;
|
||||||
clampIndex = ObjFile::Material::TextureSpecularityType;
|
clampIndex = ObjFile::Material::TextureSpecularityType;
|
||||||
} else {
|
} else {
|
||||||
ASSIMP_LOG_ERROR("OBJ/MTL: Encountered unknown texture type");
|
ASSIMP_LOG_ERROR("OBJ/MTL: Encountered unknown texture type");
|
||||||
|
@ -373,9 +340,9 @@ void ObjFileMtlImporter::getTexture() {
|
||||||
m_pModel->m_pCurrentMaterial->clamp[clampIndex] = clamp;
|
m_pModel->m_pCurrentMaterial->clamp[clampIndex] = clamp;
|
||||||
|
|
||||||
std::string texture;
|
std::string texture;
|
||||||
m_DataIt = getName<DataArrayIt>( m_DataIt, m_DataItEnd, texture );
|
m_DataIt = getName<DataArrayIt>(m_DataIt, m_DataItEnd, texture);
|
||||||
if ( NULL!=out ) {
|
if (NULL != out) {
|
||||||
out->Set( texture );
|
out->Set(texture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -398,90 +365,57 @@ void ObjFileMtlImporter::getTextureOption(bool &clamp, int &clampIndex, aiString
|
||||||
m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
||||||
|
|
||||||
// If there is any more texture option
|
// If there is any more texture option
|
||||||
while (!isEndOfBuffer(m_DataIt, m_DataItEnd) && *m_DataIt == '-')
|
while (!isEndOfBuffer(m_DataIt, m_DataItEnd) && *m_DataIt == '-') {
|
||||||
{
|
const char *pPtr(&(*m_DataIt));
|
||||||
const char *pPtr( &(*m_DataIt) );
|
|
||||||
//skip option key and value
|
//skip option key and value
|
||||||
int skipToken = 1;
|
int skipToken = 1;
|
||||||
|
|
||||||
if (!ASSIMP_strincmp(pPtr, ClampOption.c_str(), static_cast<unsigned int>(ClampOption.size())))
|
if (!ASSIMP_strincmp(pPtr, ClampOption.c_str(), static_cast<unsigned int>(ClampOption.size()))) {
|
||||||
{
|
|
||||||
DataArrayIt it = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
DataArrayIt it = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
||||||
char value[3];
|
char value[3];
|
||||||
CopyNextWord(it, m_DataItEnd, value, sizeof(value) / sizeof(*value));
|
CopyNextWord(it, m_DataItEnd, value, sizeof(value) / sizeof(*value));
|
||||||
if (!ASSIMP_strincmp(value, "on", 2))
|
if (!ASSIMP_strincmp(value, "on", 2)) {
|
||||||
{
|
|
||||||
clamp = true;
|
clamp = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
skipToken = 2;
|
skipToken = 2;
|
||||||
}
|
} else if (!ASSIMP_strincmp(pPtr, TypeOption.c_str(), static_cast<unsigned int>(TypeOption.size()))) {
|
||||||
else if( !ASSIMP_strincmp( pPtr, TypeOption.c_str(), static_cast<unsigned int>(TypeOption.size()) ) )
|
DataArrayIt it = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
||||||
{
|
char value[12];
|
||||||
DataArrayIt it = getNextToken<DataArrayIt>( m_DataIt, m_DataItEnd );
|
CopyNextWord(it, m_DataItEnd, value, sizeof(value) / sizeof(*value));
|
||||||
char value[ 12 ];
|
if (!ASSIMP_strincmp(value, "cube_top", 8)) {
|
||||||
CopyNextWord( it, m_DataItEnd, value, sizeof( value ) / sizeof( *value ) );
|
|
||||||
if( !ASSIMP_strincmp( value, "cube_top", 8 ) )
|
|
||||||
{
|
|
||||||
clampIndex = ObjFile::Material::TextureReflectionCubeTopType;
|
clampIndex = ObjFile::Material::TextureReflectionCubeTopType;
|
||||||
out = &m_pModel->m_pCurrentMaterial->textureReflection[0];
|
out = &m_pModel->m_pCurrentMaterial->textureReflection[0];
|
||||||
}
|
} else if (!ASSIMP_strincmp(value, "cube_bottom", 11)) {
|
||||||
else if( !ASSIMP_strincmp( value, "cube_bottom", 11 ) )
|
|
||||||
{
|
|
||||||
clampIndex = ObjFile::Material::TextureReflectionCubeBottomType;
|
clampIndex = ObjFile::Material::TextureReflectionCubeBottomType;
|
||||||
out = &m_pModel->m_pCurrentMaterial->textureReflection[1];
|
out = &m_pModel->m_pCurrentMaterial->textureReflection[1];
|
||||||
}
|
} else if (!ASSIMP_strincmp(value, "cube_front", 10)) {
|
||||||
else if( !ASSIMP_strincmp( value, "cube_front", 10 ) )
|
|
||||||
{
|
|
||||||
clampIndex = ObjFile::Material::TextureReflectionCubeFrontType;
|
clampIndex = ObjFile::Material::TextureReflectionCubeFrontType;
|
||||||
out = &m_pModel->m_pCurrentMaterial->textureReflection[2];
|
out = &m_pModel->m_pCurrentMaterial->textureReflection[2];
|
||||||
}
|
} else if (!ASSIMP_strincmp(value, "cube_back", 9)) {
|
||||||
else if( !ASSIMP_strincmp( value, "cube_back", 9 ) )
|
|
||||||
{
|
|
||||||
clampIndex = ObjFile::Material::TextureReflectionCubeBackType;
|
clampIndex = ObjFile::Material::TextureReflectionCubeBackType;
|
||||||
out = &m_pModel->m_pCurrentMaterial->textureReflection[3];
|
out = &m_pModel->m_pCurrentMaterial->textureReflection[3];
|
||||||
}
|
} else if (!ASSIMP_strincmp(value, "cube_left", 9)) {
|
||||||
else if( !ASSIMP_strincmp( value, "cube_left", 9 ) )
|
|
||||||
{
|
|
||||||
clampIndex = ObjFile::Material::TextureReflectionCubeLeftType;
|
clampIndex = ObjFile::Material::TextureReflectionCubeLeftType;
|
||||||
out = &m_pModel->m_pCurrentMaterial->textureReflection[4];
|
out = &m_pModel->m_pCurrentMaterial->textureReflection[4];
|
||||||
}
|
} else if (!ASSIMP_strincmp(value, "cube_right", 10)) {
|
||||||
else if( !ASSIMP_strincmp( value, "cube_right", 10 ) )
|
|
||||||
{
|
|
||||||
clampIndex = ObjFile::Material::TextureReflectionCubeRightType;
|
clampIndex = ObjFile::Material::TextureReflectionCubeRightType;
|
||||||
out = &m_pModel->m_pCurrentMaterial->textureReflection[5];
|
out = &m_pModel->m_pCurrentMaterial->textureReflection[5];
|
||||||
}
|
} else if (!ASSIMP_strincmp(value, "sphere", 6)) {
|
||||||
else if( !ASSIMP_strincmp( value, "sphere", 6 ) )
|
|
||||||
{
|
|
||||||
clampIndex = ObjFile::Material::TextureReflectionSphereType;
|
clampIndex = ObjFile::Material::TextureReflectionSphereType;
|
||||||
out = &m_pModel->m_pCurrentMaterial->textureReflection[0];
|
out = &m_pModel->m_pCurrentMaterial->textureReflection[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
skipToken = 2;
|
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, BumpOption.c_str(), static_cast<unsigned int>(BumpOption.size())) || !ASSIMP_strincmp(pPtr, ChannelOption.c_str(), static_cast<unsigned int>(ChannelOption.size()))) {
|
||||||
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, BumpOption.c_str(), static_cast<unsigned int>(BumpOption.size()))
|
|
||||||
|| !ASSIMP_strincmp(pPtr, ChannelOption.c_str(), static_cast<unsigned int>(ChannelOption.size())))
|
|
||||||
{
|
|
||||||
skipToken = 2;
|
skipToken = 2;
|
||||||
}
|
} else if (!ASSIMP_strincmp(pPtr, ModifyMapOption.c_str(), static_cast<unsigned int>(ModifyMapOption.size()))) {
|
||||||
else if (!ASSIMP_strincmp(pPtr, ModifyMapOption.c_str(), static_cast<unsigned int>(ModifyMapOption.size())))
|
|
||||||
{
|
|
||||||
skipToken = 3;
|
skipToken = 3;
|
||||||
}
|
} else if (!ASSIMP_strincmp(pPtr, OffsetOption.c_str(), static_cast<unsigned int>(OffsetOption.size())) || !ASSIMP_strincmp(pPtr, ScaleOption.c_str(), static_cast<unsigned int>(ScaleOption.size())) || !ASSIMP_strincmp(pPtr, TurbulenceOption.c_str(), static_cast<unsigned int>(TurbulenceOption.size()))) {
|
||||||
else if ( !ASSIMP_strincmp(pPtr, OffsetOption.c_str(), static_cast<unsigned int>(OffsetOption.size()))
|
|
||||||
|| !ASSIMP_strincmp(pPtr, ScaleOption.c_str(), static_cast<unsigned int>(ScaleOption.size()))
|
|
||||||
|| !ASSIMP_strincmp(pPtr, TurbulenceOption.c_str(), static_cast<unsigned int>(TurbulenceOption.size()))
|
|
||||||
)
|
|
||||||
{
|
|
||||||
skipToken = 4;
|
skipToken = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < skipToken; ++i)
|
for (int i = 0; i < skipToken; ++i) {
|
||||||
{
|
|
||||||
m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
|
||||||
|
|
||||||
Copyright (c) 2006-2020, assimp team
|
Copyright (c) 2006-2020, assimp team
|
||||||
|
|
||||||
|
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use of this software in source and binary forms,
|
Redistribution and use of this software in source and binary forms,
|
||||||
|
@ -41,9 +40,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#ifndef OBJFILEMTLIMPORTER_H_INC
|
#ifndef OBJFILEMTLIMPORTER_H_INC
|
||||||
#define OBJFILEMTLIMPORTER_H_INC
|
#define OBJFILEMTLIMPORTER_H_INC
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
#include <assimp/defs.h>
|
#include <assimp/defs.h>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
struct aiColor3D;
|
struct aiColor3D;
|
||||||
struct aiString;
|
struct aiString;
|
||||||
|
@ -51,17 +50,15 @@ struct aiString;
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
|
|
||||||
namespace ObjFile {
|
namespace ObjFile {
|
||||||
struct Model;
|
struct Model;
|
||||||
struct Material;
|
struct Material;
|
||||||
}
|
} // namespace ObjFile
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class ObjFileMtlImporter
|
* @class ObjFileMtlImporter
|
||||||
* @brief Loads the material description from a mtl file.
|
* @brief Loads the material description from a mtl file.
|
||||||
*/
|
*/
|
||||||
class ObjFileMtlImporter
|
class ObjFileMtlImporter {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
static const size_t BUFFERSIZE = 2048;
|
static const size_t BUFFERSIZE = 2048;
|
||||||
typedef std::vector<char> DataArray;
|
typedef std::vector<char> DataArray;
|
||||||
|
@ -70,8 +67,8 @@ public:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//! \brief Default constructor
|
//! \brief Default constructor
|
||||||
ObjFileMtlImporter( std::vector<char> &buffer, const std::string &strAbsPath,
|
ObjFileMtlImporter(std::vector<char> &buffer, const std::string &strAbsPath,
|
||||||
ObjFile::Model *pModel );
|
ObjFile::Model *pModel);
|
||||||
|
|
||||||
//! \brief DEstructor
|
//! \brief DEstructor
|
||||||
~ObjFileMtlImporter();
|
~ObjFileMtlImporter();
|
||||||
|
@ -80,15 +77,15 @@ private:
|
||||||
/// Copy constructor, empty.
|
/// Copy constructor, empty.
|
||||||
ObjFileMtlImporter(const ObjFileMtlImporter &rOther);
|
ObjFileMtlImporter(const ObjFileMtlImporter &rOther);
|
||||||
/// \brief Assignment operator, returns only a reference of this instance.
|
/// \brief Assignment operator, returns only a reference of this instance.
|
||||||
ObjFileMtlImporter &operator = (const ObjFileMtlImporter &rOther);
|
ObjFileMtlImporter &operator=(const ObjFileMtlImporter &rOther);
|
||||||
/// Load the whole material description
|
/// Load the whole material description
|
||||||
void load();
|
void load();
|
||||||
/// Get color data.
|
/// Get color data.
|
||||||
void getColorRGBA( aiColor3D *pColor);
|
void getColorRGBA(aiColor3D *pColor);
|
||||||
/// Get illumination model from loaded data
|
/// Get illumination model from loaded data
|
||||||
void getIlluminationModel( int &illum_model );
|
void getIlluminationModel(int &illum_model);
|
||||||
/// Gets a float value from data.
|
/// Gets a float value from data.
|
||||||
void getFloatValue( ai_real &value );
|
void getFloatValue(ai_real &value);
|
||||||
/// Creates a new material from loaded data.
|
/// Creates a new material from loaded data.
|
||||||
void createMaterial();
|
void createMaterial();
|
||||||
/// Get texture name from loaded data.
|
/// Get texture name from loaded data.
|
||||||
|
|
|
@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
|
||||||
|
|
||||||
Copyright (c) 2006-2020, assimp team
|
Copyright (c) 2006-2020, assimp team
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use of this software in source and binary forms,
|
Redistribution and use of this software in source and binary forms,
|
||||||
|
@ -43,14 +41,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#ifndef ASSIMP_BUILD_NO_OBJ_IMPORTER
|
#ifndef ASSIMP_BUILD_NO_OBJ_IMPORTER
|
||||||
|
|
||||||
#include "ObjFileParser.h"
|
#include "ObjFileParser.h"
|
||||||
|
#include "ObjFileData.h"
|
||||||
#include "ObjFileMtlImporter.h"
|
#include "ObjFileMtlImporter.h"
|
||||||
#include "ObjTools.h"
|
#include "ObjTools.h"
|
||||||
#include "ObjFileData.h"
|
|
||||||
#include <assimp/ParsingUtils.h>
|
|
||||||
#include <assimp/BaseImporter.h>
|
#include <assimp/BaseImporter.h>
|
||||||
#include <assimp/DefaultIOSystem.h>
|
#include <assimp/DefaultIOSystem.h>
|
||||||
#include <assimp/DefaultLogger.hpp>
|
#include <assimp/ParsingUtils.h>
|
||||||
#include <assimp/material.h>
|
#include <assimp/material.h>
|
||||||
|
#include <assimp/DefaultLogger.hpp>
|
||||||
#include <assimp/Importer.hpp>
|
#include <assimp/Importer.hpp>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
|
@ -58,29 +56,22 @@ namespace Assimp {
|
||||||
|
|
||||||
const std::string ObjFileParser::DEFAULT_MATERIAL = AI_DEFAULT_MATERIAL_NAME;
|
const std::string ObjFileParser::DEFAULT_MATERIAL = AI_DEFAULT_MATERIAL_NAME;
|
||||||
|
|
||||||
ObjFileParser::ObjFileParser()
|
ObjFileParser::ObjFileParser() :
|
||||||
: m_DataIt()
|
m_DataIt(), m_DataItEnd(), m_pModel(nullptr), m_uiLine(0), m_pIO(nullptr), m_progress(nullptr), m_originalObjFileName() {
|
||||||
, m_DataItEnd()
|
|
||||||
, m_pModel( nullptr )
|
|
||||||
, m_uiLine( 0 )
|
|
||||||
, m_pIO( nullptr )
|
|
||||||
, m_progress( nullptr )
|
|
||||||
, m_originalObjFileName() {
|
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjFileParser::ObjFileParser( IOStreamBuffer<char> &streamBuffer, const std::string &modelName,
|
ObjFileParser::ObjFileParser(IOStreamBuffer<char> &streamBuffer, const std::string &modelName,
|
||||||
IOSystem *io, ProgressHandler* progress,
|
IOSystem *io, ProgressHandler *progress,
|
||||||
const std::string &originalObjFileName) :
|
const std::string &originalObjFileName) :
|
||||||
m_DataIt(),
|
m_DataIt(),
|
||||||
m_DataItEnd(),
|
m_DataItEnd(),
|
||||||
m_pModel(nullptr),
|
m_pModel(nullptr),
|
||||||
m_uiLine(0),
|
m_uiLine(0),
|
||||||
m_pIO( io ),
|
m_pIO(io),
|
||||||
m_progress(progress),
|
m_progress(progress),
|
||||||
m_originalObjFileName(originalObjFileName)
|
m_originalObjFileName(originalObjFileName) {
|
||||||
{
|
std::fill_n(m_buffer, Buffersize, '\0');
|
||||||
std::fill_n(m_buffer,Buffersize,'\0');
|
|
||||||
|
|
||||||
// Create the model instance to store all the data
|
// Create the model instance to store all the data
|
||||||
m_pModel.reset(new ObjFile::Model());
|
m_pModel.reset(new ObjFile::Model());
|
||||||
|
@ -88,18 +79,18 @@ ObjFileParser::ObjFileParser( IOStreamBuffer<char> &streamBuffer, const std::str
|
||||||
|
|
||||||
// create default material and store it
|
// create default material and store it
|
||||||
m_pModel->m_pDefaultMaterial = new ObjFile::Material;
|
m_pModel->m_pDefaultMaterial = new ObjFile::Material;
|
||||||
m_pModel->m_pDefaultMaterial->MaterialName.Set( DEFAULT_MATERIAL );
|
m_pModel->m_pDefaultMaterial->MaterialName.Set(DEFAULT_MATERIAL);
|
||||||
m_pModel->m_MaterialLib.push_back( DEFAULT_MATERIAL );
|
m_pModel->m_MaterialLib.push_back(DEFAULT_MATERIAL);
|
||||||
m_pModel->m_MaterialMap[ DEFAULT_MATERIAL ] = m_pModel->m_pDefaultMaterial;
|
m_pModel->m_MaterialMap[DEFAULT_MATERIAL] = m_pModel->m_pDefaultMaterial;
|
||||||
|
|
||||||
// Start parsing the file
|
// Start parsing the file
|
||||||
parseFile( streamBuffer );
|
parseFile(streamBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjFileParser::~ObjFileParser() {
|
ObjFileParser::~ObjFileParser() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjFileParser::setBuffer( std::vector<char> &buffer ) {
|
void ObjFileParser::setBuffer(std::vector<char> &buffer) {
|
||||||
m_DataIt = buffer.begin();
|
m_DataIt = buffer.begin();
|
||||||
m_DataItEnd = buffer.end();
|
m_DataItEnd = buffer.end();
|
||||||
}
|
}
|
||||||
|
@ -108,27 +99,27 @@ ObjFile::Model *ObjFileParser::GetModel() const {
|
||||||
return m_pModel.get();
|
return m_pModel.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjFileParser::parseFile( IOStreamBuffer<char> &streamBuffer ) {
|
void ObjFileParser::parseFile(IOStreamBuffer<char> &streamBuffer) {
|
||||||
// only update every 100KB or it'll be too slow
|
// only update every 100KB or it'll be too slow
|
||||||
//const unsigned int updateProgressEveryBytes = 100 * 1024;
|
//const unsigned int updateProgressEveryBytes = 100 * 1024;
|
||||||
unsigned int progressCounter = 0;
|
unsigned int progressCounter = 0;
|
||||||
const unsigned int bytesToProcess = static_cast<unsigned int>(streamBuffer.size());
|
const unsigned int bytesToProcess = static_cast<unsigned int>(streamBuffer.size());
|
||||||
const unsigned int progressTotal = bytesToProcess;
|
const unsigned int progressTotal = bytesToProcess;
|
||||||
unsigned int processed = 0;
|
unsigned int processed = 0;
|
||||||
size_t lastFilePos( 0 );
|
size_t lastFilePos(0);
|
||||||
|
|
||||||
std::vector<char> buffer;
|
std::vector<char> buffer;
|
||||||
while ( streamBuffer.getNextDataLine( buffer, '\\' ) ) {
|
while (streamBuffer.getNextDataLine(buffer, '\\')) {
|
||||||
m_DataIt = buffer.begin();
|
m_DataIt = buffer.begin();
|
||||||
m_DataItEnd = buffer.end();
|
m_DataItEnd = buffer.end();
|
||||||
|
|
||||||
// Handle progress reporting
|
// Handle progress reporting
|
||||||
const size_t filePos( streamBuffer.getFilePos() );
|
const size_t filePos(streamBuffer.getFilePos());
|
||||||
if ( lastFilePos < filePos ) {
|
if (lastFilePos < filePos) {
|
||||||
processed = static_cast<unsigned int>(filePos);
|
processed = static_cast<unsigned int>(filePos);
|
||||||
lastFilePos = filePos;
|
lastFilePos = filePos;
|
||||||
progressCounter++;
|
progressCounter++;
|
||||||
m_progress->UpdateFileRead( processed, progressTotal );
|
m_progress->UpdateFileRead(processed, progressTotal);
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse line
|
// parse line
|
||||||
|
@ -156,25 +147,20 @@ void ObjFileParser::parseFile( IOStreamBuffer<char> &streamBuffer ) {
|
||||||
} else if (*m_DataIt == 'n') {
|
} else if (*m_DataIt == 'n') {
|
||||||
// Read in normal vector definition
|
// Read in normal vector definition
|
||||||
++m_DataIt;
|
++m_DataIt;
|
||||||
getVector3( m_pModel->m_Normals );
|
getVector3(m_pModel->m_Normals);
|
||||||
}
|
}
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case 'p': // Parse a face, line or point statement
|
case 'p': // Parse a face, line or point statement
|
||||||
case 'l':
|
case 'l':
|
||||||
case 'f':
|
case 'f': {
|
||||||
{
|
getFace(*m_DataIt == 'f' ? aiPrimitiveType_POLYGON : (*m_DataIt == 'l' ? aiPrimitiveType_LINE : aiPrimitiveType_POINT));
|
||||||
getFace(*m_DataIt == 'f' ? aiPrimitiveType_POLYGON : (*m_DataIt == 'l'
|
} break;
|
||||||
? aiPrimitiveType_LINE : aiPrimitiveType_POINT));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '#': // Parse a comment
|
case '#': // Parse a comment
|
||||||
{
|
{
|
||||||
getComment();
|
getComment();
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case 'u': // Parse a material desc. setter
|
case 'u': // Parse a material desc. setter
|
||||||
{
|
{
|
||||||
|
@ -186,12 +172,10 @@ void ObjFileParser::parseFile( IOStreamBuffer<char> &streamBuffer ) {
|
||||||
if (nextSpace != std::string::npos)
|
if (nextSpace != std::string::npos)
|
||||||
name = name.substr(0, nextSpace);
|
name = name.substr(0, nextSpace);
|
||||||
|
|
||||||
if(name == "usemtl")
|
if (name == "usemtl") {
|
||||||
{
|
|
||||||
getMaterialDesc();
|
getMaterialDesc();
|
||||||
}
|
}
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case 'm': // Parse a material library or merging group ('mg')
|
case 'm': // Parse a material library or merging group ('mg')
|
||||||
{
|
{
|
||||||
|
@ -205,37 +189,31 @@ void ObjFileParser::parseFile( IOStreamBuffer<char> &streamBuffer ) {
|
||||||
|
|
||||||
if (name == "mg")
|
if (name == "mg")
|
||||||
getGroupNumberAndResolution();
|
getGroupNumberAndResolution();
|
||||||
else if(name == "mtllib")
|
else if (name == "mtllib")
|
||||||
getMaterialLib();
|
getMaterialLib();
|
||||||
else
|
else
|
||||||
goto pf_skip_line;
|
goto pf_skip_line;
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case 'g': // Parse group name
|
case 'g': // Parse group name
|
||||||
{
|
{
|
||||||
getGroupName();
|
getGroupName();
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case 's': // Parse group number
|
case 's': // Parse group number
|
||||||
{
|
{
|
||||||
getGroupNumber();
|
getGroupNumber();
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case 'o': // Parse object name
|
case 'o': // Parse object name
|
||||||
{
|
{
|
||||||
getObjectName();
|
getObjectName();
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default: {
|
||||||
{
|
pf_skip_line:
|
||||||
pf_skip_line:
|
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||||
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
} break;
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -243,15 +221,15 @@ pf_skip_line:
|
||||||
void ObjFileParser::copyNextWord(char *pBuffer, size_t length) {
|
void ObjFileParser::copyNextWord(char *pBuffer, size_t length) {
|
||||||
size_t index = 0;
|
size_t index = 0;
|
||||||
m_DataIt = getNextWord<DataArrayIt>(m_DataIt, m_DataItEnd);
|
m_DataIt = getNextWord<DataArrayIt>(m_DataIt, m_DataItEnd);
|
||||||
if ( *m_DataIt == '\\' ) {
|
if (*m_DataIt == '\\') {
|
||||||
++m_DataIt;
|
++m_DataIt;
|
||||||
++m_DataIt;
|
++m_DataIt;
|
||||||
m_DataIt = getNextWord<DataArrayIt>( m_DataIt, m_DataItEnd );
|
m_DataIt = getNextWord<DataArrayIt>(m_DataIt, m_DataItEnd);
|
||||||
}
|
}
|
||||||
while( m_DataIt != m_DataItEnd && !IsSpaceOrNewLine( *m_DataIt ) ) {
|
while (m_DataIt != m_DataItEnd && !IsSpaceOrNewLine(*m_DataIt)) {
|
||||||
pBuffer[index] = *m_DataIt;
|
pBuffer[index] = *m_DataIt;
|
||||||
index++;
|
index++;
|
||||||
if( index == length - 1 ) {
|
if (index == length - 1) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
++m_DataIt;
|
++m_DataIt;
|
||||||
|
@ -261,10 +239,10 @@ void ObjFileParser::copyNextWord(char *pBuffer, size_t length) {
|
||||||
pBuffer[index] = '\0';
|
pBuffer[index] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isDataDefinitionEnd( const char *tmp ) {
|
static bool isDataDefinitionEnd(const char *tmp) {
|
||||||
if ( *tmp == '\\' ) {
|
if (*tmp == '\\') {
|
||||||
tmp++;
|
tmp++;
|
||||||
if ( IsLineEnd( *tmp ) ) {
|
if (IsLineEnd(*tmp)) {
|
||||||
tmp++;
|
tmp++;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -272,58 +250,58 @@ static bool isDataDefinitionEnd( const char *tmp ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isNanOrInf(const char * in) {
|
static bool isNanOrInf(const char *in) {
|
||||||
// Look for "nan" or "inf", case insensitive
|
// Look for "nan" or "inf", case insensitive
|
||||||
return ((in[0] == 'N' || in[0] == 'n') && ASSIMP_strincmp(in, "nan", 3) == 0) ||
|
return ((in[0] == 'N' || in[0] == 'n') && ASSIMP_strincmp(in, "nan", 3) == 0) ||
|
||||||
((in[0] == 'I' || in[0] == 'i') && ASSIMP_strincmp(in, "inf", 3) == 0);
|
((in[0] == 'I' || in[0] == 'i') && ASSIMP_strincmp(in, "inf", 3) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ObjFileParser::getNumComponentsInDataDefinition() {
|
size_t ObjFileParser::getNumComponentsInDataDefinition() {
|
||||||
size_t numComponents( 0 );
|
size_t numComponents(0);
|
||||||
const char* tmp( &m_DataIt[0] );
|
const char *tmp(&m_DataIt[0]);
|
||||||
bool end_of_definition = false;
|
bool end_of_definition = false;
|
||||||
while ( !end_of_definition ) {
|
while (!end_of_definition) {
|
||||||
if ( isDataDefinitionEnd( tmp ) ) {
|
if (isDataDefinitionEnd(tmp)) {
|
||||||
tmp += 2;
|
tmp += 2;
|
||||||
} else if ( IsLineEnd( *tmp ) ) {
|
} else if (IsLineEnd(*tmp)) {
|
||||||
end_of_definition = true;
|
end_of_definition = true;
|
||||||
}
|
}
|
||||||
if ( !SkipSpaces( &tmp ) ) {
|
if (!SkipSpaces(&tmp)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
const bool isNum( IsNumeric( *tmp ) || isNanOrInf(tmp));
|
const bool isNum(IsNumeric(*tmp) || isNanOrInf(tmp));
|
||||||
SkipToken( tmp );
|
SkipToken(tmp);
|
||||||
if ( isNum ) {
|
if (isNum) {
|
||||||
++numComponents;
|
++numComponents;
|
||||||
}
|
}
|
||||||
if ( !SkipSpaces( &tmp ) ) {
|
if (!SkipSpaces(&tmp)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return numComponents;
|
return numComponents;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ObjFileParser::getTexCoordVector( std::vector<aiVector3D> &point3d_array ) {
|
size_t ObjFileParser::getTexCoordVector(std::vector<aiVector3D> &point3d_array) {
|
||||||
size_t numComponents = getNumComponentsInDataDefinition();
|
size_t numComponents = getNumComponentsInDataDefinition();
|
||||||
ai_real x, y, z;
|
ai_real x, y, z;
|
||||||
if( 2 == numComponents ) {
|
if (2 == numComponents) {
|
||||||
copyNextWord( m_buffer, Buffersize );
|
copyNextWord(m_buffer, Buffersize);
|
||||||
x = ( ai_real ) fast_atof( m_buffer );
|
x = (ai_real)fast_atof(m_buffer);
|
||||||
|
|
||||||
copyNextWord( m_buffer, Buffersize );
|
copyNextWord(m_buffer, Buffersize);
|
||||||
y = ( ai_real ) fast_atof( m_buffer );
|
y = (ai_real)fast_atof(m_buffer);
|
||||||
z = 0.0;
|
z = 0.0;
|
||||||
} else if( 3 == numComponents ) {
|
} else if (3 == numComponents) {
|
||||||
copyNextWord( m_buffer, Buffersize );
|
copyNextWord(m_buffer, Buffersize);
|
||||||
x = ( ai_real ) fast_atof( m_buffer );
|
x = (ai_real)fast_atof(m_buffer);
|
||||||
|
|
||||||
copyNextWord( m_buffer, Buffersize );
|
copyNextWord(m_buffer, Buffersize);
|
||||||
y = ( ai_real ) fast_atof( m_buffer );
|
y = (ai_real)fast_atof(m_buffer);
|
||||||
|
|
||||||
copyNextWord( m_buffer, Buffersize );
|
copyNextWord(m_buffer, Buffersize);
|
||||||
z = ( ai_real ) fast_atof( m_buffer );
|
z = (ai_real)fast_atof(m_buffer);
|
||||||
} else {
|
} else {
|
||||||
throw DeadlyImportError( "OBJ: Invalid number of components" );
|
throw DeadlyImportError("OBJ: Invalid number of components");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Coerce nan and inf to 0 as is the OBJ default value
|
// Coerce nan and inf to 0 as is the OBJ default value
|
||||||
|
@ -336,96 +314,96 @@ size_t ObjFileParser::getTexCoordVector( std::vector<aiVector3D> &point3d_array
|
||||||
if (!std::isfinite(z))
|
if (!std::isfinite(z))
|
||||||
z = 0;
|
z = 0;
|
||||||
|
|
||||||
point3d_array.emplace_back( x, y, z );
|
point3d_array.emplace_back(x, y, z);
|
||||||
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||||
return numComponents;
|
return numComponents;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjFileParser::getVector3( std::vector<aiVector3D> &point3d_array ) {
|
void ObjFileParser::getVector3(std::vector<aiVector3D> &point3d_array) {
|
||||||
ai_real x, y, z;
|
ai_real x, y, z;
|
||||||
copyNextWord(m_buffer, Buffersize);
|
copyNextWord(m_buffer, Buffersize);
|
||||||
x = (ai_real) fast_atof(m_buffer);
|
x = (ai_real)fast_atof(m_buffer);
|
||||||
|
|
||||||
copyNextWord(m_buffer, Buffersize);
|
copyNextWord(m_buffer, Buffersize);
|
||||||
y = (ai_real) fast_atof(m_buffer);
|
y = (ai_real)fast_atof(m_buffer);
|
||||||
|
|
||||||
copyNextWord( m_buffer, Buffersize );
|
copyNextWord(m_buffer, Buffersize);
|
||||||
z = ( ai_real ) fast_atof( m_buffer );
|
z = (ai_real)fast_atof(m_buffer);
|
||||||
|
|
||||||
point3d_array.emplace_back( x, y, z );
|
point3d_array.emplace_back(x, y, z);
|
||||||
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjFileParser::getHomogeneousVector3( std::vector<aiVector3D> &point3d_array ) {
|
void ObjFileParser::getHomogeneousVector3(std::vector<aiVector3D> &point3d_array) {
|
||||||
ai_real x, y, z, w;
|
ai_real x, y, z, w;
|
||||||
copyNextWord(m_buffer, Buffersize);
|
copyNextWord(m_buffer, Buffersize);
|
||||||
x = (ai_real) fast_atof(m_buffer);
|
x = (ai_real)fast_atof(m_buffer);
|
||||||
|
|
||||||
copyNextWord(m_buffer, Buffersize);
|
copyNextWord(m_buffer, Buffersize);
|
||||||
y = (ai_real) fast_atof(m_buffer);
|
y = (ai_real)fast_atof(m_buffer);
|
||||||
|
|
||||||
copyNextWord( m_buffer, Buffersize );
|
copyNextWord(m_buffer, Buffersize);
|
||||||
z = ( ai_real ) fast_atof( m_buffer );
|
z = (ai_real)fast_atof(m_buffer);
|
||||||
|
|
||||||
copyNextWord( m_buffer, Buffersize );
|
copyNextWord(m_buffer, Buffersize);
|
||||||
w = ( ai_real ) fast_atof( m_buffer );
|
w = (ai_real)fast_atof(m_buffer);
|
||||||
|
|
||||||
if (w == 0)
|
if (w == 0)
|
||||||
throw DeadlyImportError("OBJ: Invalid component in homogeneous vector (Division by zero)");
|
throw DeadlyImportError("OBJ: Invalid component in homogeneous vector (Division by zero)");
|
||||||
|
|
||||||
point3d_array.emplace_back( x/w, y/w, z/w );
|
point3d_array.emplace_back(x / w, y / w, z / w);
|
||||||
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjFileParser::getTwoVectors3( std::vector<aiVector3D> &point3d_array_a, std::vector<aiVector3D> &point3d_array_b ) {
|
void ObjFileParser::getTwoVectors3(std::vector<aiVector3D> &point3d_array_a, std::vector<aiVector3D> &point3d_array_b) {
|
||||||
ai_real x, y, z;
|
ai_real x, y, z;
|
||||||
copyNextWord(m_buffer, Buffersize);
|
copyNextWord(m_buffer, Buffersize);
|
||||||
x = (ai_real) fast_atof(m_buffer);
|
x = (ai_real)fast_atof(m_buffer);
|
||||||
|
|
||||||
copyNextWord(m_buffer, Buffersize);
|
copyNextWord(m_buffer, Buffersize);
|
||||||
y = (ai_real) fast_atof(m_buffer);
|
y = (ai_real)fast_atof(m_buffer);
|
||||||
|
|
||||||
copyNextWord( m_buffer, Buffersize );
|
|
||||||
z = ( ai_real ) fast_atof( m_buffer );
|
|
||||||
|
|
||||||
point3d_array_a.emplace_back( x, y, z );
|
|
||||||
|
|
||||||
copyNextWord(m_buffer, Buffersize);
|
copyNextWord(m_buffer, Buffersize);
|
||||||
x = (ai_real) fast_atof(m_buffer);
|
z = (ai_real)fast_atof(m_buffer);
|
||||||
|
|
||||||
|
point3d_array_a.emplace_back(x, y, z);
|
||||||
|
|
||||||
copyNextWord(m_buffer, Buffersize);
|
copyNextWord(m_buffer, Buffersize);
|
||||||
y = (ai_real) fast_atof(m_buffer);
|
x = (ai_real)fast_atof(m_buffer);
|
||||||
|
|
||||||
copyNextWord( m_buffer, Buffersize );
|
copyNextWord(m_buffer, Buffersize);
|
||||||
z = ( ai_real ) fast_atof( m_buffer );
|
y = (ai_real)fast_atof(m_buffer);
|
||||||
|
|
||||||
point3d_array_b.emplace_back( x, y, z );
|
copyNextWord(m_buffer, Buffersize);
|
||||||
|
z = (ai_real)fast_atof(m_buffer);
|
||||||
|
|
||||||
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
point3d_array_b.emplace_back(x, y, z);
|
||||||
|
|
||||||
|
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjFileParser::getVector2( std::vector<aiVector2D> &point2d_array ) {
|
void ObjFileParser::getVector2(std::vector<aiVector2D> &point2d_array) {
|
||||||
ai_real x, y;
|
ai_real x, y;
|
||||||
copyNextWord(m_buffer, Buffersize);
|
copyNextWord(m_buffer, Buffersize);
|
||||||
x = (ai_real) fast_atof(m_buffer);
|
x = (ai_real)fast_atof(m_buffer);
|
||||||
|
|
||||||
copyNextWord(m_buffer, Buffersize);
|
copyNextWord(m_buffer, Buffersize);
|
||||||
y = (ai_real) fast_atof(m_buffer);
|
y = (ai_real)fast_atof(m_buffer);
|
||||||
|
|
||||||
point2d_array.emplace_back(x, y);
|
point2d_array.emplace_back(x, y);
|
||||||
|
|
||||||
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const std::string DefaultObjName = "defaultobject";
|
static const std::string DefaultObjName = "defaultobject";
|
||||||
|
|
||||||
void ObjFileParser::getFace( aiPrimitiveType type ) {
|
void ObjFileParser::getFace(aiPrimitiveType type) {
|
||||||
m_DataIt = getNextToken<DataArrayIt>( m_DataIt, m_DataItEnd );
|
m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
||||||
if ( m_DataIt == m_DataItEnd || *m_DataIt == '\0' ) {
|
if (m_DataIt == m_DataItEnd || *m_DataIt == '\0') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjFile::Face *face = new ObjFile::Face( type );
|
ObjFile::Face *face = new ObjFile::Face(type);
|
||||||
bool hasNormal = false;
|
bool hasNormal = false;
|
||||||
|
|
||||||
const int vSize = static_cast<unsigned int>(m_pModel->m_Vertices.size());
|
const int vSize = static_cast<unsigned int>(m_pModel->m_Vertices.size());
|
||||||
|
@ -435,56 +413,56 @@ void ObjFileParser::getFace( aiPrimitiveType type ) {
|
||||||
const bool vt = (!m_pModel->m_TextureCoord.empty());
|
const bool vt = (!m_pModel->m_TextureCoord.empty());
|
||||||
const bool vn = (!m_pModel->m_Normals.empty());
|
const bool vn = (!m_pModel->m_Normals.empty());
|
||||||
int iPos = 0;
|
int iPos = 0;
|
||||||
while ( m_DataIt != m_DataItEnd ) {
|
while (m_DataIt != m_DataItEnd) {
|
||||||
int iStep = 1;
|
int iStep = 1;
|
||||||
|
|
||||||
if ( IsLineEnd( *m_DataIt ) ) {
|
if (IsLineEnd(*m_DataIt)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( *m_DataIt =='/' ) {
|
if (*m_DataIt == '/') {
|
||||||
if (type == aiPrimitiveType_POINT) {
|
if (type == aiPrimitiveType_POINT) {
|
||||||
ASSIMP_LOG_ERROR("Obj: Separator unexpected in point statement");
|
ASSIMP_LOG_ERROR("Obj: Separator unexpected in point statement");
|
||||||
}
|
}
|
||||||
iPos++;
|
iPos++;
|
||||||
} else if( IsSpaceOrNewLine( *m_DataIt ) ) {
|
} else if (IsSpaceOrNewLine(*m_DataIt)) {
|
||||||
iPos = 0;
|
iPos = 0;
|
||||||
} else {
|
} else {
|
||||||
//OBJ USES 1 Base ARRAYS!!!!
|
//OBJ USES 1 Base ARRAYS!!!!
|
||||||
const int iVal( ::atoi( & ( *m_DataIt ) ) );
|
const int iVal(::atoi(&(*m_DataIt)));
|
||||||
|
|
||||||
// increment iStep position based off of the sign and # of digits
|
// increment iStep position based off of the sign and # of digits
|
||||||
int tmp = iVal;
|
int tmp = iVal;
|
||||||
if ( iVal < 0 ) {
|
if (iVal < 0) {
|
||||||
++iStep;
|
++iStep;
|
||||||
}
|
}
|
||||||
while ( ( tmp = tmp / 10 ) != 0 ) {
|
while ((tmp = tmp / 10) != 0) {
|
||||||
++iStep;
|
++iStep;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iPos == 1 && !vt && vn)
|
if (iPos == 1 && !vt && vn)
|
||||||
iPos = 2; // skip texture coords for normals if there are no tex coords
|
iPos = 2; // skip texture coords for normals if there are no tex coords
|
||||||
|
|
||||||
if ( iVal > 0 ) {
|
if (iVal > 0) {
|
||||||
// Store parsed index
|
// Store parsed index
|
||||||
if ( 0 == iPos ) {
|
if (0 == iPos) {
|
||||||
face->m_vertices.push_back( iVal - 1 );
|
face->m_vertices.push_back(iVal - 1);
|
||||||
} else if ( 1 == iPos ) {
|
} else if (1 == iPos) {
|
||||||
face->m_texturCoords.push_back( iVal - 1 );
|
face->m_texturCoords.push_back(iVal - 1);
|
||||||
} else if ( 2 == iPos ) {
|
} else if (2 == iPos) {
|
||||||
face->m_normals.push_back( iVal - 1 );
|
face->m_normals.push_back(iVal - 1);
|
||||||
hasNormal = true;
|
hasNormal = true;
|
||||||
} else {
|
} else {
|
||||||
reportErrorTokenInFace();
|
reportErrorTokenInFace();
|
||||||
}
|
}
|
||||||
} else if ( iVal < 0 ) {
|
} else if (iVal < 0) {
|
||||||
// Store relatively index
|
// Store relatively index
|
||||||
if ( 0 == iPos ) {
|
if (0 == iPos) {
|
||||||
face->m_vertices.push_back( vSize + iVal );
|
face->m_vertices.push_back(vSize + iVal);
|
||||||
} else if ( 1 == iPos ) {
|
} else if (1 == iPos) {
|
||||||
face->m_texturCoords.push_back( vtSize + iVal );
|
face->m_texturCoords.push_back(vtSize + iVal);
|
||||||
} else if ( 2 == iPos ) {
|
} else if (2 == iPos) {
|
||||||
face->m_normals.push_back( vnSize + iVal );
|
face->m_normals.push_back(vnSize + iVal);
|
||||||
hasNormal = true;
|
hasNormal = true;
|
||||||
} else {
|
} else {
|
||||||
reportErrorTokenInFace();
|
reportErrorTokenInFace();
|
||||||
|
@ -494,45 +472,44 @@ void ObjFileParser::getFace( aiPrimitiveType type ) {
|
||||||
delete face;
|
delete face;
|
||||||
throw DeadlyImportError("OBJ: Invalid face indice");
|
throw DeadlyImportError("OBJ: Invalid face indice");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
m_DataIt += iStep;
|
m_DataIt += iStep;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( face->m_vertices.empty() ) {
|
if (face->m_vertices.empty()) {
|
||||||
ASSIMP_LOG_ERROR("Obj: Ignoring empty face");
|
ASSIMP_LOG_ERROR("Obj: Ignoring empty face");
|
||||||
// skip line and clean up
|
// skip line and clean up
|
||||||
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||||
delete face;
|
delete face;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set active material, if one set
|
// Set active material, if one set
|
||||||
if( NULL != m_pModel->m_pCurrentMaterial ) {
|
if (NULL != m_pModel->m_pCurrentMaterial) {
|
||||||
face->m_pMaterial = m_pModel->m_pCurrentMaterial;
|
face->m_pMaterial = m_pModel->m_pCurrentMaterial;
|
||||||
} else {
|
} else {
|
||||||
face->m_pMaterial = m_pModel->m_pDefaultMaterial;
|
face->m_pMaterial = m_pModel->m_pDefaultMaterial;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a default object, if nothing is there
|
// Create a default object, if nothing is there
|
||||||
if( NULL == m_pModel->m_pCurrent ) {
|
if (NULL == m_pModel->m_pCurrent) {
|
||||||
createObject( DefaultObjName );
|
createObject(DefaultObjName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assign face to mesh
|
// Assign face to mesh
|
||||||
if ( NULL == m_pModel->m_pCurrentMesh ) {
|
if (NULL == m_pModel->m_pCurrentMesh) {
|
||||||
createMesh( DefaultObjName );
|
createMesh(DefaultObjName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store the face
|
// Store the face
|
||||||
m_pModel->m_pCurrentMesh->m_Faces.push_back( 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_uiNumIndices += (unsigned int)face->m_vertices.size();
|
||||||
m_pModel->m_pCurrentMesh->m_uiUVCoordinates[ 0 ] += (unsigned int) face->m_texturCoords.size();
|
m_pModel->m_pCurrentMesh->m_uiUVCoordinates[0] += (unsigned int)face->m_texturCoords.size();
|
||||||
if( !m_pModel->m_pCurrentMesh->m_hasNormals && hasNormal ) {
|
if (!m_pModel->m_pCurrentMesh->m_hasNormals && hasNormal) {
|
||||||
m_pModel->m_pCurrentMesh->m_hasNormals = true;
|
m_pModel->m_pCurrentMesh->m_hasNormals = true;
|
||||||
}
|
}
|
||||||
// Skip the rest of the line
|
// Skip the rest of the line
|
||||||
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjFileParser::getMaterialDesc() {
|
void ObjFileParser::getMaterialDesc() {
|
||||||
|
@ -543,7 +520,7 @@ void ObjFileParser::getMaterialDesc() {
|
||||||
}
|
}
|
||||||
|
|
||||||
char *pStart = &(*m_DataIt);
|
char *pStart = &(*m_DataIt);
|
||||||
while( m_DataIt != m_DataItEnd && !IsLineEnd( *m_DataIt ) ) {
|
while (m_DataIt != m_DataItEnd && !IsLineEnd(*m_DataIt)) {
|
||||||
++m_DataIt;
|
++m_DataIt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -558,13 +535,13 @@ void ObjFileParser::getMaterialDesc() {
|
||||||
|
|
||||||
// If the current mesh has the same material, we simply ignore that 'usemtl' command
|
// 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
|
// 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->m_pCurrentMaterial && m_pModel->m_pCurrentMaterial->MaterialName == aiString(strName)) {
|
||||||
skip = true;
|
skip = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!skip) {
|
if (!skip) {
|
||||||
// Search for material
|
// Search for material
|
||||||
std::map<std::string, ObjFile::Material*>::iterator it = m_pModel->m_MaterialMap.find(strName);
|
std::map<std::string, ObjFile::Material *>::iterator it = m_pModel->m_MaterialMap.find(strName);
|
||||||
if (it == m_pModel->m_MaterialMap.end()) {
|
if (it == m_pModel->m_MaterialMap.end()) {
|
||||||
// Not found, so we don't know anything about the material except for its name.
|
// 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
|
// This may be the case if the material library is missing. We don't want to lose all
|
||||||
|
@ -580,21 +557,21 @@ void ObjFileParser::getMaterialDesc() {
|
||||||
m_pModel->m_pCurrentMaterial = (*it).second;
|
m_pModel->m_pCurrentMaterial = (*it).second;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( needsNewMesh( strName ) ) {
|
if (needsNewMesh(strName)) {
|
||||||
createMesh( strName );
|
createMesh(strName);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pModel->m_pCurrentMesh->m_uiMaterialIndex = getMaterialIndex(strName);
|
m_pModel->m_pCurrentMesh->m_uiMaterialIndex = getMaterialIndex(strName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip rest of line
|
// Skip rest of line
|
||||||
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
// Get a comment, values will be skipped
|
// Get a comment, values will be skipped
|
||||||
void ObjFileParser::getComment() {
|
void ObjFileParser::getComment() {
|
||||||
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
|
@ -602,12 +579,12 @@ void ObjFileParser::getComment() {
|
||||||
void ObjFileParser::getMaterialLib() {
|
void ObjFileParser::getMaterialLib() {
|
||||||
// Translate tuple
|
// Translate tuple
|
||||||
m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
||||||
if( m_DataIt == m_DataItEnd ) {
|
if (m_DataIt == m_DataItEnd) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *pStart = &(*m_DataIt);
|
char *pStart = &(*m_DataIt);
|
||||||
while( m_DataIt != m_DataItEnd && !IsLineEnd( *m_DataIt ) ) {
|
while (m_DataIt != m_DataItEnd && !IsLineEnd(*m_DataIt)) {
|
||||||
++m_DataIt;
|
++m_DataIt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -616,14 +593,14 @@ void ObjFileParser::getMaterialLib() {
|
||||||
std::string absName;
|
std::string absName;
|
||||||
|
|
||||||
// Check if directive is valid.
|
// Check if directive is valid.
|
||||||
if ( 0 == strMatName.length() ) {
|
if (0 == strMatName.length()) {
|
||||||
ASSIMP_LOG_WARN( "OBJ: no name for material library specified." );
|
ASSIMP_LOG_WARN("OBJ: no name for material library specified.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( m_pIO->StackSize() > 0 ) {
|
if (m_pIO->StackSize() > 0) {
|
||||||
std::string path = m_pIO->CurrentDirectory();
|
std::string path = m_pIO->CurrentDirectory();
|
||||||
if ( '/' != *path.rbegin() ) {
|
if ('/' != *path.rbegin()) {
|
||||||
path += '/';
|
path += '/';
|
||||||
}
|
}
|
||||||
absName += path;
|
absName += path;
|
||||||
|
@ -632,8 +609,8 @@ void ObjFileParser::getMaterialLib() {
|
||||||
absName = strMatName;
|
absName = strMatName;
|
||||||
}
|
}
|
||||||
|
|
||||||
IOStream *pFile = m_pIO->Open( absName );
|
IOStream *pFile = m_pIO->Open(absName);
|
||||||
if ( nullptr == pFile ) {
|
if (nullptr == pFile) {
|
||||||
ASSIMP_LOG_ERROR("OBJ: Unable to locate material file " + strMatName);
|
ASSIMP_LOG_ERROR("OBJ: Unable to locate material file " + strMatName);
|
||||||
std::string strMatFallbackName = m_originalObjFileName.substr(0, m_originalObjFileName.length() - 3) + "mtl";
|
std::string strMatFallbackName = m_originalObjFileName.substr(0, m_originalObjFileName.length() - 3) + "mtl";
|
||||||
ASSIMP_LOG_INFO("OBJ: Opening fallback material file " + strMatFallbackName);
|
ASSIMP_LOG_INFO("OBJ: Opening fallback material file " + strMatFallbackName);
|
||||||
|
@ -650,11 +627,11 @@ void ObjFileParser::getMaterialLib() {
|
||||||
// material files if the model doesn't use any materials, so we
|
// material files if the model doesn't use any materials, so we
|
||||||
// allow that.
|
// allow that.
|
||||||
std::vector<char> buffer;
|
std::vector<char> buffer;
|
||||||
BaseImporter::TextFileToBuffer( pFile, buffer, BaseImporter::ALLOW_EMPTY );
|
BaseImporter::TextFileToBuffer(pFile, buffer, BaseImporter::ALLOW_EMPTY);
|
||||||
m_pIO->Close( pFile );
|
m_pIO->Close(pFile);
|
||||||
|
|
||||||
// Importing the material library
|
// Importing the material library
|
||||||
ObjFileMtlImporter mtlImporter( buffer, strMatName, m_pModel.get() );
|
ObjFileMtlImporter mtlImporter(buffer, strMatName, m_pModel.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
|
@ -662,42 +639,39 @@ void ObjFileParser::getMaterialLib() {
|
||||||
void ObjFileParser::getNewMaterial() {
|
void ObjFileParser::getNewMaterial() {
|
||||||
m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
||||||
m_DataIt = getNextWord<DataArrayIt>(m_DataIt, m_DataItEnd);
|
m_DataIt = getNextWord<DataArrayIt>(m_DataIt, m_DataItEnd);
|
||||||
if( m_DataIt == m_DataItEnd ) {
|
if (m_DataIt == m_DataItEnd) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *pStart = &(*m_DataIt);
|
char *pStart = &(*m_DataIt);
|
||||||
std::string strMat( pStart, *m_DataIt );
|
std::string strMat(pStart, *m_DataIt);
|
||||||
while( m_DataIt != m_DataItEnd && IsSpaceOrNewLine( *m_DataIt ) ) {
|
while (m_DataIt != m_DataItEnd && IsSpaceOrNewLine(*m_DataIt)) {
|
||||||
++m_DataIt;
|
++m_DataIt;
|
||||||
}
|
}
|
||||||
std::map<std::string, ObjFile::Material*>::iterator it = m_pModel->m_MaterialMap.find( strMat );
|
std::map<std::string, ObjFile::Material *>::iterator it = m_pModel->m_MaterialMap.find(strMat);
|
||||||
if ( it == m_pModel->m_MaterialMap.end() ) {
|
if (it == m_pModel->m_MaterialMap.end()) {
|
||||||
// Show a warning, if material was not found
|
// Show a warning, if material was not found
|
||||||
ASSIMP_LOG_WARN("OBJ: Unsupported material requested: " + strMat);
|
ASSIMP_LOG_WARN("OBJ: Unsupported material requested: " + strMat);
|
||||||
m_pModel->m_pCurrentMaterial = m_pModel->m_pDefaultMaterial;
|
m_pModel->m_pCurrentMaterial = m_pModel->m_pDefaultMaterial;
|
||||||
} else {
|
} else {
|
||||||
// Set new material
|
// Set new material
|
||||||
if ( needsNewMesh( strMat ) ) {
|
if (needsNewMesh(strMat)) {
|
||||||
createMesh( strMat );
|
createMesh(strMat);
|
||||||
}
|
}
|
||||||
m_pModel->m_pCurrentMesh->m_uiMaterialIndex = getMaterialIndex( strMat );
|
m_pModel->m_pCurrentMesh->m_uiMaterialIndex = getMaterialIndex(strMat);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
int ObjFileParser::getMaterialIndex( const std::string &strMaterialName )
|
int ObjFileParser::getMaterialIndex(const std::string &strMaterialName) {
|
||||||
{
|
|
||||||
int mat_index = -1;
|
int mat_index = -1;
|
||||||
if( strMaterialName.empty() ) {
|
if (strMaterialName.empty()) {
|
||||||
return mat_index;
|
return mat_index;
|
||||||
}
|
}
|
||||||
for (size_t index = 0; index < m_pModel->m_MaterialLib.size(); ++index)
|
for (size_t index = 0; index < m_pModel->m_MaterialLib.size(); ++index) {
|
||||||
{
|
if (strMaterialName == m_pModel->m_MaterialLib[index]) {
|
||||||
if ( strMaterialName == m_pModel->m_MaterialLib[ index ])
|
|
||||||
{
|
|
||||||
mat_index = (int)index;
|
mat_index = (int)index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -713,146 +687,127 @@ void ObjFileParser::getGroupName() {
|
||||||
// here we skip 'g ' from line
|
// here we skip 'g ' from line
|
||||||
m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
||||||
m_DataIt = getName<DataArrayIt>(m_DataIt, m_DataItEnd, groupName);
|
m_DataIt = getName<DataArrayIt>(m_DataIt, m_DataItEnd, groupName);
|
||||||
if( isEndOfBuffer( m_DataIt, m_DataItEnd ) ) {
|
if (isEndOfBuffer(m_DataIt, m_DataItEnd)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change active group, if necessary
|
// Change active group, if necessary
|
||||||
if ( m_pModel->m_strActiveGroup != groupName ) {
|
if (m_pModel->m_strActiveGroup != groupName) {
|
||||||
// Search for already existing entry
|
// Search for already existing entry
|
||||||
ObjFile::Model::ConstGroupMapIt it = m_pModel->m_Groups.find(groupName);
|
ObjFile::Model::ConstGroupMapIt it = m_pModel->m_Groups.find(groupName);
|
||||||
|
|
||||||
// We are mapping groups into the object structure
|
// We are mapping groups into the object structure
|
||||||
createObject( groupName );
|
createObject(groupName);
|
||||||
|
|
||||||
// New group name, creating a new entry
|
// New group name, creating a new entry
|
||||||
if (it == m_pModel->m_Groups.end())
|
if (it == m_pModel->m_Groups.end()) {
|
||||||
{
|
|
||||||
std::vector<unsigned int> *pFaceIDArray = new std::vector<unsigned int>;
|
std::vector<unsigned int> *pFaceIDArray = new std::vector<unsigned int>;
|
||||||
m_pModel->m_Groups[ groupName ] = pFaceIDArray;
|
m_pModel->m_Groups[groupName] = pFaceIDArray;
|
||||||
m_pModel->m_pGroupFaceIDs = (pFaceIDArray);
|
m_pModel->m_pGroupFaceIDs = (pFaceIDArray);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
m_pModel->m_pGroupFaceIDs = (*it).second;
|
m_pModel->m_pGroupFaceIDs = (*it).second;
|
||||||
}
|
}
|
||||||
m_pModel->m_strActiveGroup = groupName;
|
m_pModel->m_strActiveGroup = groupName;
|
||||||
}
|
}
|
||||||
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
// Not supported
|
// Not supported
|
||||||
void ObjFileParser::getGroupNumber()
|
void ObjFileParser::getGroupNumber() {
|
||||||
{
|
|
||||||
// Not used
|
// Not used
|
||||||
|
|
||||||
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
// Not supported
|
// Not supported
|
||||||
void ObjFileParser::getGroupNumberAndResolution()
|
void ObjFileParser::getGroupNumberAndResolution() {
|
||||||
{
|
|
||||||
// Not used
|
// Not used
|
||||||
|
|
||||||
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
// Stores values for a new object instance, name will be used to
|
// Stores values for a new object instance, name will be used to
|
||||||
// identify it.
|
// identify it.
|
||||||
void ObjFileParser::getObjectName()
|
void ObjFileParser::getObjectName() {
|
||||||
{
|
|
||||||
m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
||||||
if( m_DataIt == m_DataItEnd ) {
|
if (m_DataIt == m_DataItEnd) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
char *pStart = &(*m_DataIt);
|
char *pStart = &(*m_DataIt);
|
||||||
while( m_DataIt != m_DataItEnd && !IsSpaceOrNewLine( *m_DataIt ) ) {
|
while (m_DataIt != m_DataItEnd && !IsSpaceOrNewLine(*m_DataIt)) {
|
||||||
++m_DataIt;
|
++m_DataIt;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string strObjectName(pStart, &(*m_DataIt));
|
std::string strObjectName(pStart, &(*m_DataIt));
|
||||||
if (!strObjectName.empty())
|
if (!strObjectName.empty()) {
|
||||||
{
|
|
||||||
// Reset current object
|
// Reset current object
|
||||||
m_pModel->m_pCurrent = NULL;
|
m_pModel->m_pCurrent = NULL;
|
||||||
|
|
||||||
// Search for actual object
|
// Search for actual object
|
||||||
for (std::vector<ObjFile::Object*>::const_iterator it = m_pModel->m_Objects.begin();
|
for (std::vector<ObjFile::Object *>::const_iterator it = m_pModel->m_Objects.begin();
|
||||||
it != m_pModel->m_Objects.end();
|
it != m_pModel->m_Objects.end();
|
||||||
++it)
|
++it) {
|
||||||
{
|
if ((*it)->m_strObjName == strObjectName) {
|
||||||
if ((*it)->m_strObjName == strObjectName)
|
|
||||||
{
|
|
||||||
m_pModel->m_pCurrent = *it;
|
m_pModel->m_pCurrent = *it;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allocate a new object, if current one was not found before
|
// Allocate a new object, if current one was not found before
|
||||||
if( NULL == m_pModel->m_pCurrent ) {
|
if (NULL == m_pModel->m_pCurrent) {
|
||||||
createObject( strObjectName );
|
createObject(strObjectName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||||
}
|
}
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
// Creates a new object instance
|
// Creates a new object instance
|
||||||
void ObjFileParser::createObject(const std::string &objName)
|
void ObjFileParser::createObject(const std::string &objName) {
|
||||||
{
|
ai_assert(NULL != m_pModel);
|
||||||
ai_assert( NULL != m_pModel );
|
|
||||||
|
|
||||||
m_pModel->m_pCurrent = new ObjFile::Object;
|
m_pModel->m_pCurrent = new ObjFile::Object;
|
||||||
m_pModel->m_pCurrent->m_strObjName = objName;
|
m_pModel->m_pCurrent->m_strObjName = objName;
|
||||||
m_pModel->m_Objects.push_back( m_pModel->m_pCurrent );
|
m_pModel->m_Objects.push_back(m_pModel->m_pCurrent);
|
||||||
|
|
||||||
createMesh( objName );
|
createMesh(objName);
|
||||||
|
|
||||||
if( m_pModel->m_pCurrentMaterial )
|
if (m_pModel->m_pCurrentMaterial) {
|
||||||
{
|
|
||||||
m_pModel->m_pCurrentMesh->m_uiMaterialIndex =
|
m_pModel->m_pCurrentMesh->m_uiMaterialIndex =
|
||||||
getMaterialIndex( m_pModel->m_pCurrentMaterial->MaterialName.data );
|
getMaterialIndex(m_pModel->m_pCurrentMaterial->MaterialName.data);
|
||||||
m_pModel->m_pCurrentMesh->m_pMaterial = m_pModel->m_pCurrentMaterial;
|
m_pModel->m_pCurrentMesh->m_pMaterial = m_pModel->m_pCurrentMaterial;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
// Creates a new mesh
|
// Creates a new mesh
|
||||||
void ObjFileParser::createMesh( const std::string &meshName )
|
void ObjFileParser::createMesh(const std::string &meshName) {
|
||||||
{
|
ai_assert(NULL != m_pModel);
|
||||||
ai_assert( NULL != m_pModel );
|
m_pModel->m_pCurrentMesh = new ObjFile::Mesh(meshName);
|
||||||
m_pModel->m_pCurrentMesh = new ObjFile::Mesh( meshName );
|
m_pModel->m_Meshes.push_back(m_pModel->m_pCurrentMesh);
|
||||||
m_pModel->m_Meshes.push_back( m_pModel->m_pCurrentMesh );
|
unsigned int meshId = static_cast<unsigned int>(m_pModel->m_Meshes.size() - 1);
|
||||||
unsigned int meshId = static_cast<unsigned int>(m_pModel->m_Meshes.size()-1);
|
if (NULL != m_pModel->m_pCurrent) {
|
||||||
if ( NULL != m_pModel->m_pCurrent )
|
m_pModel->m_pCurrent->m_Meshes.push_back(meshId);
|
||||||
{
|
} else {
|
||||||
m_pModel->m_pCurrent->m_Meshes.push_back( meshId );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ASSIMP_LOG_ERROR("OBJ: No object detected to attach a new mesh instance.");
|
ASSIMP_LOG_ERROR("OBJ: No object detected to attach a new mesh instance.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
// Returns true, if a new mesh must be created.
|
// Returns true, if a new mesh must be created.
|
||||||
bool ObjFileParser::needsNewMesh( const std::string &materialName )
|
bool ObjFileParser::needsNewMesh(const std::string &materialName) {
|
||||||
{
|
|
||||||
// If no mesh data yet
|
// If no mesh data yet
|
||||||
if (m_pModel->m_pCurrentMesh == nullptr)
|
if (m_pModel->m_pCurrentMesh == nullptr) {
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool newMat = false;
|
bool newMat = false;
|
||||||
int matIdx = getMaterialIndex( materialName );
|
int matIdx = getMaterialIndex(materialName);
|
||||||
int curMatIdx = m_pModel->m_pCurrentMesh->m_uiMaterialIndex;
|
int curMatIdx = m_pModel->m_pCurrentMesh->m_uiMaterialIndex;
|
||||||
if ( curMatIdx != int(ObjFile::Mesh::NoMaterial)
|
if (curMatIdx != int(ObjFile::Mesh::NoMaterial) && curMatIdx != matIdx
|
||||||
&& curMatIdx != matIdx
|
|
||||||
// no need create a new mesh if no faces in current
|
// no need create a new mesh if no faces in current
|
||||||
// lets say 'usemtl' goes straight after 'g'
|
// lets say 'usemtl' goes straight after 'g'
|
||||||
&& !m_pModel->m_pCurrentMesh->m_Faces.empty() )
|
&& !m_pModel->m_pCurrentMesh->m_Faces.empty()) {
|
||||||
{
|
|
||||||
// New material -> only one material per mesh, so we need to create a new
|
// New material -> only one material per mesh, so we need to create a new
|
||||||
// material
|
// material
|
||||||
newMat = true;
|
newMat = true;
|
||||||
|
@ -862,9 +817,8 @@ bool ObjFileParser::needsNewMesh( const std::string &materialName )
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
// Shows an error in parsing process.
|
// Shows an error in parsing process.
|
||||||
void ObjFileParser::reportErrorTokenInFace()
|
void ObjFileParser::reportErrorTokenInFace() {
|
||||||
{
|
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||||
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
|
||||||
ASSIMP_LOG_ERROR("OBJ: Not supported token in face description detected");
|
ASSIMP_LOG_ERROR("OBJ: Not supported token in face description detected");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
|
||||||
|
|
||||||
Copyright (c) 2006-2020, assimp team
|
Copyright (c) 2006-2020, assimp team
|
||||||
|
|
||||||
|
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use of this software in source and binary forms,
|
Redistribution and use of this software in source and binary forms,
|
||||||
|
@ -42,24 +41,24 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#ifndef OBJ_FILEPARSER_H_INC
|
#ifndef OBJ_FILEPARSER_H_INC
|
||||||
#define OBJ_FILEPARSER_H_INC
|
#define OBJ_FILEPARSER_H_INC
|
||||||
|
|
||||||
#include <vector>
|
#include <assimp/IOStreamBuffer.h>
|
||||||
#include <string>
|
#include <assimp/mesh.h>
|
||||||
#include <map>
|
|
||||||
#include <memory>
|
|
||||||
#include <assimp/vector2.h>
|
#include <assimp/vector2.h>
|
||||||
#include <assimp/vector3.h>
|
#include <assimp/vector3.h>
|
||||||
#include <assimp/mesh.h>
|
#include <map>
|
||||||
#include <assimp/IOStreamBuffer.h>
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
|
|
||||||
namespace ObjFile {
|
namespace ObjFile {
|
||||||
struct Model;
|
struct Model;
|
||||||
struct Object;
|
struct Object;
|
||||||
struct Material;
|
struct Material;
|
||||||
struct Point3;
|
struct Point3;
|
||||||
struct Point2;
|
struct Point2;
|
||||||
}
|
} // namespace ObjFile
|
||||||
|
|
||||||
class ObjFileImporter;
|
class ObjFileImporter;
|
||||||
class IOSystem;
|
class IOSystem;
|
||||||
|
@ -78,31 +77,31 @@ public:
|
||||||
/// @brief The default constructor.
|
/// @brief The default constructor.
|
||||||
ObjFileParser();
|
ObjFileParser();
|
||||||
/// @brief Constructor with data array.
|
/// @brief Constructor with data array.
|
||||||
ObjFileParser( IOStreamBuffer<char> &streamBuffer, const std::string &modelName, IOSystem* io, ProgressHandler* progress, const std::string &originalObjFileName);
|
ObjFileParser(IOStreamBuffer<char> &streamBuffer, const std::string &modelName, IOSystem *io, ProgressHandler *progress, const std::string &originalObjFileName);
|
||||||
/// @brief Destructor
|
/// @brief Destructor
|
||||||
~ObjFileParser();
|
~ObjFileParser();
|
||||||
/// @brief If you want to load in-core data.
|
/// @brief If you want to load in-core data.
|
||||||
void setBuffer( std::vector<char> &buffer );
|
void setBuffer(std::vector<char> &buffer);
|
||||||
/// @brief Model getter.
|
/// @brief Model getter.
|
||||||
ObjFile::Model *GetModel() const;
|
ObjFile::Model *GetModel() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// Parse the loaded file
|
/// Parse the loaded file
|
||||||
void parseFile( IOStreamBuffer<char> &streamBuffer );
|
void parseFile(IOStreamBuffer<char> &streamBuffer);
|
||||||
/// Method to copy the new delimited word in the current line.
|
/// Method to copy the new delimited word in the current line.
|
||||||
void copyNextWord(char *pBuffer, size_t length);
|
void copyNextWord(char *pBuffer, size_t length);
|
||||||
/// Method to copy the new line.
|
/// Method to copy the new line.
|
||||||
// void copyNextLine(char *pBuffer, size_t length);
|
// void copyNextLine(char *pBuffer, size_t length);
|
||||||
/// Get the number of components in a line.
|
/// Get the number of components in a line.
|
||||||
size_t getNumComponentsInDataDefinition();
|
size_t getNumComponentsInDataDefinition();
|
||||||
/// Stores the vector
|
/// Stores the vector
|
||||||
size_t getTexCoordVector( std::vector<aiVector3D> &point3d_array );
|
size_t getTexCoordVector(std::vector<aiVector3D> &point3d_array);
|
||||||
/// Stores the following 3d vector.
|
/// Stores the following 3d vector.
|
||||||
void getVector3( std::vector<aiVector3D> &point3d_array );
|
void getVector3(std::vector<aiVector3D> &point3d_array);
|
||||||
/// Stores the following homogeneous vector as a 3D vector
|
/// Stores the following homogeneous vector as a 3D vector
|
||||||
void getHomogeneousVector3( std::vector<aiVector3D> &point3d_array );
|
void getHomogeneousVector3(std::vector<aiVector3D> &point3d_array);
|
||||||
/// Stores the following two 3d vectors on the line.
|
/// Stores the following two 3d vectors on the line.
|
||||||
void getTwoVectors3( std::vector<aiVector3D> &point3d_array_a, std::vector<aiVector3D> &point3d_array_b );
|
void getTwoVectors3(std::vector<aiVector3D> &point3d_array_a, std::vector<aiVector3D> &point3d_array_b);
|
||||||
/// Stores the following 3d vector.
|
/// Stores the following 3d vector.
|
||||||
void getVector2(std::vector<aiVector2D> &point2d_array);
|
void getVector2(std::vector<aiVector2D> &point2d_array);
|
||||||
/// Stores the following face.
|
/// Stores the following face.
|
||||||
|
@ -122,23 +121,23 @@ protected:
|
||||||
/// Gets the group number and resolution from file.
|
/// Gets the group number and resolution from file.
|
||||||
void getGroupNumberAndResolution();
|
void getGroupNumberAndResolution();
|
||||||
/// Returns the index of the material. Is -1 if not material was found.
|
/// Returns the index of the material. Is -1 if not material was found.
|
||||||
int getMaterialIndex( const std::string &strMaterialName );
|
int getMaterialIndex(const std::string &strMaterialName);
|
||||||
/// Parse object name
|
/// Parse object name
|
||||||
void getObjectName();
|
void getObjectName();
|
||||||
/// Creates a new object.
|
/// Creates a new object.
|
||||||
void createObject( const std::string &strObjectName );
|
void createObject(const std::string &strObjectName);
|
||||||
/// Creates a new mesh.
|
/// Creates a new mesh.
|
||||||
void createMesh( const std::string &meshName );
|
void createMesh(const std::string &meshName);
|
||||||
/// Returns true, if a new mesh instance must be created.
|
/// Returns true, if a new mesh instance must be created.
|
||||||
bool needsNewMesh( const std::string &rMaterialName );
|
bool needsNewMesh(const std::string &rMaterialName);
|
||||||
/// Error report in token
|
/// Error report in token
|
||||||
void reportErrorTokenInFace();
|
void reportErrorTokenInFace();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Copy and assignment constructor should be private
|
// Copy and assignment constructor should be private
|
||||||
// because the class contains pointer to allocated memory
|
// because the class contains pointer to allocated memory
|
||||||
ObjFileParser(const ObjFileParser& rhs);
|
ObjFileParser(const ObjFileParser &rhs);
|
||||||
ObjFileParser& operator=(const ObjFileParser& rhs);
|
ObjFileParser &operator=(const ObjFileParser &rhs);
|
||||||
|
|
||||||
/// Default material name
|
/// Default material name
|
||||||
static const std::string DEFAULT_MATERIAL;
|
static const std::string DEFAULT_MATERIAL;
|
||||||
|
@ -155,7 +154,7 @@ private:
|
||||||
/// Pointer to IO system instance.
|
/// Pointer to IO system instance.
|
||||||
IOSystem *m_pIO;
|
IOSystem *m_pIO;
|
||||||
//! Pointer to progress handler
|
//! Pointer to progress handler
|
||||||
ProgressHandler* m_progress;
|
ProgressHandler *m_progress;
|
||||||
/// Path to the current model, name of the obj file where the buffer comes from
|
/// Path to the current model, name of the obj file where the buffer comes from
|
||||||
const std::string m_originalObjFileName;
|
const std::string m_originalObjFileName;
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
|
||||||
|
|
||||||
Copyright (c) 2006-2020, assimp team
|
Copyright (c) 2006-2020, assimp team
|
||||||
|
|
||||||
|
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use of this software in source and binary forms,
|
Redistribution and use of this software in source and binary forms,
|
||||||
|
@ -46,8 +45,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#ifndef OBJ_TOOLS_H_INC
|
#ifndef OBJ_TOOLS_H_INC
|
||||||
#define OBJ_TOOLS_H_INC
|
#define OBJ_TOOLS_H_INC
|
||||||
|
|
||||||
#include <assimp/fast_atof.h>
|
|
||||||
#include <assimp/ParsingUtils.h>
|
#include <assimp/ParsingUtils.h>
|
||||||
|
#include <assimp/fast_atof.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
|
@ -57,17 +56,14 @@ namespace Assimp {
|
||||||
* @param end Iterator with end of buffer.
|
* @param end Iterator with end of buffer.
|
||||||
* @return true, if the end of the buffer is reached.
|
* @return true, if the end of the buffer is reached.
|
||||||
*/
|
*/
|
||||||
template<class char_t>
|
template <class char_t>
|
||||||
inline bool isEndOfBuffer( char_t it, char_t end ) {
|
inline bool isEndOfBuffer(char_t it, char_t end) {
|
||||||
if ( it == end )
|
if (it == end) {
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
--end;
|
--end;
|
||||||
}
|
}
|
||||||
return ( it == end );
|
return (it == end);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @brief Returns next word separated by a space
|
/** @brief Returns next word separated by a space
|
||||||
|
@ -75,12 +71,10 @@ inline bool isEndOfBuffer( char_t it, char_t end ) {
|
||||||
* @param pEnd Pointer to end of buffer
|
* @param pEnd Pointer to end of buffer
|
||||||
* @return Pointer to next space
|
* @return Pointer to next space
|
||||||
*/
|
*/
|
||||||
template<class Char_T>
|
template <class Char_T>
|
||||||
inline Char_T getNextWord( Char_T pBuffer, Char_T pEnd )
|
inline Char_T getNextWord(Char_T pBuffer, Char_T pEnd) {
|
||||||
{
|
while (!isEndOfBuffer(pBuffer, pEnd)) {
|
||||||
while ( !isEndOfBuffer( pBuffer, pEnd ) )
|
if (!IsSpaceOrNewLine(*pBuffer) || IsLineEnd(*pBuffer)) {
|
||||||
{
|
|
||||||
if ( !IsSpaceOrNewLine( *pBuffer ) || IsLineEnd( *pBuffer ) ) {
|
|
||||||
//if ( *pBuffer != '\\' )
|
//if ( *pBuffer != '\\' )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -94,16 +88,14 @@ inline Char_T getNextWord( Char_T pBuffer, Char_T pEnd )
|
||||||
* @param pEnd Pointer to end of buffer
|
* @param pEnd Pointer to end of buffer
|
||||||
* @return Pointer to next token
|
* @return Pointer to next token
|
||||||
*/
|
*/
|
||||||
template<class Char_T>
|
template <class Char_T>
|
||||||
inline Char_T getNextToken( Char_T pBuffer, Char_T pEnd )
|
inline Char_T getNextToken(Char_T pBuffer, Char_T pEnd) {
|
||||||
{
|
while (!isEndOfBuffer(pBuffer, pEnd)) {
|
||||||
while ( !isEndOfBuffer( pBuffer, pEnd ) )
|
if (IsSpaceOrNewLine(*pBuffer))
|
||||||
{
|
|
||||||
if( IsSpaceOrNewLine( *pBuffer ) )
|
|
||||||
break;
|
break;
|
||||||
pBuffer++;
|
pBuffer++;
|
||||||
}
|
}
|
||||||
return getNextWord( pBuffer, pEnd );
|
return getNextWord(pBuffer, pEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @brief Skips a line
|
/** @brief Skips a line
|
||||||
|
@ -112,18 +104,18 @@ inline Char_T getNextToken( Char_T pBuffer, Char_T pEnd )
|
||||||
* @param uiLine Current line number in format
|
* @param uiLine Current line number in format
|
||||||
* @return Current-iterator with new position
|
* @return Current-iterator with new position
|
||||||
*/
|
*/
|
||||||
template<class char_t>
|
template <class char_t>
|
||||||
inline char_t skipLine( char_t it, char_t end, unsigned int &uiLine ) {
|
inline char_t skipLine(char_t it, char_t end, unsigned int &uiLine) {
|
||||||
while( !isEndOfBuffer( it, end ) && !IsLineEnd( *it ) ) {
|
while (!isEndOfBuffer(it, end) && !IsLineEnd(*it)) {
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( it != end ) {
|
if (it != end) {
|
||||||
++it;
|
++it;
|
||||||
++uiLine;
|
++uiLine;
|
||||||
}
|
}
|
||||||
// fix .. from time to time there are spaces at the beginning of a material line
|
// fix .. from time to time there are spaces at the beginning of a material line
|
||||||
while ( it != end && ( *it == '\t' || *it == ' ' ) ) {
|
while (it != end && (*it == '\t' || *it == ' ')) {
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,20 +129,19 @@ inline char_t skipLine( char_t it, char_t end, unsigned int &uiLine ) {
|
||||||
* @param name Separated name
|
* @param name Separated name
|
||||||
* @return Current-iterator with new position
|
* @return Current-iterator with new position
|
||||||
*/
|
*/
|
||||||
template<class char_t>
|
template <class char_t>
|
||||||
inline char_t getName( char_t it, char_t end, std::string &name )
|
inline char_t getName(char_t it, char_t end, std::string &name) {
|
||||||
{
|
|
||||||
name = "";
|
name = "";
|
||||||
if( isEndOfBuffer( it, end ) ) {
|
if (isEndOfBuffer(it, end)) {
|
||||||
return end;
|
return end;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *pStart = &( *it );
|
char *pStart = &(*it);
|
||||||
while( !isEndOfBuffer( it, end ) && !IsLineEnd( *it )) {
|
while (!isEndOfBuffer(it, end) && !IsLineEnd(*it)) {
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
while(IsSpace( *it ) ) {
|
while (IsSpace(*it)) {
|
||||||
--it;
|
--it;
|
||||||
}
|
}
|
||||||
// Get name
|
// Get name
|
||||||
|
@ -158,8 +149,8 @@ inline char_t getName( char_t it, char_t end, std::string &name )
|
||||||
while (&(*it) < pStart) {
|
while (&(*it) < pStart) {
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
std::string strName( pStart, &(*it) );
|
std::string strName(pStart, &(*it));
|
||||||
if ( strName.empty() )
|
if (strName.empty())
|
||||||
return it;
|
return it;
|
||||||
else
|
else
|
||||||
name = strName;
|
name = strName;
|
||||||
|
@ -174,22 +165,19 @@ inline char_t getName( char_t it, char_t end, std::string &name )
|
||||||
* @param name Separated name
|
* @param name Separated name
|
||||||
* @return Current-iterator with new position
|
* @return Current-iterator with new position
|
||||||
*/
|
*/
|
||||||
template<class char_t>
|
template <class char_t>
|
||||||
inline char_t getNameNoSpace( char_t it, char_t end, std::string &name )
|
inline char_t getNameNoSpace(char_t it, char_t end, std::string &name) {
|
||||||
{
|
|
||||||
name = "";
|
name = "";
|
||||||
if( isEndOfBuffer( it, end ) ) {
|
if (isEndOfBuffer(it, end)) {
|
||||||
return end;
|
return end;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *pStart = &( *it );
|
char *pStart = &(*it);
|
||||||
while( !isEndOfBuffer( it, end ) && !IsLineEnd( *it )
|
while (!isEndOfBuffer(it, end) && !IsLineEnd(*it) && !IsSpaceOrNewLine(*it)) {
|
||||||
&& !IsSpaceOrNewLine( *it ) ) {
|
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
while( isEndOfBuffer( it, end ) || IsLineEnd( *it )
|
while (isEndOfBuffer(it, end) || IsLineEnd(*it) || IsSpaceOrNewLine(*it)) {
|
||||||
|| IsSpaceOrNewLine( *it ) ) {
|
|
||||||
--it;
|
--it;
|
||||||
}
|
}
|
||||||
++it;
|
++it;
|
||||||
|
@ -199,8 +187,8 @@ inline char_t getNameNoSpace( char_t it, char_t end, std::string &name )
|
||||||
while (&(*it) < pStart) {
|
while (&(*it) < pStart) {
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
std::string strName( pStart, &(*it) );
|
std::string strName(pStart, &(*it));
|
||||||
if ( strName.empty() )
|
if (strName.empty())
|
||||||
return it;
|
return it;
|
||||||
else
|
else
|
||||||
name = strName;
|
name = strName;
|
||||||
|
@ -215,20 +203,18 @@ inline char_t getNameNoSpace( char_t it, char_t end, std::string &name )
|
||||||
* @param length Buffer length
|
* @param length Buffer length
|
||||||
* @return Current-iterator with new position
|
* @return Current-iterator with new position
|
||||||
*/
|
*/
|
||||||
template<class char_t>
|
template <class char_t>
|
||||||
inline char_t CopyNextWord( char_t it, char_t end, char *pBuffer, size_t length )
|
inline char_t CopyNextWord(char_t it, char_t end, char *pBuffer, size_t length) {
|
||||||
{
|
|
||||||
size_t index = 0;
|
size_t index = 0;
|
||||||
it = getNextWord<char_t>( it, end );
|
it = getNextWord<char_t>(it, end);
|
||||||
while( !IsSpaceOrNewLine( *it ) && !isEndOfBuffer( it, end ) )
|
while (!IsSpaceOrNewLine(*it) && !isEndOfBuffer(it, end)) {
|
||||||
{
|
pBuffer[index] = *it;
|
||||||
pBuffer[index] = *it ;
|
|
||||||
index++;
|
index++;
|
||||||
if (index == length-1)
|
if (index == length - 1)
|
||||||
break;
|
break;
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
pBuffer[ index ] = '\0';
|
pBuffer[index] = '\0';
|
||||||
return it;
|
return it;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,13 +224,12 @@ inline char_t CopyNextWord( char_t it, char_t end, char *pBuffer, size_t length
|
||||||
* @param value Separated float value.
|
* @param value Separated float value.
|
||||||
* @return Current-iterator with new position
|
* @return Current-iterator with new position
|
||||||
*/
|
*/
|
||||||
template<class char_t>
|
template <class char_t>
|
||||||
inline char_t getFloat( char_t it, char_t end, ai_real &value )
|
inline char_t getFloat(char_t it, char_t end, ai_real &value) {
|
||||||
{
|
|
||||||
static const size_t BUFFERSIZE = 1024;
|
static const size_t BUFFERSIZE = 1024;
|
||||||
char buffer[ BUFFERSIZE ];
|
char buffer[BUFFERSIZE];
|
||||||
it = CopyNextWord<char_t>( it, end, buffer, BUFFERSIZE );
|
it = CopyNextWord<char_t>(it, end, buffer, BUFFERSIZE);
|
||||||
value = (ai_real) fast_atof( buffer );
|
value = (ai_real)fast_atof(buffer);
|
||||||
|
|
||||||
return it;
|
return it;
|
||||||
}
|
}
|
||||||
|
@ -255,46 +240,45 @@ inline char_t getFloat( char_t it, char_t end, ai_real &value )
|
||||||
* @param delimiters Delimiter for tokenize.
|
* @param delimiters Delimiter for tokenize.
|
||||||
* @return Number of found token.
|
* @return Number of found token.
|
||||||
*/
|
*/
|
||||||
template<class string_type>
|
template <class string_type>
|
||||||
unsigned int tokenize( const string_type& str, std::vector<string_type>& tokens,
|
unsigned int tokenize(const string_type &str, std::vector<string_type> &tokens,
|
||||||
const string_type& delimiters )
|
const string_type &delimiters) {
|
||||||
{
|
|
||||||
// Skip delimiters at beginning.
|
// Skip delimiters at beginning.
|
||||||
typename string_type::size_type lastPos = str.find_first_not_of( delimiters, 0 );
|
typename string_type::size_type lastPos = str.find_first_not_of(delimiters, 0);
|
||||||
|
|
||||||
// Find first "non-delimiter".
|
// Find first "non-delimiter".
|
||||||
typename string_type::size_type pos = str.find_first_of( delimiters, lastPos );
|
typename string_type::size_type pos = str.find_first_of(delimiters, lastPos);
|
||||||
while ( string_type::npos != pos || string_type::npos != lastPos )
|
while (string_type::npos != pos || string_type::npos != lastPos) {
|
||||||
{
|
|
||||||
// Found a token, add it to the vector.
|
// Found a token, add it to the vector.
|
||||||
string_type tmp = str.substr(lastPos, pos - lastPos);
|
string_type tmp = str.substr(lastPos, pos - lastPos);
|
||||||
if ( !tmp.empty() && ' ' != tmp[ 0 ] )
|
if (!tmp.empty() && ' ' != tmp[0])
|
||||||
tokens.push_back( tmp );
|
tokens.push_back(tmp);
|
||||||
|
|
||||||
// Skip delimiters. Note the "not_of"
|
// Skip delimiters. Note the "not_of"
|
||||||
lastPos = str.find_first_not_of( delimiters, pos );
|
lastPos = str.find_first_not_of(delimiters, pos);
|
||||||
|
|
||||||
// Find next "non-delimiter"
|
// Find next "non-delimiter"
|
||||||
pos = str.find_first_of( delimiters, lastPos );
|
pos = str.find_first_of(delimiters, lastPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
return static_cast<unsigned int>( tokens.size() );
|
return static_cast<unsigned int>(tokens.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class string_type>
|
template <class string_type>
|
||||||
string_type trim_whitespaces(string_type str)
|
string_type trim_whitespaces(string_type str) {
|
||||||
{
|
while (!str.empty() && IsSpace(str[0]))
|
||||||
while (!str.empty() && IsSpace(str[0])) str.erase(0);
|
str.erase(0);
|
||||||
while (!str.empty() && IsSpace(str[str.length() - 1])) str.erase(str.length() - 1);
|
while (!str.empty() && IsSpace(str[str.length() - 1]))
|
||||||
|
str.erase(str.length() - 1);
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template <class T>
|
||||||
bool hasLineEnd( T it, T end ) {
|
bool hasLineEnd(T it, T end) {
|
||||||
bool hasLineEnd( false );
|
bool hasLineEnd(false);
|
||||||
while ( !isEndOfBuffer( it, end ) ) {
|
while (!isEndOfBuffer(it, end)) {
|
||||||
it++;
|
it++;
|
||||||
if ( IsLineEnd( it ) ) {
|
if (IsLineEnd(it)) {
|
||||||
hasLineEnd = true;
|
hasLineEnd = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue