mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[pixi] Clean-up and improvements.
This commit is contained in:
parent
7698f5fc92
commit
8fb691c054
@ -341,6 +341,11 @@ cp -f ../spineboy/export/spineboy-pro.skel "$ROOT/spine-ts/spine-player/example/
|
||||
cp -f ../spineboy/export/spineboy-pma.atlas "$ROOT/spine-ts/spine-player/example/assets/"
|
||||
cp -f ../spineboy/export/spineboy-pma.png "$ROOT/spine-ts/spine-player/example/assets/"
|
||||
|
||||
cp -f ../spineboy/export/spineboy-pro.json "$ROOT/spine-ts/spine-pixi/example/assets/"
|
||||
cp -f ../spineboy/export/spineboy-pro.skel "$ROOT/spine-ts/spine-pixi/example/assets/"
|
||||
cp -f ../spineboy/export/spineboy.atlas "$ROOT/spine-ts/spine-pixi/example/assets/"
|
||||
cp -f ../spineboy/export/spineboy.png "$ROOT/spine-ts/spine-pixi/example/assets/"
|
||||
|
||||
rm "$ROOT/spine-ts/spine-phaser/example/assets/"*
|
||||
cp -f ../raptor/export/raptor-pro.json "$ROOT/spine-ts/spine-phaser/example/assets/"
|
||||
cp -f ../raptor/export/raptor-pma.atlas "$ROOT/spine-ts/spine-phaser/example/assets/"
|
||||
|
||||
@ -54,7 +54,7 @@
|
||||
]);
|
||||
|
||||
// Create the spine display object
|
||||
const spineBoy = spine.Spine.from("spineboySkeletonJson", "spineboyAtlasPolypack", { scale: 0.5 });
|
||||
const spineBoy = spine.Spine.from("spineboySkeletonJson", "spineboyAtlas", { scale: 0.5 });
|
||||
|
||||
// .from(...) is a shortcut + cache for creating the skeleton data at a certain scale
|
||||
// Here would be the "long way" of doing it (without cache):
|
||||
|
||||
@ -24,7 +24,6 @@ import type { IDestroyOptions, DisplayObject } from "@pixi/display";
|
||||
import { Container } from "@pixi/display";
|
||||
|
||||
export interface ISpineOptions {
|
||||
removeUnusedSlots?: boolean;
|
||||
autoUpdate?: boolean;
|
||||
slotMeshFactory?: () => ISlotMesh;
|
||||
}
|
||||
@ -56,8 +55,6 @@ export class Spine extends Container {
|
||||
this._debug = value;
|
||||
}
|
||||
|
||||
// Each slot is a pixi mesh, by default we just visible=false the ones we don't need. This forces a removeChild and addChild every time we need to show a slot.
|
||||
public removeUnusedSlots: boolean;
|
||||
protected slotMeshFactory: () => ISlotMesh;
|
||||
|
||||
private autoUpdateWarned: boolean = false;
|
||||
@ -94,7 +91,6 @@ export class Spine extends Container {
|
||||
this.skeleton = new Skeleton(skeletonData);
|
||||
const animData = new AnimationStateData(skeletonData);
|
||||
this.state = new AnimationState(animData);
|
||||
this.removeUnusedSlots = options?.removeUnusedSlots ?? false;
|
||||
this.autoUpdate = options?.autoUpdate ?? true;
|
||||
this.slotMeshFactory = options?.slotMeshFactory ?? ((): ISlotMesh => new SlotMesh());
|
||||
|
||||
@ -154,11 +150,8 @@ export class Spine extends Container {
|
||||
super.destroy(options);
|
||||
}
|
||||
|
||||
private recycleMeshes(): void {
|
||||
private resetMeshes (): void {
|
||||
for (const [, mesh] of this.meshesCache) {
|
||||
if (this.removeUnusedSlots) {
|
||||
mesh.parent?.removeChild(mesh);
|
||||
}
|
||||
mesh.zIndex = -1;
|
||||
mesh.visible = false;
|
||||
}
|
||||
@ -175,10 +168,6 @@ export class Spine extends Container {
|
||||
return mesh;
|
||||
} else {
|
||||
let mesh = this.meshesCache.get(slot)!;
|
||||
|
||||
if (this.removeUnusedSlots) {
|
||||
this.addChild(mesh);
|
||||
}
|
||||
mesh.visible = true;
|
||||
return mesh;
|
||||
}
|
||||
@ -187,7 +176,7 @@ export class Spine extends Container {
|
||||
private verticesCache: NumberArrayLike = Utils.newFloatArray(1024);
|
||||
|
||||
private updateGeometry (): void {
|
||||
this.recycleMeshes();
|
||||
this.resetMeshes();
|
||||
|
||||
let triangles: Array<number> | null = null;
|
||||
let uvs: NumberArrayLike | null = null;
|
||||
@ -304,28 +293,17 @@ export class Spine extends Container {
|
||||
const boneAux = bone;
|
||||
if (typeof bone === "string") {
|
||||
bone = this.skeleton.findBone(bone)!;
|
||||
this.skeleton.findBone;
|
||||
this.skeleton.findIkConstraint;
|
||||
this.skeleton.findPathConstraint;
|
||||
this.skeleton.findSlot;
|
||||
this.skeleton.findTransformConstraint;
|
||||
}
|
||||
|
||||
if (!bone) {
|
||||
console.error(`Cant set bone position! Bone ${String(boneAux)} not found`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!bone) throw Error(`Cant set bone position, bone ${String(boneAux)} not found`);
|
||||
Spine.vectorAux.set(position.x, position.y);
|
||||
|
||||
if (bone.parent)
|
||||
{
|
||||
if (bone.parent) {
|
||||
const aux = bone.parent.worldToLocal(Spine.vectorAux);
|
||||
bone.x = aux.x;
|
||||
bone.y = aux.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
bone.x = Spine.vectorAux.x;
|
||||
bone.y = Spine.vectorAux.y;
|
||||
}
|
||||
@ -335,11 +313,6 @@ export class Spine extends Container {
|
||||
const boneAux = bone;
|
||||
if (typeof bone === "string") {
|
||||
bone = this.skeleton.findBone(bone)!;
|
||||
this.skeleton.findBone;
|
||||
this.skeleton.findIkConstraint;
|
||||
this.skeleton.findPathConstraint;
|
||||
this.skeleton.findSlot;
|
||||
this.skeleton.findTransformConstraint;
|
||||
}
|
||||
|
||||
if (!bone) {
|
||||
@ -360,32 +333,17 @@ export class Spine extends Container {
|
||||
|
||||
public static from (skeletonAssetName: string, atlasAssetName: string, options?: ISpineOptions & { scale?: number }): Spine {
|
||||
const cacheKey = `${skeletonAssetName}-${atlasAssetName}-${options?.scale ?? 1}`;
|
||||
|
||||
let skeletonData = Spine.skeletonCache[cacheKey];
|
||||
if (skeletonData) {
|
||||
return new Spine(skeletonData, options);
|
||||
}
|
||||
|
||||
const skeletonAsset = Assets.get<any | Uint8Array>(skeletonAssetName);
|
||||
|
||||
const atlasAsset = Assets.get<TextureAtlas>(atlasAssetName);
|
||||
|
||||
// If you want a custom attachment laoder, you don't use .from(...)
|
||||
const attachmentLoader = new AtlasAttachmentLoader(atlasAsset);
|
||||
|
||||
// What parser do we need?
|
||||
let parser: SkeletonBinary | SkeletonJson;
|
||||
if (skeletonAsset instanceof Uint8Array) {
|
||||
parser = new SkeletonBinary(attachmentLoader);
|
||||
} else {
|
||||
parser = new SkeletonJson(attachmentLoader);
|
||||
}
|
||||
let parser = skeletonAsset instanceof Uint8Array ? new SkeletonBinary(attachmentLoader) : new SkeletonJson(attachmentLoader);
|
||||
parser.scale = options?.scale ?? 1;
|
||||
|
||||
skeletonData = parser.readSkeletonData(skeletonAsset);
|
||||
|
||||
Spine.skeletonCache[cacheKey] = skeletonData;
|
||||
|
||||
return new this(skeletonData, options);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user