fix: rebuild hydronic circuits around correct inline pipework
This commit is contained in:
1 parent
59292517b7
commit
e62f987563
24 files changed
+844
-586
No files matched your search
@@ -26,6 +26,7 @@ export function renderHydronicForm(host: EditorHost, item: Furniture, update: (p
|
||||
${selectField(host, "Kreisart", c.kind, [["heating", "Heizkreis"], ["cooling", "Kühlkreis"], ["changeover", "Heizen / Kühlen"], ["pump", "Einspeise- / Vorschubpumpe (ohne Ventil)"]], (kind) => patch({ kind, ...(kind === "pump" ? { has_pump: true, has_valve: false } : {}) }), { wide: true })}
|
||||
${c.kind !== "pump" ? html`${checkField(host, "Pumpe vorhanden", hasPump(c), (has_pump) => patch({ has_pump }))}${checkField(host, "Ventil vorhanden", hasValve(c), (has_valve) => patch({ has_valve }))}` : nothing}
|
||||
${hasPump(c) ? control("Pumpe", c.pump, (pump) => patch({ pump })) : nothing}
|
||||
${hasValve(c) ? selectField(host, "Ventilbauart", c.valve_type ?? "mixing", [["mixing", "Mischer (Dreiwegeventil)"], ["two_way", "Durchgangsventil (Zweiwege)" ]], (valve_type) => patch({ valve_type }), { wide: true }) : nothing}
|
||||
${hasValve(c) ? control("Ventil", c.valve, (valve) => patch({ valve }), true) : nothing}
|
||||
${numeric("Vorlauf", c.flow, (flow) => patch({ flow }))}${numeric("Rücklauf", c.return, (back) => patch({ return: back }))}
|
||||
${hasPump(c) ? numeric("Pumpenleistung (optional)", c.power, (power) => patch({ power })) : nothing}
|
||||
|
||||
@@ -6,6 +6,8 @@ export interface HydronicControl { command?: EntityRef; feedback?: EntityRef; in
|
||||
export interface HydronicCircuit {
|
||||
id: string; name: string; kind: "heating" | "cooling" | "changeover" | "pump";
|
||||
has_pump?: boolean; has_valve?: boolean;
|
||||
/** Mixing valve adds a return-side bypass; two-way valves stay in the flow only. */
|
||||
valve_type?: "mixing" | "two_way";
|
||||
pump?: HydronicControl; valve?: HydronicControl;
|
||||
flow?: EntityRef; return?: EntityRef; power?: EntityRef;
|
||||
mode_entity?: EntityRef; cooling_value?: number;
|
||||
|
||||
@@ -158,7 +158,8 @@ export class Builder {
|
||||
const at = (a: number, c: number): Vec2 => (axis === "x" ? this.plan(a, c) : this.plan(c, a));
|
||||
const first = this.buf.p.length;
|
||||
pushLyingCyl(this.buf, at, along - length / 2, along + length / 2, across, cy, r, material.side, material.top, sides);
|
||||
if (this.mirrored) flipWinding(this.buf, first);
|
||||
// Mapping along/across to z/x reverses orientation just like a mirrored plan.
|
||||
if (this.mirrored !== (axis === "z")) flipWinding(this.buf, first);
|
||||
if (!edges) return;
|
||||
for (const a of [along - length / 2, along + length / 2]) {
|
||||
for (let i = 0; i < sides; i++) {
|
||||
|
||||
@@ -114,6 +114,23 @@ test("flipping the winding swaps the second and third vertex of each triangle",
|
||||
assert.deepEqual(buf.uv, [0, 0, 0, 1, 1, 0]);
|
||||
});
|
||||
|
||||
test("lying cylinders have outward caps and walls along either axis, including mirrored models", () => {
|
||||
for (const axis of ["x","z"] as const) for (const plan of [identity,mirrored]) {
|
||||
const {buf,b}=tools(plan);b.lyingCylinder(axis,0,0,-.3,.3,.8,.6,M.metal,12);
|
||||
const centre=[0,0,0],axisIndex=axis==="x"?0:2;
|
||||
let caps=0;
|
||||
for(let i=0;i<buf.p.length;i+=9) {
|
||||
const a=buf.p.slice(i,i+3),bb=buf.p.slice(i+3,i+6),c=buf.p.slice(i+6,i+9);
|
||||
const u=bb.map((v,k)=>v-a[k]),v=c.map((p,k)=>p-a[k]);
|
||||
const n=[u[1]*v[2]-u[2]*v[1],u[2]*v[0]-u[0]*v[2],u[0]*v[1]-u[1]*v[0]];
|
||||
const mid=a.map((p,k)=>(p+bb[k]+c[k])/3-centre[k]);
|
||||
assert.ok(n.reduce((dot,p,k)=>dot+p*mid[k],0)>0,`${axis}: every face must point out of the solid`);
|
||||
if(Math.abs(n[axisIndex])>1e-6)caps++;
|
||||
}
|
||||
assert.equal(caps,24,"both solid end caps must face the camera from their outside");
|
||||
}
|
||||
});
|
||||
|
||||
test("a ring draws its segments, and a contact shadow fades out beyond the footprint", () => {
|
||||
const { lines, b } = tools();
|
||||
b.ring(0, 1, 0.3, 0, 16);
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import type { Furniture } from "../../model.ts";
|
||||
import { circuitX, hasPump, hasValve, hydronicConfig } from "../../hydronic-model.ts";
|
||||
import { hasPump, hasValve, hydronicConfig } from "../../hydronic-model.ts";
|
||||
import { circuitLayout, type PipePoint } from "../hydronic-layout.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);
|
||||
const steel = material(0x696f70, 0x929794), load = material(0x343c3e, 0x50595b), faceplate = material(0xa4aca8, 0xc9cebf);
|
||||
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);
|
||||
@@ -24,18 +26,43 @@ export function hydronicModel(b: Builder, f: Furniture, w: number, d: number, h:
|
||||
}
|
||||
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);
|
||||
const circuits = cfg.circuits ?? [], headerR = Math.min(h * .025, d * .12);
|
||||
// Both headers are below the circuit groups. Depth separation keeps crossings from becoming false tees.
|
||||
for (const [y, zz, m] of [[h * .15, -d * .14, hot], [h * .07, d * .16, cold]] as const) b.lyingCylinder("x", 0, zz, y - headerR, y + headerR, w * .94, headerR * 2, m, 16, EDGE_FAINT);
|
||||
const segment = (a: PipePoint, end: PipePoint, r: number, m = hot) => {
|
||||
const [x0,y0,z0] = a, [x1,y1,z1] = end;
|
||||
if (Math.abs(x1-x0) > 1e-6) b.lyingCylinder("x", (x0+x1)/2, z0, y0-r, y0+r, Math.abs(x1-x0), r*2, m, 12, EDGE_FAINT);
|
||||
else if (Math.abs(z1-z0) > 1e-6) b.lyingCylinder("z", x0, (z0+z1)/2, y0-r, y0+r, Math.abs(z1-z0), r*2, m, 12, EDGE_FAINT);
|
||||
else b.cylinder(x0, z0, r, Math.min(y0,y1), Math.max(y0,y1), m, 12, EDGE_FAINT);
|
||||
};
|
||||
const body = (x: number, y: number, r: number, back: number, front: number, m = steel) => b.lyingCylinder("z", x, (back+front)/2, y-r, y+r, front-back, r*2, m, 24, EDGE_FAINT);
|
||||
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);
|
||||
const p = circuitLayout(f, c, i, circuits.length);
|
||||
for (const s of p.pipes) segment(s.from, s.to, p.pipeR, s.kind === "flow" ? hot : cold);
|
||||
if (c.kind !== "pump") {
|
||||
// Neutral consumer symbol above the two risers, like the supplied hydraulic diagram.
|
||||
body(p.x, p.loadY, p.loadR, p.frontZ, p.loadFront, load);
|
||||
b.ring(p.x, p.loadY, p.loadR * .55, p.loadFront + .001, 24, EDGE_FAINT);
|
||||
const coil = p.loadR * .45;
|
||||
for (let k=0;k<4;k++) b.seg(p.x-coil+k*coil/2,p.loadY-coil*.3,p.loadFront+.002,p.x-coil+(k+.5)*coil/2,p.loadY+coil*.3,p.loadFront+.002,EDGE_FURN);
|
||||
}
|
||||
if (hasPump(c)) {
|
||||
body(p.flowX, p.pumpY, p.pumpR, p.frontZ - p.pipeR, p.pumpFront, M.darkBody);
|
||||
// Real inline flanges connect the pump body to the red riser rather than floating between pipes.
|
||||
for (const sign of [-1,1]) b.cylinder(p.flowX,p.frontZ,p.pipeR*1.65,p.pumpY+sign*p.pumpR-p.pipeR*.5,p.pumpY+sign*p.pumpR+p.pipeR*.5,steel,12,EDGE_FAINT);
|
||||
}
|
||||
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);
|
||||
body(p.flowX,p.valveY,p.valveR,p.frontZ-p.pipeR,p.valveFront,brass);
|
||||
for (const sign of [-1,1]) b.cylinder(p.flowX,p.frontZ,p.pipeR*1.5,p.valveY+sign*p.valveR-p.pipeR*.4,p.valveY+sign*p.valveR+p.pipeR*.4,brass,12,EDGE_FAINT);
|
||||
if (p.mixing) segment([p.flowX+p.valveR*.6,p.valveY,p.frontZ],[p.flowX+p.valveR*1.3,p.valveY,p.frontZ],p.pipeR*1.5,brass);
|
||||
// Compact actuator behind the position dial.
|
||||
b.block({x:[p.flowX-p.valveR*.65,p.flowX+p.valveR*.65],y:[p.valveY-p.valveR*.65,p.valveY+p.valveR*.65],z:[p.frontZ,p.frontZ+(p.valveFront-p.frontZ)*.9]},M.darkBody,EDGE_FAINT);
|
||||
}
|
||||
for (const [tapX,xx] of [[p.flowX,p.flowGaugeX],[p.returnX,p.returnGaugeX]]) {
|
||||
segment([tapX,p.temperatureY,p.frontZ],[xx,p.temperatureY,p.frontZ],p.pipeR*.5,steel);
|
||||
body(xx,p.temperatureY,p.gaugeR,p.frontZ,p.gaugeFront,faceplate);
|
||||
b.ring(xx,p.temperatureY,p.gaugeR*.8,p.gaugeFront+.001,16,EDGE_FAINT);
|
||||
}
|
||||
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);
|
||||
|
||||
@@ -127,7 +127,11 @@ export function pushLyingCyl(buf: GeoBuffer, at: (along: number, across: number)
|
||||
}
|
||||
for (const along of [a0, a1]) {
|
||||
const [x, z] = at(along, c);
|
||||
for (let i = 0; i < n; i++) buf.tri([x, cy, z], point(along, i), point(along, i + 1), capColor);
|
||||
// The two ends face opposite directions; equal winding leaves the near end open.
|
||||
for (let i = 0; i < n; i++) {
|
||||
if (along === a0) buf.tri([x, cy, z], point(along, i + 1), point(along, i), capColor);
|
||||
else buf.tri([x, cy, z], point(along, i), point(along, i + 1), capColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { test } from "node:test";
|
||||
import { circuitLayout } from "./hydronic-layout.ts";
|
||||
import { newCircuit } from "../hydronic-model.ts";
|
||||
|
||||
const size = { w:1.5,d:.35,h:1.1 };
|
||||
test("a mixed circuit follows the reference: lower headers → mixer → inline pump → probes → consumer", () => {
|
||||
const p = circuitLayout(size,newCircuit("c"),0,1);
|
||||
assert.ok(p.returnHeaderY < p.flowHeaderY && p.flowHeaderY < p.valveY && p.valveY < p.pumpY && p.pumpY < p.temperatureY && p.temperatureY < p.loadY);
|
||||
assert.ok(p.flowX < p.returnX);
|
||||
const mix = p.pipes.filter((s)=>s.kind==="mix"); assert.equal(mix.length,1);
|
||||
assert.deepEqual(mix[0].from,[p.flowX,p.valveY,p.frontZ]);
|
||||
assert.deepEqual(mix[0].to,[p.returnX,p.valveY,p.frontZ]);
|
||||
assert.ok(p.pipes.some((s)=>s.kind==="flow"&&s.from[0]===p.flowX&&s.to[0]===p.flowX&&s.from[1]<p.pumpY&&s.to[1]>p.pumpY));
|
||||
assert.equal(p.flowGaugeX-p.flowX,-(p.returnGaugeX-p.returnX));
|
||||
});
|
||||
|
||||
test("the return crosses in front of the rear supply header with physical clearance, never as a false tee", () => {
|
||||
const p=circuitLayout(size,newCircuit("c"),0,2);
|
||||
const headerR=Math.min(size.h*.025,size.d*.12);
|
||||
assert.ok(p.frontZ-p.backZ > headerR+p.pipeR);
|
||||
const lower=p.pipes.find((s)=>s.from[1]===p.flowHeaderY)!;
|
||||
assert.equal(lower.from[2],p.backZ); assert.equal(lower.to[2],p.backZ);
|
||||
assert.ok(lower.to[1] > p.flowHeaderY+headerR+p.pipeR);
|
||||
const returning=p.pipes.find((s)=>s.kind==="return"&&s.from[1]===p.returnHeaderY)!;
|
||||
assert.equal(returning.from[2],p.frontZ);assert.equal(returning.to[2],p.frontZ);
|
||||
assert.ok(returning.to[1]>p.flowHeaderY,"the crossed header remains behind this continuous return riser");
|
||||
});
|
||||
|
||||
test("two-way, valve-free and pure feed circuits have no invented mixing bypass", () => {
|
||||
for (const patch of [{valve_type:"two_way" as const},{has_valve:false},{kind:"pump" as const}]) {
|
||||
const p=circuitLayout(size,{...newCircuit("c"),...patch},0,1);
|
||||
assert.equal(p.mixing,false); assert.ok(p.pipes.every((s)=>s.kind!=="mix"));
|
||||
}
|
||||
const feed=circuitLayout(size,{...newCircuit("p"),kind:"pump"},0,1);
|
||||
assert.ok(feed.pipes.every((s)=>s.from[0]===s.to[0]),"a feed pair terminates separately; it is never short-circuited at the top");
|
||||
});
|
||||
|
||||
test("single and multi-circuit instruments remain within their column and finite at supported counts", () => {
|
||||
for (const count of [1,2,4,8,32]) for(let i=0;i<count;i++) {
|
||||
const p=circuitLayout(size,newCircuit(String(i)),i,count);
|
||||
assert.ok(p.flowX-p.pumpR > p.x-size.w*.4/count && p.returnX+p.gaugeR < p.x+size.w*.4/count);
|
||||
assert.ok(p.loadY+p.loadR <= size.h);
|
||||
assert.ok(p.pipes.every((s)=>[...s.from,...s.to].every(Number.isFinite)));
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,39 @@
|
||||
import type { Furniture } from "../model.ts";
|
||||
import { circuitX, hasValve, type HydronicCircuit } from "../hydronic-model.ts";
|
||||
|
||||
export type PipePoint = readonly [number, number, number];
|
||||
export interface HydronicPipe { from: PipePoint; to: PipePoint; kind: "flow" | "return" | "mix" }
|
||||
|
||||
/** One geometry source for the static pipework and its live instruments. Local front is +z. */
|
||||
export function circuitLayout(f: Pick<Furniture, "w" | "d" | "h">, c: HydronicCircuit, index: number, count: number) {
|
||||
const column = Math.min(f.w * .8 / Math.max(1, count), f.h * .5), x = f.w * circuitX(index, count);
|
||||
const flowX = x - column * .22, returnX = x + column * .22;
|
||||
const frontZ = f.d * .16, backZ = -f.d * .14;
|
||||
const flowHeaderY = f.h * .15, returnHeaderY = f.h * .07, flowElbowY = f.h * .24;
|
||||
const valveY = f.h * .34, pumpY = f.h * .55, temperatureY = f.h * .73, loadY = f.h * .87;
|
||||
const pipeR = Math.min(column * .04, f.h * .018, f.d * .08);
|
||||
const pumpR = Math.min(column * .13, f.h * .055, f.d * .28);
|
||||
const valveR = Math.min(column * .09, f.h * .04, f.d * .18);
|
||||
const gaugeR = Math.min(column * .06, f.h * .025, f.d * .14);
|
||||
const pumpFront = frontZ + Math.min(f.d * .28, pumpR * .8);
|
||||
const valveFront = frontZ + Math.min(f.d * .24, valveR * .9);
|
||||
const gaugeFront = frontZ + pipeR + gaugeR * .65;
|
||||
const flowGaugeX = flowX - column * .13, returnGaugeX = returnX + column * .13;
|
||||
const mixing = hasValve(c) && c.valve_type !== "two_way";
|
||||
const loadR = Math.min(column * .23, f.h * .115), loadFront = frontZ + Math.min(f.d * .22, loadR * .4);
|
||||
const topY = c.kind === "pump" ? f.h * .93 : loadY;
|
||||
const pipes: HydronicPipe[] = [
|
||||
// A rear supply header and front return header stay distinct from the usual elevated 3D view.
|
||||
{ from: [flowX, flowHeaderY, backZ], to: [flowX, flowElbowY, backZ], kind: "flow" },
|
||||
{ from: [flowX, flowElbowY, backZ], to: [flowX, flowElbowY, frontZ], kind: "flow" },
|
||||
{ from: [flowX, flowElbowY, frontZ], to: [flowX, topY, frontZ], kind: "flow" },
|
||||
{ from: [returnX, returnHeaderY, frontZ], to: [returnX, topY, frontZ], kind: "return" },
|
||||
];
|
||||
if (mixing) pipes.push({ from: [flowX, valveY, frontZ], to: [returnX, valveY, frontZ], kind: "mix" });
|
||||
if (c.kind !== "pump") {
|
||||
pipes.push({ from: [flowX, loadY, frontZ], to: [x - loadR, loadY, frontZ], kind: "flow" });
|
||||
pipes.push({ from: [x + loadR, loadY, frontZ], to: [returnX, loadY, frontZ], kind: "return" });
|
||||
}
|
||||
return { x, column, flowX, returnX, frontZ, backZ, flowHeaderY, returnHeaderY, valveY, pumpY, temperatureY, loadY, loadR, loadFront,
|
||||
pipeR, pumpR, valveR, gaugeR, pumpFront, valveFront, gaugeFront, flowGaugeX, returnGaugeX, mixing, topY, pipes };
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { test } from "node:test";
|
||||
import { Scene } from "three";
|
||||
import { Mesh, Scene } from "three";
|
||||
import type { Furniture } from "../model.ts";
|
||||
import { newCircuit } from "../hydronic-model.ts";
|
||||
import { hydronicVisual } from "../hydronic-values.ts";
|
||||
import { entity, hassOf } from "../entities/fixtures.ts";
|
||||
import { HydronicLayer } from "./live-hydronics.ts";
|
||||
import { circuitLayout } from "./hydronic-layout.ts";
|
||||
|
||||
test("live pumps animate reported operation, valve pointers follow visual inversion and floor/mount transforms stay attached", () => {
|
||||
let visible=true;
|
||||
@@ -20,3 +21,21 @@ test("live pumps animate reported operation, valve pointers follow visual invers
|
||||
visible=true; layer.set([{...spot,animate:false}]); assert.equal(layer.step(1050),false); assert.equal(rotor.rotation.z,0);
|
||||
layer.set([]); assert.equal(layer.group.children.length,0); layer.dispose(); assert.equal(scene.children.length,0);
|
||||
});
|
||||
|
||||
test("pump, valve and probe faces stay attached to actual inline bodies; pump state distinguishes on, off and missing feedback", () => {
|
||||
const scene=new Scene(),layer=new HydronicLayer(scene,()=>({y:0,dy:0,visible:true}));
|
||||
const item: Furniture={id:"inline",type:"heating_manifold",x:0,z:0,w:1.5,d:.35,h:1.1,rotation:0,variant:null,hydronic:{circuits:[{...newCircuit("c"),pump:{feedback:"sensor.pump"},valve:{feedback:"sensor.valve"}}]}};
|
||||
const h=hassOf([entity("sensor.pump","on",{symcon_value:true}),entity("sensor.valve","73",{symcon_value:73})]);
|
||||
const p=circuitLayout(item,item.hydronic!.circuits![0],0,1);
|
||||
const sync=()=>{layer.set([hydronicVisual(h,item,"f",0)]);layer.step(350);};sync();
|
||||
const root=layer.group.getObjectByName("hydronic-inline")!;
|
||||
const pump=root.getObjectByName("hydronic-pump-0") as Mesh, state=root.getObjectByName("hydronic-pumpState-0") as Mesh, valve=root.getObjectByName("hydronic-valve-0")!;
|
||||
assert.equal(pump.position.x,p.flowX);assert.equal(pump.position.y,p.pumpY);assert.ok(pump.position.z>p.pumpFront);
|
||||
assert.equal(valve.position.x,p.flowX);assert.equal(valve.position.y,p.valveY);assert.ok(valve.position.z>p.valveFront);
|
||||
assert.ok(root.children.filter((o)=>o.name.startsWith("hydronic-temperature")).every((o)=>o.position.y===p.temperatureY));
|
||||
const colour=()=> (Array.isArray(state.material)?state.material[0]:state.material) as import("three").MeshBasicMaterial;
|
||||
assert.equal(colour().color.getHex(),0x4b9639);
|
||||
h.states["sensor.pump"]={...h.states["sensor.pump"],attributes:{symcon_value:false}};sync();assert.equal(colour().color.getHex(),0xa82638);
|
||||
h.states["sensor.pump"]={...h.states["sensor.pump"],state:"unavailable"};sync();assert.equal(colour().color.getHex(),0x72787e);
|
||||
layer.dispose();
|
||||
});
|
||||
@@ -1,9 +1,10 @@
|
||||
import { BoxGeometry, Color, Group, Mesh, MeshBasicMaterial, SphereGeometry, type Scene } from "three";
|
||||
import { circuitX, hasPump, hasValve, hydronicConfig } from "../hydronic-model.ts";
|
||||
import { BoxGeometry, BufferGeometry, CircleGeometry, Color, Float32BufferAttribute, Group, Mesh, MeshBasicMaterial, SphereGeometry, type Scene } from "three";
|
||||
import { hasPump, hasValve, hydronicConfig } from "../hydronic-model.ts";
|
||||
import type { HydronicVisual } from "../hydronic-values.ts";
|
||||
import type { FloorLift } from "./live-energy.ts";
|
||||
import { circuitLayout } from "./hydronic-layout.ts";
|
||||
|
||||
interface Part { mesh: Mesh<BoxGeometry | SphereGeometry, MeshBasicMaterial>; kind: "pump" | "valve" | "temperature"; circuit?: number; probe?: number; temp?: number; circulation?: boolean }
|
||||
interface Part { mesh: Mesh<BufferGeometry, MeshBasicMaterial>; kind: "pump" | "pumpState" | "valve" | "temperature"; circuit?: number; probe?: number; temp?: number; circulation?: boolean }
|
||||
interface View { spot: HydronicVisual; group: Group; parts: Part[] }
|
||||
const heatColor = (value: number | null) => value === null ? new Color(0x69717c) : new Color().setHSL((1 - Math.max(0, Math.min(1, value / 85))) * .62, .8, .55);
|
||||
|
||||
@@ -29,19 +30,26 @@ export class HydronicLayer {
|
||||
}
|
||||
private build(spot: HydronicVisual): View {
|
||||
const group = new Group(), parts: Part[] = [], f = spot.item, h = hydronicConfig(f);
|
||||
const add = (x: number, y: number, z: number, r: number, kind: Part["kind"], data: Partial<Part> = {}) => {
|
||||
const mesh = new Mesh(kind === "temperature" ? new SphereGeometry(r, 10, 6) : new BoxGeometry(r * 1.6, r * .3, .012), new MeshBasicMaterial({ color: 0x69717c, depthWrite: true }));
|
||||
const add = (x: number, y: number, z: number, r: number, kind: Part["kind"], data: Partial<Part> = {}, geometry?: BufferGeometry) => {
|
||||
const mesh = new Mesh(geometry ?? (kind === "temperature" ? new SphereGeometry(r, 10, 6) : new BoxGeometry(r * 1.6, r * .3, .012)), new MeshBasicMaterial({ color: 0x69717c, depthWrite: true }));
|
||||
mesh.name = `hydronic-${kind}-${data.circulation ? "circulation" : data.circuit ?? data.probe ?? data.temp ?? 0}`;
|
||||
mesh.position.set(x, y, z); group.add(mesh); parts.push({ mesh, kind, ...data });
|
||||
};
|
||||
if (f.type === "heating_manifold") {
|
||||
const circuits = h.circuits ?? [], column = f.w * .8 / Math.max(1, circuits.length), r = Math.min(column * .35, f.h * .075);
|
||||
const circuits = h.circuits ?? [];
|
||||
circuits.forEach((c, i) => {
|
||||
const x = f.w * circuitX(i, circuits.length);
|
||||
if (hasPump(c)) { add(x, f.h * .6, f.d * .565, r * .8, "pump", { circuit: i }); add(x, f.h * .6, f.d * .57, r * .8, "pump", { circuit: i }); parts.at(-1)!.mesh.userData.angle = Math.PI / 2; }
|
||||
if (hasValve(c)) add(x, f.h * .43, f.d * .58, r * .65, "valve", { circuit: i });
|
||||
add(x - column * .22, f.h * .76, f.d * .57, Math.min(r * .32, .018), "temperature", { circuit: i, temp: 0 });
|
||||
add(x + column * .22, f.h * .25, f.d * .57, Math.min(r * .32, .018), "temperature", { circuit: i, temp: 1 });
|
||||
const p = circuitLayout(f,c,i,circuits.length);
|
||||
if (hasPump(c)) {
|
||||
add(p.flowX,p.pumpY,p.pumpFront+.001,p.pumpR*.84,"pumpState",{circuit:i},new CircleGeometry(p.pumpR*.84,24));
|
||||
const vertices: number[] = [];
|
||||
for (let j=0;j<3;j++) for (const [xx,yy] of [[0,.1],[.28,.18],[0,.73]]) {
|
||||
const a=j*Math.PI*2/3;vertices.push(p.pumpR*(xx*Math.cos(a)-yy*Math.sin(a)),p.pumpR*(xx*Math.sin(a)+yy*Math.cos(a)),0);
|
||||
}
|
||||
add(p.flowX,p.pumpY,p.pumpFront+.002,p.pumpR,"pump",{circuit:i},new BufferGeometry().setAttribute("position",new Float32BufferAttribute(vertices,3)));
|
||||
}
|
||||
if (hasValve(c)) add(p.flowX,p.valveY,p.valveFront+.003,p.valveR*.8,"valve",{circuit:i});
|
||||
add(p.flowGaugeX,p.temperatureY,p.gaugeFront+.001,p.gaugeR*.45,"temperature",{circuit:i,temp:0});
|
||||
add(p.returnGaugeX,p.temperatureY,p.gaugeFront+.001,p.gaugeR*.45,"temperature",{circuit:i,temp:1});
|
||||
});
|
||||
} else if (f.type === "buffer_tank") {
|
||||
(h.sensors ?? []).forEach((s, i) => add(0, f.h * (.1 + .8 * s.level), Math.min(f.w, f.d) * .46 + .025, .021, "temperature", { probe: i }));
|
||||
@@ -65,14 +73,15 @@ export class HydronicLayer {
|
||||
if (p.kind === "temperature") {
|
||||
const value = p.probe !== undefined ? spot.probes[p.probe]?.value : c ? p.temp === 0 ? c.flow : c.return : spot.temperatures[p.temp ?? 0];
|
||||
p.mesh.material.color.copy(heatColor(value ?? null));
|
||||
} else if (p.kind === "pump") {
|
||||
} else if (p.kind === "pump" || p.kind === "pumpState") {
|
||||
const running = c ? c.pump : p.circulation ? spot.circulation : spot.pump;
|
||||
p.mesh.material.color.set(running === null ? 0x89909a : running ? c?.cooling ? 0x50b8ff : 0x6fe1a2 : 0x465361);
|
||||
if (p.kind === "pumpState") { p.mesh.material.color.set(running === null ? 0x72787e : running ? 0x4b9639 : 0xa82638); continue; }
|
||||
p.mesh.material.color.set(c ? running === null ? 0xb2b7b9 : 0xe0e7d9 : running === null ? 0x89909a : running ? 0x6fe1a2 : 0x465361);
|
||||
p.mesh.rotation.z = Number(p.mesh.userData.angle ?? 0) + (running && spot.animate !== false ? now / 350 : 0);
|
||||
moving ||= l.visible && running === true && spot.animate !== false;
|
||||
} else {
|
||||
p.mesh.rotation.z = c?.valve === null || c?.valve === undefined ? 0 : c.valve / 100 * Math.PI / 2;
|
||||
p.mesh.material.color.set(c?.valve === null ? 0x89909a : c?.cooling ? 0x50b8ff : 0xf6b35b);
|
||||
p.mesh.material.color.set(c?.valve === null ? 0x89909a : c?.cooling ? 0x50b8ff : 0x8ec96a);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
// Close-up QA of the actual static builder and live layer: reference topology, running states and three-way/two-way/feed groups.
|
||||
import assert from "node:assert/strict";
|
||||
import { createServer } from "node:http";
|
||||
import { existsSync, mkdirSync } from "node:fs";
|
||||
import { join, resolve } from "node:path";
|
||||
import { build } from "esbuild";
|
||||
import puppeteer from "puppeteer-core";
|
||||
|
||||
const root=resolve(import.meta.dirname,".."),out=join(root,"preview/screenshots");mkdirSync(out,{recursive:true});
|
||||
const server=createServer((req,res)=>res.writeHead(200,{"content-type":"text/html; charset=utf-8"}).end('<!doctype html><html><head><style>body{margin:0;background:#171b1d;color:#d6dad9;font:14px system-ui}h1{position:absolute;top:20px;left:28px;font-size:18px;font-weight:500}canvas{display:block}p{position:absolute;bottom:15px;left:28px;color:#abb4b5}</style></head><body><h1>Heizkreis · Vorlauf / Rücklauf</h1><p>3D-Modell · Mischer, Pumpe und Temperaturfühler</p></body></html>'));
|
||||
await new Promise((done)=>server.listen(0,"127.0.0.1",done));
|
||||
let browser;
|
||||
try {
|
||||
const executablePath=[process.env.CHROME_PATH,"C:/Program Files/Google/Chrome/Application/chrome.exe","C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"].find((p)=>p&&existsSync(p));
|
||||
browser=await puppeteer.launch({executablePath,headless:true,args:["--use-angle=swiftshader","--enable-unsafe-swiftshader"]});
|
||||
const page=await browser.newPage(),errors=[];page.on("pageerror",(e)=>errors.push(String(e)));
|
||||
await page.setViewport({width:1100,height:960});await page.goto(`http://127.0.0.1:${server.address().port}`);
|
||||
const built=await build({stdin:{contents:`
|
||||
export { Scene, OrthographicCamera, WebGLRenderer, Mesh, MeshBasicMaterial, LineSegments, LineBasicMaterial, Color, Box3 } from "three";
|
||||
export { GeoBuffer, LineBuffer } from "./viewer/geo.ts";
|
||||
export { pushFurniture } from "./viewer/furniture.ts";
|
||||
export { HydronicLayer } from "./viewer/live-hydronics.ts";
|
||||
export { hydronicVisual } from "./hydronic-values.ts";
|
||||
export { circuitLayout } from "./viewer/hydronic-layout.ts";
|
||||
`,resolveDir:join(root,"frontend/src")},bundle:true,write:false,format:"iife",globalName:"HydraulicGeometry",logLevel:"silent"});
|
||||
await page.addScriptTag({content:built.outputFiles[0].text});
|
||||
await page.evaluate(()=>{
|
||||
const T=window.HydraulicGeometry,scene=new T.Scene(),renderer=new T.WebGLRenderer({antialias:true,preserveDrawingBuffer:true});renderer.setSize(innerWidth,innerHeight);renderer.setPixelRatio(1);renderer.setClearColor(0x171b1d,1);document.body.append(renderer.domElement);
|
||||
const base={id:"reference",type:"heating_manifold",x:0,z:0,w:1.15,d:.28,h:1.6,rotation:0,variant:null,hydronic:{circuits:[{id:"sg",name:"SG",kind:"heating",pump:{feedback:"sensor.pump"},valve:{feedback:"sensor.valve"},flow:"sensor.flow",return:"sensor.return"}]}};
|
||||
const hass={language:"de",symconObjects:[],states:{"sensor.pump":{entity_id:"sensor.pump",state:"on",attributes:{symcon_value:true}},"sensor.valve":{entity_id:"sensor.valve",state:"73",attributes:{symcon_value:73}},"sensor.flow":{entity_id:"sensor.flow",state:"28.6",attributes:{symcon_value:28.6,unit_of_measurement:"°C"}},"sensor.return":{entity_id:"sensor.return",state:"26.1",attributes:{symcon_value:26.1,unit_of_measurement:"°C"}}}};
|
||||
const layer=new T.HydronicLayer(scene,()=>({y:0,dy:0,visible:true}));
|
||||
let mesh,lines;const camera=new T.OrthographicCamera(-1.25,1.25,1.09,-1.09,.01,20);
|
||||
window.renderHydraulic=(circuits,front=false)=>{
|
||||
for(const o of [mesh,lines])if(o){scene.remove(o);o.geometry.dispose();o.material.dispose();}
|
||||
const item={...base,hydronic:{circuits},w:circuits.length===1?1.15:2.4,h:1.6},buf=new T.GeoBuffer(),edge=new T.LineBuffer(),shadow=new T.GeoBuffer();T.pushFurniture(buf,edge,shadow,item,0);
|
||||
mesh=new T.Mesh(buf.geometry(),new T.MeshBasicMaterial({vertexColors:true,color:new T.Color(1.6,1.6,1.6)}));lines=new T.LineSegments(edge.geometry(),new T.LineBasicMaterial({vertexColors:true,color:new T.Color(1.6,1.6,1.6)}));scene.add(mesh,lines);
|
||||
layer.set([T.hydronicVisual(hass,item,"f",0)]);layer.step(350);
|
||||
camera.position.set(front?0:.45,front?.8:1.03,4);camera.lookAt(0,.8,0);camera.updateProjectionMatrix();renderer.render(scene,camera);
|
||||
window.geometryItem=item;
|
||||
};
|
||||
window.geometryScene=scene;window.geometryHass=hass;window.geometryLayer=layer;window.geometryCircuit=base.hydronic.circuits[0];window.renderHydraulic(base.hydronic.circuits,true);
|
||||
});
|
||||
assert.ok(await page.evaluate(()=>{
|
||||
const T=window.HydraulicGeometry,f=window.geometryItem,p=T.circuitLayout(f,f.hydronic.circuits[0],0,1),g=window.geometryLayer.group.getObjectByName("hydronic-reference"),pump=g.getObjectByName("hydronic-pump-0"),valve=g.getObjectByName("hydronic-valve-0");
|
||||
return pump.position.x===p.flowX&&valve.position.x===p.flowX&&pump.position.y>valve.position.y&&p.pipes.some((s)=>s.kind==="mix");
|
||||
}),"front-face controls remain on the connected supply riser");
|
||||
await page.screenshot({path:join(out,"symcon-hydronic-reference-front.png")});
|
||||
await page.evaluate(()=>window.renderHydraulic([window.geometryCircuit]));
|
||||
await page.screenshot({path:join(out,"symcon-hydronic-reference-3d.png")});
|
||||
await page.evaluate(()=>{window.geometryHass.states["sensor.pump"].attributes.symcon_value=false;window.renderHydraulic([window.geometryCircuit]);});
|
||||
await page.screenshot({path:join(out,"symcon-hydronic-reference-stopped.png")});
|
||||
await page.evaluate(()=>{
|
||||
window.geometryHass.states["sensor.pump"].attributes.symcon_value=true;
|
||||
window.renderHydraulic([window.geometryCircuit,{...window.geometryCircuit,id:"two",valve_type:"two_way"},{...window.geometryCircuit,id:"feed",kind:"pump"}]);
|
||||
});
|
||||
assert.equal(await page.evaluate(()=>!!window.geometryLayer.group.getObjectByName("hydronic-valve-2")),false,"a feed pump never grows a mixer actuator");
|
||||
await page.screenshot({path:join(out,"symcon-hydronic-reference-types.png")});
|
||||
assert.deepEqual(errors,[]);console.log("OK: reference-oriented 3D circuit topology, attached controls, pump on/off, two-way bypass exclusion and valve-free feed group");
|
||||
}finally{await browser?.close();await new Promise((done)=>server.close(done));}
|
||||
@@ -76,6 +76,10 @@ try {
|
||||
};
|
||||
const circuit=()=>e.shadowRoot.querySelector('.nf-hydronic-circuit[data-circuit="c1"]');
|
||||
const pumpToggle=[...circuit().querySelectorAll("label.nf-check")].find((l)=>l.textContent.includes("Pumpe vorhanden"));pumpToggle.querySelector("input").click();await window.editorSettle();
|
||||
const valveType=()=>[...circuit().querySelectorAll("label.nf-field")].find((l)=>l.textContent.trim().startsWith("Ventilbauart")).querySelector("select");
|
||||
valveType().value="two_way";valveType().dispatchEvent(new Event("change",{bubbles:true}));await window.editorSettle();
|
||||
if(e._doc.floors[0].furniture.find((f)=>f.id==="manifold").hydronic.circuits[0].valve_type!=="two_way")throw new Error("Two-way valve selection did not persist");
|
||||
valveType().value="mixing";valveType().dispatchEvent(new Event("change",{bubbles:true}));await window.editorSettle();
|
||||
const valve=()=>circuit().querySelector(".nf-hydronic-control");valve().open=true;
|
||||
await window.pickHydronic(valve(),"Rückmeldung",604,"Ventil Ist");await window.pickHydronic(valve(),"Befehl",603,"Ventil Soll");
|
||||
[...valve().querySelectorAll("label.nf-check")].find((l)=>l.textContent.includes("3D umkehren")).querySelector("input").click();await window.editorSettle();
|
||||
|
||||
Reference in new issue
Block a user