123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- #ifndef __CCSKELETON3D_H__
- #define __CCSKELETON3D_H__
- #include "3d/CCBundle3DData.h"
- #include "base/CCRef.h"
- #include "base/CCVector.h"
- NS_CC_BEGIN
- class CC_DLL Bone3D : public Ref
- {
- friend class Skeleton3D;
- friend class MeshSkin;
- public:
-
-
- const Mat4& getInverseBindPose();
-
-
- void updateWorldMat();
-
-
- const Mat4& getWorldMat();
-
-
- const std::string& getName() const { return _name; }
-
-
- void setAnimationValue(float* trans, float* rot, float* scale, void* tag = nullptr, float weight = 1.0f);
-
-
- void clearBoneBlendState();
-
- static Bone3D* create(const std::string& id);
-
-
- void setInverseBindPose(const Mat4& m);
-
-
- void setOriPose(const Mat4& m);
-
-
- void resetPose();
-
-
- void updateJointMatrix(Vec4* matrixPalette);
-
-
- Bone3D* getParentBone();
-
- ssize_t getChildBoneCount() const;
-
- Bone3D* getChildBoneByIndex(int index) const;
-
- void addChildBone(Bone3D* bone);
-
- void removeChildBoneByIndex(int index);
-
- void removeChildBone(Bone3D* bone);
-
- void removeAllChildBone();
-
-
-
- protected:
-
- struct BoneBlendState
- {
- Vec3 localTranslate;
- Quaternion localRot;
- Vec3 localScale;
- float weight;
- void* tag;
- BoneBlendState()
- : localRot(Quaternion::identity())
- , localScale(Vec3::ONE)
- , weight(1.f)
- , tag(nullptr)
- {
-
- }
- };
-
- Bone3D(const std::string& id);
-
-
- virtual ~Bone3D();
-
-
- void updateLocalMat();
-
-
- void setWorldMatDirty(bool dirty = true);
-
- std::string _name;
-
- Mat4 _invBindPose;
-
- Mat4 _oriPose;
-
- Bone3D* _parent;
-
- Vector<Bone3D*> _children;
-
- bool _worldDirty;
- Mat4 _world;
- Mat4 _local;
-
- std::vector<BoneBlendState> _blendStates;
-
- };
- class CC_DLL Skeleton3D: public Ref
- {
- public:
-
- static Skeleton3D* create(const std::vector<NodeData*>& skeletondata);
-
-
- ssize_t getBoneCount() const;
-
-
- Bone3D* getBoneByIndex(unsigned int index) const;
- Bone3D* getBoneByName(const std::string& id) const;
-
-
- ssize_t getRootCount() const;
- Bone3D* getRootBone(int index) const;
-
-
- int getBoneIndex(Bone3D* bone) const;
-
-
- void updateBoneMatrix();
-
- CC_CONSTRUCTOR_ACCESS:
-
- Skeleton3D();
-
- ~Skeleton3D();
-
-
- void removeAllBones();
-
-
- void addBone(Bone3D* bone);
-
-
- Bone3D* createBone3D(const NodeData& nodedata);
-
- protected:
-
- Vector<Bone3D*> _bones;
- Vector<Bone3D*> _rootBones;
- };
- NS_CC_END
- #endif
|