Apply Assimp clangformat to touched Collada files

pull/3188/head
RichardTea 2020-04-28 17:46:07 +01:00
parent a52b66f10d
commit 2c6ac23a4e
7 changed files with 2103 additions and 2770 deletions

File diff suppressed because it is too large Load Diff

View File

@ -47,29 +47,27 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define AI_COLLADAEXPORTER_H_INC #define AI_COLLADAEXPORTER_H_INC
#include <assimp/ai_assert.h> #include <assimp/ai_assert.h>
#include <assimp/light.h>
#include <assimp/material.h> #include <assimp/material.h>
#include <assimp/mesh.h> #include <assimp/mesh.h>
#include <assimp/light.h>
#include <assimp/Exporter.hpp> #include <assimp/Exporter.hpp>
#include <map>
#include <sstream> #include <sstream>
#include <vector> #include <vector>
#include <map>
#include <assimp/StringUtils.h> #include <assimp/StringUtils.h>
struct aiScene; struct aiScene;
struct aiNode; struct aiNode;
namespace Assimp namespace Assimp {
{
/// Helper class to export a given scene to a Collada file. Just for my personal /// Helper class to export a given scene to a Collada file. Just for my personal
/// comfort when implementing it. /// comfort when implementing it.
class ColladaExporter class ColladaExporter {
{
public: public:
/// Constructor for a specific scene to export /// Constructor for a specific scene to export
ColladaExporter( const aiScene* pScene, IOSystem* pIOSystem, const std::string& path, const std::string& file); ColladaExporter(const aiScene *pScene, IOSystem *pIOSystem, const std::string &path, const std::string &file);
/// Destructor /// Destructor
virtual ~ColladaExporter(); virtual ~ColladaExporter();
@ -107,43 +105,49 @@ protected:
void WriteControllerLibrary(); void WriteControllerLibrary();
/// Writes a skin controller of the given mesh /// Writes a skin controller of the given mesh
void WriteController( size_t pIndex); void WriteController(size_t pIndex);
/// Writes the geometry library /// Writes the geometry library
void WriteGeometryLibrary(); void WriteGeometryLibrary();
/// Writes the given mesh /// Writes the given mesh
void WriteGeometry( size_t pIndex); void WriteGeometry(size_t pIndex);
//enum FloatDataType { FloatType_Vector, FloatType_TexCoord2, FloatType_TexCoord3, FloatType_Color, FloatType_Mat4x4, FloatType_Weight }; //enum FloatDataType { FloatType_Vector, FloatType_TexCoord2, FloatType_TexCoord3, FloatType_Color, FloatType_Mat4x4, FloatType_Weight };
// customized to add animation related type // customized to add animation related type
enum FloatDataType { FloatType_Vector, FloatType_TexCoord2, FloatType_TexCoord3, FloatType_Color, FloatType_Mat4x4, FloatType_Weight, FloatType_Time }; enum FloatDataType { FloatType_Vector,
FloatType_TexCoord2,
FloatType_TexCoord3,
FloatType_Color,
FloatType_Mat4x4,
FloatType_Weight,
FloatType_Time };
/// Writes a float array of the given type /// Writes a float array of the given type
void WriteFloatArray( const std::string& pIdString, FloatDataType pType, const ai_real* pData, size_t pElementCount); void WriteFloatArray(const std::string &pIdString, FloatDataType pType, const ai_real *pData, size_t pElementCount);
/// Writes the scene library /// Writes the scene library
void WriteSceneLibrary(); void WriteSceneLibrary();
// customized, Writes the animation library // customized, Writes the animation library
void WriteAnimationsLibrary(); void WriteAnimationsLibrary();
void WriteAnimationLibrary( size_t pIndex); void WriteAnimationLibrary(size_t pIndex);
std::string mFoundSkeletonRootNodeID = "skeleton_root"; // will be replaced by found node id in the WriteNode call. std::string mFoundSkeletonRootNodeID = "skeleton_root"; // will be replaced by found node id in the WriteNode call.
/// Recursively writes the given node /// Recursively writes the given node
void WriteNode( const aiScene* scene, aiNode* pNode); void WriteNode(const aiScene *scene, aiNode *pNode);
/// Enters a new xml element, which increases the indentation /// Enters a new xml element, which increases the indentation
void PushTag() { startstr.append( " "); } void PushTag() { startstr.append(" "); }
/// Leaves an element, decreasing the indentation /// Leaves an element, decreasing the indentation
void PopTag() { void PopTag() {
ai_assert( startstr.length() > 1); ai_assert(startstr.length() > 1);
startstr.erase( startstr.length() - 2); startstr.erase(startstr.length() - 2);
} }
/// Creates a mesh ID for the given mesh /// Creates a mesh ID for the given mesh
std::string GetMeshId( size_t pIndex) const { std::string GetMeshId(size_t pIndex) const {
return std::string( "meshId" ) + to_string(pIndex); return std::string("meshId") + to_string(pIndex);
} }
public: public:
@ -151,7 +155,7 @@ public:
std::stringstream mOutput; std::stringstream mOutput;
/// The IOSystem for output /// The IOSystem for output
IOSystem* mIOSystem; IOSystem *mIOSystem;
/// Path of the directory where the scene will be exported /// Path of the directory where the scene will be exported
const std::string mPath; const std::string mPath;
@ -160,7 +164,7 @@ public:
const std::string mFile; const std::string mFile;
/// The scene to be written /// The scene to be written
const aiScene* mScene; const aiScene *mScene;
bool mSceneOwned; bool mSceneOwned;
/// current line start string, contains the current indentation for simple stream insertion /// current line start string, contains the current indentation for simple stream insertion
@ -168,55 +172,54 @@ public:
/// current line end string for simple stream insertion /// current line end string for simple stream insertion
std::string endstr; std::string endstr;
// pair of color and texture - texture precedences color // pair of color and texture - texture precedences color
struct Surface struct Surface {
{ bool exist;
bool exist; aiColor4D color;
aiColor4D color; std::string texture;
std::string texture; size_t channel;
size_t channel; Surface() {
Surface() { exist = false; channel = 0; } exist = false;
}; channel = 0;
}
};
struct Property struct Property {
{ bool exist;
bool exist; ai_real value;
ai_real value; Property() :
Property() exist(false),
: exist(false) value(0.0) {}
, value(0.0) };
{}
};
// summarize a material in an convenient way. // summarize a material in an convenient way.
struct Material struct Material {
{ std::string name;
std::string name; std::string shading_model;
std::string shading_model; Surface ambient, diffuse, specular, emissive, reflective, transparent, normal;
Surface ambient, diffuse, specular, emissive, reflective, transparent, normal; Property shininess, transparency, index_refraction;
Property shininess, transparency, index_refraction;
Material() {} Material() {}
}; };
std::vector<Material> materials; std::vector<Material> materials;
std::map<unsigned int, std::string> textures; std::map<unsigned int, std::string> textures;
public: public:
/// Dammit C++ - y u no compile two-pass? No I have to add all methods below the struct definitions /// Dammit C++ - y u no compile two-pass? No I have to add all methods below the struct definitions
/// Reads a single surface entry from the given material keys /// Reads a single surface entry from the given material keys
void ReadMaterialSurface( Surface& poSurface, const aiMaterial* pSrcMat, aiTextureType pTexture, const char* pKey, size_t pType, size_t pIndex); void ReadMaterialSurface(Surface &poSurface, const aiMaterial *pSrcMat, aiTextureType pTexture, const char *pKey, size_t pType, size_t pIndex);
/// Writes an image entry for the given surface /// Writes an image entry for the given surface
void WriteImageEntry( const Surface& pSurface, const std::string& pNameAdd); void WriteImageEntry(const Surface &pSurface, const std::string &pNameAdd);
/// Writes the two parameters necessary for referencing a texture in an effect entry /// Writes the two parameters necessary for referencing a texture in an effect entry
void WriteTextureParamEntry( const Surface& pSurface, const std::string& pTypeName, const std::string& pMatName); void WriteTextureParamEntry(const Surface &pSurface, const std::string &pTypeName, const std::string &pMatName);
/// Writes a color-or-texture entry into an effect definition /// Writes a color-or-texture entry into an effect definition
void WriteTextureColorEntry( const Surface& pSurface, const std::string& pTypeName, const std::string& pImageName); void WriteTextureColorEntry(const Surface &pSurface, const std::string &pTypeName, const std::string &pImageName);
/// Writes a scalar property /// Writes a scalar property
void WriteFloatEntry( const Property& pProperty, const std::string& pTypeName); void WriteFloatEntry(const Property &pProperty, const std::string &pTypeName);
}; };
} } // namespace Assimp
#endif // !! AI_COLLADAEXPORTER_H_INC #endif // !! AI_COLLADAEXPORTER_H_INC

