How thatopen/engine_web-ifc works
Project Type and Purpose
• This is an open-source, cross-platform library (“web-ifc”) for reading and writing IFC (Industry Foundation Classes) BIM files at native (C++/WASM) speeds from JavaScript/TypeScript environments (browser and Node.js).
• Purpose: Provide a high-performance core (in C++) compiled to WebAssembly, plus JS/TS wrappers and schema generators to let web and Node applications load, parse, query, and export IFC data.
File Structure Analysis
• Top-level:
• Dockerfile, CI/CD configs (.github/workflows), Node configs (package.json, tsconfig.json), LICENSE, README.
• examples/ – usage demos in Node.js, browser viewer, TypeScript samples.
• src/ – three main subfolders:
– cpp/ – the C++ codebase organized into parsing, schema, model management, geometry, boolean ops, and Wasm entrypoints.
– schema-generator/ – TS scripts that generate schema interfaces/types from IFC EXPRESS files.
– ts/ – public TypeScript wrapper (web-ifc-api.ts) and helper modules (log, properties).
• dist/ (output after build) contains .wasm binaries and JS wrappers.
• tests/ – unit, functional, regression tests using Jest and custom scripts.
README Insights
• Build pipeline:
– Requires Node, NPM, Emscripten, CMake (and optional MinGW on Windows).
– npm scripts: setup-env, build-release/debug, dev server, regression tests.
– Outputs: web-ifc.wasm/.mt/.node, web-ifc-api.js/.d.ts, helpers, schema typings, worker script.
• Usage flow:
– JS/TS code calls IfcAPI.Init(), OpenModel, geometry/property fetch, CloseModel.
a. Main Components
1. Development Environment
• Node.js + NPM
• Emscripten & CMake toolchain
• TypeScript compiler (tsc)
2. Build Pipeline
• schema-generator TS scripts → generates IFC schema TS definitions
• CMake + Emscripten → compiles C++ core → multiple WASM binaries
• Wrappers bundling → web-ifc-api.js, web-ifc-api-node.js, worker scripts
3. Core Library at Runtime
• JavaScript/TypeScript Layer
• web-ifc-api.js (browser)
• web-ifc-api-node.js (Node)
• WebAssembly Layer
• web-ifc.wasm (single-thread)
• web-ifc-mt.wasm + web-ifc-mt.worker.js (multithread)
• web-ifc-node.wasm
• C++ Modules inside WASM
• Parsing (IfcLoader, token streams)
• Model Manager (ModelManager)
• Geometry Processor & Loader
• Schema Manager (IfcSchemaManager)
• Boolean & geometry utility operations
4. Consumers and Integrations
• Examples (Node script, browser viewer)
• Third-party libs (e.g., web-ifc-three)
• Tests (functional & regression feeding IFC files)
• CI/CD pipeline running build, tests, publish.
b. Relationships & Data Flow
• Developer invokes npm run build → schema-generator & CMake/Emscripten → produces WASM + JS wrappers.
• At runtime: App code → web-ifc-api.js → loads appropriate WASM (via dynamic import or worker) → calls into C++ modules → returns geometry/properties to JS.
• Tests & examples drive the API similarly, feeding IFC files (binary) into OpenModel and consuming outputs.
c. Architectural Patterns
• Layered architecture: TS/JS API layer on top of WASM layer, on top of C++ core modules.
• Build-time code generation (schema-generator) to derive types and interfaces.
• Multi-build targets (browser, node, multithread).
• Modular C++: separation between parsing, schema, model management, geometry operations.
d. Key Technologies & Frameworks
• Emscripten + CMake (WASM build)
• TypeScript (schema-generator, API)
• Jest (testing)
• npm scripts for orchestration
• Web Workers (multithreading in browser)