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
|
||||
}
|
||||
|
||||
|
@ -110,8 +105,8 @@ struct Object {
|
|||
std::vector<unsigned int> m_Meshes;
|
||||
|
||||
//! \brief Default constructor
|
||||
Object()
|
||||
: m_strObjName("") {
|
||||
Object() :
|
||||
m_strObjName("") {
|
||||
// empty
|
||||
}
|
||||
|
||||
|
@ -184,13 +179,8 @@ 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;
|
||||
|
@ -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) {
|
||||
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)
|
||||
{
|
||||
it != m_Faces.end(); ++it) {
|
||||
delete *it;
|
||||
}
|
||||
}
|
||||
|
@ -299,8 +284,7 @@ struct Model {
|
|||
m_pGroupFaceIDs(NULL),
|
||||
m_strActiveGroup(""),
|
||||
m_TextureCoordDim(0),
|
||||
m_pCurrentMesh(NULL)
|
||||
{
|
||||
m_pCurrentMesh(NULL) {
|
||||
// empty
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
@ -255,8 +251,7 @@ 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 )
|
||||
{
|
||||
std::vector<aiMesh *> &MeshArray) {
|
||||
ai_assert(NULL != pModel);
|
||||
if (NULL == pObject) {
|
||||
return NULL;
|
||||
|
@ -334,8 +329,7 @@ aiMesh *ObjFileImporter::createTopology( const ObjFile::Model* pModel, const Obj
|
|||
pMesh->mName.Set(pObjMesh->m_name);
|
||||
}
|
||||
|
||||
for (size_t index = 0; index < pObjMesh->m_Faces.size(); index++)
|
||||
{
|
||||
for (size_t index = 0; index < pObjMesh->m_Faces.size(); index++) {
|
||||
ObjFile::Face *const inp = pObjMesh->m_Faces[index];
|
||||
ai_assert(NULL != inp);
|
||||
|
||||
|
@ -374,8 +368,7 @@ aiMesh *ObjFileImporter::createTopology( const ObjFile::Model* pModel, const Obj
|
|||
f.mIndices = new unsigned int[2];
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else if (inp->m_PrimitiveType == aiPrimitiveType_POINT) {
|
||||
} else if (inp->m_PrimitiveType == aiPrimitiveType_POINT) {
|
||||
for (size_t i = 0; i < inp->m_vertices.size(); ++i) {
|
||||
aiFace &f = pMesh->mFaces[outIndex++];
|
||||
uiIdxCount += f.mNumIndices = 1;
|
||||
|
@ -437,8 +430,7 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel,
|
|||
pMesh->mColors[0] = new aiColor4D[pMesh->mNumVertices];
|
||||
|
||||
// Allocate buffer for texture coordinates
|
||||
if ( !pModel->m_TextureCoord.empty() && pObjMesh->m_uiUVCoordinates[0] )
|
||||
{
|
||||
if (!pModel->m_TextureCoord.empty() && pObjMesh->m_uiUVCoordinates[0]) {
|
||||
pMesh->mNumUVComponents[0] = pModel->m_TextureCoordDim;
|
||||
pMesh->mTextureCoords[0] = new aiVector3D[pMesh->mNumVertices];
|
||||
}
|
||||
|
@ -463,34 +455,26 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel,
|
|||
// 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 (normal >= pModel->m_Normals.size()) {
|
||||
normalsok = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
pMesh->mNormals[newIndex] = pModel->m_Normals[normal];
|
||||
}
|
||||
}
|
||||
|
||||
// Copy all vertex colors
|
||||
if ( !pModel->m_VertexColors.empty())
|
||||
{
|
||||
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())
|
||||
{
|
||||
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
|
||||
{
|
||||
} else {
|
||||
const aiVector3D &coord3d = pModel->m_TextureCoord[tex];
|
||||
pMesh->mTextureCoords[0][newIndex] = aiVector3D(coord3d.x, coord3d.y, coord3d.z);
|
||||
}
|
||||
|
@ -530,22 +514,19 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel,
|
|||
|
||||
pDestFace[-1].mIndices[1] = newIndex;
|
||||
}
|
||||
}
|
||||
else if (last) {
|
||||
} else if (last) {
|
||||
outIndex++;
|
||||
}
|
||||
++newIndex;
|
||||
}
|
||||
}
|
||||
|
||||
if (!normalsok)
|
||||
{
|
||||
if (!normalsok) {
|
||||
delete[] pMesh->mNormals;
|
||||
pMesh->mNormals = nullptr;
|
||||
}
|
||||
|
||||
if (!uvok)
|
||||
{
|
||||
if (!uvok) {
|
||||
delete[] pMesh->mTextureCoords[0];
|
||||
pMesh->mTextureCoords[0] = nullptr;
|
||||
}
|
||||
|
@ -553,17 +534,14 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel,
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// 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())
|
||||
return;
|
||||
|
||||
iNumMeshes += static_cast<unsigned int>(rObjects.size());
|
||||
for (auto object: rObjects)
|
||||
{
|
||||
if (!object->m_SubObjects.empty())
|
||||
{
|
||||
for (auto object : rObjects) {
|
||||
if (!object->m_SubObjects.empty()) {
|
||||
countObjects(object->m_SubObjects, iNumMeshes);
|
||||
}
|
||||
}
|
||||
|
@ -595,8 +573,7 @@ void ObjFileImporter::createMaterials(const ObjFile::Model* pModel, aiScene* pSc
|
|||
}
|
||||
|
||||
pScene->mMaterials = new aiMaterial *[numMaterials];
|
||||
for ( unsigned int matIndex = 0; matIndex < numMaterials; matIndex++ )
|
||||
{
|
||||
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]);
|
||||
|
@ -611,8 +588,7 @@ void ObjFileImporter::createMaterials(const ObjFile::Model* pModel, aiScene* pSc
|
|||
|
||||
// convert illumination model
|
||||
int sm = 0;
|
||||
switch (pCurrentMaterial->illumination_model)
|
||||
{
|
||||
switch (pCurrentMaterial->illumination_model) {
|
||||
case 0:
|
||||
sm = aiShadingMode_NoShading;
|
||||
break;
|
||||
|
@ -644,71 +620,58 @@ void ObjFileImporter::createMaterials(const ObjFile::Model* pModel, aiScene* pSc
|
|||
// Adding textures
|
||||
const int uvwIndex = 0;
|
||||
|
||||
if ( 0 != pCurrentMaterial->texture.length )
|
||||
{
|
||||
if (0 != pCurrentMaterial->texture.length) {
|
||||
mat->AddProperty(&pCurrentMaterial->texture, AI_MATKEY_TEXTURE_DIFFUSE(0));
|
||||
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_DIFFUSE(0));
|
||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureDiffuseType])
|
||||
{
|
||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureDiffuseType]) {
|
||||
addTextureMappingModeProperty(mat, aiTextureType_DIFFUSE);
|
||||
}
|
||||
}
|
||||
|
||||
if ( 0 != pCurrentMaterial->textureAmbient.length )
|
||||
{
|
||||
if (0 != pCurrentMaterial->textureAmbient.length) {
|
||||
mat->AddProperty(&pCurrentMaterial->textureAmbient, AI_MATKEY_TEXTURE_AMBIENT(0));
|
||||
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_AMBIENT(0));
|
||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureAmbientType])
|
||||
{
|
||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureAmbientType]) {
|
||||
addTextureMappingModeProperty(mat, aiTextureType_AMBIENT);
|
||||
}
|
||||
}
|
||||
|
||||
if ( 0 != pCurrentMaterial->textureEmissive.length )
|
||||
{
|
||||
if (0 != pCurrentMaterial->textureEmissive.length) {
|
||||
mat->AddProperty(&pCurrentMaterial->textureEmissive, AI_MATKEY_TEXTURE_EMISSIVE(0));
|
||||
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_EMISSIVE(0));
|
||||
}
|
||||
|
||||
if ( 0 != pCurrentMaterial->textureSpecular.length )
|
||||
{
|
||||
if (0 != pCurrentMaterial->textureSpecular.length) {
|
||||
mat->AddProperty(&pCurrentMaterial->textureSpecular, AI_MATKEY_TEXTURE_SPECULAR(0));
|
||||
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_SPECULAR(0));
|
||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureSpecularType])
|
||||
{
|
||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureSpecularType]) {
|
||||
addTextureMappingModeProperty(mat, aiTextureType_SPECULAR);
|
||||
}
|
||||
}
|
||||
|
||||
if ( 0 != pCurrentMaterial->textureBump.length )
|
||||
{
|
||||
if (0 != pCurrentMaterial->textureBump.length) {
|
||||
mat->AddProperty(&pCurrentMaterial->textureBump, AI_MATKEY_TEXTURE_HEIGHT(0));
|
||||
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_HEIGHT(0));
|
||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureBumpType])
|
||||
{
|
||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureBumpType]) {
|
||||
addTextureMappingModeProperty(mat, aiTextureType_HEIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
if ( 0 != pCurrentMaterial->textureNormal.length )
|
||||
{
|
||||
if (0 != pCurrentMaterial->textureNormal.length) {
|
||||
mat->AddProperty(&pCurrentMaterial->textureNormal, AI_MATKEY_TEXTURE_NORMALS(0));
|
||||
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_NORMALS(0));
|
||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureNormalType])
|
||||
{
|
||||
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;
|
||||
|
||||
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));
|
||||
|
||||
|
@ -717,32 +680,26 @@ void ObjFileImporter::createMaterials(const ObjFile::Model* pModel, aiScene* pSc
|
|||
}
|
||||
}
|
||||
|
||||
if ( 0 != pCurrentMaterial->textureDisp.length )
|
||||
{
|
||||
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 (pCurrentMaterial->clamp[ObjFile::Material::TextureDispType]) {
|
||||
addTextureMappingModeProperty(mat, aiTextureType_DISPLACEMENT);
|
||||
}
|
||||
}
|
||||
|
||||
if ( 0 != pCurrentMaterial->textureOpacity.length )
|
||||
{
|
||||
if (0 != pCurrentMaterial->textureOpacity.length) {
|
||||
mat->AddProperty(&pCurrentMaterial->textureOpacity, AI_MATKEY_TEXTURE_OPACITY(0));
|
||||
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_OPACITY(0));
|
||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureOpacityType])
|
||||
{
|
||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureOpacityType]) {
|
||||
addTextureMappingModeProperty(mat, aiTextureType_OPACITY);
|
||||
}
|
||||
}
|
||||
|
||||
if ( 0 != pCurrentMaterial->textureSpecularity.length )
|
||||
{
|
||||
if (0 != pCurrentMaterial->textureSpecularity.length) {
|
||||
mat->AddProperty(&pCurrentMaterial->textureSpecularity, AI_MATKEY_TEXTURE_SHININESS(0));
|
||||
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_SHININESS(0));
|
||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureSpecularityType])
|
||||
{
|
||||
if (pCurrentMaterial->clamp[ObjFile::Material::TextureSpecularityType]) {
|
||||
addTextureMappingModeProperty(mat, aiTextureType_SHININESS);
|
||||
}
|
||||
}
|
||||
|
@ -758,8 +715,7 @@ void ObjFileImporter::createMaterials(const ObjFile::Model* pModel, aiScene* pSc
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// 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);
|
||||
|
|
|
@ -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,
|
||||
|
@ -54,7 +53,7 @@ namespace Assimp {
|
|||
namespace ObjFile {
|
||||
struct Object;
|
||||
struct Model;
|
||||
}
|
||||
} // namespace ObjFile
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
/// \class ObjFileImporter
|
||||
|
|
|
@ -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,16 +39,15 @@ 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 {
|
||||
|
@ -92,11 +89,9 @@ ObjFileMtlImporter::ObjFileMtlImporter( std::vector<char> &buffer,
|
|||
m_DataIt(buffer.begin()),
|
||||
m_DataItEnd(buffer.end()),
|
||||
m_pModel(pModel),
|
||||
m_uiLine( 0 )
|
||||
{
|
||||
m_uiLine(0) {
|
||||
ai_assert(NULL != m_pModel);
|
||||
if ( NULL == m_pModel->m_pDefaultMaterial )
|
||||
{
|
||||
if (NULL == m_pModel->m_pDefaultMaterial) {
|
||||
m_pModel->m_pDefaultMaterial = new ObjFile::Material;
|
||||
m_pModel->m_pDefaultMaterial->MaterialName.Set("default");
|
||||
}
|
||||
|
@ -105,65 +100,51 @@ ObjFileMtlImporter::ObjFileMtlImporter( std::vector<char> &buffer,
|
|||
|
||||
// -------------------------------------------------------------------
|
||||
// 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()
|
||||
{
|
||||
void ObjFileMtlImporter::load() {
|
||||
if (m_DataIt == m_DataItEnd)
|
||||
return;
|
||||
|
||||
while ( m_DataIt != m_DataItEnd )
|
||||
{
|
||||
switch (*m_DataIt)
|
||||
{
|
||||
while (m_DataIt != m_DataItEnd) {
|
||||
switch (*m_DataIt) {
|
||||
case 'k':
|
||||
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
|
||||
} else if (*m_DataIt == 'd') // Diffuse color
|
||||
{
|
||||
++m_DataIt;
|
||||
getColorRGBA(&m_pModel->m_pCurrentMaterial->diffuse);
|
||||
}
|
||||
else if (*m_DataIt == 's')
|
||||
{
|
||||
} else if (*m_DataIt == 's') {
|
||||
++m_DataIt;
|
||||
getColorRGBA(&m_pModel->m_pCurrentMaterial->specular);
|
||||
}
|
||||
else if (*m_DataIt == 'e')
|
||||
{
|
||||
} else if (*m_DataIt == 'e') {
|
||||
++m_DataIt;
|
||||
getColorRGBA(&m_pModel->m_pCurrentMaterial->emissive);
|
||||
}
|
||||
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||
}
|
||||
break;
|
||||
case 'T':
|
||||
{
|
||||
} break;
|
||||
case 'T': {
|
||||
++m_DataIt;
|
||||
if (*m_DataIt == 'f') // Material transmission
|
||||
{
|
||||
|
@ -171,10 +152,8 @@ void ObjFileMtlImporter::load()
|
|||
getColorRGBA(&m_pModel->m_pCurrentMaterial->transparent);
|
||||
}
|
||||
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||
}
|
||||
break;
|
||||
case 'd':
|
||||
{
|
||||
} break;
|
||||
case 'd': {
|
||||
if (*(m_DataIt + 1) == 'i' && *(m_DataIt + 2) == 's' && *(m_DataIt + 3) == 'p') {
|
||||
// A displacement map
|
||||
getTexture();
|
||||
|
@ -184,15 +163,12 @@ void ObjFileMtlImporter::load()
|
|||
getFloatValue(m_pModel->m_pCurrentMaterial->alpha);
|
||||
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||
}
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case 'N':
|
||||
case 'n':
|
||||
{
|
||||
case 'n': {
|
||||
++m_DataIt;
|
||||
switch(*m_DataIt)
|
||||
{
|
||||
switch (*m_DataIt) {
|
||||
case 's': // Specular exponent
|
||||
++m_DataIt;
|
||||
getFloatValue(m_pModel->m_pCurrentMaterial->shineness);
|
||||
|
@ -206,8 +182,7 @@ void ObjFileMtlImporter::load()
|
|||
break;
|
||||
}
|
||||
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case 'm': // Texture
|
||||
case 'b': // quick'n'dirty - for 'bump' sections
|
||||
|
@ -215,30 +190,25 @@ void ObjFileMtlImporter::load()
|
|||
{
|
||||
getTexture();
|
||||
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
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;
|
||||
} break;
|
||||
|
||||
default:
|
||||
{
|
||||
default: {
|
||||
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Loads a color definition
|
||||
void ObjFileMtlImporter::getColorRGBA( aiColor3D *pColor )
|
||||
{
|
||||
void ObjFileMtlImporter::getColorRGBA(aiColor3D *pColor) {
|
||||
ai_assert(NULL != pColor);
|
||||
|
||||
ai_real r(0.0), g(0.0), b(0.0);
|
||||
|
@ -256,24 +226,21 @@ void ObjFileMtlImporter::getColorRGBA( aiColor3D *pColor )
|
|||
|
||||
// -------------------------------------------------------------------
|
||||
// Loads the kind of illumination model.
|
||||
void ObjFileMtlImporter::getIlluminationModel( int &illum_model )
|
||||
{
|
||||
void ObjFileMtlImporter::getIlluminationModel(int &illum_model) {
|
||||
m_DataIt = CopyNextWord<DataArrayIt>(m_DataIt, m_DataItEnd, m_buffer, BUFFERSIZE);
|
||||
illum_model = atoi(m_buffer);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Loads a single float value.
|
||||
void ObjFileMtlImporter::getFloatValue( ai_real &value )
|
||||
{
|
||||
void ObjFileMtlImporter::getFloatValue(ai_real &value) {
|
||||
m_DataIt = CopyNextWord<DataArrayIt>(m_DataIt, m_DataItEnd, m_buffer, BUFFERSIZE);
|
||||
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)) {
|
||||
line += *m_DataIt;
|
||||
|
@ -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 == '-')
|
||||
{
|
||||
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()) ) )
|
||||
{
|
||||
} 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 ) )
|
||||
{
|
||||
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;
|
||||
|
@ -53,15 +52,13 @@ namespace Assimp {
|
|||
namespace ObjFile {
|
||||
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;
|
||||
|
|
|
@ -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,
|
||||
|
@ -43,14 +41,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#ifndef ASSIMP_BUILD_NO_OBJ_IMPORTER
|
||||
|
||||
#include "ObjFileParser.h"
|
||||
#include "ObjFileData.h"
|
||||
#include "ObjFileMtlImporter.h"
|
||||
#include "ObjTools.h"
|
||||
#include "ObjFileData.h"
|
||||
#include <assimp/ParsingUtils.h>
|
||||
#include <assimp/BaseImporter.h>
|
||||
#include <assimp/DefaultIOSystem.h>
|
||||
#include <assimp/DefaultLogger.hpp>
|
||||
#include <assimp/ParsingUtils.h>
|
||||
#include <assimp/material.h>
|
||||
#include <assimp/DefaultLogger.hpp>
|
||||
#include <assimp/Importer.hpp>
|
||||
#include <cstdlib>
|
||||
|
||||
|
@ -58,14 +56,8 @@ namespace Assimp {
|
|||
|
||||
const std::string ObjFileParser::DEFAULT_MATERIAL = AI_DEFAULT_MATERIAL_NAME;
|
||||
|
||||
ObjFileParser::ObjFileParser()
|
||||
: m_DataIt()
|
||||
, m_DataItEnd()
|
||||
, m_pModel( nullptr )
|
||||
, m_uiLine( 0 )
|
||||
, m_pIO( nullptr )
|
||||
, m_progress( nullptr )
|
||||
, m_originalObjFileName() {
|
||||
ObjFileParser::ObjFileParser() :
|
||||
m_DataIt(), m_DataItEnd(), m_pModel(nullptr), m_uiLine(0), m_pIO(nullptr), m_progress(nullptr), m_originalObjFileName() {
|
||||
// empty
|
||||
}
|
||||
|
||||
|
@ -78,8 +70,7 @@ ObjFileParser::ObjFileParser( IOStreamBuffer<char> &streamBuffer, const std::str
|
|||
m_uiLine(0),
|
||||
m_pIO(io),
|
||||
m_progress(progress),
|
||||
m_originalObjFileName(originalObjFileName)
|
||||
{
|
||||
m_originalObjFileName(originalObjFileName) {
|
||||
std::fill_n(m_buffer, Buffersize, '\0');
|
||||
|
||||
// Create the model instance to store all the data
|
||||
|
@ -158,23 +149,18 @@ void ObjFileParser::parseFile( IOStreamBuffer<char> &streamBuffer ) {
|
|||
++m_DataIt;
|
||||
getVector3(m_pModel->m_Normals);
|
||||
}
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case 'p': // Parse a face, line or point statement
|
||||
case 'l':
|
||||
case 'f':
|
||||
{
|
||||
getFace(*m_DataIt == 'f' ? aiPrimitiveType_POLYGON : (*m_DataIt == 'l'
|
||||
? aiPrimitiveType_LINE : aiPrimitiveType_POINT));
|
||||
}
|
||||
break;
|
||||
case 'f': {
|
||||
getFace(*m_DataIt == 'f' ? aiPrimitiveType_POLYGON : (*m_DataIt == 'l' ? aiPrimitiveType_LINE : aiPrimitiveType_POINT));
|
||||
} break;
|
||||
|
||||
case '#': // Parse a comment
|
||||
{
|
||||
getComment();
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case 'u': // Parse a material desc. setter
|
||||
{
|
||||
|
@ -186,12 +172,10 @@ void ObjFileParser::parseFile( IOStreamBuffer<char> &streamBuffer ) {
|
|||
if (nextSpace != std::string::npos)
|
||||
name = name.substr(0, nextSpace);
|
||||
|
||||
if(name == "usemtl")
|
||||
{
|
||||
if (name == "usemtl") {
|
||||
getMaterialDesc();
|
||||
}
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case 'm': // Parse a material library or merging group ('mg')
|
||||
{
|
||||
|
@ -209,33 +193,27 @@ void ObjFileParser::parseFile( IOStreamBuffer<char> &streamBuffer ) {
|
|||
getMaterialLib();
|
||||
else
|
||||
goto pf_skip_line;
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case 'g': // Parse group name
|
||||
{
|
||||
getGroupName();
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case 's': // Parse group number
|
||||
{
|
||||
getGroupNumber();
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case 'o': // Parse object name
|
||||
{
|
||||
getObjectName();
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
default:
|
||||
{
|
||||
default: {
|
||||
pf_skip_line:
|
||||
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -494,7 +472,6 @@ void ObjFileParser::getFace( aiPrimitiveType type ) {
|
|||
delete face;
|
||||
throw DeadlyImportError("OBJ: Invalid face indice");
|
||||
}
|
||||
|
||||
}
|
||||
m_DataIt += iStep;
|
||||
}
|
||||
|
@ -688,16 +665,13 @@ void ObjFileParser::getNewMaterial() {
|
|||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
int ObjFileParser::getMaterialIndex( const std::string &strMaterialName )
|
||||
{
|
||||
int ObjFileParser::getMaterialIndex(const std::string &strMaterialName) {
|
||||
int mat_index = -1;
|
||||
if (strMaterialName.empty()) {
|
||||
return mat_index;
|
||||
}
|
||||
for (size_t index = 0; index < m_pModel->m_MaterialLib.size(); ++index)
|
||||
{
|
||||
if ( strMaterialName == m_pModel->m_MaterialLib[ index ])
|
||||
{
|
||||
for (size_t index = 0; index < m_pModel->m_MaterialLib.size(); ++index) {
|
||||
if (strMaterialName == m_pModel->m_MaterialLib[index]) {
|
||||
mat_index = (int)index;
|
||||
break;
|
||||
}
|
||||
|
@ -726,14 +700,11 @@ void ObjFileParser::getGroupName() {
|
|||
createObject(groupName);
|
||||
|
||||
// New group name, creating a new entry
|
||||
if (it == m_pModel->m_Groups.end())
|
||||
{
|
||||
if (it == m_pModel->m_Groups.end()) {
|
||||
std::vector<unsigned int> *pFaceIDArray = new std::vector<unsigned int>;
|
||||
m_pModel->m_Groups[groupName] = pFaceIDArray;
|
||||
m_pModel->m_pGroupFaceIDs = (pFaceIDArray);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
m_pModel->m_pGroupFaceIDs = (*it).second;
|
||||
}
|
||||
m_pModel->m_strActiveGroup = groupName;
|
||||
|
@ -743,8 +714,7 @@ void ObjFileParser::getGroupName() {
|
|||
|
||||
// -------------------------------------------------------------------
|
||||
// Not supported
|
||||
void ObjFileParser::getGroupNumber()
|
||||
{
|
||||
void ObjFileParser::getGroupNumber() {
|
||||
// Not used
|
||||
|
||||
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||
|
@ -752,8 +722,7 @@ void ObjFileParser::getGroupNumber()
|
|||
|
||||
// -------------------------------------------------------------------
|
||||
// Not supported
|
||||
void ObjFileParser::getGroupNumberAndResolution()
|
||||
{
|
||||
void ObjFileParser::getGroupNumberAndResolution() {
|
||||
// Not used
|
||||
|
||||
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||
|
@ -762,8 +731,7 @@ void ObjFileParser::getGroupNumberAndResolution()
|
|||
// -------------------------------------------------------------------
|
||||
// Stores values for a new object instance, name will be used to
|
||||
// identify it.
|
||||
void ObjFileParser::getObjectName()
|
||||
{
|
||||
void ObjFileParser::getObjectName() {
|
||||
m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
||||
if (m_DataIt == m_DataItEnd) {
|
||||
return;
|
||||
|
@ -774,18 +742,15 @@ void ObjFileParser::getObjectName()
|
|||
}
|
||||
|
||||
std::string strObjectName(pStart, &(*m_DataIt));
|
||||
if (!strObjectName.empty())
|
||||
{
|
||||
if (!strObjectName.empty()) {
|
||||
// Reset current object
|
||||
m_pModel->m_pCurrent = NULL;
|
||||
|
||||
// Search for actual object
|
||||
for (std::vector<ObjFile::Object *>::const_iterator it = m_pModel->m_Objects.begin();
|
||||
it != m_pModel->m_Objects.end();
|
||||
++it)
|
||||
{
|
||||
if ((*it)->m_strObjName == strObjectName)
|
||||
{
|
||||
++it) {
|
||||
if ((*it)->m_strObjName == strObjectName) {
|
||||
m_pModel->m_pCurrent = *it;
|
||||
break;
|
||||
}
|
||||
|
@ -800,8 +765,7 @@ void ObjFileParser::getObjectName()
|
|||
}
|
||||
// -------------------------------------------------------------------
|
||||
// Creates a new object instance
|
||||
void ObjFileParser::createObject(const std::string &objName)
|
||||
{
|
||||
void ObjFileParser::createObject(const std::string &objName) {
|
||||
ai_assert(NULL != m_pModel);
|
||||
|
||||
m_pModel->m_pCurrent = new ObjFile::Object;
|
||||
|
@ -810,8 +774,7 @@ void ObjFileParser::createObject(const std::string &objName)
|
|||
|
||||
createMesh(objName);
|
||||
|
||||
if( m_pModel->m_pCurrentMaterial )
|
||||
{
|
||||
if (m_pModel->m_pCurrentMaterial) {
|
||||
m_pModel->m_pCurrentMesh->m_uiMaterialIndex =
|
||||
getMaterialIndex(m_pModel->m_pCurrentMaterial->MaterialName.data);
|
||||
m_pModel->m_pCurrentMesh->m_pMaterial = m_pModel->m_pCurrentMaterial;
|
||||
|
@ -819,40 +782,32 @@ void ObjFileParser::createObject(const std::string &objName)
|
|||
}
|
||||
// -------------------------------------------------------------------
|
||||
// Creates a new mesh
|
||||
void ObjFileParser::createMesh( const std::string &meshName )
|
||||
{
|
||||
void ObjFileParser::createMesh(const std::string &meshName) {
|
||||
ai_assert(NULL != m_pModel);
|
||||
m_pModel->m_pCurrentMesh = new ObjFile::Mesh(meshName);
|
||||
m_pModel->m_Meshes.push_back(m_pModel->m_pCurrentMesh);
|
||||
unsigned int meshId = static_cast<unsigned int>(m_pModel->m_Meshes.size() - 1);
|
||||
if ( NULL != m_pModel->m_pCurrent )
|
||||
{
|
||||
if (NULL != m_pModel->m_pCurrent) {
|
||||
m_pModel->m_pCurrent->m_Meshes.push_back(meshId);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
ASSIMP_LOG_ERROR("OBJ: No object detected to attach a new mesh instance.");
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Returns true, if a new mesh must be created.
|
||||
bool ObjFileParser::needsNewMesh( const std::string &materialName )
|
||||
{
|
||||
bool ObjFileParser::needsNewMesh(const std::string &materialName) {
|
||||
// If no mesh data yet
|
||||
if (m_pModel->m_pCurrentMesh == nullptr)
|
||||
{
|
||||
if (m_pModel->m_pCurrentMesh == nullptr) {
|
||||
return true;
|
||||
}
|
||||
bool newMat = false;
|
||||
int matIdx = getMaterialIndex(materialName);
|
||||
int curMatIdx = m_pModel->m_pCurrentMesh->m_uiMaterialIndex;
|
||||
if ( curMatIdx != int(ObjFile::Mesh::NoMaterial)
|
||||
&& curMatIdx != matIdx
|
||||
if (curMatIdx != int(ObjFile::Mesh::NoMaterial) && curMatIdx != matIdx
|
||||
// no need create a new mesh if no faces in current
|
||||
// lets say 'usemtl' goes straight after 'g'
|
||||
&& !m_pModel->m_pCurrentMesh->m_Faces.empty() )
|
||||
{
|
||||
&& !m_pModel->m_pCurrentMesh->m_Faces.empty()) {
|
||||
// New material -> only one material per mesh, so we need to create a new
|
||||
// material
|
||||
newMat = true;
|
||||
|
@ -862,8 +817,7 @@ bool ObjFileParser::needsNewMesh( const std::string &materialName )
|
|||
|
||||
// -------------------------------------------------------------------
|
||||
// Shows an error in parsing process.
|
||||
void ObjFileParser::reportErrorTokenInFace()
|
||||
{
|
||||
void ObjFileParser::reportErrorTokenInFace() {
|
||||
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
|
||||
ASSIMP_LOG_ERROR("OBJ: Not supported token in face description detected");
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
|
|||
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
|
@ -42,14 +41,14 @@ 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 {
|
||||
|
||||
|
@ -59,7 +58,7 @@ namespace ObjFile {
|
|||
struct Material;
|
||||
struct Point3;
|
||||
struct Point2;
|
||||
}
|
||||
} // namespace ObjFile
|
||||
|
||||
class ObjFileImporter;
|
||||
class IOSystem;
|
||||
|
|
|
@ -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 {
|
||||
|
@ -59,12 +58,9 @@ namespace Assimp {
|
|||
*/
|
||||
template <class char_t>
|
||||
inline bool isEndOfBuffer(char_t it, char_t end) {
|
||||
if ( it == end )
|
||||
{
|
||||
if (it == end) {
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
--end;
|
||||
}
|
||||
return (it == end);
|
||||
|
@ -76,10 +72,8 @@ inline bool isEndOfBuffer( char_t it, char_t end ) {
|
|||
* @return Pointer to next space
|
||||
*/
|
||||
template <class Char_T>
|
||||
inline Char_T getNextWord( Char_T pBuffer, Char_T pEnd )
|
||||
{
|
||||
while ( !isEndOfBuffer( pBuffer, pEnd ) )
|
||||
{
|
||||
inline Char_T getNextWord(Char_T pBuffer, Char_T pEnd) {
|
||||
while (!isEndOfBuffer(pBuffer, pEnd)) {
|
||||
if (!IsSpaceOrNewLine(*pBuffer) || IsLineEnd(*pBuffer)) {
|
||||
//if ( *pBuffer != '\\' )
|
||||
break;
|
||||
|
@ -95,10 +89,8 @@ inline Char_T getNextWord( Char_T pBuffer, Char_T pEnd )
|
|||
* @return Pointer to next token
|
||||
*/
|
||||
template <class Char_T>
|
||||
inline Char_T getNextToken( Char_T pBuffer, Char_T pEnd )
|
||||
{
|
||||
while ( !isEndOfBuffer( pBuffer, pEnd ) )
|
||||
{
|
||||
inline Char_T getNextToken(Char_T pBuffer, Char_T pEnd) {
|
||||
while (!isEndOfBuffer(pBuffer, pEnd)) {
|
||||
if (IsSpaceOrNewLine(*pBuffer))
|
||||
break;
|
||||
pBuffer++;
|
||||
|
@ -138,8 +130,7 @@ inline char_t skipLine( char_t it, char_t end, unsigned int &uiLine ) {
|
|||
* @return Current-iterator with new position
|
||||
*/
|
||||
template <class char_t>
|
||||
inline char_t getName( char_t it, char_t end, std::string &name )
|
||||
{
|
||||
inline char_t getName(char_t it, char_t end, std::string &name) {
|
||||
name = "";
|
||||
if (isEndOfBuffer(it, end)) {
|
||||
return end;
|
||||
|
@ -175,21 +166,18 @@ inline char_t getName( char_t it, char_t end, std::string &name )
|
|||
* @return Current-iterator with new position
|
||||
*/
|
||||
template <class char_t>
|
||||
inline char_t getNameNoSpace( char_t it, char_t end, std::string &name )
|
||||
{
|
||||
inline char_t getNameNoSpace(char_t it, char_t end, std::string &name) {
|
||||
name = "";
|
||||
if (isEndOfBuffer(it, end)) {
|
||||
return end;
|
||||
}
|
||||
|
||||
char *pStart = &(*it);
|
||||
while( !isEndOfBuffer( it, end ) && !IsLineEnd( *it )
|
||||
&& !IsSpaceOrNewLine( *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;
|
||||
|
@ -216,12 +204,10 @@ inline char_t getNameNoSpace( char_t it, char_t end, std::string &name )
|
|||
* @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 )
|
||||
{
|
||||
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 ) )
|
||||
{
|
||||
while (!IsSpaceOrNewLine(*it) && !isEndOfBuffer(it, end)) {
|
||||
pBuffer[index] = *it;
|
||||
index++;
|
||||
if (index == length - 1)
|
||||
|
@ -239,8 +225,7 @@ inline char_t CopyNextWord( char_t it, char_t end, char *pBuffer, size_t length
|
|||
* @return Current-iterator with new position
|
||||
*/
|
||||
template <class char_t>
|
||||
inline char_t getFloat( char_t it, char_t end, ai_real &value )
|
||||
{
|
||||
inline char_t getFloat(char_t it, char_t end, ai_real &value) {
|
||||
static const size_t BUFFERSIZE = 1024;
|
||||
char buffer[BUFFERSIZE];
|
||||
it = CopyNextWord<char_t>(it, end, buffer, BUFFERSIZE);
|
||||
|
@ -257,15 +242,13 @@ inline char_t getFloat( char_t it, char_t end, ai_real &value )
|
|||
*/
|
||||
template <class string_type>
|
||||
unsigned int tokenize(const string_type &str, std::vector<string_type> &tokens,
|
||||
const string_type& delimiters )
|
||||
{
|
||||
const string_type &delimiters) {
|
||||
// Skip delimiters at beginning.
|
||||
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 )
|
||||
{
|
||||
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])
|
||||
|
@ -282,10 +265,11 @@ unsigned int tokenize( const string_type& str, std::vector<string_type>& tokens,
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue