26
26
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THE
27
27
* SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
28
*****************************************************************************/
29
-
30
29
import { TextureAtlas } from "@esotericsoftware/spine-core" ;
31
30
import { SpineTexture } from "../SpineTexture.js" ;
32
31
import type { AssetExtension , Loader } from "@pixi/assets" ;
32
+ import { Assets } from "@pixi/assets" ;
33
33
import { LoaderParserPriority , checkExtension } from "@pixi/assets" ;
34
34
import type { Texture } from "@pixi/core" ;
35
- import { ExtensionType , settings , utils , BaseTexture , extensions } from "@pixi/core" ;
35
+ import { ALPHA_MODES , ExtensionType , settings , utils , BaseTexture , extensions } from "@pixi/core" ;
36
36
37
37
type RawAtlas = string ;
38
38
@@ -77,7 +77,7 @@ const spineTextureAtlasLoader: AssetExtension<RawAtlas | TextureAtlas, ISpineAtl
77
77
basePath += "/" ;
78
78
}
79
79
80
- // Retval is going to be a texture atlas. However we need to wait for it's callback to resolve this promise.
80
+ // Retval is going to be a texture atlas. However, we need to wait for its callback to resolve this promise.
81
81
const retval = new TextureAtlas ( asset ) ;
82
82
83
83
// If the user gave me only one texture, that one is assumed to be the "first" texture in the atlas
@@ -90,6 +90,17 @@ const spineTextureAtlasLoader: AssetExtension<RawAtlas | TextureAtlas, ISpineAtl
90
90
// we will wait for all promises for the textures at the same time at the end.
91
91
const textureLoadingPromises = [ ] ;
92
92
93
+
94
+ // setting preferCreateImageBitmap to false for loadTextures loader to allow loading PMA images
95
+ let oldPreferCreateImageBitmap = true ;
96
+ for ( const parser of loader . parsers ) {
97
+ if ( parser . name == "loadTextures" ) {
98
+ oldPreferCreateImageBitmap = parser . config ?. preferCreateImageBitmap ;
99
+ break ;
100
+ }
101
+ }
102
+ Assets . setPreferences ( { preferCreateImageBitmap : false } ) ;
103
+
93
104
// fill the pages
94
105
for ( const page of retval . pages ) {
95
106
const pageName = page . name ;
@@ -98,15 +109,20 @@ const spineTextureAtlasLoader: AssetExtension<RawAtlas | TextureAtlas, ISpineAtl
98
109
page . setTexture ( SpineTexture . from ( providedPage ) ) ;
99
110
} else {
100
111
const url : string = providedPage ?? utils . path . normalize ( [ ...basePath . split ( utils . path . sep ) , pageName ] . join ( utils . path . sep ) ) ;
101
- const pixiPromise = loader . load < Texture > ( { src : url , data : metadata . imageMetadata } ) . then ( ( texture ) => {
102
- page . setTexture ( SpineTexture . from ( texture . baseTexture ) ) ;
103
- } ) ;
112
+ const assetsToLoadIn = { src : url , data : { ...metadata . imageMetadata , ...{ alphaMode : page . pma ? ALPHA_MODES . PMA : ALPHA_MODES . UNPACK } } } ;
113
+ const pixiPromise = loader . load < Texture > ( assetsToLoadIn )
114
+ . then ( ( texture ) => {
115
+ page . setTexture ( SpineTexture . from ( texture . baseTexture ) ) ;
116
+ } ) ;
104
117
textureLoadingPromises . push ( pixiPromise ) ;
105
118
}
106
119
}
107
120
108
121
await Promise . all ( textureLoadingPromises ) ;
109
122
123
+ // restoring preferCreateImageBitmap old value for loadTextures loader
124
+ Assets . setPreferences ( { preferCreateImageBitmap : oldPreferCreateImageBitmap } ) ;
125
+
110
126
return retval ;
111
127
} ,
112
128
} ,
0 commit comments