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§

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)
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.