2015-05-19 03:48:29 +00:00
|
|
|
/*
|
|
|
|
Open Asset Import Library (assimp)
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
2022-01-10 20:13:43 +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.
|
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/** Helper structures for the Collada loader */
|
|
|
|
|
2015-05-19 03:48:29 +00:00
|
|
|
#ifndef AI_COLLADAHELPER_H_INC
|
|
|
|
#define AI_COLLADAHELPER_H_INC
|
|
|
|
|
2016-06-06 20:04:29 +00:00
|
|
|
#include <assimp/light.h>
|
|
|
|
#include <assimp/material.h>
|
2020-04-28 16:46:07 +00:00
|
|
|
#include <assimp/mesh.h>
|
2020-10-19 17:06:11 +00:00
|
|
|
|
2021-02-02 21:34:30 +00:00
|
|
|
#include <cstdint>
|
2020-04-28 16:46:07 +00:00
|
|
|
#include <map>
|
|
|
|
#include <set>
|
|
|
|
#include <vector>
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
struct aiMaterial;
|
|
|
|
|
2020-04-28 16:46:07 +00:00
|
|
|
namespace Assimp {
|
|
|
|
namespace Collada {
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Collada file versions which evolved during the years ...
|
2020-04-28 16:46:07 +00:00
|
|
|
enum FormatVersion {
|
2015-05-19 03:57:13 +00:00
|
|
|
FV_1_5_n,
|
|
|
|
FV_1_4_n,
|
|
|
|
FV_1_3_n
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Transformation types that can be applied to a node
|
2020-04-28 16:46:07 +00:00
|
|
|
enum TransformType {
|
2015-05-19 03:57:13 +00:00
|
|
|
TF_LOOKAT,
|
|
|
|
TF_ROTATE,
|
|
|
|
TF_TRANSLATE,
|
|
|
|
TF_SCALE,
|
|
|
|
TF_SKEW,
|
|
|
|
TF_MATRIX
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Different types of input data to a vertex or face
|
2020-04-28 16:46:07 +00:00
|
|
|
enum InputType {
|
2015-05-19 03:57:13 +00:00
|
|
|
IT_Invalid,
|
2020-04-28 16:46:07 +00:00
|
|
|
IT_Vertex, // special type for per-index data referring to the <vertices> element carrying the per-vertex data.
|
2015-05-19 03:57:13 +00:00
|
|
|
IT_Position,
|
|
|
|
IT_Normal,
|
|
|
|
IT_Texcoord,
|
|
|
|
IT_Color,
|
|
|
|
IT_Tangent,
|
|
|
|
IT_Bitangent
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Supported controller types
|
2020-04-28 16:46:07 +00:00
|
|
|
enum ControllerType {
|
2017-01-12 11:41:32 +00:00
|
|
|
Skin,
|
|
|
|
Morph
|
|
|
|
};
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Supported morph methods
|
2020-04-28 16:46:07 +00:00
|
|
|
enum MorphMethod {
|
2017-01-12 11:41:32 +00:00
|
|
|
Normalized,
|
|
|
|
Relative
|
|
|
|
};
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Common metadata keys as <Collada, Assimp>
|
|
|
|
using MetaKeyPair = std::pair<std::string, std::string>;
|
|
|
|
using MetaKeyPairVector = std::vector<MetaKeyPair>;
|
2019-12-09 14:05:41 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Collada as lower_case (native)
|
2019-12-09 14:05:41 +00:00
|
|
|
const MetaKeyPairVector &GetColladaAssimpMetaKeys();
|
2020-10-19 17:06:11 +00:00
|
|
|
|
2020-01-02 12:35:00 +00:00
|
|
|
// Collada as CamelCase (used by Assimp for consistency)
|
|
|
|
const MetaKeyPairVector &GetColladaAssimpMetaKeysCamelCase();
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Convert underscore_separated to CamelCase "authoring_tool" becomes "AuthoringTool"
|
2020-01-02 12:35:00 +00:00
|
|
|
void ToCamelCase(std::string &text);
|
2017-01-12 11:41:32 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Contains all data for one of the different transformation types
|
2020-04-28 16:46:07 +00:00
|
|
|
struct Transform {
|
|
|
|
std::string mID; ///< SID of the transform step, by which anim channels address their target node
|
2015-05-19 03:57:13 +00:00
|
|
|
TransformType mType;
|
2016-07-16 02:14:36 +00:00
|
|
|
ai_real f[16]; ///< Interpretation of data depends on the type of the transformation
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// A collada camera.
|
2020-04-28 16:46:07 +00:00
|
|
|
struct Camera {
|
|
|
|
Camera() :
|
|
|
|
mOrtho(false),
|
|
|
|
mHorFov(10e10f),
|
|
|
|
mVerFov(10e10f),
|
|
|
|
mAspect(10e10f),
|
|
|
|
mZNear(0.1f),
|
|
|
|
mZFar(1000.f) {}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Name of camera
|
2015-05-19 03:57:13 +00:00
|
|
|
std::string mName;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// True if it is an orthographic camera
|
2015-05-19 03:57:13 +00:00
|
|
|
bool mOrtho;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Horizontal field of view in degrees
|
2016-07-16 02:14:36 +00:00
|
|
|
ai_real mHorFov;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Vertical field of view in degrees
|
2016-07-16 02:14:36 +00:00
|
|
|
ai_real mVerFov;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Screen aspect
|
2016-07-16 02:14:36 +00:00
|
|
|
ai_real mAspect;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Near& far z
|
2016-07-16 02:14:36 +00:00
|
|
|
ai_real mZNear, mZFar;
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define ASSIMP_COLLADA_LIGHT_ANGLE_NOT_SET 1e9f
|
|
|
|
|
|
|
|
/** A collada light source. */
|
2020-04-28 16:46:07 +00:00
|
|
|
struct Light {
|
|
|
|
Light() :
|
|
|
|
mType(aiLightSource_UNDEFINED),
|
|
|
|
mAttConstant(1.f),
|
|
|
|
mAttLinear(0.f),
|
|
|
|
mAttQuadratic(0.f),
|
|
|
|
mFalloffAngle(180.f),
|
|
|
|
mFalloffExponent(0.f),
|
|
|
|
mPenumbraAngle(ASSIMP_COLLADA_LIGHT_ANGLE_NOT_SET),
|
|
|
|
mOuterAngle(ASSIMP_COLLADA_LIGHT_ANGLE_NOT_SET),
|
|
|
|
mIntensity(1.f) {}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Type of the light source aiLightSourceType + ambient
|
2015-05-19 03:57:13 +00:00
|
|
|
unsigned int mType;
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Color of the light
|
2015-05-19 03:57:13 +00:00
|
|
|
aiColor3D mColor;
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Light attenuation
|
2020-04-28 16:46:07 +00:00
|
|
|
ai_real mAttConstant, mAttLinear, mAttQuadratic;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Spot light falloff
|
2016-07-16 02:14:36 +00:00
|
|
|
ai_real mFalloffAngle;
|
|
|
|
ai_real mFalloffExponent;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// -----------------------------------------------------
|
|
|
|
// FCOLLADA extension from here
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// ... related stuff from maja and max extensions
|
2016-07-16 02:14:36 +00:00
|
|
|
ai_real mPenumbraAngle;
|
|
|
|
ai_real mOuterAngle;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Common light intensity
|
2016-07-16 02:14:36 +00:00
|
|
|
ai_real mIntensity;
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Short vertex index description */
|
2020-04-28 16:46:07 +00:00
|
|
|
struct InputSemanticMapEntry {
|
|
|
|
InputSemanticMapEntry() :
|
|
|
|
mSet(0),
|
|
|
|
mType(IT_Invalid) {}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Index of set, optional
|
2015-05-19 03:57:13 +00:00
|
|
|
unsigned int mSet;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Type of referenced vertex input
|
2015-05-19 03:57:13 +00:00
|
|
|
InputType mType;
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Table to map from effect to vertex input semantics
|
2020-04-28 16:46:07 +00:00
|
|
|
struct SemanticMappingTable {
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Name of material
|
2015-05-19 03:57:13 +00:00
|
|
|
std::string mMatName;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// List of semantic map commands, grouped by effect semantic name
|
2021-02-02 21:06:33 +00:00
|
|
|
using InputSemanticMap = std::map<std::string, InputSemanticMapEntry>;
|
|
|
|
InputSemanticMap mMap;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// For std::find
|
2020-04-28 16:46:07 +00:00
|
|
|
bool operator==(const std::string &s) const {
|
2015-05-19 03:57:13 +00:00
|
|
|
return s == mMatName;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// 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
|
2020-04-28 16:46:07 +00:00
|
|
|
struct MeshInstance {
|
2015-05-19 03:57:13 +00:00
|
|
|
///< ID of the mesh or controller to be instanced
|
|
|
|
std::string mMeshOrController;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
///< Map of materials by the subgroup ID they're applied to
|
|
|
|
std::map<std::string, SemanticMappingTable> mMaterials;
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// A reference to a camera inside a node
|
2020-04-28 16:46:07 +00:00
|
|
|
struct CameraInstance {
|
|
|
|
///< ID of the camera
|
2015-05-19 03:57:13 +00:00
|
|
|
std::string mCamera;
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// A reference to a light inside a node
|
2020-04-28 16:46:07 +00:00
|
|
|
struct LightInstance {
|
|
|
|
///< ID of the camera
|
2015-05-19 03:57:13 +00:00
|
|
|
std::string mLight;
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// A reference to a node inside a node
|
2020-04-28 16:46:07 +00:00
|
|
|
struct NodeInstance {
|
|
|
|
///< ID of the node
|
2015-05-19 03:57:13 +00:00
|
|
|
std::string mNode;
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// A node in a scene hierarchy
|
2020-04-28 16:46:07 +00:00
|
|
|
struct Node {
|
2015-05-19 03:57:13 +00:00
|
|
|
std::string mName;
|
|
|
|
std::string mID;
|
2015-05-19 03:48:29 +00:00
|
|
|
std::string mSID;
|
2020-04-28 16:46:07 +00:00
|
|
|
Node *mParent;
|
|
|
|
std::vector<Node *> mChildren;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Operations in order to calculate the resulting transformation to parent.
|
2015-05-19 03:57:13 +00:00
|
|
|
std::vector<Transform> mTransforms;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Meshes at this node
|
2015-05-19 03:57:13 +00:00
|
|
|
std::vector<MeshInstance> mMeshes;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Lights at this node
|
2015-05-19 03:57:13 +00:00
|
|
|
std::vector<LightInstance> mLights;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Cameras at this node
|
2015-05-19 03:57:13 +00:00
|
|
|
std::vector<CameraInstance> mCameras;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Node instances at this node
|
2015-05-19 03:57:13 +00:00
|
|
|
std::vector<NodeInstance> mNodeInstances;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Root-nodes: Name of primary camera, if any
|
2015-05-19 03:57:13 +00:00
|
|
|
std::string mPrimaryCamera;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Constructor. Begin with a zero parent
|
2020-04-28 16:46:07 +00:00
|
|
|
Node() :
|
|
|
|
mParent(nullptr) {
|
2018-06-17 18:37:09 +00:00
|
|
|
// empty
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Destructor: delete all children subsequently
|
2015-05-19 03:57:13 +00:00
|
|
|
~Node() {
|
2020-10-19 17:06:11 +00:00
|
|
|
for (std::vector<Node *>::iterator it = mChildren.begin(); it != mChildren.end(); ++it) {
|
2015-05-19 03:57:13 +00:00
|
|
|
delete *it;
|
2020-10-19 17:06:11 +00:00
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Data source array: either floats or strings
|
2020-04-28 16:46:07 +00:00
|
|
|
struct Data {
|
2015-05-19 03:57:13 +00:00
|
|
|
bool mIsStringArray;
|
2016-07-16 02:14:36 +00:00
|
|
|
std::vector<ai_real> mValues;
|
2015-05-19 03:57:13 +00:00
|
|
|
std::vector<std::string> mStrings;
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Accessor to a data array
|
2020-04-28 16:46:07 +00:00
|
|
|
struct Accessor {
|
|
|
|
size_t mCount; // in number of objects
|
|
|
|
size_t mSize; // size of an object, in elements (floats or strings, mostly 1)
|
|
|
|
size_t mOffset; // in number of values
|
|
|
|
size_t mStride; // Stride in number of values
|
2015-05-19 03:57:13 +00:00
|
|
|
std::vector<std::string> mParams; // names of the data streams in the accessors. Empty string tells to ignore.
|
2020-10-19 17:06:11 +00:00
|
|
|
size_t mSubOffset[4]; // Sub-offset inside the object for the common 4 elements. For a vector, that's XYZ, for a color RGBA and so on.
|
2020-04-28 16:46:07 +00:00
|
|
|
// 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
|
2020-06-23 19:05:42 +00:00
|
|
|
mutable const Data *mData; // Pointer to the source array, if resolved. nullptr else
|
2020-04-28 16:46:07 +00:00
|
|
|
|
|
|
|
Accessor() {
|
|
|
|
mCount = 0;
|
|
|
|
mSize = 0;
|
|
|
|
mOffset = 0;
|
|
|
|
mStride = 0;
|
2020-06-23 19:05:42 +00:00
|
|
|
mData = nullptr;
|
2015-05-19 03:57:13 +00:00
|
|
|
mSubOffset[0] = mSubOffset[1] = mSubOffset[2] = mSubOffset[3] = 0;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// A single face in a mesh
|
2020-04-28 16:46:07 +00:00
|
|
|
struct Face {
|
2015-05-19 03:57:13 +00:00
|
|
|
std::vector<size_t> mIndices;
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// An input channel for mesh data, referring to a single accessor
|
2020-04-28 16:46:07 +00:00
|
|
|
struct InputChannel {
|
|
|
|
InputType mType; // Type of the data
|
|
|
|
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.
|
2015-05-19 03:57:13 +00:00
|
|
|
std::string mAccessor; // ID of the accessor where to read the actual values from.
|
2020-06-23 19:05:42 +00:00
|
|
|
mutable const Accessor *mResolved; // Pointer to the accessor, if resolved. nullptr else
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-04-28 16:46:07 +00:00
|
|
|
InputChannel() {
|
|
|
|
mType = IT_Invalid;
|
|
|
|
mIndex = 0;
|
|
|
|
mOffset = 0;
|
2020-06-23 19:05:42 +00:00
|
|
|
mResolved = nullptr;
|
2020-04-28 16:46:07 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Subset of a mesh with a certain material
|
2020-04-28 16:46:07 +00:00
|
|
|
struct SubMesh {
|
2015-05-19 03:57:13 +00:00
|
|
|
std::string mMaterial; ///< subgroup identifier
|
2020-10-19 17:06:11 +00:00
|
|
|
size_t mNumFaces; ///< number of faces in this sub-mesh
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Contains data for a single mesh
|
2020-04-28 16:46:07 +00:00
|
|
|
struct Mesh {
|
2020-04-29 16:17:46 +00:00
|
|
|
Mesh(const std::string &id) :
|
|
|
|
mId(id) {
|
2020-10-19 17:06:11 +00:00
|
|
|
for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) {
|
2015-05-19 03:57:13 +00:00
|
|
|
mNumUVComponents[i] = 2;
|
2020-10-19 17:06:11 +00:00
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2015-05-19 03:52:10 +00:00
|
|
|
|
2020-04-29 16:17:46 +00:00
|
|
|
const std::string mId;
|
2015-05-19 03:48:29 +00:00
|
|
|
std::string mName;
|
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// just to check if there's some sophisticated addressing involved...
|
|
|
|
// which we don't support, and therefore should warn about.
|
|
|
|
std::string mVertexID;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// Vertex data addressed by vertex indices
|
|
|
|
std::vector<InputChannel> mPerVertexData;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// actual mesh data, assembled on encounter of a <p> element. Verbose format, not indexed
|
|
|
|
std::vector<aiVector3D> mPositions;
|
|
|
|
std::vector<aiVector3D> mNormals;
|
|
|
|
std::vector<aiVector3D> mTangents;
|
|
|
|
std::vector<aiVector3D> mBitangents;
|
|
|
|
std::vector<aiVector3D> mTexCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS];
|
2020-04-28 16:46:07 +00:00
|
|
|
std::vector<aiColor4D> mColors[AI_MAX_NUMBER_OF_COLOR_SETS];
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
unsigned int mNumUVComponents[AI_MAX_NUMBER_OF_TEXTURECOORDS];
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// Faces. Stored are only the number of vertices for each face.
|
|
|
|
// 1 == point, 2 == line, 3 == triangle, 4+ == poly
|
|
|
|
std::vector<size_t> mFaceSize;
|
2015-05-19 03:52:10 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// Position indices for all faces in the sequence given in mFaceSize -
|
|
|
|
// necessary for bone weight assignment
|
|
|
|
std::vector<size_t> mFacePosIndices;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
// Sub-meshes in this mesh, each with a given material
|
2015-05-19 03:57:13 +00:00
|
|
|
std::vector<SubMesh> mSubMeshes;
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Which type of primitives the ReadPrimitives() function is going to read
|
2020-04-28 16:46:07 +00:00
|
|
|
enum PrimitiveType {
|
2015-05-19 03:57:13 +00:00
|
|
|
Prim_Invalid,
|
|
|
|
Prim_Lines,
|
|
|
|
Prim_LineStrip,
|
|
|
|
Prim_Triangles,
|
|
|
|
Prim_TriStrips,
|
|
|
|
Prim_TriFans,
|
|
|
|
Prim_Polylist,
|
|
|
|
Prim_Polygon
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// A skeleton controller to deform a mesh with the use of joints
|
2020-04-28 16:46:07 +00:00
|
|
|
struct Controller {
|
2017-01-12 11:41:32 +00:00
|
|
|
// controller type
|
|
|
|
ControllerType mType;
|
|
|
|
|
|
|
|
// Morphing method if type is Morph
|
|
|
|
MorphMethod mMethod;
|
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// the URL of the mesh deformed by the controller.
|
|
|
|
std::string mMeshId;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// accessor URL of the joint names
|
|
|
|
std::string mJointNameSource;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
///< The bind shape matrix, as array of floats. I'm not sure what this matrix actually describes, but it can't be ignored in all cases
|
2016-07-16 02:14:36 +00:00
|
|
|
ai_real mBindShapeMatrix[16];
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// accessor URL of the joint inverse bind matrices
|
|
|
|
std::string mJointOffsetMatrixSource;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// input channel: joint names.
|
|
|
|
InputChannel mWeightInputJoints;
|
|
|
|
// input channel: joint weights
|
|
|
|
InputChannel mWeightInputWeights;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// Number of weights per vertex.
|
|
|
|
std::vector<size_t> mWeightCounts;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// JointIndex-WeightIndex pairs for all vertices
|
2020-04-28 16:46:07 +00:00
|
|
|
std::vector<std::pair<size_t, size_t>> mWeights;
|
2017-01-12 11:41:32 +00:00
|
|
|
|
|
|
|
std::string mMorphTarget;
|
|
|
|
std::string mMorphWeight;
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// A collada material. Pretty much the only member is a reference to an effect.
|
2020-04-28 16:46:07 +00:00
|
|
|
struct Material {
|
2015-05-19 03:57:13 +00:00
|
|
|
std::string mName;
|
|
|
|
std::string mEffect;
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Type of the effect param
|
2020-04-28 16:46:07 +00:00
|
|
|
enum ParamType {
|
2015-05-19 03:57:13 +00:00
|
|
|
Param_Sampler,
|
|
|
|
Param_Surface
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// A param for an effect. Might be of several types, but they all just refer to each other, so I summarize them
|
2020-04-28 16:46:07 +00:00
|
|
|
struct EffectParam {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParamType mType;
|
|
|
|
std::string mReference; // to which other thing the param is referring to.
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Shading type supported by the standard effect spec of Collada
|
2020-04-28 16:46:07 +00:00
|
|
|
enum ShadeType {
|
2015-05-19 03:57:13 +00:00
|
|
|
Shade_Invalid,
|
|
|
|
Shade_Constant,
|
|
|
|
Shade_Lambert,
|
|
|
|
Shade_Phong,
|
|
|
|
Shade_Blinn
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Represents a texture sampler in collada
|
2020-04-28 16:46:07 +00:00
|
|
|
struct Sampler {
|
|
|
|
Sampler() :
|
|
|
|
mWrapU(true),
|
|
|
|
mWrapV(true),
|
|
|
|
mMirrorU(),
|
|
|
|
mMirrorV(),
|
|
|
|
mOp(aiTextureOp_Multiply),
|
|
|
|
mUVId(UINT_MAX),
|
|
|
|
mWeighting(1.f),
|
|
|
|
mMixWithPrevious(1.f) {}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Name of image reference
|
2015-05-19 03:57:13 +00:00
|
|
|
std::string mName;
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Wrap U?
|
2015-05-19 03:57:13 +00:00
|
|
|
bool mWrapU;
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Wrap V?
|
2015-05-19 03:57:13 +00:00
|
|
|
bool mWrapV;
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Mirror U?
|
2015-05-19 03:57:13 +00:00
|
|
|
bool mMirrorU;
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Mirror V?
|
2015-05-19 03:57:13 +00:00
|
|
|
bool mMirrorV;
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Blend mode
|
2015-05-19 03:57:13 +00:00
|
|
|
aiTextureOp mOp;
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// UV transformation
|
2015-05-19 03:57:13 +00:00
|
|
|
aiUVTransform mTransform;
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Name of source UV channel
|
2015-05-19 03:57:13 +00:00
|
|
|
std::string mUVChannel;
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Resolved UV channel index or UINT_MAX if not known
|
2015-05-19 03:57:13 +00:00
|
|
|
unsigned int mUVId;
|
|
|
|
|
|
|
|
// OKINO/MAX3D extensions from here
|
|
|
|
// -------------------------------------------------------
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Weighting factor
|
2016-07-16 02:14:36 +00:00
|
|
|
ai_real mWeighting;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Mixing factor from OKINO
|
2016-07-16 02:14:36 +00:00
|
|
|
ai_real mMixWithPrevious;
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// A collada effect. Can contain about anything according to the Collada spec,
|
|
|
|
/// but we limit our version to a reasonable subset.
|
2020-04-28 16:46:07 +00:00
|
|
|
struct Effect {
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Shading mode
|
2015-05-19 03:57:13 +00:00
|
|
|
ShadeType mShadeType;
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Colors
|
2015-05-19 03:57:13 +00:00
|
|
|
aiColor4D mEmissive, mAmbient, mDiffuse, mSpecular,
|
2020-04-28 16:46:07 +00:00
|
|
|
mTransparent, mReflective;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Textures
|
2015-05-19 03:57:13 +00:00
|
|
|
Sampler mTexEmissive, mTexAmbient, mTexDiffuse, mTexSpecular,
|
2020-04-28 16:46:07 +00:00
|
|
|
mTexTransparent, mTexBump, mTexReflective;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Scalar factory
|
2016-07-16 02:14:36 +00:00
|
|
|
ai_real mShininess, mRefractIndex, mReflectivity;
|
|
|
|
ai_real mTransparency;
|
2015-05-19 03:57:13 +00:00
|
|
|
bool mHasTransparency;
|
|
|
|
bool mRGBTransparency;
|
2015-12-08 14:24:07 +00:00
|
|
|
bool mInvertTransparency;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// local params referring to each other by their SID
|
|
|
|
using ParamLibrary = std::map<std::string, Collada::EffectParam>;
|
2015-05-19 03:57:13 +00:00
|
|
|
ParamLibrary mParams;
|
|
|
|
|
|
|
|
// MAX3D extensions
|
|
|
|
// ---------------------------------------------------------
|
|
|
|
// Double-sided?
|
|
|
|
bool mDoubleSided, mWireframe, mFaceted;
|
|
|
|
|
2020-04-28 16:46:07 +00:00
|
|
|
Effect() :
|
|
|
|
mShadeType(Shade_Phong),
|
|
|
|
mEmissive(0, 0, 0, 1),
|
|
|
|
mAmbient(0.1f, 0.1f, 0.1f, 1),
|
|
|
|
mDiffuse(0.6f, 0.6f, 0.6f, 1),
|
|
|
|
mSpecular(0.4f, 0.4f, 0.4f, 1),
|
|
|
|
mTransparent(0, 0, 0, 1),
|
|
|
|
mShininess(10.0f),
|
|
|
|
mRefractIndex(1.f),
|
|
|
|
mReflectivity(0.f),
|
|
|
|
mTransparency(1.f),
|
|
|
|
mHasTransparency(false),
|
|
|
|
mRGBTransparency(false),
|
|
|
|
mInvertTransparency(false),
|
|
|
|
mDoubleSided(false),
|
|
|
|
mWireframe(false),
|
|
|
|
mFaceted(false) {
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// An image, meaning texture
|
2020-04-28 16:46:07 +00:00
|
|
|
struct Image {
|
2015-05-19 03:57:13 +00:00
|
|
|
std::string mFileName;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Embedded image data
|
2015-05-19 03:57:13 +00:00
|
|
|
std::vector<uint8_t> mImageData;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// File format hint of embedded image data
|
2015-05-19 03:57:13 +00:00
|
|
|
std::string mEmbeddedFormat;
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// An animation channel.
|
2020-04-28 16:46:07 +00:00
|
|
|
struct AnimationChannel {
|
2020-10-19 17:06:11 +00:00
|
|
|
/// URL of the data to animate. Could be about anything, but we support only the
|
|
|
|
/// "NodeID/TransformID.SubElement" notation
|
2015-05-19 03:57:13 +00:00
|
|
|
std::string mTarget;
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Source URL of the time values. Collada calls them "input". Meh.
|
2015-05-19 03:57:13 +00:00
|
|
|
std::string mSourceTimes;
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Source URL of the value values. Collada calls them "output".
|
2015-05-19 03:57:13 +00:00
|
|
|
std::string mSourceValues;
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Source URL of the IN_TANGENT semantic values.
|
2017-01-12 11:41:32 +00:00
|
|
|
std::string mInTanValues;
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Source URL of the OUT_TANGENT semantic values.
|
2017-01-12 11:41:32 +00:00
|
|
|
std::string mOutTanValues;
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Source URL of the INTERPOLATION semantic values.
|
2017-01-12 11:41:32 +00:00
|
|
|
std::string mInterpolationValues;
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// An animation. Container for 0-x animation channels or 0-x animations
|
2020-04-28 16:46:07 +00:00
|
|
|
struct Animation {
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Anim name
|
2015-05-19 03:57:13 +00:00
|
|
|
std::string mName;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// the animation channels, if any
|
2015-05-19 03:57:13 +00:00
|
|
|
std::vector<AnimationChannel> mChannels;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// the sub-animations, if any
|
2020-04-28 16:46:07 +00:00
|
|
|
std::vector<Animation *> mSubAnims;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Destructor
|
2020-04-28 16:46:07 +00:00
|
|
|
~Animation() {
|
2020-10-19 17:06:11 +00:00
|
|
|
for (std::vector<Animation *>::iterator it = mSubAnims.begin(); it != mSubAnims.end(); ++it) {
|
2015-05-19 03:57:13 +00:00
|
|
|
delete *it;
|
2020-10-19 17:06:11 +00:00
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2016-02-07 22:36:49 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Collect all channels in the animation hierarchy into a single channel list.
|
2020-04-28 16:46:07 +00:00
|
|
|
void CollectChannelsRecursively(std::vector<AnimationChannel> &channels) {
|
|
|
|
channels.insert(channels.end(), mChannels.begin(), mChannels.end());
|
2016-02-07 22:36:49 +00:00
|
|
|
|
2020-04-28 16:46:07 +00:00
|
|
|
for (std::vector<Animation *>::iterator it = mSubAnims.begin(); it != mSubAnims.end(); ++it) {
|
|
|
|
Animation *pAnim = (*it);
|
|
|
|
pAnim->CollectChannelsRecursively(channels);
|
|
|
|
}
|
|
|
|
}
|
2016-02-10 22:57:29 +00:00
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Combine all single-channel animations' channel into the same (parent) animation channel list.
|
2020-04-28 16:46:07 +00:00
|
|
|
void CombineSingleChannelAnimations() {
|
|
|
|
CombineSingleChannelAnimationsRecursively(this);
|
|
|
|
}
|
2016-02-10 22:57:29 +00:00
|
|
|
|
2020-04-28 16:46:07 +00:00
|
|
|
void CombineSingleChannelAnimationsRecursively(Animation *pParent) {
|
|
|
|
std::set<std::string> childrenTargets;
|
|
|
|
bool childrenAnimationsHaveDifferentChannels = true;
|
2019-12-29 19:05:33 +00:00
|
|
|
|
2020-04-28 16:46:07 +00:00
|
|
|
for (std::vector<Animation *>::iterator it = pParent->mSubAnims.begin(); it != pParent->mSubAnims.end();) {
|
|
|
|
Animation *anim = *it;
|
|
|
|
CombineSingleChannelAnimationsRecursively(anim);
|
2016-02-10 22:57:29 +00:00
|
|
|
|
2020-04-28 16:46:07 +00:00
|
|
|
if (childrenAnimationsHaveDifferentChannels && anim->mChannels.size() == 1 &&
|
|
|
|
childrenTargets.find(anim->mChannels[0].mTarget) == childrenTargets.end()) {
|
|
|
|
childrenTargets.insert(anim->mChannels[0].mTarget);
|
|
|
|
} else {
|
|
|
|
childrenAnimationsHaveDifferentChannels = false;
|
|
|
|
}
|
2019-12-29 19:05:33 +00:00
|
|
|
|
2020-04-28 16:46:07 +00:00
|
|
|
++it;
|
|
|
|
}
|
2019-12-29 19:05:33 +00:00
|
|
|
|
2020-04-28 16:46:07 +00:00
|
|
|
// We only want to combine animations if they have different channels
|
|
|
|
if (childrenAnimationsHaveDifferentChannels) {
|
|
|
|
for (std::vector<Animation *>::iterator it = pParent->mSubAnims.begin(); it != pParent->mSubAnims.end();) {
|
|
|
|
Animation *anim = *it;
|
2019-12-29 19:05:33 +00:00
|
|
|
|
2020-04-28 16:46:07 +00:00
|
|
|
pParent->mChannels.push_back(anim->mChannels[0]);
|
2016-02-10 22:57:29 +00:00
|
|
|
|
2020-04-28 16:46:07 +00:00
|
|
|
it = pParent->mSubAnims.erase(it);
|
2016-02-10 22:57:29 +00:00
|
|
|
|
2020-04-28 16:46:07 +00:00
|
|
|
delete anim;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
2020-10-19 17:06:11 +00:00
|
|
|
/// Description of a collada animation channel which has been determined to affect the current node
|
2020-04-28 16:46:07 +00:00
|
|
|
struct ChannelEntry {
|
2020-10-19 17:06:11 +00:00
|
|
|
const Collada::AnimationChannel *mChannel; ///< the source channel
|
2017-01-12 11:41:32 +00:00
|
|
|
std::string mTargetId;
|
2020-04-28 16:46:07 +00:00
|
|
|
std::string mTransformId; // the ID of the transformation step of the node which is influenced
|
2015-05-19 03:57:13 +00:00
|
|
|
size_t mTransformIndex; // Index into the node's transform chain to apply the channel to
|
|
|
|
size_t mSubElement; // starting index inside the transform data
|
|
|
|
|
|
|
|
// resolved data references
|
2020-04-28 16:46:07 +00:00
|
|
|
const Collada::Accessor *mTimeAccessor; ///> Collada accessor to 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::Data *mValueData; ///> Source datat array for the key value values
|
|
|
|
|
|
|
|
ChannelEntry() :
|
|
|
|
mChannel(),
|
|
|
|
mTransformIndex(),
|
|
|
|
mSubElement(),
|
|
|
|
mTimeAccessor(),
|
|
|
|
mTimeData(),
|
|
|
|
mValueAccessor(),
|
|
|
|
mValueData() {}
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end of namespace Collada
|
|
|
|
} // end of namespace Assimp
|
|
|
|
|
|
|
|
#endif // AI_COLLADAHELPER_H_INC
|