2015-07-23 11:51:49 +08:00
|
|
|
/****************************************************************************
|
2020-10-17 16:32:16 +08:00
|
|
|
Copyright (c) 2015-2017 Chukong Technologies Inc.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-02-24 18:51:36 +08:00
|
|
|
https://adxeproject.github.io/
|
2015-07-23 11:51:49 +08:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __CCSKELETONNODE_H__
|
2021-12-25 10:04:45 +08:00
|
|
|
#define __CCSKELETONNODE_H__
|
2015-07-23 11:51:49 +08:00
|
|
|
|
2020-10-21 10:12:00 +08:00
|
|
|
#include "ActionTimeline/CCTimelineMacro.h"
|
2015-07-23 11:51:49 +08:00
|
|
|
#include "renderer/CCRenderer.h"
|
2020-10-21 10:12:00 +08:00
|
|
|
#include "CocosStudioExport.h"
|
2015-07-23 11:51:49 +08:00
|
|
|
#include "base/CCMap.h"
|
|
|
|
|
2020-10-21 10:12:00 +08:00
|
|
|
#include "ActionTimeline/CCBoneNode.h"
|
2015-07-23 11:51:49 +08:00
|
|
|
|
|
|
|
NS_TIMELINE_BEGIN
|
|
|
|
|
2020-10-17 16:32:16 +08:00
|
|
|
class CCS_DLL SkeletonNode : public BoneNode
|
2015-07-23 11:51:49 +08:00
|
|
|
{
|
|
|
|
friend class BoneNode;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static SkeletonNode* create();
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
*get bonenode in skeleton node by bone name
|
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
BoneNode* getBoneNode(std::string_view boneName);
|
2015-07-23 11:51:49 +08:00
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
*get All bones in this skeleton, <bone's name, BoneNode>
|
|
|
|
*/
|
2021-12-27 13:52:08 +08:00
|
|
|
const cocos2d::StringMap<BoneNode*>& getAllSubBonesMap() const;
|
2015-07-23 11:51:49 +08:00
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
*@brief: change displays
|
|
|
|
*@param: boneSkinNameMap, map <name of bone, name of skin to display which added to bone>
|
|
|
|
*/
|
2021-12-27 13:52:08 +08:00
|
|
|
void changeSkins(const hlookup::string_map<std::string>& boneSkinNameMap);
|
2015-07-23 11:51:49 +08:00
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
*@brief: change displays
|
|
|
|
*@param: skinGroupName have
|
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
void changeSkins(std::string_view skinGroupName);
|
2015-07-23 11:51:49 +08:00
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
*@brief: add a boneSkinNameMap as a SkinGroup named groupName
|
|
|
|
*@param: groupName, key
|
|
|
|
*@param: boneSkinNameMap, map <name of bone, name of skin to display which added to bone>
|
|
|
|
*/
|
2021-12-27 13:52:08 +08:00
|
|
|
void addSkinGroup(std::string groupName, hlookup::string_map<std::string> boneSkinNameMap);
|
2015-07-23 11:51:49 +08:00
|
|
|
|
|
|
|
cocos2d::Rect getBoundingBox() const override;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
CC_CONSTRUCTOR_ACCESS : SkeletonNode();
|
2015-07-23 11:51:49 +08:00
|
|
|
virtual ~SkeletonNode();
|
|
|
|
virtual bool init() override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-07-23 15:13:14 +08:00
|
|
|
protected:
|
2015-07-23 11:51:49 +08:00
|
|
|
virtual void updateVertices() override;
|
|
|
|
virtual void updateColor() override;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void visit(cocos2d::Renderer* renderer,
|
|
|
|
const cocos2d::Mat4& parentTransform,
|
|
|
|
uint32_t parentFlags) override;
|
|
|
|
virtual void draw(cocos2d::Renderer* renderer, const cocos2d::Mat4& transform, uint32_t flags) override;
|
2015-07-23 11:51:49 +08:00
|
|
|
|
|
|
|
protected:
|
2021-12-27 13:52:08 +08:00
|
|
|
cocos2d::StringMap<BoneNode*> _subBonesMap;
|
2015-07-23 11:51:49 +08:00
|
|
|
|
|
|
|
private:
|
2019-11-25 01:35:26 +08:00
|
|
|
struct VertexData
|
|
|
|
{
|
|
|
|
cocos2d::Vec3 vertex;
|
|
|
|
cocos2d::Color4F color;
|
|
|
|
};
|
|
|
|
|
|
|
|
cocos2d::Vec2 _squareVertices[8];
|
|
|
|
VertexData _vertexData[8];
|
2015-07-23 11:51:49 +08:00
|
|
|
|
2021-12-28 11:00:34 +08:00
|
|
|
hlookup::string_map<hlookup::string_map<std::string>>
|
2021-12-25 10:04:45 +08:00
|
|
|
_skinGroupMap; // map< suit name, map< bone name, skin name> >
|
2015-07-23 11:51:49 +08:00
|
|
|
CC_DISALLOW_COPY_AND_ASSIGN(SkeletonNode);
|
|
|
|
|
2015-08-04 14:13:13 +08:00
|
|
|
void checkSubBonesDirty();
|
|
|
|
// for draw skins as ordered bones' local z
|
2021-12-25 10:04:45 +08:00
|
|
|
cocos2d::Vector<BoneNode*> _subOrderedAllBones;
|
2015-08-04 14:13:13 +08:00
|
|
|
void updateOrderedAllbones();
|
|
|
|
void sortOrderedAllBones();
|
2015-07-23 11:51:49 +08:00
|
|
|
// for batch draw sub bones
|
2021-12-25 10:04:45 +08:00
|
|
|
bool _subBonesDirty;
|
|
|
|
bool _subBonesOrderDirty;
|
2019-11-25 01:35:26 +08:00
|
|
|
std::vector<VertexData> _batchedBoneVertexData;
|
2021-12-25 10:04:45 +08:00
|
|
|
int _batchedVeticesCount;
|
|
|
|
cocos2d::CustomCommand _batchBoneCommand;
|
2015-07-23 11:51:49 +08:00
|
|
|
|
2019-11-25 01:35:26 +08:00
|
|
|
void batchDrawAllSubBones();
|
2015-07-23 11:51:49 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_TIMELINE_END
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
#endif //__CCSKELETONNODE_H__
|