Skip to content

Commit

Permalink
feat(core): allow the mesh culler to update instanced meshes count
Browse files Browse the repository at this point in the history
  • Loading branch information
agviegas committed Jul 25, 2024
1 parent eea990c commit 961d03d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@thatopen/components",
"description": "Collection of core functionalities to author BIM apps.",
"version": "2.1.13",
"version": "2.1.14",
"author": "That Open Company",
"contributors": [
"Antonio Gonzalez Viegas (https://github.com/agviegas)",
Expand Down
14 changes: 14 additions & 0 deletions packages/core/src/core/Cullers/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as THREE from "three";
import { Components } from "../Components";
import { MeshCullerRenderer, CullerRendererSettings } from "./src";
import { Component, Event, Disposable, World } from "../Types";
Expand Down Expand Up @@ -91,4 +92,17 @@ export class Cullers extends Component implements Disposable {
}
this.list.clear();
}

/**
* Updates the given instanced meshes inside the all the cullers. You should use this if you change the count property, e.g. when changing the visibility of fragments.
*
* @param meshes - The meshes to update.
*
* @returns {void}
*/
updateInstanced(meshes: Iterable<THREE.InstancedMesh>) {
for (const [, culler] of this.list) {
culler.updateInstanced(meshes);
}
}
}
17 changes: 17 additions & 0 deletions packages/core/src/core/Cullers/src/mesh-culler-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,23 @@ export class MeshCullerRenderer extends CullerRenderer implements Disposable {
this.isProcessing = false;
}

/**
* Updates the given instanced meshes inside the culler. You should use this if you change the count property, e.g. when changing the visibility of fragments.
*
* @param meshes - The meshes to update.
*
* @returns {void}
*/
updateInstanced(meshes: Iterable<THREE.InstancedMesh>) {
for (const mesh of meshes) {
const colorMesh = this.colorMeshes.get(mesh.uuid);
if (!colorMesh) {
continue;
}
colorMesh.count = mesh.count;
}
}

private handleWorkerMessage = async (event: MessageEvent) => {
if (this.isProcessing) {
return;
Expand Down

0 comments on commit 961d03d

Please sign in to comment.