2015-05-19 03:48:29 +00:00
|
|
|
/** Defines the collada loader class */
|
|
|
|
|
|
|
|
/*
|
|
|
|
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
|
|
|
|
2017-05-09 17:57:36 +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.
|
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef AI_COLLADALOADER_H_INC
|
|
|
|
#define AI_COLLADALOADER_H_INC
|
|
|
|
|
|
|
|
#include "ColladaParser.h"
|
2021-02-02 21:06:33 +00:00
|
|
|
#include <assimp/BaseImporter.h>
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
struct aiNode;
|
|
|
|
struct aiCamera;
|
|
|
|
struct aiLight;
|
|
|
|
struct aiTexture;
|
|
|
|
struct aiAnimation;
|
|
|
|
|
2021-02-02 21:06:33 +00:00
|
|
|
namespace Assimp {
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2021-02-02 21:06:33 +00:00
|
|
|
struct ColladaMeshIndex {
|
2015-05-19 03:57:13 +00:00
|
|
|
std::string mMeshID;
|
|
|
|
size_t mSubMesh;
|
|
|
|
std::string mMaterial;
|
2021-02-02 21:06:33 +00:00
|
|
|
ColladaMeshIndex(const std::string &pMeshID, size_t pSubMesh, const std::string &pMaterial) :
|
|
|
|
mMeshID(pMeshID), mSubMesh(pSubMesh), mMaterial(pMaterial) {
|
|
|
|
ai_assert(!pMeshID.empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator<(const ColladaMeshIndex &p) const {
|
|
|
|
if (mMeshID == p.mMeshID) {
|
|
|
|
if (mSubMesh == p.mSubMesh)
|
2015-05-19 03:57:13 +00:00
|
|
|
return mMaterial < p.mMaterial;
|
|
|
|
else
|
|
|
|
return mSubMesh < p.mSubMesh;
|
2021-02-02 21:06:33 +00:00
|
|
|
} else {
|
2015-05-19 03:57:13 +00:00
|
|
|
return mMeshID < p.mMeshID;
|
|
|
|
}
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Loader class to read Collada scenes. Collada is over-engineered to death, with every new iteration bringing
|
2015-05-19 03:52:10 +00:00
|
|
|
* more useless stuff, so I limited the data to what I think is useful for games.
|
2015-05-19 03:48:29 +00:00
|
|
|
*/
|
2021-02-02 21:06:33 +00:00
|
|
|
class ColladaLoader : public BaseImporter {
|
2015-05-19 03:48:29 +00:00
|
|
|
public:
|
2021-02-02 21:34:30 +00:00
|
|
|
/// The class constructor.
|
2015-05-19 03:57:13 +00:00
|
|
|
ColladaLoader();
|
2021-02-02 21:34:30 +00:00
|
|
|
|
|
|
|
/// The class destructor.
|
2023-11-11 08:59:42 +00:00
|
|
|
~ColladaLoader() override = default;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2021-02-02 21:34:30 +00:00
|
|
|
/// Returns whether the class can handle the format of the given file.
|
|
|
|
/// @see BaseImporter::CanRead() for more details.
|
2021-02-02 21:06:33 +00:00
|
|
|
bool CanRead(const std::string &pFile, IOSystem *pIOHandler, bool checkSig) const override;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
protected:
|
2021-02-02 21:34:30 +00:00
|
|
|
/// See #BaseImporter::GetInfo for the details
|
2021-02-02 21:06:33 +00:00
|
|
|
const aiImporterDesc *GetInfo() const override;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2021-02-02 21:34:30 +00:00
|
|
|
/// See #BaseImporter::SetupProperties for the details
|
2021-02-02 21:06:33 +00:00
|
|
|
void SetupProperties(const Importer *pImp) override;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2021-02-02 21:34:30 +00:00
|
|
|
/// See #BaseImporter::InternReadFile for the details
|
2021-02-02 21:06:33 +00:00
|
|
|
void InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) override;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
/** Recursively constructs a scene node for the given parser node and returns it. */
|
2021-02-02 21:06:33 +00:00
|
|
|
aiNode *BuildHierarchy(const ColladaParser &pParser, const Collada::Node *pNode);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
/** Resolve node instances */
|
2021-02-02 21:06:33 +00:00
|
|
|
void ResolveNodeInstances(const ColladaParser &pParser, const Collada::Node *pNode,
|
|
|
|
std::vector<const Collada::Node *> &resolved);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
/** Builds meshes for the given node and references them */
|
2021-02-02 21:06:33 +00:00
|
|
|
void BuildMeshesForNode(const ColladaParser &pParser, const Collada::Node *pNode,
|
|
|
|
aiNode *pTarget);
|
|
|
|
|
|
|
|
aiMesh *findMesh(const std::string &meshid);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
/** Creates a mesh for the given ColladaMesh face subset and returns the newly created mesh */
|
2021-02-02 21:06:33 +00:00
|
|
|
aiMesh *CreateMesh(const ColladaParser &pParser, const Collada::Mesh *pSrcMesh, const Collada::SubMesh &pSubMesh,
|
|
|
|
const Collada::Controller *pSrcController, size_t pStartVertex, size_t pStartFace);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
/** Builds cameras for the given node and references them */
|
2021-02-02 21:06:33 +00:00
|
|
|
void BuildCamerasForNode(const ColladaParser &pParser, const Collada::Node *pNode,
|
|
|
|
aiNode *pTarget);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
/** Builds lights for the given node and references them */
|
2021-02-02 21:06:33 +00:00
|
|
|
void BuildLightsForNode(const ColladaParser &pParser, const Collada::Node *pNode,
|
|
|
|
aiNode *pTarget);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
/** Stores all meshes in the given scene */
|
2021-02-02 21:06:33 +00:00
|
|
|
void StoreSceneMeshes(aiScene *pScene);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
/** Stores all materials in the given scene */
|
2021-02-02 21:06:33 +00:00
|
|
|
void StoreSceneMaterials(aiScene *pScene);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
/** Stores all lights in the given scene */
|
2021-02-02 21:06:33 +00:00
|
|
|
void StoreSceneLights(aiScene *pScene);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
/** Stores all cameras in the given scene */
|
2021-02-02 21:06:33 +00:00
|
|
|
void StoreSceneCameras(aiScene *pScene);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
/** Stores all textures in the given scene */
|
2021-02-02 21:06:33 +00:00
|
|
|
void StoreSceneTextures(aiScene *pScene);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
/** Stores all animations
|
|
|
|
* @param pScene target scene to store the anims
|
|
|
|
*/
|
2021-02-02 21:06:33 +00:00
|
|
|
void StoreAnimations(aiScene *pScene, const ColladaParser &pParser);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
/** Stores all animations for the given source anim and its nested child animations
|
|
|
|
* @param pScene target scene to store the anims
|
|
|
|
* @param pSrcAnim the source animation to process
|
|
|
|
* @param pPrefix Prefix to the name in case of nested animations
|
|
|
|
*/
|
2021-02-02 21:06:33 +00:00
|
|
|
void StoreAnimations(aiScene *pScene, const ColladaParser &pParser, const Collada::Animation *pSrcAnim, const std::string &pPrefix);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
/** Constructs the animation for the given source anim */
|
2021-02-02 21:06:33 +00:00
|
|
|
void CreateAnimation(aiScene *pScene, const ColladaParser &pParser, const Collada::Animation *pSrcAnim, const std::string &pName);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
/** Constructs materials from the collada material definitions */
|
2021-02-02 21:06:33 +00:00
|
|
|
void BuildMaterials(ColladaParser &pParser, aiScene *pScene);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
/** Fill materials from the collada material definitions */
|
2021-02-02 21:06:33 +00:00
|
|
|
void FillMaterials(const ColladaParser &pParser, aiScene *pScene);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
/** Resolve UV channel mappings*/
|
2021-02-02 21:06:33 +00:00
|
|
|
void ApplyVertexToEffectSemanticMapping(Collada::Sampler &sampler,
|
|
|
|
const Collada::SemanticMappingTable &table);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
/** Add a texture and all of its sampling properties to a material*/
|
2021-02-02 21:06:33 +00:00
|
|
|
void AddTexture(aiMaterial &mat, const ColladaParser &pParser,
|
|
|
|
const Collada::Effect &effect,
|
|
|
|
const Collada::Sampler &sampler,
|
|
|
|
aiTextureType type, unsigned int idx = 0);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
/** Resolves the texture name for the given effect texture entry */
|
2021-02-02 21:06:33 +00:00
|
|
|
aiString FindFilenameForEffectTexture(const ColladaParser &pParser,
|
|
|
|
const Collada::Effect &pEffect, const std::string &pName);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
/** Reads a float value from an accessor and its data array.
|
|
|
|
* @param pAccessor The accessor to use for reading
|
|
|
|
* @param pData The data array to read from
|
|
|
|
* @param pIndex The index of the element to retrieve
|
|
|
|
* @param pOffset Offset into the element, for multipart elements such as vectors or matrices
|
|
|
|
* @return the specified value
|
|
|
|
*/
|
2021-02-02 21:06:33 +00:00
|
|
|
ai_real ReadFloat(const Collada::Accessor &pAccessor, const Collada::Data &pData, size_t pIndex, size_t pOffset) const;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
/** Reads a string value from an accessor and its data array.
|
|
|
|
* @param pAccessor The accessor to use for reading
|
|
|
|
* @param pData The data array to read from
|
|
|
|
* @param pIndex The index of the element to retrieve
|
|
|
|
* @return the specified value
|
|
|
|
*/
|
2021-02-02 21:06:33 +00:00
|
|
|
const std::string &ReadString(const Collada::Accessor &pAccessor, const Collada::Data &pData, size_t pIndex) const;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
/** Recursively collects all nodes into the given array */
|
2021-02-02 21:06:33 +00:00
|
|
|
void CollectNodes(const aiNode *pNode, std::vector<const aiNode *> &poNodes) const;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
/** Finds a node in the collada scene by the given name */
|
2021-02-02 21:06:33 +00:00
|
|
|
const Collada::Node *FindNode(const Collada::Node *pNode, const std::string &pName) const;
|
2015-05-19 03:57:13 +00:00
|
|
|
/** Finds a node in the collada scene by the given SID */
|
2021-02-02 21:06:33 +00:00
|
|
|
const Collada::Node *FindNodeBySID(const Collada::Node *pNode, const std::string &pSID) const;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
/** Finds a proper name for a node derived from the collada-node's properties */
|
2021-02-02 21:06:33 +00:00
|
|
|
std::string FindNameForNode(const Collada::Node *pNode);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
protected:
|
2015-05-19 03:57:13 +00:00
|
|
|
/** Filename, for a verbose error message */
|
|
|
|
std::string mFileName;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
/** Which mesh-material compound was stored under which mesh ID */
|
|
|
|
std::map<ColladaMeshIndex, size_t> mMeshIndexByID;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
/** Which material was stored under which index in the scene */
|
|
|
|
std::map<std::string, size_t> mMaterialIndexByName;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
/** Accumulated meshes for the target scene */
|
2021-02-02 21:06:33 +00:00
|
|
|
std::vector<aiMesh *> mMeshes;
|
|
|
|
|
2017-01-12 11:41:32 +00:00
|
|
|
/** Accumulated morph target meshes */
|
2021-02-02 21:06:33 +00:00
|
|
|
std::vector<aiMesh *> mTargetMeshes;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
/** Temporary material list */
|
2021-02-02 21:06:33 +00:00
|
|
|
std::vector<std::pair<Collada::Effect *, aiMaterial *>> newMats;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
/** Temporary camera list */
|
2021-02-02 21:06:33 +00:00
|
|
|
std::vector<aiCamera *> mCameras;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
/** Temporary light list */
|
2021-02-02 21:06:33 +00:00
|
|
|
std::vector<aiLight *> mLights;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
/** Temporary texture list */
|
2021-02-02 21:06:33 +00:00
|
|
|
std::vector<aiTexture *> mTextures;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
/** Accumulated animations for the target scene */
|
2021-02-02 21:06:33 +00:00
|
|
|
std::vector<aiAnimation *> mAnims;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
bool noSkeletonMesh;
|
2022-06-20 21:09:20 +00:00
|
|
|
bool removeEmptyBones;
|
2015-05-19 03:57:13 +00:00
|
|
|
bool ignoreUpDirection;
|
2023-08-04 07:54:55 +00:00
|
|
|
bool ignoreUnitSize;
|
2018-03-03 16:03:30 +00:00
|
|
|
bool useColladaName;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
/** Used by FindNameForNode() to generate unique node names */
|
|
|
|
unsigned int mNodeNameCounter;
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end of namespace Assimp
|
|
|
|
|
|
|
|
#endif // AI_COLLADALOADER_H_INC
|