use super::IfcAPI;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub struct ProfileEntryJs {
express_id: u32,
ifc_type: String,
outer_points: Vec<f32>,
hole_counts: Vec<u32>,
hole_points: Vec<f32>,
transform: [f32; 16],
extrusion_dir: [f32; 3],
extrusion_depth: f32,
model_index: u32,
}
#[wasm_bindgen]
impl ProfileEntryJs {
#[wasm_bindgen(getter, js_name = expressId)]
pub fn express_id(&self) -> u32 {
self.express_id
}
#[wasm_bindgen(getter, js_name = ifcType)]
pub fn ifc_type(&self) -> String {
self.ifc_type.clone()
}
#[wasm_bindgen(getter, js_name = outerPoints)]
pub fn outer_points(&self) -> js_sys::Float32Array {
js_sys::Float32Array::from(&self.outer_points[..])
}
#[wasm_bindgen(getter, js_name = holeCounts)]
pub fn hole_counts(&self) -> js_sys::Uint32Array {
js_sys::Uint32Array::from(&self.hole_counts[..])
}
#[wasm_bindgen(getter, js_name = holePoints)]
pub fn hole_points(&self) -> js_sys::Float32Array {
js_sys::Float32Array::from(&self.hole_points[..])
}
#[wasm_bindgen(getter)]
pub fn transform(&self) -> js_sys::Float32Array {
js_sys::Float32Array::from(&self.transform[..])
}
#[wasm_bindgen(getter, js_name = extrusionDir)]
pub fn extrusion_dir(&self) -> js_sys::Float32Array {
js_sys::Float32Array::from(&self.extrusion_dir[..])
}
#[wasm_bindgen(getter, js_name = extrusionDepth)]
pub fn extrusion_depth(&self) -> f32 {
self.extrusion_depth
}
#[wasm_bindgen(getter, js_name = modelIndex)]
pub fn model_index(&self) -> u32 {
self.model_index
}
}
impl From<ifc_lite_geometry::ExtractedProfile> for ProfileEntryJs {
fn from(p: ifc_lite_geometry::ExtractedProfile) -> Self {
Self {
express_id: p.express_id,
ifc_type: p.ifc_type,
outer_points: p.outer_points,
hole_counts: p.hole_counts,
hole_points: p.hole_points,
transform: p.transform,
extrusion_dir: p.extrusion_dir,
extrusion_depth: p.extrusion_depth,
model_index: p.model_index,
}
}
}
#[wasm_bindgen]
pub struct ProfileCollection {
entries: Vec<ProfileEntryJs>,
}
#[wasm_bindgen]
impl ProfileCollection {
#[wasm_bindgen(getter)]
pub fn length(&self) -> usize {
self.entries.len()
}
pub fn get(&self, index: usize) -> Option<ProfileEntryJs> {
self.entries.get(index).map(|e| ProfileEntryJs {
express_id: e.express_id,
ifc_type: e.ifc_type.clone(),
outer_points: e.outer_points.clone(),
hole_counts: e.hole_counts.clone(),
hole_points: e.hole_points.clone(),
transform: e.transform,
extrusion_dir: e.extrusion_dir,
extrusion_depth: e.extrusion_depth,
model_index: e.model_index,
})
}
}
#[wasm_bindgen]
impl IfcAPI {
#[wasm_bindgen(js_name = extractProfiles)]
pub fn extract_profiles(&self, content: String, model_index: u32) -> ProfileCollection {
let raw = ifc_lite_geometry::extract_profiles(&content, model_index);
ProfileCollection {
entries: raw.into_iter().map(ProfileEntryJs::from).collect(),
}
}
}