2013-06-06 12:02:54 +08:00
|
|
|
/****************************************************************************
|
2020-10-17 16:32:16 +08:00
|
|
|
Copyright (c) 2013-2017 Chukong Technologies Inc.
|
2021-07-16 11:04:38 +08:00
|
|
|
Copyright (c) 2021 Bytedance Inc.
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2022-07-09 22:23:34 +08:00
|
|
|
https://axis-project.github.io/
|
2013-06-06 12:02:54 +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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-10-21 10:12:00 +08:00
|
|
|
#include "CCBone.h"
|
|
|
|
#include "CCArmature.h"
|
|
|
|
#include "CCArmatureDataManager.h"
|
|
|
|
#include "CCTransformHelp.h"
|
|
|
|
#include "CCDisplayManager.h"
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
USING_NS_AX;
|
2013-10-15 18:00:03 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
namespace cocostudio
|
|
|
|
{
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Bone* Bone::create()
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Bone* pBone = new Bone();
|
2021-12-08 00:11:53 +08:00
|
|
|
if (pBone->init())
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
|
|
|
pBone->autorelease();
|
|
|
|
return pBone;
|
|
|
|
}
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_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
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
Bone* Bone::create(std::string_view name)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Bone* pBone = new Bone();
|
2021-12-08 00:11:53 +08:00
|
|
|
if (pBone->init(name))
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
|
|
|
pBone->autorelease();
|
|
|
|
return pBone;
|
|
|
|
}
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_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()
|
2021-07-16 11:04:38 +08:00
|
|
|
: _tweenData(nullptr)
|
|
|
|
, _parentBone(nullptr)
|
|
|
|
, _armature(nullptr)
|
|
|
|
, _childArmature(nullptr)
|
|
|
|
, _boneData(nullptr)
|
|
|
|
, _tween(nullptr)
|
|
|
|
, _displayManager(nullptr)
|
|
|
|
, _ignoreMovementBoneData(false)
|
|
|
|
, _worldTransform(Mat4::IDENTITY)
|
|
|
|
, _boneTransformDirty(true)
|
|
|
|
, _blendFunc(BlendFunc::ALPHA_PREMULTIPLIED)
|
|
|
|
, _blendDirty(false)
|
|
|
|
, _worldInfo(nullptr)
|
|
|
|
, _armatureParentBone(nullptr)
|
|
|
|
, _dataVersion(0)
|
|
|
|
{}
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2020-10-17 16:32:16 +08:00
|
|
|
Bone::~Bone(void)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_SAFE_DELETE(_tweenData);
|
|
|
|
AX_SAFE_DELETE(_tween);
|
|
|
|
AX_SAFE_DELETE(_displayManager);
|
|
|
|
AX_SAFE_DELETE(_worldInfo);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_SAFE_RELEASE_NULL(_boneData);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_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
|
|
|
{
|
2020-10-17 16:32:16 +08:00
|
|
|
return Bone::init(nullptr);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
bool Bone::init(std::string_view 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
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_SAFE_DELETE(_tweenData);
|
2021-12-08 00:11:53 +08:00
|
|
|
_tweenData = new FrameData();
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_SAFE_DELETE(_tween);
|
2021-12-08 00:11:53 +08:00
|
|
|
_tween = new Tween();
|
2013-09-16 14:56:59 +08:00
|
|
|
_tween->init(this);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_SAFE_DELETE(_displayManager);
|
2021-12-08 00:11:53 +08:00
|
|
|
_displayManager = new DisplayManager();
|
2013-09-16 12:21:18 +08:00
|
|
|
_displayManager->init(this);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_SAFE_DELETE(_worldInfo);
|
2021-12-08 00:11:53 +08:00
|
|
|
_worldInfo = new BaseData();
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_SAFE_DELETE(_boneData);
|
2021-12-25 10:04:45 +08:00
|
|
|
_boneData = new BoneData();
|
2013-11-05 11:57:20 +08:00
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
bRet = true;
|
2021-12-25 10:04:45 +08:00
|
|
|
} while (0);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void Bone::setBoneData(BoneData* boneData)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXASSERT(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)
|
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_SAFE_RETAIN(boneData);
|
|
|
|
AX_SAFE_RELEASE(_boneData);
|
2013-11-05 11:57:20 +08:00
|
|
|
_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
|
|
|
|
2021-12-25 10:04:45 +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
|
|
|
|
2021-12-25 10:04: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());
|
2021-12-25 10:04:45 +08:00
|
|
|
_dataVersion = _armature->getArmatureData()->dataVersion;
|
2013-10-30 09:41:40 +08:00
|
|
|
_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
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +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
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
_worldInfo->x = _worldInfo->x + _position.x;
|
|
|
|
_worldInfo->y = _worldInfo->y + _position.y;
|
2014-11-06 17:51:19 +08:00
|
|
|
_worldInfo->scaleX = _worldInfo->scaleX * _scaleX;
|
|
|
|
_worldInfo->scaleY = _worldInfo->scaleY * _scaleY;
|
2022-07-15 19:17:01 +08:00
|
|
|
_worldInfo->skewX = _worldInfo->skewX + _skewX + AX_DEGREES_TO_RADIANS(_rotationZ_X);
|
|
|
|
_worldInfo->skewY = _worldInfo->skewY + _skewY - AX_DEGREES_TO_RADIANS(_rotationZ_Y);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2021-12-25 10:04:45 +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
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
for (const auto& obj : _children)
|
|
|
|
{
|
|
|
|
Bone* childBone = static_cast<Bone*>(obj);
|
2013-11-28 16:02:03 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void Bone::applyParentTransform(Bone* parent)
|
2013-10-30 09:41:40 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
float x = _worldInfo->x;
|
|
|
|
float y = _worldInfo->y;
|
|
|
|
_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;
|
2021-12-25 10:04:45 +08:00
|
|
|
_worldInfo->skewX = _worldInfo->skewX + parent->_worldInfo->skewX;
|
|
|
|
_worldInfo->skewY = _worldInfo->skewY + parent->_worldInfo->skewY;
|
2013-10-30 09:41:40 +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
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
_blendFunc = blendFunc;
|
2013-12-13 15:02:09 +08:00
|
|
|
_blendDirty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void Bone::updateDisplayedColor(const Color3B& parentColor)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
#ifdef AX_STUDIO_ENABLED_VIEW
|
2015-08-20 13:33:48 +08:00
|
|
|
_realColor = Color3B(255, 255, 255);
|
2022-07-15 19:17:01 +08:00
|
|
|
#endif // AX_STUDIO_ENABLED_VIEW
|
2013-12-06 18:07:16 +08:00
|
|
|
Node::updateDisplayedColor(parentColor);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2019-11-25 01:35:26 +08:00
|
|
|
void Bone::updateDisplayedOpacity(uint8_t parentOpacity)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
#ifdef AX_STUDIO_ENABLED_VIEW
|
2015-08-20 13:33:48 +08:00
|
|
|
_realOpacity = 255;
|
2022-07-15 19:17:01 +08:00
|
|
|
#endif // AX_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
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
Node* display = _displayManager->getDisplayRenderNode();
|
|
|
|
if (display != nullptr)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
display->setColor(Color3B(_displayedColor.r * _tweenData->r / 255, _displayedColor.g * _tweenData->g / 255,
|
|
|
|
_displayedColor.b * _tweenData->b / 255));
|
2013-12-06 18:07:16 +08:00
|
|
|
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
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void Bone::addChildBone(Bone* child)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXASSERT(nullptr != child, "Argument must be non-nil");
|
|
|
|
AXASSERT(nullptr == child->_parentBone, "child already added. It can't be added again");
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2021-12-25 10:04:45 +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
|
|
|
}
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
if (_children.getIndex(child) == AX_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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void Bone::removeChildBone(Bone* bone, bool recursion)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
if (!_children.empty() && _children.getIndex(bone) != AX_INVALID_INDEX)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (recursion)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-11-28 16:02:03 +08:00
|
|
|
auto ccbones = bone->_children;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-21 19:19:08 +08:00
|
|
|
for (auto&& object : ccbones)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +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
|
|
|
}
|
|
|
|
|
2021-12-25 10:04: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
|
|
|
}
|
|
|
|
|
2021-12-25 10:04: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
|
|
|
}
|
|
|
|
|
2021-12-25 10:04: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
|
|
|
}
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_SAFE_RETAIN(armature);
|
|
|
|
AX_SAFE_RELEASE(_childArmature);
|
2013-09-16 12:21:18 +08:00
|
|
|
_childArmature = armature;
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +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
|
|
|
}
|
|
|
|
|
2021-12-25 10:04: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
|
|
|
}
|
|
|
|
|
2021-12-25 10:04: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();
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04: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
|
|
|
}
|
|
|
|
|
2021-12-25 10:04: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
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
void Bone::changeDisplayByName(std::string_view name, bool force)
|
2014-01-02 11:07:31 +08:00
|
|
|
{
|
|
|
|
changeDisplayWithName(name, force);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Bone::changeDisplayWithIndex(int index, bool force)
|
|
|
|
{
|
|
|
|
_displayManager->changeDisplayWithIndex(index, force);
|
|
|
|
}
|
2013-12-06 13:40:49 +08:00
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
void Bone::changeDisplayWithName(std::string_view 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
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (DecorativeDisplay* decoDisplay = _displayManager->getCurrentDecorativeDisplay())
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2021-12-25 10:04: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-12-06 13:40:49 +08:00
|
|
|
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT
|
2021-12-25 10:04:45 +08:00
|
|
|
void Bone::setColliderFilter(ColliderFilter* filter)
|
2013-11-01 14:36:44 +08:00
|
|
|
{
|
2013-12-18 22:36:10 +08:00
|
|
|
auto array = _displayManager->getDecorativeDisplayList();
|
2013-11-06 15:25:44 +08:00
|
|
|
|
2022-07-21 19:19:08 +08:00
|
|
|
for (auto&& object : array)
|
2013-11-01 14:36:44 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
DecorativeDisplay* decoDisplay = static_cast<DecorativeDisplay*>(object);
|
|
|
|
if (ColliderDetector* detector = decoDisplay->getColliderDetector())
|
2013-11-01 14:36:44 +08:00
|
|
|
{
|
|
|
|
detector->setColliderFilter(filter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
ColliderFilter* Bone::getColliderFilter()
|
2013-11-01 14:36:44 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (DecorativeDisplay* decoDisplay = _displayManager->getCurrentDecorativeDisplay())
|
2013-11-01 14:36:44 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (ColliderDetector* detector = decoDisplay->getColliderDetector())
|
2013-11-01 14:36:44 +08:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
} // namespace cocostudio
|