From 230a45e85774bcd59543a154558ab1b1d9a9eab8 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Mon, 6 Apr 2026 17:36:04 +0200 Subject: [PATCH] Refactor texture creation and contact patch collection in viewport-host.ts --- src/viewport-three/viewport-host.ts | 98 ++++++++++++++--------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/src/viewport-three/viewport-host.ts b/src/viewport-three/viewport-host.ts index 86fabf79..f2f418c8 100644 --- a/src/viewport-three/viewport-host.ts +++ b/src/viewport-three/viewport-host.ts @@ -2989,55 +2989,6 @@ export class ViewportHost { cachedTexture?.texture.dispose(); - private collectViewportWaterContactPatches( - document: SceneDocument, - excludedBrushId: string, - center: Vec3, - rotationDegrees: Vec3, - size: Vec3 - ) { - const contactBounds: GeneratedColliderBounds[] = []; - - for (const brush of Object.values(document.brushes)) { - if (brush.id === excludedBrushId || brush.volume.mode !== "none") { - continue; - } - - contactBounds.push(getBoxBrushBounds(brush)); - } - - for (const modelInstance of getModelInstances(document.modelInstances)) { - if (modelInstance.collision.mode === "none") { - continue; - } - - const asset = this.projectAssets[modelInstance.assetId]; - - if (asset?.kind !== "model") { - continue; - } - - try { - const generatedCollider = buildGeneratedModelCollider(modelInstance, asset, this.loadedModelAssets[modelInstance.assetId]); - - if (generatedCollider !== null) { - contactBounds.push(generatedCollider.worldBounds); - } - } catch { - // Validation already surfaces unsupported collider modes; the viewport keeps rendering. - } - } - - return collectWaterContactPatches( - { - center, - rotationDegrees, - size - }, - contactBounds - ); - } - const texture = createStarterMaterialTexture(material); this.materialTextureCache.set(material.id, { @@ -3048,6 +2999,55 @@ export class ViewportHost { return texture; } + private collectViewportWaterContactPatches( + document: SceneDocument, + excludedBrushId: string, + center: Vec3, + rotationDegrees: Vec3, + size: Vec3 + ) { + const contactBounds: GeneratedColliderBounds[] = []; + + for (const brush of Object.values(document.brushes)) { + if (brush.id === excludedBrushId || brush.volume.mode !== "none") { + continue; + } + + contactBounds.push(getBoxBrushBounds(brush)); + } + + for (const modelInstance of getModelInstances(document.modelInstances)) { + if (modelInstance.collision.mode === "none") { + continue; + } + + const asset = this.projectAssets[modelInstance.assetId]; + + if (asset?.kind !== "model") { + continue; + } + + try { + const generatedCollider = buildGeneratedModelCollider(modelInstance, asset, this.loadedModelAssets[modelInstance.assetId]); + + if (generatedCollider !== null) { + contactBounds.push(generatedCollider.worldBounds); + } + } catch { + // Validation already surfaces unsupported collider modes; the viewport keeps rendering. + } + } + + return collectWaterContactPatches( + { + center, + rotationDegrees, + size + }, + contactBounds + ); + } + private createEdgeHelper(brush: BoxBrush, edgeId: BoxEdgeId): { id: BoxEdgeId; line: Line } { const segment = getBoxBrushEdgeWorldSegment(brush, edgeId); const geometry = new BufferGeometry().setFromPoints([