View File

@ -43,8 +43,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "ColladaHelper.h" #include "ColladaHelper.h"
#include <assimp/commonMetaData.h>
#include <assimp/ParsingUtils.h> #include <assimp/ParsingUtils.h>
#include <assimp/commonMetaData.h>
namespace Assimp { namespace Assimp {
namespace Collada { namespace Collada {
@ -63,42 +63,35 @@ const MetaKeyPairVector &GetColladaAssimpMetaKeys() {
const MetaKeyPairVector MakeColladaAssimpMetaKeysCamelCase() { const MetaKeyPairVector MakeColladaAssimpMetaKeysCamelCase() {
MetaKeyPairVector result = MakeColladaAssimpMetaKeys(); MetaKeyPairVector result = MakeColladaAssimpMetaKeys();
for (auto &val : result) for (auto &val : result) {
{
ToCamelCase(val.first); ToCamelCase(val.first);
} }
return result; return result;
}; };
const MetaKeyPairVector &GetColladaAssimpMetaKeysCamelCase() const MetaKeyPairVector &GetColladaAssimpMetaKeysCamelCase() {
{
static const MetaKeyPairVector result = MakeColladaAssimpMetaKeysCamelCase(); static const MetaKeyPairVector result = MakeColladaAssimpMetaKeysCamelCase();
return result; return result;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Convert underscore_separated to CamelCase: "authoring_tool" becomes "AuthoringTool" // Convert underscore_separated to CamelCase: "authoring_tool" becomes "AuthoringTool"
void ToCamelCase(std::string &text) void ToCamelCase(std::string &text) {
{
if (text.empty()) if (text.empty())
return; return;
// Capitalise first character // Capitalise first character
auto it = text.begin(); auto it = text.begin();
(*it) = ToUpper(*it); (*it) = ToUpper(*it);
++it; ++it;
for (/*started above*/ ; it != text.end(); /*iterated below*/) for (/*started above*/; it != text.end(); /*iterated below*/) {
{ if ((*it) == '_') {
if ((*it) == '_')
{
it = text.erase(it); it = text.erase(it);
if (it != text.end()) if (it != text.end())
(*it) = ToUpper(*it); (*it) = ToUpper(*it);
} } else {
else
{
// Make lower case // Make lower case
(*it) = ToLower(*it); (*it) = ToLower(*it);
++it; ++it;
} }
} }
} }

View File

@ -45,31 +45,28 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef AI_COLLADAHELPER_H_INC #ifndef AI_COLLADAHELPER_H_INC
#define AI_COLLADAHELPER_H_INC #define AI_COLLADAHELPER_H_INC
#include <map>
#include <vector>
#include <set>
#include <stdint.h>
#include <assimp/light.h> #include <assimp/light.h>
#include <assimp/mesh.h>
#include <assimp/material.h> #include <assimp/material.h>
#include <assimp/mesh.h>
#include <stdint.h>
#include <map>
#include <set>
#include <vector>
struct aiMaterial; struct aiMaterial;
namespace Assimp { namespace Assimp {
namespace Collada { namespace Collada {
/** Collada file versions which evolved during the years ... */ /** Collada file versions which evolved during the years ... */
enum FormatVersion enum FormatVersion {
{
FV_1_5_n, FV_1_5_n,
FV_1_4_n, FV_1_4_n,
FV_1_3_n FV_1_3_n
}; };
/** Transformation types that can be applied to a node */ /** Transformation types that can be applied to a node */
enum TransformType enum TransformType {
{
TF_LOOKAT, TF_LOOKAT,
TF_ROTATE, TF_ROTATE,
TF_TRANSLATE, TF_TRANSLATE,
@ -79,10 +76,9 @@ enum TransformType
}; };
/** Different types of input data to a vertex or face */ /** Different types of input data to a vertex or face */
enum InputType enum InputType {
{
IT_Invalid, IT_Invalid,
IT_Vertex, // special type for per-index data referring to the <vertices> element carrying the per-vertex data. IT_Vertex, // special type for per-index data referring to the <vertices> element carrying the per-vertex data.
IT_Position, IT_Position,
IT_Normal, IT_Normal,
IT_Texcoord, IT_Texcoord,
@ -92,15 +88,13 @@ enum InputType
}; };
/** Supported controller types */ /** Supported controller types */
enum ControllerType enum ControllerType {
{
Skin, Skin,
Morph Morph
}; };
/** Supported morph methods */ /** Supported morph methods */
enum MorphMethod enum MorphMethod {
{
Normalized, Normalized,
Relative Relative
}; };
@ -118,24 +112,21 @@ const MetaKeyPairVector &GetColladaAssimpMetaKeysCamelCase();
void ToCamelCase(std::string &text); void ToCamelCase(std::string &text);
/** Contains all data for one of the different transformation types */ /** Contains all data for one of the different transformation types */
struct Transform struct Transform {
{ std::string mID; ///< SID of the transform step, by which anim channels address their target node
std::string mID; ///< SID of the transform step, by which anim channels address their target node
TransformType mType; TransformType mType;
ai_real f[16]; ///< Interpretation of data depends on the type of the transformation ai_real f[16]; ///< Interpretation of data depends on the type of the transformation
}; };
/** A collada camera. */ /** A collada camera. */
struct Camera struct Camera {
{ Camera() :
Camera() mOrtho(false),
: mOrtho (false) mHorFov(10e10f),
, mHorFov (10e10f) mVerFov(10e10f),
, mVerFov (10e10f) mAspect(10e10f),
, mAspect (10e10f) mZNear(0.1f),
, mZNear (0.1f) mZFar(1000.f) {}
, mZFar (1000.f)
{}
// Name of camera // Name of camera
std::string mName; std::string mName;
@ -159,19 +150,17 @@ struct Camera
#define ASSIMP_COLLADA_LIGHT_ANGLE_NOT_SET 1e9f #define ASSIMP_COLLADA_LIGHT_ANGLE_NOT_SET 1e9f
/** A collada light source. */ /** A collada light source. */
struct Light struct Light {
{ Light() :
Light() mType(aiLightSource_UNDEFINED),
: mType (aiLightSource_UNDEFINED) mAttConstant(1.f),
, mAttConstant (1.f) mAttLinear(0.f),
, mAttLinear (0.f) mAttQuadratic(0.f),
, mAttQuadratic (0.f) mFalloffAngle(180.f),
, mFalloffAngle (180.f) mFalloffExponent(0.f),
, mFalloffExponent (0.f) mPenumbraAngle(ASSIMP_COLLADA_LIGHT_ANGLE_NOT_SET),
, mPenumbraAngle (ASSIMP_COLLADA_LIGHT_ANGLE_NOT_SET) mOuterAngle(ASSIMP_COLLADA_LIGHT_ANGLE_NOT_SET),
, mOuterAngle (ASSIMP_COLLADA_LIGHT_ANGLE_NOT_SET) mIntensity(1.f) {}
, mIntensity (1.f)
{}
//! Type of the light source aiLightSourceType + ambient //! Type of the light source aiLightSourceType + ambient
unsigned int mType; unsigned int mType;
@ -180,7 +169,7 @@ struct Light
aiColor3D mColor; aiColor3D mColor;
//! Light attenuation //! Light attenuation
ai_real mAttConstant,mAttLinear,mAttQuadratic; ai_real mAttConstant, mAttLinear, mAttQuadratic;
//! Spot light falloff //! Spot light falloff
ai_real mFalloffAngle; ai_real mFalloffAngle;
@ -198,12 +187,10 @@ struct Light
}; };
/** Short vertex index description */ /** Short vertex index description */
struct InputSemanticMapEntry struct InputSemanticMapEntry {
{ InputSemanticMapEntry() :
InputSemanticMapEntry() mSet(0),
: mSet(0) mType(IT_Invalid) {}
, mType(IT_Invalid)
{}
//! Index of set, optional //! Index of set, optional
unsigned int mSet; unsigned int mSet;
@ -213,8 +200,7 @@ struct InputSemanticMapEntry
}; };
/** Table to map from effect to vertex input semantics */ /** Table to map from effect to vertex input semantics */
struct SemanticMappingTable struct SemanticMappingTable {
{
//! Name of material //! Name of material
std::string mMatName; std::string mMatName;
@ -222,7 +208,7 @@ struct SemanticMappingTable
std::map<std::string, InputSemanticMapEntry> mMap; std::map<std::string, InputSemanticMapEntry> mMap;
//! For std::find //! For std::find
bool operator == (const std::string& s) const { bool operator==(const std::string &s) const {
return s == mMatName; return s == mMatName;
} }
}; };
@ -230,8 +216,7 @@ struct SemanticMappingTable
/** A reference to a mesh inside a node, including materials assigned to the various subgroups. /** A reference to a mesh inside a node, including materials assigned to the various subgroups.
* The ID refers to either a mesh or a controller which specifies the mesh * The ID refers to either a mesh or a controller which specifies the mesh
*/ */
struct MeshInstance struct MeshInstance {
{
///< ID of the mesh or controller to be instanced ///< ID of the mesh or controller to be instanced
std::string mMeshOrController; std::string mMeshOrController;
@ -240,34 +225,30 @@ struct MeshInstance
}; };
/** A reference to a camera inside a node*/ /** A reference to a camera inside a node*/
struct CameraInstance struct CameraInstance {
{ ///< ID of the camera
///< ID of the camera
std::string mCamera; std::string mCamera;
}; };
/** A reference to a light inside a node*/ /** A reference to a light inside a node*/
struct LightInstance struct LightInstance {
{ ///< ID of the camera
///< ID of the camera
std::string mLight; std::string mLight;
}; };
/** A reference to a node inside a node*/ /** A reference to a node inside a node*/
struct NodeInstance struct NodeInstance {
{ ///< ID of the node
///< ID of the node
std::string mNode; std::string mNode;
}; };
/** A node in a scene hierarchy */ /** A node in a scene hierarchy */
struct Node struct Node {
{
std::string mName; std::string mName;
std::string mID; std::string mID;
std::string mSID; std::string mSID;
Node* mParent; Node *mParent;
std::vector<Node*> mChildren; std::vector<Node *> mChildren;
/** Operations in order to calculate the resulting transformation to parent. */ /** Operations in order to calculate the resulting transformation to parent. */
std::vector<Transform> mTransforms; std::vector<Transform> mTransforms;
@ -288,77 +269,78 @@ struct Node
std::string mPrimaryCamera; std::string mPrimaryCamera;
//! Constructor. Begin with a zero parent //! Constructor. Begin with a zero parent
Node() Node() :
: mParent( nullptr ){ mParent(nullptr) {
// empty // empty
} }
//! Destructor: delete all children subsequently //! Destructor: delete all children subsequently
~Node() { ~Node() {
for( std::vector<Node*>::iterator it = mChildren.begin(); it != mChildren.end(); ++it) for (std::vector<Node *>::iterator it = mChildren.begin(); it != mChildren.end(); ++it)
delete *it; delete *it;
} }
}; };
/** Data source array: either floats or strings */ /** Data source array: either floats or strings */
struct Data struct Data {
{
bool mIsStringArray; bool mIsStringArray;
std::vector<ai_real> mValues; std::vector<ai_real> mValues;
std::vector<std::string> mStrings; std::vector<std::string> mStrings;
}; };
/** Accessor to a data array */ /** Accessor to a data array */
struct Accessor struct Accessor {
{ size_t mCount; // in number of objects
size_t mCount; // in number of objects size_t mSize; // size of an object, in elements (floats or strings, mostly 1)
size_t mSize; // size of an object, in elements (floats or strings, mostly 1) size_t mOffset; // in number of values
size_t mOffset; // in number of values size_t mStride; // Stride in number of values
size_t mStride; // Stride in number of values
std::vector<std::string> mParams; // names of the data streams in the accessors. Empty string tells to ignore. std::vector<std::string> mParams; // names of the data streams in the accessors. Empty string tells to ignore.
size_t mSubOffset[4]; // Suboffset inside the object for the common 4 elements. For a vector, that's XYZ, for a color RGBA and so on. size_t mSubOffset[4]; // Suboffset inside the object for the common 4 elements. For a vector, that's XYZ, for a color RGBA and so on.
// For example, SubOffset[0] denotes which of the values inside the object is the vector X component. // For example, SubOffset[0] denotes which of the values inside the object is the vector X component.
std::string mSource; // URL of the source array std::string mSource; // URL of the source array
mutable const Data* mData; // Pointer to the source array, if resolved. NULL else mutable const Data *mData; // Pointer to the source array, if resolved. NULL else
Accessor() Accessor() {
{ mCount = 0;
mCount = 0; mSize = 0; mOffset = 0; mStride = 0; mData = NULL; mSize = 0;
mOffset = 0;
mStride = 0;
mData = NULL;
mSubOffset[0] = mSubOffset[1] = mSubOffset[2] = mSubOffset[3] = 0; mSubOffset[0] = mSubOffset[1] = mSubOffset[2] = mSubOffset[3] = 0;
} }
}; };
/** A single face in a mesh */ /** A single face in a mesh */
struct Face struct Face {
{
std::vector<size_t> mIndices; std::vector<size_t> mIndices;
}; };
/** An input channel for mesh data, referring to a single accessor */ /** An input channel for mesh data, referring to a single accessor */
struct InputChannel struct InputChannel {
{ InputType mType; // Type of the data
InputType mType; // Type of the data size_t mIndex; // Optional index, if multiple sets of the same data type are given
size_t mIndex; // Optional index, if multiple sets of the same data type are given size_t mOffset; // Index offset in the indices array of per-face indices. Don't ask, can't explain that any better.
size_t mOffset; // Index offset in the indices array of per-face indices. Don't ask, can't explain that any better.
std::string mAccessor; // ID of the accessor where to read the actual values from. std::string mAccessor; // ID of the accessor where to read the actual values from.
mutable const Accessor* mResolved; // Pointer to the accessor, if resolved. NULL else mutable const Accessor *mResolved; // Pointer to the accessor, if resolved. NULL else
InputChannel() { mType = IT_Invalid; mIndex = 0; mOffset = 0; mResolved = NULL; } InputChannel() {
mType = IT_Invalid;
mIndex = 0;
mOffset = 0;
mResolved = NULL;
}
}; };
/** Subset of a mesh with a certain material */ /** Subset of a mesh with a certain material */
struct SubMesh struct SubMesh {
{
std::string mMaterial; ///< subgroup identifier std::string mMaterial; ///< subgroup identifier
size_t mNumFaces; ///< number of faces in this submesh size_t mNumFaces; ///< number of faces in this submesh
}; };
/** Contains data for a single mesh */ /** Contains data for a single mesh */
struct Mesh struct Mesh {
{ Mesh() {
Mesh() for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i)
{
for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS;++i)
mNumUVComponents[i] = 2; mNumUVComponents[i] = 2;
} }
@ -377,7 +359,7 @@ struct Mesh
std::vector<aiVector3D> mTangents; std::vector<aiVector3D> mTangents;
std::vector<aiVector3D> mBitangents; std::vector<aiVector3D> mBitangents;
std::vector<aiVector3D> mTexCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS]; std::vector<aiVector3D> mTexCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS];
std::vector<aiColor4D> mColors[AI_MAX_NUMBER_OF_COLOR_SETS]; std::vector<aiColor4D> mColors[AI_MAX_NUMBER_OF_COLOR_SETS];
unsigned int mNumUVComponents[AI_MAX_NUMBER_OF_TEXTURECOORDS]; unsigned int mNumUVComponents[AI_MAX_NUMBER_OF_TEXTURECOORDS];
@ -394,8 +376,7 @@ struct Mesh
}; };
/** Which type of primitives the ReadPrimitives() function is going to read */ /** Which type of primitives the ReadPrimitives() function is going to read */
enum PrimitiveType enum PrimitiveType {
{
Prim_Invalid, Prim_Invalid,
Prim_Lines, Prim_Lines,
Prim_LineStrip, Prim_LineStrip,
@ -407,8 +388,7 @@ enum PrimitiveType
}; };
/** A skeleton controller to deform a mesh with the use of joints */ /** A skeleton controller to deform a mesh with the use of joints */
struct Controller struct Controller {
{
// controller type // controller type
ControllerType mType; ControllerType mType;
@ -436,36 +416,32 @@ struct Controller
std::vector<size_t> mWeightCounts; std::vector<size_t> mWeightCounts;
// JointIndex-WeightIndex pairs for all vertices // JointIndex-WeightIndex pairs for all vertices
std::vector< std::pair<size_t, size_t> > mWeights; std::vector<std::pair<size_t, size_t>> mWeights;
std::string mMorphTarget; std::string mMorphTarget;
std::string mMorphWeight; std::string mMorphWeight;
}; };
/** A collada material. Pretty much the only member is a reference to an effect. */ /** A collada material. Pretty much the only member is a reference to an effect. */
struct Material struct Material {
{
std::string mName; std::string mName;
std::string mEffect; std::string mEffect;
}; };
/** Type of the effect param */ /** Type of the effect param */
enum ParamType enum ParamType {
{
Param_Sampler, Param_Sampler,
Param_Surface Param_Surface
}; };
/** A param for an effect. Might be of several types, but they all just refer to each other, so I summarize them */ /** A param for an effect. Might be of several types, but they all just refer to each other, so I summarize them */
struct EffectParam struct EffectParam {
{
ParamType mType; ParamType mType;
std::string mReference; // to which other thing the param is referring to. std::string mReference; // to which other thing the param is referring to.
}; };
/** Shading type supported by the standard effect spec of Collada */ /** Shading type supported by the standard effect spec of Collada */
enum ShadeType enum ShadeType {
{
Shade_Invalid, Shade_Invalid,
Shade_Constant, Shade_Constant,
Shade_Lambert, Shade_Lambert,
@ -474,18 +450,16 @@ enum ShadeType
}; };
/** Represents a texture sampler in collada */ /** Represents a texture sampler in collada */
struct Sampler struct Sampler {
{ Sampler() :
Sampler() mWrapU(true),
: mWrapU (true) mWrapV(true),
, mWrapV (true) mMirrorU(),
, mMirrorU () mMirrorV(),
, mMirrorV () mOp(aiTextureOp_Multiply),
, mOp (aiTextureOp_Multiply) mUVId(UINT_MAX),
, mUVId (UINT_MAX) mWeighting(1.f),
, mWeighting (1.f) mMixWithPrevious(1.f) {}
, mMixWithPrevious (1.f)
{}
/** Name of image reference /** Name of image reference
*/ */
@ -537,18 +511,17 @@ struct Sampler
/** A collada effect. Can contain about anything according to the Collada spec, /** A collada effect. Can contain about anything according to the Collada spec,
but we limit our version to a reasonable subset. */ but we limit our version to a reasonable subset. */
struct Effect struct Effect {
{
// Shading mode // Shading mode
ShadeType mShadeType; ShadeType mShadeType;
// Colors // Colors
aiColor4D mEmissive, mAmbient, mDiffuse, mSpecular, aiColor4D mEmissive, mAmbient, mDiffuse, mSpecular,
mTransparent, mReflective; mTransparent, mReflective;
// Textures // Textures
Sampler mTexEmissive, mTexAmbient, mTexDiffuse, mTexSpecular, Sampler mTexEmissive, mTexAmbient, mTexDiffuse, mTexSpecular,
mTexTransparent, mTexBump, mTexReflective; mTexTransparent, mTexBump, mTexReflective;
// Scalar factory // Scalar factory
ai_real mShininess, mRefractIndex, mReflectivity; ai_real mShininess, mRefractIndex, mReflectivity;
@ -566,30 +539,28 @@ struct Effect
// Double-sided? // Double-sided?
bool mDoubleSided, mWireframe, mFaceted; bool mDoubleSided, mWireframe, mFaceted;
Effect() Effect() :
: mShadeType (Shade_Phong) mShadeType(Shade_Phong),
, mEmissive ( 0, 0, 0, 1) mEmissive(0, 0, 0, 1),
, mAmbient ( 0.1f, 0.1f, 0.1f, 1) mAmbient(0.1f, 0.1f, 0.1f, 1),
, mDiffuse ( 0.6f, 0.6f, 0.6f, 1) mDiffuse(0.6f, 0.6f, 0.6f, 1),
, mSpecular ( 0.4f, 0.4f, 0.4f, 1) mSpecular(0.4f, 0.4f, 0.4f, 1),
, mTransparent ( 0, 0, 0, 1) mTransparent(0, 0, 0, 1),
, mShininess (10.0f) mShininess(10.0f),
, mRefractIndex (1.f) mRefractIndex(1.f),
, mReflectivity (0.f) mReflectivity(0.f),
, mTransparency (1.f) mTransparency(1.f),
, mHasTransparency (false) mHasTransparency(false),
, mRGBTransparency(false) mRGBTransparency(false),
, mInvertTransparency(false) mInvertTransparency(false),
, mDoubleSided (false) mDoubleSided(false),
, mWireframe (false) mWireframe(false),
, mFaceted (false) mFaceted(false) {
{
} }
}; };
/** An image, meaning texture */ /** An image, meaning texture */
struct Image struct Image {
{
std::string mFileName; std::string mFileName;
/** Embedded image data */ /** Embedded image data */
@ -600,8 +571,7 @@ struct Image
}; };
/** An animation channel. */ /** An animation channel. */
struct AnimationChannel struct AnimationChannel {
{
/** URL of the data to animate. Could be about anything, but we support only the /** URL of the data to animate. Could be about anything, but we support only the
* "NodeID/TransformID.SubElement" notation * "NodeID/TransformID.SubElement" notation
*/ */
@ -620,8 +590,7 @@ struct AnimationChannel
}; };
/** An animation. Container for 0-x animation channels or 0-x animations */ /** An animation. Container for 0-x animation channels or 0-x animations */
struct Animation struct Animation {
{
/** Anim name */ /** Anim name */
std::string mName; std::string mName;
@ -629,96 +598,86 @@ struct Animation
std::vector<AnimationChannel> mChannels; std::vector<AnimationChannel> mChannels;
/** the sub-animations, if any */ /** the sub-animations, if any */
std::vector<Animation*> mSubAnims; std::vector<Animation *> mSubAnims;
/** Destructor */ /** Destructor */
~Animation() ~Animation() {
{ for (std::vector<Animation *>::iterator it = mSubAnims.begin(); it != mSubAnims.end(); ++it)
for( std::vector<Animation*>::iterator it = mSubAnims.begin(); it != mSubAnims.end(); ++it)
delete *it; delete *it;
} }
/** Collect all channels in the animation hierarchy into a single channel list. */ /** Collect all channels in the animation hierarchy into a single channel list. */
void CollectChannelsRecursively(std::vector<AnimationChannel> &channels) void CollectChannelsRecursively(std::vector<AnimationChannel> &channels) {
{ channels.insert(channels.end(), mChannels.begin(), mChannels.end());
channels.insert(channels.end(), mChannels.begin(), mChannels.end());
for (std::vector<Animation*>::iterator it = mSubAnims.begin(); it != mSubAnims.end(); ++it) for (std::vector<Animation *>::iterator it = mSubAnims.begin(); it != mSubAnims.end(); ++it) {
{ Animation *pAnim = (*it);
Animation *pAnim = (*it);
pAnim->CollectChannelsRecursively(channels); pAnim->CollectChannelsRecursively(channels);
} }
} }
/** Combine all single-channel animations' channel into the same (parent) animation channel list. */ /** Combine all single-channel animations' channel into the same (parent) animation channel list. */
void CombineSingleChannelAnimations() void CombineSingleChannelAnimations() {
{ CombineSingleChannelAnimationsRecursively(this);
CombineSingleChannelAnimationsRecursively(this); }
}
void CombineSingleChannelAnimationsRecursively(Animation *pParent) void CombineSingleChannelAnimationsRecursively(Animation *pParent) {
{ std::set<std::string> childrenTargets;
std::set<std::string> childrenTargets; bool childrenAnimationsHaveDifferentChannels = true;
bool childrenAnimationsHaveDifferentChannels = true;
for (std::vector<Animation*>::iterator it = pParent->mSubAnims.begin(); it != pParent->mSubAnims.end();) for (std::vector<Animation *>::iterator it = pParent->mSubAnims.begin(); it != pParent->mSubAnims.end();) {
{ Animation *anim = *it;
Animation *anim = *it; CombineSingleChannelAnimationsRecursively(anim);
CombineSingleChannelAnimationsRecursively(anim);
if (childrenAnimationsHaveDifferentChannels && anim->mChannels.size() == 1 && if (childrenAnimationsHaveDifferentChannels && anim->mChannels.size() == 1 &&
childrenTargets.find(anim->mChannels[0].mTarget) == childrenTargets.end()) { childrenTargets.find(anim->mChannels[0].mTarget) == childrenTargets.end()) {
childrenTargets.insert(anim->mChannels[0].mTarget); childrenTargets.insert(anim->mChannels[0].mTarget);
} else { } else {
childrenAnimationsHaveDifferentChannels = false; childrenAnimationsHaveDifferentChannels = false;
} }
++it; ++it;
} }
// We only want to combine animations if they have different channels // We only want to combine animations if they have different channels
if (childrenAnimationsHaveDifferentChannels) if (childrenAnimationsHaveDifferentChannels) {
{ for (std::vector<Animation *>::iterator it = pParent->mSubAnims.begin(); it != pParent->mSubAnims.end();) {
for (std::vector<Animation*>::iterator it = pParent->mSubAnims.begin(); it != pParent->mSubAnims.end();) Animation *anim = *it;
{
Animation *anim = *it;
pParent->mChannels.push_back(anim->mChannels[0]); pParent->mChannels.push_back(anim->mChannels[0]);
it = pParent->mSubAnims.erase(it); it = pParent->mSubAnims.erase(it);
delete anim; delete anim;
continue; continue;
} }
} }
} }
}; };
/** Description of a collada animation channel which has been determined to affect the current node */ /** Description of a collada animation channel which has been determined to affect the current node */
struct ChannelEntry struct ChannelEntry {
{ const Collada::AnimationChannel *mChannel; ///> the source channel
const Collada::AnimationChannel* mChannel; ///> the source channel
std::string mTargetId; std::string mTargetId;
std::string mTransformId; // the ID of the transformation step of the node which is influenced std::string mTransformId; // the ID of the transformation step of the node which is influenced
size_t mTransformIndex; // Index into the node's transform chain to apply the channel to size_t mTransformIndex; // Index into the node's transform chain to apply the channel to
size_t mSubElement; // starting index inside the transform data size_t mSubElement; // starting index inside the transform data
// resolved data references // resolved data references
const Collada::Accessor* mTimeAccessor; ///> Collada accessor to the time values const Collada::Accessor *mTimeAccessor; ///> Collada accessor to the time values
const Collada::Data* mTimeData; ///> Source data array for the time values const Collada::Data *mTimeData; ///> Source data array for the time values
const Collada::Accessor* mValueAccessor; ///> Collada accessor to the key value values const Collada::Accessor *mValueAccessor; ///> Collada accessor to the key value values
const Collada::Data* mValueData; ///> Source datat array for the key value values const Collada::Data *mValueData; ///> Source datat array for the key value values
ChannelEntry() ChannelEntry() :
: mChannel() mChannel(),
, mTransformIndex() mTransformIndex(),
, mSubElement() mSubElement(),
, mTimeAccessor() mTimeAccessor(),
, mTimeData() mTimeData(),
, mValueAccessor() mValueAccessor(),
, mValueData() mValueData() {}
{}
}; };
} // end of namespace Collada } // end of namespace Collada

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -47,346 +47,345 @@
#ifndef AI_COLLADAPARSER_H_INC #ifndef AI_COLLADAPARSER_H_INC
#define AI_COLLADAPARSER_H_INC #define AI_COLLADAPARSER_H_INC
#include <assimp/irrXMLWrapper.h>
#include "ColladaHelper.h" #include "ColladaHelper.h"
#include <assimp/ai_assert.h>
#include <assimp/TinyFormatter.h> #include <assimp/TinyFormatter.h>
#include <assimp/ai_assert.h>
#include <assimp/irrXMLWrapper.h>
namespace Assimp namespace Assimp {
{ class ZipArchiveIOSystem;
class ZipArchiveIOSystem;
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
/** Parser helper class for the Collada loader. /** Parser helper class for the Collada loader.
* *
* Does all the XML reading and builds internal data structures from it, * Does all the XML reading and builds internal data structures from it,
* but leaves the resolving of all the references to the loader. * but leaves the resolving of all the references to the loader.
*/ */
class ColladaParser class ColladaParser {
{ friend class ColladaLoader;
friend class ColladaLoader;
/** Converts a path read from a collada file to the usual representation */ /** Converts a path read from a collada file to the usual representation */
static void UriDecodePath(aiString& ss); static void UriDecodePath(aiString &ss);
protected: protected:
/** Map for generic metadata as aiString */ /** Map for generic metadata as aiString */
typedef std::map<std::string, aiString> StringMetaData; typedef std::map<std::string, aiString> StringMetaData;
/** Constructor from XML file */ /** Constructor from XML file */
ColladaParser(IOSystem* pIOHandler, const std::string& pFile); ColladaParser(IOSystem *pIOHandler, const std::string &pFile);
/** Destructor */ /** Destructor */
~ColladaParser(); ~ColladaParser();
/** Attempts to read the ZAE manifest and returns the DAE to open */ /** Attempts to read the ZAE manifest and returns the DAE to open */
static std::string ReadZaeManifest(ZipArchiveIOSystem &zip_archive); static std::string ReadZaeManifest(ZipArchiveIOSystem &zip_archive);
/** Reads the contents of the file */ /** Reads the contents of the file */
void ReadContents(); void ReadContents();
/** Reads the structure of the file */ /** Reads the structure of the file */
void ReadStructure(); void ReadStructure();
/** Reads asset information such as coordinate system information and legal blah */ /** Reads asset information such as coordinate system information and legal blah */
void ReadAssetInfo(); void ReadAssetInfo();
/** Reads contributor information such as author and legal blah */ /** Reads contributor information such as author and legal blah */
void ReadContributorInfo(); void ReadContributorInfo();
/** Reads generic metadata into provided map and renames keys for Assimp */ /** Reads generic metadata into provided map and renames keys for Assimp */
void ReadMetaDataItem(StringMetaData &metadata); void ReadMetaDataItem(StringMetaData &metadata);
/** Reads the animation library */ /** Reads the animation library */
void ReadAnimationLibrary(); void ReadAnimationLibrary();
/** Reads the animation clip library */ /** Reads the animation clip library */
void ReadAnimationClipLibrary(); void ReadAnimationClipLibrary();
/** Unwrap controllers dependency hierarchy */ /** Unwrap controllers dependency hierarchy */
void PostProcessControllers(); void PostProcessControllers();
/** Re-build animations from animation clip library, if present, otherwise combine single-channel animations */
void PostProcessRootAnimations();
/** Reads an animation into the given parent structure */ /** Re-build animations from animation clip library, if present, otherwise combine single-channel animations */
void ReadAnimation( Collada::Animation* pParent); void PostProcessRootAnimations();
/** Reads an animation sampler into the given anim channel */ /** Reads an animation into the given parent structure */
void ReadAnimationSampler( Collada::AnimationChannel& pChannel); void ReadAnimation(Collada::Animation *pParent);
/** Reads the skeleton controller library */ /** Reads an animation sampler into the given anim channel */
void ReadControllerLibrary(); void ReadAnimationSampler(Collada::AnimationChannel &pChannel);
/** Reads a controller into the given mesh structure */ /** Reads the skeleton controller library */
void ReadController( Collada::Controller& pController); void ReadControllerLibrary();
/** Reads the joint definitions for the given controller */ /** Reads a controller into the given mesh structure */
void ReadControllerJoints( Collada::Controller& pController); void ReadController(Collada::Controller &pController);
/** Reads the joint weights for the given controller */ /** Reads the joint definitions for the given controller */
void ReadControllerWeights( Collada::Controller& pController); void ReadControllerJoints(Collada::Controller &pController);
/** Reads the image library contents */ /** Reads the joint weights for the given controller */
void ReadImageLibrary(); void ReadControllerWeights(Collada::Controller &pController);
/** Reads an image entry into the given image */ /** Reads the image library contents */
void ReadImage( Collada::Image& pImage); void ReadImageLibrary();
/** Reads the material library */ /** Reads an image entry into the given image */
void ReadMaterialLibrary(); void ReadImage(Collada::Image &pImage);
/** Reads a material entry into the given material */ /** Reads the material library */
void ReadMaterial( Collada::Material& pMaterial); void ReadMaterialLibrary();
/** Reads the camera library */ /** Reads a material entry into the given material */
void ReadCameraLibrary(); void ReadMaterial(Collada::Material &pMaterial);
/** Reads a camera entry into the given camera */ /** Reads the camera library */
void ReadCamera( Collada::Camera& pCamera); void ReadCameraLibrary();
/** Reads the light library */ /** Reads a camera entry into the given camera */
void ReadLightLibrary(); void ReadCamera(Collada::Camera &pCamera);
/** Reads a light entry into the given light */ /** Reads the light library */
void ReadLight( Collada::Light& pLight); void ReadLightLibrary();
/** Reads the effect library */ /** Reads a light entry into the given light */
void ReadEffectLibrary(); void ReadLight(Collada::Light &pLight);
/** Reads an effect entry into the given effect*/ /** Reads the effect library */
void ReadEffect( Collada::Effect& pEffect); void ReadEffectLibrary();
/** Reads an COMMON effect profile */ /** Reads an effect entry into the given effect*/
void ReadEffectProfileCommon( Collada::Effect& pEffect); void ReadEffect(Collada::Effect &pEffect);
/** Read sampler properties */ /** Reads an COMMON effect profile */
void ReadSamplerProperties( Collada::Sampler& pSampler); void ReadEffectProfileCommon(Collada::Effect &pEffect);
/** Reads an effect entry containing a color or a texture defining that color */ /** Read sampler properties */
void ReadEffectColor( aiColor4D& pColor, Collada::Sampler& pSampler); void ReadSamplerProperties(Collada::Sampler &pSampler);
/** Reads an effect entry containing a float */ /** Reads an effect entry containing a color or a texture defining that color */
void ReadEffectFloat( ai_real& pFloat); void ReadEffectColor(aiColor4D &pColor, Collada::Sampler &pSampler);
/** Reads an effect parameter specification of any kind */ /** Reads an effect entry containing a float */
void ReadEffectParam( Collada::EffectParam& pParam); void ReadEffectFloat(ai_real &pFloat);
/** Reads the geometry library contents */ /** Reads an effect parameter specification of any kind */
void ReadGeometryLibrary(); void ReadEffectParam(Collada::EffectParam &pParam);
/** Reads a geometry from the geometry library. */ /** Reads the geometry library contents */
void ReadGeometry( Collada::Mesh* pMesh); void ReadGeometryLibrary();
/** Reads a mesh from the geometry library */ /** Reads a geometry from the geometry library. */
void ReadMesh( Collada::Mesh* pMesh); void ReadGeometry(Collada::Mesh *pMesh);
/** Reads a source element - a combination of raw data and an accessor defining /** Reads a mesh from the geometry library */
void ReadMesh(Collada::Mesh *pMesh);
/** Reads a source element - a combination of raw data and an accessor defining
* things that should not be redefinable. Yes, that's another rant. * things that should not be redefinable. Yes, that's another rant.
*/ */
void ReadSource(); void ReadSource();
/** Reads a data array holding a number of elements, and stores it in the global library. /** Reads a data array holding a number of elements, and stores it in the global library.
* Currently supported are array of floats and arrays of strings. * Currently supported are array of floats and arrays of strings.
*/ */
void ReadDataArray(); void ReadDataArray();
/** Reads an accessor and stores it in the global library under the given ID - /** Reads an accessor and stores it in the global library under the given ID -
* accessors use the ID of the parent <source> element * accessors use the ID of the parent <source> element
*/ */
void ReadAccessor( const std::string& pID); void ReadAccessor(const std::string &pID);
/** Reads input declarations of per-vertex mesh data into the given mesh */ /** Reads input declarations of per-vertex mesh data into the given mesh */
void ReadVertexData( Collada::Mesh* pMesh); void ReadVertexData(Collada::Mesh *pMesh);
/** Reads input declarations of per-index mesh data into the given mesh */ /** Reads input declarations of per-index mesh data into the given mesh */
void ReadIndexData( Collada::Mesh* pMesh); void ReadIndexData(Collada::Mesh *pMesh);
/** Reads a single input channel element and stores it in the given array, if valid */ /** Reads a single input channel element and stores it in the given array, if valid */
void ReadInputChannel( std::vector<Collada::InputChannel>& poChannels); void ReadInputChannel(std::vector<Collada::InputChannel> &poChannels);
/** Reads a <p> primitive index list and assembles the mesh data into the given mesh */ /** Reads a <p> primitive index list and assembles the mesh data into the given mesh */
size_t ReadPrimitives( Collada::Mesh* pMesh, std::vector<Collada::InputChannel>& pPerIndexChannels, size_t ReadPrimitives(Collada::Mesh *pMesh, std::vector<Collada::InputChannel> &pPerIndexChannels,
size_t pNumPrimitives, const std::vector<size_t>& pVCount, Collada::PrimitiveType pPrimType); size_t pNumPrimitives, const std::vector<size_t> &pVCount, Collada::PrimitiveType pPrimType);
/** Copies the data for a single primitive into the mesh, based on the InputChannels */ /** Copies the data for a single primitive into the mesh, based on the InputChannels */
void CopyVertex(size_t currentVertex, size_t numOffsets, size_t numPoints, size_t perVertexOffset, void CopyVertex(size_t currentVertex, size_t numOffsets, size_t numPoints, size_t perVertexOffset,
Collada::Mesh* pMesh, std::vector<Collada::InputChannel>& pPerIndexChannels, Collada::Mesh *pMesh, std::vector<Collada::InputChannel> &pPerIndexChannels,
size_t currentPrimitive, const std::vector<size_t>& indices); size_t currentPrimitive, const std::vector<size_t> &indices);
/** Reads one triangle of a tristrip into the mesh */ /** Reads one triangle of a tristrip into the mesh */
void ReadPrimTriStrips(size_t numOffsets, size_t perVertexOffset, Collada::Mesh* pMesh, void ReadPrimTriStrips(size_t numOffsets, size_t perVertexOffset, Collada::Mesh *pMesh,
std::vector<Collada::InputChannel>& pPerIndexChannels, size_t currentPrimitive, const std::vector<size_t>& indices); std::vector<Collada::InputChannel> &pPerIndexChannels, size_t currentPrimitive, const std::vector<size_t> &indices);
/** Extracts a single object from an input channel and stores it in the appropriate mesh data array */ /** Extracts a single object from an input channel and stores it in the appropriate mesh data array */
void ExtractDataObjectFromChannel( const Collada::InputChannel& pInput, size_t pLocalIndex, Collada::Mesh* pMesh); void ExtractDataObjectFromChannel(const Collada::InputChannel &pInput, size_t pLocalIndex, Collada::Mesh *pMesh);
/** Reads the library of node hierarchies and scene parts */ /** Reads the library of node hierarchies and scene parts */
void ReadSceneLibrary(); void ReadSceneLibrary();
/** Reads a scene node's contents including children and stores it in the given node */ /** Reads a scene node's contents including children and stores it in the given node */
void ReadSceneNode( Collada::Node* pNode); void ReadSceneNode(Collada::Node *pNode);
/** Reads a node transformation entry of the given type and adds it to the given node's transformation list. */ /** Reads a node transformation entry of the given type and adds it to the given node's transformation list. */
void ReadNodeTransformation( Collada::Node* pNode, Collada::TransformType pType); void ReadNodeTransformation(Collada::Node *pNode, Collada::TransformType pType);
/** Reads a mesh reference in a node and adds it to the node's mesh list */ /** Reads a mesh reference in a node and adds it to the node's mesh list */
void ReadNodeGeometry( Collada::Node* pNode); void ReadNodeGeometry(Collada::Node *pNode);
/** Reads the collada scene */ /** Reads the collada scene */
void ReadScene(); void ReadScene();
// Processes bind_vertex_input and bind elements // Processes bind_vertex_input and bind elements
void ReadMaterialVertexInputBinding( Collada::SemanticMappingTable& tbl); void ReadMaterialVertexInputBinding(Collada::SemanticMappingTable &tbl);
/** Reads embedded textures from a ZAE archive*/ /** Reads embedded textures from a ZAE archive*/
void ReadEmbeddedTextures(ZipArchiveIOSystem &zip_archive); void ReadEmbeddedTextures(ZipArchiveIOSystem &zip_archive);
protected: protected:
/** Aborts the file reading with an exception */ /** Aborts the file reading with an exception */
AI_WONT_RETURN void ThrowException( const std::string& pError) const AI_WONT_RETURN_SUFFIX; AI_WONT_RETURN void ThrowException(const std::string &pError) const AI_WONT_RETURN_SUFFIX;
void ReportWarning(const char* msg,...); void ReportWarning(const char *msg, ...);
/** Skips all data until the end node of the current element */ /** Skips all data until the end node of the current element */
void SkipElement(); void SkipElement();
/** Skips all data until the end node of the given element */ /** Skips all data until the end node of the given element */
void SkipElement( const char* pElement); void SkipElement(const char *pElement);
/** Compares the current xml element name to the given string and returns true if equal */ /** Compares the current xml element name to the given string and returns true if equal */
bool IsElement( const char* pName) const; bool IsElement(const char *pName) const;
/** Tests for the opening tag of the given element, throws an exception if not found */ /** Tests for the opening tag of the given element, throws an exception if not found */
void TestOpening( const char* pName); void TestOpening(const char *pName);
/** Tests for the closing tag of the given element, throws an exception if not found */ /** Tests for the closing tag of the given element, throws an exception if not found */
void TestClosing( const char* pName); void TestClosing(const char *pName);
/** Checks the present element for the presence of the attribute, returns its index /** Checks the present element for the presence of the attribute, returns its index
or throws an exception if not found */ or throws an exception if not found */
int GetAttribute( const char* pAttr) const; int GetAttribute(const char *pAttr) const;
/** Returns the index of the named attribute or -1 if not found. Does not throw, /** Returns the index of the named attribute or -1 if not found. Does not throw,
therefore useful for optional attributes */ therefore useful for optional attributes */
int TestAttribute( const char* pAttr) const; int TestAttribute(const char *pAttr) const;
/** Reads the text contents of an element, throws an exception if not given. /** Reads the text contents of an element, throws an exception if not given.
Skips leading whitespace. */ Skips leading whitespace. */
const char* GetTextContent(); const char *GetTextContent();
/** Reads the text contents of an element, returns NULL if not given. /** Reads the text contents of an element, returns NULL if not given.
Skips leading whitespace. */ Skips leading whitespace. */
const char* TestTextContent(); const char *TestTextContent();
/** Reads a single bool from current text content */ /** Reads a single bool from current text content */
bool ReadBoolFromTextContent(); bool ReadBoolFromTextContent();
/** Reads a single float from current text content */ /** Reads a single float from current text content */
ai_real ReadFloatFromTextContent(); ai_real ReadFloatFromTextContent();
/** Calculates the resulting transformation from all the given transform steps */ /** Calculates the resulting transformation from all the given transform steps */
aiMatrix4x4 CalculateResultTransform( const std::vector<Collada::Transform>& pTransforms) const; aiMatrix4x4 CalculateResultTransform(const std::vector<Collada::Transform> &pTransforms) const;
/** Determines the input data type for the given semantic string */ /** Determines the input data type for the given semantic string */
Collada::InputType GetTypeForSemantic( const std::string& pSemantic); Collada::InputType GetTypeForSemantic(const std::string &pSemantic);
/** Finds the item in the given library by its reference, throws if not found */ /** Finds the item in the given library by its reference, throws if not found */
template <typename Type> const Type& ResolveLibraryReference( const std::map<std::string, Type>& pLibrary, const std::string& pURL) const;
protected:
/** Filename, for a verbose error message */
std::string mFileName;
/** XML reader, member for everyday use */
irr::io::IrrXMLReader* mReader;
/** All data arrays found in the file by ID. Might be referred to by actually
everyone. Collada, you are a steaming pile of indirection. */
typedef std::map<std::string, Collada::Data> DataLibrary;
DataLibrary mDataLibrary;
/** Same for accessors which define how the data in a data array is accessed. */
typedef std::map<std::string, Collada::Accessor> AccessorLibrary;
AccessorLibrary mAccessorLibrary;
/** Mesh library: mesh by ID */
typedef std::map<std::string, Collada::Mesh*> MeshLibrary;
MeshLibrary mMeshLibrary;
/** node library: root node of the hierarchy part by ID */
typedef std::map<std::string, Collada::Node*> NodeLibrary;
NodeLibrary mNodeLibrary;
/** Image library: stores texture properties by ID */
typedef std::map<std::string, Collada::Image> ImageLibrary;
ImageLibrary mImageLibrary;
/** Effect library: surface attributes by ID */
typedef std::map<std::string, Collada::Effect> EffectLibrary;
EffectLibrary mEffectLibrary;
/** Material library: surface material by ID */
typedef std::map<std::string, Collada::Material> MaterialLibrary;
MaterialLibrary mMaterialLibrary;
/** Light library: surface light by ID */
typedef std::map<std::string, Collada::Light> LightLibrary;
LightLibrary mLightLibrary;
/** Camera library: surface material by ID */
typedef std::map<std::string, Collada::Camera> CameraLibrary;
CameraLibrary mCameraLibrary;
/** Controller library: joint controllers by ID */
typedef std::map<std::string, Collada::Controller> ControllerLibrary;
ControllerLibrary mControllerLibrary;
/** Animation library: animation references by ID */
typedef std::map<std::string, Collada::Animation*> AnimationLibrary;
AnimationLibrary mAnimationLibrary;
/** Animation clip library: clip animation references by ID */
typedef std::vector<std::pair<std::string, std::vector<std::string> > > AnimationClipLibrary;
AnimationClipLibrary mAnimationClipLibrary;
/** Pointer to the root node. Don't delete, it just points to one of
the nodes in the node library. */
Collada::Node* mRootNode;
/** Root animation container */
Collada::Animation mAnims;
/** Size unit: how large compared to a meter */
ai_real mUnitSize;
/** Which is the up vector */
enum { UP_X, UP_Y, UP_Z } mUpDirection;
/** Asset metadata (global for scene) */
StringMetaData mAssetMetaData;
/** Collada file format version */
Collada::FormatVersion mFormat;
};
// ------------------------------------------------------------------------------------------------
// Check for element match
inline bool ColladaParser::IsElement( const char* pName) const
{
ai_assert( mReader->getNodeType() == irr::io::EXN_ELEMENT);
return ::strcmp( mReader->getNodeName(), pName) == 0;
}
// ------------------------------------------------------------------------------------------------
// Finds the item in the given library by its reference, throws if not found
template <typename Type> template <typename Type>
const Type& ColladaParser::ResolveLibraryReference( const std::map<std::string, Type>& pLibrary, const std::string& pURL) const const Type &ResolveLibraryReference(const std::map<std::string, Type> &pLibrary, const std::string &pURL) const;
{
typename std::map<std::string, Type>::const_iterator it = pLibrary.find( pURL); protected:
if( it == pLibrary.end()) /** Filename, for a verbose error message */
ThrowException( Formatter::format() << "Unable to resolve library reference \"" << pURL << "\"." ); std::string mFileName;
return it->second;
} /** XML reader, member for everyday use */
irr::io::IrrXMLReader *mReader;
/** All data arrays found in the file by ID. Might be referred to by actually
everyone. Collada, you are a steaming pile of indirection. */
typedef std::map<std::string, Collada::Data> DataLibrary;
DataLibrary mDataLibrary;
/** Same for accessors which define how the data in a data array is accessed. */
typedef std::map<std::string, Collada::Accessor> AccessorLibrary;
AccessorLibrary mAccessorLibrary;
/** Mesh library: mesh by ID */
typedef std::map<std::string, Collada::Mesh *> MeshLibrary;
MeshLibrary mMeshLibrary;
/** node library: root node of the hierarchy part by ID */
typedef std::map<std::string, Collada::Node *> NodeLibrary;
NodeLibrary mNodeLibrary;
/** Image library: stores texture properties by ID */
typedef std::map<std::string, Collada::Image> ImageLibrary;
ImageLibrary mImageLibrary;
/** Effect library: surface attributes by ID */
typedef std::map<std::string, Collada::Effect> EffectLibrary;
EffectLibrary mEffectLibrary;
/** Material library: surface material by ID */
typedef std::map<std::string, Collada::Material> MaterialLibrary;
MaterialLibrary mMaterialLibrary;
/** Light library: surface light by ID */
typedef std::map<std::string, Collada::Light> LightLibrary;
LightLibrary mLightLibrary;
/** Camera library: surface material by ID */
typedef std::map<std::string, Collada::Camera> CameraLibrary;
CameraLibrary mCameraLibrary;
/** Controller library: joint controllers by ID */
typedef std::map<std::string, Collada::Controller> ControllerLibrary;
ControllerLibrary mControllerLibrary;
/** Animation library: animation references by ID */
typedef std::map<std::string, Collada::Animation *> AnimationLibrary;
AnimationLibrary mAnimationLibrary;
/** Animation clip library: clip animation references by ID */
typedef std::vector<std::pair<std::string, std::vector<std::string>>> AnimationClipLibrary;
AnimationClipLibrary mAnimationClipLibrary;
/** Pointer to the root node. Don't delete, it just points to one of
the nodes in the node library. */
Collada::Node *mRootNode;
/** Root animation container */
Collada::Animation mAnims;
/** Size unit: how large compared to a meter */
ai_real mUnitSize;
/** Which is the up vector */
enum { UP_X,
UP_Y,
UP_Z } mUpDirection;
/** Asset metadata (global for scene) */
StringMetaData mAssetMetaData;
/** Collada file format version */
Collada::FormatVersion mFormat;
};
// ------------------------------------------------------------------------------------------------
// Check for element match
inline bool ColladaParser::IsElement(const char *pName) const {
ai_assert(mReader->getNodeType() == irr::io::EXN_ELEMENT);
return ::strcmp(mReader->getNodeName(), pName) == 0;
}
// ------------------------------------------------------------------------------------------------
// Finds the item in the given library by its reference, throws if not found
template <typename Type>
const Type &ColladaParser::ResolveLibraryReference(const std::map<std::string, Type> &pLibrary, const std::string &pURL) const {
typename std::map<std::string, Type>::const_iterator it = pLibrary.find(pURL);
if (it == pLibrary.end())
ThrowException(Formatter::format() << "Unable to resolve library reference \"" << pURL << "\".");
return it->second;
}
} // end of namespace Assimp } // end of namespace Assimp