diff --git a/cocos/3d/CCAnimate3D.h b/cocos/3d/CCAnimate3D.h index b8011e3946..ba8ccee7ae 100644 --- a/cocos/3d/CCAnimate3D.h +++ b/cocos/3d/CCAnimate3D.h @@ -38,7 +38,7 @@ NS_CC_BEGIN class Animation3D; -class Bone; +class Bone3D; /** * Animate3D, Animates a Sprite3D given with an Animation3D */ @@ -92,7 +92,7 @@ protected: float _start; //start time 0 - 1, used to generate sub Animate3D float _last; //last time 0 - 1, used to generate sub Animate3D bool _playReverse; // is playing reverse - std::map _boneCurves; //weak ref + std::map _boneCurves; //weak ref }; NS_CC_END diff --git a/cocos/3d/CCMeshSkin.cpp b/cocos/3d/CCMeshSkin.cpp index 64add14d67..3e8d563888 100644 --- a/cocos/3d/CCMeshSkin.cpp +++ b/cocos/3d/CCMeshSkin.cpp @@ -36,22 +36,22 @@ NS_CC_BEGIN * * @param m C3DMatrix representing the inverse bind pose for this Bone. */ -void Bone::setInverseBindPose(const Mat4& m) +void Bone3D::setInverseBindPose(const Mat4& m) { _invBindPose = m; } -const Mat4& Bone::getInverseBindPose() +const Mat4& Bone3D::getInverseBindPose() { return _invBindPose; } -void Bone::setOriPose(const Mat4& m) +void Bone3D::setOriPose(const Mat4& m) { _oriPose = m; } -void Bone::resetPose() +void Bone3D::resetPose() { _local =_oriPose; @@ -60,7 +60,7 @@ void Bone::resetPose() } } -void Bone::setWorldMatDirty(bool dirty) +void Bone3D::setWorldMatDirty(bool dirty) { _worldDirty = dirty; for (auto it : _children) { @@ -69,7 +69,7 @@ void Bone::setWorldMatDirty(bool dirty) } //update own world matrix and children's -void Bone::updateWorldMat() +void Bone3D::updateWorldMat() { getWorldMat(); for (auto itor : _children) { @@ -77,7 +77,7 @@ void Bone::updateWorldMat() } } -const Mat4& Bone::getWorldMat() +const Mat4& Bone3D::getWorldMat() { if (_worldDirty) { @@ -95,7 +95,7 @@ const Mat4& Bone::getWorldMat() return _world; } -void Bone::setAnimationValue(float* trans, float* rot, float* scale, void* tag, float weight) +void Bone3D::setAnimationValue(float* trans, float* rot, float* scale, void* tag, float weight) { for (auto& it : _blendStates) { if (it.tag == tag) @@ -124,7 +124,7 @@ void Bone::setAnimationValue(float* trans, float* rot, float* scale, void* tag, _blendStates.push_back(state); } -void Bone::clearBoneBlendState() +void Bone3D::clearBoneBlendState() { _blendStates.clear(); for (auto it : _children) { @@ -135,14 +135,14 @@ void Bone::clearBoneBlendState() /** * Creates C3DBone. */ -Bone* Bone::create(const std::string& id) +Bone3D* Bone3D::create(const std::string& id) { - auto bone = new Bone(id); + auto bone = new Bone3D(id); bone->autorelease(); return bone; } -void Bone::updateJointMatrix(Vec4* matrixPalette) +void Bone3D::updateJointMatrix(Vec4* matrixPalette) { { static Mat4 t; @@ -154,37 +154,37 @@ void Bone::updateJointMatrix(Vec4* matrixPalette) } } -Bone* Bone::getParentBone() +Bone3D* Bone3D::getParentBone() { return _parent; } -ssize_t Bone::getChildBoneCount() const +ssize_t Bone3D::getChildBoneCount() const { return _children.size(); } -Bone* Bone::getChildBoneByIndex(int index) +Bone3D* Bone3D::getChildBoneByIndex(int index) { return _children.at(index); } -void Bone::addChildBone(Bone* bone) +void Bone3D::addChildBone(Bone3D* bone) { if (_children.find(bone) == _children.end()) _children.pushBack(bone); } -void Bone::removeChildBoneByIndex(int index) +void Bone3D::removeChildBoneByIndex(int index) { _children.erase(index); } -void Bone::removeChildBone(Bone* bone) +void Bone3D::removeChildBone(Bone3D* bone) { _children.eraseObject(bone); } -void Bone::removeAllChildBone() +void Bone3D::removeAllChildBone() { _children.clear(); } -Bone::Bone(const std::string& id) +Bone3D::Bone3D(const std::string& id) : _name(id) , _parent(nullptr) , _worldDirty(true) @@ -192,12 +192,12 @@ Bone::Bone(const std::string& id) } -Bone::~Bone() +Bone3D::~Bone3D() { removeAllChildBone(); } -void Bone::updateLocalMat() +void Bone3D::updateLocalMat() { if (_blendStates.size()) { @@ -299,13 +299,13 @@ bool MeshSkin::initFromSkinData(const SkinData& skindata) { ssize_t i = 0; for (; i < skindata.skinBoneNames.size(); i++) { - auto bone = Bone::create(skindata.skinBoneNames[i]); + auto bone = Bone3D::create(skindata.skinBoneNames[i]); bone->_invBindPose = skindata.inverseBindPoseMatrices[i]; bone->setOriPose(skindata.skinBoneOriginMatrices[i]); addSkinBone(bone); } for (i = 0; i < skindata.nodeBoneNames.size(); i++) { - auto bone = Bone::create(skindata.nodeBoneNames[i]); + auto bone = Bone3D::create(skindata.nodeBoneNames[i]); bone->setOriPose(skindata.nodeBoneOriginMatrices[i]); addNodeBone(bone); } @@ -330,7 +330,7 @@ ssize_t MeshSkin::getBoneCount() const } //get bone -Bone* MeshSkin::getBoneByIndex(unsigned int index) const +Bone3D* MeshSkin::getBoneByIndex(unsigned int index) const { if (index < _skinBones.size()) return _skinBones.at(index); @@ -340,7 +340,7 @@ Bone* MeshSkin::getBoneByIndex(unsigned int index) const return nullptr; } -Bone* MeshSkin::getBoneByName(const std::string& id) const +Bone3D* MeshSkin::getBoneByName(const std::string& id) const { //search from skin bones for (auto it : _skinBones) { @@ -355,18 +355,18 @@ Bone* MeshSkin::getBoneByName(const std::string& id) const return nullptr; } -Bone* MeshSkin::getRootBone() const +Bone3D* MeshSkin::getRootBone() const { return _rootBone; } -void MeshSkin::setRootBone(Bone* joint) +void MeshSkin::setRootBone(Bone3D* joint) { CC_SAFE_RETAIN(joint); CC_SAFE_RELEASE(_rootBone); _rootBone = joint; } -int MeshSkin::getBoneIndex(Bone* bone) const +int MeshSkin::getBoneIndex(Bone3D* bone) const { int i = 0; for (; i < _skinBones.size(); i++) { @@ -419,12 +419,12 @@ void MeshSkin::removeAllBones() CC_SAFE_RELEASE(_rootBone); } -void MeshSkin::addSkinBone(Bone* bone) +void MeshSkin::addSkinBone(Bone3D* bone) { _skinBones.pushBack(bone); } -void MeshSkin::addNodeBone(Bone* bone) +void MeshSkin::addNodeBone(Bone3D* bone) { _nodeBones.pushBack(bone); } diff --git a/cocos/3d/CCMeshSkin.h b/cocos/3d/CCMeshSkin.h index eaeaa03467..b031afeefb 100644 --- a/cocos/3d/CCMeshSkin.h +++ b/cocos/3d/CCMeshSkin.h @@ -40,7 +40,7 @@ NS_CC_BEGIN /** * Defines a basic hierachial structure of transformation spaces. */ -class Bone : public Ref +class Bone3D : public Ref { friend class MeshSkin; public: @@ -76,7 +76,7 @@ public: /** * Creates C3DBone. */ - static Bone* create(const std::string& id); + static Bone3D* create(const std::string& id); /** * Sets the inverse bind pose matrix. @@ -105,17 +105,17 @@ public: void updateJointMatrix(Vec4* matrixPalette); /**bone tree, we do not inherit from Node, Node has too many properties that we do not need. A clean Node is needed.*/ - Bone* getParentBone(); + Bone3D* getParentBone(); /**get child bone count*/ ssize_t getChildBoneCount() const; /**get child bone by index*/ - Bone* getChildBoneByIndex(int index); + Bone3D* getChildBoneByIndex(int index); /**add child bone*/ - void addChildBone(Bone* bone); + void addChildBone(Bone3D* bone); /**remove child bone by index*/ void removeChildBoneByIndex(int index); /**remove child bone*/ - void removeChildBone(Bone* bone); + void removeChildBone(Bone3D* bone); /**remove all child bone*/ void removeAllChildBone(); @@ -143,12 +143,12 @@ protected: /** * Constructor. */ - Bone(const std::string& id); + Bone3D(const std::string& id); /** * Destructor. */ - virtual ~Bone(); + virtual ~Bone3D(); /** * Update local matrix @@ -166,9 +166,9 @@ protected: Mat4 _oriPose; //original bone pose - Bone* _parent; //parent bone + Bone3D* _parent; //parent bone - Vector _children; + Vector _children; bool _worldDirty; Mat4 _world; @@ -193,15 +193,15 @@ public: ssize_t getBoneCount() const; /**get bone*/ - Bone* getBoneByIndex(unsigned int index) const; - Bone* getBoneByName(const std::string& id) const; + Bone3D* getBoneByIndex(unsigned int index) const; + Bone3D* getBoneByName(const std::string& id) const; /**get & set root bone*/ - Bone* getRootBone() const; - void setRootBone(Bone* bone); + Bone3D* getRootBone() const; + void setRootBone(Bone3D* bone); /**get bone index*/ - int getBoneIndex(Bone* bone) const; + int getBoneIndex(Bone3D* bone) const; /**compute matrix palette used by gpu skin*/ Vec4* getMatrixPalette(); @@ -225,17 +225,17 @@ CC_CONSTRUCTOR_ACCESS: void removeAllBones(); /**add skin bone*/ - void addSkinBone(Bone* bone); + void addSkinBone(Bone3D* bone); /**add Node bone*/ - void addNodeBone(Bone* bone); + void addNodeBone(Bone3D* bone); protected: - Vector _skinBones; // bones with skin - Vector _nodeBones; //bones without skin, only used to compute transform of children + Vector _skinBones; // bones with skin + Vector _nodeBones; //bones without skin, only used to compute transform of children - Bone* _rootBone; + Bone3D* _rootBone; // Pointer to the array of palette matrices. // This array is passed to the vertex shader as a uniform.