mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-22 02:06:03 +08:00
[cocos2d-x] Fixed broken mesh indices when RegionAttachment alpha == 0. Closes #1708.
This commit is contained in:
parent
06bd6a90bd
commit
254baf4d75
@ -48,6 +48,7 @@ namespace spine {
|
|||||||
bool cullRectangle(Renderer* renderer, const Mat4& transform, const cocos2d::Rect& rect);
|
bool cullRectangle(Renderer* renderer, const Mat4& transform, const cocos2d::Rect& rect);
|
||||||
Color4B ColorToColor4B(const Color& color);
|
Color4B ColorToColor4B(const Color& color);
|
||||||
bool slotIsOutRange(Slot& slot, int startSlotIndex, int endSlotIndex);
|
bool slotIsOutRange(Slot& slot, int startSlotIndex, int endSlotIndex);
|
||||||
|
bool nothingToDraw(Slot& slot, int startSlotIndex, int endSlotIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
// C Variable length array
|
// C Variable length array
|
||||||
@ -301,18 +302,7 @@ namespace spine {
|
|||||||
for (int i = 0, n = _skeleton->getSlots().size(); i < n; ++i) {
|
for (int i = 0, n = _skeleton->getSlots().size(); i < n; ++i) {
|
||||||
Slot* slot = _skeleton->getDrawOrder()[i];;
|
Slot* slot = _skeleton->getDrawOrder()[i];;
|
||||||
|
|
||||||
if (slotIsOutRange(*slot, _startSlotIndex, _endSlotIndex)) {
|
if (nothingToDraw(*slot, _startSlotIndex, _endSlotIndex)) {
|
||||||
_clipper->clipEnd(*slot);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!slot->getAttachment()) {
|
|
||||||
_clipper->clipEnd(*slot);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Early exit if slot is invisible
|
|
||||||
if (slot->getColor().a == 0 || !slot->getBone().isActive()) {
|
|
||||||
_clipper->clipEnd(*slot);
|
_clipper->clipEnd(*slot);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -324,12 +314,6 @@ namespace spine {
|
|||||||
RegionAttachment* attachment = static_cast<RegionAttachment*>(slot->getAttachment());
|
RegionAttachment* attachment = static_cast<RegionAttachment*>(slot->getAttachment());
|
||||||
attachmentVertices = static_cast<AttachmentVertices*>(attachment->getRendererObject());
|
attachmentVertices = static_cast<AttachmentVertices*>(attachment->getRendererObject());
|
||||||
|
|
||||||
// Early exit if attachment is invisible
|
|
||||||
if (attachment->getColor().a == 0) {
|
|
||||||
_clipper->clipEnd(*slot);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
float* dstTriangleVertices = nullptr;
|
float* dstTriangleVertices = nullptr;
|
||||||
int dstStride = 0; // in floats
|
int dstStride = 0; // in floats
|
||||||
if (hasSingleTint) {
|
if (hasSingleTint) {
|
||||||
@ -556,7 +540,7 @@ namespace spine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
#if COCOS2D_VERSION < 0x00040000
|
#if COCOS2D_VERSION < 0x00040000
|
||||||
TwoColorTrianglesCommand* batchedTriangles = lastTwoColorTrianglesCommand = twoColorBatch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture->getName(), _glProgramState, blendFunc, trianglesTwoColor, transform, transformFlags);
|
TwoColorTrianglesCommand* batchedTriangles = lastTwoColorTrianglesCommand = twoColorBatch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture->getName(), _glProgramState, blendFunc, trianglesTwoColor, transform, transformFlags);
|
||||||
#else
|
#else
|
||||||
@ -641,7 +625,7 @@ namespace spine {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
DrawNode* drawNode = DrawNode::create();
|
DrawNode* drawNode = DrawNode::create();
|
||||||
drawNode->setGlobalZOrder(getGlobalZOrder());
|
drawNode->setGlobalZOrder(getGlobalZOrder());
|
||||||
|
|
||||||
// Draw bounding rectangle
|
// Draw bounding rectangle
|
||||||
if (_debugBoundingRect) {
|
if (_debugBoundingRect) {
|
||||||
@ -935,21 +919,28 @@ namespace spine {
|
|||||||
return startSlotIndex > index || endSlotIndex < index;
|
return startSlotIndex > index || endSlotIndex < index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool nothingToDraw(Slot& slot, int startSlotIndex, int endSlotIndex) {
|
||||||
|
Attachment *attachment = slot.getAttachment();
|
||||||
|
if (!attachment ||
|
||||||
|
slotIsOutRange(slot, startSlotIndex, endSlotIndex) ||
|
||||||
|
!slot.getBone().isActive() ||
|
||||||
|
slot.getColor().a == 0)
|
||||||
|
return true;
|
||||||
|
if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) {
|
||||||
|
if (static_cast<RegionAttachment*>(attachment)->getColor().a == 0)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int computeTotalCoordCount(Skeleton& skeleton, int startSlotIndex, int endSlotIndex) {
|
int computeTotalCoordCount(Skeleton& skeleton, int startSlotIndex, int endSlotIndex) {
|
||||||
int coordCount = 0;
|
int coordCount = 0;
|
||||||
for (size_t i = 0; i < skeleton.getSlots().size(); ++i) {
|
for (size_t i = 0; i < skeleton.getSlots().size(); ++i) {
|
||||||
Slot& slot = *skeleton.getSlots()[i];
|
Slot& slot = *skeleton.getSlots()[i];
|
||||||
|
if (nothingToDraw(slot, startSlotIndex, endSlotIndex)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
Attachment* const attachment = slot.getAttachment();
|
Attachment* const attachment = slot.getAttachment();
|
||||||
if (!attachment) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (slotIsOutRange(slot, startSlotIndex, endSlotIndex)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// Early exit if slot is invisible
|
|
||||||
if (slot.getColor().a == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) {
|
if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) {
|
||||||
coordCount += 8;
|
coordCount += 8;
|
||||||
}
|
}
|
||||||
@ -969,16 +960,10 @@ namespace spine {
|
|||||||
#endif
|
#endif
|
||||||
for (size_t i = 0; i < skeleton.getSlots().size(); ++i) {
|
for (size_t i = 0; i < skeleton.getSlots().size(); ++i) {
|
||||||
/*const*/ Slot& slot = *skeleton.getDrawOrder()[i]; // match the draw order of SkeletonRenderer::Draw
|
/*const*/ Slot& slot = *skeleton.getDrawOrder()[i]; // match the draw order of SkeletonRenderer::Draw
|
||||||
|
if (nothingToDraw(slot, startSlotIndex, endSlotIndex)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
Attachment* const attachment = slot.getAttachment();
|
Attachment* const attachment = slot.getAttachment();
|
||||||
if (!attachment) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (slotIsOutRange(slot, startSlotIndex, endSlotIndex)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (slot.getColor().a == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) {
|
if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) {
|
||||||
RegionAttachment* const regionAttachment = static_cast<RegionAttachment*>(attachment);
|
RegionAttachment* const regionAttachment = static_cast<RegionAttachment*>(attachment);
|
||||||
assert(dstPtr + 8 <= dstEnd);
|
assert(dstPtr + 8 <= dstEnd);
|
||||||
@ -1010,7 +995,7 @@ namespace spine {
|
|||||||
|
|
||||||
BlendFunc makeBlendFunc(BlendMode blendMode, bool premultipliedAlpha) {
|
BlendFunc makeBlendFunc(BlendMode blendMode, bool premultipliedAlpha) {
|
||||||
BlendFunc blendFunc;
|
BlendFunc blendFunc;
|
||||||
|
|
||||||
#if COCOS2D_VERSION < 0x00040000
|
#if COCOS2D_VERSION < 0x00040000
|
||||||
switch (blendMode) {
|
switch (blendMode) {
|
||||||
case BlendMode_Additive:
|
case BlendMode_Additive:
|
||||||
@ -1056,15 +1041,15 @@ namespace spine {
|
|||||||
bool cullRectangle(Renderer* renderer, const Mat4& transform, const cocos2d::Rect& rect) {
|
bool cullRectangle(Renderer* renderer, const Mat4& transform, const cocos2d::Rect& rect) {
|
||||||
if (Camera::getVisitingCamera() == nullptr)
|
if (Camera::getVisitingCamera() == nullptr)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
auto director = Director::getInstance();
|
auto director = Director::getInstance();
|
||||||
auto scene = director->getRunningScene();
|
auto scene = director->getRunningScene();
|
||||||
|
|
||||||
if (!scene || (scene && Camera::getDefaultCamera() != Camera::getVisitingCamera()))
|
if (!scene || (scene && Camera::getDefaultCamera() != Camera::getVisitingCamera()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Rect visibleRect(director->getVisibleOrigin(), director->getVisibleSize());
|
Rect visibleRect(director->getVisibleOrigin(), director->getVisibleSize());
|
||||||
|
|
||||||
// transform center point to screen space
|
// transform center point to screen space
|
||||||
float hSizeX = rect.size.width/2;
|
float hSizeX = rect.size.width/2;
|
||||||
float hSizeY = rect.size.height/2;
|
float hSizeY = rect.size.height/2;
|
||||||
@ -1075,7 +1060,7 @@ namespace spine {
|
|||||||
// convert content size to world coordinates
|
// convert content size to world coordinates
|
||||||
float wshw = std::max(fabsf(hSizeX * transform.m[0] + hSizeY * transform.m[4]), fabsf(hSizeX * transform.m[0] - hSizeY * transform.m[4]));
|
float wshw = std::max(fabsf(hSizeX * transform.m[0] + hSizeY * transform.m[4]), fabsf(hSizeX * transform.m[0] - hSizeY * transform.m[4]));
|
||||||
float wshh = std::max(fabsf(hSizeX * transform.m[1] + hSizeY * transform.m[5]), fabsf(hSizeX * transform.m[1] - hSizeY * transform.m[5]));
|
float wshh = std::max(fabsf(hSizeX * transform.m[1] + hSizeY * transform.m[5]), fabsf(hSizeX * transform.m[1] - hSizeY * transform.m[5]));
|
||||||
|
|
||||||
// enlarge visible rect half size in screen coord
|
// enlarge visible rect half size in screen coord
|
||||||
visibleRect.origin.x -= wshw;
|
visibleRect.origin.x -= wshw;
|
||||||
visibleRect.origin.y -= wshh;
|
visibleRect.origin.y -= wshh;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user