Skip to main content

ifc_lite_wasm/api/
export_obj.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_obj — IFC render geometry → Wavefront OBJ string.
6
7use super::IfcAPI;
8use wasm_bindgen::prelude::*;
9
10#[wasm_bindgen]
11impl IfcAPI {
12    /// Export the render geometry in `content` as Wavefront **OBJ** 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    /// `hidden` / `isolated` are express-id filters mirroring the viewer's visibility
19    /// state (empty `isolated` ⇒ all visible). Instanced type-library shapes are skipped.
20    ///
21    /// ```javascript
22    /// const obj = api.exportObj(ifcContent, true, new Uint32Array(), new Uint32Array());
23    /// ```
24    #[wasm_bindgen(js_name = exportObj)]
25    pub fn export_obj(
26        &self,
27        content: &[u8],
28        include_normals: bool,
29        hidden: &[u32],
30        isolated: &[u32],
31    ) -> Vec<u8> {
32        let opts = ifc_lite_export::ObjOptions {
33            include_normals,
34            hidden: hidden.to_vec(),
35            isolated: isolated.to_vec(),
36        };
37        ifc_lite_export::export_obj(content, &opts).into_bytes()
38    }
39}