mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 17:56:04 +08:00
[ts][pixi] DarkTint renderer is registered by the runtime. DarkTintMesh is automatically used if a slot has dark color.
This commit is contained in:
parent
126a8f02aa
commit
098fc0847a
@ -46,6 +46,7 @@ import {
|
|||||||
} from "@esotericsoftware/spine-core";
|
} from "@esotericsoftware/spine-core";
|
||||||
import type { SpineTexture } from "./SpineTexture.js";
|
import type { SpineTexture } from "./SpineTexture.js";
|
||||||
import { SlotMesh } from "./SlotMesh.js";
|
import { SlotMesh } from "./SlotMesh.js";
|
||||||
|
import { DarkSlotMesh } from "./DarkSlotMesh.js";
|
||||||
import type { ISpineDebugRenderer } from "./SpineDebugRenderer.js";
|
import type { ISpineDebugRenderer } from "./SpineDebugRenderer.js";
|
||||||
import { Assets } from "@pixi/assets";
|
import { Assets } from "@pixi/assets";
|
||||||
import type { IPointData } from "@pixi/core";
|
import type { IPointData } from "@pixi/core";
|
||||||
@ -85,7 +86,7 @@ export class Spine extends Container {
|
|||||||
this._debug = value;
|
this._debug = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected slotMeshFactory: () => ISlotMesh;
|
protected slotMeshFactory: () => ISlotMesh = ((): ISlotMesh => new SlotMesh());
|
||||||
|
|
||||||
private autoUpdateWarned: boolean = false;
|
private autoUpdateWarned: boolean = false;
|
||||||
private _autoUpdate: boolean = true;
|
private _autoUpdate: boolean = true;
|
||||||
@ -122,11 +123,24 @@ export class Spine extends Container {
|
|||||||
const animData = new AnimationStateData(skeletonData);
|
const animData = new AnimationStateData(skeletonData);
|
||||||
this.state = new AnimationState(animData);
|
this.state = new AnimationState(animData);
|
||||||
this.autoUpdate = options?.autoUpdate ?? true;
|
this.autoUpdate = options?.autoUpdate ?? true;
|
||||||
this.slotMeshFactory = options?.slotMeshFactory ?? ((): ISlotMesh => new SlotMesh());
|
this.initializeMeshFactory(options);
|
||||||
this.skeleton.setToSetupPose();
|
this.skeleton.setToSetupPose();
|
||||||
this.skeleton.updateWorldTransform(Physics.update);
|
this.skeleton.updateWorldTransform(Physics.update);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private initializeMeshFactory(options?: ISpineOptions) {
|
||||||
|
if (options?.slotMeshFactory) {
|
||||||
|
this.slotMeshFactory = options?.slotMeshFactory;
|
||||||
|
} else {
|
||||||
|
for (let i = 0; i < this.skeleton.slots.length; i++) {
|
||||||
|
if (this.skeleton.slots[i].data.darkColor) {
|
||||||
|
this.slotMeshFactory = options?.slotMeshFactory ?? ((): ISlotMesh => new DarkSlotMesh());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public update (deltaSeconds: number): void {
|
public update (deltaSeconds: number): void {
|
||||||
if (this.autoUpdate && !this.autoUpdateWarned) {
|
if (this.autoUpdate && !this.autoUpdateWarned) {
|
||||||
console.warn("You are calling update on a Spine instance that has autoUpdate set to true. This is probably not what you want.");
|
console.warn("You are calling update on a Spine instance that has autoUpdate set to true. This is probably not what you want.");
|
||||||
|
|||||||
@ -30,7 +30,7 @@
|
|||||||
import type { IDarkTintElement } from "./DarkTintMesh.js";
|
import type { IDarkTintElement } from "./DarkTintMesh.js";
|
||||||
import { DarkTintBatchGeometry } from "./DarkTintBatchGeom.js";
|
import { DarkTintBatchGeometry } from "./DarkTintBatchGeom.js";
|
||||||
import type { ExtensionMetadata, Renderer, ViewableBuffer } from "@pixi/core";
|
import type { ExtensionMetadata, Renderer, ViewableBuffer } from "@pixi/core";
|
||||||
import { BatchRenderer, ExtensionType, BatchShaderGenerator, Color } from "@pixi/core";
|
import { extensions, BatchRenderer, ExtensionType, BatchShaderGenerator, Color } from "@pixi/core";
|
||||||
|
|
||||||
const vertex = `
|
const vertex = `
|
||||||
precision highp float;
|
precision highp float;
|
||||||
@ -117,3 +117,5 @@ export class DarkTintRenderer extends BatchRenderer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extensions.add(DarkTintRenderer);
|
||||||
Loading…
x
Reference in New Issue
Block a user