@@ -46,6 +46,7 @@ import {
46
46
} from "@esotericsoftware/spine-core" ;
47
47
import type { SpineTexture } from "./SpineTexture.js" ;
48
48
import { SlotMesh } from "./SlotMesh.js" ;
49
+ import { DarkSlotMesh } from "./DarkSlotMesh.js" ;
49
50
import type { ISpineDebugRenderer } from "./SpineDebugRenderer.js" ;
50
51
import { Assets } from "@pixi/assets" ;
51
52
import type { IPointData } from "@pixi/core" ;
@@ -85,7 +86,7 @@ export class Spine extends Container {
85
86
this . _debug = value ;
86
87
}
87
88
88
- protected slotMeshFactory : ( ) => ISlotMesh ;
89
+ protected slotMeshFactory : ( ) => ISlotMesh = ( ( ) : ISlotMesh => new SlotMesh ( ) ) ;
89
90
90
91
private autoUpdateWarned : boolean = false ;
91
92
private _autoUpdate : boolean = true ;
@@ -122,11 +123,24 @@ export class Spine extends Container {
122
123
const animData = new AnimationStateData ( skeletonData ) ;
123
124
this . state = new AnimationState ( animData ) ;
124
125
this . autoUpdate = options ?. autoUpdate ?? true ;
125
- this . slotMeshFactory = options ?. slotMeshFactory ?? ( ( ) : ISlotMesh => new SlotMesh ( ) ) ;
126
+ this . initializeMeshFactory ( options ) ;
126
127
this . skeleton . setToSetupPose ( ) ;
127
128
this . skeleton . updateWorldTransform ( Physics . update ) ;
128
129
}
129
130
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
+
130
144
public update ( deltaSeconds : number ) : void {
131
145
if ( this . autoUpdate && ! this . autoUpdateWarned ) {
132
146
console . warn ( "You are calling update on a Spine instance that has autoUpdate set to true. This is probably not what you want." ) ;
0 commit comments