From 6c742a9c7298f6c48d31c33c0407039a72903547 Mon Sep 17 00:00:00 2001 From: SmallMain Date: Tue, 21 Jun 2022 15:37:22 +0800 Subject: [PATCH 13/15] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20Spine=20=E5=8D=95?= =?UTF-8?q?=E5=8A=A8=E7=94=BB=E7=94=A8=E4=BA=86=E5=A4=9A=E4=B8=AA=E7=BA=B9?= =?UTF-8?q?=E7=90=86=E6=97=B6=EF=BC=8C=E7=BC=93=E5=AD=98=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E4=B8=8B=E6=98=BE=E7=A4=BA=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- engine/extensions/spine/Skeleton.js | 10 +++++++--- engine/extensions/spine/skeleton-cache.js | 4 ++-- engine/extensions/spine/spine-assembler.js | 18 +++++++++++------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/engine/extensions/spine/Skeleton.js b/engine/extensions/spine/Skeleton.js index 61cde65..b1eda9c 100644 --- a/engine/extensions/spine/Skeleton.js +++ b/engine/extensions/spine/Skeleton.js @@ -464,8 +464,8 @@ sp.Skeleton = cc.Class({ }, setVertsDirty() { - this.invalidAnimationCache(); this._dataDirty = true; + this.invalidAnimationCache(); this._materialCache = {}; this._super(); }, @@ -702,6 +702,8 @@ sp.Skeleton = cc.Class({ if (this.isAnimationCached()) { + this._assembler.handleDynamicAtlasAndSwitchMaterial(this); + // Cache mode and has animation queue. if (this._isAniComplete) { if (this._animationQueue.length === 0 && !this._headAniInfo) { @@ -1086,6 +1088,7 @@ sp.Skeleton = cc.Class({ if (this.attachUtil._hasAttachedNode()) { this._frameCache.enableCacheAttachedInfo(); } + this._assembler.handleDynamicAtlasAndSwitchMaterial(this); this._frameCache.updateToFrame(0); this._curFrame = this._frameCache.frames[0]; } @@ -1379,7 +1382,9 @@ sp.Skeleton = cc.Class({ } }, - _updateSkeletonData () { + _updateSkeletonData() { + this._dataDirty = true; + if (!this.skeletonData) { this.disableRender(); return; @@ -1406,7 +1411,6 @@ sp.Skeleton = cc.Class({ this.attachUtil._associateAttachedNode(); this._preCacheMode = this._cacheMode; this.animation = this.defaultAnimation; - this._dataDirty = true; }, _refreshInspector () { diff --git a/engine/extensions/spine/skeleton-cache.js b/engine/extensions/spine/skeleton-cache.js index c0ef822..5a26e01 100644 --- a/engine/extensions/spine/skeleton-cache.js +++ b/engine/extensions/spine/skeleton-cache.js @@ -423,8 +423,8 @@ let AnimationCache = cc.Class({ } blendMode = slot.data.blendMode; - if (_preTexUrl !== texture.nativeUrl || _preBlendMode !== blendMode) { - _preTexUrl = texture.nativeUrl; + if (_preTexUrl !== texture._texture._id || _preBlendMode !== blendMode) { + _preTexUrl = texture._texture._id; _preBlendMode = blendMode; // Handle pre segment. preSegOffset = _segOffset - 1; diff --git a/engine/extensions/spine/spine-assembler.js b/engine/extensions/spine/spine-assembler.js index 36c91f0..2744684 100644 --- a/engine/extensions/spine/spine-assembler.js +++ b/engine/extensions/spine/spine-assembler.js @@ -199,6 +199,15 @@ export default class SpineAssembler extends Assembler { updateRenderData (comp) { if (comp.isAnimationCached()) return; + this.handleDynamicAtlasAndSwitchMaterial(comp); + + let skeleton = comp._skeleton; + if (skeleton) { + skeleton.updateWorldTransform(); + } + } + + handleDynamicAtlasAndSwitchMaterial(comp) { if (comp._dataDirty) { // 自动合图 this.packDynamicAtlasForSpine(comp); @@ -210,13 +219,13 @@ export default class SpineAssembler extends Assembler { if (!material) return false; const skins = comp.skeletonData._skeletonCache.skins; - for (const skin of skins) { + root: for (const skin of skins) { for (const attachment of skin.attachments) { for (const key in attachment) { const region = attachment[key].region; if (region && region.texture) { this.checkAndSwitchMaterial(comp, region.texture._texture, material); - break; + break root; } } } @@ -224,11 +233,6 @@ export default class SpineAssembler extends Assembler { } comp._dataDirty = false; } - - let skeleton = comp._skeleton; - if (skeleton) { - skeleton.updateWorldTransform(); - } } packDynamicAtlasForSpine(comp) { -- 2.32.0 (Apple Git-132)