Skip to content

Commit 098fc08

Browse files
committed
[ts][pixi] DarkTint renderer is registered by the runtime. DarkTintMesh is automatically used if a slot has dark color.
1 parent 126a8f0 commit 098fc08

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

spine-ts/spine-pixi/src/Spine.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import {
4646
} from "@esotericsoftware/spine-core";
4747
import type { SpineTexture } from "./SpineTexture.js";
4848
import { SlotMesh } from "./SlotMesh.js";
49+
import { DarkSlotMesh } from "./DarkSlotMesh.js";
4950
import type { ISpineDebugRenderer } from "./SpineDebugRenderer.js";
5051
import { Assets } from "@pixi/assets";
5152
import type { IPointData } from "@pixi/core";
@@ -85,7 +86,7 @@ export class Spine extends Container {
8586
this._debug = value;
8687
}
8788

88-
protected slotMeshFactory: () => ISlotMesh;
89+
protected slotMeshFactory: () => ISlotMesh = ((): ISlotMesh => new SlotMesh());
8990

9091
private autoUpdateWarned: boolean = false;
9192
private _autoUpdate: boolean = true;
@@ -122,11 +123,24 @@ export class Spine extends Container {
122123
const animData = new AnimationStateData(skeletonData);
123124
this.state = new AnimationState(animData);
124125
this.autoUpdate = options?.autoUpdate ?? true;
125-
this.slotMeshFactory = options?.slotMeshFactory ?? ((): ISlotMesh => new SlotMesh());
126+
this.initializeMeshFactory(options);
126127
this.skeleton.setToSetupPose();
127128
this.skeleton.updateWorldTransform(Physics.update);
128129
}
129130

131+
private initializeMeshFactory(options?: ISpineOptions) {
132+
if (options?.slotMeshFactory) {
133+
this.slotMeshFactory = options?.slotMeshFactory;
134+
} else {
135+
for (let i = 0; i < this.skeleton.slots.length; i++) {
136+
if (this.skeleton.slots[i].data.darkColor) {
137+
this.slotMeshFactory = options?.slotMeshFactory ?? ((): ISlotMesh => new DarkSlotMesh());
138+
break;
139+
}
140+
}
141+
}
142+
}
143+
130144
public update (deltaSeconds: number): void {
131145
if (this.autoUpdate && !this.autoUpdateWarned) {
132146
console.warn("You are calling update on a Spine instance that has autoUpdate set to true. This is probably not what you want.");

spine-ts/spine-pixi/src/darkTintMesh/DarkTintRenderer.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import type { IDarkTintElement } from "./DarkTintMesh.js";
3131
import { DarkTintBatchGeometry } from "./DarkTintBatchGeom.js";
3232
import type { ExtensionMetadata, Renderer, ViewableBuffer } from "@pixi/core";
33-
import { BatchRenderer, ExtensionType, BatchShaderGenerator, Color } from "@pixi/core";
33+
import { extensions, BatchRenderer, ExtensionType, BatchShaderGenerator, Color } from "@pixi/core";
3434

3535
const vertex = `
3636
precision highp float;
@@ -117,3 +117,5 @@ export class DarkTintRenderer extends BatchRenderer {
117117
}
118118
}
119119
}
120+
121+
extensions.add(DarkTintRenderer);

0 commit comments

Comments
 (0)