2015-05-19 03:48:29 +00:00
|
|
|
/*
|
|
|
|
Open Asset Import Library (assimp)
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
2022-07-30 10:58:09 +00:00
|
|
|
Copyright (c) 2006-2022, assimp team
|
2018-01-28 18:42:05 +00:00
|
|
|
|
2015-05-19 03:48:29 +00:00
|
|
|
All rights reserved.
|
|
|
|
|
2015-05-19 03:52:10 +00:00
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the
|
2015-05-19 03:48:29 +00:00
|
|
|
following conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer.
|
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer in the documentation and/or other
|
|
|
|
materials provided with the distribution.
|
|
|
|
|
|
|
|
* Neither the name of the assimp team, nor the names of its
|
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
|
|
|
written permission of the assimp team.
|
|
|
|
|
2015-05-19 03:52:10 +00:00
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
2015-05-19 03:48:29 +00:00
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
2015-05-19 03:52:10 +00:00
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
2015-05-19 03:48:29 +00:00
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
2015-05-19 03:52:10 +00:00
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
2015-05-19 03:48:29 +00:00
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
2015-05-19 03:52:10 +00:00
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
2015-05-19 03:48:29 +00:00
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2016-11-09 19:09:45 +00:00
|
|
|
#pragma once
|
2015-05-19 03:48:29 +00:00
|
|
|
#ifndef OBJ_FILEDATA_H_INC
|
2020-06-23 19:05:42 +00:00
|
|
|
#define OBJ_FILEDATA_H_INC
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
#include <assimp/mesh.h>
|
|
|
|
#include <assimp/types.h>
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
2022-03-12 07:03:27 +00:00
|
|
|
#include "Common/Maybe.h"
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-07-09 23:21:10 +00:00
|
|
|
namespace Assimp {
|
|
|
|
namespace ObjFile {
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
struct Object;
|
|
|
|
struct Face;
|
|
|
|
struct Material;
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:57:13 +00:00
|
|
|
//! \struct Face
|
|
|
|
//! \brief Data structure for a simple obj-face, describes discredit,l.ation and materials
|
2016-11-09 19:09:45 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
struct Face {
|
2021-09-13 20:38:20 +00:00
|
|
|
using IndexArray = std::vector<unsigned int>;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
//! Primitive type
|
2022-07-30 19:52:33 +00:00
|
|
|
aiPrimitiveType mPrimitiveType;
|
2015-05-19 03:57:13 +00:00
|
|
|
//! Vertex indices
|
2016-11-09 19:09:45 +00:00
|
|
|
IndexArray m_vertices;
|
2015-05-19 03:57:13 +00:00
|
|
|
//! Normal indices
|
2016-11-09 19:09:45 +00:00
|
|
|
IndexArray m_normals;
|
2015-05-19 03:57:13 +00:00
|
|
|
//! Texture coordinates indices
|
2016-11-09 19:09:45 +00:00
|
|
|
IndexArray m_texturCoords;
|
2015-05-19 03:57:13 +00:00
|
|
|
//! Pointer to assigned material
|
|
|
|
Material *m_pMaterial;
|
|
|
|
|
|
|
|
//! \brief Default constructor
|
2020-03-15 09:21:08 +00:00
|
|
|
Face(aiPrimitiveType pt = aiPrimitiveType_POLYGON) :
|
2022-07-30 19:52:33 +00:00
|
|
|
mPrimitiveType(pt), m_vertices(), m_normals(), m_texturCoords(), m_pMaterial(nullptr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// empty
|
|
|
|
}
|
|
|
|
|
|
|
|
//! \brief Destructor
|
2022-07-30 10:58:09 +00:00
|
|
|
~Face() = default;
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:57:13 +00:00
|
|
|
//! \struct Object
|
2016-10-07 07:19:10 +00:00
|
|
|
//! \brief Stores all objects of an obj-file object definition
|
2016-11-09 19:09:45 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
struct Object {
|
|
|
|
enum ObjectType {
|
2015-05-19 03:57:13 +00:00
|
|
|
ObjType,
|
|
|
|
GroupType
|
|
|
|
};
|
|
|
|
|
|
|
|
//! Object name
|
|
|
|
std::string m_strObjName;
|
|
|
|
//! Transformation matrix, stored in OpenGL format
|
|
|
|
aiMatrix4x4 m_Transformation;
|
|
|
|
//! All sub-objects referenced by this object
|
2020-03-15 09:21:08 +00:00
|
|
|
std::vector<Object *> m_SubObjects;
|
2015-05-19 03:57:13 +00:00
|
|
|
/// Assigned meshes
|
|
|
|
std::vector<unsigned int> m_Meshes;
|
|
|
|
|
|
|
|
//! \brief Default constructor
|
2020-02-18 16:50:48 +00:00
|
|
|
Object() = default;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
//! \brief Destructor
|
2016-11-09 19:09:45 +00:00
|
|
|
~Object() {
|
2020-03-15 09:21:08 +00:00
|
|
|
for (std::vector<Object *>::iterator it = m_SubObjects.begin(); it != m_SubObjects.end(); ++it) {
|
2015-05-19 03:57:13 +00:00
|
|
|
delete *it;
|
|
|
|
}
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:57:13 +00:00
|
|
|
//! \struct Material
|
|
|
|
//! \brief Data structure to store all material specific data
|
2016-11-09 19:09:45 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
struct Material {
|
2015-05-19 03:57:13 +00:00
|
|
|
//! Name of material description
|
|
|
|
aiString MaterialName;
|
|
|
|
//! Texture names
|
|
|
|
aiString texture;
|
|
|
|
aiString textureSpecular;
|
|
|
|
aiString textureAmbient;
|
|
|
|
aiString textureEmissive;
|
|
|
|
aiString textureBump;
|
|
|
|
aiString textureNormal;
|
2015-10-15 13:46:35 +00:00
|
|
|
aiString textureReflection[6];
|
2015-05-19 03:57:13 +00:00
|
|
|
aiString textureSpecularity;
|
|
|
|
aiString textureOpacity;
|
|
|
|
aiString textureDisp;
|
2021-12-20 18:43:46 +00:00
|
|
|
aiString textureRoughness;
|
|
|
|
aiString textureMetallic;
|
|
|
|
aiString textureSheen;
|
|
|
|
aiString textureRMA;
|
2016-10-07 07:19:10 +00:00
|
|
|
|
|
|
|
enum TextureType {
|
2015-05-19 03:57:13 +00:00
|
|
|
TextureDiffuseType = 0,
|
|
|
|
TextureSpecularType,
|
|
|
|
TextureAmbientType,
|
|
|
|
TextureEmissiveType,
|
|
|
|
TextureBumpType,
|
|
|
|
TextureNormalType,
|
2015-10-15 13:46:35 +00:00
|
|
|
TextureReflectionSphereType,
|
|
|
|
TextureReflectionCubeTopType,
|
|
|
|
TextureReflectionCubeBottomType,
|
|
|
|
TextureReflectionCubeFrontType,
|
|
|
|
TextureReflectionCubeBackType,
|
|
|
|
TextureReflectionCubeLeftType,
|
|
|
|
TextureReflectionCubeRightType,
|
2015-05-19 03:57:13 +00:00
|
|
|
TextureSpecularityType,
|
|
|
|
TextureOpacityType,
|
|
|
|
TextureDispType,
|
2021-12-20 18:43:46 +00:00
|
|
|
TextureRoughnessType,
|
|
|
|
TextureMetallicType,
|
|
|
|
TextureSheenType,
|
|
|
|
TextureRMAType,
|
2015-05-19 03:57:13 +00:00
|
|
|
TextureTypeCount
|
|
|
|
};
|
|
|
|
bool clamp[TextureTypeCount];
|
|
|
|
|
|
|
|
//! Ambient color
|
|
|
|
aiColor3D ambient;
|
|
|
|
//! Diffuse color
|
|
|
|
aiColor3D diffuse;
|
|
|
|
//! Specular color
|
|
|
|
aiColor3D specular;
|
|
|
|
//! Emissive color
|
|
|
|
aiColor3D emissive;
|
|
|
|
//! Alpha value
|
2016-07-16 02:14:36 +00:00
|
|
|
ai_real alpha;
|
2015-05-19 03:57:13 +00:00
|
|
|
//! Shineness factor
|
2016-07-16 02:14:36 +00:00
|
|
|
ai_real shineness;
|
2015-05-19 03:57:13 +00:00
|
|
|
//! Illumination model
|
|
|
|
int illumination_model;
|
|
|
|
//! Index of refraction
|
2016-07-16 02:14:36 +00:00
|
|
|
ai_real ior;
|
2017-01-13 01:11:17 +00:00
|
|
|
//! Transparency color
|
|
|
|
aiColor3D transparent;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2021-12-20 18:43:46 +00:00
|
|
|
//! PBR Roughness
|
2022-03-11 21:29:59 +00:00
|
|
|
Maybe<ai_real> roughness;
|
2021-12-20 18:43:46 +00:00
|
|
|
//! PBR Metallic
|
2022-03-11 21:29:59 +00:00
|
|
|
Maybe<ai_real> metallic;
|
2021-12-20 18:43:46 +00:00
|
|
|
//! PBR Metallic
|
2022-03-11 21:29:59 +00:00
|
|
|
Maybe<aiColor3D> sheen;
|
2021-12-20 18:43:46 +00:00
|
|
|
//! PBR Clearcoat Thickness
|
2022-03-11 21:29:59 +00:00
|
|
|
Maybe<ai_real> clearcoat_thickness;
|
2021-12-20 18:43:46 +00:00
|
|
|
//! PBR Clearcoat Rougness
|
2022-03-11 21:29:59 +00:00
|
|
|
Maybe<ai_real> clearcoat_roughness;
|
2021-12-20 18:43:46 +00:00
|
|
|
//! PBR Anisotropy
|
|
|
|
ai_real anisotropy;
|
|
|
|
|
2022-02-18 05:10:46 +00:00
|
|
|
//! bump map multipler (normal map scalar)(-bm)
|
|
|
|
ai_real bump_multiplier;
|
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
//! Constructor
|
2020-03-15 09:21:08 +00:00
|
|
|
Material() :
|
2020-03-15 09:28:37 +00:00
|
|
|
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)),
|
2021-12-20 18:43:46 +00:00
|
|
|
transparent(ai_real(1.0), ai_real(1.0), ai_real(1.0)),
|
2022-03-11 21:29:59 +00:00
|
|
|
roughness(),
|
|
|
|
metallic(),
|
|
|
|
sheen(),
|
|
|
|
clearcoat_thickness(),
|
|
|
|
clearcoat_roughness(),
|
2022-02-18 05:10:46 +00:00
|
|
|
anisotropy(ai_real(0.0)),
|
|
|
|
bump_multiplier(ai_real(1.0)) {
|
2020-03-15 09:28:37 +00:00
|
|
|
std::fill_n(clamp, static_cast<unsigned int>(TextureTypeCount), false);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Destructor
|
2020-02-18 16:50:48 +00:00
|
|
|
~Material() = default;
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:57:13 +00:00
|
|
|
//! \struct Mesh
|
|
|
|
//! \brief Data structure to store a mesh
|
2016-11-09 19:09:45 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-07-09 18:15:44 +00:00
|
|
|
struct Mesh {
|
2015-05-19 03:57:13 +00:00
|
|
|
static const unsigned int NoMaterial = ~0u;
|
2015-07-09 18:15:44 +00:00
|
|
|
/// The name for the mesh
|
|
|
|
std::string m_name;
|
2015-05-19 03:57:13 +00:00
|
|
|
/// Array with pointer to all stored faces
|
2022-07-30 19:52:33 +00:00
|
|
|
std::vector<Face*> m_Faces;
|
2015-05-19 03:57:13 +00:00
|
|
|
/// Assigned material
|
|
|
|
Material *m_pMaterial;
|
|
|
|
/// Number of stored indices.
|
|
|
|
unsigned int m_uiNumIndices;
|
|
|
|
/// Number of UV
|
2020-03-15 09:21:08 +00:00
|
|
|
unsigned int m_uiUVCoordinates[AI_MAX_NUMBER_OF_TEXTURECOORDS];
|
2015-05-19 03:57:13 +00:00
|
|
|
/// Material index.
|
|
|
|
unsigned int m_uiMaterialIndex;
|
|
|
|
/// True, if normals are stored.
|
|
|
|
bool m_hasNormals;
|
2015-07-09 18:15:44 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
/// Constructor
|
2020-03-15 09:21:08 +00:00
|
|
|
explicit Mesh(const std::string &name) :
|
2020-06-23 19:05:42 +00:00
|
|
|
m_name(name),
|
|
|
|
m_pMaterial(nullptr),
|
|
|
|
m_uiNumIndices(0),
|
|
|
|
m_uiMaterialIndex(NoMaterial),
|
|
|
|
m_hasNormals(false) {
|
2020-03-15 09:21:08 +00:00
|
|
|
memset(m_uiUVCoordinates, 0, sizeof(unsigned int) * AI_MAX_NUMBER_OF_TEXTURECOORDS);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Destructor
|
2016-11-09 19:09:45 +00:00
|
|
|
~Mesh() {
|
2022-07-31 11:37:42 +00:00
|
|
|
for (std::vector<Face *>::iterator it = m_Faces.begin();
|
2020-03-15 09:21:08 +00:00
|
|
|
it != m_Faces.end(); ++it) {
|
2015-05-19 03:57:13 +00:00
|
|
|
delete *it;
|
2022-07-31 11:37:42 +00:00
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:57:13 +00:00
|
|
|
//! \struct Model
|
2021-10-05 08:59:43 +00:00
|
|
|
//! \brief Data structure to store all obj-specific model data
|
2016-11-09 19:09:45 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
struct Model {
|
2021-09-13 20:38:20 +00:00
|
|
|
using GroupMap = std::map<std::string, std::vector<unsigned int> *>;
|
|
|
|
using GroupMapIt = std::map<std::string, std::vector<unsigned int> *>::iterator;
|
|
|
|
using ConstGroupMapIt = std::map<std::string, std::vector<unsigned int> *>::const_iterator;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
//! Model name
|
2022-07-31 18:54:58 +00:00
|
|
|
std::string mModelName;
|
2015-05-19 03:57:13 +00:00
|
|
|
//! List ob assigned objects
|
2022-07-31 18:54:58 +00:00
|
|
|
std::vector<Object *> mObjects;
|
2015-05-19 03:57:13 +00:00
|
|
|
//! Pointer to current object
|
2022-07-31 18:54:58 +00:00
|
|
|
ObjFile::Object *mCurrentObject;
|
2015-05-19 03:57:13 +00:00
|
|
|
//! Pointer to current material
|
2022-07-31 18:54:58 +00:00
|
|
|
ObjFile::Material *mCurrentMaterial;
|
2015-05-19 03:57:13 +00:00
|
|
|
//! Pointer to default material
|
2022-07-31 18:54:58 +00:00
|
|
|
ObjFile::Material *mDefaultMaterial;
|
2015-05-19 03:57:13 +00:00
|
|
|
//! Vector with all generated materials
|
2022-07-31 18:54:58 +00:00
|
|
|
std::vector<std::string> mMaterialLib;
|
2015-05-19 03:57:13 +00:00
|
|
|
//! Vector with all generated vertices
|
2022-07-31 18:54:58 +00:00
|
|
|
std::vector<aiVector3D> mVertices;
|
2015-05-19 03:57:13 +00:00
|
|
|
//! vector with all generated normals
|
2022-07-31 18:54:58 +00:00
|
|
|
std::vector<aiVector3D> mNormals;
|
2016-06-28 00:08:22 +00:00
|
|
|
//! vector with all vertex colors
|
2022-07-31 18:54:58 +00:00
|
|
|
std::vector<aiVector3D> mVertexColors;
|
2015-05-19 03:57:13 +00:00
|
|
|
//! Group map
|
2022-07-31 18:54:58 +00:00
|
|
|
GroupMap mGroups;
|
2015-05-19 03:57:13 +00:00
|
|
|
//! Group to face id assignment
|
2022-07-31 18:54:58 +00:00
|
|
|
std::vector<unsigned int> *mGroupFaceIDs;
|
2015-05-19 03:57:13 +00:00
|
|
|
//! Active group
|
2022-07-31 18:54:58 +00:00
|
|
|
std::string mActiveGroup;
|
2015-05-19 03:57:13 +00:00
|
|
|
//! Vector with generated texture coordinates
|
2022-07-31 18:54:58 +00:00
|
|
|
std::vector<aiVector3D> mTextureCoord;
|
2019-03-15 21:43:12 +00:00
|
|
|
//! Maximum dimension of texture coordinates
|
2022-07-31 18:54:58 +00:00
|
|
|
unsigned int mTextureCoordDim;
|
2015-05-19 03:57:13 +00:00
|
|
|
//! Current mesh instance
|
2022-07-31 18:54:58 +00:00
|
|
|
Mesh *mCurrentMesh;
|
2015-05-19 03:57:13 +00:00
|
|
|
//! Vector with stored meshes
|
2022-07-31 18:54:58 +00:00
|
|
|
std::vector<Mesh *> mMeshes;
|
2015-05-19 03:57:13 +00:00
|
|
|
//! Material map
|
2022-07-31 18:54:58 +00:00
|
|
|
std::map<std::string, Material*> mMaterialMap;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
//! \brief The default class constructor
|
|
|
|
Model() :
|
2022-07-31 18:54:58 +00:00
|
|
|
mModelName(),
|
|
|
|
mCurrentObject(nullptr),
|
|
|
|
mCurrentMaterial(nullptr),
|
|
|
|
mDefaultMaterial(nullptr),
|
|
|
|
mGroupFaceIDs(nullptr),
|
|
|
|
mActiveGroup(),
|
|
|
|
mTextureCoordDim(0),
|
|
|
|
mCurrentMesh(nullptr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// empty
|
|
|
|
}
|
|
|
|
|
|
|
|
//! \brief The class destructor
|
2016-11-09 19:09:45 +00:00
|
|
|
~Model() {
|
2022-07-31 18:54:58 +00:00
|
|
|
for (auto & it : mObjects) {
|
2021-09-13 20:38:20 +00:00
|
|
|
delete it;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2022-07-31 18:54:58 +00:00
|
|
|
for (auto & Meshe : mMeshes) {
|
2021-09-13 20:38:20 +00:00
|
|
|
delete Meshe;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2022-07-31 18:54:58 +00:00
|
|
|
for (auto & Group : mGroups) {
|
2021-09-13 20:38:20 +00:00
|
|
|
delete Group.second;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2022-07-31 18:54:58 +00:00
|
|
|
for (auto & it : mMaterialMap) {
|
2021-09-13 20:38:20 +00:00
|
|
|
delete it.second;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
} // Namespace ObjFile
|
|
|
|
} // Namespace Assimp
|
|
|
|
|
2016-11-09 19:09:45 +00:00
|
|
|
#endif // OBJ_FILEDATA_H_INC
|