- TypeScript 91.5%
- C++ 5%
- HTML 1.8%
- JavaScript 0.7%
- Python 0.4%
- Other 0.5%
The sun layer (disc, glow, night) now also shows over the colour and gradient skies, as over a panorama; not in orthographic views, which show no sky. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> |
||
|---|---|---|
| .claude | ||
| apps/demo | ||
| converter | ||
| docs | ||
| fixtures | ||
| packages | ||
| scripts | ||
| wishlist | ||
| .gitattributes | ||
| .gitignore | ||
| package.json | ||
| pnpm-lock.yaml | ||
| pnpm-workspace.yaml | ||
| README.md | ||
| tsconfig.base.json | ||
kozijn
Fast web viewer for IFC models: an IfcOpenShell-based converter that writes the compact
.kzn format, and a three.js / TypeScript library that renders it.
converter/— C++ converter (IfcOpenShell 0.9, meshoptimizer), built with pixi inside Dockerpackages/format/—.kznspec and TypeScript readerpackages/viewer/— three.js library (KozijnModel,Viewer, element adapters)packages/app/— the full viewer UI (React), mountable withcreateApppackages/embed/— drive the viewer in an iframe with the same API (connect(iframe))packages/bundle/—kozijn.js, one self-contained script (window.Kozijn) with the app and the engine, for sandboxed hostspackages/converter-service/— the converter as a self-hosted HTTP service (jobs, API keys, dedup) and its clientapps/demo/— Vite demo app: the app on the fixture serverfixtures/— local test models (git-ignored)
Setup
Requires Node 20.19+, Docker, and pnpm (corepack enable, or npx pnpm@12).
pnpm install
pnpm convert fixtures/model.ifc # builds the converter image on first run → fixtures/model.kzn
pnpm dev # demo on http://localhost:5173, lists fixtures/*.kzn
pnpm convert --help lists the converter options; pnpm convert --rebuild rebuilds the image.
Converter development
The converter builds IfcOpenShell from source (pinned commit plus kozijn's patches, see
converter/ifcopenshell); all other dependencies come from
conda-forge through pixi, pinned in converter/pixi.lock. Docker is the
default way to build:
cd converter
docker build --target env -t kozijn-converter-env .
docker run --rm -v "$PWD":/converter -v kozijn-pixi:/converter/.pixi kozijn-converter-env pixi run build
The first build compiles IfcOpenShell (about 20 minutes). After that the kozijn-pixi volume
and converter/build/ make rebuilds incremental. With pixi installed locally, pixi run build
works natively too, Windows included.
Geometry kernel
The default kernel is hybrid-passthrough-opencascade. Geometry that is already tessellated in
the IFC (faceted B-reps, polygonal face sets, polygonal extrusions) is triangulated directly by
IfcOpenShell's passthrough kernel; curved geometry, and products with openings to cut, go
through OCCT. Rebuilding tessellated input as OCCT B-reps is what made large faceted exports
take minutes and run out of memory (AMS-GP-BWK: 54 s / 4.4 GB → 4 s / 1.9 GB, with the same
geometry per element). --kernel opencascade forces OCCT for everything.
This relies on two IfcOpenShell patches in converter/ifcopenshell/patches/.
IfcSpace is included by default (translucent, no edges); --no-spaces drops it.
IfcOpeningElement is kept in the IFC data (entities without geometry, with the voids/fills
relations, e.g. for the sum table); --no-openings drops it.
Design notes
- Merged vs. instanced is decided in the converter: repeated geometry is instanced when
that saves at least
--min-saved-vertices; everything else is merged into per-storey chunks. Instance groups span storeys (one draw per shape); levels hide their instances through the element state instead of the storey's scene group. Repeats are found by a shape hash (vertex positions at 0.1 mm, materials, triangle count and area-weighted normal) relative to each mesh's own origin, not only by IFC representation reuse. That catches Revit's one-off geometry baked at world coordinates, whose copies differ in vertex order and in the triangulation of near-degenerate faces (klimaatplafond: 88 MB → 4.8 MB). - Element state (hidden, selected, highlighted, color override) lives in one RGBA8 texture
indexed by element. Changes touch only the changed texels and work identically for merged,
instanced and
BatchedMeshgeometry. - Levels (
showLevels) cut the models above the active level by storey group, and handle roofs and ceilings ("covers") per element: covers belong to the level their underside lies in (or, optionally, their IFC storey), so misassigned ceilings and roof slabs above the cut hide with it, and lifting the lid hides the active level's own covers to look into it. - Rendering always goes through an offscreen target with 4x MSAA and a 32-bit float depth buffer: with reversed depth that keeps ~1e-7 relative precision, where the canvas's 24-bit buffer had metre-sized depth steps at site scale (the map covered ground floors).
- Graphics options (
Viewer.setGraphics, all optional): a contact shadow under the models (rendered from below on changes only; opacity and size), light and reflections from the gradient or daylight sky, glass shading (Fresnel opacity; IfcSpace is exempt through an element flag), distance haze that also blends the sky's horizon, a polished floor reflection without a map (one extra half-resolution render per frame; its colour follows the ground lighting under the daylight sky, so it darkens at dusk and night), bloom for highlights, colour grading and tilt-shift. - Ambient occlusion (
setAmbientOcclusion, N8AO): radius, intensity, falloff, threshold (minimum occluding depth difference), colour, sample quality including N8AO's neural denoiser modes, half resolution, and an AO-only view for tuning. - Progressive refinement (
refine, on by default): 120 ms after the view settles, the viewer rendersREFINE_SAMPLES(32) more frames with a subpixel-jittered projection (Halton 2,3), the sun moved over a 0.5° disc (shadow map re-rendered) and N8AO's noise rotated, and averages them in linear HDR before bloom and tone mapping: supersampled edges, lines and textures, soft sun shadows, smooth AO (from the 5th sample without N8AO's denoiser, so the average converges crisper). Any change cancels it; nothing runs while moving or after the last sample (~0.25 s onmedium). - Surface textures (
texturesgraphics option, off by default): materials are classified by their IFC surface style name (Dutch/English/German keywords,SURFACE_RULESinsurfaces.ts) into brick, concrete, plaster, wood, roof tiles, tiles, metal, stone, paving, asphalt, grass and gravel; "roof" names get tiles on pitched faces and flat roofing on flat ones. Names that match no rule fall back to the element's IFC class (ELEMENT_RULES: roofs, walls, slabs, site…; a per-element R8 texture); glass, plastics and insulation stay plain. CC0 ambientCG textures (packages/viewer/assets/surfaces, built byscripts/surface-textures.py, 1.3 MB) are projected triplanar in model space (.kznhas no UVs) with their normal and roughness maps, per-kind relief strength (scaled by thetextureReliefoption);textureNormals: 'bump'derives the relief from height maps instead, scaled per kind to match the normal maps' strength;textureCavitydarkens the recesses (where a height map lies below its average: mortar joints, gaps, grooves), which shows the relief in shade too. By default they shade the IFC colour;textureColorsblends to the textures' own colours (colour overrides always show). No measurable GPU cost onmedium. - Colors come from a material table texture indexed per vertex, so PBR parameters vary per IFC material within one draw call.
- ElementAdapter implementations (
MergedAdapter,InstancedAdapter,BatchedAdapter) cover the operations that do depend on storage: picking, per-element triangles, extraction.
Known limitations
Rough edges of the current MVP, to pick up later:
- Map tiles (3d-tiles-renderer on the WGS84 ellipsoid): Web Mercator XYZ imagery only, and tile vertices are in Earth-centred coordinates, so the ground has ~1 m float precision.
- Shadows: one shadow map covers all visible models, so shadows get coarse on large sites (the 1.5 km Schiphol set). Cascaded shadow maps would fix this.
- Heights: models keep their IFC zero at scene height 0 and the map sits just below the lowest ground floor (found by storey name, else the storey nearest zero; overridable). Absolute heights (NAP, OrthogonalHeight, terrain) are ignored, so models whose IFC zeros differ are not levelled against each other.
- Geocoding: the demo uses Nominatim, whose usage policy only allows light, user-triggered searches; production needs another geocoder.
- Sun panel: date and time are in the browser's time zone, not the site's.
- IfcSite lat/lon placements are approximate (exporters often put them tens of metres off); IfcMapConversion or RD coordinates win when present.
- BatchedMesh mode is unused and can exhaust GPU memory in ANGLE/Metal with many models; merged + instanced is the supported path.