From 4c8167b885b5667961f1aee8c890bd83ac3288ce Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Tue, 4 Oct 2022 08:58:11 +0200 Subject: [PATCH] [threejs] Fix batch capacity calculation, closes #2163 --- spine-ts/spine-threejs/src/MeshBatcher.ts | 6 +++--- spine-ts/spine-threejs/src/SkeletonMesh.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spine-ts/spine-threejs/src/MeshBatcher.ts b/spine-ts/spine-threejs/src/MeshBatcher.ts index 15adec245..f474b484f 100644 --- a/spine-ts/spine-threejs/src/MeshBatcher.ts +++ b/spine-ts/spine-threejs/src/MeshBatcher.ts @@ -98,9 +98,9 @@ export class MeshBatcher extends THREE.Mesh { this.indicesLength = 0; } - canBatch (verticesLength: number, indicesLength: number) { - if (this.indicesLength + indicesLength >= this.indices.byteLength / 2) return false; - if (this.verticesLength + verticesLength >= this.vertices.byteLength / 2) return false; + canBatch (numVertices: number, numIndices: number) { + if (this.indicesLength + numIndices >= this.indices.byteLength / 2) return false; + if (this.verticesLength / MeshBatcher.VERTEX_SIZE + numVertices >= (this.vertices.byteLength / 4) / MeshBatcher.VERTEX_SIZE) return false; return true; } diff --git a/spine-ts/spine-threejs/src/SkeletonMesh.ts b/spine-ts/spine-threejs/src/SkeletonMesh.ts index 853b7ad21..07c48e119 100644 --- a/spine-ts/spine-threejs/src/SkeletonMesh.ts +++ b/spine-ts/spine-threejs/src/SkeletonMesh.ts @@ -249,7 +249,7 @@ export class SkeletonMesh extends THREE.Object3D { } // Start new batch if this one can't hold vertices/indices - if (!batch.canBatch(finalVerticesLength, finalIndicesLength)) { + if (!batch.canBatch(finalVerticesLength / SkeletonMesh.VERTEX_SIZE, finalIndicesLength)) { batch.end(); batch = this.nextBatch(); batch.begin();