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,29 +145,75 @@ void SkeletonNode::updateColor()
|
|||
_transformUpdated = _transformDirty = _inverseDirty = _contentSizeDirty = true;
|
||||
}
|
||||
|
||||
|
||||
void SkeletonNode::visit(cocos2d::Renderer *renderer, const cocos2d::Mat4& parentTransform, uint32_t parentFlags)
|
||||
{
|
||||
BoneNode::visit(renderer, parentTransform, parentFlags);
|
||||
if (_visible && _isRackShow)
|
||||
// quick return if not visible. children won't be drawn.
|
||||
if (!_visible)
|
||||
{
|
||||
_customCommand.init(_globalZOrder, parentTransform, parentFlags);
|
||||
_customCommand.func = CC_CALLBACK_0(SkeletonNode::onDraw, this, parentTransform, parentFlags);
|
||||
renderer->addCommand(&_customCommand);
|
||||
for (int i = 0; i < 8; ++i)
|
||||
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
|
||||
_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++)
|
||||
{
|
||||
cocos2d::Vec4 pos;
|
||||
pos.x = _squareVertices[i].x; pos.y = _squareVertices[i].y; pos.z = _positionZ;
|
||||
pos.w = 1;
|
||||
_modelViewTransform.transformVector(&pos);
|
||||
_noMVPVertices[i] = cocos2d::Vec3(pos.x, pos.y, pos.z) / pos.w;
|
||||
auto node = _children.at(i);
|
||||
|
||||
if (node && node->getLocalZOrder() < 0)
|
||||
node->visit(renderer, _modelViewTransform, flags);
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
this->draw(renderer, parentTransform, parentFlags);
|
||||
_batchBoneCommand.init(_globalZOrder, parentTransform, parentFlags);
|
||||
_batchBoneCommand.func = CC_CALLBACK_0(SkeletonNode::batchDrawAllSubBones, this, parentTransform);
|
||||
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);
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
cocos2d::Vec4 pos;
|
||||
pos.x = _squareVertices[i].x; pos.y = _squareVertices[i].y; pos.z = _positionZ;
|
||||
pos.w = 1;
|
||||
_modelViewTransform.transformVector(&pos);
|
||||
_noMVPVertices[i] = cocos2d::Vec3(pos.x, pos.y, pos.z) / pos.w;
|
||||
}
|
||||
}
|
||||
|
||||
void SkeletonNode::batchDrawAllSubBones(const cocos2d::Mat4 &transform)
|
||||
|
|
|
@ -82,6 +82,7 @@ protected:
|
|||
virtual void updateColor() 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;
|
||||
|
||||
protected:
|
||||
|
|
Loading…
Reference in New Issue