Skip to main content

ifc_lite_wasm/api/
export_hbjson.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
5//! WASM API: export_hbjson — IFC → Honeybee HBJSON (energy/daylight model) string.
6
7use super::IfcAPI;
8use wasm_bindgen::prelude::*;
9
10#[wasm_bindgen]
11impl IfcAPI {
12    /// Export the `IfcSpace` volumes in `content` as Honeybee **HBJSON** UTF-8 bytes.
13    ///
14    /// Returned as UTF-8 bytes (`Uint8Array`) so output is not capped by the
15    /// V8 max-string ceiling (~512 MB); decode with `TextDecoder` when a string
16    /// is genuinely needed.
17    ///
18    /// Rooms are built analytically from extruded-area profiles (watertight by construction);
19    /// faces are typed Floor / RoofCeiling / Wall with outward normals. The result loads via
20    /// `honeybee.model.Model.from_hbjson` and is ready for Ladybug Tools / Pollination.
21    ///
22    /// ```javascript
23    /// const api = new IfcAPI();
24    /// const hbjson = api.exportHbjson(ifcContent, "my_model");
25    /// ```
26    #[wasm_bindgen(js_name = exportHbjson)]
27    pub fn export_hbjson(&self, content: &[u8], name: String) -> Vec<u8> {
28        let opts = ifc_lite_export::HbjsonOptions { name, tolerance: 0.01 };
29        ifc_lite_export::export_hbjson(content, &opts).into_bytes()
30    }
31}