From 8d2940154df3710de1a409ec401d718ad8057cb8 Mon Sep 17 00:00:00 2001 From: bofeng Date: Wed, 4 Dec 2024 17:01:35 +0800 Subject: [PATCH] Fix the issue on the web where calling spine.setAttachment causes visual glitches due to using incorrect textures. --- cocos/spine/assembler/simple.ts | 8 ++-- cocos/spine/lib/spine-core.d.ts | 6 +-- cocos/spine/skeleton-cache.ts | 5 ++- cocos/spine/skeleton-data.ts | 29 ++++++++----- cocos/spine/skeleton.ts | 26 ++---------- .../AtlasAttachmentLoaderExtension.cpp | 6 +-- .../AtlasAttachmentLoaderExtension.h | 4 +- .../editor-support/spine-wasm/spine-model.cpp | 11 ++--- .../editor-support/spine-wasm/spine-model.h | 4 +- .../spine-wasm/spine-skeleton-instance.cpp | 2 +- .../spine-wasm/spine-skeleton-instance.h | 4 +- .../spine-wasm/spine-type-export.cpp | 27 +++++++++++- .../editor-support/spine-wasm/spine-wasm.cpp | 42 ++++++++++++++++++- .../editor-support/spine-wasm/spine-wasm.h | 4 +- 14 files changed, 116 insertions(+), 62 deletions(-) diff --git a/cocos/spine/assembler/simple.ts b/cocos/spine/assembler/simple.ts index 98d1e128d21..c3ef40763dc 100644 --- a/cocos/spine/assembler/simple.ts +++ b/cocos/spine/assembler/simple.ts @@ -169,14 +169,14 @@ function realTimeTraverse (comp: Skeleton): void { for (let i = 0; i < ic; i++) ibuf[i] += chunkOffset; const data = model.getData(); + const textures = model.getTextures(); const count = data.size(); let indexOffset = 0; let indexCount = 0; - for (let i = 0; i < count; i += 6) { + for (let i = 0; i < count; i += 5) { indexCount = data.get(i + 3); const material = _getSlotMaterial(data.get(i + 4) as number, comp); - const textureID: number = data.get(i + 5); - comp.requestDrawData(material, textureID, indexOffset, indexCount); + comp.requestDrawData(material, textures.get(i / 5), indexOffset, indexCount); indexOffset += indexCount; } @@ -321,7 +321,7 @@ function cacheTraverse (comp: Skeleton): void { const material = _getSlotMaterial(mesh.blendMode as number, comp); const textureID = mesh.textureID; indexCount = mesh.iCount; - comp.requestDrawData(material, textureID as number, indexOffset, indexCount); + comp.requestDrawData(material, textureID, indexOffset, indexCount); indexOffset += indexCount; } diff --git a/cocos/spine/lib/spine-core.d.ts b/cocos/spine/lib/spine-core.d.ts index 6bcf725f17e..cb00e9a3516 100644 --- a/cocos/spine/lib/spine-core.d.ts +++ b/cocos/spine/lib/spine-core.d.ts @@ -1208,7 +1208,7 @@ declare namespace spine { setDebugMode(debug: boolean); getDebugShapes(); resizeSlotRegion(slotName: string, width: number, height: number, createNew: boolean); - setSlotTexture(slotName: string, index: number); + setSlotTexture(slotName: string, uuid: string); } class wasmUtil { @@ -1216,8 +1216,8 @@ declare namespace spine { static spineWasmDestroy(): void; static queryStoreMemory(size: number): number; static querySpineSkeletonDataByUUID(uuid: string): SkeletonData; - static createSpineSkeletonDataWithJson(jsonStr: string, atlasText: string): SkeletonData; - static createSpineSkeletonDataWithBinary(byteSize: number, atlasText: string): SkeletonData; + static createSpineSkeletonDataWithJson(jsonStr: string, atlasText: string, textureNames: string[], textureUUIDs: string[]): SkeletonData; + static createSpineSkeletonDataWithBinary(byteSize: number, atlasText: string, textureNames: string[], textureUUIDs: string[]): SkeletonData; static registerSpineSkeletonDataWithUUID(data: SkeletonData, uuid: string); static destroySpineSkeletonDataWithUUID(uuid: string); static destroySpineSkeleton(skeleton: Skeleton): void; diff --git a/cocos/spine/skeleton-cache.ts b/cocos/spine/skeleton-cache.ts index e10ba8224ae..8798c425236 100644 --- a/cocos/spine/skeleton-cache.ts +++ b/cocos/spine/skeleton-cache.ts @@ -189,12 +189,13 @@ export class AnimationCache { modelData.iData = iUint16Buf; const data = model.getData(); + const textures = model.getTextures(); const count = data.size(); - for (let i = 0; i < count; i += 6) { + for (let i = 0; i < count; i += 5) { const meshData = new SpineDrawItem(); meshData.iCount = data.get(i + 3); meshData.blendMode = data.get(i + 4); - meshData.textureID = data.get(i + 5); + meshData.textureID = textures.get(i / 5); modelData.meshes.push(meshData); } diff --git a/cocos/spine/skeleton-data.ts b/cocos/spine/skeleton-data.ts index d872fd1ccc2..cc5bfb69367 100644 --- a/cocos/spine/skeleton-data.ts +++ b/cocos/spine/skeleton-data.ts @@ -212,18 +212,25 @@ export class SkeletonData extends Asset { const spData = spine.wasmUtil.querySpineSkeletonDataByUUID(uuid); if (spData) { this._skeletonCache = spData; - } else if (this._skeletonJson) { - this._skeletonCache = spine.wasmUtil.createSpineSkeletonDataWithJson(this.skeletonJsonStr, this._atlasText); - spine.wasmUtil.registerSpineSkeletonDataWithUUID(this._skeletonCache, uuid); } else { - const rawData = new Uint8Array(this._nativeAsset); - const byteSize = rawData.length; - const ptr = spine.wasmUtil.queryStoreMemory(byteSize); - const wasmMem = spine.wasmUtil.wasm.HEAPU8.subarray(ptr, ptr + byteSize); - wasmMem.set(rawData); - this._skeletonCache = spine.wasmUtil.createSpineSkeletonDataWithBinary(byteSize, this._atlasText); - spine.wasmUtil.registerSpineSkeletonDataWithUUID(this._skeletonCache, uuid); - } + const size = this.textures.length; + let textureUUIDs = [] as string[]; + for (let i = 0; i < size; ++i) { + textureUUIDs.push(this.textures[i].uuid); + } + if (this._skeletonJson) { + this._skeletonCache = spine.wasmUtil.createSpineSkeletonDataWithJson(this.skeletonJsonStr, this._atlasText, this.textureNames, textureUUIDs); + spine.wasmUtil.registerSpineSkeletonDataWithUUID(this._skeletonCache, uuid); + } else { + const rawData = new Uint8Array(this._nativeAsset); + const byteSize = rawData.length; + const ptr = spine.wasmUtil.queryStoreMemory(byteSize); + const wasmMem = spine.wasmUtil.wasm.HEAPU8.subarray(ptr, ptr + byteSize); + wasmMem.set(rawData); + this._skeletonCache = spine.wasmUtil.createSpineSkeletonDataWithBinary(byteSize, this._atlasText, this.textureNames, textureUUIDs); + spine.wasmUtil.registerSpineSkeletonDataWithUUID(this._skeletonCache, uuid); + } + } return this._skeletonCache; } diff --git a/cocos/spine/skeleton.ts b/cocos/spine/skeleton.ts index 2734df0e1ea..455b834a045 100644 --- a/cocos/spine/skeleton.ts +++ b/cocos/spine/skeleton.ts @@ -33,7 +33,7 @@ import { Graphics, UIRenderer } from '../2d'; import { Batcher2D } from '../2d/renderer/batcher-2d'; import { BlendFactor, BlendOp } from '../gfx'; import { MaterialInstance } from '../render-scene'; -import { builtinResMgr } from '../asset/asset-manager'; +import { assetManager, builtinResMgr } from '../asset/asset-manager'; import { legacyCC } from '../core/global-exports'; import { SkeletonSystem } from './skeleton-system'; import { RenderEntity, RenderEntityType } from '../2d/renderer/render-entity'; @@ -45,8 +45,6 @@ import { TrackEntryListeners } from './track-entry-listeners'; import { setPropertyEnumType } from '../core/internal-index'; const CachedFrameTime = 1 / 60; -const CUSTOM_SLOT_TEXTURE_BEGIN = 10000; -let _slotTextureID = CUSTOM_SLOT_TEXTURE_BEGIN; type TrackListener = (x: spine.TrackEntry) => void; type TrackListener2 = (x: spine.TrackEntry, ev: spine.Event | number) => void; @@ -310,8 +308,6 @@ export class Skeleton extends UIRenderer { */ public _endSlotIndex; - private _slotTextures: Map | null = null; - _vLength = 0; _vBuffer: Uint8Array | null = null; _iLength = 0; @@ -1173,15 +1169,10 @@ export class Skeleton extends UIRenderer { /** * @engineInternal */ - public requestDrawData (material: Material, textureID: number, indexOffset: number, indexCount: number): SkeletonDrawData { + public requestDrawData (material: Material, textureID: string, indexOffset: number, indexCount: number): SkeletonDrawData { const draw = this._drawList.add(); draw.material = material; - if (textureID < CUSTOM_SLOT_TEXTURE_BEGIN) { - draw.texture = this._textures[textureID]; - } else { - const texture = this._slotTextures?.get(textureID); - if (texture) draw.texture = texture; - } + draw.texture = assetManager.assets.get(textureID) as Texture2D; draw.indexOffset = indexOffset; draw.indexCount = indexCount; return draw; @@ -1867,16 +1858,7 @@ export class Skeleton extends UIRenderer { const height = tex2d.height; const createNewAttachment = createNew || false; this._instance!.resizeSlotRegion(slotName, width, height, createNewAttachment); - if (!this._slotTextures) this._slotTextures = new Map(); - let textureID = 0; - this._slotTextures.forEach((value, key) => { - if (value === tex2d) textureID = key; - }); - if (textureID === 0) { - textureID = ++_slotTextureID; - this._slotTextures.set(textureID, tex2d); - } - this._instance!.setSlotTexture(slotName, textureID); + this._instance!.setSlotTexture(slotName, tex2d.uuid); } private _destroySkeletonInfo (skeletonCache: SkeletonCache | null): void { diff --git a/native/cocos/editor-support/spine-wasm/AtlasAttachmentLoaderExtension.cpp b/native/cocos/editor-support/spine-wasm/AtlasAttachmentLoaderExtension.cpp index 5ca9d9d9ea1..d901bb08133 100644 --- a/native/cocos/editor-support/spine-wasm/AtlasAttachmentLoaderExtension.cpp +++ b/native/cocos/editor-support/spine-wasm/AtlasAttachmentLoaderExtension.cpp @@ -5,7 +5,7 @@ using namespace spine; static uint16_t quadTriangles[6] = {0, 1, 2, 2, 3, 0}; -AttachmentVertices::AttachmentVertices(int verticesCount, uint16_t *triangles, int trianglesCount, uint32_t textureId) { +AttachmentVertices::AttachmentVertices(int verticesCount, uint16_t *triangles, int trianglesCount, spine::String textureId) { _triangles = new Triangles(); _triangles->verts = new V3F_T2F_C4B[verticesCount]; _triangles->vertCount = verticesCount; @@ -38,7 +38,7 @@ void AtlasAttachmentLoaderExtension::configureAttachment(Attachment *attachment) auto *regionAttachment = static_cast(attachment); auto &pages = _atlasCache->getPages(); auto *region = static_cast(regionAttachment->getRendererObject()); - auto *attachmentVertices = new AttachmentVertices(4, quadTriangles, 6, pages.indexOf(region->page)); + auto *attachmentVertices = new AttachmentVertices(4, 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) { @@ -51,7 +51,7 @@ void AtlasAttachmentLoaderExtension::configureAttachment(Attachment *attachment) auto &pages = _atlasCache->getPages(); auto *region = static_cast(meshAttachment->getRendererObject()); auto *attachmentVertices = new AttachmentVertices( - static_cast(meshAttachment->getWorldVerticesLength() >> 1), meshAttachment->getTriangles().buffer(), static_cast(meshAttachment->getTriangles().size()), pages.indexOf(region->page)); + static_cast(meshAttachment->getWorldVerticesLength() >> 1), meshAttachment->getTriangles().buffer(), static_cast(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) { diff --git a/native/cocos/editor-support/spine-wasm/AtlasAttachmentLoaderExtension.h b/native/cocos/editor-support/spine-wasm/AtlasAttachmentLoaderExtension.h index 256f72d99b6..22be63ca4eb 100644 --- a/native/cocos/editor-support/spine-wasm/AtlasAttachmentLoaderExtension.h +++ b/native/cocos/editor-support/spine-wasm/AtlasAttachmentLoaderExtension.h @@ -5,11 +5,11 @@ class AttachmentVertices { public: - AttachmentVertices(int verticesCount, uint16_t *triangles, int trianglesCount, uint32_t textureId); + AttachmentVertices(int verticesCount, uint16_t *triangles, int trianglesCount, spine::String textureId); virtual ~AttachmentVertices(); AttachmentVertices *copy(); Triangles *_triangles = nullptr; - uint32_t _textureId = 0; + spine::String _textureId{""}; }; class AtlasAttachmentLoaderExtension : public spine::AtlasAttachmentLoader { diff --git a/native/cocos/editor-support/spine-wasm/spine-model.cpp b/native/cocos/editor-support/spine-wasm/spine-model.cpp index e44fc15a492..fd7093ed8cc 100644 --- a/native/cocos/editor-support/spine-wasm/spine-model.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-model.cpp @@ -11,20 +11,20 @@ void SpineModel::addSlotMesh(SlotMesh& mesh, bool needMerge) { bool canMerge = false; auto count = _data.size(); if (needMerge && count > 0) { - if (_data[count - 2] == mesh.blendMode && _data[count - 1] == mesh.textureID) { + if (_data[count - 1] == mesh.blendMode && _textures[count / 5 - 1] == mesh.textureID) { canMerge = true; - _data[count-4] += mesh.vCount; - _data[count-3] += mesh.iCount; + _data[count-3] += mesh.vCount; + _data[count-2] += mesh.iCount; } } if (!canMerge) { - _data.setSize(count + 6, 0); + _data.setSize(count + 5, 0); _data[count] = (uint32_t)mesh.vBuf; _data[count + 1] = (uint32_t)mesh.iBuf; _data[count + 2] = mesh.vCount; _data[count + 3] = mesh.iCount; _data[count + 4] = mesh.blendMode; - _data[count + 5] = mesh.textureID; + _textures.add(mesh.textureID); } auto indexCount = mesh.iCount; @@ -45,6 +45,7 @@ void SpineModel::addSlotMesh(SlotMesh& mesh, bool needMerge) { void SpineModel::clearMeshes() { _data.setSize(0, 0); + _textures.setSize(0, ""); vCount = 0; iCount = 0; } diff --git a/native/cocos/editor-support/spine-wasm/spine-model.h b/native/cocos/editor-support/spine-wasm/spine-model.h index 6921fd592e9..ef69365f2e2 100644 --- a/native/cocos/editor-support/spine-wasm/spine-model.h +++ b/native/cocos/editor-support/spine-wasm/spine-model.h @@ -19,7 +19,7 @@ class SlotMesh { uint32_t vCount{}; uint32_t iCount{}; uint32_t blendMode{}; - uint32_t textureID{}; + spine::String textureID{""}; }; class SpineModel { @@ -31,8 +31,10 @@ class SpineModel { void setBufferPtr(uint8_t* vp, uint16_t* ip); spine::Vector* getData(); + inline spine::Vector* getTextures() { return &_textures; } private: spine::Vector _data; + spine::Vector _textures; public: uint32_t vCount{}; uint32_t iCount{}; diff --git a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp index ed4bc3a85e8..8cf8222c77d 100644 --- a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp @@ -503,7 +503,7 @@ void SpineSkeletonInstance::resizeSlotRegion(const spine::String &slotName, uint } } -void SpineSkeletonInstance::setSlotTexture(const spine::String &slotName, uint32_t textureID) { +void SpineSkeletonInstance::setSlotTexture(const spine::String &slotName, spine::String textureID) { if (!_skeleton) return; auto* slot = _skeleton->findSlot(slotName); if (!slot) return; diff --git a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h index 2743a0e799f..1fbc7a95a16 100644 --- a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h +++ b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h @@ -54,7 +54,7 @@ class SpineSkeletonInstance { void onTrackEntryEvent(spine::TrackEntry *entry, spine::EventType type, spine::Event *event); inline spine::Vector &getDebugShapes() { return _debugShapes; } void resizeSlotRegion(const spine::String &slotName, uint32_t width, uint32_t height, bool createNew = false); - void setSlotTexture(const spine::String &slotName, uint32_t index); + void setSlotTexture(const spine::String &slotName, spine::String textureID); void destroy(); bool isCache{false}; bool enable{true}; @@ -74,5 +74,5 @@ class SpineSkeletonInstance { uint32_t _trackEntryListenerID = 0; UserData _userData; spine::Vector _debugShapes{}; - spine::HashMap _slotTextureSet{}; + spine::HashMap _slotTextureSet{}; }; diff --git a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp index ac34fbc3f01..10b225b5199 100644 --- a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp @@ -1341,6 +1341,7 @@ EMSCRIPTEN_BINDINGS(spine) { .property("iCount", &SpineModel::iCount) .property("vPtr", &SpineModel::vPtr) .property("iPtr", &SpineModel::iPtr) + .function("getTextures", &SpineModel::getTextures, allow_raw_pointers()) .function("getData", &SpineModel::getData, allow_raw_pointer()); class_("SpineDebugShape") @@ -1384,8 +1385,30 @@ EMSCRIPTEN_BINDINGS(cocos_spine) { .class_function("spineWasmDestroy", &SpineWasmUtil::spineWasmDestroy) .class_function("queryStoreMemory", &SpineWasmUtil::queryStoreMemory) .class_function("querySpineSkeletonDataByUUID", &SpineWasmUtil::querySpineSkeletonDataByUUID, allow_raw_pointers()) - .class_function("createSpineSkeletonDataWithJson", &SpineWasmUtil::createSpineSkeletonDataWithJson, allow_raw_pointers()) - .class_function("createSpineSkeletonDataWithBinary", &SpineWasmUtil::createSpineSkeletonDataWithBinary, allow_raw_pointers()) + .class_function("createSpineSkeletonDataWithJson", optional_override([](String jsonStr, String atlasStr, emscripten::val nameArray, emscripten::val uuidArray){ + unsigned count = nameArray["length"].as(); + Vector names = Vector(); + Vector ids = Vector(); + names.setSize(count, ""); + ids.setSize(count, ""); + for (int i = 0; i < count; i++) { + names[i] = nameArray[i].as(); + ids[i] = uuidArray[i].as(); + } + return SpineWasmUtil::createSpineSkeletonDataWithJson(jsonStr, atlasStr, names, ids); + }), allow_raw_pointers()) + .class_function("createSpineSkeletonDataWithBinary", optional_override([](uint32_t byteSize, String atlasStr, emscripten::val nameArray, emscripten::val uuidArray){ + unsigned count = nameArray["length"].as(); + Vector names = Vector(); + Vector ids = Vector(); + names.setSize(count, ""); + ids.setSize(count, ""); + for (int i = 0; i < count; i++) { + names[i] = nameArray[i].as(); + ids[i] = uuidArray[i].as(); + } + return SpineWasmUtil::createSpineSkeletonDataWithBinary(byteSize, atlasStr, names, ids); + }), allow_raw_pointers()) .class_function("registerSpineSkeletonDataWithUUID", &SpineWasmUtil::registerSpineSkeletonDataWithUUID, allow_raw_pointers()) .class_function("destroySpineSkeletonDataWithUUID", &SpineWasmUtil::destroySpineSkeletonDataWithUUID) .class_function("destroySpineSkeleton", &SpineWasmUtil::destroySpineSkeleton, allow_raw_pointers()) diff --git a/native/cocos/editor-support/spine-wasm/spine-wasm.cpp b/native/cocos/editor-support/spine-wasm/spine-wasm.cpp index cc486db5c5a..b695d68a336 100644 --- a/native/cocos/editor-support/spine-wasm/spine-wasm.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-wasm.cpp @@ -4,10 +4,43 @@ #include "util-function.h" #include "wasmSpineExtension.h" +#include + using namespace spine; namespace { HashMap skeletonDataMap{}; + + static void updateAttachmentVerticesTextureId(SkeletonData* skeletonData, spine::Vector& textureNames, spine::Vector& textureUUIDs) { + std::map textureMap; + int textureSize = textureNames.size(); + for (int i = 0; i < textureSize; ++i) { + textureMap[textureNames[i].buffer()] = textureUUIDs[i].buffer(); + } + + auto& skins = skeletonData->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(); + AttachmentVertices* attachmentVertices; + auto* attachment = entry._attachment; + if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) { + auto* meshAttachment = static_cast(attachment); + attachmentVertices = static_cast(meshAttachment->getRendererObject()); + } else { + auto* regionAttachment = static_cast(attachment); + attachmentVertices = static_cast(regionAttachment->getRendererObject()); + } + auto* textureName = attachmentVertices->_textureId.buffer(); + auto iter = textureMap.find(textureName); + if (iter == textureMap.end()) continue; + attachmentVertices->_textureId = String(iter->second.c_str()); + } + } + } } uint32_t SpineWasmUtil::s_listenerID = 0; @@ -42,7 +75,7 @@ SkeletonData* SpineWasmUtil::querySpineSkeletonDataByUUID(const String& uuid) { return skeletonDataMap[uuid]; } -SkeletonData* SpineWasmUtil::createSpineSkeletonDataWithJson(const String& jsonStr, const String& altasStr) { +SkeletonData* SpineWasmUtil::createSpineSkeletonDataWithJson(const String& jsonStr, const String& altasStr, spine::Vector& textureNames, spine::Vector& textureUUIDs) { #if ENABLE_JSON_PARSER auto* atlas = new Atlas(altasStr.buffer(), altasStr.length(), "", nullptr, false); if (!atlas) { @@ -53,13 +86,15 @@ SkeletonData* SpineWasmUtil::createSpineSkeletonDataWithJson(const String& jsonS json.setScale(1.0F); SkeletonData* skeletonData = json.readSkeletonData(jsonStr.buffer()); + updateAttachmentVerticesTextureId(skeletonData, textureNames, textureUUIDs); + return skeletonData; #else return nullptr; #endif } -SkeletonData* SpineWasmUtil::createSpineSkeletonDataWithBinary(uint32_t byteSize, const String& altasStr) { +SkeletonData* SpineWasmUtil::createSpineSkeletonDataWithBinary(uint32_t byteSize, const String& altasStr, spine::Vector& textureNames, spine::Vector& textureUUIDs) { #if ENABLE_BINARY_PARSER auto* atlas = new Atlas(altasStr.buffer(), altasStr.length(), "", nullptr, false); if (!atlas) { @@ -69,6 +104,9 @@ SkeletonData* SpineWasmUtil::createSpineSkeletonDataWithBinary(uint32_t byteSize SkeletonBinary binary(attachmentLoader); binary.setScale(1.0F); SkeletonData* skeletonData = binary.readSkeletonData(s_mem, byteSize); + + updateAttachmentVerticesTextureId(skeletonData, textureNames, textureUUIDs); + return skeletonData; #else return nullptr; diff --git a/native/cocos/editor-support/spine-wasm/spine-wasm.h b/native/cocos/editor-support/spine-wasm/spine-wasm.h index 655b7f743c1..f9194562b2a 100644 --- a/native/cocos/editor-support/spine-wasm/spine-wasm.h +++ b/native/cocos/editor-support/spine-wasm/spine-wasm.h @@ -11,8 +11,8 @@ class SpineWasmUtil { static void freeStoreMemory(); static spine::SkeletonData* querySpineSkeletonDataByUUID(const spine::String& uuid); - static spine::SkeletonData* createSpineSkeletonDataWithJson(const spine::String& jsonStr, const spine::String& altasStr); - static spine::SkeletonData* createSpineSkeletonDataWithBinary(uint32_t byteSize, const spine::String& altasStr); + static spine::SkeletonData* createSpineSkeletonDataWithJson(const spine::String& jsonStr, const spine::String& altasStr, spine::Vector& textureNames, spine::Vector& textureUUIDs); + static spine::SkeletonData* createSpineSkeletonDataWithBinary(uint32_t byteSize, const spine::String& altasStr, spine::Vector& textureNames, spine::Vector& textureUUIDs); static void registerSpineSkeletonDataWithUUID(spine::SkeletonData* data, const spine::String& uuid); static void destroySpineSkeletonDataWithUUID(const spine::String& uuid); static void destroySpineSkeleton(spine::Skeleton* skeleton);