Update collision detection to handle triangle meshes and transformed colliders

This commit is contained in:
2026-04-07 05:44:04 +02:00
parent a9567d3dc8
commit a74a7c02f0
5 changed files with 163 additions and 33 deletions

View File

@@ -815,21 +815,40 @@ export class RuntimeHost {
private collectRuntimeStaticWaterContactPatches(brush: RuntimeBoxBrushInstance) {
const contactBounds: Parameters<typeof collectWaterContactPatches>[1] = [];
for (const otherBrush of this.runtimeScene?.brushes ?? []) {
if (otherBrush.id === brush.id || otherBrush.volume.mode !== "none") {
const runtimeBrushesById = new Map((this.runtimeScene?.brushes ?? []).map((runtimeBrush) => [runtimeBrush.id, runtimeBrush]));
for (const collider of this.runtimeScene?.colliders ?? []) {
if (collider.source === "brush") {
const otherBrush = runtimeBrushesById.get(collider.brushId);
if (otherBrush === undefined || otherBrush.id === brush.id || otherBrush.volume.mode !== "none") {
continue;
}
contactBounds.push({
kind: "triangleMesh",
vertices: collider.vertices,
indices: collider.indices,
transform: {
position: collider.center,
rotationDegrees: collider.rotationDegrees,
scale: {
x: 1,
y: 1,
z: 1
}
}
});
continue;
}
contactBounds.push({
kind: "orientedBox",
center: otherBrush.center,
rotationDegrees: otherBrush.rotationDegrees,
size: otherBrush.size
});
}
for (const collider of this.runtimeScene?.colliders ?? []) {
if (collider.source !== "modelInstance") {
if (collider.kind === "trimesh") {
contactBounds.push({
kind: "triangleMesh",
vertices: collider.vertices,
indices: collider.indices,
transform: collider.transform
});
continue;
}