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[],
|
||||
|
||||
Reference in new issue
Block a user