2015-07-23 11:51:49 +08:00
|
|
|
/****************************************************************************
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2015-07-24 01:30:34 +08:00
|
|
|
|
2015-07-23 11:51:49 +08:00
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
2019-02-20 17:07:31 +08:00
|
|
|
#pragma once
|
2015-07-23 11:51:49 +08:00
|
|
|
|
|
|
|
#include "base/CCProtocols.h"
|
2015-07-24 01:30:34 +08:00
|
|
|
#include "2d/CCNode.h"
|
|
|
|
#include "renderer/CCCustomCommand.h"
|
2016-03-20 21:53:44 +08:00
|
|
|
#include "editor-support/cocostudio/ActionTimeline/CCTimelineMacro.h"
|
|
|
|
#include "editor-support/cocostudio/CocosStudioExport.h"
|
|
|
|
#include "editor-support/cocostudio/ActionTimeline/CCSkinNode.h"
|
2015-07-23 11:51:49 +08:00
|
|
|
|
2019-02-20 17:07:31 +08:00
|
|
|
namespace cocos2d{ namespace backend {
|
|
|
|
class ProgramState;
|
|
|
|
}}
|
2015-07-24 01:30:34 +08:00
|
|
|
|
2015-07-23 11:51:49 +08:00
|
|
|
NS_TIMELINE_BEGIN
|
|
|
|
|
|
|
|
class SkeletonNode;
|
|
|
|
|
|
|
|
class CC_STUDIO_DLL BoneNode : public cocos2d::Node, public cocos2d::BlendProtocol
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static BoneNode* create();
|
2015-07-24 01:30:34 +08:00
|
|
|
static BoneNode* create(int length);
|
2015-07-23 11:51:49 +08:00
|
|
|
|
|
|
|
using Node::addChild;
|
2015-07-24 01:30:34 +08:00
|
|
|
// add child, and add child to bone list and skeleton's sub bone map or add it to skin list
|
2015-07-23 11:51:49 +08:00
|
|
|
virtual void addChild(cocos2d::Node* child, int localZOrder, const std::string &name) override;
|
|
|
|
virtual void addChild(cocos2d::Node* child, int localZOrder, int tag) override;
|
|
|
|
|
2015-09-22 16:08:23 +08:00
|
|
|
// remove child, and remove child from bone list and skeleton's sub bone map or remove it from skin list
|
2015-07-23 11:51:49 +08:00
|
|
|
virtual void removeChild(Node* child, bool cleanup) override;
|
|
|
|
|
2015-07-24 01:30:34 +08:00
|
|
|
// get child bone list
|
2015-07-23 11:51:49 +08:00
|
|
|
virtual const cocos2d::Vector<BoneNode*>& getChildBones() const { return _childBones; }
|
|
|
|
virtual cocos2d::Vector<BoneNode*>& getChildBones() { return _childBones; }
|
|
|
|
|
2015-07-24 01:30:34 +08:00
|
|
|
|
|
|
|
// get this bone's root skeleton, return null while bone is not in a skeleton
|
|
|
|
virtual SkeletonNode* getRootSkeletonNode() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief: get all bones in this bone tree
|
|
|
|
*/
|
|
|
|
cocos2d::Vector<BoneNode*> getAllSubBones() const;
|
|
|
|
|
2015-07-23 11:51:49 +08:00
|
|
|
/**
|
|
|
|
*@brief: add a skin
|
|
|
|
*@param: display, whether display this skin
|
|
|
|
*/
|
|
|
|
virtual void addSkin(SkinNode* skin, bool display);
|
|
|
|
|
|
|
|
/**
|
|
|
|
*@brief: add a skin
|
|
|
|
*@param: display, whether display this skin
|
|
|
|
*@param: hideOthers, whether hide other skins added to this bone
|
|
|
|
*/
|
|
|
|
virtual void addSkin(SkinNode* skin, bool display, bool hideOthers);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief: display skin
|
|
|
|
* @param: hideOthers, set other skins invisible
|
|
|
|
*/
|
|
|
|
virtual void displaySkin(SkinNode* skin, bool hideOthers);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief: display all skins named skinName, if hide display only one skin,
|
|
|
|
* prefer to use display(SkinNode* skin, bool hideOthers = false)
|
|
|
|
* @param: hideOthers, set other skins invisible
|
|
|
|
*/
|
|
|
|
virtual void displaySkin(const std::string &skinName, bool hideOthers );
|
|
|
|
|
|
|
|
// get the skins which is visible (displaying skins)
|
|
|
|
virtual cocos2d::Vector<SkinNode*> getVisibleSkins() const;
|
|
|
|
|
|
|
|
/**
|
2015-07-24 01:30:34 +08:00
|
|
|
* get skins in this bone's children
|
|
|
|
*/
|
|
|
|
virtual const cocos2d::Vector<SkinNode*>& getSkins() const { return _boneSkins; }
|
|
|
|
virtual cocos2d::Vector<SkinNode*>& getSkins() { return _boneSkins; }
|
|
|
|
|
2015-07-23 11:51:49 +08:00
|
|
|
/**
|
|
|
|
* @brief: get all skins in this bone tree
|
|
|
|
*/
|
|
|
|
cocos2d::Vector<SkinNode*> getAllSubSkins() const;
|
|
|
|
|
|
|
|
// blendFunc
|
|
|
|
virtual void setBlendFunc(const cocos2d::BlendFunc &blendFunc) override;
|
|
|
|
virtual const cocos2d::BlendFunc & getBlendFunc() const override { return _blendFunc; }
|
|
|
|
|
2015-08-07 17:09:11 +08:00
|
|
|
// debug draw show, bone's debugdraw can be draw when bone is visible
|
2016-09-06 10:14:14 +08:00
|
|
|
// when bone's added to skeleton, DebugDrawEnabled controlled by skeleton's DebugDrawEnabled
|
2015-07-23 11:51:49 +08:00
|
|
|
virtual void setDebugDrawEnabled(bool isDebugDraw);
|
|
|
|
virtual bool isDebugDrawEnabled() const { return _isRackShow; }
|
|
|
|
|
2015-07-24 01:30:34 +08:00
|
|
|
// bone's debug draw's length
|
2015-07-23 11:51:49 +08:00
|
|
|
virtual void setDebugDrawLength(float length);
|
|
|
|
virtual float getDebugDrawLength() const { return _rackLength; }
|
|
|
|
|
2015-07-24 01:30:34 +08:00
|
|
|
// bone's debug draw's width
|
2015-07-23 11:51:49 +08:00
|
|
|
virtual void setDebugDrawWidth(float width);
|
|
|
|
virtual float getDebugDrawWidth() const { return _rackWidth; }
|
|
|
|
|
2015-07-24 01:30:34 +08:00
|
|
|
// bone's debug draw's width
|
2015-07-23 11:51:49 +08:00
|
|
|
virtual void setDebugDrawColor(const cocos2d::Color4F &color);
|
|
|
|
virtual cocos2d::Color4F getDebugDrawColor() const { return _rackColor; }
|
|
|
|
|
2015-09-22 16:08:23 +08:00
|
|
|
// get bone's bounding box, depends on getVisibleSkinsRect, apply on node to parent's transform
|
2015-07-23 11:51:49 +08:00
|
|
|
cocos2d::Rect getBoundingBox() const override;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*get displayings rect in self transform
|
|
|
|
*/
|
|
|
|
virtual cocos2d::Rect getVisibleSkinsRect() const;
|
|
|
|
|
|
|
|
// transform & draw
|
|
|
|
virtual void draw(cocos2d::Renderer *renderer, const cocos2d::Mat4 &transform, uint32_t flags) override;
|
|
|
|
|
2015-09-22 16:08:23 +08:00
|
|
|
// set local zorder, and dirty the debugdraw to make debugdraw's render layer right
|
2015-07-23 11:51:49 +08:00
|
|
|
virtual void setLocalZOrder(int localZOrder) override;
|
|
|
|
|
2015-09-22 16:08:23 +08:00
|
|
|
// set name, and replace the subbone map in skeleton
|
2015-07-23 11:51:49 +08:00
|
|
|
virtual void setName(const std::string& name) override;
|
|
|
|
|
2015-07-24 01:30:34 +08:00
|
|
|
// set visible, and dirty the debugdraw to make debugdraw's render layer right
|
2015-07-23 11:51:49 +08:00
|
|
|
virtual void setVisible(bool visible) override;
|
|
|
|
|
2015-09-22 16:08:23 +08:00
|
|
|
// set contentsize, and recalculate debugdraw
|
2015-07-24 01:30:34 +08:00
|
|
|
virtual void setContentSize(const cocos2d::Size& contentSize) override;
|
2015-07-23 11:51:49 +08:00
|
|
|
|
2015-09-22 16:08:23 +08:00
|
|
|
// set localzorder, and recalculate debugdraw
|
2015-07-24 01:30:34 +08:00
|
|
|
virtual void setAnchorPoint(const cocos2d::Vec2& anchorPoint) override;
|
2015-07-23 15:13:14 +08:00
|
|
|
|
2015-07-23 11:51:49 +08:00
|
|
|
#ifdef CC_STUDIO_ENABLED_VIEW
|
|
|
|
// hit test , bonePoint is in self coordinate
|
|
|
|
virtual bool isPointOnRack(const cocos2d::Vec2& bonePoint);
|
|
|
|
#endif
|
|
|
|
|
2015-07-23 15:13:14 +08:00
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
2019-02-20 17:07:31 +08:00
|
|
|
BoneNode() = default;
|
2015-07-23 11:51:49 +08:00
|
|
|
virtual ~BoneNode();
|
|
|
|
virtual bool init() override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual void addToChildrenListHelper(Node * child);
|
|
|
|
virtual void removeFromChildrenListHelper(Node * child);
|
|
|
|
|
|
|
|
// add bone to children bone list, and add bone to skeleton's subbone map
|
|
|
|
virtual void addToBoneList(BoneNode* bone);
|
|
|
|
|
|
|
|
// remove bone from children bone list, and remove bone from skeleton's subbone map
|
|
|
|
virtual void removeFromBoneList(BoneNode* bone);
|
|
|
|
|
|
|
|
// add skin to skin list
|
|
|
|
virtual void addToSkinList(SkinNode* skin);
|
|
|
|
|
|
|
|
// remove skin from skin list
|
|
|
|
virtual void removeFromSkinList(SkinNode* skin);
|
|
|
|
|
|
|
|
// sort all _children , bone list and skin list
|
|
|
|
virtual void sortAllChildren() override;
|
|
|
|
|
|
|
|
virtual void updateVertices();
|
|
|
|
virtual void updateColor() override;
|
|
|
|
|
2015-08-26 20:24:20 +08:00
|
|
|
// bone's color and opacity cannot cascade to bone
|
|
|
|
virtual void updateDisplayedColor(const cocos2d::Color3B& parentColor) override;
|
2019-06-05 17:58:33 +08:00
|
|
|
virtual void updateDisplayedOpacity(uint8_t parentOpacity) override;
|
2015-08-26 20:24:20 +08:00
|
|
|
virtual void disableCascadeOpacity() override;
|
|
|
|
virtual void disableCascadeColor() override;
|
|
|
|
|
2015-08-04 14:13:13 +08:00
|
|
|
// override Node::visit, just visit bones in children
|
|
|
|
virtual void visit(cocos2d::Renderer *renderer, const cocos2d::Mat4& parentTransform, uint32_t parentFlags) override;
|
|
|
|
|
2015-07-23 11:51:49 +08:00
|
|
|
// a help function for SkeletonNode
|
|
|
|
// for batch bone's draw to _rootSkeleton
|
|
|
|
virtual void batchBoneDrawToSkeleton(BoneNode* bone) const;
|
|
|
|
|
2015-09-22 16:08:23 +08:00
|
|
|
// a help function for SkeletonNode
|
2015-08-04 14:13:13 +08:00
|
|
|
// @param bone, visit bone's skins
|
2015-08-07 15:41:31 +08:00
|
|
|
virtual void visitSkins(cocos2d::Renderer* renderer, BoneNode* bone) const;
|
|
|
|
|
|
|
|
// a help function for SkeletonNode
|
|
|
|
// set bone's rootSkeleton = skeleton
|
|
|
|
void setRootSkeleton(BoneNode* bone, SkeletonNode* skeleton) const;
|
2015-07-23 11:51:49 +08:00
|
|
|
protected:
|
|
|
|
cocos2d::CustomCommand _customCommand;
|
2019-02-26 14:57:12 +08:00
|
|
|
cocos2d::backend::UniformLocation _mvpLocation;
|
|
|
|
|
2019-02-20 17:07:31 +08:00
|
|
|
cocos2d::BlendFunc _blendFunc = cocos2d::BlendFunc::ALPHA_NON_PREMULTIPLIED;
|
2015-07-23 11:51:49 +08:00
|
|
|
|
2019-02-20 17:07:31 +08:00
|
|
|
bool _isRackShow = false;
|
|
|
|
cocos2d::Color4F _rackColor = cocos2d::Color4F::WHITE;
|
2019-09-20 11:20:07 +08:00
|
|
|
float _rackLength = 50.0f;
|
|
|
|
float _rackWidth = 20.0f;
|
2015-07-23 11:51:49 +08:00
|
|
|
|
|
|
|
cocos2d::Vector<BoneNode*> _childBones;
|
|
|
|
cocos2d::Vector<SkinNode*> _boneSkins;
|
2019-02-20 17:07:31 +08:00
|
|
|
SkeletonNode* _rootSkeleton = nullptr;
|
2015-07-23 11:51:49 +08:00
|
|
|
private:
|
2019-02-20 17:07:31 +08:00
|
|
|
struct VertexData
|
|
|
|
{
|
|
|
|
cocos2d::Color4F squareColor;
|
|
|
|
cocos2d::Vec3 noMVPVertices;
|
|
|
|
};
|
|
|
|
|
|
|
|
cocos2d::Vec2 _squareVertices[4];
|
|
|
|
VertexData _vertexData[4];
|
|
|
|
|
2015-07-23 11:51:49 +08:00
|
|
|
CC_DISALLOW_COPY_AND_ASSIGN(BoneNode);
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_TIMELINE_END
|