From a93a7fb85dd499db8f6c3b1c9622d8c05cd0a631 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Gonz=C3=A1lez=20Viegas?= Date: Tue, 13 Feb 2024 20:36:43 +0100 Subject: [PATCH] fix: adjust add items behavior --- package.json | 2 +- resources/fragment.js | 9 +++++++-- src/fragment.ts | 11 +++++++++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index ec79776..a23eec7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bim-fragment", - "version": "1.3.11", + "version": "1.3.13", "description": "3D BIM Geometry API", "main": "src/index.js", "scripts": { diff --git a/resources/fragment.js b/resources/fragment.js index 8e699b4..5ac4d7b 100644 --- a/resources/fragment.js +++ b/resources/fragment.js @@ -4256,13 +4256,18 @@ let Fragment$1 = class Fragment { } const necessaryCapacity = this.mesh.count + size; if (necessaryCapacity > this.capacity) { - const newMesh = new FragmentMesh(this.mesh.geometry, this.mesh.material, necessaryCapacity + this.capacityOffset, this); + const newCapacity = necessaryCapacity + this.capacityOffset; + const newMesh = new FragmentMesh(this.mesh.geometry, this.mesh.material, newCapacity, this); newMesh.count = this.mesh.count; - this.capacity = size; + this.capacity = newCapacity; const oldMesh = this.mesh; (_a = oldMesh.parent) === null || _a === void 0 ? void 0 : _a.add(newMesh); oldMesh.removeFromParent(); this.mesh = newMesh; + newMesh.instanceMatrix = oldMesh.instanceMatrix; + newMesh.instanceColor = oldMesh.instanceColor; + oldMesh.instanceMatrix = undefined; + oldMesh.instanceColor = null; oldMesh.dispose(); } for (let i = 0; i < items.length; i++) { diff --git a/src/fragment.ts b/src/fragment.ts index 27e2532..d8e5c0b 100644 --- a/src/fragment.ts +++ b/src/fragment.ts @@ -120,20 +120,27 @@ export class Fragment { const necessaryCapacity = this.mesh.count + size; if (necessaryCapacity > this.capacity) { + const newCapacity = necessaryCapacity + this.capacityOffset; const newMesh = new FragmentMesh( this.mesh.geometry, this.mesh.material, - necessaryCapacity + this.capacityOffset, + newCapacity, this ); newMesh.count = this.mesh.count; - this.capacity = size; + this.capacity = newCapacity; const oldMesh = this.mesh; oldMesh.parent?.add(newMesh); oldMesh.removeFromParent(); this.mesh = newMesh; + + newMesh.instanceMatrix = oldMesh.instanceMatrix; + newMesh.instanceColor = oldMesh.instanceColor; + + oldMesh.instanceMatrix = undefined as any; + oldMesh.instanceColor = null; oldMesh.dispose(); }