Skip to main content

Crate ifc_lite_wasm

Crate ifc_lite_wasm 

Source
Expand description

§IFC-Lite WebAssembly Bindings

JavaScript/TypeScript API for IFC-Lite built with wasm-bindgen.

§Overview

This crate provides WebAssembly bindings for IFC-Lite, enabling high-performance IFC parsing and geometry processing in web browsers.

§Features

  • Zero-Copy Buffers: Direct GPU buffer access without data copying
  • Streaming Parse: Event-based parsing with progress callbacks
  • Small Bundle: ~60 KB WASM binary, ~20 KB gzipped

§JavaScript Usage

import init, { IfcAPI, version } from 'ifc-lite-wasm';

// Initialize WASM
await init();

// Create API instance
const api = new IfcAPI();

// Parse IFC file
const buffer = await fetch('model.ifc').then(r => r.arrayBuffer());
const result = api.parse(new Uint8Array(buffer));

console.log(`Parsed ${result.entityCount} entities`);
console.log(`Version: ${version()}`);

§Streaming Parse

const result = await api.parseStreaming(data, (event) => {
  if (event.type === 'progress') {
    console.log(`Progress: ${event.percent}%`);
  }
});

§Zero-Copy Memory Access

For optimal performance, mesh data can be accessed directly from WASM memory:

const positions = api.getPositionsBuffer(expressId);
const view = positions.asFloat32Array();

// Upload directly to GPU without copying
device.queue.writeBuffer(gpuBuffer, 0, view);

Structs§

GpuGeometry
GPU-ready geometry stored in WASM linear memory
GpuInstancedGeometry
GPU-ready instanced geometry for efficient rendering of repeated shapes
GpuInstancedGeometryCollection
Collection of GPU-ready instanced geometries
GpuInstancedGeometryRef
Reference to geometry in collection for zero-copy access This avoids cloning when accessing geometry data
GpuMeshMetadata
Metadata for a single mesh within the GPU geometry buffer
IfcAPI
Main IFC-Lite API
InstanceData
Instance data for instanced rendering
InstancedGeometry
Instanced geometry - one geometry definition with multiple instances
InstancedMeshCollection
Collection of instanced geometries
MeshCollection
Collection of mesh data for returning multiple meshes
MeshDataJs
Individual mesh data with express ID and color (matches MeshData interface)
SymbolicCircle
A 2D circle/arc for symbolic representations
SymbolicPolyline
A single 2D polyline for symbolic representations (Plan, Annotation, FootPrint) Points are stored as [x1, y1, x2, y2, …] in 2D coordinates
SymbolicRepresentationCollection
Collection of symbolic representations for an IFC model
ZeroCopyMesh
Zero-copy mesh that exposes pointers to WASM memory

Functions§

get_memory
Get WASM memory to allow JavaScript to create TypedArray views
init
Initialize the WASM module.
init_panic_hook
Set panic hook for better error messages in the browser
set_panic_hook
Set the console.error panic hook the first time this is called. Subsequent invocations do nothing.
version
Get the version of IFC-Lite.