@@ -12,12 +12,6 @@ extern void spineTrackListenerCallback();
12
12
}
13
13
using namespace spine ;
14
14
15
- #ifdef CC_SPINE_VERSION_3_8
16
- static void deleteAttachmentVertices (void *vertices) {
17
- delete static_cast <AttachmentVertices *>(vertices);
18
- }
19
- #endif
20
-
21
15
static void animationCallback (AnimationState *state, EventType type, TrackEntry *entry, Event *event) {
22
16
SpineSkeletonInstance *instance = (static_cast <SpineSkeletonInstance *>(state->getRendererObject ()));
23
17
if (instance) {
@@ -70,10 +64,7 @@ SpineSkeletonInstance::~SpineSkeletonInstance() {
70
64
while (entries.hasNext ()) {
71
65
auto entry = entries.next ();
72
66
auto info = entry.value ;
73
- if (info.attachment && info.isOwner ) {
74
- delete info.attachment ;
75
- info.attachment = nullptr ;
76
- }
67
+ releaseSlotCacheInfo (info);
77
68
}
78
69
}
79
70
}
@@ -157,6 +148,7 @@ SpineModel *SpineSkeletonInstance::updateRenderData() {
157
148
_model->byteStride = sizeof (V3F_T2F_C4B);
158
149
}
159
150
collectMeshData ();
151
+ globalMesh.textureID = " " ;
160
152
_model->setBufferPtr (SpineMeshData::vb (), SpineMeshData::ib ());
161
153
return _model;
162
154
}
@@ -202,19 +194,24 @@ void SpineSkeletonInstance::collectMeshData() {
202
194
color.b = _userData.color .b ;
203
195
color.a = _userData.color .a ;
204
196
spine::Attachment* attachmentSlot = slot->getAttachment ();
197
+ AttachmentVertices *cacheSlotAttachmentVertices = nullptr ;
205
198
if (_userData.useSlotTexture && _slotTextureSet.containsKey (slot)) {
206
199
auto info = _slotTextureSet[slot];
207
200
attachmentSlot = info.attachment ;
201
+ cacheSlotAttachmentVertices = info.attachmentVertices ;
208
202
}
209
203
const spine::RTTI& attachmentRTTI = attachmentSlot->getRTTI ();
210
204
if (attachmentRTTI.isExactly (spine::RegionAttachment::rtti)) {
211
205
debugShapeType = DEBUG_SHAPE_TYPE::DEBUG_REGION;
212
206
auto *attachment = static_cast <spine::RegionAttachment *>(attachmentSlot);
207
+ auto *attachmentVertices = cacheSlotAttachmentVertices;
208
+ if (!attachmentVertices) {
213
209
#ifdef CC_SPINE_VERSION_3_8
214
- auto * attachmentVertices = reinterpret_cast <AttachmentVertices *>(attachment->getRendererObject ());
210
+ attachmentVertices = reinterpret_cast <AttachmentVertices *>(attachment->getRendererObject ());
215
211
#else
216
- auto * attachmentVertices = reinterpret_cast <AttachmentVertices *>(attachment->getRegion ()->rendererObject );
212
+ attachmentVertices = reinterpret_cast <AttachmentVertices *>(attachment->getRegion ()->rendererObject );
217
213
#endif
214
+ }
218
215
219
216
auto *triangles = attachmentVertices->_triangles ;
220
217
auto vertCount = triangles->vertCount ;
@@ -249,11 +246,14 @@ void SpineSkeletonInstance::collectMeshData() {
249
246
} else if (attachmentRTTI.isExactly (spine::MeshAttachment::rtti)) {
250
247
debugShapeType = DEBUG_SHAPE_TYPE::DEBUG_MESH;
251
248
auto *attachment = static_cast <spine::MeshAttachment *>(attachmentSlot);
249
+ auto *attachmentVertices = cacheSlotAttachmentVertices;
250
+ if (!attachmentVertices) {
252
251
#ifdef CC_SPINE_VERSION_3_8
253
- auto * attachmentVertices = static_cast <AttachmentVertices *>(attachment->getRendererObject ());
252
+ attachmentVertices = static_cast <AttachmentVertices *>(attachment->getRendererObject ());
254
253
#else
255
- auto * attachmentVertices = static_cast <AttachmentVertices *>(attachment->getRegion ()->rendererObject );
254
+ attachmentVertices = static_cast <AttachmentVertices *>(attachment->getRegion ()->rendererObject );
256
255
#endif
256
+ }
257
257
258
258
auto *triangles = attachmentVertices->_triangles ;
259
259
auto vertCount = triangles->vertCount ;
@@ -534,12 +534,10 @@ void SpineSkeletonInstance::resizeSlotRegion(const spine::String &slotName, uint
534
534
if (!attachment) return ;
535
535
if (createNew) {
536
536
attachment = attachment->copy ();
537
- slot->setAttachment (attachment);
538
537
}
539
538
SlotCacheInfo info;
540
539
info.attachment = attachment;
541
540
info.isOwner = createNew;
542
- _slotTextureSet.put (slot, info);
543
541
if (attachment->getRTTI ().isExactly (spine::RegionAttachment::rtti)) {
544
542
auto *region = static_cast <RegionAttachment *>(attachment);
545
543
#ifdef CC_SPINE_VERSION_3_8
@@ -554,7 +552,7 @@ void SpineSkeletonInstance::resizeSlotRegion(const spine::String &slotName, uint
554
552
auto *attachmentVertices = static_cast <AttachmentVertices *>(region->getRendererObject ());
555
553
if (createNew) {
556
554
attachmentVertices = attachmentVertices->copy ();
557
- region-> setRendererObject ( attachmentVertices, deleteAttachmentVertices) ;
555
+ info. attachmentVertices = attachmentVertices ;
558
556
}
559
557
#else
560
558
auto *textureRegion = region->getRegion ();
@@ -563,6 +561,11 @@ void SpineSkeletonInstance::resizeSlotRegion(const spine::String &slotName, uint
563
561
textureRegion->height = height;
564
562
textureRegion->originalWidth = width;
565
563
textureRegion->originalHeight = height;
564
+
565
+ textureRegion->u = 0 ;
566
+ textureRegion->v = 0 ;
567
+ textureRegion->u2 = 1 .0f ;
568
+ textureRegion->v2 = 1 .0f ;
566
569
}
567
570
region->setWidth (width);
568
571
region->setHeight (height);
@@ -579,7 +582,7 @@ void SpineSkeletonInstance::resizeSlotRegion(const spine::String &slotName, uint
579
582
auto *attachmentVertices = static_cast <AttachmentVertices *>(region->getRegion ()->rendererObject );
580
583
if (createNew) {
581
584
attachmentVertices = attachmentVertices->copy ();
582
- region-> getRegion ()-> rendererObject = attachmentVertices;
585
+ info. attachmentVertices = attachmentVertices;
583
586
}
584
587
#endif
585
588
V3F_T2F_C4B *vertices = attachmentVertices->_triangles ->verts ;
@@ -607,7 +610,7 @@ void SpineSkeletonInstance::resizeSlotRegion(const spine::String &slotName, uint
607
610
auto *attachmentVertices = static_cast <AttachmentVertices *>(mesh->getRendererObject ());
608
611
if (createNew) {
609
612
attachmentVertices = attachmentVertices->copy ();
610
- mesh-> setRendererObject ( attachmentVertices, deleteAttachmentVertices) ;
613
+ info. attachmentVertices = attachmentVertices ;
611
614
}
612
615
#else
613
616
auto *region = mesh->getRegion ();
@@ -628,7 +631,7 @@ void SpineSkeletonInstance::resizeSlotRegion(const spine::String &slotName, uint
628
631
auto *attachmentVertices = static_cast <AttachmentVertices *>(mesh->getRegion ()->rendererObject );
629
632
if (createNew) {
630
633
attachmentVertices = attachmentVertices->copy ();
631
- mesh-> getRegion ()-> rendererObject = attachmentVertices;
634
+ info. attachmentVertices = attachmentVertices;
632
635
}
633
636
#endif
634
637
V3F_T2F_C4B *vertices = attachmentVertices->_triangles ->verts ;
@@ -638,6 +641,11 @@ void SpineSkeletonInstance::resizeSlotRegion(const spine::String &slotName, uint
638
641
vertices[i].texCoord .v = UVs[ii + 1 ];
639
642
}
640
643
}
644
+ if (_slotTextureSet.containsKey (slot)) {
645
+ auto cacheInfo = _slotTextureSet[slot];
646
+ releaseSlotCacheInfo (cacheInfo);
647
+ }
648
+ _slotTextureSet.put (slot, info);
641
649
_skeleton->updateCache ();
642
650
}
643
651
@@ -647,23 +655,7 @@ void SpineSkeletonInstance::setSlotTexture(const spine::String &slotName, const
647
655
if (!slot) return ;
648
656
_userData.useSlotTexture = true ;
649
657
if (_slotTextureSet.containsKey (slot)) {
650
- AttachmentVertices *attachmentVertices = nullptr ;
651
- auto * attachment = _slotTextureSet[slot].attachment ;
652
- if (attachment->getRTTI ().isExactly (spine::RegionAttachment::rtti)) {
653
- auto *regionAttachment = static_cast <RegionAttachment *>(attachment);
654
- #ifdef CC_SPINE_VERSION_3_8
655
- attachmentVertices = static_cast <AttachmentVertices *>(regionAttachment->getRendererObject ());
656
- #else
657
- attachmentVertices = static_cast <AttachmentVertices *>(regionAttachment->getRegion ()->rendererObject );
658
- #endif
659
- } else if (attachment->getRTTI ().isExactly (spine::MeshAttachment::rtti)) {
660
- auto *meshAttachment = static_cast <MeshAttachment *>(attachment);
661
- #ifdef CC_SPINE_VERSION_3_8
662
- attachmentVertices = static_cast <AttachmentVertices *>(meshAttachment->getRendererObject ());
663
- #else
664
- attachmentVertices = static_cast <AttachmentVertices *>(meshAttachment->getRegion ()->rendererObject );
665
- #endif
666
- }
658
+ AttachmentVertices *attachmentVertices = _slotTextureSet[slot].attachmentVertices ;
667
659
if (attachmentVertices) {
668
660
attachmentVertices->_textureUUID = textureUuid;
669
661
}
@@ -691,4 +683,13 @@ void SpineSkeletonInstance::dispatchEvents() {
691
683
auto & info = vecTrackEvents[i];
692
684
onTrackEntryEvent (info.entry , info.eventType , info.event );
693
685
}
686
+ }
687
+
688
+ void SpineSkeletonInstance::releaseSlotCacheInfo (SlotCacheInfo &info) {
689
+ if (info.attachment && info.isOwner ) {
690
+ delete info.attachment ;
691
+ info.attachment = nullptr ;
692
+ delete info.attachmentVertices ;
693
+ info.attachmentVertices = nullptr ;
694
+ }
694
695
}
0 commit comments