2013-06-06 12:02:54 +08:00
|
|
|
/****************************************************************************
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2013-06-06 12:02:54 +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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-03-20 21:53:44 +08:00
|
|
|
#include "editor-support/cocostudio/CCBone.h"
|
|
|
|
#include "editor-support/cocostudio/CCArmature.h"
|
|
|
|
#include "editor-support/cocostudio/CCUtilMath.h"
|
|
|
|
#include "editor-support/cocostudio/CCArmatureDataManager.h"
|
|
|
|
#include "editor-support/cocostudio/CCTransformHelp.h"
|
|
|
|
#include "editor-support/cocostudio/CCDisplayManager.h"
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
using namespace cocos2d;
|
|
|
|
|
|
|
|
namespace cocostudio {
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
Bone *Bone::create()
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
|
|
|
|
2014-08-28 07:31:57 +08:00
|
|
|
Bone *pBone = new (std::nothrow) Bone();
|
2013-06-06 12:02:54 +08:00
|
|
|
if (pBone && pBone->init())
|
|
|
|
{
|
|
|
|
pBone->autorelease();
|
|
|
|
return pBone;
|
|
|
|
}
|
|
|
|
CC_SAFE_DELETE(pBone);
|
2013-11-05 15:32:13 +08:00
|
|
|
return nullptr;
|
2013-06-06 12:02:54 +08:00
|
|
|
|
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-12-23 14:05:46 +08:00
|
|
|
Bone *Bone::create(const std::string& name)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2014-08-28 07:31:57 +08:00
|
|
|
Bone *pBone = new (std::nothrow) Bone();
|
2013-06-06 12:02:54 +08:00
|
|
|
if (pBone && pBone->init(name))
|
|
|
|
{
|
|
|
|
pBone->autorelease();
|
|
|
|
return pBone;
|
|
|
|
}
|
|
|
|
CC_SAFE_DELETE(pBone);
|
2013-11-05 15:32:13 +08:00
|
|
|
return nullptr;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
Bone::Bone()
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-11-05 15:32:13 +08:00
|
|
|
_tweenData = nullptr;
|
|
|
|
_parentBone = nullptr;
|
|
|
|
_armature = nullptr;
|
|
|
|
_childArmature = nullptr;
|
|
|
|
_boneData = nullptr;
|
|
|
|
_tween = nullptr;
|
|
|
|
_displayManager = nullptr;
|
2013-09-16 12:21:18 +08:00
|
|
|
_ignoreMovementBoneData = false;
|
2014-05-15 01:07:09 +08:00
|
|
|
_worldTransform = Mat4::IDENTITY;
|
2013-09-16 12:21:18 +08:00
|
|
|
_boneTransformDirty = true;
|
2014-07-23 20:07:33 +08:00
|
|
|
_blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
|
2013-12-13 15:02:09 +08:00
|
|
|
_blendDirty = false;
|
2013-11-05 15:32:13 +08:00
|
|
|
_worldInfo = nullptr;
|
2013-10-30 09:41:40 +08:00
|
|
|
|
2013-11-05 15:32:13 +08:00
|
|
|
_armatureParentBone = nullptr;
|
2013-10-30 09:41:40 +08:00
|
|
|
_dataVersion = 0;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-22 09:38:46 +08:00
|
|
|
Bone::~Bone()
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
CC_SAFE_DELETE(_tweenData);
|
2013-09-16 14:56:59 +08:00
|
|
|
CC_SAFE_DELETE(_tween);
|
2013-09-16 12:21:18 +08:00
|
|
|
CC_SAFE_DELETE(_displayManager);
|
2013-10-30 09:41:40 +08:00
|
|
|
CC_SAFE_DELETE(_worldInfo);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-11-05 11:57:20 +08:00
|
|
|
CC_SAFE_RELEASE_NULL(_boneData);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-09-16 12:21:18 +08:00
|
|
|
CC_SAFE_RELEASE(_childArmature);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
bool Bone::init()
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2019-07-22 09:35:57 +08:00
|
|
|
return Bone::init("");
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-23 14:05:46 +08:00
|
|
|
bool Bone::init(const std::string& name)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
|
|
|
bool bRet = false;
|
|
|
|
do
|
|
|
|
{
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-12-23 14:05:46 +08:00
|
|
|
_name = name;
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
CC_SAFE_DELETE(_tweenData);
|
2014-08-28 07:31:57 +08:00
|
|
|
_tweenData = new (std::nothrow) FrameData();
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-09-16 14:56:59 +08:00
|
|
|
CC_SAFE_DELETE(_tween);
|
2014-08-28 07:31:57 +08:00
|
|
|
_tween = new (std::nothrow) Tween();
|
2013-09-16 14:56:59 +08:00
|
|
|
_tween->init(this);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-09-16 12:21:18 +08:00
|
|
|
CC_SAFE_DELETE(_displayManager);
|
2014-08-28 07:31:57 +08:00
|
|
|
_displayManager = new (std::nothrow) DisplayManager();
|
2013-09-16 12:21:18 +08:00
|
|
|
_displayManager->init(this);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-10-30 09:41:40 +08:00
|
|
|
CC_SAFE_DELETE(_worldInfo);
|
2014-08-28 07:31:57 +08:00
|
|
|
_worldInfo = new (std::nothrow) BaseData();
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-11-05 11:57:20 +08:00
|
|
|
CC_SAFE_DELETE(_boneData);
|
2014-08-28 07:31:57 +08:00
|
|
|
_boneData = new (std::nothrow) BoneData();
|
2013-11-05 11:57:20 +08:00
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
bRet = true;
|
|
|
|
}
|
|
|
|
while (0);
|
|
|
|
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
void Bone::setBoneData(BoneData *boneData)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-11-05 15:32:13 +08:00
|
|
|
CCASSERT(nullptr != boneData, "_boneData must not be nullptr");
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-11-05 11:57:20 +08:00
|
|
|
if (_boneData != boneData)
|
|
|
|
{
|
|
|
|
CC_SAFE_RETAIN(boneData);
|
|
|
|
CC_SAFE_RELEASE(_boneData);
|
|
|
|
_boneData = boneData;
|
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-09-16 12:21:18 +08:00
|
|
|
_name = _boneData->name;
|
2016-07-31 22:44:24 +08:00
|
|
|
_setLocalZOrder(_boneData->zOrder);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-09-16 12:21:18 +08:00
|
|
|
_displayManager->initDisplayList(boneData);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-11-05 19:53:38 +08:00
|
|
|
BoneData *Bone::getBoneData() const
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-16 12:21:18 +08:00
|
|
|
return _boneData;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
void Bone::setArmature(Armature *armature)
|
2013-06-08 22:08:22 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
_armature = armature;
|
|
|
|
if (_armature)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-16 14:56:59 +08:00
|
|
|
_tween->setAnimation(_armature->getAnimation());
|
2013-10-30 09:41:40 +08:00
|
|
|
_dataVersion = _armature->getArmatureData()->dataVersion;
|
|
|
|
_armatureParentBone = _armature->getParentBone();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-05 15:32:13 +08:00
|
|
|
_armatureParentBone = nullptr;
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
2013-06-08 22:08:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-05 19:53:38 +08:00
|
|
|
Armature *Bone::getArmature() const
|
2013-06-08 22:08:22 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
return _armature;
|
2013-06-08 22:08:22 +08:00
|
|
|
}
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
void Bone::update(float delta)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
if (_parentBone)
|
2013-09-16 12:21:18 +08:00
|
|
|
_boneTransformDirty = _boneTransformDirty || _parentBone->isTransformDirty();
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-10-30 09:41:40 +08:00
|
|
|
if (_armatureParentBone && !_boneTransformDirty)
|
2013-10-29 16:57:06 +08:00
|
|
|
{
|
2013-10-30 09:41:40 +08:00
|
|
|
_boneTransformDirty = _armatureParentBone->isTransformDirty();
|
2013-10-29 16:57:06 +08:00
|
|
|
}
|
|
|
|
|
2013-09-16 12:21:18 +08:00
|
|
|
if (_boneTransformDirty)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2014-11-06 17:51:19 +08:00
|
|
|
_worldInfo->copy(_tweenData);
|
2013-10-30 09:41:40 +08:00
|
|
|
if (_dataVersion >= VERSION_COMBINED)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2014-11-06 17:51:19 +08:00
|
|
|
TransformHelp::nodeConcat(*_worldInfo, *_boneData);
|
|
|
|
_worldInfo->scaleX -= 1;
|
|
|
|
_worldInfo->scaleY -= 1;
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2014-11-06 17:51:19 +08:00
|
|
|
_worldInfo->x = _worldInfo->x + _position.x;
|
|
|
|
_worldInfo->y = _worldInfo->y + _position.y;
|
|
|
|
_worldInfo->scaleX = _worldInfo->scaleX * _scaleX;
|
|
|
|
_worldInfo->scaleY = _worldInfo->scaleY * _scaleY;
|
|
|
|
_worldInfo->skewX = _worldInfo->skewX + _skewX + CC_DEGREES_TO_RADIANS(_rotationZ_X);
|
|
|
|
_worldInfo->skewY = _worldInfo->skewY + _skewY - CC_DEGREES_TO_RADIANS(_rotationZ_Y);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
if(_parentBone)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-10-30 09:41:40 +08:00
|
|
|
applyParentTransform(_parentBone);
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
2013-10-29 16:57:06 +08:00
|
|
|
else
|
|
|
|
{
|
2013-10-30 09:41:40 +08:00
|
|
|
if (_armatureParentBone)
|
2013-10-29 16:57:06 +08:00
|
|
|
{
|
2013-10-30 09:41:40 +08:00
|
|
|
applyParentTransform(_armatureParentBone);
|
2013-10-29 16:57:06 +08:00
|
|
|
}
|
|
|
|
}
|
2013-10-30 09:41:40 +08:00
|
|
|
|
|
|
|
TransformHelp::nodeToMatrix(*_worldInfo, _worldTransform);
|
|
|
|
|
|
|
|
if (_armatureParentBone)
|
|
|
|
{
|
2013-12-11 03:07:15 +08:00
|
|
|
_worldTransform = TransformConcat(_worldTransform, _armature->getNodeToParentTransform());
|
2013-10-30 09:41:40 +08:00
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
|
|
|
|
2013-10-30 09:41:40 +08:00
|
|
|
DisplayFactory::updateDisplay(this, delta, _boneTransformDirty || _armature->getArmatureTransformDirty());
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-12-20 05:34:41 +08:00
|
|
|
for(const auto &obj: _children) {
|
2013-11-28 16:02:03 +08:00
|
|
|
Bone *childBone = static_cast<Bone*>(obj);
|
|
|
|
childBone->update(delta);
|
2013-12-20 05:34:41 +08:00
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-09-16 12:21:18 +08:00
|
|
|
_boneTransformDirty = false;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-10-30 09:41:40 +08:00
|
|
|
void Bone::applyParentTransform(Bone *parent)
|
|
|
|
{
|
|
|
|
float x = _worldInfo->x;
|
|
|
|
float y = _worldInfo->y;
|
2014-04-09 14:44:54 +08:00
|
|
|
_worldInfo->x = x * parent->_worldTransform.m[0] + y * parent->_worldTransform.m[4] + parent->_worldInfo->x;
|
|
|
|
_worldInfo->y = x * parent->_worldTransform.m[1] + y * parent->_worldTransform.m[5] + parent->_worldInfo->y;
|
2013-10-30 09:41:40 +08:00
|
|
|
_worldInfo->scaleX = _worldInfo->scaleX * parent->_worldInfo->scaleX;
|
|
|
|
_worldInfo->scaleY = _worldInfo->scaleY * parent->_worldInfo->scaleY;
|
|
|
|
_worldInfo->skewX = _worldInfo->skewX + parent->_worldInfo->skewX;
|
|
|
|
_worldInfo->skewY = _worldInfo->skewY + parent->_worldInfo->skewY;
|
|
|
|
}
|
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2014-04-03 16:19:49 +08:00
|
|
|
void Bone::setBlendFunc(const BlendFunc& blendFunc)
|
2013-12-13 15:02:09 +08:00
|
|
|
{
|
2014-04-03 10:34:20 +08:00
|
|
|
if (_blendFunc.src != blendFunc.src || _blendFunc.dst != blendFunc.dst)
|
2013-12-13 15:02:09 +08:00
|
|
|
{
|
|
|
|
_blendFunc = blendFunc;
|
|
|
|
_blendDirty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
void Bone::updateDisplayedColor(const Color3B &parentColor)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2015-08-20 13:33:48 +08:00
|
|
|
#ifdef CC_STUDIO_ENABLED_VIEW
|
|
|
|
_realColor = Color3B(255, 255, 255);
|
|
|
|
#endif // CC_STUDIO_ENABLED_VIEW
|
2013-12-06 18:07:16 +08:00
|
|
|
Node::updateDisplayedColor(parentColor);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2019-06-05 17:58:33 +08:00
|
|
|
void Bone::updateDisplayedOpacity(uint8_t parentOpacity)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2015-08-20 13:33:48 +08:00
|
|
|
#ifdef CC_STUDIO_ENABLED_VIEW
|
|
|
|
_realOpacity = 255;
|
|
|
|
#endif // CC_STUDIO_ENABLED_VIEW
|
2013-12-06 18:07:16 +08:00
|
|
|
Node::updateDisplayedOpacity(parentOpacity);
|
2013-10-30 09:41:40 +08:00
|
|
|
}
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
void Bone::updateColor()
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-16 12:21:18 +08:00
|
|
|
Node *display = _displayManager->getDisplayRenderNode();
|
2013-12-06 18:07:16 +08:00
|
|
|
if(display != nullptr)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-12-06 18:07:16 +08:00
|
|
|
display->setColor(Color3B(_displayedColor.r * _tweenData->r / 255, _displayedColor.g * _tweenData->g / 255, _displayedColor.b * _tweenData->b / 255));
|
|
|
|
display->setOpacity(_displayedOpacity * _tweenData->a / 255);
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
void Bone::updateZOrder()
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-10-30 09:41:40 +08:00
|
|
|
if (_dataVersion >= VERSION_COMBINED)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-16 12:21:18 +08:00
|
|
|
int zorder = _tweenData->zOrder + _boneData->zOrder;
|
2014-01-19 03:35:27 +08:00
|
|
|
setLocalZOrder(zorder);
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-01-19 03:35:27 +08:00
|
|
|
setLocalZOrder(_tweenData->zOrder);
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
|
|
|
}
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
void Bone::addChildBone(Bone *child)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-11-05 15:32:13 +08:00
|
|
|
CCASSERT( nullptr != child, "Argument must be non-nil");
|
|
|
|
CCASSERT( nullptr == child->_parentBone, "child already added. It can't be added again");
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-11-28 18:23:06 +08:00
|
|
|
if(_children.empty())
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-12-05 10:35:10 +08:00
|
|
|
_children.reserve(4);
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
|
|
|
|
2013-12-05 10:35:10 +08:00
|
|
|
if (_children.getIndex(child) == CC_INVALID_INDEX)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-12-05 10:35:10 +08:00
|
|
|
_children.pushBack(child);
|
2013-06-07 10:52:32 +08:00
|
|
|
child->setParentBone(this);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
void Bone::removeChildBone(Bone *bone, bool recursion)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-12-05 10:35:10 +08:00
|
|
|
if (!_children.empty() && _children.getIndex(bone) != CC_INVALID_INDEX )
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
|
|
|
if(recursion)
|
|
|
|
{
|
2013-11-28 16:02:03 +08:00
|
|
|
auto ccbones = bone->_children;
|
2013-11-06 15:25:44 +08:00
|
|
|
|
2013-11-28 16:02:03 +08:00
|
|
|
for(auto& object : ccbones)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-11-28 16:02:03 +08:00
|
|
|
Bone *ccBone = static_cast<Bone*>(object);
|
2013-11-06 15:25:44 +08:00
|
|
|
bone->removeChildBone(ccBone, recursion);
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-05 15:32:13 +08:00
|
|
|
bone->setParentBone(nullptr);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-11-05 15:32:13 +08:00
|
|
|
bone->getDisplayManager()->setCurrentDecorativeDisplay(nullptr);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-12-12 14:45:30 +08:00
|
|
|
_children.eraseObject(bone);
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
void Bone::removeFromParent(bool recursion)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-11-05 15:32:13 +08:00
|
|
|
if (nullptr != _parentBone)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
_parentBone->removeChildBone(this, recursion);
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
void Bone::setParentBone(Bone *parent)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
_parentBone = parent;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
Bone *Bone::getParentBone()
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
return _parentBone;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
void Bone::setChildArmature(Armature *armature)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-16 12:21:18 +08:00
|
|
|
if (_childArmature != armature)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-11-05 15:32:13 +08:00
|
|
|
if (armature == nullptr && _childArmature)
|
2013-10-30 09:41:40 +08:00
|
|
|
{
|
2013-11-05 15:32:13 +08:00
|
|
|
_childArmature->setParentBone(nullptr);
|
2013-10-30 09:41:40 +08:00
|
|
|
}
|
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
CC_SAFE_RETAIN(armature);
|
2013-09-16 12:21:18 +08:00
|
|
|
CC_SAFE_RELEASE(_childArmature);
|
|
|
|
_childArmature = armature;
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-05 19:53:38 +08:00
|
|
|
Armature *Bone::getChildArmature() const
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-16 12:21:18 +08:00
|
|
|
return _childArmature;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
Tween *Bone::getTween()
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-16 14:56:59 +08:00
|
|
|
return _tween;
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2014-01-19 03:35:27 +08:00
|
|
|
void Bone::setLocalZOrder(int zOrder)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2016-07-31 22:44:24 +08:00
|
|
|
if (getLocalZOrder() != zOrder)
|
2014-01-19 03:35:27 +08:00
|
|
|
Node::setLocalZOrder(zOrder);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4 Bone::getNodeToArmatureTransform() const
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-16 12:21:18 +08:00
|
|
|
return _worldTransform;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4 Bone::getNodeToWorldTransform() const
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-12-11 03:07:15 +08:00
|
|
|
return TransformConcat(_worldTransform, _armature->getNodeToWorldTransform());
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
Node *Bone::getDisplayRenderNode()
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-09-16 12:21:18 +08:00
|
|
|
return _displayManager->getDisplayRenderNode();
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
|
|
|
|
2013-10-30 09:41:40 +08:00
|
|
|
DisplayType Bone::getDisplayRenderNodeType()
|
|
|
|
{
|
|
|
|
return _displayManager->getDisplayRenderNodeType();
|
|
|
|
}
|
|
|
|
|
2013-11-06 15:25:44 +08:00
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
void Bone::addDisplay(DisplayData *displayData, int index)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-09-16 12:21:18 +08:00
|
|
|
_displayManager->addDisplay(displayData, index);
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
void Bone::addDisplay(Node *display, int index)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-09-16 12:21:18 +08:00
|
|
|
_displayManager->addDisplay(display, index);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-10-30 09:41:40 +08:00
|
|
|
void Bone::removeDisplay(int index)
|
|
|
|
{
|
|
|
|
_displayManager->removeDisplay(index);
|
|
|
|
}
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
void Bone::changeDisplayByIndex(int index, bool force)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2014-01-02 11:07:31 +08:00
|
|
|
changeDisplayWithIndex(index, force);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2014-01-02 11:07:31 +08:00
|
|
|
void Bone::changeDisplayByName(const std::string &name, bool force)
|
|
|
|
{
|
|
|
|
changeDisplayWithName(name, force);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Bone::changeDisplayWithIndex(int index, bool force)
|
|
|
|
{
|
|
|
|
_displayManager->changeDisplayWithIndex(index, force);
|
|
|
|
}
|
2013-12-06 13:40:49 +08:00
|
|
|
|
2014-01-02 11:07:31 +08:00
|
|
|
void Bone::changeDisplayWithName(const std::string& name, bool force)
|
2013-12-06 13:40:49 +08:00
|
|
|
{
|
2014-01-02 11:07:31 +08:00
|
|
|
_displayManager->changeDisplayWithName(name, force);
|
2013-12-06 13:40:49 +08:00
|
|
|
}
|
|
|
|
|
2013-12-16 14:34:09 +08:00
|
|
|
ColliderDetector* Bone::getColliderDetector() const
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-16 12:21:18 +08:00
|
|
|
if (DecorativeDisplay *decoDisplay = _displayManager->getCurrentDecorativeDisplay())
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-15 19:08:45 +08:00
|
|
|
if (ColliderDetector *detector = decoDisplay->getColliderDetector())
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-12-16 14:34:09 +08:00
|
|
|
return detector;
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
|
|
|
}
|
2013-11-05 15:32:13 +08:00
|
|
|
return nullptr;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2013-12-06 13:40:49 +08:00
|
|
|
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT
|
2013-11-01 14:36:44 +08:00
|
|
|
void Bone::setColliderFilter(ColliderFilter *filter)
|
|
|
|
{
|
2013-12-18 22:36:10 +08:00
|
|
|
auto array = _displayManager->getDecorativeDisplayList();
|
2013-11-06 15:25:44 +08:00
|
|
|
|
2013-12-18 22:36:10 +08:00
|
|
|
for(auto& object : array)
|
2013-11-01 14:36:44 +08:00
|
|
|
{
|
|
|
|
DecorativeDisplay *decoDisplay = static_cast<DecorativeDisplay *>(object);
|
|
|
|
if (ColliderDetector *detector = decoDisplay->getColliderDetector())
|
|
|
|
{
|
|
|
|
detector->setColliderFilter(filter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ColliderFilter *Bone::getColliderFilter()
|
|
|
|
{
|
|
|
|
if (DecorativeDisplay *decoDisplay = _displayManager->getCurrentDecorativeDisplay())
|
|
|
|
{
|
|
|
|
if (ColliderDetector *detector = decoDisplay->getColliderDetector())
|
|
|
|
{
|
|
|
|
return detector->getColliderFilter();
|
|
|
|
}
|
|
|
|
}
|
2013-11-05 15:32:13 +08:00
|
|
|
return nullptr;
|
2013-11-01 14:36:44 +08:00
|
|
|
}
|
2013-12-06 13:40:49 +08:00
|
|
|
#endif
|
2013-11-01 14:36:44 +08:00
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
}
|