npm.io
1.9.0 • Published 3d ago

@ifc-lite/clash

Licence
MPL-2.0
Version
1.9.0
Deps
7
Size
756 kB
Vulns
0
Weekly
0
Stars
340

@ifc-lite/clash

Clash detection for IFC-Lite. A representation-agnostic core engine plus thin, version-specific source adapters.

  • The core (@ifc-lite/clash) operates on ClashElement[]{ key, ref, tag, bounds, positions, indices } — and never imports @ifc-lite/parser/@ifc-lite/query. STEP/IFC4 and IFC5/USD are just adapters that produce those elements.
  • Broad phase: BVH (@ifc-lite/spatial). Narrow phase: exact triangle–triangle intersection and exact triangle–triangle minimum distance — no decimation.
  • Results classify as hard (interpenetration), clearance (within a gap), or touch (within tolerance, suppressed by default).

Installation

npm install @ifc-lite/clash

Usage

import { createClashEngine, CLASH_RULE_PRESETS } from '@ifc-lite/clash';
import { elementsFromStep } from '@ifc-lite/clash/step';

const { elements, exclusions } = elementsFromStep({ store, meshes, modelId: 'm1' });
const engine = createClashEngine({ backend: 'auto' });
const result = await engine.run(elements, [
  { id: 'mep-str', name: 'MEP vs Structure', a: 'IfcPipe*|IfcDuct*', b: 'IfcBeam|IfcColumn|IfcSlab', mode: 'hard' },
], { exclusions });

console.log(result.summary.total, 'clashes');

If your host has already shifted mesh.expressId into a federated global id space (as the viewer's loader does for every model past the first) while the IfcDataStore keeps local ids, pass that shift as meshIdOffset so the adapter can address the store correctly:

elementsFromStep({ store, meshes, modelId, federation, meshIdOffset: model.idOffset });

ClashElement.key is the element's IFC GlobalId. An element that has none — a malformed root, or every element of a GLB-sourced model, whose store carries no IFC entities — falls back to expressid:<encoded modelId>:<expressId>. Express ids are only unique within a model, so the model id is part of that key: clashReviewKey and the viewer's element-pair exclusions key on the element key alone, and an unqualified fallback would let a review or an exclusion set on one model apply to another model's element. That fallback is stable only for as long as the host's modelId is (in the viewer it is a per-load uuid).

Includes the TypeScript reference engine, a Rust→WASM kernel kept in lockstep by a differential test (opt-in via @ifc-lite/clash/wasm; backend: 'auto' currently resolves to the TS engine), STEP and IFC5/USD source adapters, spatial grouping, duplicate-element detection, clash review status (open / resolved / accepted) that round-trips through BCF, and a sensible BCF bridge (grouped topics, deterministic GUIDs, optional snapshots). Surfaced through the viewer's clash panel, the ifc-lite clash CLI, the MCP clash_check / clash_matrix tools, and the SDK clash namespace.

Docs

See the ifc-lite docs and the design rationale in clash-detection-plan.md.

License

MPL-2.0

Keywords