Refactor texture creation and contact patch collection in viewport-host.ts

This commit is contained in:
2026-04-06 17:36:04 +02:00
parent 2f8d22640d
commit 230a45e857

View File

@@ -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<BufferGeometry, LineBasicMaterial> } {
const segment = getBoxBrushEdgeWorldSegment(brush, edgeId);
const geometry = new BufferGeometry().setFromPoints([