mirror of https://github.com/axmolengine/axmol.git
fix bug:use wrong _modelviewTransform in director to draw bone
This commit is contained in:
parent
4327e4a532
commit
a5d41aac0d
|
@ -145,14 +145,66 @@ void SkeletonNode::updateColor()
|
||||||
_transformUpdated = _transformDirty = _inverseDirty = _contentSizeDirty = true;
|
_transformUpdated = _transformDirty = _inverseDirty = _contentSizeDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SkeletonNode::visit(cocos2d::Renderer *renderer, const cocos2d::Mat4& parentTransform, uint32_t parentFlags)
|
void SkeletonNode::visit(cocos2d::Renderer *renderer, const cocos2d::Mat4& parentTransform, uint32_t parentFlags)
|
||||||
{
|
{
|
||||||
BoneNode::visit(renderer, parentTransform, parentFlags);
|
// quick return if not visible. children won't be drawn.
|
||||||
if (_visible && _isRackShow)
|
if (!_visible)
|
||||||
{
|
{
|
||||||
_customCommand.init(_globalZOrder, parentTransform, parentFlags);
|
return;
|
||||||
_customCommand.func = CC_CALLBACK_0(SkeletonNode::onDraw, this, parentTransform, parentFlags);
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
_director->pushMatrix(cocos2d::MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
||||||
|
_director->loadMatrix(cocos2d::MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform);
|
||||||
|
|
||||||
|
bool visibleByCamera = isVisitableByVisitingCamera();
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
if (!_children.empty())
|
||||||
|
{
|
||||||
|
sortAllChildren();
|
||||||
|
// draw children zOrder < 0
|
||||||
|
for (; i < _children.size(); i++)
|
||||||
|
{
|
||||||
|
auto node = _children.at(i);
|
||||||
|
|
||||||
|
if (node && node->getLocalZOrder() < 0)
|
||||||
|
node->visit(renderer, _modelViewTransform, flags);
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto it = _children.cbegin() + i; it != _children.cend(); ++it)
|
||||||
|
(*it)->visit(renderer, _modelViewTransform, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (visibleByCamera)
|
||||||
|
{
|
||||||
|
this->draw(renderer, _modelViewTransform, flags);
|
||||||
|
// batch draw all sub bones
|
||||||
|
_batchBoneCommand.init(_globalZOrder, _modelViewTransform, parentFlags);
|
||||||
|
_batchBoneCommand.func = CC_CALLBACK_0(SkeletonNode::batchDrawAllSubBones, this, _modelViewTransform);
|
||||||
|
renderer->addCommand(&_batchBoneCommand);
|
||||||
|
}
|
||||||
|
_director->popMatrix(cocos2d::MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SkeletonNode::draw(cocos2d::Renderer *renderer, const cocos2d::Mat4 &transform, uint32_t flags)
|
||||||
|
{
|
||||||
|
if (!_isRackShow)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_customCommand.init(_globalZOrder, transform, flags);
|
||||||
|
_customCommand.func = CC_CALLBACK_0(SkeletonNode::onDraw, this, transform, flags);
|
||||||
renderer->addCommand(&_customCommand);
|
renderer->addCommand(&_customCommand);
|
||||||
for (int i = 0; i < 8; ++i)
|
for (int i = 0; i < 8; ++i)
|
||||||
{
|
{
|
||||||
|
@ -162,12 +214,6 @@ void SkeletonNode::visit(cocos2d::Renderer *renderer, const cocos2d::Mat4& paren
|
||||||
_modelViewTransform.transformVector(&pos);
|
_modelViewTransform.transformVector(&pos);
|
||||||
_noMVPVertices[i] = cocos2d::Vec3(pos.x, pos.y, pos.z) / pos.w;
|
_noMVPVertices[i] = cocos2d::Vec3(pos.x, pos.y, pos.z) / pos.w;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->draw(renderer, parentTransform, parentFlags);
|
|
||||||
_batchBoneCommand.init(_globalZOrder, parentTransform, parentFlags);
|
|
||||||
_batchBoneCommand.func = CC_CALLBACK_0(SkeletonNode::batchDrawAllSubBones, this, parentTransform);
|
|
||||||
renderer->addCommand(&_batchBoneCommand);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonNode::batchDrawAllSubBones(const cocos2d::Mat4 &transform)
|
void SkeletonNode::batchDrawAllSubBones(const cocos2d::Mat4 &transform)
|
||||||
|
|
|
@ -82,6 +82,7 @@ protected:
|
||||||
virtual void updateColor() override;
|
virtual void updateColor() override;
|
||||||
|
|
||||||
virtual void visit(cocos2d::Renderer *renderer, const cocos2d::Mat4& parentTransform, uint32_t parentFlags) override;
|
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;
|
||||||
virtual void onDraw(const cocos2d::Mat4 &transform, uint32_t flags) override;
|
virtual void onDraw(const cocos2d::Mat4 &transform, uint32_t flags) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
Loading…
Reference in New Issue