Skip to content

Commit

Permalink
Fix the issue where dynamic uniform setting for custom materials in S…
Browse files Browse the repository at this point in the history
…pine is not working. (#18012)

* Fix the issue where dynamic uniform setting for custom materials in Spine is not working.
  • Loading branch information
bofeng-song authored Dec 11, 2024
1 parent 35d27d6 commit 83c5c0a
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions cocos/spine/skeleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ export class Skeleton extends UIRenderer {

private _slotTextures: Map<number, Texture2D> | null = null;

private _customMaterialInstance: MaterialInstance | null = null;

_vLength = 0;
_vBuffer: Uint8Array | null = null;
_iLength = 0;
Expand Down Expand Up @@ -636,6 +638,21 @@ export class Skeleton extends UIRenderer {
this.markForUpdateRenderData();
}

get customMaterialInstance (): MaterialInstance | null {
if (!this._customMaterial) {
return null;
}
if (!this._customMaterialInstance) {
const matInfo = {
parent: this._customMaterial,
subModelIdx: 0,
owner: this,
};
this._customMaterialInstance = new MaterialInstance(matInfo);
}
return this._customMaterialInstance;
}

public __preload (): void {
super.__preload();
if (EDITOR_NOT_IN_PREVIEW) {
Expand Down Expand Up @@ -1208,14 +1225,17 @@ export class Skeleton extends UIRenderer {
if (inst) {
return inst;
}

const material = this.getMaterialTemplate();
const matInfo = {
parent: material,
subModelIdx: 0,
owner: this,
};
inst = new MaterialInstance(matInfo);
if (this._customMaterialInstance) {
inst = this._customMaterialInstance;
} else {
const material = this.getMaterialTemplate();
const matInfo = {
parent: material,
subModelIdx: 0,
owner: this,
};
inst = new MaterialInstance(matInfo);
}
this._materialCache[key] = inst;
inst.overridePipelineStates({
blendState: {
Expand Down

0 comments on commit 83c5c0a

Please sign in to comment.