In Spine 4.2, the attachment->computeWorldVertices() method may modify UV values, requiring updates every frame. (#18714)

This commit is contained in:
bofeng-song
2025-05-16 11:21:20 +08:00
committed by GitHub
parent f29677a7a8
commit 4fc4e75271
12 changed files with 408 additions and 302 deletions
@@ -30,10 +30,14 @@
#include "SkeletonCache.h"
#include "base/memory/Memory.h"
#include "spine-creator-support/AttachmentVertices.h"
#include "SkeletonDataMgr.h"
USING_NS_MW; // NOLINT(google-build-using-namespace)
using namespace cc; // NOLINT(google-build-using-namespace)
using namespace spine;
extern "C" AttachmentVertices *generateAttachmentVertices(Attachment *attachment);
namespace cc {
float SkeletonCache::FrameTime = 1.0F / 60.0F;
@@ -311,6 +315,10 @@ void SkeletonCache::renderAnimationFrame(AnimationData *animationData) {
matm[13] = bone->getWorldY();
}
auto *verticesMap = SkeletonDataMgr::getInstance()->getSkeletonDataInfo(_uuid);
if (!verticesMap) return;
auto &attachmentVerticesMap = *verticesMap;
auto &drawOrder = _skeleton->getDrawOrder();
for (size_t i = 0, n = drawOrder.size(); i < n; ++i) {
slot = drawOrder[i];
@@ -319,20 +327,34 @@ void SkeletonCache::renderAnimationFrame(AnimationData *animationData) {
continue;
}
if (!slot->getAttachment()) {
auto *tmpAttachment = slot->getAttachment();
if (!tmpAttachment) {
_clipper->clipEnd(*slot);
continue;
}
const spine::Color &slotColor = slot->getColor();
auto iterAttachment = attachmentVerticesMap.find(tmpAttachment);
if (iterAttachment != attachmentVerticesMap.end()) {
attachmentVertices = iterAttachment->second;
} else {
attachmentVertices = nullptr;
}
TwoColorTriangles trianglesTwoColor;
spine::Color attachmentColor;
if (slot->getAttachment()->getRTTI().isExactly(RegionAttachment::rtti)) {
auto *attachment = dynamic_cast<RegionAttachment *>(slot->getAttachment());
#if CC_USE_SPINE_3_8
attachmentVertices = static_cast<AttachmentVertices *>(attachment->getRendererObject());
#else
attachmentVertices = static_cast<AttachmentVertices *>(attachment->getRegion()->rendererObject);
if (tmpAttachment->getRTTI().isExactly(RegionAttachment::rtti)) {
auto *attachment = dynamic_cast<RegionAttachment *>(tmpAttachment);
#if CC_USE_SPINE_4_2
if (!attachment->getRegion()) {
attachment->getSequence()->apply(slot, attachment);
if (attachment->getRegion()) {
attachmentVertices = generateAttachmentVertices(attachment);
if (attachmentVertices) {
attachmentVerticesMap[attachment] = attachmentVertices;
}
}
}
#endif
// Early exit if attachment is invisible
@@ -362,12 +384,18 @@ void SkeletonCache::renderAnimationFrame(AnimationData *animationData) {
attachmentColor = attachment->getColor();
} else if (slot->getAttachment()->getRTTI().isExactly(MeshAttachment::rtti)) {
auto *attachment = dynamic_cast<MeshAttachment *>(slot->getAttachment());
#if CC_USE_SPINE_3_8
attachmentVertices = static_cast<AttachmentVertices *>(attachment->getRendererObject());
#else
attachmentVertices = static_cast<AttachmentVertices *>(attachment->getRegion()->rendererObject);
} else if (tmpAttachment->getRTTI().isExactly(MeshAttachment::rtti)) {
auto *attachment = dynamic_cast<MeshAttachment *>(tmpAttachment);
#if CC_USE_SPINE_4_2
if (!attachment->getRegion()) {
attachment->getSequence()->apply(slot, attachment);
if (attachment->getRegion()) {
attachmentVertices = generateAttachmentVertices(attachment);
if (attachmentVertices) {
attachmentVerticesMap[attachment] = attachmentVertices;
}
}
}
#endif
// Early exit if attachment is invisible
@@ -391,8 +419,8 @@ void SkeletonCache::renderAnimationFrame(AnimationData *animationData) {
trianglesTwoColor.indices = reinterpret_cast<uint16_t *>(ib.getCurBuffer());
memcpy(trianglesTwoColor.indices, attachmentVertices->_triangles->indices, ibSize);
attachmentColor = attachment->getColor();
} else if (slot->getAttachment()->getRTTI().isExactly(ClippingAttachment::rtti)) {
auto *clip = dynamic_cast<ClippingAttachment *>(slot->getAttachment());
} else if (tmpAttachment->getRTTI().isExactly(ClippingAttachment::rtti)) {
auto *clip = dynamic_cast<ClippingAttachment *>(tmpAttachment);
_clipper->clipStart(*slot, clip);
continue;
} else {
@@ -35,9 +35,48 @@
using namespace spine; //NOLINT
using namespace cc; //NOLINT
static uint16_t quadTriangles[6] = {0, 1, 2, 2, 3, 0};
extern "C" AttachmentVertices *generateAttachmentVertices(Attachment *attachment) {
AttachmentVertices *attachmentVertices = nullptr;
if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) {
auto *regionAttachMent = static_cast<RegionAttachment *>(attachment);
#if CC_USE_SPINE_3_8
auto *region = static_cast<AtlasRegion *>(regionAttachMent->getRendererObject());
attachmentVertices = new AttachmentVertices(static_cast<middleware::Texture2D *>(region->page->getRendererObject()), 4, quadTriangles, 6);
#else
auto *region = static_cast<AtlasRegion *>(regionAttachMent->getRegion());
if (!region) return nullptr;
attachmentVertices = new AttachmentVertices(static_cast<middleware::Texture2D *>(region->page->texture), 4, quadTriangles, 6);
#endif
auto *vertices = attachmentVertices->_triangles->verts;
for (int i = 0, ii = 0; i < 4; ++i, ii += 2) {
vertices[i].texCoord.u = regionAttachMent->getUVs()[ii];
vertices[i].texCoord.v = regionAttachMent->getUVs()[ii + 1];
}
} else if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) {
auto *meshAttachMent = static_cast<MeshAttachment *>(attachment);
#if CC_USE_SPINE_3_8
auto *region = static_cast<AtlasRegion *>(meshAttachMent->getRendererObject());
attachmentVertices = new AttachmentVertices(static_cast<middleware::Texture2D *>(region->page->getRendererObject()),
static_cast<int32_t>(meshAttachMent->getWorldVerticesLength() >> 1), meshAttachMent->getTriangles().buffer(), static_cast<int32_t>(meshAttachMent->getTriangles().size()));
#else
auto *region = static_cast<AtlasRegion *>(meshAttachMent->getRegion());
if (!region) return nullptr;
attachmentVertices = new AttachmentVertices(static_cast<middleware::Texture2D *>(region->page->texture),
static_cast<int32_t>(meshAttachMent->getWorldVerticesLength() >> 1), meshAttachMent->getTriangles().buffer(), static_cast<int32_t>(meshAttachMent->getTriangles().size()));
#endif
auto *vertices = attachmentVertices->_triangles->verts;
for (size_t i = 0, ii = 0, nn = meshAttachMent->getWorldVerticesLength(); ii < nn; ++i, ii += 2) {
vertices[i].texCoord.u = meshAttachMent->getUVs()[ii];
vertices[i].texCoord.v = meshAttachMent->getUVs()[ii + 1];
}
}
return attachmentVertices;
}
namespace cc {
class SkeletonDataInfo {
public:
SkeletonDataInfo() = default;
@@ -49,24 +88,6 @@ public:
}
if (atlas) {
#if CC_USE_SPINE_4_2
auto &regions = atlas->getRegions();
auto size = regions.size();
for (int i = 0; i < size; i++) {
auto *region = regions[i];
if (region->rendererObject) {
auto *map = static_cast<spine::HashMap<Attachment *, AttachmentVertices *> *>(region->rendererObject);
auto entries = map->getEntries();
while (entries.hasNext()) {
auto entry = entries.next();
auto *attachmentVertices = entry.value;
delete attachmentVertices;
}
delete map;
region->rendererObject = nullptr;
}
}
#endif
delete atlas;
atlas = nullptr;
}
@@ -75,14 +96,40 @@ public:
delete attachmentLoader;
attachmentLoader = nullptr;
}
for (const auto& pair : attachmentVerticesMap) {
delete pair.second;
}
}
SkeletonData *data = nullptr;
Atlas *atlas = nullptr;
AttachmentLoader *attachmentLoader = nullptr;
std::vector<int> texturesIndex;
std::unordered_map<Attachment *, AttachmentVertices *> attachmentVerticesMap;
};
void saveAttachmentVertices(SkeletonDataInfo *info) {
auto &attachmentVerticesMap = info->attachmentVerticesMap;
auto &skins = info->data->getSkins();
auto skinSize = skins.size();
for (int i = 0; i < skinSize; ++i) {
auto *skin = skins[i];
auto entries = skin->getAttachments();
while (entries.hasNext()) {
Skin::AttachmentMap::Entry &entry = entries.next();
auto *attachment = entry._attachment;
if (attachmentVerticesMap.count(attachment) < 1) {
auto *attachmentVertices = generateAttachmentVertices(attachment);
if (attachmentVertices) {
attachmentVerticesMap[attachment] = attachmentVertices;
}
}
}
}
}
} // namespace cc
SkeletonDataMgr *SkeletonDataMgr::instance = nullptr;
@@ -111,6 +158,17 @@ void SkeletonDataMgr::setSkeletonData(const std::string &uuid, SkeletonData *dat
info->attachmentLoader = attachmentLoader;
info->texturesIndex = texturesIndex;
_dataMap[uuid] = info;
saveAttachmentVertices(info);
}
std::unordered_map<Attachment *, AttachmentVertices *>
*SkeletonDataMgr::getSkeletonDataInfo(const std::string &uuid) {
auto dataIt = _dataMap.find(uuid);
if (dataIt == _dataMap.end()) {
return nullptr;
}
return &dataIt->second->attachmentVerticesMap;
}
SkeletonData *SkeletonDataMgr::retainByUUID(const std::string &uuid) {
@@ -33,6 +33,7 @@
#include <map>
#include <string>
#include <vector>
#include <unordered_map>
#include "base/RefCounted.h"
#include "spine/SkeletonData.h"
#include "spine/spine.h"
@@ -41,6 +42,7 @@ using namespace spine;
namespace cc {
class SkeletonDataInfo;
class AttachmentVertices;
/**
* Cache skeleton data.
@@ -71,6 +73,9 @@ public:
// equal to 'deleteByUUID'
void releaseByUUID(const std::string &uuid);
std::unordered_map<Attachment *, AttachmentVertices *>
*getSkeletonDataInfo(const std::string &uuid);
using destroyCallback = std::function<void(int)>;
void setDestroyCallback(destroyCallback callback) {
_destroyCallback = std::move(callback);
@@ -81,5 +86,4 @@ private:
destroyCallback _destroyCallback = nullptr;
std::map<std::string, SkeletonDataInfo *> _dataMap;
};
} // namespace cc
@@ -44,6 +44,7 @@
#include "spine-creator-support/AttachmentVertices.h"
#include "spine-creator-support/spine-cocos2dx.h"
USING_NS_MW; // NOLINT(google-build-using-namespace)
using namespace spine; // NOLINT(google-build-using-namespace)
using namespace cc; // NOLINT(google-build-using-namespace)
@@ -64,6 +65,7 @@ enum DebugType {
BONES
};
extern "C" AttachmentVertices *generateAttachmentVertices(Attachment *attachment);
namespace cc {
SkeletonRenderer *SkeletonRenderer::create() {
return new SkeletonRenderer();
@@ -410,6 +412,9 @@ void SkeletonRenderer::render(float /*deltaTime*/) {
void *effect = nullptr;
#endif
auto *verticesMap = SkeletonDataMgr::getInstance()->getSkeletonDataInfo(_uuid);
if (!verticesMap) return;
auto &attachmentVerticesMap = *verticesMap;
auto &drawOrder = _skeleton->getDrawOrder();
for (size_t i = 0, n = drawOrder.size(); i < n; ++i) {
isFull = 0;
@@ -440,7 +445,12 @@ void SkeletonRenderer::render(float /*deltaTime*/) {
cc::middleware::Triangles triangles;
cc::middleware::TwoColorTriangles trianglesTwoColor;
attachmentVertices = nullptr;
auto iterAttachment = attachmentVerticesMap.find(tmpAttachment);
if (iterAttachment != attachmentVerticesMap.end()) {
attachmentVertices = iterAttachment->second;
} else {
attachmentVertices = nullptr;
}
auto iter = _slotTextureSet.find(slot);
if (iter != _slotTextureSet.end()) {
@@ -449,14 +459,17 @@ void SkeletonRenderer::render(float /*deltaTime*/) {
}
if (tmpAttachment->getRTTI().isExactly(RegionAttachment::rtti)) {
auto *attachment = dynamic_cast<RegionAttachment *>(tmpAttachment);
if (!attachmentVertices) {
#if CC_USE_SPINE_3_8
attachmentVertices = reinterpret_cast<AttachmentVertices *>(attachment->getRendererObject());
#else
auto *tmpMap = static_cast<spine::HashMap<Attachment *, AttachmentVertices *> *>(attachment->getRegion()->rendererObject);
attachmentVertices = (*tmpMap)[attachment];
#endif
#if CC_USE_SPINE_4_2
if (!attachment->getRegion()) {
attachment->getSequence()->apply(slot, attachment);
if (attachment->getRegion()) {
attachmentVertices = generateAttachmentVertices(attachment);
if (attachmentVertices) {
attachmentVerticesMap[attachment] = attachmentVertices;
}
}
}
#endif
// Early exit if attachment is invisible
if (attachment->getColor().a == 0) {
@@ -473,6 +486,7 @@ void SkeletonRenderer::render(float /*deltaTime*/) {
#if CC_USE_SPINE_3_8
attachment->computeWorldVertices(slot->getBone(), reinterpret_cast<float *>(triangles.verts), 0, vs1);
#else
loopUVCoords(triangles.verts, attachment->getUVs(), triangles.vertCount);
attachment->computeWorldVertices(*slot, reinterpret_cast<float *>(triangles.verts), 0, vs1);
#endif
@@ -486,12 +500,13 @@ void SkeletonRenderer::render(float /*deltaTime*/) {
vbSize = trianglesTwoColor.vertCount * sizeof(V3F_T2F_C4B_C4B);
isFull |= vb.checkSpace(vbSize, true);
trianglesTwoColor.verts = reinterpret_cast<V3F_T2F_C4B_C4B *>(vb.getCurBuffer());
#if CC_USE_SPINE_3_8
for (int ii = 0; ii < trianglesTwoColor.vertCount; ii++) {
trianglesTwoColor.verts[ii].texCoord = attachmentVertices->_triangles->verts[ii].texCoord;
}
#if CC_USE_SPINE_3_8
attachment->computeWorldVertices(slot->getBone(), reinterpret_cast<float *>(trianglesTwoColor.verts), 0, vs2);
#else
loopUVCoords(trianglesTwoColor.verts, attachment->getUVs(), trianglesTwoColor.vertCount);
attachment->computeWorldVertices(*slot, reinterpret_cast<float *>(trianglesTwoColor.verts), 0, vs2);
#endif
@@ -521,14 +536,17 @@ void SkeletonRenderer::render(float /*deltaTime*/) {
}
} else if (tmpAttachment->getRTTI().isExactly(MeshAttachment::rtti)) {
auto *attachment = dynamic_cast<MeshAttachment *>(tmpAttachment);
if (!attachmentVertices) {
#if CC_USE_SPINE_3_8
attachmentVertices = static_cast<AttachmentVertices *>(attachment->getRendererObject());
#else
auto *tmpMap = static_cast<spine::HashMap<Attachment *, AttachmentVertices *> *>(attachment->getRegion()->rendererObject);
attachmentVertices = (*tmpMap)[attachment];
#endif
#if CC_USE_SPINE_4_2
if (!attachment->getRegion()) {
attachment->getSequence()->apply(slot, attachment);
if (attachment->getRegion()) {
attachmentVertices = generateAttachmentVertices(attachment);
if (attachmentVertices) {
attachmentVerticesMap[attachment] = attachmentVertices;
}
}
}
#endif
// Early exit if attachment is invisible
if (attachment->getColor().a == 0) {
@@ -542,6 +560,9 @@ void SkeletonRenderer::render(float /*deltaTime*/) {
isFull |= vb.checkSpace(vbSize, true);
triangles.verts = reinterpret_cast<V3F_T2F_C4B *>(vb.getCurBuffer());
memcpy(static_cast<void *>(triangles.verts), static_cast<void *>(attachmentVertices->_triangles->verts), vbSize);
#ifdef CC_USE_SPINE_4_2
loopUVCoords(triangles.verts, attachment->getUVs(), triangles.vertCount);
#endif
attachment->computeWorldVertices(*slot, 0, attachment->getWorldVerticesLength(), reinterpret_cast<float *>(triangles.verts), 0, vs1);
triangles.indexCount = attachmentVertices->_triangles->indexCount;
@@ -554,9 +575,13 @@ void SkeletonRenderer::render(float /*deltaTime*/) {
vbSize = trianglesTwoColor.vertCount * sizeof(V3F_T2F_C4B_C4B);
isFull |= vb.checkSpace(vbSize, true);
trianglesTwoColor.verts = reinterpret_cast<V3F_T2F_C4B_C4B *>(vb.getCurBuffer());
#ifdef CC_USE_SPINE_3_8
for (int ii = 0; ii < trianglesTwoColor.vertCount; ii++) {
trianglesTwoColor.verts[ii].texCoord = attachmentVertices->_triangles->verts[ii].texCoord;
}
#else
loopUVCoords(trianglesTwoColor.verts, attachment->getUVs(), trianglesTwoColor.vertCount);
#endif
attachment->computeWorldVertices(*slot, 0, attachment->getWorldVerticesLength(), reinterpret_cast<float *>(trianglesTwoColor.verts), 0, vs2);
trianglesTwoColor.indexCount = attachmentVertices->_triangles->indexCount;
@@ -1135,12 +1160,15 @@ void SkeletonRenderer::setSlotTexture(const std::string &slotName, cc::Texture2D
if (!attachment) return;
auto width = tex2d->getWidth();
auto height = tex2d->getHeight();
auto *verticesMap = SkeletonDataMgr::getInstance()->getSkeletonDataInfo(_uuid);
if (!verticesMap) return;
auto &attachmentVerticesMap = *verticesMap;
auto *attachmentVertices = attachmentVerticesMap.at(attachment);
if (createAttachment) {
attachment = attachment->copy();
}
SlotCacheInfo slotCacheInfo{createAttachment, attachment, nullptr};
AttachmentVertices *attachmentVertices = nullptr;
if (attachment->getRTTI().isExactly(spine::RegionAttachment::rtti)) {
auto region = static_cast<RegionAttachment *>(attachment);
#if CC_USE_SPINE_3_8
@@ -1152,7 +1180,6 @@ void SkeletonRenderer::setSlotTexture(const std::string &slotName, cc::Texture2D
region->setHeight(height);
region->setUVs(0, 0, 1.0f, 1.0f, false);
region->updateOffset();
attachmentVertices = static_cast<AttachmentVertices *>(region->getRendererObject());
if (createAttachment) {
attachmentVertices = attachmentVertices->copy();
slotCacheInfo.attachmentVertices = attachmentVertices;
@@ -1182,8 +1209,6 @@ void SkeletonRenderer::setSlotTexture(const std::string &slotName, cc::Texture2D
uvs[0] = 1;
uvs[1] = 1;
region->updateRegion();
auto *tmpMap = static_cast<spine::HashMap<Attachment *, AttachmentVertices *> *>(textureRegion->rendererObject);
attachmentVertices = (*tmpMap)[slot->getAttachment()];
if (createAttachment) {
attachmentVertices = attachmentVertices->copy();
slotCacheInfo.attachmentVertices = attachmentVertices;
@@ -1211,7 +1236,6 @@ void SkeletonRenderer::setSlotTexture(const std::string &slotName, cc::Texture2D
mesh->setRegionRotate(true);
mesh->setRegionDegrees(0);
mesh->updateUVs();
attachmentVertices = static_cast<AttachmentVertices *>(mesh->getRendererObject());
if (createAttachment) {
attachmentVertices = attachmentVertices->copy();
slotCacheInfo.attachmentVertices = attachmentVertices;
@@ -1232,8 +1256,6 @@ void SkeletonRenderer::setSlotTexture(const std::string &slotName, cc::Texture2D
mesh->setWidth(width);
mesh->setHeight(height);
mesh->updateRegion();
auto *tmpMap = static_cast<spine::HashMap<Attachment *, AttachmentVertices *> *>(mesh->getRegion()->rendererObject);
attachmentVertices = (*tmpMap)[slot->getAttachment()];
if (createAttachment) {
attachmentVertices = attachmentVertices->copy();
slotCacheInfo.attachmentVertices = attachmentVertices;
@@ -50,6 +50,15 @@ class Material;
class AttachmentVertices;
template <typename VertexType, typename UVArrayType>
void loopUVCoords(VertexType *tmp, const UVArrayType &uvs, int count) {
for (int i = 0, ii = 0; i < count; ++i, ii += 2) {
tmp[i].texCoord.u = uvs[ii];
tmp[i].texCoord.v = uvs[ii + 1];
}
}
struct SlotCacheInfo {
bool isOwner{false};
spine::Attachment *attachment{nullptr};
@@ -49,83 +49,13 @@ USING_NS_MW; // NOLINT(google-build-using-namespace)
using namespace cc; // NOLINT(google-build-using-namespace)
using namespace spine; // NOLINT(google-build-using-namespace)
#if CC_USE_SPINE_3_8
static void deleteAttachmentVertices(void *vertices) {
delete static_cast<AttachmentVertices *>(vertices);
}
#endif
static uint16_t quadTriangles[6] = {0, 1, 2, 2, 3, 0};
#if CC_USE_SPINE_4_2
/**
* The relationship between ​​AtlasRegion​​ and ​​AttachmentVertices​​ is ​​one-to-many​​.
*/
static void saveAttachmentVertices(Attachment *attachment, AtlasRegion *region, AttachmentVertices *attachmentVertices) {
spine::HashMap<Attachment *, AttachmentVertices *> *map = nullptr;
if (region->rendererObject && region->rendererObject != region->page->texture) {
map = static_cast<spine::HashMap<Attachment *, AttachmentVertices *> *>(region->rendererObject);
} else {
map = new spine::HashMap<Attachment *, AttachmentVertices *>();
region->rendererObject = map;
}
map->put(attachment, attachmentVertices);
}
#endif
static void setAttachmentVertices(RegionAttachment *attachment) {
#if CC_USE_SPINE_3_8
auto *region = static_cast<AtlasRegion *>(attachment->getRendererObject());
auto *attachmentVertices = new AttachmentVertices(static_cast<middleware::Texture2D *>(region->page->getRendererObject()), 4, quadTriangles, 6);
#else
auto *region = static_cast<AtlasRegion *>(attachment->getRegion());
auto *attachmentVertices = new AttachmentVertices(static_cast<middleware::Texture2D *>(region->page->texture), 4, quadTriangles, 6);
#endif
V3F_T2F_C4B *vertices = attachmentVertices->_triangles->verts;
for (int i = 0, ii = 0; i < 4; ++i, ii += 2) {
vertices[i].texCoord.u = attachment->getUVs()[ii];
vertices[i].texCoord.v = attachment->getUVs()[ii + 1];
}
#if CC_USE_SPINE_3_8
attachment->setRendererObject(attachmentVertices, deleteAttachmentVertices);
#else
saveAttachmentVertices(attachment, region, attachmentVertices);
#endif
}
static void setAttachmentVertices(MeshAttachment *attachment) {
#if CC_USE_SPINE_3_8
auto *region = static_cast<AtlasRegion *>(attachment->getRendererObject());
auto *attachmentVertices = new AttachmentVertices(static_cast<middleware::Texture2D *>(region->page->getRendererObject()),
static_cast<int32_t>(attachment->getWorldVerticesLength() >> 1), attachment->getTriangles().buffer(), static_cast<int32_t>(attachment->getTriangles().size()));
#else
auto *region = static_cast<AtlasRegion *>(attachment->getRegion());
auto *attachmentVertices = new AttachmentVertices(static_cast<middleware::Texture2D *>(region->page->texture),
static_cast<int32_t>(attachment->getWorldVerticesLength() >> 1), attachment->getTriangles().buffer(), static_cast<int32_t>(attachment->getTriangles().size()));
#endif
V3F_T2F_C4B *vertices = attachmentVertices->_triangles->verts;
for (size_t i = 0, ii = 0, nn = attachment->getWorldVerticesLength(); ii < nn; ++i, ii += 2) {
vertices[i].texCoord.u = attachment->getUVs()[ii];
vertices[i].texCoord.v = attachment->getUVs()[ii + 1];
}
#if CC_USE_SPINE_3_8
attachment->setRendererObject(attachmentVertices, deleteAttachmentVertices);
#else
saveAttachmentVertices(attachment, region, attachmentVertices);
#endif
}
Cocos2dAtlasAttachmentLoader::Cocos2dAtlasAttachmentLoader(Atlas *atlas) : AtlasAttachmentLoader(atlas) {
}
Cocos2dAtlasAttachmentLoader::~Cocos2dAtlasAttachmentLoader() = default;
void Cocos2dAtlasAttachmentLoader::configureAttachment(Attachment *attachment) {
if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) {
setAttachmentVertices(dynamic_cast<RegionAttachment *>(attachment));
} else if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) {
setAttachmentVertices(dynamic_cast<MeshAttachment *>(attachment));
}
//
}
uint32_t wrap(TextureWrap wrap) {
@@ -3,19 +3,6 @@
//#include "LogUtil.h"
using namespace spine;
#include <emscripten/emscripten.h>
#include <emscripten/val.h>
using namespace spine;
static void wasmLog(const char* message) {
EM_ASM({
console.log(UTF8ToString($0));
}, message);
}
static const uint16_t quadTriangles[6] = {0, 1, 2, 2, 3, 0};
AttachmentVertices::AttachmentVertices(int verticesCount, uint16_t *triangles, int trianglesCount, const spine::String& textureName) {
_triangles = new Triangles();
_triangles->verts = new V3F_T2F_C4B[verticesCount];
@@ -37,74 +24,10 @@ AttachmentVertices *AttachmentVertices::copy() {
return atv;
}
#ifdef CC_SPINE_VERSION_3_8
static void deleteAttachmentVertices(void *vertices) {
delete static_cast<AttachmentVertices *>(vertices);
}
#else
/**
* The relationship between ​​AtlasRegion​​ and ​​AttachmentVertices​​ is ​​one-to-many​​.
*/
static void saveAttachmentVertices(Attachment *attachment, AtlasRegion *region, AttachmentVertices *attachmentVertices) {
spine::HashMap<Attachment *, AttachmentVertices *> *map = nullptr;
if (region->rendererObject && region->rendererObject != region->page->texture) {
map = static_cast<spine::HashMap<Attachment *, AttachmentVertices *> *>(region->rendererObject);
} else {
map = new spine::HashMap<Attachment *, AttachmentVertices *>();
region->rendererObject = map;
}
map->put(attachment, attachmentVertices);
}
#endif
AtlasAttachmentLoaderExtension::AtlasAttachmentLoaderExtension(Atlas *atlas) : AtlasAttachmentLoader(atlas), _atlasCache(atlas) {
}
AtlasAttachmentLoaderExtension::~AtlasAttachmentLoaderExtension() = default;
void AtlasAttachmentLoaderExtension::configureAttachment(Attachment *attachment) {
if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) {
auto *regionAttachment = static_cast<RegionAttachment *>(attachment);
auto &pages = _atlasCache->getPages();
#ifdef CC_SPINE_VERSION_3_8
auto *region = static_cast<AtlasRegion *>(regionAttachment->getRendererObject());
#else
auto *region = static_cast<AtlasRegion *>(regionAttachment->getRegion());
#endif
auto *attachmentVertices = new AttachmentVertices(4, const_cast<uint16_t*>(quadTriangles), 6, region->page->name);
V3F_T2F_C4B *vertices = attachmentVertices->_triangles->verts;
const auto &uvs = regionAttachment->getUVs();
for (int i = 0, ii = 0; i < 4; ++i, ii += 2) {
vertices[i].texCoord.u = uvs[ii];
vertices[i].texCoord.v = uvs[ii + 1];
}
#ifdef CC_SPINE_VERSION_3_8
regionAttachment->setRendererObject(attachmentVertices, deleteAttachmentVertices);
#else
saveAttachmentVertices(attachment, region, attachmentVertices);
#endif
} else if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) {
auto *meshAttachment = static_cast<MeshAttachment *>(attachment);
auto &pages = _atlasCache->getPages();
#ifdef CC_SPINE_VERSION_3_8
auto *region = static_cast<AtlasRegion *>(meshAttachment->getRendererObject());
#else
auto *region = static_cast<AtlasRegion *>(meshAttachment->getRegion());
#endif
auto *attachmentVertices = new AttachmentVertices(
static_cast<int32_t>(meshAttachment->getWorldVerticesLength() >> 1), meshAttachment->getTriangles().buffer(), static_cast<int32_t>(meshAttachment->getTriangles().size()), region->page->name);
V3F_T2F_C4B *vertices = attachmentVertices->_triangles->verts;
const auto &uvs = meshAttachment->getUVs();
for (size_t i = 0, ii = 0, nn = meshAttachment->getWorldVerticesLength(); ii < nn; ++i, ii += 2) {
vertices[i].texCoord.u = uvs[ii];
vertices[i].texCoord.v = uvs[ii + 1];
}
#ifdef CC_SPINE_VERSION_3_8
meshAttachment->setRendererObject(attachmentVertices, deleteAttachmentVertices);
#else
saveAttachmentVertices(attachment, region, attachmentVertices);
#endif
} else {
wasmLog(attachment->getName().buffer());
}
}
@@ -9,8 +9,81 @@ SlotMesh globalMesh(nullptr, nullptr, 0, 0);
extern "C" {
extern void spineListenerCallBackFromJS();
extern void spineTrackListenerCallback();
AttachmentVertices* generateAttachmentVertices(spine::Attachment* attachment);
}
using namespace spine;
extern HashMap<SkeletonData *, HashMap<Attachment *, AttachmentVertices *>*> spineAttachmentVerticesMap;
extern HashMap<SkeletonData *, HashMap<spine::String, spine::String>*> spineTexturesMap;
template<typename VertexType, typename UVArrayType>
void loopUVCoords(VertexType* tmp, const UVArrayType& uvs, int count) {
for (int i = 0, ii = 0; i < count; ++i, ii += 2) {
tmp[i].texCoord.u = uvs[ii];
tmp[i].texCoord.v = uvs[ii + 1];
}
}
#ifdef CC_SPINE_VERSION_4_2
template<typename MeshT,
typename AttachmentT,
typename VerticesT,
typename TexMapT>
void setSpineTextureID(MeshT& currMesh,
AttachmentT* attachment,
VerticesT* vertices,
TexMapT* texMap) {
if (auto* region = static_cast<AtlasRegion*>(attachment->getRegion())) {
if (region->page && region->page->name != vertices->_textureName) {
currMesh.textureID = (*texMap)[region->page->name];
return;
}
}
currMesh.textureID = vertices->_textureUUID;
}
template<typename VerticesT, typename AttachmentT,
typename SlotT, typename TexMapT, typename VertMapT>
void initAttachmentVertices(VerticesT*& vertices,
AttachmentT* attachment,
SlotT* slot,
TexMapT* texMap,
VertMapT* vertMap)
{
if (!vertices && !attachment->getRegion()) {
attachment->getSequence()->apply(slot, attachment);
if (attachment->getRegion()) {
vertices = generateAttachmentVertices(attachment);
if (texMap->containsKey(vertices->_textureName)) {
vertices->_textureUUID = (*texMap)[vertices->_textureName];
}
vertMap->put(attachment, vertices);
}
}
}
#else
template<typename MeshT,
typename AttachmentT,
typename VerticesT,
typename TexMapT>
void setSpineTextureID(MeshT& currMesh,
AttachmentT*,
VerticesT* vertices,
TexMapT*)
{
//do nothing
currMesh.textureID = vertices->_textureUUID;
}
template<typename VerticesT, typename AttachmentT,
typename SlotT, typename TexMapT, typename VertMapT>
void initAttachmentVertices(VerticesT*&, AttachmentT*, SlotT*, TexMapT*, VertMapT*)
{
//do nothing
}
#endif
static void animationCallback(AnimationState *state, EventType type, TrackEntry *entry, Event *event) {
SpineSkeletonInstance *instance = (static_cast<SpineSkeletonInstance *>(state->getRendererObject()));
@@ -177,6 +250,14 @@ void SpineSkeletonInstance::collectMeshData() {
#else
void* _effect = nullptr;
#endif
#ifdef CC_SPINE_VERSION_4_2
if (!spineTexturesMap.containsKey(_skeletonData)) return;
auto* texturesMap = spineTexturesMap[_skeletonData];
#else
HashMap<spine::String, spine::String> *texturesMap = nullptr;
#endif
if (!spineAttachmentVerticesMap.containsKey(_skeletonData)) return;
auto* attachmentVerticesMap = spineAttachmentVerticesMap[_skeletonData];
const Color& skeletonColor = _skeleton->getColor();
for (uint32_t drawIdx = 0; drawIdx < slotCount; ++drawIdx) {
auto* slot = slotArray[drawIdx];
@@ -195,25 +276,24 @@ void SpineSkeletonInstance::collectMeshData() {
color.a = _userData.color.a;
spine::Attachment* attachmentSlot = slot->getAttachment();
AttachmentVertices *cacheSlotAttachmentVertices = nullptr;
AttachmentVertices *attachmentVertices = nullptr;
if (attachmentVerticesMap->containsKey(attachmentSlot)) {
attachmentVertices = (*attachmentVerticesMap)[attachmentSlot];
}
if (_userData.useSlotTexture && _slotTextureSet.containsKey(slot)) {
auto info = _slotTextureSet[slot];
attachmentSlot = info.attachment;
cacheSlotAttachmentVertices = info.attachmentVertices;
}
if (cacheSlotAttachmentVertices) {
attachmentVertices = cacheSlotAttachmentVertices;
}
const spine::RTTI& attachmentRTTI = attachmentSlot->getRTTI();
if (attachmentRTTI.isExactly(spine::RegionAttachment::rtti)) {
debugShapeType = DEBUG_SHAPE_TYPE::DEBUG_REGION;
auto *attachment = static_cast<spine::RegionAttachment *>(attachmentSlot);
auto *attachmentVertices = cacheSlotAttachmentVertices;
if (!attachmentVertices) {
#ifdef CC_SPINE_VERSION_3_8
attachmentVertices = reinterpret_cast<AttachmentVertices *>(attachment->getRendererObject());
#else
auto *tmpMap = static_cast<spine::HashMap<Attachment *, AttachmentVertices *> *>(attachment->getRegion()->rendererObject);
attachmentVertices = (*tmpMap)[slot->getAttachment()];
#endif
}
initAttachmentVertices(attachmentVertices, attachment, slot, texturesMap, attachmentVerticesMap);
setSpineTextureID(currMesh, attachment, attachmentVertices, texturesMap);
auto *triangles = attachmentVertices->_triangles;
auto vertCount = triangles->vertCount;
auto indexCount = triangles->indexCount;
@@ -222,14 +302,23 @@ void SpineSkeletonInstance::collectMeshData() {
auto vbSize = vertCount * byteStrideColor;
auto *vertices = SpineMeshData::queryVBuffer();
auto *indices = SpineMeshData::queryIBuffer();
if (!_userData.useTint) {
memcpy(static_cast<void *>(vertices), static_cast<void *>(triangles->verts), vbSize);
#ifdef CC_SPINE_VERSION_4_2
const auto& uvs = attachment->getUVs();
V3F_T2F_C4B* tmp = (V3F_T2F_C4B *)(vertices);
loopUVCoords(tmp, uvs, 4);
#endif
} else {
V3F_T2F_C4B_C4B *verts = (V3F_T2F_C4B_C4B *)vertices;
for (int ii = 0; ii < vertCount; ii++) {
verts[ii].texCoord = triangles->verts[ii].texCoord;
}
#ifdef CC_SPINE_VERSION_4_2
const auto& uvs = attachment->getUVs();
loopUVCoords(verts, uvs, vertCount);
#else
for (int ii = 0; ii < vertCount; ii++) {
verts[ii].texCoord = triangles->verts[ii].texCoord;
}
#endif
}
memcpy(indices, triangles->indices, ibSize);
#ifdef CC_SPINE_VERSION_3_8
@@ -243,20 +332,11 @@ void SpineSkeletonInstance::collectMeshData() {
color.g *= attachmentColor.g;
color.b *= attachmentColor.b;
color.a *= attachmentColor.a;
currMesh.textureID = attachmentVertices->_textureUUID;
} else if (attachmentRTTI.isExactly(spine::MeshAttachment::rtti)) {
debugShapeType = DEBUG_SHAPE_TYPE::DEBUG_MESH;
auto *attachment = static_cast<spine::MeshAttachment *>(attachmentSlot);
auto *attachmentVertices = cacheSlotAttachmentVertices;
if (!attachmentVertices) {
#ifdef CC_SPINE_VERSION_3_8
attachmentVertices = static_cast<AttachmentVertices *>(attachment->getRendererObject());
#else
auto *tmpMap = static_cast<spine::HashMap<Attachment *, AttachmentVertices *> *>(attachment->getRegion()->rendererObject);
attachmentVertices = (*tmpMap)[slot->getAttachment()];
#endif
}
initAttachmentVertices(attachmentVertices, attachment, slot, texturesMap, attachmentVerticesMap);
setSpineTextureID(currMesh, attachment, attachmentVertices, texturesMap);
auto *triangles = attachmentVertices->_triangles;
auto vertCount = triangles->vertCount;
auto indexCount = triangles->indexCount;
@@ -265,13 +345,25 @@ void SpineSkeletonInstance::collectMeshData() {
auto vbSize = vertCount * byteStrideColor;
auto *vertices = SpineMeshData::queryVBuffer();
auto *indices = SpineMeshData::queryIBuffer();
bool isRegionChanged = currMesh.textureID != attachmentVertices->_textureUUID;
if (!_userData.useTint) {
memcpy(static_cast<void *>(vertices), static_cast<void *>(triangles->verts), vbSize);
#ifdef CC_SPINE_VERSION_4_2
// Calling 'attachment->computeWorldVertices()' can alter the UV coordinates.
const auto& uvs = attachment->getUVs();
V3F_T2F_C4B* tmp = (V3F_T2F_C4B *)(vertices);
loopUVCoords(tmp, uvs, 4);
#endif
} else {
V3F_T2F_C4B_C4B *verts = (V3F_T2F_C4B_C4B *)vertices;
#ifdef CC_SPINE_VERSION_4_2
const auto& uvs = attachment->getUVs();
loopUVCoords(verts, uvs, vertCount);
#else
for (int ii = 0; ii < vertCount; ii++) {
verts[ii].texCoord = triangles->verts[ii].texCoord;
}
#endif
}
memcpy(indices, triangles->indices, ibSize);
attachment->computeWorldVertices(*slot, 0, attachment->getWorldVerticesLength(), (float *)vertices, 0, strideColor);
@@ -281,7 +373,6 @@ void SpineSkeletonInstance::collectMeshData() {
color.g *= attachmentColor.g;
color.b *= attachmentColor.b;
color.a *= attachmentColor.a;
currMesh.textureID = attachmentVertices->_textureUUID;
} else if (attachmentRTTI.isExactly(spine::ClippingAttachment::rtti)) {
auto *clip = static_cast<spine::ClippingAttachment *>(attachmentSlot);
_clipper->clipStart(*slot, clip);
@@ -530,6 +621,11 @@ void SpineSkeletonInstance::onAnimationStateEvent(TrackEntry *entry, EventType t
void SpineSkeletonInstance::resizeSlotRegion(const spine::String &slotName, uint32_t width, uint32_t height, bool createNew) {
if (!_skeleton) return;
HashMap<Attachment *, AttachmentVertices *> *attachmentVerticesMap = nullptr;
if (spineAttachmentVerticesMap.containsKey(_skeletonData)) {
attachmentVerticesMap = spineAttachmentVerticesMap[_skeletonData];
}
if (!attachmentVerticesMap) return;
auto* slot = _skeleton->findSlot(slotName);
if (!slot) return;
auto *attachment = slot->getAttachment();
@@ -551,11 +647,6 @@ void SpineSkeletonInstance::resizeSlotRegion(const spine::String &slotName, uint
region->setHeight(height);
region->setUVs(0, 0, 1.0f, 1.0f, false);
region->updateOffset();
auto *attachmentVertices = static_cast<AttachmentVertices *>(region->getRendererObject());
if (createNew) {
attachmentVertices = attachmentVertices->copy();
info.attachmentVertices = attachmentVertices;
}
#else
auto *textureRegion = region->getRegion();
if (textureRegion) {
@@ -581,13 +672,17 @@ void SpineSkeletonInstance::resizeSlotRegion(const spine::String &slotName, uint
uvs[0] = 1;
uvs[1] = 1;
region->updateRegion();
auto *tmpMap = static_cast<spine::HashMap<Attachment *, AttachmentVertices *> *>(textureRegion->rendererObject);
auto *attachmentVertices = (*tmpMap)[slot->getAttachment()];
#endif
AttachmentVertices *attachmentVertices = nullptr;
if (attachmentVerticesMap->containsKey(attachment)) {
attachmentVertices = (*attachmentVerticesMap)[attachment];
}
if (!attachmentVertices) return;
if (createNew) {
attachmentVertices = attachmentVertices->copy();
info.attachmentVertices = attachmentVertices;
}
#endif
V3F_T2F_C4B *vertices = attachmentVertices->_triangles->verts;
auto &UVs = region->getUVs();
for (int i = 0, ii = 0; i < 4; ++i, ii += 2) {
@@ -610,11 +705,6 @@ void SpineSkeletonInstance::resizeSlotRegion(const spine::String &slotName, uint
mesh->setRegionRotate(true);
mesh->setRegionDegrees(0);
mesh->updateUVs();
auto *attachmentVertices = static_cast<AttachmentVertices *>(mesh->getRendererObject());
if (createNew) {
attachmentVertices = attachmentVertices->copy();
info.attachmentVertices = attachmentVertices;
}
#else
auto *region = mesh->getRegion();
if (region) {
@@ -631,13 +721,17 @@ void SpineSkeletonInstance::resizeSlotRegion(const spine::String &slotName, uint
mesh->setWidth(width);
mesh->setHeight(height);
mesh->updateRegion();
auto *tmpMap = static_cast<spine::HashMap<Attachment *, AttachmentVertices *> *>(mesh->getRegion()->rendererObject);
auto *attachmentVertices = (*tmpMap)[slot->getAttachment()];
#endif
AttachmentVertices *attachmentVertices = nullptr;
if (attachmentVerticesMap->containsKey(attachment)) {
attachmentVertices = (*attachmentVerticesMap)[attachment];
}
if (!attachmentVertices) return;
if (createNew) {
attachmentVertices = attachmentVertices->copy();
info.attachmentVertices = attachmentVertices;
}
#endif
V3F_T2F_C4B *vertices = attachmentVertices->_triangles->verts;
const auto &UVs = mesh->getUVs();
for (size_t i = 0, ii = 0, nn = mesh->getWorldVerticesLength(); ii < nn; ++i, ii += 2) {
@@ -11,6 +11,50 @@
using namespace spine;
HashMap<SkeletonData *, HashMap<Attachment *, AttachmentVertices *>*> spineAttachmentVerticesMap{};
HashMap<SkeletonData *, HashMap<spine::String, spine::String>*> spineTexturesMap{};
static const uint16_t quadTriangles[6] = {0, 1, 2, 2, 3, 0};
extern "C" AttachmentVertices* generateAttachmentVertices(Attachment* attachment) {
AttachmentVertices* attachmentVertices = nullptr;
if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) {
auto* regionAttachment = static_cast<RegionAttachment*>(attachment);
#ifdef CC_SPINE_VERSION_3_8
auto* region = static_cast<AtlasRegion*>(regionAttachment->getRendererObject());
#else
auto* region = static_cast<AtlasRegion*>(regionAttachment->getRegion());
#endif
if (!region) return nullptr;
attachmentVertices = new AttachmentVertices(4, const_cast<uint16_t*>(quadTriangles), 6, region->page->name);
V3F_T2F_C4B* vertices = attachmentVertices->_triangles->verts;
const auto& uvs = regionAttachment->getUVs();
for (int i = 0, ii = 0; i < 4; ++i, ii += 2) {
vertices[i].texCoord.u = uvs[ii];
vertices[i].texCoord.v = uvs[ii + 1];
}
} else if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) {
auto* meshAttachment = static_cast<MeshAttachment*>(attachment);
#ifdef CC_SPINE_VERSION_3_8
auto* region = static_cast<AtlasRegion*>(meshAttachment->getRendererObject());
#else
auto* region = static_cast<AtlasRegion*>(meshAttachment->getRegion());
#endif
if (!region) return nullptr;
attachmentVertices = new AttachmentVertices(
static_cast<int32_t>(meshAttachment->getWorldVerticesLength() >> 1), meshAttachment->getTriangles().buffer(), static_cast<int32_t>(meshAttachment->getTriangles().size()), region->page->name);
V3F_T2F_C4B* vertices = attachmentVertices->_triangles->verts;
const auto& uvs = meshAttachment->getUVs();
for (size_t i = 0, ii = 0, nn = meshAttachment->getWorldVerticesLength(); ii < nn; ++i, ii += 2) {
vertices[i].texCoord.u = uvs[ii];
vertices[i].texCoord.v = uvs[ii + 1];
}
}
return attachmentVertices;
}
namespace {
const int LOG_LEVEL_ERROR = 3;
const int LOG_LEVEL_WARN = 2;
@@ -34,11 +78,31 @@ void logToConsole(const char* message, int logLevel = LOG_LEVEL_INFO) {
HashMap<String, SkeletonData*> skeletonDataMap{};
void updateAttachmentVerticesTextureId(SkeletonData* skeletonData, const spine::Vector<spine::String>& textureNames, const spine::Vector<spine::String>& textureUUIDs) {
void saveAttachmentVertices(SkeletonData* skeletonData, const spine::Vector<spine::String>& textureNames, const spine::Vector<spine::String>& textureUUIDs) {
spine::HashMap<spine::String, spine::String> textureMap{};
spine::HashMap<spine::String, spine::String>* texturesMap = nullptr;
#ifdef CC_SPINE_VERSION_3_8
// Attachment can not switch pages in 3.8
texturesMap = &textureMap;
#else
if (!spineTexturesMap.containsKey(skeletonData)) {
texturesMap = new HashMap<spine::String, spine::String>();
spineTexturesMap.put(skeletonData, texturesMap);
} else {
texturesMap = spineTexturesMap[skeletonData];
}
#endif
int textureSize = textureNames.size();
for (int i = 0; i < textureSize; ++i) {
textureMap.put(textureNames[i], textureUUIDs[i]);
texturesMap->put(textureNames[i], textureUUIDs[i]);
}
HashMap<Attachment*, AttachmentVertices*>* attachmentVerticesMap = nullptr;
if (!spineAttachmentVerticesMap.containsKey(skeletonData)) {
attachmentVerticesMap = new HashMap<Attachment*, AttachmentVertices*>();
spineAttachmentVerticesMap.put(skeletonData, attachmentVerticesMap);
} else {
attachmentVerticesMap = spineAttachmentVerticesMap[skeletonData];
}
auto& skins = skeletonData->getSkins();
@@ -50,28 +114,19 @@ void updateAttachmentVerticesTextureId(SkeletonData* skeletonData, const spine::
Skin::AttachmentMap::Entry& entry = entries.next();
AttachmentVertices* attachmentVertices = nullptr;
auto* attachment = entry._attachment;
spine::HashMap<Attachment *, AttachmentVertices *> *map = nullptr;
if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) {
auto* meshAttachment = static_cast<MeshAttachment*>(attachment);
#ifdef CC_SPINE_VERSION_3_8
attachmentVertices = static_cast<AttachmentVertices*>(meshAttachment->getRendererObject());
#else
map = static_cast<spine::HashMap<Attachment *, AttachmentVertices *> *>(meshAttachment->getRegion()->rendererObject);
attachmentVertices = (*map)[attachment];
#endif
} else if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) {
auto* regionAttachment = static_cast<RegionAttachment*>(attachment);
#ifdef CC_SPINE_VERSION_3_8
attachmentVertices = static_cast<AttachmentVertices*>(regionAttachment->getRendererObject());
#else
map = static_cast<spine::HashMap<Attachment *, AttachmentVertices *> *>(regionAttachment->getRegion()->rendererObject);
attachmentVertices = (*map)[attachment];
#endif
if (attachmentVerticesMap->containsKey(attachment)) {
attachmentVertices = (*attachmentVerticesMap)[attachment];
} else {
attachmentVertices = generateAttachmentVertices(attachment);
if (attachmentVertices) {
attachmentVerticesMap->put(attachment, attachmentVertices);
}
}
if (attachmentVertices) {
auto& textureName = attachmentVertices->_textureName;
if (textureMap.containsKey(textureName)) {
attachmentVertices->_textureUUID = textureMap[textureName];
if (texturesMap->containsKey(textureName)) {
attachmentVertices->_textureUUID = (*texturesMap)[textureName];
} else {
spine::String logInfo(textureName);
logInfo.append(" attachment's texture doesn`t exist ");
@@ -134,7 +189,7 @@ SkeletonData* SpineWasmUtil::createSpineSkeletonDataWithJson(const String& jsonS
logToConsole(errorMsg.buffer(), LOG_LEVEL_WARN);
}
updateAttachmentVerticesTextureId(skeletonData, textureNames, textureUUIDs);
saveAttachmentVertices(skeletonData, textureNames, textureUUIDs);
return skeletonData;
#else
@@ -161,7 +216,7 @@ SkeletonData* SpineWasmUtil::createSpineSkeletonDataWithBinary(uint32_t byteSize
logToConsole(errorMsg.buffer(), LOG_LEVEL_WARN);
}
updateAttachmentVerticesTextureId(skeletonData, textureNames, textureUUIDs);
saveAttachmentVertices(skeletonData, textureNames, textureUUIDs);
return skeletonData;
#else
@@ -178,38 +233,19 @@ void SpineWasmUtil::registerSpineSkeletonDataWithUUID(SkeletonData* data, const
void SpineWasmUtil::destroySpineSkeletonDataWithUUID(const String& uuid) {
if (skeletonDataMap.containsKey(uuid)) {
auto* data = skeletonDataMap[uuid];
#if CC_USE_SPINE_4_2
auto& skins = data->getSkins();
auto skinSize = skins.size();
// release AttachmentVertices
for (int i = 0; i < skinSize; ++i) {
auto* skin = skins[i];
auto entries = skin->getAttachments();
HashMap<Attachment *, AttachmentVertices *> *attachmentVerticesMap = nullptr;
if (spineAttachmentVerticesMap.containsKey(data)) {
attachmentVerticesMap = spineAttachmentVerticesMap[data];
auto entries = attachmentVerticesMap->getEntries();
while (entries.hasNext()) {
Skin::AttachmentMap::Entry& entry = entries.next();
auto* attachment = entry._attachment;
spine::HashMap<Attachment *, AttachmentVertices *> *map = nullptr;
if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) {
auto* meshAttachment = static_cast<MeshAttachment*>(attachment);
map = static_cast<spine::HashMap<Attachment *, AttachmentVertices *> *>(meshAttachment->getRegion()->rendererObject);
meshAttachment->getRegion()->rendererObject = nullptr;
} else if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) {
auto* regionAttachment = static_cast<RegionAttachment*>(attachment);
map = static_cast<spine::HashMap<Attachment *, AttachmentVertices *> *>(regionAttachment->getRegion()->rendererObject);
regionAttachment->getRegion()->rendererObject = nullptr;
}
if (map) {
auto attachmentVerticesEntries = map->getEntries();
while (attachmentVerticesEntries.hasNext()) {
auto entryTmp = attachmentVerticesEntries.next();
auto *attachmentVertices = entryTmp.value;
delete attachmentVertices;
}
delete map;
}
auto entry = entries.next();
auto* attachmentVertices = entry.value;
delete attachmentVertices;
}
delete attachmentVerticesMap;
spineAttachmentVerticesMap.remove(data);
}
#endif
delete data;
skeletonDataMap.remove(uuid);
}
+1 -1
View File
@@ -3,6 +3,6 @@
"type": "github",
"owner": "cocos",
"name": "cocos-engine-external",
"checkout": "v3.8.7-14"
"checkout": "v3.8.7-15"
}
}
+1
View File
@@ -115,6 +115,7 @@ using namespace spine;
%ignore cc::SkeletonDataMgr::setSkeletonData;
%ignore cc::SkeletonDataMgr::retainByUUID;
%ignore cc::SkeletonDataMgr::releaseByUUID;
%ignore cc::SkeletonDataMgr::getSkeletonDataInfo;
%ignore cc::SkeletonCacheAnimation::render;
%ignore cc::SkeletonCacheAnimation::requestDrawInfo;
%ignore cc::SkeletonCacheAnimation::requestMaterial;
+1
View File
@@ -113,6 +113,7 @@ using namespace spine;
%ignore cc::SkeletonDataMgr::setSkeletonData;
%ignore cc::SkeletonDataMgr::retainByUUID;
%ignore cc::SkeletonDataMgr::releaseByUUID;
%ignore cc::SkeletonDataMgr::getSkeletonDataInfo;
%ignore cc::SkeletonCacheAnimation::render;
%ignore cc::SkeletonCacheAnimation::requestDrawInfo;
%ignore cc::SkeletonCacheAnimation::requestMaterial;