Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' of https://github.com/pixijs/spine-v8
Browse files Browse the repository at this point in the history
  • Loading branch information
GoodBoyDigital committed Jul 8, 2024
2 parents fbdd266 + 0bdbab1 commit 8483f1e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@pixi/spine-pixi",
"version": "1.1.0",
"version": "2.0.2",
"description": "A port of the @esotericsoftware/spine-pixi runtime to PixiJS v8.",
"homepage": "https://pixijs.com/",
"bugs": "https://github.com/pixijs/spine-pixi/issues",
"bugs": "https://github.com/pixijs/spine-v8/issues",
"repository": {
"type": "git",
"url": "https://github.com/pixijs/spine-pixi.git"
"url": "https://github.com/pixijs/spine-v8.git"
},
"license": "MIT",
"author": "PixiJS Team",
Expand Down Expand Up @@ -35,7 +35,7 @@
"test": "xs test",
"types": "xs types",
"watch": "xs watch",
"deploy": "xs deploy"
"upload": "xs upload"
},
"dependencies": {
"@esotericsoftware/spine-core": "~4.2.45"
Expand Down
25 changes: 14 additions & 11 deletions src/Spine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export class Spine extends Container implements View
private _lastAttachments: Attachment[];

private _stateChanged: boolean;
private attachmentCacheData: Record<string, AttachmentCacheData> = {};
private attachmentCacheData: Record<string, AttachmentCacheData>[] = [];

public get debug(): ISpineDebugRenderer | undefined
{
Expand Down Expand Up @@ -209,6 +209,13 @@ export class Spine extends Container implements View
this.state = new AnimationState(new AnimationStateData(skeletonData));
this.autoUpdate = options?.autoUpdate ?? true;

const slots = this.skeleton.slots;

for (let i = 0; i < slots.length; i++)
{
this.attachmentCacheData[i] = Object.create(null);
}

this._updateState(0);
}

Expand Down Expand Up @@ -546,23 +553,19 @@ export class Spine extends Container implements View
/** @internal */
_getCachedData(slot: Slot, attachment: RegionAttachment | MeshAttachment): AttachmentCacheData
{
const key = `${slot.data.index}-${attachment.name}`;

return this.attachmentCacheData[key] || this.initCachedData(slot, attachment);
return this.attachmentCacheData[slot.data.index][attachment.name] || this.initCachedData(slot, attachment);
}

private initCachedData(slot: Slot, attachment: RegionAttachment | MeshAttachment): AttachmentCacheData
{
const key = `${slot.data.index}-${attachment.name}`;

let vertices: Float32Array;

if (attachment instanceof RegionAttachment)
{
vertices = new Float32Array(8);

this.attachmentCacheData[key] = {
id: key,
this.attachmentCacheData[slot.data.index][attachment.name] = {
id: `${slot.data.index}-${attachment.name}`,
vertices,
clipped: false,
indices: [0, 1, 2, 0, 2, 3],
Expand All @@ -574,8 +577,8 @@ export class Spine extends Container implements View
{
vertices = new Float32Array(attachment.worldVerticesLength);

this.attachmentCacheData[key] = {
id: key,
this.attachmentCacheData[slot.data.index][attachment.name] = {
id: `${slot.data.index}-${attachment.name}`,
vertices,
clipped: false,
indices: attachment.triangles,
Expand All @@ -584,7 +587,7 @@ export class Spine extends Container implements View
};
}

return this.attachmentCacheData[key];
return this.attachmentCacheData[slot.data.index][attachment.name];
}

protected onViewUpdate()
Expand Down
2 changes: 1 addition & 1 deletion src/SpinePipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export class SpinePipe implements RenderPipe<Spine>
{
const batchableSpineSlot = gpuSpine.slotBatches[spine._getCachedData(slot, attachment).id];

batchableSpineSlot.batcher.updateElement(batchableSpineSlot);
batchableSpineSlot.batcher?.updateElement(batchableSpineSlot);
}
}
}
Expand Down

0 comments on commit 8483f1e

Please sign in to comment.