From 961d03d97972ed2d4ed38d4861d82aec68761d17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Gonz=C3=A1lez=20Viegas?= Date: Thu, 25 Jul 2024 22:19:19 +0200 Subject: [PATCH] feat(core): allow the mesh culler to update instanced meshes count --- packages/core/package.json | 2 +- packages/core/src/core/Cullers/index.ts | 14 ++++++++++++++ .../core/Cullers/src/mesh-culler-renderer.ts | 17 +++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/packages/core/package.json b/packages/core/package.json index b01080b99..5bf73f09b 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -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)", diff --git a/packages/core/src/core/Cullers/index.ts b/packages/core/src/core/Cullers/index.ts index 66c1fff50..965128f0c 100644 --- a/packages/core/src/core/Cullers/index.ts +++ b/packages/core/src/core/Cullers/index.ts @@ -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"; @@ -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) { + for (const [, culler] of this.list) { + culler.updateInstanced(meshes); + } + } } diff --git a/packages/core/src/core/Cullers/src/mesh-culler-renderer.ts b/packages/core/src/core/Cullers/src/mesh-culler-renderer.ts index ce884314f..5e47caf01 100644 --- a/packages/core/src/core/Cullers/src/mesh-culler-renderer.ts +++ b/packages/core/src/core/Cullers/src/mesh-culler-renderer.ts @@ -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) { + 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;