30
30
#include " SkeletonCache.h"
31
31
#include " base/memory/Memory.h"
32
32
#include " spine-creator-support/AttachmentVertices.h"
33
+ #include " SkeletonDataMgr.h"
33
34
34
35
USING_NS_MW; // NOLINT(google-build-using-namespace)
35
36
using namespace cc ; // NOLINT(google-build-using-namespace)
36
37
using namespace spine ;
38
+
39
+ extern " C" AttachmentVertices *generateAttachmentVertices (Attachment *attachment);
40
+
37
41
namespace cc {
38
42
39
43
float SkeletonCache::FrameTime = 1 .0F / 60 .0F ;
@@ -311,6 +315,10 @@ void SkeletonCache::renderAnimationFrame(AnimationData *animationData) {
311
315
matm[13 ] = bone->getWorldY ();
312
316
}
313
317
318
+
319
+ auto *verticesMap = SkeletonDataMgr::getInstance ()->getSkeletonDataInfo (_uuid);
320
+ if (!verticesMap) return ;
321
+ auto &attachmentVerticesMap = *verticesMap;
314
322
auto &drawOrder = _skeleton->getDrawOrder ();
315
323
for (size_t i = 0 , n = drawOrder.size (); i < n; ++i) {
316
324
slot = drawOrder[i];
@@ -319,20 +327,34 @@ void SkeletonCache::renderAnimationFrame(AnimationData *animationData) {
319
327
continue ;
320
328
}
321
329
322
- if (!slot->getAttachment ()) {
330
+ auto *tmpAttachment = slot->getAttachment ();
331
+ if (!tmpAttachment) {
323
332
_clipper->clipEnd (*slot);
324
333
continue ;
325
334
}
326
335
const spine::Color &slotColor = slot->getColor ();
327
336
337
+ auto iterAttachment = attachmentVerticesMap.find (tmpAttachment);
338
+ if (iterAttachment != attachmentVerticesMap.end ()) {
339
+ attachmentVertices = iterAttachment->second ;
340
+ } else {
341
+ attachmentVertices = nullptr ;
342
+ }
343
+
328
344
TwoColorTriangles trianglesTwoColor;
329
345
spine::Color attachmentColor;
330
- if (slot->getAttachment ()->getRTTI ().isExactly (RegionAttachment::rtti)) {
331
- auto *attachment = dynamic_cast <RegionAttachment *>(slot->getAttachment ());
332
- #if CC_USE_SPINE_3_8
333
- attachmentVertices = static_cast <AttachmentVertices *>(attachment->getRendererObject ());
334
- #else
335
- attachmentVertices = static_cast <AttachmentVertices *>(attachment->getRegion ()->rendererObject );
346
+ if (tmpAttachment->getRTTI ().isExactly (RegionAttachment::rtti)) {
347
+ auto *attachment = dynamic_cast <RegionAttachment *>(tmpAttachment);
348
+ #if CC_USE_SPINE_4_2
349
+ if (!attachment->getRegion ()) {
350
+ attachment->getSequence ()->apply (slot, attachment);
351
+ if (attachment->getRegion ()) {
352
+ attachmentVertices = generateAttachmentVertices (attachment);
353
+ if (attachmentVertices) {
354
+ attachmentVerticesMap[attachment] = attachmentVertices;
355
+ }
356
+ }
357
+ }
336
358
#endif
337
359
338
360
// Early exit if attachment is invisible
@@ -362,12 +384,18 @@ void SkeletonCache::renderAnimationFrame(AnimationData *animationData) {
362
384
363
385
attachmentColor = attachment->getColor ();
364
386
365
- } else if (slot->getAttachment ()->getRTTI ().isExactly (MeshAttachment::rtti)) {
366
- auto *attachment = dynamic_cast <MeshAttachment *>(slot->getAttachment ());
367
- #if CC_USE_SPINE_3_8
368
- attachmentVertices = static_cast <AttachmentVertices *>(attachment->getRendererObject ());
369
- #else
370
- attachmentVertices = static_cast <AttachmentVertices *>(attachment->getRegion ()->rendererObject );
387
+ } else if (tmpAttachment->getRTTI ().isExactly (MeshAttachment::rtti)) {
388
+ auto *attachment = dynamic_cast <MeshAttachment *>(tmpAttachment);
389
+ #if CC_USE_SPINE_4_2
390
+ if (!attachment->getRegion ()) {
391
+ attachment->getSequence ()->apply (slot, attachment);
392
+ if (attachment->getRegion ()) {
393
+ attachmentVertices = generateAttachmentVertices (attachment);
394
+ if (attachmentVertices) {
395
+ attachmentVerticesMap[attachment] = attachmentVertices;
396
+ }
397
+ }
398
+ }
371
399
#endif
372
400
373
401
// Early exit if attachment is invisible
@@ -391,8 +419,8 @@ void SkeletonCache::renderAnimationFrame(AnimationData *animationData) {
391
419
trianglesTwoColor.indices = reinterpret_cast <uint16_t *>(ib.getCurBuffer ());
392
420
memcpy (trianglesTwoColor.indices , attachmentVertices->_triangles ->indices , ibSize);
393
421
attachmentColor = attachment->getColor ();
394
- } else if (slot-> getAttachment () ->getRTTI ().isExactly (ClippingAttachment::rtti)) {
395
- auto *clip = dynamic_cast <ClippingAttachment *>(slot-> getAttachment () );
422
+ } else if (tmpAttachment ->getRTTI ().isExactly (ClippingAttachment::rtti)) {
423
+ auto *clip = dynamic_cast <ClippingAttachment *>(tmpAttachment );
396
424
_clipper->clipStart (*slot, clip);
397
425
continue ;
398
426
} else {
0 commit comments