Skip to content

Commit

Permalink
fix: adjust add items behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
agviegas committed Feb 13, 2024
1 parent 040aa8a commit a93a7fb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
9 changes: 7 additions & 2 deletions resources/fragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
11 changes: 9 additions & 2 deletions src/fragment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down

0 comments on commit a93a7fb

Please sign in to comment.