use super::IfcAPI;
use crate::zero_copy::ZeroCopyMesh;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
impl IfcAPI {
#[wasm_bindgen(js_name = parseZeroCopy)]
pub fn parse_zero_copy(&self, content: String) -> ZeroCopyMesh {
use ifc_lite_core::{build_entity_index, EntityDecoder, EntityScanner};
use ifc_lite_geometry::{calculate_normals, GeometryRouter, Mesh};
let entity_index = build_entity_index(&content);
let mut scanner = EntityScanner::new(&content);
let mut decoder = EntityDecoder::with_index(&content, entity_index);
let router = GeometryRouter::with_units(&content, &mut decoder);
let mut meshes: Vec<Mesh> = Vec::with_capacity(2000);
while let Some((id, type_name, start, end)) = scanner.next_entity() {
if !ifc_lite_core::has_geometry_by_name(type_name) {
continue;
}
if let Ok(entity) = decoder.decode_at_with_id(id, start, end) {
if let Ok(mesh) = router.process_element(&entity, &mut decoder) {
if !mesh.is_empty() {
meshes.push(mesh);
}
}
}
}
let mut combined_mesh = Mesh::new();
combined_mesh.merge_all(&meshes);
if combined_mesh.normals.len() != combined_mesh.positions.len() {
calculate_normals(&mut combined_mesh);
}
ZeroCopyMesh::from(combined_mesh)
}
}