ifc_lite_processing/types/
mesh.rs1use serde::{Deserialize, Serialize};
8use std::collections::BTreeMap;
9
10#[derive(Debug, Clone, Serialize, Deserialize)]
14pub struct MeshTextureData {
15 pub rgba: Vec<u8>,
17 pub width: u32,
18 pub height: u32,
19 pub repeat_s: bool,
21 pub repeat_t: bool,
22}
23
24#[derive(Debug, Clone, Serialize, Deserialize)]
26pub struct MeshData {
27 pub express_id: u32,
29 pub ifc_type: String,
31 #[serde(skip_serializing_if = "Option::is_none")]
33 pub global_id: Option<String>,
34 #[serde(skip_serializing_if = "Option::is_none")]
36 pub name: Option<String>,
37 #[serde(skip_serializing_if = "Option::is_none")]
39 pub presentation_layer: Option<String>,
40 pub positions: Vec<f32>,
42 pub normals: Vec<f32>,
44 pub indices: Vec<u32>,
46 pub color: [f32; 4],
48 #[serde(skip_serializing_if = "Option::is_none")]
50 pub material_name: Option<String>,
51 #[serde(skip_serializing_if = "Option::is_none")]
53 pub geometry_item_id: Option<u32>,
54 #[serde(skip_serializing_if = "Option::is_none")]
57 pub properties: Option<BTreeMap<String, String>>,
58 #[serde(skip_serializing_if = "Option::is_none")]
61 pub uvs: Option<Vec<f32>>,
62 #[serde(skip_serializing_if = "Option::is_none")]
64 pub texture: Option<MeshTextureData>,
65}
66
67impl MeshData {
68 pub fn new(
70 express_id: u32,
71 ifc_type: String,
72 positions: Vec<f32>,
73 normals: Vec<f32>,
74 indices: Vec<u32>,
75 color: [f32; 4],
76 ) -> Self {
77 Self {
78 express_id,
79 ifc_type,
80 global_id: None,
81 name: None,
82 presentation_layer: None,
83 positions,
84 normals,
85 indices,
86 color,
87 material_name: None,
88 geometry_item_id: None,
89 properties: None,
90 uvs: None,
91 texture: None,
92 }
93 }
94
95 pub fn with_texture(mut self, uvs: Vec<f32>, texture: MeshTextureData) -> Self {
98 self.uvs = Some(uvs);
99 self.texture = Some(texture);
100 self
101 }
102
103 pub fn with_element_metadata(
105 mut self,
106 global_id: Option<String>,
107 name: Option<String>,
108 presentation_layer: Option<String>,
109 ) -> Self {
110 self.global_id = global_id;
111 self.name = name;
112 self.presentation_layer = presentation_layer;
113 self
114 }
115
116 pub fn with_style_metadata(
118 mut self,
119 material_name: Option<String>,
120 geometry_item_id: Option<u32>,
121 ) -> Self {
122 self.material_name = material_name;
123 self.geometry_item_id = geometry_item_id;
124 self
125 }
126
127 pub fn with_properties(mut self, properties: Option<BTreeMap<String, String>>) -> Self {
129 self.properties = properties;
130 self
131 }
132
133 pub fn vertex_count(&self) -> usize {
135 self.positions.len() / 3
136 }
137
138 pub fn triangle_count(&self) -> usize {
140 self.indices.len() / 3
141 }
142
143 pub fn is_empty(&self) -> bool {
145 self.positions.is_empty() || self.indices.is_empty()
146 }
147}