Refactor brush handling in runtime-host.ts
This commit is contained in:
@@ -1828,20 +1828,9 @@ export class RuntimeHost {
|
|||||||
: resolveBoxVolumeRenderPaths(this.currentWorld.advancedRendering);
|
: resolveBoxVolumeRenderPaths(this.currentWorld.advancedRendering);
|
||||||
|
|
||||||
for (const brush of brushes) {
|
for (const brush of brushes) {
|
||||||
const geometryBrush: BoxBrush = {
|
const geometryBrush = createRuntimeGeometryBrush(brush);
|
||||||
id: brush.id,
|
const derivedMesh = buildBoxBrushDerivedMeshData(geometryBrush);
|
||||||
kind: "box",
|
const geometry = derivedMesh.geometry;
|
||||||
name: undefined,
|
|
||||||
visible: brush.visible,
|
|
||||||
enabled: true,
|
|
||||||
center: brush.center,
|
|
||||||
rotationDegrees: brush.rotationDegrees,
|
|
||||||
size: brush.size,
|
|
||||||
geometry: brush.geometry,
|
|
||||||
faces: brush.faces,
|
|
||||||
volume: brush.volume
|
|
||||||
};
|
|
||||||
const geometry = buildBoxBrushDerivedMeshData(geometryBrush).geometry;
|
|
||||||
const staticContactPatches =
|
const staticContactPatches =
|
||||||
brush.volume.mode === "water"
|
brush.volume.mode === "water"
|
||||||
? this.collectRuntimeStaticWaterContactPatches(brush)
|
? this.collectRuntimeStaticWaterContactPatches(brush)
|
||||||
@@ -1855,56 +1844,22 @@ export class RuntimeHost {
|
|||||||
)
|
)
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
const materials = this.createFogMaterialSet(brush, volumeRenderPaths) ?? [
|
const materials =
|
||||||
this.createFaceMaterial(
|
this.createFogMaterialSet(
|
||||||
brush,
|
brush,
|
||||||
"posX",
|
|
||||||
brush.faces.posX.material,
|
|
||||||
volumeRenderPaths,
|
volumeRenderPaths,
|
||||||
contactPatches,
|
derivedMesh.faceIdsInOrder
|
||||||
staticContactPatches
|
) ??
|
||||||
),
|
derivedMesh.faceIdsInOrder.map((faceId) =>
|
||||||
this.createFaceMaterial(
|
this.createFaceMaterial(
|
||||||
brush,
|
brush,
|
||||||
"negX",
|
faceId,
|
||||||
brush.faces.negX.material,
|
brush.faces[faceId]?.material ?? null,
|
||||||
volumeRenderPaths,
|
volumeRenderPaths,
|
||||||
contactPatches,
|
contactPatches,
|
||||||
staticContactPatches
|
staticContactPatches
|
||||||
),
|
)
|
||||||
this.createFaceMaterial(
|
);
|
||||||
brush,
|
|
||||||
"posY",
|
|
||||||
brush.faces.posY.material,
|
|
||||||
volumeRenderPaths,
|
|
||||||
contactPatches,
|
|
||||||
staticContactPatches
|
|
||||||
),
|
|
||||||
this.createFaceMaterial(
|
|
||||||
brush,
|
|
||||||
"negY",
|
|
||||||
brush.faces.negY.material,
|
|
||||||
volumeRenderPaths,
|
|
||||||
contactPatches,
|
|
||||||
staticContactPatches
|
|
||||||
),
|
|
||||||
this.createFaceMaterial(
|
|
||||||
brush,
|
|
||||||
"posZ",
|
|
||||||
brush.faces.posZ.material,
|
|
||||||
volumeRenderPaths,
|
|
||||||
contactPatches,
|
|
||||||
staticContactPatches
|
|
||||||
),
|
|
||||||
this.createFaceMaterial(
|
|
||||||
brush,
|
|
||||||
"negZ",
|
|
||||||
brush.faces.negZ.material,
|
|
||||||
volumeRenderPaths,
|
|
||||||
contactPatches,
|
|
||||||
staticContactPatches
|
|
||||||
)
|
|
||||||
];
|
|
||||||
|
|
||||||
const mesh = new Mesh(geometry, materials);
|
const mesh = new Mesh(geometry, materials);
|
||||||
mesh.position.set(brush.center.x, brush.center.y, brush.center.z);
|
mesh.position.set(brush.center.x, brush.center.y, brush.center.z);
|
||||||
@@ -1927,7 +1882,8 @@ export class RuntimeHost {
|
|||||||
volumeRenderPaths: {
|
volumeRenderPaths: {
|
||||||
fog: "performance" | "quality";
|
fog: "performance" | "quality";
|
||||||
water: "performance" | "quality";
|
water: "performance" | "quality";
|
||||||
}
|
},
|
||||||
|
faceIds: WhiteboxFaceId[]
|
||||||
): Material[] | null {
|
): Material[] | null {
|
||||||
if (brush.volume.mode !== "fog") {
|
if (brush.volume.mode !== "fog") {
|
||||||
return null;
|
return null;
|
||||||
@@ -1947,10 +1903,7 @@ export class RuntimeHost {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.volumeAnimatedUniforms.push(fogMaterial.animationUniform);
|
this.volumeAnimatedUniforms.push(fogMaterial.animationUniform);
|
||||||
return Array.from(
|
return faceIds.map(() => fogMaterial.material);
|
||||||
{ length: BOX_FACE_MATERIAL_COUNT },
|
|
||||||
() => fogMaterial.material
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const densityOpacity = Math.max(
|
const densityOpacity = Math.max(
|
||||||
@@ -1964,7 +1917,7 @@ export class RuntimeHost {
|
|||||||
depthWrite: false
|
depthWrite: false
|
||||||
});
|
});
|
||||||
|
|
||||||
return Array.from({ length: BOX_FACE_MATERIAL_COUNT }, () => fogMaterial);
|
return faceIds.map(() => fogMaterial);
|
||||||
}
|
}
|
||||||
|
|
||||||
private configureFogVolumeMesh(
|
private configureFogVolumeMesh(
|
||||||
@@ -2211,8 +2164,8 @@ export class RuntimeHost {
|
|||||||
|
|
||||||
private createFaceMaterial(
|
private createFaceMaterial(
|
||||||
brush: RuntimeBoxBrushInstance,
|
brush: RuntimeBoxBrushInstance,
|
||||||
faceId: "posX" | "negX" | "posY" | "negY" | "posZ" | "negZ",
|
faceId: WhiteboxFaceId,
|
||||||
material: RuntimeBoxBrushInstance["faces"]["posX"]["material"],
|
material: RuntimeBrushFace["material"],
|
||||||
volumeRenderPaths: {
|
volumeRenderPaths: {
|
||||||
fog: "performance" | "quality";
|
fog: "performance" | "quality";
|
||||||
water: "performance" | "quality";
|
water: "performance" | "quality";
|
||||||
@@ -2225,6 +2178,7 @@ export class RuntimeHost {
|
|||||||
0.05,
|
0.05,
|
||||||
Math.min(1, brush.volume.water.surfaceOpacity)
|
Math.min(1, brush.volume.water.surfaceOpacity)
|
||||||
);
|
);
|
||||||
|
const isTopFace = brush.kind === "box" && faceId === "posY";
|
||||||
const waterMaterial = createWaterMaterial({
|
const waterMaterial = createWaterMaterial({
|
||||||
colorHex: brush.volume.water.colorHex,
|
colorHex: brush.volume.water.colorHex,
|
||||||
surfaceOpacity: brush.volume.water.surfaceOpacity,
|
surfaceOpacity: brush.volume.water.surfaceOpacity,
|
||||||
@@ -2232,12 +2186,12 @@ export class RuntimeHost {
|
|||||||
surfaceDisplacementEnabled:
|
surfaceDisplacementEnabled:
|
||||||
brush.volume.water.surfaceDisplacementEnabled,
|
brush.volume.water.surfaceDisplacementEnabled,
|
||||||
opacity:
|
opacity:
|
||||||
faceId === "posY"
|
isTopFace
|
||||||
? Math.min(1, baseOpacity + 0.18)
|
? Math.min(1, baseOpacity + 0.18)
|
||||||
: baseOpacity * 0.5,
|
: baseOpacity * 0.5,
|
||||||
quality: volumeRenderPaths.water === "quality",
|
quality: volumeRenderPaths.water === "quality",
|
||||||
wireframe: false,
|
wireframe: false,
|
||||||
isTopFace: faceId === "posY",
|
isTopFace,
|
||||||
time: this.volumeTime,
|
time: this.volumeTime,
|
||||||
halfSize: {
|
halfSize: {
|
||||||
x: brush.size.x * 0.5,
|
x: brush.size.x * 0.5,
|
||||||
@@ -2246,7 +2200,7 @@ export class RuntimeHost {
|
|||||||
contactPatches,
|
contactPatches,
|
||||||
reflection: {
|
reflection: {
|
||||||
texture: null,
|
texture: null,
|
||||||
enabled: faceId === "posY"
|
enabled: isTopFace
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -2255,7 +2209,7 @@ export class RuntimeHost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
faceId === "posY" &&
|
isTopFace &&
|
||||||
waterMaterial.contactPatchesUniform !== null &&
|
waterMaterial.contactPatchesUniform !== null &&
|
||||||
waterMaterial.contactPatchAxesUniform !== null
|
waterMaterial.contactPatchAxesUniform !== null
|
||||||
) {
|
) {
|
||||||
@@ -2630,7 +2584,7 @@ export class RuntimeHost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private getOrCreateTextureSet(
|
private getOrCreateTextureSet(
|
||||||
material: NonNullable<RuntimeBoxBrushInstance["faces"]["posX"]["material"]>
|
material: NonNullable<RuntimeBrushFace["material"]>
|
||||||
) {
|
) {
|
||||||
const signature = createStarterMaterialSignature(material);
|
const signature = createStarterMaterialSignature(material);
|
||||||
const cachedTexture = this.materialTextureCache.get(material.id);
|
const cachedTexture = this.materialTextureCache.get(material.id);
|
||||||
|
|||||||
Reference in New Issue
Block a user