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 ad9cfe900e6..81b4e0b98a3 100644 --- a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp @@ -352,13 +352,9 @@ void SpineSkeletonInstance::collectMeshData() { } currMesh.blendMode = static_cast(slot->getData().getBlendMode()); - if (_userData.useSlotTexture) { - uint32_t textureID = findSlotTextureID(slot); - if(textureID == 10000) textureID = slot->getData().hash; - currMesh.textureID = textureID; - } else { - currMesh.textureID = slot->getData().hash; - } + + currMesh.textureID = slot->getData().hash; + _model->addSlotMesh(currMesh); _clipper->clipEnd(*slot); @@ -537,24 +533,9 @@ void SpineSkeletonInstance::resizeSlotRegion(const std::string& slotName, uint32 } } -uint32_t SpineSkeletonInstance::findSlotTextureID(Slot* slot) { - auto iter = slotTextureSet.find(slot); - if (iter != slotTextureSet.end()) { - return iter->second; - } else { - return 10000; - } -} - void SpineSkeletonInstance::setSlotTexture(const std::string& slotName, uint32_t textureID) { if (!_skeleton) return; auto slot = _skeleton->findSlot(slotName.c_str()); if (!slot) return; - _userData.useSlotTexture = true; - auto iter = slotTextureSet.find(slot); - if (iter != slotTextureSet.end()) { - iter->second = textureID; - } else { - slotTextureSet[slot] = textureID; - } + slot->getData().hash = textureID; } \ No newline at end of file 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 39a692b4bc0..59878693e94 100644 --- a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h +++ b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h @@ -36,7 +36,6 @@ class SpineSkeletonInstance { bool useTint = false; bool premultipliedAlpha = false; bool debugMode = false; - bool useSlotTexture = false; Color4F color = Color4F(1.0F, 1.0F, 1.0F, 1.0F); }; @@ -65,7 +64,6 @@ class SpineSkeletonInstance { private: void collectMeshData(); - uint32_t findSlotTextureID(Slot* slot); private: Skeleton *_skeleton = nullptr; SkeletonData *_skeletonData = nullptr; @@ -82,7 +80,6 @@ class SpineSkeletonInstance { uint32_t _eventListenerID = 0; UserData _userData; std::vector _debugShapes{}; - std::map slotTextureSet{}; }; #endif \ No newline at end of file diff --git a/native/cocos/editor-support/spine-wasm/spine-wasm.cpp b/native/cocos/editor-support/spine-wasm/spine-wasm.cpp index 788a028ffb0..548f33bca41 100644 --- a/native/cocos/editor-support/spine-wasm/spine-wasm.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-wasm.cpp @@ -70,23 +70,22 @@ SkeletonData* SpineWasmUtil::createSpineSkeletonDataWithBinary(uint32_t byteSize void SpineWasmUtil::calculateTextureID(Atlas* atlas, SkeletonData* skeletonData) { + spine::Vector skins = skeletonData->getSkins(); auto& slotArray = skeletonData->getSlots(); - const size_t count = slotArray.size(); - for (size_t i = 0; i < count; i++) { - slotArray[i]->hash = 60000; - const spine::String attachmentName = slotArray[i]->getAttachmentName(); - AtlasRegion* atlasRegion = atlas->findRegion(attachmentName); - if(atlasRegion != NULL) { - slotArray[i]->hash = atlas->getPages().indexOf(atlasRegion->page) + 10000; - }else{ - const spine::String name = slotArray[i]->getName(); - AtlasRegion* atlasRegion = atlas->findRegion(name); - if(atlasRegion) { - slotArray[i]->hash = atlas->getPages().indexOf(atlasRegion->page) + 10000; - }else{ - slotArray[i]->hash = 20000; - } + + const size_t count = skins.size(); + for (int32_t i = 0; i < count; i++) { + + spine::Skin *skin = skins[i]; + auto entries = skin->getAttachments(); + while (entries.hasNext()) + { + auto &entry = entries.next(); + AtlasRegion* atlasRegion = atlas->findRegion(entry._name); + if(atlasRegion) + slotArray[entry._slotIndex]->hash = atlas->getPages().indexOf(atlasRegion->page) + 10000; } + } } diff --git a/native/cocos/editor-support/spine/SlotData.h b/native/cocos/editor-support/spine/SlotData.h index 5a663198146..3bca94ebe2b 100644 --- a/native/cocos/editor-support/spine/SlotData.h +++ b/native/cocos/editor-support/spine/SlotData.h @@ -76,7 +76,7 @@ class SP_API SlotData : public SpineObject { int getIndex(); - int hash; + uint32_t hash; const String &getName();