Obj: apply clang format.
parent
0357333c81
commit
8b6f95ec30
|
@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
|
|||
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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
|
||||
#define OBJ_FILEDATA_H_INC
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <assimp/types.h>
|
||||
#include <assimp/mesh.h>
|
||||
#include <assimp/types.h>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
namespace Assimp {
|
||||
namespace ObjFile {
|
||||
|
@ -75,12 +74,8 @@ struct Face {
|
|||
Material *m_pMaterial;
|
||||
|
||||
//! \brief Default constructor
|
||||
Face( aiPrimitiveType pt = aiPrimitiveType_POLYGON)
|
||||
: m_PrimitiveType( pt )
|
||||
, m_vertices()
|
||||
, m_normals()
|
||||
, m_texturCoords()
|
||||
, m_pMaterial( 0L ) {
|
||||
Face(aiPrimitiveType pt = aiPrimitiveType_POLYGON) :
|
||||
m_PrimitiveType(pt), m_vertices(), m_normals(), m_texturCoords(), m_pMaterial(0L) {
|
||||
// empty
|
||||
}
|
||||
|
||||
|
@ -105,19 +100,19 @@ struct Object {
|
|||
//! Transformation matrix, stored in OpenGL format
|
||||
aiMatrix4x4 m_Transformation;
|
||||
//! All sub-objects referenced by this object
|
||||
std::vector<Object*> m_SubObjects;
|
||||
std::vector<Object *> m_SubObjects;
|
||||
/// Assigned meshes
|
||||
std::vector<unsigned int> m_Meshes;
|
||||
|
||||
//! \brief Default constructor
|
||||
Object()
|
||||
: m_strObjName("") {
|
||||
Object() :
|
||||
m_strObjName("") {
|
||||
// empty
|
||||
}
|
||||
|
||||
//! \brief Destructor
|
||||
~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;
|
||||
}
|
||||
}
|
||||
|
@ -184,16 +179,11 @@ struct Material {
|
|||
aiColor3D transparent;
|
||||
|
||||
//! Constructor
|
||||
Material()
|
||||
: 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)) {
|
||||
Material() :
|
||||
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)) {
|
||||
// empty
|
||||
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
|
||||
std::string m_name;
|
||||
/// Array with pointer to all stored faces
|
||||
std::vector<Face*> m_Faces;
|
||||
std::vector<Face *> m_Faces;
|
||||
/// Assigned material
|
||||
Material *m_pMaterial;
|
||||
/// Number of stored indices.
|
||||
unsigned int m_uiNumIndices;
|
||||
/// Number of UV
|
||||
unsigned int m_uiUVCoordinates[ AI_MAX_NUMBER_OF_TEXTURECOORDS ];
|
||||
unsigned int m_uiUVCoordinates[AI_MAX_NUMBER_OF_TEXTURECOORDS];
|
||||
/// Material index.
|
||||
unsigned int m_uiMaterialIndex;
|
||||
/// True, if normals are stored.
|
||||
|
@ -227,20 +217,15 @@ struct Mesh {
|
|||
bool m_hasVertexColors;
|
||||
|
||||
/// Constructor
|
||||
explicit Mesh( const std::string &name )
|
||||
: m_name( name )
|
||||
, m_pMaterial(NULL)
|
||||
, m_uiNumIndices(0)
|
||||
, m_uiMaterialIndex( NoMaterial )
|
||||
, m_hasNormals(false) {
|
||||
memset(m_uiUVCoordinates, 0, sizeof( unsigned int ) * AI_MAX_NUMBER_OF_TEXTURECOORDS);
|
||||
explicit Mesh(const std::string &name) :
|
||||
m_name(name), m_pMaterial(NULL), m_uiNumIndices(0), m_uiMaterialIndex(NoMaterial), m_hasNormals(false) {
|
||||
memset(m_uiUVCoordinates, 0, sizeof(unsigned int) * AI_MAX_NUMBER_OF_TEXTURECOORDS);
|
||||
}
|
||||
|
||||
/// Destructor
|
||||
~Mesh() {
|
||||
for (std::vector<Face*>::iterator it = m_Faces.begin();
|
||||
it != m_Faces.end(); ++it)
|
||||
{
|
||||
for (std::vector<Face *>::iterator it = m_Faces.begin();
|
||||
it != m_Faces.end(); ++it) {
|
||||
delete *it;
|
||||
}
|
||||
}
|
||||
|
@ -251,14 +236,14 @@ struct Mesh {
|
|||
//! \brief Data structure to store all obj-specific model datas
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
struct Model {
|
||||
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>* >::const_iterator ConstGroupMapIt;
|
||||
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> *>::const_iterator ConstGroupMapIt;
|
||||
|
||||
//! Model name
|
||||
std::string m_ModelName;
|
||||
//! List ob assigned objects
|
||||
std::vector<Object*> m_Objects;
|
||||
std::vector<Object *> m_Objects;
|
||||
//! Pointer to current object
|
||||
ObjFile::Object *m_pCurrent;
|
||||
//! Pointer to current material
|
||||
|
@ -286,46 +271,45 @@ struct Model {
|
|||
//! Current mesh instance
|
||||
Mesh *m_pCurrentMesh;
|
||||
//! Vector with stored meshes
|
||||
std::vector<Mesh*> m_Meshes;
|
||||
std::vector<Mesh *> m_Meshes;
|
||||
//! Material map
|
||||
std::map<std::string, Material*> m_MaterialMap;
|
||||
std::map<std::string, Material *> m_MaterialMap;
|
||||
|
||||
//! \brief The default class constructor
|
||||
Model() :
|
||||
m_ModelName(""),
|
||||
m_pCurrent(NULL),
|
||||
m_pCurrentMaterial(NULL),
|
||||
m_pDefaultMaterial(NULL),
|
||||
m_pGroupFaceIDs(NULL),
|
||||
m_strActiveGroup(""),
|
||||
m_TextureCoordDim(0),
|
||||
m_pCurrentMesh(NULL)
|
||||
{
|
||||
m_ModelName(""),
|
||||
m_pCurrent(NULL),
|
||||
m_pCurrentMaterial(NULL),
|
||||
m_pDefaultMaterial(NULL),
|
||||
m_pGroupFaceIDs(NULL),
|
||||
m_strActiveGroup(""),
|
||||
m_TextureCoordDim(0),
|
||||
m_pCurrentMesh(NULL) {
|
||||
// empty
|
||||
}
|
||||
|
||||
//! \brief The class destructor
|
||||
~Model() {
|
||||
// Clear all stored object instances
|
||||
for (std::vector<Object*>::iterator it = m_Objects.begin();
|
||||
it != m_Objects.end(); ++it) {
|
||||
for (std::vector<Object *>::iterator it = m_Objects.begin();
|
||||
it != m_Objects.end(); ++it) {
|
||||
delete *it;
|
||||
}
|
||||
m_Objects.clear();
|
||||
|
||||
// Clear all stored mesh instances
|
||||
for (std::vector<Mesh*>::iterator it = m_Meshes.begin();
|
||||
it != m_Meshes.end(); ++it) {
|
||||
for (std::vector<Mesh *>::iterator it = m_Meshes.begin();
|
||||
it != m_Meshes.end(); ++it) {
|
||||
delete *it;
|
||||
}
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
|
|||
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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
|
||||
|
||||
#include "ObjFileImporter.h"
|
||||
#include "ObjFileParser.h"
|
||||
#include "ObjFileData.h"
|
||||
#include <assimp/IOStreamBuffer.h>
|
||||
#include <memory>
|
||||
#include "ObjFileParser.h"
|
||||
#include <assimp/DefaultIOSystem.h>
|
||||
#include <assimp/Importer.hpp>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/IOStreamBuffer.h>
|
||||
#include <assimp/ai_assert.h>
|
||||
#include <assimp/DefaultLogger.hpp>
|
||||
#include <assimp/importerdesc.h>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/DefaultLogger.hpp>
|
||||
#include <assimp/Importer.hpp>
|
||||
#include <memory>
|
||||
|
||||
static const aiImporterDesc desc = {
|
||||
"Wavefront Object Importer",
|
||||
|
@ -76,10 +74,8 @@ using namespace std;
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Default constructor
|
||||
ObjFileImporter::ObjFileImporter()
|
||||
: m_Buffer()
|
||||
, m_pRootObject( nullptr )
|
||||
, m_strAbsPath( std::string(1, DefaultIOSystem().getOsSeparator()) ) {}
|
||||
ObjFileImporter::ObjFileImporter() :
|
||||
m_Buffer(), m_pRootObject(nullptr), m_strAbsPath(std::string(1, DefaultIOSystem().getOsSeparator())) {}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Destructor.
|
||||
|
@ -90,59 +86,59 @@ ObjFileImporter::~ObjFileImporter() {
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Returns true, if file is an obj file.
|
||||
bool ObjFileImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler , bool checkSig ) const {
|
||||
if(!checkSig) {
|
||||
bool ObjFileImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool checkSig) const {
|
||||
if (!checkSig) {
|
||||
//Check File Extension
|
||||
return SimpleExtensionCheck(pFile,"obj");
|
||||
return SimpleExtensionCheck(pFile, "obj");
|
||||
} else {
|
||||
// Check file Header
|
||||
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;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// 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
|
||||
static const std::string mode = "rb";
|
||||
std::unique_ptr<IOStream> fileStream( pIOHandler->Open( file, mode));
|
||||
if( !fileStream.get() ) {
|
||||
throw DeadlyImportError( "Failed to open file " + file + "." );
|
||||
std::unique_ptr<IOStream> fileStream(pIOHandler->Open(file, mode));
|
||||
if (!fileStream.get()) {
|
||||
throw DeadlyImportError("Failed to open file " + file + ".");
|
||||
}
|
||||
|
||||
// Get the file-size and validate it, throwing an exception when fails
|
||||
size_t fileSize = fileStream->FileSize();
|
||||
if( fileSize < ObjMinSize ) {
|
||||
throw DeadlyImportError( "OBJ-file is too small.");
|
||||
if (fileSize < ObjMinSize) {
|
||||
throw DeadlyImportError("OBJ-file is too small.");
|
||||
}
|
||||
|
||||
IOStreamBuffer<char> streamedBuffer;
|
||||
streamedBuffer.open( fileStream.get() );
|
||||
streamedBuffer.open(fileStream.get());
|
||||
|
||||
// Allocate buffer and read file into it
|
||||
//TextFileToBuffer( fileStream.get(),m_Buffer);
|
||||
|
||||
// Get the model name
|
||||
std::string modelName, folderName;
|
||||
std::string::size_type pos = file.find_last_of( "\\/" );
|
||||
if ( pos != std::string::npos ) {
|
||||
modelName = file.substr(pos+1, file.size() - pos - 1);
|
||||
folderName = file.substr( 0, pos );
|
||||
if ( !folderName.empty() ) {
|
||||
pIOHandler->PushDirectory( folderName );
|
||||
std::string modelName, folderName;
|
||||
std::string::size_type pos = file.find_last_of("\\/");
|
||||
if (pos != std::string::npos) {
|
||||
modelName = file.substr(pos + 1, file.size() - pos - 1);
|
||||
folderName = file.substr(0, pos);
|
||||
if (!folderName.empty()) {
|
||||
pIOHandler->PushDirectory(folderName);
|
||||
}
|
||||
} else {
|
||||
modelName = file;
|
||||
}
|
||||
|
||||
// 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
|
||||
CreateDataFromImport(parser.GetModel(), pScene);
|
||||
|
@ -153,21 +149,21 @@ void ObjFileImporter::InternReadFile( const std::string &file, aiScene* pScene,
|
|||
m_Buffer.clear();
|
||||
|
||||
// Pop directory stack
|
||||
if ( pIOHandler->StackSize() > 0 ) {
|
||||
if (pIOHandler->StackSize() > 0) {
|
||||
pIOHandler->PopDirectory();
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Create the data from parsed obj-file
|
||||
void ObjFileImporter::CreateDataFromImport(const ObjFile::Model* pModel, aiScene* pScene) {
|
||||
if( 0L == pModel ) {
|
||||
void ObjFileImporter::CreateDataFromImport(const ObjFile::Model *pModel, aiScene *pScene) {
|
||||
if (0L == pModel) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Create the root node of the scene
|
||||
pScene->mRootNode = new aiNode;
|
||||
if ( !pModel->m_ModelName.empty() ) {
|
||||
if (!pModel->m_ModelName.empty()) {
|
||||
// Set the name of the scene
|
||||
pScene->mRootNode->mName.Set(pModel->m_ModelName);
|
||||
} else {
|
||||
|
@ -181,17 +177,17 @@ void ObjFileImporter::CreateDataFromImport(const ObjFile::Model* pModel, aiScene
|
|||
unsigned int childCount = 0;
|
||||
|
||||
for (auto object : pModel->m_Objects) {
|
||||
if(object) {
|
||||
if (object) {
|
||||
++childCount;
|
||||
meshCount += (unsigned int)object->m_Meshes.size();
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
std::vector<aiMesh*> MeshArray;
|
||||
std::vector<aiMesh *> MeshArray;
|
||||
MeshArray.reserve(meshCount);
|
||||
for (size_t index = 0; index < pModel->m_Objects.size(); ++index) {
|
||||
createNodes(pModel, pModel->m_Objects[index], pScene->mRootNode, pScene, MeshArray);
|
||||
|
@ -201,7 +197,7 @@ void ObjFileImporter::CreateDataFromImport(const ObjFile::Model* pModel, aiScene
|
|||
|
||||
// Create mesh pointer buffer for this scene
|
||||
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) {
|
||||
pScene->mMeshes[index] = MeshArray[index];
|
||||
}
|
||||
|
@ -209,34 +205,34 @@ void ObjFileImporter::CreateDataFromImport(const ObjFile::Model* pModel, aiScene
|
|||
|
||||
// Create all materials
|
||||
createMaterials(pModel, pScene);
|
||||
}else {
|
||||
if (pModel->m_Vertices.empty()){
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (pModel->m_Vertices.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr<aiMesh> mesh( new aiMesh );
|
||||
std::unique_ptr<aiMesh> mesh(new aiMesh);
|
||||
mesh->mPrimitiveTypes = aiPrimitiveType_POINT;
|
||||
unsigned int n = (unsigned int)pModel->m_Vertices.size();
|
||||
mesh->mNumVertices = 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];
|
||||
if (pModel->m_Normals.size() < n) {
|
||||
throw DeadlyImportError("OBJ: vertex normal index out of range");
|
||||
}
|
||||
memcpy(mesh->mNormals, pModel->m_Normals.data(), n*sizeof(aiVector3D));
|
||||
memcpy(mesh->mNormals, pModel->m_Normals.data(), n * sizeof(aiVector3D));
|
||||
}
|
||||
|
||||
if ( !pModel->m_VertexColors.empty() ){
|
||||
if (!pModel->m_VertexColors.empty()) {
|
||||
mesh->mColors[0] = new aiColor4D[mesh->mNumVertices];
|
||||
for (unsigned int i = 0; i < n; ++i) {
|
||||
if (i < pModel->m_VertexColors.size() ) {
|
||||
const aiVector3D& color = pModel->m_VertexColors[i];
|
||||
if (i < pModel->m_VertexColors.size()) {
|
||||
const aiVector3D &color = pModel->m_VertexColors[i];
|
||||
mesh->mColors[0][i] = aiColor4D(color.x, color.y, color.z, 1.0);
|
||||
}else {
|
||||
} else {
|
||||
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->mMeshes = new unsigned int[1];
|
||||
pScene->mRootNode->mMeshes[0] = 0;
|
||||
pScene->mMeshes = new aiMesh*[1];
|
||||
pScene->mMeshes = new aiMesh *[1];
|
||||
pScene->mNumMeshes = 1;
|
||||
pScene->mMeshes[0] = mesh.release();
|
||||
}
|
||||
|
@ -253,12 +249,11 @@ void ObjFileImporter::CreateDataFromImport(const ObjFile::Model* pModel, aiScene
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Creates all nodes of the model
|
||||
aiNode *ObjFileImporter::createNodes(const ObjFile::Model* pModel, const ObjFile::Object* pObject,
|
||||
aiNode *pParent, aiScene* pScene,
|
||||
std::vector<aiMesh*> &MeshArray )
|
||||
{
|
||||
ai_assert( NULL != pModel );
|
||||
if( NULL == pObject ) {
|
||||
aiNode *ObjFileImporter::createNodes(const ObjFile::Model *pModel, const ObjFile::Object *pObject,
|
||||
aiNode *pParent, aiScene *pScene,
|
||||
std::vector<aiMesh *> &MeshArray) {
|
||||
ai_assert(NULL != pModel);
|
||||
if (NULL == pObject) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -269,15 +264,15 @@ aiNode *ObjFileImporter::createNodes(const ObjFile::Model* pModel, const ObjFile
|
|||
pNode->mName = pObject->m_strObjName;
|
||||
|
||||
// If we have a parent node, store it
|
||||
ai_assert( NULL != pParent );
|
||||
appendChildToParentNode( pParent, pNode );
|
||||
ai_assert(NULL != pParent);
|
||||
appendChildToParentNode(pParent, pNode);
|
||||
|
||||
for ( size_t i=0; i< pObject->m_Meshes.size(); ++i ) {
|
||||
unsigned int meshId = pObject->m_Meshes[ i ];
|
||||
aiMesh *pMesh = createTopology( pModel, pObject, meshId );
|
||||
if( pMesh ) {
|
||||
for (size_t i = 0; i < pObject->m_Meshes.size(); ++i) {
|
||||
unsigned int meshId = pObject->m_Meshes[i];
|
||||
aiMesh *pMesh = createTopology(pModel, pObject, meshId);
|
||||
if (pMesh) {
|
||||
if (pMesh->mNumFaces > 0) {
|
||||
MeshArray.push_back( pMesh );
|
||||
MeshArray.push_back(pMesh);
|
||||
} else {
|
||||
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
|
||||
if ( !pObject->m_SubObjects.empty() ) {
|
||||
if (!pObject->m_SubObjects.empty()) {
|
||||
size_t numChilds = pObject->m_SubObjects.size();
|
||||
pNode->mNumChildren = static_cast<unsigned int>( numChilds );
|
||||
pNode->mChildren = new aiNode*[ numChilds ];
|
||||
pNode->mNumChildren = static_cast<unsigned int>(numChilds);
|
||||
pNode->mChildren = new aiNode *[numChilds];
|
||||
pNode->mNumMeshes = 1;
|
||||
pNode->mMeshes = new unsigned int[ 1 ];
|
||||
pNode->mMeshes = new unsigned int[1];
|
||||
}
|
||||
|
||||
// Set mesh instances into scene- and node-instances
|
||||
const size_t meshSizeDiff = MeshArray.size()- oldMeshSize;
|
||||
if ( meshSizeDiff > 0 ) {
|
||||
pNode->mMeshes = new unsigned int[ meshSizeDiff ];
|
||||
pNode->mNumMeshes = static_cast<unsigned int>( meshSizeDiff );
|
||||
const size_t meshSizeDiff = MeshArray.size() - oldMeshSize;
|
||||
if (meshSizeDiff > 0) {
|
||||
pNode->mMeshes = new unsigned int[meshSizeDiff];
|
||||
pNode->mNumMeshes = static_cast<unsigned int>(meshSizeDiff);
|
||||
size_t index = 0;
|
||||
for (size_t i = oldMeshSize; i < MeshArray.size(); ++i ) {
|
||||
pNode->mMeshes[ index ] = pScene->mNumMeshes;
|
||||
for (size_t i = oldMeshSize; i < MeshArray.size(); ++i) {
|
||||
pNode->mMeshes[index] = pScene->mNumMeshes;
|
||||
pScene->mNumMeshes++;
|
||||
++index;
|
||||
}
|
||||
|
@ -311,33 +306,32 @@ aiNode *ObjFileImporter::createNodes(const ObjFile::Model* pModel, const ObjFile
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// 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
|
||||
ai_assert( NULL != pModel );
|
||||
ai_assert(NULL != pModel);
|
||||
|
||||
if( NULL == pData ) {
|
||||
if (NULL == pData) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Create faces
|
||||
ObjFile::Mesh *pObjMesh = pModel->m_Meshes[ meshIndex ];
|
||||
if( !pObjMesh ) {
|
||||
ObjFile::Mesh *pObjMesh = pModel->m_Meshes[meshIndex];
|
||||
if (!pObjMesh) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if( pObjMesh->m_Faces.empty() ) {
|
||||
if (pObjMesh->m_Faces.empty()) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
std::unique_ptr<aiMesh> pMesh(new aiMesh);
|
||||
if( !pObjMesh->m_name.empty() ) {
|
||||
pMesh->mName.Set( pObjMesh->m_name );
|
||||
if (!pObjMesh->m_name.empty()) {
|
||||
pMesh->mName.Set(pObjMesh->m_name);
|
||||
}
|
||||
|
||||
for (size_t index = 0; index < pObjMesh->m_Faces.size(); index++)
|
||||
{
|
||||
ObjFile::Face *const inp = pObjMesh->m_Faces[ index ];
|
||||
ai_assert( NULL != inp );
|
||||
for (size_t index = 0; index < pObjMesh->m_Faces.size(); index++) {
|
||||
ObjFile::Face *const inp = pObjMesh->m_Faces[index];
|
||||
ai_assert(NULL != inp);
|
||||
|
||||
if (inp->m_PrimitiveType == aiPrimitiveType_LINE) {
|
||||
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 );
|
||||
if ( pMesh->mNumFaces > 0 ) {
|
||||
pMesh->mFaces = new aiFace[ pMesh->mNumFaces ];
|
||||
if ( pObjMesh->m_uiMaterialIndex != ObjFile::Mesh::NoMaterial ) {
|
||||
unsigned int uiIdxCount(0u);
|
||||
if (pMesh->mNumFaces > 0) {
|
||||
pMesh->mFaces = new aiFace[pMesh->mNumFaces];
|
||||
if (pObjMesh->m_uiMaterialIndex != ObjFile::Mesh::NoMaterial) {
|
||||
pMesh->mMaterialIndex = pObjMesh->m_uiMaterialIndex;
|
||||
}
|
||||
|
||||
unsigned int outIndex( 0 );
|
||||
unsigned int outIndex(0);
|
||||
|
||||
// Copy all data from all stored meshes
|
||||
for (auto& face : pObjMesh->m_Faces) {
|
||||
ObjFile::Face* const inp = face;
|
||||
for (auto &face : pObjMesh->m_Faces) {
|
||||
ObjFile::Face *const inp = face;
|
||||
if (inp->m_PrimitiveType == aiPrimitiveType_LINE) {
|
||||
for(size_t i = 0; i < inp->m_vertices.size() - 1; ++i) {
|
||||
aiFace& f = pMesh->mFaces[ outIndex++ ];
|
||||
for (size_t i = 0; i < inp->m_vertices.size() - 1; ++i) {
|
||||
aiFace &f = pMesh->mFaces[outIndex++];
|
||||
uiIdxCount += f.mNumIndices = 2;
|
||||
f.mIndices = new unsigned int[2];
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else if (inp->m_PrimitiveType == aiPrimitiveType_POINT) {
|
||||
for(size_t i = 0; i < inp->m_vertices.size(); ++i) {
|
||||
aiFace& f = pMesh->mFaces[ outIndex++ ];
|
||||
} else if (inp->m_PrimitiveType == aiPrimitiveType_POINT) {
|
||||
for (size_t i = 0; i < inp->m_vertices.size(); ++i) {
|
||||
aiFace &f = pMesh->mFaces[outIndex++];
|
||||
uiIdxCount += f.mNumIndices = 1;
|
||||
f.mIndices = new unsigned int[1];
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
aiFace *pFace = &pMesh->mFaces[ outIndex++ ];
|
||||
const unsigned int uiNumIndices = (unsigned int) face->m_vertices.size();
|
||||
uiIdxCount += pFace->mNumIndices = (unsigned int) uiNumIndices;
|
||||
aiFace *pFace = &pMesh->mFaces[outIndex++];
|
||||
const unsigned int uiNumIndices = (unsigned int)face->m_vertices.size();
|
||||
uiIdxCount += pFace->mNumIndices = (unsigned int)uiNumIndices;
|
||||
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
|
||||
void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel,
|
||||
const ObjFile::Object* pCurrentObject,
|
||||
unsigned int uiMeshIndex,
|
||||
aiMesh* pMesh,
|
||||
unsigned int numIndices) {
|
||||
void ObjFileImporter::createVertexArray(const ObjFile::Model *pModel,
|
||||
const ObjFile::Object *pCurrentObject,
|
||||
unsigned int uiMeshIndex,
|
||||
aiMesh *pMesh,
|
||||
unsigned int numIndices) {
|
||||
// Checking preconditions
|
||||
ai_assert( NULL != pCurrentObject );
|
||||
ai_assert(NULL != pCurrentObject);
|
||||
|
||||
// Break, if no faces are stored in object
|
||||
if ( pCurrentObject->m_Meshes.empty() )
|
||||
if (pCurrentObject->m_Meshes.empty())
|
||||
return;
|
||||
|
||||
// Get current mesh
|
||||
ObjFile::Mesh *pObjMesh = pModel->m_Meshes[ uiMeshIndex ];
|
||||
if ( NULL == pObjMesh || pObjMesh->m_uiNumIndices < 1 ) {
|
||||
ObjFile::Mesh *pObjMesh = pModel->m_Meshes[uiMeshIndex];
|
||||
if (NULL == pObjMesh || pObjMesh->m_uiNumIndices < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Copy vertices of this mesh instance
|
||||
pMesh->mNumVertices = numIndices;
|
||||
if (pMesh->mNumVertices == 0) {
|
||||
throw DeadlyImportError( "OBJ: no vertices" );
|
||||
throw DeadlyImportError("OBJ: no 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
|
||||
if ( !pModel->m_Normals.empty() && pObjMesh->m_hasNormals )
|
||||
pMesh->mNormals = new aiVector3D[ pMesh->mNumVertices ];
|
||||
if (!pModel->m_Normals.empty() && pObjMesh->m_hasNormals)
|
||||
pMesh->mNormals = new aiVector3D[pMesh->mNumVertices];
|
||||
|
||||
// Allocate buffer for vertex-color vectors
|
||||
if ( !pModel->m_VertexColors.empty() )
|
||||
pMesh->mColors[0] = new aiColor4D[ pMesh->mNumVertices ];
|
||||
if (!pModel->m_VertexColors.empty())
|
||||
pMesh->mColors[0] = new aiColor4D[pMesh->mNumVertices];
|
||||
|
||||
// Allocate buffer for texture coordinates
|
||||
if ( !pModel->m_TextureCoord.empty() && pObjMesh->m_uiUVCoordinates[0] )
|
||||
{
|
||||
pMesh->mNumUVComponents[ 0 ] = pModel->m_TextureCoordDim;
|
||||
pMesh->mTextureCoords[ 0 ] = new aiVector3D[ pMesh->mNumVertices ];
|
||||
if (!pModel->m_TextureCoord.empty() && pObjMesh->m_uiUVCoordinates[0]) {
|
||||
pMesh->mNumUVComponents[0] = pModel->m_TextureCoordDim;
|
||||
pMesh->mTextureCoords[0] = new aiVector3D[pMesh->mNumVertices];
|
||||
}
|
||||
|
||||
// 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;
|
||||
for (auto sourceFace : pObjMesh->m_Faces) {
|
||||
// Copy all index arrays
|
||||
for (size_t vertexIndex = 0, outVertexIndex = 0; vertexIndex < sourceFace->m_vertices.size(); vertexIndex++ ) {
|
||||
const unsigned int vertex = sourceFace->m_vertices.at(vertexIndex );
|
||||
if ( vertex >= pModel->m_Vertices.size() ) {
|
||||
throw DeadlyImportError( "OBJ: vertex index out of range" );
|
||||
for (size_t vertexIndex = 0, outVertexIndex = 0; vertexIndex < sourceFace->m_vertices.size(); vertexIndex++) {
|
||||
const unsigned int vertex = sourceFace->m_vertices.at(vertexIndex);
|
||||
if (vertex >= pModel->m_Vertices.size()) {
|
||||
throw DeadlyImportError("OBJ: vertex index out of range");
|
||||
}
|
||||
|
||||
if ( pMesh->mNumVertices <= newIndex ) {
|
||||
if (pMesh->mNumVertices <= newIndex) {
|
||||
throw DeadlyImportError("OBJ: bad vertex index");
|
||||
}
|
||||
|
||||
pMesh->mVertices[ newIndex ] = pModel->m_Vertices[ vertex ];
|
||||
pMesh->mVertices[newIndex] = pModel->m_Vertices[vertex];
|
||||
|
||||
// Copy all normals
|
||||
if ( normalsok && !pModel->m_Normals.empty() && vertexIndex < sourceFace->m_normals.size()) {
|
||||
const unsigned int normal = sourceFace->m_normals.at(vertexIndex );
|
||||
if ( normal >= pModel->m_Normals.size() )
|
||||
{
|
||||
if (normalsok && !pModel->m_Normals.empty() && vertexIndex < sourceFace->m_normals.size()) {
|
||||
const unsigned int normal = sourceFace->m_normals.at(vertexIndex);
|
||||
if (normal >= pModel->m_Normals.size()) {
|
||||
normalsok = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
pMesh->mNormals[ newIndex ] = pModel->m_Normals[ normal ];
|
||||
} else {
|
||||
pMesh->mNormals[newIndex] = pModel->m_Normals[normal];
|
||||
}
|
||||
}
|
||||
|
||||
// Copy all vertex colors
|
||||
if ( !pModel->m_VertexColors.empty())
|
||||
{
|
||||
const aiVector3D& color = pModel->m_VertexColors[ vertex ];
|
||||
pMesh->mColors[0][ newIndex ] = aiColor4D(color.x, color.y, color.z, 1.0);
|
||||
if (!pModel->m_VertexColors.empty()) {
|
||||
const aiVector3D &color = pModel->m_VertexColors[vertex];
|
||||
pMesh->mColors[0][newIndex] = aiColor4D(color.x, color.y, color.z, 1.0);
|
||||
}
|
||||
|
||||
// Copy all texture coordinates
|
||||
if ( uvok && !pModel->m_TextureCoord.empty() && vertexIndex < sourceFace->m_texturCoords.size())
|
||||
{
|
||||
const unsigned int tex = sourceFace->m_texturCoords.at(vertexIndex );
|
||||
if (uvok && !pModel->m_TextureCoord.empty() && vertexIndex < sourceFace->m_texturCoords.size()) {
|
||||
const unsigned int tex = sourceFace->m_texturCoords.at(vertexIndex);
|
||||
|
||||
if ( tex >= pModel->m_TextureCoord.size() )
|
||||
{
|
||||
if (tex >= pModel->m_TextureCoord.size()) {
|
||||
uvok = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
const aiVector3D &coord3d = pModel->m_TextureCoord[ tex ];
|
||||
pMesh->mTextureCoords[ 0 ][ newIndex ] = aiVector3D( coord3d.x, coord3d.y, coord3d.z );
|
||||
} else {
|
||||
const aiVector3D &coord3d = pModel->m_TextureCoord[tex];
|
||||
pMesh->mTextureCoords[0][newIndex] = aiVector3D(coord3d.x, coord3d.y, coord3d.z);
|
||||
}
|
||||
}
|
||||
|
||||
// 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) {
|
||||
pDestFace->mIndices[ outVertexIndex ] = newIndex;
|
||||
pDestFace->mIndices[outVertexIndex] = newIndex;
|
||||
outVertexIndex++;
|
||||
}
|
||||
|
||||
|
@ -511,18 +495,18 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel,
|
|||
} else if (sourceFace->m_PrimitiveType == aiPrimitiveType_LINE) {
|
||||
outVertexIndex = 0;
|
||||
|
||||
if(!last)
|
||||
if (!last)
|
||||
outIndex++;
|
||||
|
||||
if (vertexIndex) {
|
||||
if(!last) {
|
||||
pMesh->mVertices[ newIndex+1 ] = pMesh->mVertices[ newIndex ];
|
||||
if (!last) {
|
||||
pMesh->mVertices[newIndex + 1] = pMesh->mVertices[newIndex];
|
||||
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() ) {
|
||||
for ( size_t i=0; i < pMesh->GetNumUVChannels(); i++ ) {
|
||||
pMesh->mTextureCoords[ i ][ newIndex+1 ] = pMesh->mTextureCoords[ i ][ newIndex ];
|
||||
if (!pModel->m_TextureCoord.empty()) {
|
||||
for (size_t i = 0; i < pMesh->GetNumUVChannels(); i++) {
|
||||
pMesh->mTextureCoords[i][newIndex + 1] = pMesh->mTextureCoords[i][newIndex];
|
||||
}
|
||||
}
|
||||
++newIndex;
|
||||
|
@ -530,40 +514,34 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel,
|
|||
|
||||
pDestFace[-1].mIndices[1] = newIndex;
|
||||
}
|
||||
}
|
||||
else if (last) {
|
||||
} else if (last) {
|
||||
outIndex++;
|
||||
}
|
||||
++newIndex;
|
||||
}
|
||||
}
|
||||
|
||||
if (!normalsok)
|
||||
{
|
||||
delete [] pMesh->mNormals;
|
||||
if (!normalsok) {
|
||||
delete[] pMesh->mNormals;
|
||||
pMesh->mNormals = nullptr;
|
||||
}
|
||||
|
||||
if (!uvok)
|
||||
{
|
||||
delete [] pMesh->mTextureCoords[0];
|
||||
if (!uvok) {
|
||||
delete[] pMesh->mTextureCoords[0];
|
||||
pMesh->mTextureCoords[0] = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// 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;
|
||||
if ( rObjects.empty() )
|
||||
if (rObjects.empty())
|
||||
return;
|
||||
|
||||
iNumMeshes += static_cast<unsigned int>( rObjects.size() );
|
||||
for (auto object: rObjects)
|
||||
{
|
||||
if (!object->m_SubObjects.empty())
|
||||
{
|
||||
iNumMeshes += static_cast<unsigned int>(rObjects.size());
|
||||
for (auto object : rObjects) {
|
||||
if (!object->m_SubObjects.empty()) {
|
||||
countObjects(object->m_SubObjects, iNumMeshes);
|
||||
}
|
||||
}
|
||||
|
@ -571,209 +549,187 @@ void ObjFileImporter::countObjects(const std::vector<ObjFile::Object*> &rObjects
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Add clamp mode property to material if necessary
|
||||
void ObjFileImporter::addTextureMappingModeProperty( aiMaterial* mat, aiTextureType type, int clampMode, int index) {
|
||||
if ( nullptr == mat ) {
|
||||
void ObjFileImporter::addTextureMappingModeProperty(aiMaterial *mat, aiTextureType type, int clampMode, int index) {
|
||||
if (nullptr == mat) {
|
||||
return;
|
||||
}
|
||||
|
||||
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_U(type, index));
|
||||
mat->AddProperty<int>(&clampMode, 1, AI_MATKEY_MAPPINGMODE_V(type, index));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Creates the material
|
||||
void ObjFileImporter::createMaterials(const ObjFile::Model* pModel, aiScene* pScene ) {
|
||||
if ( NULL == pScene ) {
|
||||
void ObjFileImporter::createMaterials(const ObjFile::Model *pModel, aiScene *pScene) {
|
||||
if (NULL == pScene) {
|
||||
return;
|
||||
}
|
||||
|
||||
const unsigned int numMaterials = (unsigned int) pModel->m_MaterialLib.size();
|
||||
const unsigned int numMaterials = (unsigned int)pModel->m_MaterialLib.size();
|
||||
pScene->mNumMaterials = 0;
|
||||
if ( pModel->m_MaterialLib.empty() ) {
|
||||
if (pModel->m_MaterialLib.empty()) {
|
||||
ASSIMP_LOG_DEBUG("OBJ: no materials specified");
|
||||
return;
|
||||
}
|
||||
|
||||
pScene->mMaterials = new aiMaterial*[ numMaterials ];
|
||||
for ( unsigned int matIndex = 0; matIndex < numMaterials; matIndex++ )
|
||||
{
|
||||
pScene->mMaterials = new aiMaterial *[numMaterials];
|
||||
for (unsigned int matIndex = 0; matIndex < numMaterials; matIndex++) {
|
||||
// Store material name
|
||||
std::map<std::string, ObjFile::Material*>::const_iterator it;
|
||||
it = pModel->m_MaterialMap.find( pModel->m_MaterialLib[ matIndex ] );
|
||||
std::map<std::string, ObjFile::Material *>::const_iterator it;
|
||||
it = pModel->m_MaterialMap.find(pModel->m_MaterialLib[matIndex]);
|
||||
|
||||
// No material found, use the default material
|
||||
if ( pModel->m_MaterialMap.end() == it )
|
||||
if (pModel->m_MaterialMap.end() == it)
|
||||
continue;
|
||||
|
||||
aiMaterial* mat = new aiMaterial;
|
||||
aiMaterial *mat = new aiMaterial;
|
||||
ObjFile::Material *pCurrentMaterial = (*it).second;
|
||||
mat->AddProperty( &pCurrentMaterial->MaterialName, AI_MATKEY_NAME );
|
||||
mat->AddProperty(&pCurrentMaterial->MaterialName, AI_MATKEY_NAME);
|
||||
|
||||
// convert illumination model
|
||||
int sm = 0;
|
||||
switch (pCurrentMaterial->illumination_model)
|
||||
{
|
||||
case 0:
|
||||
sm = aiShadingMode_NoShading;
|
||||
break;
|
||||
case 1:
|
||||
sm = aiShadingMode_Gouraud;
|
||||
break;
|
||||
case 2:
|
||||
sm = aiShadingMode_Phong;
|
||||
break;
|
||||
default:
|
||||
sm = aiShadingMode_Gouraud;
|
||||
ASSIMP_LOG_ERROR("OBJ: unexpected illumination model (0-2 recognized)");
|
||||
switch (pCurrentMaterial->illumination_model) {
|
||||
case 0:
|
||||
sm = aiShadingMode_NoShading;
|
||||
break;
|
||||
case 1:
|
||||
sm = aiShadingMode_Gouraud;
|
||||
break;
|
||||
case 2:
|
||||
sm = aiShadingMode_Phong;
|
||||
break;
|
||||
default:
|
||||
sm = aiShadingMode_Gouraud;
|
||||
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
|
||||
mat->AddProperty( &pCurrentMaterial->ambient, 1, AI_MATKEY_COLOR_AMBIENT );
|
||||
mat->AddProperty( &pCurrentMaterial->diffuse, 1, AI_MATKEY_COLOR_DIFFUSE );
|
||||
mat->AddProperty( &pCurrentMaterial->specular, 1, AI_MATKEY_COLOR_SPECULAR );
|
||||
mat->AddProperty( &pCurrentMaterial->emissive, 1, AI_MATKEY_COLOR_EMISSIVE );
|
||||
mat->AddProperty( &pCurrentMaterial->shineness, 1, AI_MATKEY_SHININESS );
|
||||
mat->AddProperty( &pCurrentMaterial->alpha, 1, AI_MATKEY_OPACITY );
|
||||
mat->AddProperty( &pCurrentMaterial->transparent,1,AI_MATKEY_COLOR_TRANSPARENT);
|
||||
mat->AddProperty(&pCurrentMaterial->ambient, 1, AI_MATKEY_COLOR_AMBIENT);
|
||||
mat->AddProperty(&pCurrentMaterial->diffuse, 1, AI_MATKEY_COLOR_DIFFUSE);
|
||||
mat->AddProperty(&pCurrentMaterial->specular, 1, AI_MATKEY_COLOR_SPECULAR);
|
||||
mat->AddProperty(&pCurrentMaterial->emissive, 1, AI_MATKEY_COLOR_EMISSIVE);
|
||||
mat->AddProperty(&pCurrentMaterial->shineness, 1, AI_MATKEY_SHININESS);
|
||||
mat->AddProperty(&pCurrentMaterial->alpha, 1, AI_MATKEY_OPACITY);
|
||||
mat->AddProperty(&pCurrentMaterial->transparent, 1, AI_MATKEY_COLOR_TRANSPARENT);
|
||||
|
||||
// Adding refraction index
|
||||
mat->AddProperty( &pCurrentMaterial->ior, 1, AI_MATKEY_REFRACTI );
|
||||
mat->AddProperty(&pCurrentMaterial->ior, 1, AI_MATKEY_REFRACTI);
|
||||
|
||||
// Adding textures
|
||||
const int uvwIndex = 0;
|
||||
|
||||
if ( 0 != pCurrentMaterial->texture.length )
|
||||
{
|
||||
mat->AddProperty( &pCurrentMaterial->texture, AI_MATKEY_TEXTURE_DIFFUSE(0));
|
||||
mat->AddProperty( &uvwIndex, 1, AI_MATKEY_UVWSRC_DIFFUSE(0) );
|
||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureDiffuseType])
|
||||
{
|
||||
if (0 != pCurrentMaterial->texture.length) {
|
||||
mat->AddProperty(&pCurrentMaterial->texture, AI_MATKEY_TEXTURE_DIFFUSE(0));
|
||||
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_DIFFUSE(0));
|
||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureDiffuseType]) {
|
||||
addTextureMappingModeProperty(mat, aiTextureType_DIFFUSE);
|
||||
}
|
||||
}
|
||||
|
||||
if ( 0 != pCurrentMaterial->textureAmbient.length )
|
||||
{
|
||||
mat->AddProperty( &pCurrentMaterial->textureAmbient, AI_MATKEY_TEXTURE_AMBIENT(0));
|
||||
mat->AddProperty( &uvwIndex, 1, AI_MATKEY_UVWSRC_AMBIENT(0) );
|
||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureAmbientType])
|
||||
{
|
||||
if (0 != pCurrentMaterial->textureAmbient.length) {
|
||||
mat->AddProperty(&pCurrentMaterial->textureAmbient, AI_MATKEY_TEXTURE_AMBIENT(0));
|
||||
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_AMBIENT(0));
|
||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureAmbientType]) {
|
||||
addTextureMappingModeProperty(mat, aiTextureType_AMBIENT);
|
||||
}
|
||||
}
|
||||
|
||||
if ( 0 != pCurrentMaterial->textureEmissive.length )
|
||||
{
|
||||
mat->AddProperty( &pCurrentMaterial->textureEmissive, AI_MATKEY_TEXTURE_EMISSIVE(0));
|
||||
mat->AddProperty( &uvwIndex, 1, AI_MATKEY_UVWSRC_EMISSIVE(0) );
|
||||
if (0 != pCurrentMaterial->textureEmissive.length) {
|
||||
mat->AddProperty(&pCurrentMaterial->textureEmissive, AI_MATKEY_TEXTURE_EMISSIVE(0));
|
||||
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_EMISSIVE(0));
|
||||
}
|
||||
|
||||
if ( 0 != pCurrentMaterial->textureSpecular.length )
|
||||
{
|
||||
mat->AddProperty( &pCurrentMaterial->textureSpecular, AI_MATKEY_TEXTURE_SPECULAR(0));
|
||||
mat->AddProperty( &uvwIndex, 1, AI_MATKEY_UVWSRC_SPECULAR(0) );
|
||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureSpecularType])
|
||||
{
|
||||
if (0 != pCurrentMaterial->textureSpecular.length) {
|
||||
mat->AddProperty(&pCurrentMaterial->textureSpecular, AI_MATKEY_TEXTURE_SPECULAR(0));
|
||||
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_SPECULAR(0));
|
||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureSpecularType]) {
|
||||
addTextureMappingModeProperty(mat, aiTextureType_SPECULAR);
|
||||
}
|
||||
}
|
||||
|
||||
if ( 0 != pCurrentMaterial->textureBump.length )
|
||||
{
|
||||
mat->AddProperty( &pCurrentMaterial->textureBump, AI_MATKEY_TEXTURE_HEIGHT(0));
|
||||
mat->AddProperty( &uvwIndex, 1, AI_MATKEY_UVWSRC_HEIGHT(0) );
|
||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureBumpType])
|
||||
{
|
||||
if (0 != pCurrentMaterial->textureBump.length) {
|
||||
mat->AddProperty(&pCurrentMaterial->textureBump, AI_MATKEY_TEXTURE_HEIGHT(0));
|
||||
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_HEIGHT(0));
|
||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureBumpType]) {
|
||||
addTextureMappingModeProperty(mat, aiTextureType_HEIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
if ( 0 != pCurrentMaterial->textureNormal.length )
|
||||
{
|
||||
mat->AddProperty( &pCurrentMaterial->textureNormal, AI_MATKEY_TEXTURE_NORMALS(0));
|
||||
mat->AddProperty( &uvwIndex, 1, AI_MATKEY_UVWSRC_NORMALS(0) );
|
||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureNormalType])
|
||||
{
|
||||
if (0 != pCurrentMaterial->textureNormal.length) {
|
||||
mat->AddProperty(&pCurrentMaterial->textureNormal, AI_MATKEY_TEXTURE_NORMALS(0));
|
||||
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_NORMALS(0));
|
||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureNormalType]) {
|
||||
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::TextureReflectionCubeTopType :
|
||||
ObjFile::Material::TextureReflectionSphereType;
|
||||
ObjFile::Material::TextureReflectionCubeTopType :
|
||||
ObjFile::Material::TextureReflectionSphereType;
|
||||
|
||||
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( &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);
|
||||
}
|
||||
}
|
||||
|
||||
if ( 0 != pCurrentMaterial->textureDisp.length )
|
||||
{
|
||||
mat->AddProperty( &pCurrentMaterial->textureDisp, AI_MATKEY_TEXTURE_DISPLACEMENT(0) );
|
||||
mat->AddProperty( &uvwIndex, 1, AI_MATKEY_UVWSRC_DISPLACEMENT(0) );
|
||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureDispType])
|
||||
{
|
||||
if (0 != pCurrentMaterial->textureDisp.length) {
|
||||
mat->AddProperty(&pCurrentMaterial->textureDisp, AI_MATKEY_TEXTURE_DISPLACEMENT(0));
|
||||
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_DISPLACEMENT(0));
|
||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureDispType]) {
|
||||
addTextureMappingModeProperty(mat, aiTextureType_DISPLACEMENT);
|
||||
}
|
||||
}
|
||||
|
||||
if ( 0 != pCurrentMaterial->textureOpacity.length )
|
||||
{
|
||||
mat->AddProperty( &pCurrentMaterial->textureOpacity, AI_MATKEY_TEXTURE_OPACITY(0));
|
||||
mat->AddProperty( &uvwIndex, 1, AI_MATKEY_UVWSRC_OPACITY(0) );
|
||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureOpacityType])
|
||||
{
|
||||
if (0 != pCurrentMaterial->textureOpacity.length) {
|
||||
mat->AddProperty(&pCurrentMaterial->textureOpacity, AI_MATKEY_TEXTURE_OPACITY(0));
|
||||
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_OPACITY(0));
|
||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureOpacityType]) {
|
||||
addTextureMappingModeProperty(mat, aiTextureType_OPACITY);
|
||||
}
|
||||
}
|
||||
|
||||
if ( 0 != pCurrentMaterial->textureSpecularity.length )
|
||||
{
|
||||
mat->AddProperty( &pCurrentMaterial->textureSpecularity, AI_MATKEY_TEXTURE_SHININESS(0));
|
||||
mat->AddProperty( &uvwIndex, 1, AI_MATKEY_UVWSRC_SHININESS(0) );
|
||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureSpecularityType])
|
||||
{
|
||||
if (0 != pCurrentMaterial->textureSpecularity.length) {
|
||||
mat->AddProperty(&pCurrentMaterial->textureSpecularity, AI_MATKEY_TEXTURE_SHININESS(0));
|
||||
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_SHININESS(0));
|
||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureSpecularityType]) {
|
||||
addTextureMappingModeProperty(mat, aiTextureType_SHININESS);
|
||||
}
|
||||
}
|
||||
|
||||
// Store material property info in material array in scene
|
||||
pScene->mMaterials[ pScene->mNumMaterials ] = mat;
|
||||
pScene->mMaterials[pScene->mNumMaterials] = mat;
|
||||
pScene->mNumMaterials++;
|
||||
}
|
||||
|
||||
// Test number of created materials.
|
||||
ai_assert( pScene->mNumMaterials == numMaterials );
|
||||
ai_assert(pScene->mNumMaterials == numMaterials);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Appends this node to the parent node
|
||||
void ObjFileImporter::appendChildToParentNode(aiNode *pParent, aiNode *pChild)
|
||||
{
|
||||
void ObjFileImporter::appendChildToParentNode(aiNode *pParent, aiNode *pChild) {
|
||||
// Checking preconditions
|
||||
ai_assert( NULL != pParent );
|
||||
ai_assert( NULL != pChild );
|
||||
ai_assert(NULL != pParent);
|
||||
ai_assert(NULL != pChild);
|
||||
|
||||
// Assign parent to child
|
||||
pChild->mParent = pParent;
|
||||
|
||||
// Copy node instances into parent node
|
||||
pParent->mNumChildren++;
|
||||
pParent->mChildren[ pParent->mNumChildren-1 ] = pChild;
|
||||
pParent->mChildren[pParent->mNumChildren - 1] = pChild;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
} // Namespace Assimp
|
||||
} // Namespace Assimp
|
||||
|
||||
#endif // !! ASSIMP_BUILD_NO_OBJ_IMPORTER
|
||||
|
|
|
@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
|
|||
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
|
@ -52,9 +51,9 @@ struct aiNode;
|
|||
namespace Assimp {
|
||||
|
||||
namespace ObjFile {
|
||||
struct Object;
|
||||
struct Model;
|
||||
}
|
||||
struct Object;
|
||||
struct Model;
|
||||
} // namespace ObjFile
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
/// \class ObjFileImporter
|
||||
|
@ -71,38 +70,38 @@ public:
|
|||
public:
|
||||
/// \brief Returns whether the class can handle the format of the given file.
|
||||
/// \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:
|
||||
//! \brief Appends the supported extension.
|
||||
const aiImporterDesc* GetInfo () const;
|
||||
const aiImporterDesc *GetInfo() const;
|
||||
|
||||
//! \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.
|
||||
void CreateDataFromImport(const ObjFile::Model* pModel, aiScene* pScene);
|
||||
void CreateDataFromImport(const ObjFile::Model *pModel, aiScene *pScene);
|
||||
|
||||
//! \brief Creates all nodes stored in imported content.
|
||||
aiNode *createNodes(const ObjFile::Model* pModel, const ObjFile::Object* pData,
|
||||
aiNode *pParent, aiScene* pScene, std::vector<aiMesh*> &MeshArray);
|
||||
aiNode *createNodes(const ObjFile::Model *pModel, const ObjFile::Object *pData,
|
||||
aiNode *pParent, aiScene *pScene, std::vector<aiMesh *> &MeshArray);
|
||||
|
||||
//! \brief Creates topology data like faces and meshes for the geometry.
|
||||
aiMesh *createTopology( const ObjFile::Model* pModel, const ObjFile::Object* pData,
|
||||
unsigned int uiMeshIndex );
|
||||
aiMesh *createTopology(const ObjFile::Model *pModel, const ObjFile::Object *pData,
|
||||
unsigned int uiMeshIndex);
|
||||
|
||||
//! \brief Creates vertices from model.
|
||||
void createVertexArray(const ObjFile::Model* pModel, const ObjFile::Object* pCurrentObject,
|
||||
unsigned int uiMeshIndex, aiMesh* pMesh, unsigned int numIndices );
|
||||
void createVertexArray(const ObjFile::Model *pModel, const ObjFile::Object *pCurrentObject,
|
||||
unsigned int uiMeshIndex, aiMesh *pMesh, unsigned int numIndices);
|
||||
|
||||
//! \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.
|
||||
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.
|
||||
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.
|
||||
void appendChildToParentNode(aiNode *pParent, aiNode *pChild);
|
||||
|
|
|
@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
|
|||
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
|
@ -41,214 +39,186 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
---------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_OBJ_IMPORTER
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "ObjFileMtlImporter.h"
|
||||
#include "ObjTools.h"
|
||||
#include "ObjFileData.h"
|
||||
#include <assimp/fast_atof.h>
|
||||
#include "ObjTools.h"
|
||||
#include <assimp/ParsingUtils.h>
|
||||
#include <assimp/fast_atof.h>
|
||||
#include <assimp/material.h>
|
||||
#include <stdlib.h>
|
||||
#include <assimp/DefaultLogger.hpp>
|
||||
|
||||
namespace Assimp {
|
||||
namespace Assimp {
|
||||
|
||||
// Material specific token (case insensitive compare)
|
||||
static const std::string DiffuseTexture = "map_Kd";
|
||||
static const std::string AmbientTexture = "map_Ka";
|
||||
static const std::string SpecularTexture = "map_Ks";
|
||||
static const std::string OpacityTexture = "map_d";
|
||||
static const std::string EmissiveTexture1 = "map_emissive";
|
||||
static const std::string EmissiveTexture2 = "map_Ke";
|
||||
static const std::string BumpTexture1 = "map_bump";
|
||||
static const std::string BumpTexture2 = "bump";
|
||||
static const std::string NormalTexture = "map_Kn";
|
||||
static const std::string ReflectionTexture = "refl";
|
||||
static const std::string DiffuseTexture = "map_Kd";
|
||||
static const std::string AmbientTexture = "map_Ka";
|
||||
static const std::string SpecularTexture = "map_Ks";
|
||||
static const std::string OpacityTexture = "map_d";
|
||||
static const std::string EmissiveTexture1 = "map_emissive";
|
||||
static const std::string EmissiveTexture2 = "map_Ke";
|
||||
static const std::string BumpTexture1 = "map_bump";
|
||||
static const std::string BumpTexture2 = "bump";
|
||||
static const std::string NormalTexture = "map_Kn";
|
||||
static const std::string ReflectionTexture = "refl";
|
||||
static const std::string DisplacementTexture1 = "map_disp";
|
||||
static const std::string DisplacementTexture2 = "disp";
|
||||
static const std::string SpecularityTexture = "map_ns";
|
||||
static const std::string SpecularityTexture = "map_ns";
|
||||
|
||||
// texture option specific token
|
||||
static const std::string BlendUOption = "-blendu";
|
||||
static const std::string BlendVOption = "-blendv";
|
||||
static const std::string BoostOption = "-boost";
|
||||
static const std::string ModifyMapOption = "-mm";
|
||||
static const std::string OffsetOption = "-o";
|
||||
static const std::string ScaleOption = "-s";
|
||||
static const std::string TurbulenceOption = "-t";
|
||||
static const std::string ResolutionOption = "-texres";
|
||||
static const std::string ClampOption = "-clamp";
|
||||
static const std::string BumpOption = "-bm";
|
||||
static const std::string ChannelOption = "-imfchan";
|
||||
static const std::string TypeOption = "-type";
|
||||
static const std::string BlendUOption = "-blendu";
|
||||
static const std::string BlendVOption = "-blendv";
|
||||
static const std::string BoostOption = "-boost";
|
||||
static const std::string ModifyMapOption = "-mm";
|
||||
static const std::string OffsetOption = "-o";
|
||||
static const std::string ScaleOption = "-s";
|
||||
static const std::string TurbulenceOption = "-t";
|
||||
static const std::string ResolutionOption = "-texres";
|
||||
static const std::string ClampOption = "-clamp";
|
||||
static const std::string BumpOption = "-bm";
|
||||
static const std::string ChannelOption = "-imfchan";
|
||||
static const std::string TypeOption = "-type";
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Constructor
|
||||
ObjFileMtlImporter::ObjFileMtlImporter( std::vector<char> &buffer,
|
||||
const std::string &,
|
||||
ObjFile::Model *pModel ) :
|
||||
m_DataIt( buffer.begin() ),
|
||||
m_DataItEnd( buffer.end() ),
|
||||
m_pModel( pModel ),
|
||||
m_uiLine( 0 )
|
||||
{
|
||||
ai_assert( NULL != m_pModel );
|
||||
if ( NULL == m_pModel->m_pDefaultMaterial )
|
||||
{
|
||||
ObjFileMtlImporter::ObjFileMtlImporter(std::vector<char> &buffer,
|
||||
const std::string &,
|
||||
ObjFile::Model *pModel) :
|
||||
m_DataIt(buffer.begin()),
|
||||
m_DataItEnd(buffer.end()),
|
||||
m_pModel(pModel),
|
||||
m_uiLine(0) {
|
||||
ai_assert(NULL != m_pModel);
|
||||
if (NULL == m_pModel->m_pDefaultMaterial) {
|
||||
m_pModel->m_pDefaultMaterial = new ObjFile::Material;
|
||||
m_pModel->m_pDefaultMaterial->MaterialName.Set( "default" );
|
||||
m_pModel->m_pDefaultMaterial->MaterialName.Set("default");
|
||||
}
|
||||
load();
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Destructor
|
||||
ObjFileMtlImporter::~ObjFileMtlImporter()
|
||||
{
|
||||
ObjFileMtlImporter::~ObjFileMtlImporter() {
|
||||
// empty
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Private copy constructor
|
||||
ObjFileMtlImporter::ObjFileMtlImporter(const ObjFileMtlImporter & )
|
||||
{
|
||||
ObjFileMtlImporter::ObjFileMtlImporter(const ObjFileMtlImporter &) {
|
||||
// empty
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Private copy constructor
|
||||
ObjFileMtlImporter &ObjFileMtlImporter::operator = ( const ObjFileMtlImporter & )
|
||||
{
|
||||
ObjFileMtlImporter &ObjFileMtlImporter::operator=(const ObjFileMtlImporter &) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Loads the material description
|
||||
void ObjFileMtlImporter::load()
|
||||
{
|
||||
if ( m_DataIt == m_DataItEnd )
|
||||
void ObjFileMtlImporter::load() {
|
||||
if (m_DataIt == m_DataItEnd)
|
||||
return;
|
||||
|
||||
while ( m_DataIt != m_DataItEnd )
|
||||
{
|
||||
switch (*m_DataIt)
|
||||
{
|
||||
case 'k':
|
||||
case 'K':
|
||||
{
|
||||
while (m_DataIt != m_DataItEnd) {
|
||||
switch (*m_DataIt) {
|
||||
case 'k':
|
||||
case 'K': {
|
||||
++m_DataIt;
|
||||
if (*m_DataIt == 'a') // Ambient color
|
||||
{
|
||||
++m_DataIt;
|
||||
getColorRGBA( &m_pModel->m_pCurrentMaterial->ambient );
|
||||
}
|
||||
else if (*m_DataIt == 'd') // Diffuse color
|
||||
getColorRGBA(&m_pModel->m_pCurrentMaterial->ambient);
|
||||
} else if (*m_DataIt == 'd') // Diffuse color
|
||||
{
|
||||
++m_DataIt;
|
||||
getColorRGBA( &m_pModel->m_pCurrentMaterial->diffuse );
|
||||
}
|
||||
else if (*m_DataIt == 's')
|
||||
{
|
||||
getColorRGBA(&m_pModel->m_pCurrentMaterial->diffuse);
|
||||
} else if (*m_DataIt == 's') {
|
||||
++m_DataIt;
|
||||
getColorRGBA( &m_pModel->m_pCurrentMaterial->specular );
|
||||
}
|
||||
else if (*m_DataIt == 'e')
|
||||
{
|
||||
getColorRGBA(&m_pModel->m_pCurrentMaterial->specular);
|
||||
} else if (*m_DataIt == 'e') {
|
||||
++m_DataIt;
|
||||
getColorRGBA( &m_pModel->m_pCurrentMaterial->emissive );
|
||||
getColorRGBA(&m_pModel->m_pCurrentMaterial->emissive);
|
||||
}
|
||||
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
||||
}
|
||||
break;
|
||||
case 'T':
|
||||
{
|
||||
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||
} break;
|
||||
case 'T': {
|
||||
++m_DataIt;
|
||||
if (*m_DataIt == 'f') // Material transmission
|
||||
{
|
||||
++m_DataIt;
|
||||
getColorRGBA( &m_pModel->m_pCurrentMaterial->transparent);
|
||||
getColorRGBA(&m_pModel->m_pCurrentMaterial->transparent);
|
||||
}
|
||||
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
||||
}
|
||||
break;
|
||||
case 'd':
|
||||
{
|
||||
if( *(m_DataIt+1) == 'i' && *( m_DataIt + 2 ) == 's' && *( m_DataIt + 3 ) == 'p' ) {
|
||||
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||
} break;
|
||||
case 'd': {
|
||||
if (*(m_DataIt + 1) == 'i' && *(m_DataIt + 2) == 's' && *(m_DataIt + 3) == 'p') {
|
||||
// A displacement map
|
||||
getTexture();
|
||||
} else {
|
||||
// Alpha value
|
||||
++m_DataIt;
|
||||
getFloatValue( m_pModel->m_pCurrentMaterial->alpha );
|
||||
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
||||
getFloatValue(m_pModel->m_pCurrentMaterial->alpha);
|
||||
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||
}
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case 'N':
|
||||
case 'n':
|
||||
{
|
||||
case 'N':
|
||||
case 'n': {
|
||||
++m_DataIt;
|
||||
switch(*m_DataIt)
|
||||
{
|
||||
case 's': // Specular exponent
|
||||
++m_DataIt;
|
||||
getFloatValue(m_pModel->m_pCurrentMaterial->shineness);
|
||||
break;
|
||||
case 'i': // Index Of refraction
|
||||
++m_DataIt;
|
||||
getFloatValue(m_pModel->m_pCurrentMaterial->ior);
|
||||
break;
|
||||
case 'e': // New material
|
||||
createMaterial();
|
||||
break;
|
||||
switch (*m_DataIt) {
|
||||
case 's': // Specular exponent
|
||||
++m_DataIt;
|
||||
getFloatValue(m_pModel->m_pCurrentMaterial->shineness);
|
||||
break;
|
||||
case 'i': // Index Of refraction
|
||||
++m_DataIt;
|
||||
getFloatValue(m_pModel->m_pCurrentMaterial->ior);
|
||||
break;
|
||||
case 'e': // New material
|
||||
createMaterial();
|
||||
break;
|
||||
}
|
||||
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
||||
}
|
||||
break;
|
||||
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||
} break;
|
||||
|
||||
case 'm': // Texture
|
||||
case 'b': // quick'n'dirty - for 'bump' sections
|
||||
case 'r': // quick'n'dirty - for 'refl' sections
|
||||
case 'm': // Texture
|
||||
case 'b': // quick'n'dirty - for 'bump' sections
|
||||
case 'r': // quick'n'dirty - for 'refl' sections
|
||||
{
|
||||
getTexture();
|
||||
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
||||
}
|
||||
break;
|
||||
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||
} break;
|
||||
|
||||
case 'i': // Illumination model
|
||||
case 'i': // Illumination model
|
||||
{
|
||||
m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
||||
getIlluminationModel( m_pModel->m_pCurrentMaterial->illumination_model );
|
||||
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
||||
}
|
||||
break;
|
||||
getIlluminationModel(m_pModel->m_pCurrentMaterial->illumination_model);
|
||||
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||
} break;
|
||||
|
||||
default:
|
||||
{
|
||||
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Loads a color definition
|
||||
void ObjFileMtlImporter::getColorRGBA( aiColor3D *pColor )
|
||||
{
|
||||
ai_assert( NULL != pColor );
|
||||
void ObjFileMtlImporter::getColorRGBA(aiColor3D *pColor) {
|
||||
ai_assert(NULL != pColor);
|
||||
|
||||
ai_real r( 0.0 ), g( 0.0 ), b( 0.0 );
|
||||
m_DataIt = getFloat<DataArrayIt>( m_DataIt, m_DataItEnd, r );
|
||||
ai_real r(0.0), g(0.0), b(0.0);
|
||||
m_DataIt = getFloat<DataArrayIt>(m_DataIt, m_DataItEnd, r);
|
||||
pColor->r = r;
|
||||
|
||||
// we have to check if color is default 0 with only one token
|
||||
if( !IsLineEnd( *m_DataIt ) ) {
|
||||
m_DataIt = getFloat<DataArrayIt>( m_DataIt, m_DataItEnd, g );
|
||||
m_DataIt = getFloat<DataArrayIt>( m_DataIt, m_DataItEnd, b );
|
||||
if (!IsLineEnd(*m_DataIt)) {
|
||||
m_DataIt = getFloat<DataArrayIt>(m_DataIt, m_DataItEnd, g);
|
||||
m_DataIt = getFloat<DataArrayIt>(m_DataIt, m_DataItEnd, b);
|
||||
}
|
||||
pColor->g = g;
|
||||
pColor->b = b;
|
||||
|
@ -256,34 +226,31 @@ void ObjFileMtlImporter::getColorRGBA( aiColor3D *pColor )
|
|||
|
||||
// -------------------------------------------------------------------
|
||||
// Loads the kind of illumination model.
|
||||
void ObjFileMtlImporter::getIlluminationModel( int &illum_model )
|
||||
{
|
||||
m_DataIt = CopyNextWord<DataArrayIt>( m_DataIt, m_DataItEnd, m_buffer, BUFFERSIZE );
|
||||
void ObjFileMtlImporter::getIlluminationModel(int &illum_model) {
|
||||
m_DataIt = CopyNextWord<DataArrayIt>(m_DataIt, m_DataItEnd, m_buffer, BUFFERSIZE);
|
||||
illum_model = atoi(m_buffer);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Loads a single float value.
|
||||
void ObjFileMtlImporter::getFloatValue( ai_real &value )
|
||||
{
|
||||
m_DataIt = CopyNextWord<DataArrayIt>( m_DataIt, m_DataItEnd, m_buffer, BUFFERSIZE );
|
||||
value = (ai_real) fast_atof(m_buffer);
|
||||
void ObjFileMtlImporter::getFloatValue(ai_real &value) {
|
||||
m_DataIt = CopyNextWord<DataArrayIt>(m_DataIt, m_DataItEnd, m_buffer, BUFFERSIZE);
|
||||
value = (ai_real)fast_atof(m_buffer);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Creates a material from loaded data.
|
||||
void ObjFileMtlImporter::createMaterial()
|
||||
{
|
||||
void ObjFileMtlImporter::createMaterial() {
|
||||
std::string line;
|
||||
while( !IsLineEnd( *m_DataIt ) ) {
|
||||
while (!IsLineEnd(*m_DataIt)) {
|
||||
line += *m_DataIt;
|
||||
++m_DataIt;
|
||||
}
|
||||
|
||||
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;
|
||||
if ( numToken == 1 ) {
|
||||
if (numToken == 1) {
|
||||
name = AI_DEFAULT_MATERIAL_NAME;
|
||||
} else {
|
||||
// skip newmtl and all following white spaces
|
||||
|
@ -296,13 +263,13 @@ void ObjFileMtlImporter::createMaterial()
|
|||
|
||||
name = trim_whitespaces(name);
|
||||
|
||||
std::map<std::string, ObjFile::Material*>::iterator it = m_pModel->m_MaterialMap.find( name );
|
||||
if ( m_pModel->m_MaterialMap.end() == it) {
|
||||
std::map<std::string, ObjFile::Material *>::iterator it = m_pModel->m_MaterialMap.find(name);
|
||||
if (m_pModel->m_MaterialMap.end() == it) {
|
||||
// New Material created
|
||||
m_pModel->m_pCurrentMaterial = new ObjFile::Material();
|
||||
m_pModel->m_pCurrentMaterial->MaterialName.Set( name );
|
||||
m_pModel->m_MaterialLib.push_back( name );
|
||||
m_pModel->m_MaterialMap[ name ] = m_pModel->m_pCurrentMaterial;
|
||||
m_pModel->m_pCurrentMaterial->MaterialName.Set(name);
|
||||
m_pModel->m_MaterialLib.push_back(name);
|
||||
m_pModel->m_MaterialMap[name] = m_pModel->m_pCurrentMaterial;
|
||||
|
||||
if (m_pModel->m_pCurrentMesh) {
|
||||
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.
|
||||
void ObjFileMtlImporter::getTexture() {
|
||||
aiString *out( NULL );
|
||||
aiString *out(NULL);
|
||||
int clampIndex = -1;
|
||||
|
||||
const char *pPtr( &(*m_DataIt) );
|
||||
if ( !ASSIMP_strincmp( pPtr, DiffuseTexture.c_str(), static_cast<unsigned int>(DiffuseTexture.size()) ) ) {
|
||||
const char *pPtr(&(*m_DataIt));
|
||||
if (!ASSIMP_strincmp(pPtr, DiffuseTexture.c_str(), static_cast<unsigned int>(DiffuseTexture.size()))) {
|
||||
// Diffuse texture
|
||||
out = & m_pModel->m_pCurrentMaterial->texture;
|
||||
out = &m_pModel->m_pCurrentMaterial->texture;
|
||||
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
|
||||
out = & m_pModel->m_pCurrentMaterial->textureAmbient;
|
||||
out = &m_pModel->m_pCurrentMaterial->textureAmbient;
|
||||
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
|
||||
out = & m_pModel->m_pCurrentMaterial->textureSpecular;
|
||||
out = &m_pModel->m_pCurrentMaterial->textureSpecular;
|
||||
clampIndex = ObjFile::Material::TextureSpecularType;
|
||||
} else if ( !ASSIMP_strincmp( pPtr, DisplacementTexture1.c_str(), static_cast<unsigned int>(DisplacementTexture1.size()) ) ||
|
||||
!ASSIMP_strincmp( pPtr, DisplacementTexture2.c_str(), static_cast<unsigned int>(DisplacementTexture2.size()) ) ) {
|
||||
} else if (!ASSIMP_strincmp(pPtr, DisplacementTexture1.c_str(), static_cast<unsigned int>(DisplacementTexture1.size())) ||
|
||||
!ASSIMP_strincmp(pPtr, DisplacementTexture2.c_str(), static_cast<unsigned int>(DisplacementTexture2.size()))) {
|
||||
// Displacement texture
|
||||
out = &m_pModel->m_pCurrentMaterial->textureDisp;
|
||||
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
|
||||
out = & m_pModel->m_pCurrentMaterial->textureOpacity;
|
||||
out = &m_pModel->m_pCurrentMaterial->textureOpacity;
|
||||
clampIndex = ObjFile::Material::TextureOpacityType;
|
||||
} else if ( !ASSIMP_strincmp( pPtr, EmissiveTexture1.c_str(), static_cast<unsigned int>(EmissiveTexture1.size()) ) ||
|
||||
!ASSIMP_strincmp( pPtr, EmissiveTexture2.c_str(), static_cast<unsigned int>(EmissiveTexture2.size()) ) ) {
|
||||
} else if (!ASSIMP_strincmp(pPtr, EmissiveTexture1.c_str(), static_cast<unsigned int>(EmissiveTexture1.size())) ||
|
||||
!ASSIMP_strincmp(pPtr, EmissiveTexture2.c_str(), static_cast<unsigned int>(EmissiveTexture2.size()))) {
|
||||
// Emissive texture
|
||||
out = & m_pModel->m_pCurrentMaterial->textureEmissive;
|
||||
out = &m_pModel->m_pCurrentMaterial->textureEmissive;
|
||||
clampIndex = ObjFile::Material::TextureEmissiveType;
|
||||
} else if ( !ASSIMP_strincmp( pPtr, BumpTexture1.c_str(), static_cast<unsigned int>(BumpTexture1.size()) ) ||
|
||||
!ASSIMP_strincmp( pPtr, BumpTexture2.c_str(), static_cast<unsigned int>(BumpTexture2.size()) ) ) {
|
||||
} else if (!ASSIMP_strincmp(pPtr, BumpTexture1.c_str(), static_cast<unsigned int>(BumpTexture1.size())) ||
|
||||
!ASSIMP_strincmp(pPtr, BumpTexture2.c_str(), static_cast<unsigned int>(BumpTexture2.size()))) {
|
||||
// Bump texture
|
||||
out = & m_pModel->m_pCurrentMaterial->textureBump;
|
||||
out = &m_pModel->m_pCurrentMaterial->textureBump;
|
||||
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
|
||||
out = & m_pModel->m_pCurrentMaterial->textureNormal;
|
||||
out = &m_pModel->m_pCurrentMaterial->textureNormal;
|
||||
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)
|
||||
//Do nothing here
|
||||
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)
|
||||
out = & m_pModel->m_pCurrentMaterial->textureSpecularity;
|
||||
out = &m_pModel->m_pCurrentMaterial->textureSpecularity;
|
||||
clampIndex = ObjFile::Material::TextureSpecularityType;
|
||||
} else {
|
||||
ASSIMP_LOG_ERROR("OBJ/MTL: Encountered unknown texture type");
|
||||
|
@ -373,9 +340,9 @@ void ObjFileMtlImporter::getTexture() {
|
|||
m_pModel->m_pCurrentMaterial->clamp[clampIndex] = clamp;
|
||||
|
||||
std::string texture;
|
||||
m_DataIt = getName<DataArrayIt>( m_DataIt, m_DataItEnd, texture );
|
||||
if ( NULL!=out ) {
|
||||
out->Set( texture );
|
||||
m_DataIt = getName<DataArrayIt>(m_DataIt, m_DataItEnd, texture);
|
||||
if (NULL != out) {
|
||||
out->Set(texture);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -398,90 +365,57 @@ void ObjFileMtlImporter::getTextureOption(bool &clamp, int &clampIndex, aiString
|
|||
m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
||||
|
||||
// If there is any more texture option
|
||||
while (!isEndOfBuffer(m_DataIt, m_DataItEnd) && *m_DataIt == '-')
|
||||
{
|
||||
const char *pPtr( &(*m_DataIt) );
|
||||
while (!isEndOfBuffer(m_DataIt, m_DataItEnd) && *m_DataIt == '-') {
|
||||
const char *pPtr(&(*m_DataIt));
|
||||
//skip option key and value
|
||||
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);
|
||||
char value[3];
|
||||
CopyNextWord(it, m_DataItEnd, value, sizeof(value) / sizeof(*value));
|
||||
if (!ASSIMP_strincmp(value, "on", 2))
|
||||
{
|
||||
if (!ASSIMP_strincmp(value, "on", 2)) {
|
||||
clamp = true;
|
||||
}
|
||||
|
||||
skipToken = 2;
|
||||
}
|
||||
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 ];
|
||||
CopyNextWord( it, m_DataItEnd, value, sizeof( value ) / sizeof( *value ) );
|
||||
if( !ASSIMP_strincmp( value, "cube_top", 8 ) )
|
||||
{
|
||||
} 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];
|
||||
CopyNextWord(it, m_DataItEnd, value, sizeof(value) / sizeof(*value));
|
||||
if (!ASSIMP_strincmp(value, "cube_top", 8)) {
|
||||
clampIndex = ObjFile::Material::TextureReflectionCubeTopType;
|
||||
out = &m_pModel->m_pCurrentMaterial->textureReflection[0];
|
||||
}
|
||||
else if( !ASSIMP_strincmp( value, "cube_bottom", 11 ) )
|
||||
{
|
||||
} else if (!ASSIMP_strincmp(value, "cube_bottom", 11)) {
|
||||
clampIndex = ObjFile::Material::TextureReflectionCubeBottomType;
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
out = &m_pModel->m_pCurrentMaterial->textureReflection[0];
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
for (int i = 0; i < skipToken; ++i)
|
||||
{
|
||||
for (int i = 0; i < skipToken; ++i) {
|
||||
m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
|
|||
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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
|
||||
#define OBJFILEMTLIMPORTER_H_INC
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <assimp/defs.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct aiColor3D;
|
||||
struct aiString;
|
||||
|
@ -51,17 +50,15 @@ struct aiString;
|
|||
namespace Assimp {
|
||||
|
||||
namespace ObjFile {
|
||||
struct Model;
|
||||
struct Material;
|
||||
}
|
||||
|
||||
struct Model;
|
||||
struct Material;
|
||||
} // namespace ObjFile
|
||||
|
||||
/**
|
||||
* @class ObjFileMtlImporter
|
||||
* @brief Loads the material description from a mtl file.
|
||||
*/
|
||||
class ObjFileMtlImporter
|
||||
{
|
||||
class ObjFileMtlImporter {
|
||||
public:
|
||||
static const size_t BUFFERSIZE = 2048;
|
||||
typedef std::vector<char> DataArray;
|
||||
|
@ -70,8 +67,8 @@ public:
|
|||
|
||||
public:
|
||||
//! \brief Default constructor
|
||||
ObjFileMtlImporter( std::vector<char> &buffer, const std::string &strAbsPath,
|
||||
ObjFile::Model *pModel );
|
||||
ObjFileMtlImporter(std::vector<char> &buffer, const std::string &strAbsPath,
|
||||
ObjFile::Model *pModel);
|
||||
|
||||
//! \brief DEstructor
|
||||
~ObjFileMtlImporter();
|
||||
|
@ -80,15 +77,15 @@ private:
|
|||
/// Copy constructor, empty.
|
||||
ObjFileMtlImporter(const ObjFileMtlImporter &rOther);
|
||||
/// \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
|
||||
void load();
|
||||
/// Get color data.
|
||||
void getColorRGBA( aiColor3D *pColor);
|
||||
void getColorRGBA(aiColor3D *pColor);
|
||||
/// Get illumination model from loaded data
|
||||
void getIlluminationModel( int &illum_model );
|
||||
void getIlluminationModel(int &illum_model);
|
||||
/// Gets a float value from data.
|
||||
void getFloatValue( ai_real &value );
|
||||
void getFloatValue(ai_real &value);
|
||||
/// Creates a new material from loaded data.
|
||||
void createMaterial();
|
||||
/// Get texture name from loaded data.
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
|
|||
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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
|
||||
#define OBJ_FILEPARSER_H_INC
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <assimp/IOStreamBuffer.h>
|
||||
#include <assimp/mesh.h>
|
||||
#include <assimp/vector2.h>
|
||||
#include <assimp/vector3.h>
|
||||
#include <assimp/mesh.h>
|
||||
#include <assimp/IOStreamBuffer.h>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Assimp {
|
||||
|
||||
namespace ObjFile {
|
||||
struct Model;
|
||||
struct Object;
|
||||
struct Material;
|
||||
struct Point3;
|
||||
struct Point2;
|
||||
}
|
||||
struct Model;
|
||||
struct Object;
|
||||
struct Material;
|
||||
struct Point3;
|
||||
struct Point2;
|
||||
} // namespace ObjFile
|
||||
|
||||
class ObjFileImporter;
|
||||
class IOSystem;
|
||||
|
@ -78,31 +77,31 @@ public:
|
|||
/// @brief The default constructor.
|
||||
ObjFileParser();
|
||||
/// @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
|
||||
~ObjFileParser();
|
||||
/// @brief If you want to load in-core data.
|
||||
void setBuffer( std::vector<char> &buffer );
|
||||
void setBuffer(std::vector<char> &buffer);
|
||||
/// @brief Model getter.
|
||||
ObjFile::Model *GetModel() const;
|
||||
|
||||
protected:
|
||||
/// 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.
|
||||
void copyNextWord(char *pBuffer, size_t length);
|
||||
/// 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.
|
||||
size_t getNumComponentsInDataDefinition();
|
||||
/// Stores the vector
|
||||
size_t getTexCoordVector( std::vector<aiVector3D> &point3d_array );
|
||||
size_t getTexCoordVector(std::vector<aiVector3D> &point3d_array);
|
||||
/// 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
|
||||
void getHomogeneousVector3( std::vector<aiVector3D> &point3d_array );
|
||||
void getHomogeneousVector3(std::vector<aiVector3D> &point3d_array);
|
||||
/// 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.
|
||||
void getVector2(std::vector<aiVector2D> &point2d_array);
|
||||
/// Stores the following face.
|
||||
|
@ -122,23 +121,23 @@ protected:
|
|||
/// Gets the group number and resolution from file.
|
||||
void getGroupNumberAndResolution();
|
||||
/// 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
|
||||
void getObjectName();
|
||||
/// Creates a new object.
|
||||
void createObject( const std::string &strObjectName );
|
||||
void createObject(const std::string &strObjectName);
|
||||
/// 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.
|
||||
bool needsNewMesh( const std::string &rMaterialName );
|
||||
bool needsNewMesh(const std::string &rMaterialName);
|
||||
/// Error report in token
|
||||
void reportErrorTokenInFace();
|
||||
|
||||
private:
|
||||
// Copy and assignment constructor should be private
|
||||
// because the class contains pointer to allocated memory
|
||||
ObjFileParser(const ObjFileParser& rhs);
|
||||
ObjFileParser& operator=(const ObjFileParser& rhs);
|
||||
ObjFileParser(const ObjFileParser &rhs);
|
||||
ObjFileParser &operator=(const ObjFileParser &rhs);
|
||||
|
||||
/// Default material name
|
||||
static const std::string DEFAULT_MATERIAL;
|
||||
|
@ -155,11 +154,11 @@ private:
|
|||
/// Pointer to IO system instance.
|
||||
IOSystem *m_pIO;
|
||||
//! 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
|
||||
const std::string m_originalObjFileName;
|
||||
};
|
||||
|
||||
} // Namespace Assimp
|
||||
} // Namespace Assimp
|
||||
|
||||
#endif
|
||||
|
|
|
@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
|
|||
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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
|
||||
#define OBJ_TOOLS_H_INC
|
||||
|
||||
#include <assimp/fast_atof.h>
|
||||
#include <assimp/ParsingUtils.h>
|
||||
#include <assimp/fast_atof.h>
|
||||
#include <vector>
|
||||
|
||||
namespace Assimp {
|
||||
|
@ -57,17 +56,14 @@ namespace Assimp {
|
|||
* @param end Iterator with end of buffer.
|
||||
* @return true, if the end of the buffer is reached.
|
||||
*/
|
||||
template<class char_t>
|
||||
inline bool isEndOfBuffer( char_t it, char_t end ) {
|
||||
if ( it == end )
|
||||
{
|
||||
template <class char_t>
|
||||
inline bool isEndOfBuffer(char_t it, char_t end) {
|
||||
if (it == end) {
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
--end;
|
||||
}
|
||||
return ( it == end );
|
||||
return (it == end);
|
||||
}
|
||||
|
||||
/** @brief Returns next word separated by a space
|
||||
|
@ -75,14 +71,12 @@ inline bool isEndOfBuffer( char_t it, char_t end ) {
|
|||
* @param pEnd Pointer to end of buffer
|
||||
* @return Pointer to next space
|
||||
*/
|
||||
template<class Char_T>
|
||||
inline Char_T getNextWord( Char_T pBuffer, Char_T pEnd )
|
||||
{
|
||||
while ( !isEndOfBuffer( pBuffer, pEnd ) )
|
||||
{
|
||||
if ( !IsSpaceOrNewLine( *pBuffer ) || IsLineEnd( *pBuffer ) ) {
|
||||
template <class Char_T>
|
||||
inline Char_T getNextWord(Char_T pBuffer, Char_T pEnd) {
|
||||
while (!isEndOfBuffer(pBuffer, pEnd)) {
|
||||
if (!IsSpaceOrNewLine(*pBuffer) || IsLineEnd(*pBuffer)) {
|
||||
//if ( *pBuffer != '\\' )
|
||||
break;
|
||||
break;
|
||||
}
|
||||
pBuffer++;
|
||||
}
|
||||
|
@ -94,16 +88,14 @@ inline Char_T getNextWord( Char_T pBuffer, Char_T pEnd )
|
|||
* @param pEnd Pointer to end of buffer
|
||||
* @return Pointer to next token
|
||||
*/
|
||||
template<class Char_T>
|
||||
inline Char_T getNextToken( Char_T pBuffer, Char_T pEnd )
|
||||
{
|
||||
while ( !isEndOfBuffer( pBuffer, pEnd ) )
|
||||
{
|
||||
if( IsSpaceOrNewLine( *pBuffer ) )
|
||||
template <class Char_T>
|
||||
inline Char_T getNextToken(Char_T pBuffer, Char_T pEnd) {
|
||||
while (!isEndOfBuffer(pBuffer, pEnd)) {
|
||||
if (IsSpaceOrNewLine(*pBuffer))
|
||||
break;
|
||||
pBuffer++;
|
||||
}
|
||||
return getNextWord( pBuffer, pEnd );
|
||||
return getNextWord(pBuffer, pEnd);
|
||||
}
|
||||
|
||||
/** @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
|
||||
* @return Current-iterator with new position
|
||||
*/
|
||||
template<class char_t>
|
||||
inline char_t skipLine( char_t it, char_t end, unsigned int &uiLine ) {
|
||||
while( !isEndOfBuffer( it, end ) && !IsLineEnd( *it ) ) {
|
||||
template <class char_t>
|
||||
inline char_t skipLine(char_t it, char_t end, unsigned int &uiLine) {
|
||||
while (!isEndOfBuffer(it, end) && !IsLineEnd(*it)) {
|
||||
++it;
|
||||
}
|
||||
|
||||
if ( it != end ) {
|
||||
if (it != end) {
|
||||
++it;
|
||||
++uiLine;
|
||||
}
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
@ -137,20 +129,19 @@ inline char_t skipLine( char_t it, char_t end, unsigned int &uiLine ) {
|
|||
* @param name Separated name
|
||||
* @return Current-iterator with new position
|
||||
*/
|
||||
template<class char_t>
|
||||
inline char_t getName( char_t it, char_t end, std::string &name )
|
||||
{
|
||||
template <class char_t>
|
||||
inline char_t getName(char_t it, char_t end, std::string &name) {
|
||||
name = "";
|
||||
if( isEndOfBuffer( it, end ) ) {
|
||||
if (isEndOfBuffer(it, end)) {
|
||||
return end;
|
||||
}
|
||||
|
||||
char *pStart = &( *it );
|
||||
while( !isEndOfBuffer( it, end ) && !IsLineEnd( *it )) {
|
||||
char *pStart = &(*it);
|
||||
while (!isEndOfBuffer(it, end) && !IsLineEnd(*it)) {
|
||||
++it;
|
||||
}
|
||||
|
||||
while(IsSpace( *it ) ) {
|
||||
while (IsSpace(*it)) {
|
||||
--it;
|
||||
}
|
||||
// Get name
|
||||
|
@ -158,8 +149,8 @@ inline char_t getName( char_t it, char_t end, std::string &name )
|
|||
while (&(*it) < pStart) {
|
||||
++it;
|
||||
}
|
||||
std::string strName( pStart, &(*it) );
|
||||
if ( strName.empty() )
|
||||
std::string strName(pStart, &(*it));
|
||||
if (strName.empty())
|
||||
return it;
|
||||
else
|
||||
name = strName;
|
||||
|
@ -174,22 +165,19 @@ inline char_t getName( char_t it, char_t end, std::string &name )
|
|||
* @param name Separated name
|
||||
* @return Current-iterator with new position
|
||||
*/
|
||||
template<class char_t>
|
||||
inline char_t getNameNoSpace( char_t it, char_t end, std::string &name )
|
||||
{
|
||||
template <class char_t>
|
||||
inline char_t getNameNoSpace(char_t it, char_t end, std::string &name) {
|
||||
name = "";
|
||||
if( isEndOfBuffer( it, end ) ) {
|
||||
if (isEndOfBuffer(it, end)) {
|
||||
return end;
|
||||
}
|
||||
|
||||
char *pStart = &( *it );
|
||||
while( !isEndOfBuffer( it, end ) && !IsLineEnd( *it )
|
||||
&& !IsSpaceOrNewLine( *it ) ) {
|
||||
char *pStart = &(*it);
|
||||
while (!isEndOfBuffer(it, end) && !IsLineEnd(*it) && !IsSpaceOrNewLine(*it)) {
|
||||
++it;
|
||||
}
|
||||
|
||||
while( isEndOfBuffer( it, end ) || IsLineEnd( *it )
|
||||
|| IsSpaceOrNewLine( *it ) ) {
|
||||
while (isEndOfBuffer(it, end) || IsLineEnd(*it) || IsSpaceOrNewLine(*it)) {
|
||||
--it;
|
||||
}
|
||||
++it;
|
||||
|
@ -199,8 +187,8 @@ inline char_t getNameNoSpace( char_t it, char_t end, std::string &name )
|
|||
while (&(*it) < pStart) {
|
||||
++it;
|
||||
}
|
||||
std::string strName( pStart, &(*it) );
|
||||
if ( strName.empty() )
|
||||
std::string strName(pStart, &(*it));
|
||||
if (strName.empty())
|
||||
return it;
|
||||
else
|
||||
name = strName;
|
||||
|
@ -215,20 +203,18 @@ inline char_t getNameNoSpace( char_t it, char_t end, std::string &name )
|
|||
* @param length Buffer length
|
||||
* @return Current-iterator with new position
|
||||
*/
|
||||
template<class char_t>
|
||||
inline char_t CopyNextWord( char_t it, char_t end, char *pBuffer, size_t length )
|
||||
{
|
||||
template <class char_t>
|
||||
inline char_t CopyNextWord(char_t it, char_t end, char *pBuffer, size_t length) {
|
||||
size_t index = 0;
|
||||
it = getNextWord<char_t>( it, end );
|
||||
while( !IsSpaceOrNewLine( *it ) && !isEndOfBuffer( it, end ) )
|
||||
{
|
||||
pBuffer[index] = *it ;
|
||||
it = getNextWord<char_t>(it, end);
|
||||
while (!IsSpaceOrNewLine(*it) && !isEndOfBuffer(it, end)) {
|
||||
pBuffer[index] = *it;
|
||||
index++;
|
||||
if (index == length-1)
|
||||
if (index == length - 1)
|
||||
break;
|
||||
++it;
|
||||
}
|
||||
pBuffer[ index ] = '\0';
|
||||
pBuffer[index] = '\0';
|
||||
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.
|
||||
* @return Current-iterator with new position
|
||||
*/
|
||||
template<class char_t>
|
||||
inline char_t getFloat( char_t it, char_t end, ai_real &value )
|
||||
{
|
||||
template <class char_t>
|
||||
inline char_t getFloat(char_t it, char_t end, ai_real &value) {
|
||||
static const size_t BUFFERSIZE = 1024;
|
||||
char buffer[ BUFFERSIZE ];
|
||||
it = CopyNextWord<char_t>( it, end, buffer, BUFFERSIZE );
|
||||
value = (ai_real) fast_atof( buffer );
|
||||
char buffer[BUFFERSIZE];
|
||||
it = CopyNextWord<char_t>(it, end, buffer, BUFFERSIZE);
|
||||
value = (ai_real)fast_atof(buffer);
|
||||
|
||||
return it;
|
||||
}
|
||||
|
@ -255,46 +240,45 @@ inline char_t getFloat( char_t it, char_t end, ai_real &value )
|
|||
* @param delimiters Delimiter for tokenize.
|
||||
* @return Number of found token.
|
||||
*/
|
||||
template<class string_type>
|
||||
unsigned int tokenize( const string_type& str, std::vector<string_type>& tokens,
|
||||
const string_type& delimiters )
|
||||
{
|
||||
template <class string_type>
|
||||
unsigned int tokenize(const string_type &str, std::vector<string_type> &tokens,
|
||||
const string_type &delimiters) {
|
||||
// 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".
|
||||
typename string_type::size_type pos = str.find_first_of( delimiters, lastPos );
|
||||
while ( string_type::npos != pos || string_type::npos != lastPos )
|
||||
{
|
||||
typename string_type::size_type pos = str.find_first_of(delimiters, lastPos);
|
||||
while (string_type::npos != pos || string_type::npos != lastPos) {
|
||||
// Found a token, add it to the vector.
|
||||
string_type tmp = str.substr(lastPos, pos - lastPos);
|
||||
if ( !tmp.empty() && ' ' != tmp[ 0 ] )
|
||||
tokens.push_back( tmp );
|
||||
if (!tmp.empty() && ' ' != tmp[0])
|
||||
tokens.push_back(tmp);
|
||||
|
||||
// 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"
|
||||
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>
|
||||
string_type trim_whitespaces(string_type str)
|
||||
{
|
||||
while (!str.empty() && IsSpace(str[0])) str.erase(0);
|
||||
while (!str.empty() && IsSpace(str[str.length() - 1])) str.erase(str.length() - 1);
|
||||
string_type trim_whitespaces(string_type str) {
|
||||
while (!str.empty() && IsSpace(str[0]))
|
||||
str.erase(0);
|
||||
while (!str.empty() && IsSpace(str[str.length() - 1]))
|
||||
str.erase(str.length() - 1);
|
||||
return str;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool hasLineEnd( T it, T end ) {
|
||||
bool hasLineEnd( false );
|
||||
while ( !isEndOfBuffer( it, end ) ) {
|
||||
template <class T>
|
||||
bool hasLineEnd(T it, T end) {
|
||||
bool hasLineEnd(false);
|
||||
while (!isEndOfBuffer(it, end)) {
|
||||
it++;
|
||||
if ( IsLineEnd( it ) ) {
|
||||
if (IsLineEnd(it)) {
|
||||
hasLineEnd = true;
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue