[ts][pixi] Fix atlas src cannot be resolved for preferred texture

This commit is contained in:
Richard Fu 2024-09-04 18:19:20 +10:00 committed by Davide
parent eb247bbfa2
commit 167470fb16
17 changed files with 666 additions and 1 deletions

View File

@ -53,6 +53,7 @@
<li><a href="/spine-pixi/example/physics3.html">Physics III</a></li>
<li><a href="/spine-pixi/example/physics4.html">Physics IV</a></li>
<li><a href="/spine-pixi/example/slot-objects.html">Slot Objects</a></li>
<li><a href="/spine-pixi/example/assets-bundle.html">Assets Bundle</a></li>
</ul>
<li>Phaser</li>
<ul>

View File

@ -0,0 +1,57 @@
<html>
<head>
<meta charset="UTF-8" />
<title>spine-pixi</title>
<script src="https://cdn.jsdelivr.net/npm/pixi.js@7.4.2/dist/pixi.min.js"></script>
<script src="../dist/iife/spine-pixi.js"></script>
<script src="https://cdn.jsdelivr.net/npm/tweakpane@3.1.9/dist/tweakpane.min.js"></script>
<link rel="stylesheet" href="../../index.css">
</head>
<body>
<script>
(async function () {
var app = new PIXI.Application({
width: window.innerWidth,
height: window.innerHeight,
resolution: window.devicePixelRatio || 1,
autoDensity: true,
resizeTo: window,
backgroundColor: 0x2c3e50,
hello: true,
});
document.body.appendChild(app.view);
// Initialize Assets with given manifest and preference
await PIXI.Assets.init({
basePath: './assets/spineboy-bundle',
manifest: './manifest.json',
texturePreference: {
resolution: Math.min(PIXI.utils.isMobile.any ? window.devicePixelRatio : 3, 3), // Set the preferred resolution to 3 for desktop, or devicePixelRatio for mobile; Pixi.Assets will load the corresponding asset if found
format: ['webp', 'png'], // Prefer WEBP, then fallback to PNG if the device doesn't support it
},
});
// Load the bundle that includes the skeleton data and atlas
await PIXI.Assets.loadBundle("spineboy");
// Create the spine display object
const spineboy = spine.Spine.from("spineboyData", "spineboyAtlas");
// Set the default mix time to use when transitioning
// from one animation to the next.
spineboy.state.data.defaultMix = 0.2;
// Center the spine object on screen.
spineboy.x = window.innerWidth / 2;
spineboy.y = window.innerHeight / 2 + spineboy.getBounds().height / 2;
// Set animation "run" on track 0, looped.
spineboy.state.setAnimation(0, "run", true);
// Add the display object to the stage.
app.stage.addChild(spineboy);
})();
</script>
</body>
</html>

View File

@ -0,0 +1,30 @@
{
"bundles": [
{
"name": "spineboy",
"assets": [
{
"alias": [
"spineboyAtlas"
],
"src": [
"spineboy.png.atlas",
"spineboy@2x.png.atlas",
"spineboy@3x.png.atlas",
"spineboy.webp.atlas",
"spineboy@2x.webp.atlas",
"spineboy@3x.webp.atlas"
]
},
{
"alias": [
"spineboyData"
],
"src": [
"spineboy-pro.json"
]
}
]
}
]
}

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View File

@ -0,0 +1,94 @@
spineboy.png
size: 341, 85
filter: Linear, Linear
scale: 0.16666666666666666
crosshair
bounds: 117, 2, 15, 15
eye-indifferent
bounds: 287, 35, 15, 15
eye-surprised
bounds: 168, 26, 15, 15
front-bracer
bounds: 275, 22, 9, 13
front-fist-closed
bounds: 262, 21, 12, 13
front-fist-open
bounds: 236, 17, 14, 14
rotate: 90
front-foot
bounds: 70, 2, 21, 11
front-shin
bounds: 221, 42, 13, 30
rotate: 90
front-thigh
bounds: 0, 0, 7, 18
rotate: 90
front-upper-arm
bounds: 83, 68, 7, 16
goggles
bounds: 221, 57, 43, 27
gun
bounds: 266, 50, 35, 34
head
bounds: 0, 9, 45, 49
hoverboard-board
bounds: 0, 59, 82, 25
hoverboard-thruster
bounds: 240, 32, 10, 10
rotate: 90
hoverglow-small
bounds: 91, 27, 45, 12
mouth-grind
bounds: 204, 32, 15, 10
mouth-oooo
bounds: 204, 21, 15, 10
mouth-smile
bounds: 220, 21, 15, 10
muzzle-glow
bounds: 127, 18, 8, 8
muzzle-ring
bounds: 91, 18, 8, 35
rotate: 90
muzzle01
bounds: 303, 31, 22, 13
rotate: 90
muzzle02
bounds: 264, 36, 22, 14
muzzle03
bounds: 318, 57, 27, 17
rotate: 90
muzzle04
bounds: 91, 2, 25, 15
muzzle05
bounds: 46, 1, 22, 12
neck
bounds: 83, 60, 6, 7
portal-bg
bounds: 46, 14, 44, 44
portal-flare1
bounds: 184, 21, 18, 10
portal-flare2
bounds: 253, 37, 19, 10
rotate: 90
portal-flare3
bounds: 184, 32, 19, 10
portal-shade
bounds: 91, 40, 44, 44
portal-streaks1
bounds: 136, 42, 42, 42
portal-streaks2
bounds: 179, 43, 41, 41
rear-bracer
bounds: 285, 22, 9, 12
rear-foot
bounds: 221, 32, 19, 10
rear-shin
bounds: 138, 28, 12, 29
rotate: 90
rear-thigh
bounds: 252, 21, 9, 15
rear-upper-arm
bounds: 20, 1, 6, 14
rotate: 90
torso
bounds: 301, 54, 16, 30

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View File

@ -0,0 +1,94 @@
spineboy.webp
size: 341, 85
filter: Linear, Linear
scale: 0.16666666666666666
crosshair
bounds: 117, 2, 15, 15
eye-indifferent
bounds: 287, 35, 15, 15
eye-surprised
bounds: 168, 26, 15, 15
front-bracer
bounds: 275, 22, 9, 13
front-fist-closed
bounds: 262, 21, 12, 13
front-fist-open
bounds: 236, 17, 14, 14
rotate: 90
front-foot
bounds: 70, 2, 21, 11
front-shin
bounds: 221, 42, 13, 30
rotate: 90
front-thigh
bounds: 0, 0, 7, 18
rotate: 90
front-upper-arm
bounds: 83, 68, 7, 16
goggles
bounds: 221, 57, 43, 27
gun
bounds: 266, 50, 35, 34
head
bounds: 0, 9, 45, 49
hoverboard-board
bounds: 0, 59, 82, 25
hoverboard-thruster
bounds: 240, 32, 10, 10
rotate: 90
hoverglow-small
bounds: 91, 27, 45, 12
mouth-grind
bounds: 204, 32, 15, 10
mouth-oooo
bounds: 204, 21, 15, 10
mouth-smile
bounds: 220, 21, 15, 10
muzzle-glow
bounds: 127, 18, 8, 8
muzzle-ring
bounds: 91, 18, 8, 35
rotate: 90
muzzle01
bounds: 303, 31, 22, 13
rotate: 90
muzzle02
bounds: 264, 36, 22, 14
muzzle03
bounds: 318, 57, 27, 17
rotate: 90
muzzle04
bounds: 91, 2, 25, 15
muzzle05
bounds: 46, 1, 22, 12
neck
bounds: 83, 60, 6, 7
portal-bg
bounds: 46, 14, 44, 44
portal-flare1
bounds: 184, 21, 18, 10
portal-flare2
bounds: 253, 37, 19, 10
rotate: 90
portal-flare3
bounds: 184, 32, 19, 10
portal-shade
bounds: 91, 40, 44, 44
portal-streaks1
bounds: 136, 42, 42, 42
portal-streaks2
bounds: 179, 43, 41, 41
rear-bracer
bounds: 285, 22, 9, 12
rear-foot
bounds: 221, 32, 19, 10
rear-shin
bounds: 138, 28, 12, 29
rotate: 90
rear-thigh
bounds: 252, 21, 9, 15
rear-upper-arm
bounds: 20, 1, 6, 14
rotate: 90
torso
bounds: 301, 54, 16, 30

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

View File

@ -0,0 +1,94 @@
spineboy@2x.png
size: 682, 170
filter: Linear, Linear
scale: 0.3333333333333333
crosshair
bounds: 234, 4, 30, 30
eye-indifferent
bounds: 574, 70, 31, 30
eye-surprised
bounds: 336, 52, 31, 30
front-bracer
bounds: 550, 44, 19, 26
front-fist-closed
bounds: 524, 43, 25, 27
front-fist-open
bounds: 473, 34, 28, 29
rotate: 90
front-foot
bounds: 140, 4, 42, 23
front-shin
bounds: 443, 85, 27, 61
rotate: 90
front-thigh
bounds: 1, 1, 15, 37
rotate: 90
front-upper-arm
bounds: 166, 136, 15, 32
goggles
bounds: 443, 114, 87, 55
gun
bounds: 532, 101, 70, 68
head
bounds: 1, 18, 90, 99
hoverboard-board
bounds: 1, 118, 164, 50
hoverboard-thruster
bounds: 481, 64, 20, 21
rotate: 90
hoverglow-small
bounds: 183, 54, 91, 25
mouth-grind
bounds: 409, 64, 31, 20
mouth-oooo
bounds: 408, 43, 31, 20
mouth-smile
bounds: 440, 42, 31, 20
muzzle-glow
bounds: 254, 36, 16, 16
muzzle-ring
bounds: 183, 36, 16, 70
rotate: 90
muzzle01
bounds: 607, 63, 44, 26
rotate: 90
muzzle02
bounds: 528, 72, 45, 28
muzzle03
bounds: 637, 114, 55, 35
rotate: 90
muzzle04
bounds: 183, 4, 50, 30
muzzle05
bounds: 93, 2, 45, 25
neck
bounds: 166, 121, 12, 14
portal-bg
bounds: 93, 28, 88, 88
portal-flare1
bounds: 369, 43, 37, 20
portal-flare2
bounds: 506, 74, 38, 20
rotate: 90
portal-flare3
bounds: 369, 64, 38, 20
portal-shade
bounds: 183, 80, 88, 88
portal-streaks1
bounds: 273, 84, 84, 85
portal-streaks2
bounds: 358, 86, 83, 83
rear-bracer
bounds: 571, 44, 18, 24
rear-foot
bounds: 442, 64, 38, 20
rear-shin
bounds: 276, 57, 25, 59
rotate: 90
rear-thigh
bounds: 504, 42, 18, 31
rear-upper-arm
bounds: 40, 3, 13, 29
rotate: 90
torso
bounds: 603, 109, 32, 60

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

View File

@ -0,0 +1,94 @@
spineboy@2x.webp
size: 682, 170
filter: Linear, Linear
scale: 0.3333333333333333
crosshair
bounds: 234, 4, 30, 30
eye-indifferent
bounds: 574, 70, 31, 30
eye-surprised
bounds: 336, 52, 31, 30
front-bracer
bounds: 550, 44, 19, 26
front-fist-closed
bounds: 524, 43, 25, 27
front-fist-open
bounds: 473, 34, 28, 29
rotate: 90
front-foot
bounds: 140, 4, 42, 23
front-shin
bounds: 443, 85, 27, 61
rotate: 90
front-thigh
bounds: 1, 1, 15, 37
rotate: 90
front-upper-arm
bounds: 166, 136, 15, 32
goggles
bounds: 443, 114, 87, 55
gun
bounds: 532, 101, 70, 68
head
bounds: 1, 18, 90, 99
hoverboard-board
bounds: 1, 118, 164, 50
hoverboard-thruster
bounds: 481, 64, 20, 21
rotate: 90
hoverglow-small
bounds: 183, 54, 91, 25
mouth-grind
bounds: 409, 64, 31, 20
mouth-oooo
bounds: 408, 43, 31, 20
mouth-smile
bounds: 440, 42, 31, 20
muzzle-glow
bounds: 254, 36, 16, 16
muzzle-ring
bounds: 183, 36, 16, 70
rotate: 90
muzzle01
bounds: 607, 63, 44, 26
rotate: 90
muzzle02
bounds: 528, 72, 45, 28
muzzle03
bounds: 637, 114, 55, 35
rotate: 90
muzzle04
bounds: 183, 4, 50, 30
muzzle05
bounds: 93, 2, 45, 25
neck
bounds: 166, 121, 12, 14
portal-bg
bounds: 93, 28, 88, 88
portal-flare1
bounds: 369, 43, 37, 20
portal-flare2
bounds: 506, 74, 38, 20
rotate: 90
portal-flare3
bounds: 369, 64, 38, 20
portal-shade
bounds: 183, 80, 88, 88
portal-streaks1
bounds: 273, 84, 84, 85
portal-streaks2
bounds: 358, 86, 83, 83
rear-bracer
bounds: 571, 44, 18, 24
rear-foot
bounds: 442, 64, 38, 20
rear-shin
bounds: 276, 57, 25, 59
rotate: 90
rear-thigh
bounds: 504, 42, 18, 31
rear-upper-arm
bounds: 40, 3, 13, 29
rotate: 90
torso
bounds: 603, 109, 32, 60

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

View File

@ -0,0 +1,94 @@
spineboy@3x.png
size: 1024, 256
filter: Linear, Linear
scale: 0.5
crosshair
bounds: 352, 7, 45, 45
eye-indifferent
bounds: 862, 105, 47, 45
eye-surprised
bounds: 505, 79, 47, 45
front-bracer
bounds: 826, 66, 29, 40
front-fist-closed
bounds: 786, 65, 38, 41
front-fist-open
bounds: 710, 51, 43, 44
rotate: 90
front-foot
bounds: 210, 6, 63, 35
front-shin
bounds: 665, 128, 41, 92
rotate: 90
front-thigh
bounds: 2, 2, 23, 56
rotate: 90
front-upper-arm
bounds: 250, 205, 23, 49
goggles
bounds: 665, 171, 131, 83
gun
bounds: 798, 152, 105, 102
head
bounds: 2, 27, 136, 149
hoverboard-board
bounds: 2, 178, 246, 76
hoverboard-thruster
bounds: 722, 96, 30, 32
rotate: 90
hoverglow-small
bounds: 275, 81, 137, 38
mouth-grind
bounds: 614, 97, 47, 30
mouth-oooo
bounds: 612, 65, 47, 30
mouth-smile
bounds: 661, 64, 47, 30
muzzle-glow
bounds: 382, 54, 25, 25
muzzle-ring
bounds: 275, 54, 25, 105
rotate: 90
muzzle01
bounds: 911, 95, 67, 40
rotate: 90
muzzle02
bounds: 792, 108, 68, 42
muzzle03
bounds: 956, 171, 83, 53
rotate: 90
muzzle04
bounds: 275, 7, 75, 45
muzzle05
bounds: 140, 3, 68, 38
neck
bounds: 250, 182, 18, 21
portal-bg
bounds: 140, 43, 133, 133
portal-flare1
bounds: 554, 65, 56, 30
portal-flare2
bounds: 759, 112, 57, 31
rotate: 90
portal-flare3
bounds: 554, 97, 58, 30
portal-shade
bounds: 275, 121, 133, 133
portal-streaks1
bounds: 410, 126, 126, 128
portal-streaks2
bounds: 538, 129, 125, 125
rear-bracer
bounds: 857, 67, 28, 36
rear-foot
bounds: 663, 96, 57, 30
rear-shin
bounds: 414, 86, 38, 89
rotate: 90
rear-thigh
bounds: 756, 63, 28, 47
rear-upper-arm
bounds: 60, 5, 20, 44
rotate: 90
torso
bounds: 905, 164, 49, 90

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

View File

@ -0,0 +1,94 @@
spineboy@3x.webp
size: 1024, 256
filter: Linear, Linear
scale: 0.5
crosshair
bounds: 352, 7, 45, 45
eye-indifferent
bounds: 862, 105, 47, 45
eye-surprised
bounds: 505, 79, 47, 45
front-bracer
bounds: 826, 66, 29, 40
front-fist-closed
bounds: 786, 65, 38, 41
front-fist-open
bounds: 710, 51, 43, 44
rotate: 90
front-foot
bounds: 210, 6, 63, 35
front-shin
bounds: 665, 128, 41, 92
rotate: 90
front-thigh
bounds: 2, 2, 23, 56
rotate: 90
front-upper-arm
bounds: 250, 205, 23, 49
goggles
bounds: 665, 171, 131, 83
gun
bounds: 798, 152, 105, 102
head
bounds: 2, 27, 136, 149
hoverboard-board
bounds: 2, 178, 246, 76
hoverboard-thruster
bounds: 722, 96, 30, 32
rotate: 90
hoverglow-small
bounds: 275, 81, 137, 38
mouth-grind
bounds: 614, 97, 47, 30
mouth-oooo
bounds: 612, 65, 47, 30
mouth-smile
bounds: 661, 64, 47, 30
muzzle-glow
bounds: 382, 54, 25, 25
muzzle-ring
bounds: 275, 54, 25, 105
rotate: 90
muzzle01
bounds: 911, 95, 67, 40
rotate: 90
muzzle02
bounds: 792, 108, 68, 42
muzzle03
bounds: 956, 171, 83, 53
rotate: 90
muzzle04
bounds: 275, 7, 75, 45
muzzle05
bounds: 140, 3, 68, 38
neck
bounds: 250, 182, 18, 21
portal-bg
bounds: 140, 43, 133, 133
portal-flare1
bounds: 554, 65, 56, 30
portal-flare2
bounds: 759, 112, 57, 31
rotate: 90
portal-flare3
bounds: 554, 97, 58, 30
portal-shade
bounds: 275, 121, 133, 133
portal-streaks1
bounds: 410, 126, 126, 128
portal-streaks2
bounds: 538, 129, 125, 125
rear-bracer
bounds: 857, 67, 28, 36
rear-foot
bounds: 663, 96, 57, 30
rear-shin
bounds: 414, 86, 38, 89
rotate: 90
rear-thigh
bounds: 756, 63, 28, 47
rear-upper-arm
bounds: 60, 5, 20, 44
rotate: 90
torso
bounds: 905, 164, 49, 90

View File

@ -28,7 +28,7 @@
*****************************************************************************/
import { TextureAtlas } from "@esotericsoftware/spine-core";
import { SpineTexture } from "../SpineTexture.js";
import type { AssetExtension, Loader } from "@pixi/assets";
import type { AssetExtension, Loader, UnresolvedAsset } from "@pixi/assets";
import { Assets } from "@pixi/assets";
import { LoaderParserPriority, checkExtension } from "@pixi/assets";
import type { Texture } from "@pixi/core";
@ -39,6 +39,18 @@ type RawAtlas = string;
const spineTextureAtlasLoader: AssetExtension<RawAtlas | TextureAtlas, ISpineAtlasMetadata> = {
extension: ExtensionType.Asset,
resolver: {
test: (value: string): boolean => checkExtension(value, ".atlas"),
parse: (value: string): UnresolvedAsset => {
const split = value.split('.');
return {
resolution: parseFloat(settings.RETINA_PREFIX?.exec(value)?.[1] ?? '1'),
format: split[split.length - 2],
src: value,
};
},
},
loader: {
extension: {
type: ExtensionType.LoadParser,