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 and invalid operation reported by …
Browse files Browse the repository at this point in the history
…webgl/gpu
  • Loading branch information
davidetan committed Jul 26, 2024
1 parent 0bdbab1 commit 9762607
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/Spine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,10 @@ export class Spine extends Container implements View
else
{
clipper.clipEndWithSlot(slot);
continue;
}
}
clipper.clipEndWithSlot(slot);
}

clipper.clipEnd();
Expand Down
19 changes: 11 additions & 8 deletions src/SpinePipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ import {
} from 'pixi.js';
import { BatchableSpineSlot } from './BatchableSpineSlot';
import { Spine } from './Spine';
import { MeshAttachment, RegionAttachment, SkeletonClipping } from '@esotericsoftware/spine-core';

const clipper = new SkeletonClipping();
import { MeshAttachment, RegionAttachment } from '@esotericsoftware/spine-core';

const spineBlendModeMap = {
0: 'normal',
Expand Down Expand Up @@ -101,7 +99,7 @@ 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))
if (!cacheData.clipped || (cacheData.clipped && cacheData.clippedData.vertexCount > 0))
{
batchableSpineSlot.setData(
spine,
Expand All @@ -126,8 +124,6 @@ export class SpinePipe implements RenderPipe<Spine>
container.includeInBuild = false;
}
}

clipper.clipEnd();
}

updateRenderable(spine: Spine)
Expand All @@ -146,9 +142,16 @@ 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.clipped || (cacheData.clipped && cacheData.clippedData.vertexCount > 0))
{
const batchableSpineSlot = gpuSpine.slotBatches[cacheData.id];

// this marks the batch dirty and make
// the batcher call packAttributes on the BatchableSpineSlot
batchableSpineSlot.batcher?.updateElement(batchableSpineSlot);
}
}
}
}
Expand Down

0 comments on commit 9762607

Please sign in to comment.