No description
  • TypeScript 91.5%
  • C++ 5%
  • HTML 1.8%
  • JavaScript 0.7%
  • Python 0.4%
  • Other 0.5%
Find a file
Marcin Koziuk 7a639bf660 feat(viewer): the sun over the plain and gradient skies too
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>
2026-10-29 15:23:17 +01:00
.claude chore: preview configs for the library and BAG worktrees 2026-10-28 15:11:25 +01:00
apps/demo feat: placeable models (furnishing) with a CC0 starter library 2026-10-28 15:11:25 +01:00
converter feat: conversion progress that keeps moving, with time left, shown in the viewer 2026-10-22 16:43:59 +02:00
docs feat: placed-model helpers, free mount, scaling, tree target button 2026-10-28 16:27:07 +01:00
fixtures feat: initial kozijn spike 2026-09-30 10:44:20 +02:00
packages feat(viewer): the sun over the plain and gradient skies too 2026-10-29 15:23:17 +01:00
scripts feat: placed-model helpers, free mount, scaling, tree target button 2026-10-28 16:27:07 +01:00
wishlist feat: material library, paint mode and per-assignment texture placement 2026-10-22 20:33:58 +02:00
.gitattributes feat: initial kozijn spike 2026-09-30 10:44:20 +02:00
.gitignore chore: ignore the .idea folder 2026-10-22 16:44:09 +02:00
package.json feat: initial kozijn spike 2026-09-30 10:44:20 +02:00
pnpm-lock.yaml feat(viewer): physical sky and volumetric clouds test (takram) 2026-10-29 14:27:43 +01:00
pnpm-workspace.yaml feat(format): LD export from .kzp (kzpToRdf + kzp-to-rdf CLI) with parity check 2026-10-06 13:28:31 +02:00
README.md feat: converter service, phase 1 (@kozijn/converter-service) 2026-10-22 16:43:59 +02:00
tsconfig.base.json feat: initial kozijn spike 2026-09-30 10:44:20 +02:00

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 Docker
  • packages/format/ — .kzn spec and TypeScript reader
  • packages/viewer/ — three.js library (KozijnModel, Viewer, element adapters)
  • packages/app/ — the full viewer UI (React), mountable with createApp
  • packages/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 hosts
  • packages/converter-service/ — the converter as a self-hosted HTTP service (jobs, API keys, dedup) and its client
  • apps/demo/ — Vite demo app: the app on the fixture server
  • fixtures/ — 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 BatchedMesh geometry.
  • 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 renders REFINE_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 on medium).
  • Surface textures (textures graphics option, off by default): materials are classified by their IFC surface style name (Dutch/English/German keywords, SURFACE_RULES in surfaces.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 by scripts/surface-textures.py, 1.3 MB) are projected triplanar in model space (.kzn has no UVs) with their normal and roughness maps, per-kind relief strength (scaled by the textureRelief option); textureNormals: 'bump' derives the relief from height maps instead, scaled per kind to match the normal maps' strength; textureCavity darkens 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; textureColors blends to the textures' own colours (colour overrides always show). No measurable GPU cost on medium.
  • 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.