Update water contact patch handling in runtime and viewport components

This commit is contained in:
2026-04-07 05:01:27 +02:00
parent de430fdda1
commit 867a20ab15
2 changed files with 33 additions and 9 deletions

View File

@@ -3,7 +3,7 @@ import { createModelInstanceRenderGroup, disposeModelInstance } from "../assets/
import { buildBoxBrushDerivedMeshData } from "../geometry/box-brush-mesh";
import { createStarterMaterialSignature, createStarterMaterialTexture } from "../materials/starter-material-textures";
import { applyAdvancedRenderingLightShadowFlags, applyAdvancedRenderingRenderableShadowFlags, configureAdvancedRenderingRenderer, createAdvancedRenderingComposer, resolveBoxVolumeRenderPaths } from "../rendering/advanced-rendering";
import { collectWaterContactPatches, createWaterContactPatchUniformValue, createWaterMaterial } from "../rendering/water-material";
import { collectWaterContactPatches, createWaterContactPatchAxisUniformValue, createWaterContactPatchUniformValue, createWaterMaterial } from "../rendering/water-material";
import { areAdvancedRenderingSettingsEqual, cloneAdvancedRenderingSettings } from "../document/world-settings";
import { FirstPersonNavigationController } from "./first-person-navigation-controller";
import { RapierCollisionWorld } from "./rapier-collision-world";
@@ -441,10 +441,11 @@ export class RuntimeHost {
if (waterMaterial.animationUniform !== null) {
this.volumeAnimatedUniforms.push(waterMaterial.animationUniform);
}
if (faceId === "posY" && waterMaterial.contactPatchesUniform !== null) {
if (faceId === "posY" && waterMaterial.contactPatchesUniform !== null && waterMaterial.contactPatchAxesUniform !== null) {
this.runtimeWaterContactUniforms.push({
brush,
uniform: waterMaterial.contactPatchesUniform,
axisUniform: waterMaterial.contactPatchAxesUniform,
staticContactPatches
});
}
@@ -590,10 +591,27 @@ export class RuntimeHost {
}
}
collectRuntimeStaticWaterContactPatches(brush) {
const contactBounds = this.runtimeScene?.colliders.map((collider) => ({
min: collider.worldBounds.min,
max: collider.worldBounds.max
})) ?? [];
const contactBounds = [];
for (const otherBrush of this.runtimeScene?.brushes ?? []) {
if (otherBrush.id === brush.id || otherBrush.volume.mode !== "none") {
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") {
continue;
}
contactBounds.push({
min: collider.worldBounds.min,
max: collider.worldBounds.max
});
}
return collectWaterContactPatches({
center: brush.center,
rotationDegrees: brush.rotationDegrees,
@@ -616,7 +634,9 @@ export class RuntimeHost {
}
updateRuntimeWaterContactUniforms() {
for (const binding of this.runtimeWaterContactUniforms) {
binding.uniform.value = createWaterContactPatchUniformValue(this.mergeRuntimeWaterContactPatches(binding.staticContactPatches, this.collectRuntimePlayerWaterContactPatches(binding.brush)));
const mergedPatches = this.mergeRuntimeWaterContactPatches(binding.staticContactPatches, this.collectRuntimePlayerWaterContactPatches(binding.brush));
binding.uniform.value = createWaterContactPatchUniformValue(mergedPatches);
binding.axisUniform.value = createWaterContactPatchAxisUniformValue(mergedPatches);
}
}
clearModelInstances() {