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;
|
_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);
|
}
|
||||||
renderer->addCommand(&_customCommand);
|
|
||||||
for (int i = 0; i < 8; ++i)
|
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;
|
auto node = _children.at(i);
|
||||||
pos.x = _squareVertices[i].x; pos.y = _squareVertices[i].y; pos.z = _positionZ;
|
|
||||||
pos.w = 1;
|
if (node && node->getLocalZOrder() < 0)
|
||||||
_modelViewTransform.transformVector(&pos);
|
node->visit(renderer, _modelViewTransform, flags);
|
||||||
_noMVPVertices[i] = cocos2d::Vec3(pos.x, pos.y, pos.z) / pos.w;
|
else
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->draw(renderer, parentTransform, parentFlags);
|
for (auto it = _children.cbegin() + i; it != _children.cend(); ++it)
|
||||||
_batchBoneCommand.init(_globalZOrder, parentTransform, parentFlags);
|
(*it)->visit(renderer, _modelViewTransform, flags);
|
||||||
_batchBoneCommand.func = CC_CALLBACK_0(SkeletonNode::batchDrawAllSubBones, this, parentTransform);
|
}
|
||||||
|
|
||||||
|
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);
|
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)
|
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