diff --git a/cc.config.json b/cc.config.json index dacad28ce8..90dde5ed2b 100644 --- a/cc.config.json +++ b/cc.config.json @@ -117,6 +117,10 @@ }, "dragon-bones": { "modules": [ "dragon-bones" ], + "dependentAssets":[ + "c27215d8-6835-4b68-bfbb-bdeac6100c04", + "b5d6115f-0370-4d7c-aad3-c194cc71cf98" + ], "dependentModules": [ "2d" ] }, "marionette": { diff --git a/cocos/dragon-bones/ArmatureDisplay.ts b/cocos/dragon-bones/ArmatureDisplay.ts index 083dea6a45..b3240130fa 100644 --- a/cocos/dragon-bones/ArmatureDisplay.ts +++ b/cocos/dragon-bones/ArmatureDisplay.ts @@ -591,11 +591,10 @@ export class ArmatureDisplay extends UIRenderer { } private getMaterialTemplate () : Material { - let material = this.customMaterial; - if (material === null) { - material = builtinResMgr.get('default-spine-material'); - } - return material; + if (this.customMaterial !== null) return this.customMaterial; + if (this.material) return this.material; + this.updateMaterial(); + return this.material!; } public getMaterialForBlend (src: BlendFactor, dst: BlendFactor): MaterialInstance { @@ -624,6 +623,12 @@ export class ArmatureDisplay extends UIRenderer { return inst; } + @override + protected _updateBuiltinMaterial (): Material { + const material = builtinResMgr.get('default-spine-material'); + return material; + } + @override @type(Material) @displayOrder(0) @@ -633,11 +638,19 @@ export class ArmatureDisplay extends UIRenderer { } set customMaterial (val) { this._customMaterial = val; - this._cleanMaterialCache(); - this.setMaterial(this._customMaterial, 0); + this.updateMaterial(); this.markForUpdateRenderData(); } + @override + protected updateMaterial () { + let mat; + if (this._customMaterial) mat = this._customMaterial; + else mat = this._updateBuiltinMaterial(); + this.setMaterial(mat, 0); + this._cleanMaterialCache(); + } + protected _render (batcher: Batcher2D) { let indicesCount = 0; if (this.renderData && this._drawList) { diff --git a/cocos/spine/skeleton.ts b/cocos/spine/skeleton.ts index ccb1fa21c4..4c7e70be48 100644 --- a/cocos/spine/skeleton.ts +++ b/cocos/spine/skeleton.ts @@ -160,6 +160,12 @@ export class Skeleton extends UIRenderer { public static AnimationCacheMode = AnimationCacheMode; get drawList () { return this._drawList; } + @override + protected _updateBuiltinMaterial (): Material { + const material = builtinResMgr.get('default-spine-material'); + return material; + } + @override @type(Material) @displayOrder(0) @@ -169,11 +175,19 @@ export class Skeleton extends UIRenderer { } set customMaterial (val) { this._customMaterial = val; - this._cleanMaterialCache(); - this.setMaterial(this._customMaterial, 0); + this.updateMaterial(); this.markForUpdateRenderData(); } + @override + protected updateMaterial () { + let mat; + if (this._customMaterial) mat = this._customMaterial; + else mat = this._updateBuiltinMaterial(); + this.setMaterial(mat, 0); + this._cleanMaterialCache(); + } + /** * @en The skeletal animation is paused? * @zh 该骨骼动画是否暂停。 @@ -1354,11 +1368,10 @@ export class Skeleton extends UIRenderer { } private getMaterialTemplate () : Material { - let material = this.customMaterial; - if (material === null) { - material = builtinResMgr.get('default-spine-material'); - } - return material; + if (this.customMaterial !== null) return this.customMaterial; + if (this.material) return this.material; + this.updateMaterial(); + return this.material!; } public getMaterialForBlendAndTint (src: BlendFactor, dst: BlendFactor, type: SpineMaterialType): MaterialInstance { diff --git a/native/cocos/editor-support/dragonbones-creator-support/CCArmatureCacheDisplay.cpp b/native/cocos/editor-support/dragonbones-creator-support/CCArmatureCacheDisplay.cpp index 12433489ac..b85ae14fc2 100644 --- a/native/cocos/editor-support/dragonbones-creator-support/CCArmatureCacheDisplay.cpp +++ b/native/cocos/editor-support/dragonbones-creator-support/CCArmatureCacheDisplay.cpp @@ -416,6 +416,10 @@ void CCArmatureCacheDisplay::setRenderEntity(cc::RenderEntity* entity) { void CCArmatureCacheDisplay::setMaterial(cc::Material *material) { _material = material; + for (auto &item : _materialCaches) { + CC_SAFE_DELETE(item.second); + } + _materialCaches.clear(); } diff --git a/native/cocos/editor-support/dragonbones-creator-support/CCArmatureDisplay.cpp b/native/cocos/editor-support/dragonbones-creator-support/CCArmatureDisplay.cpp index bdddc56294..572064609e 100644 --- a/native/cocos/editor-support/dragonbones-creator-support/CCArmatureDisplay.cpp +++ b/native/cocos/editor-support/dragonbones-creator-support/CCArmatureDisplay.cpp @@ -419,6 +419,10 @@ void CCArmatureDisplay::setRenderEntity(cc::RenderEntity* entity) { void CCArmatureDisplay::setMaterial(cc::Material *material) { _material = material; + for (auto &item : _materialCaches) { + CC_SAFE_DELETE(item.second); + } + _materialCaches.clear(); } diff --git a/native/cocos/editor-support/spine-creator-support/SkeletonCacheAnimation.cpp b/native/cocos/editor-support/spine-creator-support/SkeletonCacheAnimation.cpp index 22baa05f33..8483d87a2b 100644 --- a/native/cocos/editor-support/spine-creator-support/SkeletonCacheAnimation.cpp +++ b/native/cocos/editor-support/spine-creator-support/SkeletonCacheAnimation.cpp @@ -558,6 +558,10 @@ void SkeletonCacheAnimation::setRenderEntity(cc::RenderEntity* entity) { void SkeletonCacheAnimation::setMaterial(cc::Material *material) { _material = material; + for (auto &item : _materialCaches) { + CC_SAFE_DELETE(item.second); + } + _materialCaches.clear(); } cc::RenderDrawInfo* SkeletonCacheAnimation::requestDrawInfo(int idx) { diff --git a/native/cocos/editor-support/spine-creator-support/SkeletonRenderer.cpp b/native/cocos/editor-support/spine-creator-support/SkeletonRenderer.cpp index 13d519d613..1d86d2975e 100644 --- a/native/cocos/editor-support/spine-creator-support/SkeletonRenderer.cpp +++ b/native/cocos/editor-support/spine-creator-support/SkeletonRenderer.cpp @@ -1005,6 +1005,10 @@ void SkeletonRenderer::setRenderEntity(cc::RenderEntity* entity) { void SkeletonRenderer::setMaterial(cc::Material *material) { _material = material; + for (auto &item : _materialCaches) { + CC_SAFE_DELETE(item.second); + } + _materialCaches.clear(); } cc::RenderDrawInfo* SkeletonRenderer::requestDrawInfo(int idx) { diff --git a/platforms/native/engine/jsb-dragonbones.js b/platforms/native/engine/jsb-dragonbones.js index 40fa60b926..b2e37037ae 100644 --- a/platforms/native/engine/jsb-dragonbones.js +++ b/platforms/native/engine/jsb-dragonbones.js @@ -546,6 +546,15 @@ const cacheManager = require('./jsb-cache-manager'); middleware.release(); }; + const _updateMaterial = armatureDisplayProto.updateMaterial; + armatureDisplayProto.updateMaterial = function () { + _updateMaterial.call(this); + if (this._nativeDisplay) { + const mat = this.getMaterialTemplate(); + this._nativeDisplay.setMaterial(mat); + } + }; + armatureDisplayProto.once = function (eventType, listener, target) { if (this._nativeDisplay) { if (this.isAnimationCached()) { diff --git a/platforms/native/engine/jsb-spine-skeleton.js b/platforms/native/engine/jsb-spine-skeleton.js index 94eaa01705..f3794751d2 100644 --- a/platforms/native/engine/jsb-spine-skeleton.js +++ b/platforms/native/engine/jsb-spine-skeleton.js @@ -258,6 +258,15 @@ const cacheManager = require('./jsb-cache-manager'); }, }); + const _updateMaterial = skeleton.updateMaterial; + skeleton.updateMaterial = function () { + _updateMaterial.call(this); + if (this._nativeSkeleton) { + const mat = this.getMaterialTemplate(); + this._nativeSkeleton.setMaterial(mat); + } + }; + const _updateDebugDraw = skeleton._updateDebugDraw; skeleton._updateDebugDraw = function () { _updateDebugDraw.call(this);