2015-07-23 11:51:49 +08:00
|
|
|
/****************************************************************************
|
2020-10-17 16:32:16 +08:00
|
|
|
Copyright (c) 2015-2017 Chukong Technologies Inc.
|
2015-08-04 14:13:13 +08:00
|
|
|
|
2022-07-09 22:23:34 +08:00
|
|
|
https://axis-project.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.
|
|
|
|
****************************************************************************/
|
2020-10-21 10:12:00 +08:00
|
|
|
#include "ActionTimeline/CCSkeletonNode.h"
|
2015-07-23 11:51:49 +08:00
|
|
|
|
|
|
|
#include "base/CCDirector.h"
|
|
|
|
#include "math/TransformUtils.h"
|
|
|
|
#include "renderer/CCRenderer.h"
|
2019-11-25 01:35:26 +08:00
|
|
|
#include "renderer/ccShaders.h"
|
|
|
|
#include "base/ccUtils.h"
|
2015-07-23 11:51:49 +08:00
|
|
|
#include <stack>
|
|
|
|
|
|
|
|
NS_TIMELINE_BEGIN
|
|
|
|
|
|
|
|
SkeletonNode* SkeletonNode::create()
|
|
|
|
{
|
2021-12-08 00:11:53 +08:00
|
|
|
SkeletonNode* skeletonNode = new SkeletonNode();
|
|
|
|
if (skeletonNode->init())
|
2015-07-23 11:51:49 +08:00
|
|
|
{
|
|
|
|
skeletonNode->autorelease();
|
|
|
|
return skeletonNode;
|
|
|
|
}
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_SAFE_DELETE(skeletonNode);
|
2015-07-23 11:51:49 +08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SkeletonNode::init()
|
|
|
|
{
|
2015-08-04 14:13:13 +08:00
|
|
|
_rackLength = _rackWidth = 20;
|
2015-07-23 11:51:49 +08:00
|
|
|
updateVertices();
|
2019-11-25 01:35:26 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
// init _customCommand
|
2019-11-25 01:35:26 +08:00
|
|
|
auto& pipelineDescriptor = _customCommand.getPipelineDescriptor();
|
2021-12-25 10:04:45 +08:00
|
|
|
auto* program =
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::backend::Program::getBuiltinProgram(axis::backend::ProgramType::POSITION_COLOR); // TODO: noMVP?
|
|
|
|
setProgramState(new axis::backend::ProgramState(program), false);
|
2019-11-25 01:35:26 +08:00
|
|
|
pipelineDescriptor.programState = _programState;
|
|
|
|
|
|
|
|
_mvpLocation = _programState->getUniformLocation("u_MVPMatrix");
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
auto vertexLayout = _programState->getVertexLayout();
|
2019-11-25 01:35:26 +08:00
|
|
|
const auto& attributeInfo = _programState->getProgram()->getActiveAttributes();
|
2021-12-25 10:04:45 +08:00
|
|
|
auto iter = attributeInfo.find("a_position");
|
|
|
|
if (iter != attributeInfo.end())
|
2019-11-25 01:35:26 +08:00
|
|
|
{
|
2022-07-11 17:50:21 +08:00
|
|
|
vertexLayout->setAttribute("a_position", iter->second.location, axis::backend::VertexFormat::FLOAT3, 0,
|
2021-12-25 10:04:45 +08:00
|
|
|
false);
|
2019-11-25 01:35:26 +08:00
|
|
|
}
|
|
|
|
iter = attributeInfo.find("a_color");
|
2021-12-25 10:04:45 +08:00
|
|
|
if (iter != attributeInfo.end())
|
2019-11-25 01:35:26 +08:00
|
|
|
{
|
2022-07-11 17:50:21 +08:00
|
|
|
vertexLayout->setAttribute("a_color", iter->second.location, axis::backend::VertexFormat::FLOAT4,
|
2021-12-25 10:04:45 +08:00
|
|
|
3 * sizeof(float), false);
|
2019-11-25 01:35:26 +08:00
|
|
|
}
|
|
|
|
vertexLayout->setLayout(7 * sizeof(float));
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
_customCommand.createVertexBuffer(sizeof(_vertexData[0]), 8, axis::CustomCommand::BufferUsage::DYNAMIC);
|
|
|
|
_customCommand.createIndexBuffer(axis::CustomCommand::IndexFormat::U_SHORT, 12,
|
|
|
|
axis::CustomCommand::BufferUsage::STATIC);
|
2021-12-25 10:04:45 +08:00
|
|
|
unsigned short indices[12] = {0, 1, 2, 1, 3, 2, 4, 5, 6, 5, 7, 6};
|
2019-11-25 01:35:26 +08:00
|
|
|
_customCommand.updateIndexBuffer(indices, sizeof(indices));
|
|
|
|
|
|
|
|
// init _batchBoneCommand
|
|
|
|
_batchBoneCommand.getPipelineDescriptor().programState = _programState;
|
|
|
|
|
2015-07-23 11:51:49 +08:00
|
|
|
_rootSkeleton = this;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Rect SkeletonNode::getBoundingBox() const
|
2015-07-23 11:51:49 +08:00
|
|
|
{
|
|
|
|
float minx, miny, maxx, maxy = 0;
|
2021-12-25 10:04:45 +08:00
|
|
|
minx = miny = maxx = maxy;
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Rect boundingBox = getVisibleSkinsRect();
|
2021-12-25 10:04:45 +08:00
|
|
|
bool first = true;
|
2022-07-11 17:50:21 +08:00
|
|
|
if (!boundingBox.equals(axis::Rect::ZERO))
|
2015-07-23 11:51:49 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
minx = boundingBox.getMinX();
|
|
|
|
miny = boundingBox.getMinY();
|
|
|
|
maxx = boundingBox.getMaxX();
|
|
|
|
maxy = boundingBox.getMaxY();
|
2015-07-23 11:51:49 +08:00
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
auto allbones = getAllSubBones();
|
|
|
|
for (const auto& bone : allbones)
|
|
|
|
{
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Rect r = RectApplyAffineTransform(bone->getVisibleSkinsRect(),
|
2021-12-25 10:04:45 +08:00
|
|
|
bone->getNodeToParentAffineTransform(bone->getRootSkeletonNode()));
|
2022-07-11 17:50:21 +08:00
|
|
|
if (r.equals(axis::Rect::ZERO))
|
2015-07-23 11:51:49 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (first)
|
|
|
|
{
|
|
|
|
minx = r.getMinX();
|
|
|
|
miny = r.getMinY();
|
|
|
|
maxx = r.getMaxX();
|
|
|
|
maxy = r.getMaxY();
|
|
|
|
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
minx = MIN(r.getMinX(), minx);
|
|
|
|
miny = MIN(r.getMinY(), miny);
|
|
|
|
maxx = MAX(r.getMaxX(), maxx);
|
|
|
|
maxy = MAX(r.getMaxY(), maxy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
boundingBox.setRect(minx, miny, maxx - minx, maxy - miny);
|
2016-09-12 09:45:34 +08:00
|
|
|
return RectApplyAffineTransform(boundingBox, this->getNodeToParentAffineTransform());
|
2015-07-23 11:51:49 +08:00
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
SkeletonNode::SkeletonNode() : BoneNode(), _subBonesDirty(true), _subBonesOrderDirty(true), _batchedVeticesCount(0) {}
|
2015-07-23 11:51:49 +08:00
|
|
|
|
|
|
|
SkeletonNode::~SkeletonNode()
|
|
|
|
{
|
2022-07-21 19:19:08 +08:00
|
|
|
for (auto&& bonepair : _subBonesMap)
|
2015-08-07 17:09:11 +08:00
|
|
|
{
|
|
|
|
setRootSkeleton(bonepair.second, nullptr);
|
|
|
|
}
|
2015-07-23 11:51:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SkeletonNode::updateVertices()
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (_rackLength != _squareVertices[6].x - _anchorPointInPoints.x ||
|
|
|
|
_rackWidth != _squareVertices[3].y - _anchorPointInPoints.y)
|
2015-07-23 11:51:49 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
const float radiusl = _rackLength * .5f;
|
|
|
|
const float radiusw = _rackWidth * .5f;
|
2015-07-23 11:51:49 +08:00
|
|
|
const float radiusl_2 = radiusl * .25f;
|
|
|
|
const float radiusw_2 = radiusw * .25f;
|
2021-12-25 10:04:45 +08:00
|
|
|
_squareVertices[5].y = _squareVertices[2].y = _squareVertices[1].y = _squareVertices[6].y =
|
|
|
|
_squareVertices[0].x = _squareVertices[4].x = _squareVertices[7].x = _squareVertices[3].x = .0f;
|
|
|
|
_squareVertices[5].x = -radiusl;
|
|
|
|
_squareVertices[0].y = -radiusw;
|
|
|
|
_squareVertices[6].x = radiusl;
|
|
|
|
_squareVertices[3].y = radiusw;
|
|
|
|
_squareVertices[1].x = radiusl_2;
|
|
|
|
_squareVertices[7].y = radiusw_2;
|
|
|
|
_squareVertices[2].x = -radiusl_2;
|
|
|
|
_squareVertices[4].y = -radiusw_2;
|
2015-07-23 11:51:49 +08:00
|
|
|
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
_squareVertices[i] += _anchorPointInPoints;
|
|
|
|
}
|
|
|
|
|
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = _contentSizeDirty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkeletonNode::updateColor()
|
|
|
|
{
|
|
|
|
for (unsigned int i = 0; i < 8; i++)
|
|
|
|
{
|
2019-11-25 01:35:26 +08:00
|
|
|
_vertexData[i].color = _rackColor;
|
2015-07-23 11:51:49 +08:00
|
|
|
}
|
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = _contentSizeDirty = true;
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
void SkeletonNode::visit(axis::Renderer* renderer, const axis::Mat4& parentTransform, uint32_t parentFlags)
|
2015-07-23 11:51:49 +08:00
|
|
|
{
|
2015-07-24 19:48:05 +08:00
|
|
|
// quick return if not visible. children won't be drawn.
|
|
|
|
if (!_visible)
|
2015-07-23 11:51:49 +08:00
|
|
|
{
|
2015-07-24 19:48:05 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t flags = processParentFlags(parentTransform, parentFlags);
|
|
|
|
|
|
|
|
// IMPORTANT:
|
|
|
|
// To ease the migration to v3.0, we still support the Mat4 stack,
|
|
|
|
// but it is deprecated and your code should not rely on it
|
2022-07-11 17:50:21 +08:00
|
|
|
_director->pushMatrix(axis::MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
|
|
|
_director->loadMatrix(axis::MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform);
|
2015-07-24 19:48:05 +08:00
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
if (!_children.empty())
|
|
|
|
{
|
|
|
|
sortAllChildren();
|
|
|
|
// draw children zOrder < 0
|
|
|
|
for (; i < _children.size(); i++)
|
2015-07-23 11:51:49 +08:00
|
|
|
{
|
2015-07-24 19:48:05 +08:00
|
|
|
auto node = _children.at(i);
|
|
|
|
|
|
|
|
if (node && node->getLocalZOrder() < 0)
|
|
|
|
node->visit(renderer, _modelViewTransform, flags);
|
|
|
|
else
|
|
|
|
break;
|
2015-07-23 11:51:49 +08:00
|
|
|
}
|
|
|
|
|
2015-07-24 19:48:05 +08:00
|
|
|
for (auto it = _children.cbegin() + i; it != _children.cend(); ++it)
|
|
|
|
(*it)->visit(renderer, _modelViewTransform, flags);
|
|
|
|
}
|
|
|
|
|
2015-08-04 14:13:13 +08:00
|
|
|
checkSubBonesDirty();
|
|
|
|
for (const auto& bone : _subOrderedAllBones)
|
2015-07-24 19:48:05 +08:00
|
|
|
{
|
2015-08-04 14:13:13 +08:00
|
|
|
visitSkins(renderer, bone);
|
2015-07-23 11:51:49 +08:00
|
|
|
}
|
2015-08-04 14:13:13 +08:00
|
|
|
|
2015-08-07 17:09:11 +08:00
|
|
|
if (_isRackShow)
|
|
|
|
{
|
|
|
|
this->draw(renderer, _modelViewTransform, flags);
|
|
|
|
// batch draw all sub bones
|
2019-11-25 01:35:26 +08:00
|
|
|
_batchBoneCommand.init(_globalZOrder, _blendFunc);
|
2015-08-07 17:09:11 +08:00
|
|
|
renderer->addCommand(&_batchBoneCommand);
|
2019-11-25 01:35:26 +08:00
|
|
|
batchDrawAllSubBones();
|
2015-08-07 17:09:11 +08:00
|
|
|
}
|
2022-07-11 17:50:21 +08:00
|
|
|
_director->popMatrix(axis::MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
2015-07-24 19:48:05 +08:00
|
|
|
// FIX ME: Why need to set _orderOfArrival to 0??
|
|
|
|
// Please refer to https://github.com/cocos2d/cocos2d-x/pull/6920
|
|
|
|
// reset for next frame
|
|
|
|
// _orderOfArrival = 0;
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
void SkeletonNode::draw(axis::Renderer* renderer, const axis::Mat4& transform, uint32_t flags)
|
2015-07-24 19:48:05 +08:00
|
|
|
{
|
2019-11-25 01:35:26 +08:00
|
|
|
_customCommand.init(_globalZOrder, _blendFunc);
|
2015-07-24 19:48:05 +08:00
|
|
|
renderer->addCommand(&_customCommand);
|
|
|
|
for (int i = 0; i < 8; ++i)
|
|
|
|
{
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Vec4 pos;
|
2021-12-25 10:04:45 +08:00
|
|
|
pos.x = _squareVertices[i].x;
|
|
|
|
pos.y = _squareVertices[i].y;
|
|
|
|
pos.z = _positionZ;
|
2015-07-24 19:48:05 +08:00
|
|
|
pos.w = 1;
|
|
|
|
_modelViewTransform.transformVector(&pos);
|
2022-07-11 17:50:21 +08:00
|
|
|
_vertexData[i].vertex = axis::Vec3(pos.x, pos.y, pos.z) / pos.w;
|
2015-07-24 19:48:05 +08:00
|
|
|
}
|
2019-11-25 01:35:26 +08:00
|
|
|
_customCommand.updateVertexBuffer(_vertexData, sizeof(_vertexData));
|
|
|
|
|
|
|
|
// custom command and batched draw command share the same program state, so just set one time.
|
|
|
|
_programState->setUniform(_mvpLocation, transform.m, sizeof(transform.m));
|
2015-07-23 11:51:49 +08:00
|
|
|
}
|
|
|
|
|
2019-11-25 01:35:26 +08:00
|
|
|
void SkeletonNode::batchDrawAllSubBones()
|
2015-07-23 11:51:49 +08:00
|
|
|
{
|
2015-08-04 14:13:13 +08:00
|
|
|
checkSubBonesDirty();
|
2015-07-23 11:51:49 +08:00
|
|
|
|
|
|
|
_batchedVeticesCount = 0;
|
2015-08-04 14:13:13 +08:00
|
|
|
for (const auto& bone : _subOrderedAllBones)
|
2015-07-23 11:51:49 +08:00
|
|
|
{
|
2015-08-07 17:09:11 +08:00
|
|
|
batchBoneDrawToSkeleton(bone);
|
2015-07-23 11:51:49 +08:00
|
|
|
}
|
2015-08-07 17:09:11 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
_batchBoneCommand.createVertexBuffer(sizeof(VertexData), _batchedVeticesCount,
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::CustomCommand::BufferUsage::DYNAMIC);
|
2019-11-25 01:35:26 +08:00
|
|
|
_batchBoneCommand.updateVertexBuffer(_batchedBoneVertexData.data(), sizeof(VertexData) * _batchedVeticesCount);
|
2015-07-23 11:51:49 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
#ifdef AX_STUDIO_ENABLED_VIEW
|
2021-12-25 10:04:45 +08:00
|
|
|
// TODO
|
|
|
|
// glLineWidth(1);
|
|
|
|
// glEnable(GL_LINE_SMOOTH);
|
|
|
|
// glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
|
|
|
|
// for (int i = 0; i < _batchedVeticesCount; i += 4 )
|
|
|
|
// {
|
|
|
|
// glDrawArrays(GL_TRIANGLE_FAN, i, 4);
|
|
|
|
// glDrawArrays(GL_LINE_LOOP, i, 4);
|
|
|
|
// }
|
2022-07-15 19:17:01 +08:00
|
|
|
// AX_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, _batchedVeticesCount);
|
2015-07-23 11:51:49 +08:00
|
|
|
#else
|
2019-11-25 01:35:26 +08:00
|
|
|
unsigned short* indices = (unsigned short*)malloc(sizeof(unsigned short) * _batchedVeticesCount);
|
2015-07-23 11:51:49 +08:00
|
|
|
for (int i = 0; i < _batchedVeticesCount; i += 4)
|
|
|
|
{
|
2019-11-25 01:35:26 +08:00
|
|
|
*indices++ = i;
|
|
|
|
*indices++ = i + 1;
|
|
|
|
*indices++ = i + 2;
|
|
|
|
|
|
|
|
*indices++ = i;
|
|
|
|
*indices++ = i + 2;
|
|
|
|
*indices++ = i + 3;
|
2015-07-23 11:51:49 +08:00
|
|
|
}
|
2022-07-11 17:50:21 +08:00
|
|
|
_batchBoneCommand.createIndexBuffer(axis::CustomCommand::IndexFormat::U_SHORT, _batchedVeticesCount,
|
|
|
|
axis::CustomCommand::BufferUsage::DYNAMIC);
|
2019-11-25 01:35:26 +08:00
|
|
|
_batchBoneCommand.updateIndexBuffer(indices, sizeof(unsigned short) * _batchedVeticesCount);
|
|
|
|
free(indices);
|
2022-07-15 19:17:01 +08:00
|
|
|
#endif // AX_STUDIO_ENABLED_VIEW
|
2015-07-23 11:51:49 +08:00
|
|
|
}
|
|
|
|
|
2021-12-27 13:52:08 +08:00
|
|
|
void SkeletonNode::changeSkins(const hlookup::string_map<std::string>& boneSkinNameMap)
|
2015-07-23 11:51:49 +08:00
|
|
|
{
|
2022-07-21 19:19:08 +08:00
|
|
|
for (auto&& boneskin : boneSkinNameMap)
|
2015-07-23 11:51:49 +08:00
|
|
|
{
|
|
|
|
auto bone = getBoneNode(boneskin.first);
|
2015-08-04 14:13:13 +08:00
|
|
|
if (nullptr != bone)
|
2015-07-23 11:51:49 +08:00
|
|
|
bone->displaySkin(boneskin.second, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
void SkeletonNode::changeSkins(std::string_view skinGroupName)
|
2015-07-23 11:51:49 +08:00
|
|
|
{
|
|
|
|
auto suit = _skinGroupMap.find(skinGroupName);
|
|
|
|
if (suit != _skinGroupMap.end())
|
|
|
|
{
|
|
|
|
changeSkins(suit->second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
BoneNode* SkeletonNode::getBoneNode(std::string_view boneName)
|
2015-07-23 11:51:49 +08:00
|
|
|
{
|
|
|
|
auto iter = _subBonesMap.find(boneName);
|
|
|
|
if (iter != _subBonesMap.end())
|
|
|
|
{
|
|
|
|
return iter->second;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
const axis::StringMap<BoneNode*>& SkeletonNode::getAllSubBonesMap() const
|
2015-07-23 11:51:49 +08:00
|
|
|
{
|
|
|
|
return _subBonesMap;
|
|
|
|
}
|
|
|
|
|
2021-12-27 13:52:08 +08:00
|
|
|
void SkeletonNode::addSkinGroup(std::string groupName, hlookup::string_map<std::string> boneSkinNameMap)
|
2015-07-23 11:51:49 +08:00
|
|
|
{
|
2021-12-27 13:52:08 +08:00
|
|
|
_skinGroupMap.emplace(groupName, std::move(boneSkinNameMap));
|
2015-07-23 11:51:49 +08:00
|
|
|
}
|
|
|
|
|
2015-08-04 14:13:13 +08:00
|
|
|
void SkeletonNode::checkSubBonesDirty()
|
|
|
|
{
|
|
|
|
if (_subBonesDirty)
|
|
|
|
{
|
|
|
|
updateOrderedAllbones();
|
|
|
|
_subBonesDirty = false;
|
|
|
|
}
|
|
|
|
if (_subBonesOrderDirty)
|
|
|
|
{
|
|
|
|
sortOrderedAllBones();
|
|
|
|
_subBonesOrderDirty = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkeletonNode::updateOrderedAllbones()
|
2015-07-23 11:51:49 +08:00
|
|
|
{
|
2015-08-04 14:13:13 +08:00
|
|
|
_subOrderedAllBones.clear();
|
|
|
|
// update sub bones, get All Visible SubBones
|
2015-07-28 16:31:06 +08:00
|
|
|
// get all sub bones as visit with visible
|
|
|
|
std::stack<BoneNode*> boneStack;
|
|
|
|
for (const auto& bone : _childBones)
|
2015-07-23 11:51:49 +08:00
|
|
|
{
|
2015-08-04 14:13:13 +08:00
|
|
|
if (bone->isVisible())
|
2015-07-28 16:31:06 +08:00
|
|
|
boneStack.push(bone);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (boneStack.size() > 0)
|
|
|
|
{
|
|
|
|
auto top = boneStack.top();
|
2015-08-04 14:13:13 +08:00
|
|
|
_subOrderedAllBones.pushBack(top);
|
2015-07-28 16:31:06 +08:00
|
|
|
boneStack.pop();
|
|
|
|
auto topChildren = top->getChildBones();
|
|
|
|
for (const auto& childbone : topChildren)
|
|
|
|
{
|
2015-08-04 14:13:13 +08:00
|
|
|
if (childbone->isVisible())
|
2015-07-28 16:31:06 +08:00
|
|
|
boneStack.push(childbone);
|
|
|
|
}
|
2015-07-23 11:51:49 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-04 14:13:13 +08:00
|
|
|
void SkeletonNode::sortOrderedAllBones()
|
2015-07-23 11:51:49 +08:00
|
|
|
{
|
2016-07-31 22:44:24 +08:00
|
|
|
sortNodes(this->_subOrderedAllBones);
|
2015-07-23 11:51:49 +08:00
|
|
|
}
|
|
|
|
|
2016-11-08 11:50:00 +08:00
|
|
|
NS_TIMELINE_END
|