Obj: apply clang format.

pull/3012/head
Kim Kulling 2020-03-15 10:21:08 +01:00
parent 0357333c81
commit 8b6f95ec30
8 changed files with 816 additions and 1009 deletions

View File

@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2020, assimp team Copyright (c) 2006-2020, assimp team
All rights reserved. All rights reserved.
Redistribution and use of this software in source and binary forms, Redistribution and use of this software in source and binary forms,
@ -44,10 +43,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef OBJ_FILEDATA_H_INC #ifndef OBJ_FILEDATA_H_INC
#define OBJ_FILEDATA_H_INC #define OBJ_FILEDATA_H_INC
#include <vector>
#include <map>
#include <assimp/types.h>
#include <assimp/mesh.h> #include <assimp/mesh.h>
#include <assimp/types.h>
#include <map>
#include <vector>
namespace Assimp { namespace Assimp {
namespace ObjFile { namespace ObjFile {
@ -75,12 +74,8 @@ struct Face {
Material *m_pMaterial; Material *m_pMaterial;
//! \brief Default constructor //! \brief Default constructor
Face( aiPrimitiveType pt = aiPrimitiveType_POLYGON) Face(aiPrimitiveType pt = aiPrimitiveType_POLYGON) :
: m_PrimitiveType( pt ) m_PrimitiveType(pt), m_vertices(), m_normals(), m_texturCoords(), m_pMaterial(0L) {
, m_vertices()
, m_normals()
, m_texturCoords()
, m_pMaterial( 0L ) {
// empty // empty
} }
@ -110,8 +105,8 @@ struct Object {
std::vector<unsigned int> m_Meshes; std::vector<unsigned int> m_Meshes;
//! \brief Default constructor //! \brief Default constructor
Object() Object() :
: m_strObjName("") { m_strObjName("") {
// empty // empty
} }
@ -184,13 +179,8 @@ struct Material {
aiColor3D transparent; aiColor3D transparent;
//! Constructor //! Constructor
Material() Material() :
: diffuse ( ai_real( 0.6 ), ai_real( 0.6 ), ai_real( 0.6 ) ) diffuse(ai_real(0.6), ai_real(0.6), ai_real(0.6)), alpha(ai_real(1.0)), shineness(ai_real(0.0)), illumination_model(1), ior(ai_real(1.0)), transparent(ai_real(1.0), ai_real(1.0), ai_real(1.0)) {
, alpha (ai_real( 1.0 ) )
, shineness ( ai_real( 0.0) )
, illumination_model (1)
, ior ( ai_real( 1.0 ) )
, transparent( ai_real( 1.0), ai_real (1.0), ai_real(1.0)) {
// empty // empty
for (size_t i = 0; i < TextureTypeCount; ++i) { for (size_t i = 0; i < TextureTypeCount; ++i) {
clamp[i] = false; clamp[i] = false;
@ -227,20 +217,15 @@ struct Mesh {
bool m_hasVertexColors; bool m_hasVertexColors;
/// Constructor /// Constructor
explicit Mesh( const std::string &name ) explicit Mesh(const std::string &name) :
: m_name( name ) m_name(name), m_pMaterial(NULL), m_uiNumIndices(0), m_uiMaterialIndex(NoMaterial), m_hasNormals(false) {
, m_pMaterial(NULL)
, m_uiNumIndices(0)
, m_uiMaterialIndex( NoMaterial )
, m_hasNormals(false) {
memset(m_uiUVCoordinates, 0, sizeof(unsigned int) * AI_MAX_NUMBER_OF_TEXTURECOORDS); memset(m_uiUVCoordinates, 0, sizeof(unsigned int) * AI_MAX_NUMBER_OF_TEXTURECOORDS);
} }
/// Destructor /// Destructor
~Mesh() { ~Mesh() {
for (std::vector<Face *>::iterator it = m_Faces.begin(); for (std::vector<Face *>::iterator it = m_Faces.begin();
it != m_Faces.end(); ++it) it != m_Faces.end(); ++it) {
{
delete *it; delete *it;
} }
} }
@ -299,8 +284,7 @@ struct Model {
m_pGroupFaceIDs(NULL), m_pGroupFaceIDs(NULL),
m_strActiveGroup(""), m_strActiveGroup(""),
m_TextureCoordDim(0), m_TextureCoordDim(0),
m_pCurrentMesh(NULL) m_pCurrentMesh(NULL) {
{
// empty // empty
} }

View File

@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2020, assimp team Copyright (c) 2006-2020, assimp team
All rights reserved. All rights reserved.
Redistribution and use of this software in source and binary forms, Redistribution and use of this software in source and binary forms,
@ -44,16 +42,16 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef ASSIMP_BUILD_NO_OBJ_IMPORTER #ifndef ASSIMP_BUILD_NO_OBJ_IMPORTER
#include "ObjFileImporter.h" #include "ObjFileImporter.h"
#include "ObjFileParser.h"
#include "ObjFileData.h" #include "ObjFileData.h"
#include <assimp/IOStreamBuffer.h> #include "ObjFileParser.h"
#include <memory>
#include <assimp/DefaultIOSystem.h> #include <assimp/DefaultIOSystem.h>
#include <assimp/Importer.hpp> #include <assimp/IOStreamBuffer.h>
#include <assimp/scene.h>
#include <assimp/ai_assert.h> #include <assimp/ai_assert.h>
#include <assimp/DefaultLogger.hpp>
#include <assimp/importerdesc.h> #include <assimp/importerdesc.h>
#include <assimp/scene.h>
#include <assimp/DefaultLogger.hpp>
#include <assimp/Importer.hpp>
#include <memory>
static const aiImporterDesc desc = { static const aiImporterDesc desc = {
"Wavefront Object Importer", "Wavefront Object Importer",
@ -76,10 +74,8 @@ using namespace std;
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Default constructor // Default constructor
ObjFileImporter::ObjFileImporter() ObjFileImporter::ObjFileImporter() :
: m_Buffer() m_Buffer(), m_pRootObject(nullptr), m_strAbsPath(std::string(1, DefaultIOSystem().getOsSeparator())) {}
, m_pRootObject( nullptr )
, m_strAbsPath( std::string(1, DefaultIOSystem().getOsSeparator()) ) {}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Destructor. // Destructor.
@ -255,8 +251,7 @@ void ObjFileImporter::CreateDataFromImport(const ObjFile::Model* pModel, aiScene
// Creates all nodes of the model // Creates all nodes of the model
aiNode *ObjFileImporter::createNodes(const ObjFile::Model *pModel, const ObjFile::Object *pObject, aiNode *ObjFileImporter::createNodes(const ObjFile::Model *pModel, const ObjFile::Object *pObject,
aiNode *pParent, aiScene *pScene, aiNode *pParent, aiScene *pScene,
std::vector<aiMesh*> &MeshArray ) std::vector<aiMesh *> &MeshArray) {
{
ai_assert(NULL != pModel); ai_assert(NULL != pModel);
if (NULL == pObject) { if (NULL == pObject) {
return NULL; return NULL;
@ -334,8 +329,7 @@ aiMesh *ObjFileImporter::createTopology( const ObjFile::Model* pModel, const Obj
pMesh->mName.Set(pObjMesh->m_name); pMesh->mName.Set(pObjMesh->m_name);
} }
for (size_t index = 0; index < pObjMesh->m_Faces.size(); index++) for (size_t index = 0; index < pObjMesh->m_Faces.size(); index++) {
{
ObjFile::Face *const inp = pObjMesh->m_Faces[index]; ObjFile::Face *const inp = pObjMesh->m_Faces[index];
ai_assert(NULL != inp); ai_assert(NULL != inp);
@ -374,8 +368,7 @@ aiMesh *ObjFileImporter::createTopology( const ObjFile::Model* pModel, const Obj
f.mIndices = new unsigned int[2]; f.mIndices = new unsigned int[2];
} }
continue; continue;
} } else if (inp->m_PrimitiveType == aiPrimitiveType_POINT) {
else if (inp->m_PrimitiveType == aiPrimitiveType_POINT) {
for (size_t i = 0; i < inp->m_vertices.size(); ++i) { for (size_t i = 0; i < inp->m_vertices.size(); ++i) {
aiFace &f = pMesh->mFaces[outIndex++]; aiFace &f = pMesh->mFaces[outIndex++];
uiIdxCount += f.mNumIndices = 1; uiIdxCount += f.mNumIndices = 1;
@ -437,8 +430,7 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel,
pMesh->mColors[0] = new aiColor4D[pMesh->mNumVertices]; pMesh->mColors[0] = new aiColor4D[pMesh->mNumVertices];
// Allocate buffer for texture coordinates // Allocate buffer for texture coordinates
if ( !pModel->m_TextureCoord.empty() && pObjMesh->m_uiUVCoordinates[0] ) if (!pModel->m_TextureCoord.empty() && pObjMesh->m_uiUVCoordinates[0]) {
{
pMesh->mNumUVComponents[0] = pModel->m_TextureCoordDim; pMesh->mNumUVComponents[0] = pModel->m_TextureCoordDim;
pMesh->mTextureCoords[0] = new aiVector3D[pMesh->mNumVertices]; pMesh->mTextureCoords[0] = new aiVector3D[pMesh->mNumVertices];
} }
@ -463,34 +455,26 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel,
// Copy all normals // Copy all normals
if (normalsok && !pModel->m_Normals.empty() && vertexIndex < sourceFace->m_normals.size()) { if (normalsok && !pModel->m_Normals.empty() && vertexIndex < sourceFace->m_normals.size()) {
const unsigned int normal = sourceFace->m_normals.at(vertexIndex); const unsigned int normal = sourceFace->m_normals.at(vertexIndex);
if ( normal >= pModel->m_Normals.size() ) if (normal >= pModel->m_Normals.size()) {
{
normalsok = false; normalsok = false;
} } else {
else
{
pMesh->mNormals[newIndex] = pModel->m_Normals[normal]; pMesh->mNormals[newIndex] = pModel->m_Normals[normal];
} }
} }
// Copy all vertex colors // Copy all vertex colors
if ( !pModel->m_VertexColors.empty()) if (!pModel->m_VertexColors.empty()) {
{
const aiVector3D &color = pModel->m_VertexColors[vertex]; const aiVector3D &color = pModel->m_VertexColors[vertex];
pMesh->mColors[0][newIndex] = aiColor4D(color.x, color.y, color.z, 1.0); pMesh->mColors[0][newIndex] = aiColor4D(color.x, color.y, color.z, 1.0);
} }
// Copy all texture coordinates // Copy all texture coordinates
if ( uvok && !pModel->m_TextureCoord.empty() && vertexIndex < sourceFace->m_texturCoords.size()) if (uvok && !pModel->m_TextureCoord.empty() && vertexIndex < sourceFace->m_texturCoords.size()) {
{
const unsigned int tex = sourceFace->m_texturCoords.at(vertexIndex); const unsigned int tex = sourceFace->m_texturCoords.at(vertexIndex);
if ( tex >= pModel->m_TextureCoord.size() ) if (tex >= pModel->m_TextureCoord.size()) {
{
uvok = false; uvok = false;
} } else {
else
{
const aiVector3D &coord3d = pModel->m_TextureCoord[tex]; const aiVector3D &coord3d = pModel->m_TextureCoord[tex];
pMesh->mTextureCoords[0][newIndex] = aiVector3D(coord3d.x, coord3d.y, coord3d.z); 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; pDestFace[-1].mIndices[1] = newIndex;
} }
} } else if (last) {
else if (last) {
outIndex++; outIndex++;
} }
++newIndex; ++newIndex;
} }
} }
if (!normalsok) if (!normalsok) {
{
delete[] pMesh->mNormals; delete[] pMesh->mNormals;
pMesh->mNormals = nullptr; pMesh->mNormals = nullptr;
} }
if (!uvok) if (!uvok) {
{
delete[] pMesh->mTextureCoords[0]; delete[] pMesh->mTextureCoords[0];
pMesh->mTextureCoords[0] = nullptr; pMesh->mTextureCoords[0] = nullptr;
} }
@ -553,17 +534,14 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel,
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Counts all stored meshes // Counts all stored meshes
void ObjFileImporter::countObjects(const std::vector<ObjFile::Object*> &rObjects, int &iNumMeshes) void ObjFileImporter::countObjects(const std::vector<ObjFile::Object *> &rObjects, int &iNumMeshes) {
{
iNumMeshes = 0; iNumMeshes = 0;
if (rObjects.empty()) if (rObjects.empty())
return; return;
iNumMeshes += static_cast<unsigned int>(rObjects.size()); iNumMeshes += static_cast<unsigned int>(rObjects.size());
for (auto object: rObjects) for (auto object : rObjects) {
{ if (!object->m_SubObjects.empty()) {
if (!object->m_SubObjects.empty())
{
countObjects(object->m_SubObjects, iNumMeshes); countObjects(object->m_SubObjects, iNumMeshes);
} }
} }
@ -595,8 +573,7 @@ void ObjFileImporter::createMaterials(const ObjFile::Model* pModel, aiScene* pSc
} }
pScene->mMaterials = new aiMaterial *[numMaterials]; pScene->mMaterials = new aiMaterial *[numMaterials];
for ( unsigned int matIndex = 0; matIndex < numMaterials; matIndex++ ) for (unsigned int matIndex = 0; matIndex < numMaterials; matIndex++) {
{
// Store material name // Store material name
std::map<std::string, ObjFile::Material *>::const_iterator it; std::map<std::string, ObjFile::Material *>::const_iterator it;
it = pModel->m_MaterialMap.find(pModel->m_MaterialLib[matIndex]); it = pModel->m_MaterialMap.find(pModel->m_MaterialLib[matIndex]);
@ -611,8 +588,7 @@ void ObjFileImporter::createMaterials(const ObjFile::Model* pModel, aiScene* pSc
// convert illumination model // convert illumination model
int sm = 0; int sm = 0;
switch (pCurrentMaterial->illumination_model) switch (pCurrentMaterial->illumination_model) {
{
case 0: case 0:
sm = aiShadingMode_NoShading; sm = aiShadingMode_NoShading;
break; break;
@ -644,71 +620,58 @@ void ObjFileImporter::createMaterials(const ObjFile::Model* pModel, aiScene* pSc
// Adding textures // Adding textures
const int uvwIndex = 0; const int uvwIndex = 0;
if ( 0 != pCurrentMaterial->texture.length ) if (0 != pCurrentMaterial->texture.length) {
{
mat->AddProperty(&pCurrentMaterial->texture, AI_MATKEY_TEXTURE_DIFFUSE(0)); mat->AddProperty(&pCurrentMaterial->texture, AI_MATKEY_TEXTURE_DIFFUSE(0));
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_DIFFUSE(0)); mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_DIFFUSE(0));
if (pCurrentMaterial->clamp[ObjFile::Material::TextureDiffuseType]) if (pCurrentMaterial->clamp[ObjFile::Material::TextureDiffuseType]) {
{
addTextureMappingModeProperty(mat, aiTextureType_DIFFUSE); addTextureMappingModeProperty(mat, aiTextureType_DIFFUSE);
} }
} }
if ( 0 != pCurrentMaterial->textureAmbient.length ) if (0 != pCurrentMaterial->textureAmbient.length) {
{
mat->AddProperty(&pCurrentMaterial->textureAmbient, AI_MATKEY_TEXTURE_AMBIENT(0)); mat->AddProperty(&pCurrentMaterial->textureAmbient, AI_MATKEY_TEXTURE_AMBIENT(0));
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_AMBIENT(0)); mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_AMBIENT(0));
if (pCurrentMaterial->clamp[ObjFile::Material::TextureAmbientType]) if (pCurrentMaterial->clamp[ObjFile::Material::TextureAmbientType]) {
{
addTextureMappingModeProperty(mat, aiTextureType_AMBIENT); addTextureMappingModeProperty(mat, aiTextureType_AMBIENT);
} }
} }
if ( 0 != pCurrentMaterial->textureEmissive.length ) if (0 != pCurrentMaterial->textureEmissive.length) {
{
mat->AddProperty(&pCurrentMaterial->textureEmissive, AI_MATKEY_TEXTURE_EMISSIVE(0)); mat->AddProperty(&pCurrentMaterial->textureEmissive, AI_MATKEY_TEXTURE_EMISSIVE(0));
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_EMISSIVE(0)); mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_EMISSIVE(0));
} }
if ( 0 != pCurrentMaterial->textureSpecular.length ) if (0 != pCurrentMaterial->textureSpecular.length) {
{
mat->AddProperty(&pCurrentMaterial->textureSpecular, AI_MATKEY_TEXTURE_SPECULAR(0)); mat->AddProperty(&pCurrentMaterial->textureSpecular, AI_MATKEY_TEXTURE_SPECULAR(0));
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_SPECULAR(0)); mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_SPECULAR(0));
if (pCurrentMaterial->clamp[ObjFile::Material::TextureSpecularType]) if (pCurrentMaterial->clamp[ObjFile::Material::TextureSpecularType]) {
{
addTextureMappingModeProperty(mat, aiTextureType_SPECULAR); addTextureMappingModeProperty(mat, aiTextureType_SPECULAR);
} }
} }
if ( 0 != pCurrentMaterial->textureBump.length ) if (0 != pCurrentMaterial->textureBump.length) {
{
mat->AddProperty(&pCurrentMaterial->textureBump, AI_MATKEY_TEXTURE_HEIGHT(0)); mat->AddProperty(&pCurrentMaterial->textureBump, AI_MATKEY_TEXTURE_HEIGHT(0));
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_HEIGHT(0)); mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_HEIGHT(0));
if (pCurrentMaterial->clamp[ObjFile::Material::TextureBumpType]) if (pCurrentMaterial->clamp[ObjFile::Material::TextureBumpType]) {
{
addTextureMappingModeProperty(mat, aiTextureType_HEIGHT); addTextureMappingModeProperty(mat, aiTextureType_HEIGHT);
} }
} }
if ( 0 != pCurrentMaterial->textureNormal.length ) if (0 != pCurrentMaterial->textureNormal.length) {
{
mat->AddProperty(&pCurrentMaterial->textureNormal, AI_MATKEY_TEXTURE_NORMALS(0)); mat->AddProperty(&pCurrentMaterial->textureNormal, AI_MATKEY_TEXTURE_NORMALS(0));
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_NORMALS(0)); mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_NORMALS(0));
if (pCurrentMaterial->clamp[ObjFile::Material::TextureNormalType]) if (pCurrentMaterial->clamp[ObjFile::Material::TextureNormalType]) {
{
addTextureMappingModeProperty(mat, aiTextureType_NORMALS); addTextureMappingModeProperty(mat, aiTextureType_NORMALS);
} }
} }
if( 0 != pCurrentMaterial->textureReflection[0].length ) if (0 != pCurrentMaterial->textureReflection[0].length) {
{
ObjFile::Material::TextureType type = 0 != pCurrentMaterial->textureReflection[1].length ? ObjFile::Material::TextureType type = 0 != pCurrentMaterial->textureReflection[1].length ?
ObjFile::Material::TextureReflectionCubeTopType : ObjFile::Material::TextureReflectionCubeTopType :
ObjFile::Material::TextureReflectionSphereType; ObjFile::Material::TextureReflectionSphereType;
unsigned count = type == ObjFile::Material::TextureReflectionSphereType ? 1 : 6; unsigned count = type == ObjFile::Material::TextureReflectionSphereType ? 1 : 6;
for( unsigned i = 0; i < count; i++ ) for (unsigned i = 0; i < count; i++) {
{
mat->AddProperty(&pCurrentMaterial->textureReflection[i], AI_MATKEY_TEXTURE_REFLECTION(i)); mat->AddProperty(&pCurrentMaterial->textureReflection[i], AI_MATKEY_TEXTURE_REFLECTION(i));
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_REFLECTION(i)); mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_REFLECTION(i));
@ -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(&pCurrentMaterial->textureDisp, AI_MATKEY_TEXTURE_DISPLACEMENT(0));
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_DISPLACEMENT(0)); mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_DISPLACEMENT(0));
if (pCurrentMaterial->clamp[ObjFile::Material::TextureDispType]) if (pCurrentMaterial->clamp[ObjFile::Material::TextureDispType]) {
{
addTextureMappingModeProperty(mat, aiTextureType_DISPLACEMENT); addTextureMappingModeProperty(mat, aiTextureType_DISPLACEMENT);
} }
} }
if ( 0 != pCurrentMaterial->textureOpacity.length ) if (0 != pCurrentMaterial->textureOpacity.length) {
{
mat->AddProperty(&pCurrentMaterial->textureOpacity, AI_MATKEY_TEXTURE_OPACITY(0)); mat->AddProperty(&pCurrentMaterial->textureOpacity, AI_MATKEY_TEXTURE_OPACITY(0));
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_OPACITY(0)); mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_OPACITY(0));
if (pCurrentMaterial->clamp[ObjFile::Material::TextureOpacityType]) if (pCurrentMaterial->clamp[ObjFile::Material::TextureOpacityType]) {
{
addTextureMappingModeProperty(mat, aiTextureType_OPACITY); addTextureMappingModeProperty(mat, aiTextureType_OPACITY);
} }
} }
if ( 0 != pCurrentMaterial->textureSpecularity.length ) if (0 != pCurrentMaterial->textureSpecularity.length) {
{
mat->AddProperty(&pCurrentMaterial->textureSpecularity, AI_MATKEY_TEXTURE_SHININESS(0)); mat->AddProperty(&pCurrentMaterial->textureSpecularity, AI_MATKEY_TEXTURE_SHININESS(0));
mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_SHININESS(0)); mat->AddProperty(&uvwIndex, 1, AI_MATKEY_UVWSRC_SHININESS(0));
if (pCurrentMaterial->clamp[ObjFile::Material::TextureSpecularityType]) if (pCurrentMaterial->clamp[ObjFile::Material::TextureSpecularityType]) {
{
addTextureMappingModeProperty(mat, aiTextureType_SHININESS); addTextureMappingModeProperty(mat, aiTextureType_SHININESS);
} }
} }
@ -758,8 +715,7 @@ void ObjFileImporter::createMaterials(const ObjFile::Model* pModel, aiScene* pSc
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Appends this node to the parent node // Appends this node to the parent node
void ObjFileImporter::appendChildToParentNode(aiNode *pParent, aiNode *pChild) void ObjFileImporter::appendChildToParentNode(aiNode *pParent, aiNode *pChild) {
{
// Checking preconditions // Checking preconditions
ai_assert(NULL != pParent); ai_assert(NULL != pParent);
ai_assert(NULL != pChild); ai_assert(NULL != pChild);

View File

@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2020, assimp team Copyright (c) 2006-2020, assimp team
All rights reserved. All rights reserved.
Redistribution and use of this software in source and binary forms, Redistribution and use of this software in source and binary forms,
@ -54,7 +53,7 @@ namespace Assimp {
namespace ObjFile { namespace ObjFile {
struct Object; struct Object;
struct Model; struct Model;
} } // namespace ObjFile
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
/// \class ObjFileImporter /// \class ObjFileImporter

View File

@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2020, assimp team Copyright (c) 2006-2020, assimp team
All rights reserved. All rights reserved.
Redistribution and use of this software in source and binary forms, Redistribution and use of this software in source and binary forms,
@ -41,16 +39,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
*/ */
#ifndef ASSIMP_BUILD_NO_OBJ_IMPORTER #ifndef ASSIMP_BUILD_NO_OBJ_IMPORTER
#include <stdlib.h>
#include "ObjFileMtlImporter.h" #include "ObjFileMtlImporter.h"
#include "ObjTools.h"
#include "ObjFileData.h" #include "ObjFileData.h"
#include <assimp/fast_atof.h> #include "ObjTools.h"
#include <assimp/ParsingUtils.h> #include <assimp/ParsingUtils.h>
#include <assimp/fast_atof.h>
#include <assimp/material.h> #include <assimp/material.h>
#include <stdlib.h>
#include <assimp/DefaultLogger.hpp> #include <assimp/DefaultLogger.hpp>
namespace Assimp { namespace Assimp {
@ -92,11 +89,9 @@ ObjFileMtlImporter::ObjFileMtlImporter( std::vector<char> &buffer,
m_DataIt(buffer.begin()), m_DataIt(buffer.begin()),
m_DataItEnd(buffer.end()), m_DataItEnd(buffer.end()),
m_pModel(pModel), m_pModel(pModel),
m_uiLine( 0 ) m_uiLine(0) {
{
ai_assert(NULL != m_pModel); ai_assert(NULL != m_pModel);
if ( NULL == m_pModel->m_pDefaultMaterial ) if (NULL == m_pModel->m_pDefaultMaterial) {
{
m_pModel->m_pDefaultMaterial = new ObjFile::Material; m_pModel->m_pDefaultMaterial = new ObjFile::Material;
m_pModel->m_pDefaultMaterial->MaterialName.Set("default"); m_pModel->m_pDefaultMaterial->MaterialName.Set("default");
} }
@ -105,65 +100,51 @@ ObjFileMtlImporter::ObjFileMtlImporter( std::vector<char> &buffer,
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Destructor // Destructor
ObjFileMtlImporter::~ObjFileMtlImporter() ObjFileMtlImporter::~ObjFileMtlImporter() {
{
// empty // empty
} }
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Private copy constructor // Private copy constructor
ObjFileMtlImporter::ObjFileMtlImporter(const ObjFileMtlImporter & ) ObjFileMtlImporter::ObjFileMtlImporter(const ObjFileMtlImporter &) {
{
// empty // empty
} }
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Private copy constructor // Private copy constructor
ObjFileMtlImporter &ObjFileMtlImporter::operator = ( const ObjFileMtlImporter & ) ObjFileMtlImporter &ObjFileMtlImporter::operator=(const ObjFileMtlImporter &) {
{
return *this; return *this;
} }
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Loads the material description // Loads the material description
void ObjFileMtlImporter::load() void ObjFileMtlImporter::load() {
{
if (m_DataIt == m_DataItEnd) if (m_DataIt == m_DataItEnd)
return; return;
while ( m_DataIt != m_DataItEnd ) while (m_DataIt != m_DataItEnd) {
{ switch (*m_DataIt) {
switch (*m_DataIt)
{
case 'k': case 'k':
case 'K': case 'K': {
{
++m_DataIt; ++m_DataIt;
if (*m_DataIt == 'a') // Ambient color if (*m_DataIt == 'a') // Ambient color
{ {
++m_DataIt; ++m_DataIt;
getColorRGBA(&m_pModel->m_pCurrentMaterial->ambient); getColorRGBA(&m_pModel->m_pCurrentMaterial->ambient);
} } else if (*m_DataIt == 'd') // Diffuse color
else if (*m_DataIt == 'd') // Diffuse color
{ {
++m_DataIt; ++m_DataIt;
getColorRGBA(&m_pModel->m_pCurrentMaterial->diffuse); getColorRGBA(&m_pModel->m_pCurrentMaterial->diffuse);
} } else if (*m_DataIt == 's') {
else if (*m_DataIt == 's')
{
++m_DataIt; ++m_DataIt;
getColorRGBA(&m_pModel->m_pCurrentMaterial->specular); getColorRGBA(&m_pModel->m_pCurrentMaterial->specular);
} } else if (*m_DataIt == 'e') {
else if (*m_DataIt == 'e')
{
++m_DataIt; ++m_DataIt;
getColorRGBA(&m_pModel->m_pCurrentMaterial->emissive); getColorRGBA(&m_pModel->m_pCurrentMaterial->emissive);
} }
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine); m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
} } break;
break; case 'T': {
case 'T':
{
++m_DataIt; ++m_DataIt;
if (*m_DataIt == 'f') // Material transmission if (*m_DataIt == 'f') // Material transmission
{ {
@ -171,10 +152,8 @@ void ObjFileMtlImporter::load()
getColorRGBA(&m_pModel->m_pCurrentMaterial->transparent); getColorRGBA(&m_pModel->m_pCurrentMaterial->transparent);
} }
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine); m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
} } break;
break; case 'd': {
case 'd':
{
if (*(m_DataIt + 1) == 'i' && *(m_DataIt + 2) == 's' && *(m_DataIt + 3) == 'p') { if (*(m_DataIt + 1) == 'i' && *(m_DataIt + 2) == 's' && *(m_DataIt + 3) == 'p') {
// A displacement map // A displacement map
getTexture(); getTexture();
@ -184,15 +163,12 @@ void ObjFileMtlImporter::load()
getFloatValue(m_pModel->m_pCurrentMaterial->alpha); getFloatValue(m_pModel->m_pCurrentMaterial->alpha);
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine); m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
} }
} } break;
break;
case 'N': case 'N':
case 'n': case 'n': {
{
++m_DataIt; ++m_DataIt;
switch(*m_DataIt) switch (*m_DataIt) {
{
case 's': // Specular exponent case 's': // Specular exponent
++m_DataIt; ++m_DataIt;
getFloatValue(m_pModel->m_pCurrentMaterial->shineness); getFloatValue(m_pModel->m_pCurrentMaterial->shineness);
@ -206,8 +182,7 @@ void ObjFileMtlImporter::load()
break; break;
} }
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine); m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
} } break;
break;
case 'm': // Texture case 'm': // Texture
case 'b': // quick'n'dirty - for 'bump' sections case 'b': // quick'n'dirty - for 'bump' sections
@ -215,30 +190,25 @@ void ObjFileMtlImporter::load()
{ {
getTexture(); getTexture();
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine); m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
} } break;
break;
case 'i': // Illumination model case 'i': // Illumination model
{ {
m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd); m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
getIlluminationModel(m_pModel->m_pCurrentMaterial->illumination_model); getIlluminationModel(m_pModel->m_pCurrentMaterial->illumination_model);
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine); m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
} } break;
break;
default: default: {
{
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine); m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
} } break;
break;
} }
} }
} }
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Loads a color definition // Loads a color definition
void ObjFileMtlImporter::getColorRGBA( aiColor3D *pColor ) void ObjFileMtlImporter::getColorRGBA(aiColor3D *pColor) {
{
ai_assert(NULL != pColor); ai_assert(NULL != pColor);
ai_real r(0.0), g(0.0), b(0.0); ai_real r(0.0), g(0.0), b(0.0);
@ -256,24 +226,21 @@ void ObjFileMtlImporter::getColorRGBA( aiColor3D *pColor )
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Loads the kind of illumination model. // Loads the kind of illumination model.
void ObjFileMtlImporter::getIlluminationModel( int &illum_model ) void ObjFileMtlImporter::getIlluminationModel(int &illum_model) {
{
m_DataIt = CopyNextWord<DataArrayIt>(m_DataIt, m_DataItEnd, m_buffer, BUFFERSIZE); m_DataIt = CopyNextWord<DataArrayIt>(m_DataIt, m_DataItEnd, m_buffer, BUFFERSIZE);
illum_model = atoi(m_buffer); illum_model = atoi(m_buffer);
} }
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Loads a single float value. // Loads a single float value.
void ObjFileMtlImporter::getFloatValue( ai_real &value ) void ObjFileMtlImporter::getFloatValue(ai_real &value) {
{
m_DataIt = CopyNextWord<DataArrayIt>(m_DataIt, m_DataItEnd, m_buffer, BUFFERSIZE); m_DataIt = CopyNextWord<DataArrayIt>(m_DataIt, m_DataItEnd, m_buffer, BUFFERSIZE);
value = (ai_real)fast_atof(m_buffer); value = (ai_real)fast_atof(m_buffer);
} }
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Creates a material from loaded data. // Creates a material from loaded data.
void ObjFileMtlImporter::createMaterial() void ObjFileMtlImporter::createMaterial() {
{
std::string line; std::string line;
while (!IsLineEnd(*m_DataIt)) { while (!IsLineEnd(*m_DataIt)) {
line += *m_DataIt; line += *m_DataIt;
@ -398,90 +365,57 @@ void ObjFileMtlImporter::getTextureOption(bool &clamp, int &clampIndex, aiString
m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd); m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
// If there is any more texture option // If there is any more texture option
while (!isEndOfBuffer(m_DataIt, m_DataItEnd) && *m_DataIt == '-') while (!isEndOfBuffer(m_DataIt, m_DataItEnd) && *m_DataIt == '-') {
{
const char *pPtr(&(*m_DataIt)); const char *pPtr(&(*m_DataIt));
//skip option key and value //skip option key and value
int skipToken = 1; int skipToken = 1;
if (!ASSIMP_strincmp(pPtr, ClampOption.c_str(), static_cast<unsigned int>(ClampOption.size()))) if (!ASSIMP_strincmp(pPtr, ClampOption.c_str(), static_cast<unsigned int>(ClampOption.size()))) {
{
DataArrayIt it = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd); DataArrayIt it = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
char value[3]; char value[3];
CopyNextWord(it, m_DataItEnd, value, sizeof(value) / sizeof(*value)); CopyNextWord(it, m_DataItEnd, value, sizeof(value) / sizeof(*value));
if (!ASSIMP_strincmp(value, "on", 2)) if (!ASSIMP_strincmp(value, "on", 2)) {
{
clamp = true; clamp = true;
} }
skipToken = 2; skipToken = 2;
} } else if (!ASSIMP_strincmp(pPtr, TypeOption.c_str(), static_cast<unsigned int>(TypeOption.size()))) {
else if( !ASSIMP_strincmp( pPtr, TypeOption.c_str(), static_cast<unsigned int>(TypeOption.size()) ) )
{
DataArrayIt it = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd); DataArrayIt it = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
char value[12]; char value[12];
CopyNextWord(it, m_DataItEnd, value, sizeof(value) / sizeof(*value)); 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; clampIndex = ObjFile::Material::TextureReflectionCubeTopType;
out = &m_pModel->m_pCurrentMaterial->textureReflection[0]; out = &m_pModel->m_pCurrentMaterial->textureReflection[0];
} } else if (!ASSIMP_strincmp(value, "cube_bottom", 11)) {
else if( !ASSIMP_strincmp( value, "cube_bottom", 11 ) )
{
clampIndex = ObjFile::Material::TextureReflectionCubeBottomType; clampIndex = ObjFile::Material::TextureReflectionCubeBottomType;
out = &m_pModel->m_pCurrentMaterial->textureReflection[1]; out = &m_pModel->m_pCurrentMaterial->textureReflection[1];
} } else if (!ASSIMP_strincmp(value, "cube_front", 10)) {
else if( !ASSIMP_strincmp( value, "cube_front", 10 ) )
{
clampIndex = ObjFile::Material::TextureReflectionCubeFrontType; clampIndex = ObjFile::Material::TextureReflectionCubeFrontType;
out = &m_pModel->m_pCurrentMaterial->textureReflection[2]; out = &m_pModel->m_pCurrentMaterial->textureReflection[2];
} } else if (!ASSIMP_strincmp(value, "cube_back", 9)) {
else if( !ASSIMP_strincmp( value, "cube_back", 9 ) )
{
clampIndex = ObjFile::Material::TextureReflectionCubeBackType; clampIndex = ObjFile::Material::TextureReflectionCubeBackType;
out = &m_pModel->m_pCurrentMaterial->textureReflection[3]; out = &m_pModel->m_pCurrentMaterial->textureReflection[3];
} } else if (!ASSIMP_strincmp(value, "cube_left", 9)) {
else if( !ASSIMP_strincmp( value, "cube_left", 9 ) )
{
clampIndex = ObjFile::Material::TextureReflectionCubeLeftType; clampIndex = ObjFile::Material::TextureReflectionCubeLeftType;
out = &m_pModel->m_pCurrentMaterial->textureReflection[4]; out = &m_pModel->m_pCurrentMaterial->textureReflection[4];
} } else if (!ASSIMP_strincmp(value, "cube_right", 10)) {
else if( !ASSIMP_strincmp( value, "cube_right", 10 ) )
{
clampIndex = ObjFile::Material::TextureReflectionCubeRightType; clampIndex = ObjFile::Material::TextureReflectionCubeRightType;
out = &m_pModel->m_pCurrentMaterial->textureReflection[5]; out = &m_pModel->m_pCurrentMaterial->textureReflection[5];
} } else if (!ASSIMP_strincmp(value, "sphere", 6)) {
else if( !ASSIMP_strincmp( value, "sphere", 6 ) )
{
clampIndex = ObjFile::Material::TextureReflectionSphereType; clampIndex = ObjFile::Material::TextureReflectionSphereType;
out = &m_pModel->m_pCurrentMaterial->textureReflection[0]; out = &m_pModel->m_pCurrentMaterial->textureReflection[0];
} }
skipToken = 2; skipToken = 2;
} } else if (!ASSIMP_strincmp(pPtr, BlendUOption.c_str(), static_cast<unsigned int>(BlendUOption.size())) || !ASSIMP_strincmp(pPtr, BlendVOption.c_str(), static_cast<unsigned int>(BlendVOption.size())) || !ASSIMP_strincmp(pPtr, BoostOption.c_str(), static_cast<unsigned int>(BoostOption.size())) || !ASSIMP_strincmp(pPtr, ResolutionOption.c_str(), static_cast<unsigned int>(ResolutionOption.size())) || !ASSIMP_strincmp(pPtr, BumpOption.c_str(), static_cast<unsigned int>(BumpOption.size())) || !ASSIMP_strincmp(pPtr, ChannelOption.c_str(), static_cast<unsigned int>(ChannelOption.size()))) {
else if (!ASSIMP_strincmp(pPtr, BlendUOption.c_str(), static_cast<unsigned int>(BlendUOption.size()))
|| !ASSIMP_strincmp(pPtr, BlendVOption.c_str(), static_cast<unsigned int>(BlendVOption.size()))
|| !ASSIMP_strincmp(pPtr, BoostOption.c_str(), static_cast<unsigned int>(BoostOption.size()))
|| !ASSIMP_strincmp(pPtr, ResolutionOption.c_str(), static_cast<unsigned int>(ResolutionOption.size()))
|| !ASSIMP_strincmp(pPtr, BumpOption.c_str(), static_cast<unsigned int>(BumpOption.size()))
|| !ASSIMP_strincmp(pPtr, ChannelOption.c_str(), static_cast<unsigned int>(ChannelOption.size())))
{
skipToken = 2; skipToken = 2;
} } else if (!ASSIMP_strincmp(pPtr, ModifyMapOption.c_str(), static_cast<unsigned int>(ModifyMapOption.size()))) {
else if (!ASSIMP_strincmp(pPtr, ModifyMapOption.c_str(), static_cast<unsigned int>(ModifyMapOption.size())))
{
skipToken = 3; skipToken = 3;
} } else if (!ASSIMP_strincmp(pPtr, OffsetOption.c_str(), static_cast<unsigned int>(OffsetOption.size())) || !ASSIMP_strincmp(pPtr, ScaleOption.c_str(), static_cast<unsigned int>(ScaleOption.size())) || !ASSIMP_strincmp(pPtr, TurbulenceOption.c_str(), static_cast<unsigned int>(TurbulenceOption.size()))) {
else if ( !ASSIMP_strincmp(pPtr, OffsetOption.c_str(), static_cast<unsigned int>(OffsetOption.size()))
|| !ASSIMP_strincmp(pPtr, ScaleOption.c_str(), static_cast<unsigned int>(ScaleOption.size()))
|| !ASSIMP_strincmp(pPtr, TurbulenceOption.c_str(), static_cast<unsigned int>(TurbulenceOption.size()))
)
{
skipToken = 4; skipToken = 4;
} }
for (int i = 0; i < skipToken; ++i) for (int i = 0; i < skipToken; ++i) {
{
m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd); m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
} }
} }

View File

@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2020, assimp team Copyright (c) 2006-2020, assimp team
All rights reserved. All rights reserved.
Redistribution and use of this software in source and binary forms, Redistribution and use of this software in source and binary forms,
@ -41,9 +40,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef OBJFILEMTLIMPORTER_H_INC #ifndef OBJFILEMTLIMPORTER_H_INC
#define OBJFILEMTLIMPORTER_H_INC #define OBJFILEMTLIMPORTER_H_INC
#include <vector>
#include <string>
#include <assimp/defs.h> #include <assimp/defs.h>
#include <string>
#include <vector>
struct aiColor3D; struct aiColor3D;
struct aiString; struct aiString;
@ -53,15 +52,13 @@ namespace Assimp {
namespace ObjFile { namespace ObjFile {
struct Model; struct Model;
struct Material; struct Material;
} } // namespace ObjFile
/** /**
* @class ObjFileMtlImporter * @class ObjFileMtlImporter
* @brief Loads the material description from a mtl file. * @brief Loads the material description from a mtl file.
*/ */
class ObjFileMtlImporter class ObjFileMtlImporter {
{
public: public:
static const size_t BUFFERSIZE = 2048; static const size_t BUFFERSIZE = 2048;
typedef std::vector<char> DataArray; typedef std::vector<char> DataArray;

View File

@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2020, assimp team Copyright (c) 2006-2020, assimp team
All rights reserved. All rights reserved.
Redistribution and use of this software in source and binary forms, Redistribution and use of this software in source and binary forms,
@ -43,14 +41,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef ASSIMP_BUILD_NO_OBJ_IMPORTER #ifndef ASSIMP_BUILD_NO_OBJ_IMPORTER
#include "ObjFileParser.h" #include "ObjFileParser.h"
#include "ObjFileData.h"
#include "ObjFileMtlImporter.h" #include "ObjFileMtlImporter.h"
#include "ObjTools.h" #include "ObjTools.h"
#include "ObjFileData.h"
#include <assimp/ParsingUtils.h>
#include <assimp/BaseImporter.h> #include <assimp/BaseImporter.h>
#include <assimp/DefaultIOSystem.h> #include <assimp/DefaultIOSystem.h>
#include <assimp/DefaultLogger.hpp> #include <assimp/ParsingUtils.h>
#include <assimp/material.h> #include <assimp/material.h>
#include <assimp/DefaultLogger.hpp>
#include <assimp/Importer.hpp> #include <assimp/Importer.hpp>
#include <cstdlib> #include <cstdlib>
@ -58,14 +56,8 @@ namespace Assimp {
const std::string ObjFileParser::DEFAULT_MATERIAL = AI_DEFAULT_MATERIAL_NAME; const std::string ObjFileParser::DEFAULT_MATERIAL = AI_DEFAULT_MATERIAL_NAME;
ObjFileParser::ObjFileParser() ObjFileParser::ObjFileParser() :
: m_DataIt() m_DataIt(), m_DataItEnd(), m_pModel(nullptr), m_uiLine(0), m_pIO(nullptr), m_progress(nullptr), m_originalObjFileName() {
, m_DataItEnd()
, m_pModel( nullptr )
, m_uiLine( 0 )
, m_pIO( nullptr )
, m_progress( nullptr )
, m_originalObjFileName() {
// empty // empty
} }
@ -78,8 +70,7 @@ ObjFileParser::ObjFileParser( IOStreamBuffer<char> &streamBuffer, const std::str
m_uiLine(0), m_uiLine(0),
m_pIO(io), m_pIO(io),
m_progress(progress), m_progress(progress),
m_originalObjFileName(originalObjFileName) m_originalObjFileName(originalObjFileName) {
{
std::fill_n(m_buffer, Buffersize, '\0'); std::fill_n(m_buffer, Buffersize, '\0');
// Create the model instance to store all the data // Create the model instance to store all the data
@ -158,23 +149,18 @@ void ObjFileParser::parseFile( IOStreamBuffer<char> &streamBuffer ) {
++m_DataIt; ++m_DataIt;
getVector3(m_pModel->m_Normals); getVector3(m_pModel->m_Normals);
} }
} } break;
break;
case 'p': // Parse a face, line or point statement case 'p': // Parse a face, line or point statement
case 'l': case 'l':
case 'f': case 'f': {
{ getFace(*m_DataIt == 'f' ? aiPrimitiveType_POLYGON : (*m_DataIt == 'l' ? aiPrimitiveType_LINE : aiPrimitiveType_POINT));
getFace(*m_DataIt == 'f' ? aiPrimitiveType_POLYGON : (*m_DataIt == 'l' } break;
? aiPrimitiveType_LINE : aiPrimitiveType_POINT));
}
break;
case '#': // Parse a comment case '#': // Parse a comment
{ {
getComment(); getComment();
} } break;
break;
case 'u': // Parse a material desc. setter case 'u': // Parse a material desc. setter
{ {
@ -186,12 +172,10 @@ void ObjFileParser::parseFile( IOStreamBuffer<char> &streamBuffer ) {
if (nextSpace != std::string::npos) if (nextSpace != std::string::npos)
name = name.substr(0, nextSpace); name = name.substr(0, nextSpace);
if(name == "usemtl") if (name == "usemtl") {
{
getMaterialDesc(); getMaterialDesc();
} }
} } break;
break;
case 'm': // Parse a material library or merging group ('mg') case 'm': // Parse a material library or merging group ('mg')
{ {
@ -209,33 +193,27 @@ void ObjFileParser::parseFile( IOStreamBuffer<char> &streamBuffer ) {
getMaterialLib(); getMaterialLib();
else else
goto pf_skip_line; goto pf_skip_line;
} } break;
break;
case 'g': // Parse group name case 'g': // Parse group name
{ {
getGroupName(); getGroupName();
} } break;
break;
case 's': // Parse group number case 's': // Parse group number
{ {
getGroupNumber(); getGroupNumber();
} } break;
break;
case 'o': // Parse object name case 'o': // Parse object name
{ {
getObjectName(); getObjectName();
} } break;
break;
default: default: {
{
pf_skip_line: pf_skip_line:
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine); m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
} } break;
break;
} }
} }
} }
@ -494,7 +472,6 @@ void ObjFileParser::getFace( aiPrimitiveType type ) {
delete face; delete face;
throw DeadlyImportError("OBJ: Invalid face indice"); throw DeadlyImportError("OBJ: Invalid face indice");
} }
} }
m_DataIt += iStep; m_DataIt += iStep;
} }
@ -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; int mat_index = -1;
if (strMaterialName.empty()) { if (strMaterialName.empty()) {
return mat_index; return mat_index;
} }
for (size_t index = 0; index < m_pModel->m_MaterialLib.size(); ++index) for (size_t index = 0; index < m_pModel->m_MaterialLib.size(); ++index) {
{ if (strMaterialName == m_pModel->m_MaterialLib[index]) {
if ( strMaterialName == m_pModel->m_MaterialLib[ index ])
{
mat_index = (int)index; mat_index = (int)index;
break; break;
} }
@ -726,14 +700,11 @@ void ObjFileParser::getGroupName() {
createObject(groupName); createObject(groupName);
// New group name, creating a new entry // New group name, creating a new entry
if (it == m_pModel->m_Groups.end()) if (it == m_pModel->m_Groups.end()) {
{
std::vector<unsigned int> *pFaceIDArray = new std::vector<unsigned int>; std::vector<unsigned int> *pFaceIDArray = new std::vector<unsigned int>;
m_pModel->m_Groups[groupName] = pFaceIDArray; m_pModel->m_Groups[groupName] = pFaceIDArray;
m_pModel->m_pGroupFaceIDs = (pFaceIDArray); m_pModel->m_pGroupFaceIDs = (pFaceIDArray);
} } else {
else
{
m_pModel->m_pGroupFaceIDs = (*it).second; m_pModel->m_pGroupFaceIDs = (*it).second;
} }
m_pModel->m_strActiveGroup = groupName; m_pModel->m_strActiveGroup = groupName;
@ -743,8 +714,7 @@ void ObjFileParser::getGroupName() {
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Not supported // Not supported
void ObjFileParser::getGroupNumber() void ObjFileParser::getGroupNumber() {
{
// Not used // Not used
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine); m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
@ -752,8 +722,7 @@ void ObjFileParser::getGroupNumber()
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Not supported // Not supported
void ObjFileParser::getGroupNumberAndResolution() void ObjFileParser::getGroupNumberAndResolution() {
{
// Not used // Not used
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine); m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
@ -762,8 +731,7 @@ void ObjFileParser::getGroupNumberAndResolution()
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Stores values for a new object instance, name will be used to // Stores values for a new object instance, name will be used to
// identify it. // identify it.
void ObjFileParser::getObjectName() void ObjFileParser::getObjectName() {
{
m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd); m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
if (m_DataIt == m_DataItEnd) { if (m_DataIt == m_DataItEnd) {
return; return;
@ -774,18 +742,15 @@ void ObjFileParser::getObjectName()
} }
std::string strObjectName(pStart, &(*m_DataIt)); std::string strObjectName(pStart, &(*m_DataIt));
if (!strObjectName.empty()) if (!strObjectName.empty()) {
{
// Reset current object // Reset current object
m_pModel->m_pCurrent = NULL; m_pModel->m_pCurrent = NULL;
// Search for actual object // Search for actual object
for (std::vector<ObjFile::Object *>::const_iterator it = m_pModel->m_Objects.begin(); for (std::vector<ObjFile::Object *>::const_iterator it = m_pModel->m_Objects.begin();
it != m_pModel->m_Objects.end(); it != m_pModel->m_Objects.end();
++it) ++it) {
{ if ((*it)->m_strObjName == strObjectName) {
if ((*it)->m_strObjName == strObjectName)
{
m_pModel->m_pCurrent = *it; m_pModel->m_pCurrent = *it;
break; break;
} }
@ -800,8 +765,7 @@ void ObjFileParser::getObjectName()
} }
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Creates a new object instance // Creates a new object instance
void ObjFileParser::createObject(const std::string &objName) void ObjFileParser::createObject(const std::string &objName) {
{
ai_assert(NULL != m_pModel); ai_assert(NULL != m_pModel);
m_pModel->m_pCurrent = new ObjFile::Object; m_pModel->m_pCurrent = new ObjFile::Object;
@ -810,8 +774,7 @@ void ObjFileParser::createObject(const std::string &objName)
createMesh(objName); createMesh(objName);
if( m_pModel->m_pCurrentMaterial ) if (m_pModel->m_pCurrentMaterial) {
{
m_pModel->m_pCurrentMesh->m_uiMaterialIndex = m_pModel->m_pCurrentMesh->m_uiMaterialIndex =
getMaterialIndex(m_pModel->m_pCurrentMaterial->MaterialName.data); getMaterialIndex(m_pModel->m_pCurrentMaterial->MaterialName.data);
m_pModel->m_pCurrentMesh->m_pMaterial = m_pModel->m_pCurrentMaterial; m_pModel->m_pCurrentMesh->m_pMaterial = m_pModel->m_pCurrentMaterial;
@ -819,40 +782,32 @@ void ObjFileParser::createObject(const std::string &objName)
} }
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Creates a new mesh // Creates a new mesh
void ObjFileParser::createMesh( const std::string &meshName ) void ObjFileParser::createMesh(const std::string &meshName) {
{
ai_assert(NULL != m_pModel); ai_assert(NULL != m_pModel);
m_pModel->m_pCurrentMesh = new ObjFile::Mesh(meshName); m_pModel->m_pCurrentMesh = new ObjFile::Mesh(meshName);
m_pModel->m_Meshes.push_back(m_pModel->m_pCurrentMesh); m_pModel->m_Meshes.push_back(m_pModel->m_pCurrentMesh);
unsigned int meshId = static_cast<unsigned int>(m_pModel->m_Meshes.size() - 1); unsigned int meshId = static_cast<unsigned int>(m_pModel->m_Meshes.size() - 1);
if ( NULL != m_pModel->m_pCurrent ) if (NULL != m_pModel->m_pCurrent) {
{
m_pModel->m_pCurrent->m_Meshes.push_back(meshId); m_pModel->m_pCurrent->m_Meshes.push_back(meshId);
} } else {
else
{
ASSIMP_LOG_ERROR("OBJ: No object detected to attach a new mesh instance."); ASSIMP_LOG_ERROR("OBJ: No object detected to attach a new mesh instance.");
} }
} }
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Returns true, if a new mesh must be created. // Returns true, if a new mesh must be created.
bool ObjFileParser::needsNewMesh( const std::string &materialName ) bool ObjFileParser::needsNewMesh(const std::string &materialName) {
{
// If no mesh data yet // If no mesh data yet
if (m_pModel->m_pCurrentMesh == nullptr) if (m_pModel->m_pCurrentMesh == nullptr) {
{
return true; return true;
} }
bool newMat = false; bool newMat = false;
int matIdx = getMaterialIndex(materialName); int matIdx = getMaterialIndex(materialName);
int curMatIdx = m_pModel->m_pCurrentMesh->m_uiMaterialIndex; int curMatIdx = m_pModel->m_pCurrentMesh->m_uiMaterialIndex;
if ( curMatIdx != int(ObjFile::Mesh::NoMaterial) if (curMatIdx != int(ObjFile::Mesh::NoMaterial) && curMatIdx != matIdx
&& curMatIdx != matIdx
// no need create a new mesh if no faces in current // no need create a new mesh if no faces in current
// lets say 'usemtl' goes straight after 'g' // lets say 'usemtl' goes straight after 'g'
&& !m_pModel->m_pCurrentMesh->m_Faces.empty() ) && !m_pModel->m_pCurrentMesh->m_Faces.empty()) {
{
// New material -> only one material per mesh, so we need to create a new // New material -> only one material per mesh, so we need to create a new
// material // material
newMat = true; newMat = true;
@ -862,8 +817,7 @@ bool ObjFileParser::needsNewMesh( const std::string &materialName )
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Shows an error in parsing process. // Shows an error in parsing process.
void ObjFileParser::reportErrorTokenInFace() void ObjFileParser::reportErrorTokenInFace() {
{
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine); m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
ASSIMP_LOG_ERROR("OBJ: Not supported token in face description detected"); ASSIMP_LOG_ERROR("OBJ: Not supported token in face description detected");
} }

View File

@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2020, assimp team Copyright (c) 2006-2020, assimp team
All rights reserved. All rights reserved.
Redistribution and use of this software in source and binary forms, Redistribution and use of this software in source and binary forms,
@ -42,14 +41,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef OBJ_FILEPARSER_H_INC #ifndef OBJ_FILEPARSER_H_INC
#define OBJ_FILEPARSER_H_INC #define OBJ_FILEPARSER_H_INC
#include <vector> #include <assimp/IOStreamBuffer.h>
#include <string> #include <assimp/mesh.h>
#include <map>
#include <memory>
#include <assimp/vector2.h> #include <assimp/vector2.h>
#include <assimp/vector3.h> #include <assimp/vector3.h>
#include <assimp/mesh.h> #include <map>
#include <assimp/IOStreamBuffer.h> #include <memory>
#include <string>
#include <vector>
namespace Assimp { namespace Assimp {
@ -59,7 +58,7 @@ namespace ObjFile {
struct Material; struct Material;
struct Point3; struct Point3;
struct Point2; struct Point2;
} } // namespace ObjFile
class ObjFileImporter; class ObjFileImporter;
class IOSystem; class IOSystem;

View File

@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2020, assimp team Copyright (c) 2006-2020, assimp team
All rights reserved. All rights reserved.
Redistribution and use of this software in source and binary forms, Redistribution and use of this software in source and binary forms,
@ -46,8 +45,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef OBJ_TOOLS_H_INC #ifndef OBJ_TOOLS_H_INC
#define OBJ_TOOLS_H_INC #define OBJ_TOOLS_H_INC
#include <assimp/fast_atof.h>
#include <assimp/ParsingUtils.h> #include <assimp/ParsingUtils.h>
#include <assimp/fast_atof.h>
#include <vector> #include <vector>
namespace Assimp { namespace Assimp {
@ -59,12 +58,9 @@ namespace Assimp {
*/ */
template <class char_t> template <class char_t>
inline bool isEndOfBuffer(char_t it, char_t end) { inline bool isEndOfBuffer(char_t it, char_t end) {
if ( it == end ) if (it == end) {
{
return true; return true;
} } else {
else
{
--end; --end;
} }
return (it == end); return (it == end);
@ -76,10 +72,8 @@ inline bool isEndOfBuffer( char_t it, char_t end ) {
* @return Pointer to next space * @return Pointer to next space
*/ */
template <class Char_T> template <class Char_T>
inline Char_T getNextWord( Char_T pBuffer, Char_T pEnd ) inline Char_T getNextWord(Char_T pBuffer, Char_T pEnd) {
{ while (!isEndOfBuffer(pBuffer, pEnd)) {
while ( !isEndOfBuffer( pBuffer, pEnd ) )
{
if (!IsSpaceOrNewLine(*pBuffer) || IsLineEnd(*pBuffer)) { if (!IsSpaceOrNewLine(*pBuffer) || IsLineEnd(*pBuffer)) {
//if ( *pBuffer != '\\' ) //if ( *pBuffer != '\\' )
break; break;
@ -95,10 +89,8 @@ inline Char_T getNextWord( Char_T pBuffer, Char_T pEnd )
* @return Pointer to next token * @return Pointer to next token
*/ */
template <class Char_T> template <class Char_T>
inline Char_T getNextToken( Char_T pBuffer, Char_T pEnd ) inline Char_T getNextToken(Char_T pBuffer, Char_T pEnd) {
{ while (!isEndOfBuffer(pBuffer, pEnd)) {
while ( !isEndOfBuffer( pBuffer, pEnd ) )
{
if (IsSpaceOrNewLine(*pBuffer)) if (IsSpaceOrNewLine(*pBuffer))
break; break;
pBuffer++; pBuffer++;
@ -138,8 +130,7 @@ inline char_t skipLine( char_t it, char_t end, unsigned int &uiLine ) {
* @return Current-iterator with new position * @return Current-iterator with new position
*/ */
template <class char_t> template <class char_t>
inline char_t getName( char_t it, char_t end, std::string &name ) inline char_t getName(char_t it, char_t end, std::string &name) {
{
name = ""; name = "";
if (isEndOfBuffer(it, end)) { if (isEndOfBuffer(it, end)) {
return end; return end;
@ -175,21 +166,18 @@ inline char_t getName( char_t it, char_t end, std::string &name )
* @return Current-iterator with new position * @return Current-iterator with new position
*/ */
template <class char_t> template <class char_t>
inline char_t getNameNoSpace( char_t it, char_t end, std::string &name ) inline char_t getNameNoSpace(char_t it, char_t end, std::string &name) {
{
name = ""; name = "";
if (isEndOfBuffer(it, end)) { if (isEndOfBuffer(it, end)) {
return end; return end;
} }
char *pStart = &(*it); char *pStart = &(*it);
while( !isEndOfBuffer( it, end ) && !IsLineEnd( *it ) while (!isEndOfBuffer(it, end) && !IsLineEnd(*it) && !IsSpaceOrNewLine(*it)) {
&& !IsSpaceOrNewLine( *it ) ) {
++it; ++it;
} }
while( isEndOfBuffer( it, end ) || IsLineEnd( *it ) while (isEndOfBuffer(it, end) || IsLineEnd(*it) || IsSpaceOrNewLine(*it)) {
|| IsSpaceOrNewLine( *it ) ) {
--it; --it;
} }
++it; ++it;
@ -216,12 +204,10 @@ inline char_t getNameNoSpace( char_t it, char_t end, std::string &name )
* @return Current-iterator with new position * @return Current-iterator with new position
*/ */
template <class char_t> template <class char_t>
inline char_t CopyNextWord( char_t it, char_t end, char *pBuffer, size_t length ) inline char_t CopyNextWord(char_t it, char_t end, char *pBuffer, size_t length) {
{
size_t index = 0; size_t index = 0;
it = getNextWord<char_t>(it, end); it = getNextWord<char_t>(it, end);
while( !IsSpaceOrNewLine( *it ) && !isEndOfBuffer( it, end ) ) while (!IsSpaceOrNewLine(*it) && !isEndOfBuffer(it, end)) {
{
pBuffer[index] = *it; pBuffer[index] = *it;
index++; index++;
if (index == length - 1) if (index == length - 1)
@ -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 * @return Current-iterator with new position
*/ */
template <class char_t> template <class char_t>
inline char_t getFloat( char_t it, char_t end, ai_real &value ) inline char_t getFloat(char_t it, char_t end, ai_real &value) {
{
static const size_t BUFFERSIZE = 1024; static const size_t BUFFERSIZE = 1024;
char buffer[BUFFERSIZE]; char buffer[BUFFERSIZE];
it = CopyNextWord<char_t>(it, end, buffer, BUFFERSIZE); it = CopyNextWord<char_t>(it, end, buffer, BUFFERSIZE);
@ -257,15 +242,13 @@ inline char_t getFloat( char_t it, char_t end, ai_real &value )
*/ */
template <class string_type> template <class string_type>
unsigned int tokenize(const string_type &str, std::vector<string_type> &tokens, unsigned int tokenize(const string_type &str, std::vector<string_type> &tokens,
const string_type& delimiters ) const string_type &delimiters) {
{
// Skip delimiters at beginning. // Skip delimiters at beginning.
typename string_type::size_type lastPos = str.find_first_not_of(delimiters, 0); typename string_type::size_type lastPos = str.find_first_not_of(delimiters, 0);
// Find first "non-delimiter". // Find first "non-delimiter".
typename string_type::size_type pos = str.find_first_of(delimiters, lastPos); typename string_type::size_type pos = str.find_first_of(delimiters, lastPos);
while ( string_type::npos != pos || string_type::npos != lastPos ) while (string_type::npos != pos || string_type::npos != lastPos) {
{
// Found a token, add it to the vector. // Found a token, add it to the vector.
string_type tmp = str.substr(lastPos, pos - lastPos); string_type tmp = str.substr(lastPos, pos - lastPos);
if (!tmp.empty() && ' ' != tmp[0]) if (!tmp.empty() && ' ' != tmp[0])
@ -282,10 +265,11 @@ unsigned int tokenize( const string_type& str, std::vector<string_type>& tokens,
} }
template <class string_type> template <class string_type>
string_type trim_whitespaces(string_type str) string_type trim_whitespaces(string_type str) {
{ while (!str.empty() && IsSpace(str[0]))
while (!str.empty() && IsSpace(str[0])) str.erase(0); str.erase(0);
while (!str.empty() && IsSpace(str[str.length() - 1])) str.erase(str.length() - 1); while (!str.empty() && IsSpace(str[str.length() - 1]))
str.erase(str.length() - 1);
return str; return str;
} }