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

Commit

Permalink
fix: clipping not working properly v2 (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
GoodBoyDigital authored Aug 2, 2024
1 parent 9f697b1 commit 25e3053
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
9 changes: 7 additions & 2 deletions src/Spine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export interface AttachmentCacheData
uvs: Float32Array;
indices: number[];
color: Color;
skipRender: boolean;
clippedData?: {
vertices: Float32Array;
uvs: Float32Array;
Expand Down Expand Up @@ -431,7 +432,7 @@ export class Spine extends Container implements View
skeletonColor.a * slotColor.a * attachmentColor.a,
);

cacheData.clipped = false;
cacheData.skipRender = cacheData.clipped = false;

if (clipper.isClipping())
{
Expand Down Expand Up @@ -489,7 +490,9 @@ export class Spine extends Container implements View

const sizeChange = clippedData.vertexCount !== verticesCount || indicesCount !== clippedData.indicesCount;

if (sizeChange)
cacheData.skipRender = verticesCount === 0;

if (sizeChange && !cacheData.skipRender)
{
this.spineAttachmentsDirty = true;

Expand Down Expand Up @@ -583,6 +586,7 @@ export class Spine extends Container implements View
indices: [0, 1, 2, 0, 2, 3],
uvs: attachment.uvs as Float32Array,
color: new Color(1, 1, 1, 1),
skipRender: false,
};
}
else
Expand All @@ -596,6 +600,7 @@ export class Spine extends Container implements View
indices: attachment.triangles,
uvs: attachment.uvs as Float32Array,
color: new Color(1, 1, 1, 1),
skipRender: false,
};
}

Expand Down
27 changes: 16 additions & 11 deletions src/SpinePipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,16 @@ export class SpinePipe implements RenderPipe<Spine>
const cacheData = spine._getCachedData(slot, attachment);
const batchableSpineSlot = gpuSpine.slotBatches[cacheData.id] ||= new BatchableSpineSlot();

if (!cacheData.clipped || (cacheData.clipped && cacheData.clippedData.vertices.length > 0))
batchableSpineSlot.setData(
spine,
cacheData,
(attachment.region?.texture.texture) || Texture.EMPTY,
blendMode,
roundPixels
);

if (!cacheData.skipRender)
{
batchableSpineSlot.setData(
spine,
cacheData,
(attachment.region?.texture.texture) || Texture.EMPTY,
blendMode,
roundPixels
);

batcher.addToBatch(batchableSpineSlot);
}
}
Expand Down Expand Up @@ -146,9 +146,14 @@ export class SpinePipe implements RenderPipe<Spine>

if (attachment instanceof RegionAttachment || attachment instanceof MeshAttachment)
{
const batchableSpineSlot = gpuSpine.slotBatches[spine._getCachedData(slot, attachment).id];
const cacheData = spine._getCachedData(slot, attachment);

batchableSpineSlot.batcher?.updateElement(batchableSpineSlot);
if (!cacheData.skipRender)
{
const batchableSpineSlot = gpuSpine.slotBatches[spine._getCachedData(slot, attachment).id];

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

0 comments on commit 25e3053

Please sign in to comment.