Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the issue where dynamic uniform setting for custom materials in Spine is not working. #18012

Merged
merged 4 commits into from
Dec 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading