123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454 |
- #ifndef __CC_BUNDLE_3D_DATA_H__
- #define __CC_BUNDLE_3D_DATA_H__
- #include "base/CCRef.h"
- #include "base/ccTypes.h"
- #include "math/CCMath.h"
- #include "3d/CCAABB.h"
- #include <vector>
- #include <map>
-
- NS_CC_BEGIN
- struct MeshVertexAttrib
- {
-
- GLint size;
-
- GLenum type;
-
- int vertexAttrib;
-
- int attribSizeBytes;
- };
- struct ModelData
- {
- std::string subMeshId;
- std::string materialId;
- std::vector<std::string> bones;
- std::vector<Mat4> invBindPose;
-
- virtual ~ModelData()
- {
- resetData();
- }
- virtual void resetData()
- {
- bones.clear();
- invBindPose.clear();
- }
- };
- struct NodeData
- {
- std::string id;
- Mat4 transform;
- std::vector<ModelData*> modelNodeDatas;
- std::vector<NodeData*> children;
- virtual ~NodeData()
- {
- resetData();
- }
- virtual void resetData()
- {
- id.clear();
- transform.setIdentity();
- for (auto& it : children)
- {
- delete it;
- }
- children.clear();
-
- for(auto& modeldata : modelNodeDatas)
- {
- delete modeldata;
- }
- modelNodeDatas.clear();
- }
- };
- struct NodeDatas
- {
- std::vector<NodeData*> skeleton;
- std::vector<NodeData*> nodes;
-
- virtual ~NodeDatas()
- {
- resetData();
- }
-
- void resetData()
- {
- for(auto& it : skeleton)
- {
- delete it;
- }
- skeleton.clear();
- for(auto& it : nodes)
- {
- delete it;
- }
- nodes.clear();
- }
- };
- struct MeshData
- {
- typedef std::vector<unsigned short> IndexArray;
- std::vector<float> vertex;
- int vertexSizeInFloat;
- std::vector<IndexArray> subMeshIndices;
- std::vector<std::string> subMeshIds;
- std::vector<AABB> subMeshAABB;
- int numIndex;
- std::vector<MeshVertexAttrib> attribs;
- int attribCount;
- public:
-
- int getPerVertexSize() const
- {
- int vertexsize = 0;
- for(const auto& attrib : attribs)
- {
- vertexsize += attrib.attribSizeBytes;
- }
- return vertexsize;
- }
-
- void resetData()
- {
- vertex.clear();
- subMeshIndices.clear();
- subMeshAABB.clear();
- attribs.clear();
- vertexSizeInFloat = 0;
- numIndex = 0;
- attribCount = 0;
- }
- MeshData()
- : vertexSizeInFloat(0)
- , numIndex(0)
- , attribCount(0)
- {
- }
- ~MeshData()
- {
- resetData();
- }
- };
- struct MeshDatas
- {
- std::vector<MeshData*> meshDatas;
-
- void resetData()
- {
- for(auto& it : meshDatas)
- {
- delete it;
- }
- meshDatas.clear();
- }
- ~MeshDatas()
- {
- resetData();
- }
- };
- struct SkinData
- {
- std::vector<std::string> skinBoneNames;
- std::vector<std::string> nodeBoneNames;
- std::vector<Mat4> inverseBindPoseMatrices;
- std::vector<Mat4> skinBoneOriginMatrices;
- std::vector<Mat4> nodeBoneOriginMatrices;
-
-
- std::map<int, std::vector<int> > boneChild;
- int rootBoneIndex;
- void resetData()
- {
- skinBoneNames.clear();
- nodeBoneNames.clear();
- inverseBindPoseMatrices.clear();
- skinBoneOriginMatrices.clear();
- nodeBoneOriginMatrices.clear();
- boneChild.clear();
- rootBoneIndex = -1;
- }
- void addSkinBoneNames(const std::string& name)
- {
- auto it = std::find(skinBoneNames.begin(), skinBoneNames.end(), name);
- if (it == skinBoneNames.end())
- skinBoneNames.push_back(name);
- }
-
- void addNodeBoneNames(const std::string& name)
- {
- auto it = std::find(nodeBoneNames.begin(), nodeBoneNames.end(), name);
- if (it == nodeBoneNames.end())
- nodeBoneNames.push_back(name);
- }
-
- int getSkinBoneNameIndex(const std::string& name)const
- {
- int i = 0;
- for (const auto& iter : skinBoneNames)
- {
- if ((iter) == name)
- return i;
- i++;
- }
- return -1;
- }
-
- int getBoneNameIndex(const std::string& name)const
- {
- int i = 0;
- for (const auto& iter : skinBoneNames)
- {
- if ((iter) == name)
- return i;
- i++;
- }
- for(const auto& iter : nodeBoneNames)
- {
- if (iter == name)
- return i;
- i++;
- }
- return -1;
- }
- };
- struct MaterialData
- {
- std::map<int, std::string> texturePaths;
- void resetData()
- {
- texturePaths.clear();
- }
- };
- struct NTextureData
- {
- enum class Usage {
- Unknown = 0,
- None = 1,
- Diffuse = 2,
- Emissive = 3,
- Ambient = 4,
- Specular = 5,
- Shininess = 6,
- Normal = 7,
- Bump = 8,
- Transparency = 9,
- Reflection = 10
- };
- std::string id;
- std::string filename;
- Usage type;
- GLenum wrapS;
- GLenum wrapT;
- } ;
- struct NMaterialData
- {
- std::vector<NTextureData> textures;
- std::string id;
- const NTextureData* getTextureData(const NTextureData::Usage& type) const
- {
- for(const auto& it : textures)
- {
- if (it.type == type)
- return ⁢
- }
- return nullptr;
- }
- };
- struct MaterialDatas
- {
- std::vector<NMaterialData> materials;
- void resetData()
- {
- materials.clear();
- }
- const NMaterialData* getMaterialData(const std::string& materialid) const
- {
- for(const auto& it : materials)
- {
- if (it.id == materialid)
- return ⁢
- }
- return nullptr;
- }
- };
- struct Animation3DData
- {
- public:
- struct Vec3Key
- {
- Vec3Key()
- : _time(0)
- {
- }
-
- Vec3Key(float time, const Vec3& v)
- : _time(time)
- , _key(v)
- {
- }
-
- float _time;
- Vec3 _key;
- };
-
- struct QuatKey
- {
- QuatKey()
- : _time(0)
- , _key(Quaternion::identity())
- {
- }
-
- QuatKey(float time, const Quaternion& quat)
- : _time(time)
- , _key(quat)
- {
- }
-
- float _time;
- Quaternion _key;
- };
- public:
- std::map<std::string, std::vector<Vec3Key>> _translationKeys;
- std::map<std::string, std::vector<QuatKey>> _rotationKeys;
- std::map<std::string, std::vector<Vec3Key>> _scaleKeys;
-
- float _totalTime;
- public:
- Animation3DData()
- :_totalTime(0)
- {
- }
-
- Animation3DData(const Animation3DData& other)
- : _translationKeys(other._translationKeys)
- , _rotationKeys(other._rotationKeys)
- , _scaleKeys(other._scaleKeys)
- , _totalTime(other._totalTime)
- {
- }
-
- void resetData()
- {
- _totalTime = 0;
- _translationKeys.clear();
- _rotationKeys.clear();
- _scaleKeys.clear();
- }
- };
- struct Reference
- {
- public:
- std::string id;
- unsigned int type;
- unsigned int offset;
- Reference(){}
- ~Reference(){}
- };
- NS_CC_END
- #endif
|