Files
NextFloor/frontend/src/viewer/furniture/hydronic.ts
T

51 lines
3.1 KiB
TypeScript

import type { Furniture } from "../../model.ts";
import { circuitX, hasPump, hasValve, hydronicConfig } from "../../hydronic-model.ts";
import { Builder } from "./builder.ts";
import { EDGE_FAINT, EDGE_FURN, M, material } from "./palette.ts";
const hot = material(0x9d413e, 0xc86b56), cold = material(0x285f85, 0x4e99bd), brass = material(0x92724b, 0xc9a56a);
export function hydronicModel(b: Builder, f: Furniture, w: number, d: number, h: number): void {
const cfg = hydronicConfig(f), z = d * .3;
const pipe = (x: number, y0: number, y1: number, r: number, m = hot) => b.cylinder(x, z, r, y0, y1, m, 10, EDGE_FAINT);
const face = (x: number, y: number, r: number, m = M.dark) => b.lyingCylinder("z", x, z, y - r, y + r, d * .5, r * 2, m, 16, EDGE_FURN);
if (f.type === "buffer_tank") {
const r = Math.min(w, d) * .46;
b.cylinder(0, 0, r, h * .06, h * .94, M.darkBody, 24, EDGE_FURN);
b.cylinder(0, 0, r * .96, h * .94, h * .99, M.metal, 24, EDGE_FAINT);
b.cylinder(0, 0, r * .98, h * .035, h * .06, M.metal, 24, EDGE_FAINT);
for (const y of [.12, .88]) b.lyingCylinder("x", r * .95, 0, h * y - .025, h * y + .025, w * .14, .05, y > .5 ? hot : cold, 12, EDGE_FURN);
for (const s of cfg.sensors ?? []) {
const y = h * (.1 + .8 * s.level);
b.lyingCylinder("z", 0, r, y - .018, y + .018, .035, .036, brass, 10, EDGE_FAINT);
b.ring(0, y, .025, r + .022, 12, EDGE_FAINT);
}
for (const x of [-1, 1]) for (const zz of [-1, 1]) b.cylinder(x * r * .52, zz * r * .52, .025, 0, h * .05, M.metal);
return;
}
b.block({ x: [-w * .49, w * .49], y: [h * .02, h * .98], z: [-d * .48, -d * .35] }, M.darkBody, EDGE_FURN);
if (f.type === "heating_manifold") {
for (const [y, m] of [[.83, hot], [.18, cold]] as const) b.lyingCylinder("x", 0, z, h * y - .027, h * y + .027, w * .92, .054, m, 12, EDGE_FURN);
const circuits = cfg.circuits ?? [], column = w * .8 / Math.max(1, circuits.length);
circuits.forEach((c, i) => {
const x = w * circuitX(i, circuits.length), r = Math.min(column * .35, h * .075);
pipe(x - column * .22, h * .18, h * .83, Math.min(.018, column * .09));
pipe(x + column * .22, h * .18, h * .83, Math.min(.018, column * .09), cold);
if (hasPump(c)) face(x, h * .6, r, M.dark);
if (hasValve(c)) {
b.block({ x: [x - r * .7, x + r * .7], y: [h * .38, h * .48], z: [0, d * .57] }, brass, EDGE_FAINT);
face(x, h * .43, r * .65, M.white);
}
for (const [y, xx] of [[.76, x - column * .22], [.25, x + column * .22]]) face(xx, h * y, Math.min(r * .4, .025), M.white);
});
} else {
b.block({ x: [-w * .24, w * .24], y: [h * .35, h * .84], z: [-d * .2, d * .12] }, brass, EDGE_FURN);
for (let i = 0; i < 9; i++) b.seg(-w * .22 + i * w * .055, h * .38, d * .13, -w * .22 + i * w * .055, h * .81, d * .13, EDGE_FAINT);
for (const [i, x] of [-.36, -.12, .12, .36].entries()) {
pipe(w * x, 0, h * (i < 2 ? .9 : .35), .018, i === 1 ? cold : hot);
face(w * x, h * .28, .028, M.white);
}
face(-w * .3, h * .55, Math.min(w, h) * .085, M.dark);
face(w * .3, h * .55, Math.min(w, h) * .085, M.dark);
}
}