truck-meshalgo: Kennwerte (Volumen, Oberflaeche, Schwerpunkt, Dichtheit) im Objekt-Panel, Kollisionspruefung (WASM)
This commit is contained in:
1 parent
3e249ed34a
commit
501ea13a7a
8 files changed
+259
-1
No files matched your search
@@ -76,4 +76,17 @@ describe("trucksolid-WASM", () => {
|
||||
expect(vols[0]).toBeCloseTo((5 * 2.6 - 1.2 * 1.2) * 0.3, 1); // Wand
|
||||
expect(vols[1]).toBeCloseTo(Math.PI * 2, 1); // Zylinder
|
||||
});
|
||||
|
||||
it("Kennwerte + Kollision (truck-meshalgo)", () => {
|
||||
const cub = (x0: number, y0: number, z0: number, x1: number, y1: number, z1: number) => ({ kind: "cuboid", min: [x0, y0, z0], max: [x1, y1, z1] });
|
||||
const p = JSON.parse(mod.solid_props(JSON.stringify({ spec: cub(0, 0, 0, 2, 1, 3) })));
|
||||
expect(p.volume).toBeCloseTo(6, 6);
|
||||
expect(p.area).toBeCloseTo(22, 6);
|
||||
expect(p.closed).toBe(true);
|
||||
const c = JSON.parse(mod.solid_clash(JSON.stringify({ a: cub(0, 0, 0, 2, 1, 3), b: cub(1, 0.5, 1, 3, 2, 2) })));
|
||||
expect(c.colliding).toBe(true);
|
||||
expect(c.overlap_volume).toBeCloseTo(0.5, 5);
|
||||
const far = JSON.parse(mod.solid_clash(JSON.stringify({ a: cub(0, 0, 0, 1, 1, 1), b: cub(5, 5, 5, 6, 6, 6) })));
|
||||
expect(far.colliding).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -120,6 +120,41 @@ export async function buildSolidMesh(spec: SolidSpec, tol = 0.01): Promise<Extru
|
||||
return JSON.parse(m.build_solid_mesh(JSON.stringify({ spec, tol }))) as ExtrudedMesh;
|
||||
}
|
||||
|
||||
/** Kennwerte eines Körpers (Meter / m² / m³). */
|
||||
export interface SolidProps {
|
||||
volume: number;
|
||||
area: number;
|
||||
centroid: [number, number, number];
|
||||
/** Wasserdicht (geschlossenes, orientiertes Mesh). */
|
||||
closed: boolean;
|
||||
min: [number, number, number];
|
||||
max: [number, number, number];
|
||||
}
|
||||
|
||||
export async function solidProps(spec: SolidSpec, tol = 0.005): Promise<SolidProps> {
|
||||
const m = await getModule();
|
||||
return JSON.parse(m.solid_props(JSON.stringify({ spec, tol }))) as SolidProps;
|
||||
}
|
||||
|
||||
export interface ClashResult {
|
||||
colliding: boolean;
|
||||
/** Durchdringungslinien [x0,y0,z0,x1,y1,z1]. */
|
||||
lines: Array<[number, number, number, number, number, number]>;
|
||||
/** Volumen der Durchdringung (m³), falls berechenbar. */
|
||||
overlapVolume: number | null;
|
||||
}
|
||||
|
||||
/** Kollisionsprüfung zweier Körper (truck-meshalgo). */
|
||||
export async function solidClash(a: SolidSpec, b: SolidSpec, tol = 0.01): Promise<ClashResult> {
|
||||
const m = await getModule();
|
||||
const r = JSON.parse(m.solid_clash(JSON.stringify({ a, b, tol }))) as {
|
||||
colliding: boolean;
|
||||
lines: ClashResult["lines"];
|
||||
overlap_volume: number | null;
|
||||
};
|
||||
return { colliding: r.colliding, lines: r.lines, overlapVolume: r.overlap_volume };
|
||||
}
|
||||
|
||||
/** Exportiert Körper als STEP-Text (ISO 10303-42 B-Rep). */
|
||||
export async function exportStepSolids(
|
||||
solids: SolidSpec[],
|
||||
|
||||
@@ -712,6 +712,10 @@ export const de = {
|
||||
"objinfo.extrudedSolid.cornerRadius": "Eckenradius",
|
||||
"objinfo.extrudedSolid.chamfer": "Fase",
|
||||
"objinfo.extrudedSolid.brep": "B-Rep-Körper",
|
||||
"objinfo.extrudedSolid.volume": "Volumen",
|
||||
"objinfo.extrudedSolid.surface": "Oberfläche",
|
||||
"objinfo.extrudedSolid.centroid": "Schwerpunkt",
|
||||
"objinfo.extrudedSolid.notClosed": "Körper nicht wasserdicht",
|
||||
"objinfo.extrudedSolid.area": "Grundfläche",
|
||||
"objinfo.extrudedSolid.floor": "Geschoss",
|
||||
"objinfo.rotate": "Drehen",
|
||||
|
||||
@@ -708,6 +708,10 @@ export const en: Record<TranslationKey, string> = {
|
||||
"objinfo.extrudedSolid.cornerRadius": "Corner radius",
|
||||
"objinfo.extrudedSolid.chamfer": "Chamfer",
|
||||
"objinfo.extrudedSolid.brep": "B-rep solid",
|
||||
"objinfo.extrudedSolid.volume": "Volume",
|
||||
"objinfo.extrudedSolid.surface": "Surface",
|
||||
"objinfo.extrudedSolid.centroid": "Centroid",
|
||||
"objinfo.extrudedSolid.notClosed": "Solid is not watertight",
|
||||
"objinfo.extrudedSolid.area": "Footprint area",
|
||||
"objinfo.extrudedSolid.floor": "Floor",
|
||||
"objinfo.rotate": "Rotate",
|
||||
|
||||
@@ -14,7 +14,9 @@
|
||||
// Bezeichner englisch, UI-Text/Kommentare deutsch (CONVENTIONS.md). Alle sichtbaren
|
||||
// Texte über t(...).
|
||||
|
||||
import { useState } from "react";
|
||||
import { solidProps } from "../engine/truckSolid";
|
||||
import type { SolidProps, SolidSpec } from "../engine/truckSolid";
|
||||
import { useEffect, useState } from "react";
|
||||
// Anzeige-Fallbacks für die Öffnungs-Linien-Übersteuerung (LineStyleRow) —
|
||||
// dieselben Werte wie POCHE_STROKE/SYMBOL_HAIRLINE_MM in plan/generatePlan.ts
|
||||
// (reine UI-Default-Anzeige, kein Re-Export nötig).
|
||||
@@ -637,6 +639,46 @@ export function DetailRefSection({
|
||||
);
|
||||
}
|
||||
|
||||
/** Volumen/Oberfläche/Schwerpunkt aus truck (asynchron, aus dem tessellierten B-Rep). */
|
||||
function SolidPropsRows({ spec }: { spec: SolidSpec | null }) {
|
||||
const [props, setProps] = useState<SolidProps | null>(null);
|
||||
const key = JSON.stringify(spec);
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
setProps(null);
|
||||
if (!spec) return;
|
||||
solidProps(spec).then(
|
||||
(p) => alive && setProps(p),
|
||||
() => alive && setProps(null),
|
||||
);
|
||||
return () => {
|
||||
alive = false;
|
||||
};
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [key]);
|
||||
if (!props) return null;
|
||||
const f = (v: number, d = 2) => v.toLocaleString(undefined, { minimumFractionDigits: d, maximumFractionDigits: d });
|
||||
return (
|
||||
<>
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.extrudedSolid.volume")}</span>
|
||||
<span className="objinfo-fval">{f(props.volume)} m³</span>
|
||||
</div>
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.extrudedSolid.surface")}</span>
|
||||
<span className="objinfo-fval">{f(props.area)} m²</span>
|
||||
</div>
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.extrudedSolid.centroid")}</span>
|
||||
<span className="objinfo-fval">
|
||||
{f(props.centroid[0])} / {f(props.centroid[1])} / {f(props.centroid[2])}
|
||||
</span>
|
||||
</div>
|
||||
{!props.closed && <div className="objinfo-field objinfo-warn">{t("objinfo.extrudedSolid.notClosed")}</div>}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
// ── Extrusions-Attribut-Abschnitt (truck-Integration) ───────────────────────
|
||||
// Höhe editierbar (löst Re-Extrusion aus); Grundfläche + Geschoss read-only.
|
||||
export function ExtrudedSolidSection({
|
||||
@@ -668,6 +710,8 @@ export function ExtrudedSolidSection({
|
||||
/>
|
||||
</div>
|
||||
|
||||
<SolidPropsRows spec={solid.spec} />
|
||||
|
||||
{solid.brepLabel && (
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.extrudedSolid.brep")}</span>
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
//
|
||||
// Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
|
||||
|
||||
import { extrudedSolidSpec } from "../plan/extrudedSolidSpec";
|
||||
import type { SolidSpec } from "../engine/truckSolid";
|
||||
import {
|
||||
ceilingThickness,
|
||||
flattenCategories,
|
||||
@@ -321,6 +323,8 @@ export interface ExtrudedSolidInfo {
|
||||
brepLabel?: string;
|
||||
/** Grundfläche des Profils (m²). */
|
||||
area: number;
|
||||
/** B-Rep-Beschreibung (Weltkoordinaten) für Kennwerte — `null`, wenn truck keine hat. */
|
||||
spec: SolidSpec | null;
|
||||
/** Geschoss, dessen `baseElevation` die UK des Körpers bestimmt. */
|
||||
floorId: string;
|
||||
floorName: string;
|
||||
@@ -1052,6 +1056,7 @@ function extrudedSolidSelection(project: Project, s: ExtrudedSolid): Selection {
|
||||
chamfer: s.chamfer ?? 0,
|
||||
...(s.brep ? { brepLabel: s.brep.label ?? "B-Rep" } : {}),
|
||||
area: polygonArea(s.points),
|
||||
spec: extrudedSolidSpec(s, floor?.baseElevation ?? 0),
|
||||
floorId: s.levelId,
|
||||
floorName: floor?.name ?? s.levelId,
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user