ifc_lite_processing/processor/request.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//! [`ProcessingRequest`]: everything a caller can ask of one pass.
6//!
7//! One value type for what used to be spread over eleven entry points: the
8//! opening filter, tessellation quality, batching, which optional phases run,
9//! the id allow-list, an injected entity index and a cancel flag. A new pass
10//! input is a field here, never a new `process_geometry_*` function.
11
12use super::OpeningFilterMode;
13use ifc_lite_core::EntityIndex;
14use ifc_lite_geometry::TessellationQuality;
15use std::collections::HashSet;
16use std::sync::atomic::AtomicBool;
17use std::sync::Arc;
18
19/// How the meshing loop chunks its jobs, and in what order.
20///
21/// Chunking is a delivery property: it decides how often the sink hears
22/// `on_batch`, never what the result holds.
23#[non_exhaustive]
24#[derive(Debug, Clone, Copy, PartialEq, Eq)]
25pub struct Batching {
26 /// Jobs in the very first chunk.
27 pub initial: usize,
28 /// Jobs in every later chunk.
29 pub throughput: usize,
30 /// Mesh cheap, high-yield element classes first.
31 pub fast_first: bool,
32}
33
34impl Batching {
35 /// `initial` jobs first, then `throughput` per chunk, in file order.
36 pub fn new(initial: usize, throughput: usize) -> Self {
37 Self { initial, throughput, fast_first: false }
38 }
39
40 /// One chunk holding every job.
41 pub fn single_chunk() -> Self {
42 Self::new(usize::MAX, usize::MAX)
43 }
44
45 /// Sort jobs by element-class priority (walls and slabs first) before chunking.
46 pub fn fast_first(mut self, fast_first: bool) -> Self {
47 self.fast_first = fast_first;
48 self
49 }
50}
51
52/// The optional phases of a pass. All on except the bootstrap and the
53/// finishes, as before.
54#[non_exhaustive]
55#[derive(Debug, Clone, Copy, PartialEq, Eq)]
56pub struct Features {
57 /// Resolve space/zone property sets on the first-frame path.
58 pub properties: bool,
59 /// Resolve IfcPresentationLayerAssignment on the first-frame path.
60 pub presentation_layers: bool,
61 /// Emit [`ProcessingSink::on_bootstrap`](super::ProcessingSink::on_bootstrap)
62 /// once the scan is done.
63 pub quick_metadata_bootstrap: bool,
64 /// Emit [`ProcessingSink::on_finishes`](super::ProcessingSink::on_finishes)
65 /// before every batch: each mesh's IFC-authored finish (#5984), joined from
66 /// the pass's own scan instead of a second read of the file. Instance
67 /// finishes are delivered by
68 /// [`ProcessingSink::on_instance_finishes`](super::ProcessingSink::on_instance_finishes).
69 /// With `Batching::fast_first`, a pass asked for finishes resolves the
70 /// attached styles before the first chunk, not after it (#10698).
71 /// Off by default.
72 pub finishes: bool,
73}
74
75impl Features {
76 pub fn properties(mut self, on: bool) -> Self {
77 self.properties = on;
78 self
79 }
80
81 pub fn presentation_layers(mut self, on: bool) -> Self {
82 self.presentation_layers = on;
83 self
84 }
85
86 pub fn quick_metadata_bootstrap(mut self, on: bool) -> Self {
87 self.quick_metadata_bootstrap = on;
88 self
89 }
90
91 pub fn finishes(mut self, on: bool) -> Self {
92 self.finishes = on;
93 self
94 }
95}
96
97impl Default for Features {
98 fn default() -> Self {
99 Self { properties: true, presentation_layers: true, quick_metadata_bootstrap: false, finishes: false }
100 }
101}
102
103/// One pass over one file: the input of [`process`](super::process).
104///
105/// `ProcessingRequest::default()` is the streaming shape (50-job chunks);
106/// [`ProcessingRequest::full_pass`] is the one-chunk shape the non-streaming
107/// consumers (server routes, exporters, FFI) use. Both mesh the same elements
108/// the same way.
109#[non_exhaustive]
110#[derive(Debug, Clone)]
111pub struct ProcessingRequest {
112 /// Which window / door openings are cut and drawn.
113 pub opening_filter: OpeningFilterMode,
114 /// Leave hosts uncut by IfcRelVoidsElement; authored booleans and fillings remain.
115 pub skip_voids: bool,
116 /// Tessellation detail (#976). `Medium` is the historical output.
117 pub quality: TessellationQuality,
118 /// Slice material-layer walls into per-layer submeshes. Default false.
119 pub layer_slicing: bool,
120 pub batching: Batching,
121 pub features: Features,
122 /// Keep the emitted meshes in the returned [`ProcessingResult`](super::ProcessingResult).
123 pub retain_meshes: bool,
124 /// #1623 "don't-bake" instancing; needs `retain_meshes`.
125 pub instancing: bool,
126 /// Restrict meshing to these express ids. `None` is the unfiltered pass;
127 /// `Some(empty)` is an active filter that meshes nothing. The whole file is
128 /// still scanned and resolved, so a selected wall keeps the opening cutters
129 /// it needs; only unselected product jobs never reach the meshing loop.
130 pub entity_ids: Option<Arc<HashSet<u32>>>,
131 /// A prebuilt index of the SAME bytes, instead of building one inline.
132 pub entity_index: Option<Arc<EntityIndex>>,
133 /// Cooperative cancellation between job chunks and before final sink events.
134 /// A cancelled pass returns a PARTIAL result that the caller must not
135 /// present as complete.
136 pub cancel: Option<Arc<AtomicBool>>,
137}
138
139impl Default for ProcessingRequest {
140 fn default() -> Self {
141 Self::from_streaming(OpeningFilterMode::Default, StreamingOptions::default())
142 }
143}
144
145impl ProcessingRequest {
146 /// Every job in one chunk, no events beyond that one.
147 pub fn full_pass() -> Self {
148 Self::default().batching(Batching::single_chunk())
149 }
150
151 pub fn opening_filter(mut self, mode: OpeningFilterMode) -> Self {
152 self.opening_filter = mode;
153 self
154 }
155
156 /// Generate gross host geometry without changing emitted filling elements.
157 pub fn skip_voids(mut self, on: bool) -> Self {
158 self.skip_voids = on;
159 self
160 }
161
162 pub fn quality(mut self, quality: TessellationQuality) -> Self {
163 self.quality = quality;
164 self
165 }
166
167 /// Opt into the shared browser material-layer slicing path.
168 pub fn layer_slicing(mut self, on: bool) -> Self {
169 self.layer_slicing = on;
170 self
171 }
172
173 pub fn batching(mut self, batching: Batching) -> Self {
174 self.batching = batching;
175 self
176 }
177
178 pub fn features(mut self, features: Features) -> Self {
179 self.features = features;
180 self
181 }
182
183 pub fn retain_meshes(mut self, retain: bool) -> Self {
184 self.retain_meshes = retain;
185 self
186 }
187
188 pub fn instancing(mut self, on: bool) -> Self {
189 self.instancing = on;
190 self
191 }
192
193 pub fn ids(mut self, ids: Option<Arc<HashSet<u32>>>) -> Self {
194 self.entity_ids = ids;
195 self
196 }
197
198 pub fn index(mut self, index: Arc<EntityIndex>) -> Self {
199 self.entity_index = Some(index);
200 self
201 }
202
203 pub fn cancel(mut self, cancel: Arc<AtomicBool>) -> Self {
204 self.cancel = Some(cancel);
205 self
206 }
207
208 /// The request a [`StreamingOptions`] literal stands for. For the
209 /// deprecated entry points and the callers that still build the old
210 /// struct; C10 deletes it with `StreamingOptions`.
211 #[doc(hidden)]
212 pub fn from_streaming(opening_filter: OpeningFilterMode, options: StreamingOptions) -> Self {
213 Self {
214 opening_filter,
215 skip_voids: false,
216 quality: options.tessellation_quality,
217 layer_slicing: false,
218 batching: Batching {
219 initial: options.initial_batch_size,
220 throughput: options.throughput_batch_size,
221 fast_first: options.fast_first_batch,
222 },
223 features: Features {
224 properties: options.include_properties,
225 presentation_layers: options.include_presentation_layers,
226 quick_metadata_bootstrap: options.emit_quick_metadata_bootstrap,
227 finishes: false,
228 },
229 retain_meshes: options.retain_emitted_meshes,
230 instancing: options.enable_instancing,
231 entity_ids: None,
232 entity_index: options.entity_index,
233 cancel: options.cancel,
234 }
235 }
236}
237
238/// Controls the tradeoff between first-frame latency and richer upfront metadata.
239// Not `Copy`: `entity_index` holds an `Arc`. Every construction either moves the
240// struct into a process call once or `..Default::default()`s it, so `Clone` suffices.
241#[derive(Debug, Clone)]
242pub struct StreamingOptions {
243 /// Batch size used for the very first emitted chunk.
244 pub initial_batch_size: usize,
245 /// Batch size used after the first emitted chunk for higher throughput.
246 pub throughput_batch_size: usize,
247 /// Prioritize cheap/high-yield element classes first.
248 pub fast_first_batch: bool,
249 /// Include expensive property parsing on the first-frame path.
250 pub include_properties: bool,
251 /// Include expensive presentation-layer resolution on the first-frame path.
252 pub include_presentation_layers: bool,
253 /// Emit a lightweight spatial bootstrap during the scan phase.
254 pub emit_quick_metadata_bootstrap: bool,
255 /// Retain emitted meshes in the returned ProcessingResult.
256 pub retain_emitted_meshes: bool,
257 /// Tessellation detail level (#976). `Medium` reproduces the historical
258 /// output byte-for-byte; consumer-selectable on the wasm path via
259 /// `setTessellationQuality`, and on the server via the
260 /// `tessellation_quality` query parameter. 2D symbolic extraction
261 /// (`symbolic.rs`) deliberately ignores the level — symbols are
262 /// resolution-independent line work.
263 pub tessellation_quality: TessellationQuality,
264 /// Pre-built entity index to reuse instead of scanning `content` again. A caller
265 /// that runs both the geometry pass and a second pass over the same bytes (e.g. a
266 /// server emitting GLB *and* extracting properties) can `build_entity_index`
267 /// once and inject it here, skipping the duplicate SIMD scan. `None` builds it
268 /// internally, exactly as before. The index MUST come from
269 /// `build_entity_index(content)` for the *same* `content`, or decoding will read
270 /// the wrong byte ranges.
271 pub entity_index: Option<Arc<EntityIndex>>,
272 /// Cooperative cancellation: when the flag flips true, the streaming core
273 /// stops between job chunks (no further meshing or batch emission). The
274 /// returned `ProcessingResult` is then PARTIAL - the caller set the flag,
275 /// so it must not present the result as a completed parse. Used by the
276 /// server to stop burning a core when an SSE client disconnects.
277 pub cancel: Option<Arc<std::sync::atomic::AtomicBool>>,
278 /// #1623 Phase 2 "don't-bake" instancing. When `true` (AND
279 /// `retain_emitted_meshes`), the geometry phase meshes each repeated single-solid
280 /// `IfcRepresentationMap` ONCE (a template occurrence) and emits every OTHER
281 /// occurrence as a lightweight `InstanceRecord` (placement + colour + id) instead
282 /// of materializing a full world-space mesh per occurrence — killing the
283 /// per-occurrence 43M-vertex bake on mapped-item-heavy models. `false` (default)
284 /// reproduces the historical materialized output byte-for-byte, so determinism /
285 /// parity / every exporter are unaffected (none arm this).
286 pub enable_instancing: bool,
287}
288
289impl Default for StreamingOptions {
290 fn default() -> Self {
291 Self {
292 initial_batch_size: 50,
293 throughput_batch_size: 50,
294 fast_first_batch: false,
295 include_properties: true,
296 include_presentation_layers: true,
297 emit_quick_metadata_bootstrap: false,
298 retain_emitted_meshes: true,
299 tessellation_quality: TessellationQuality::default(),
300 entity_index: None,
301 cancel: None,
302 enable_instancing: false,
303 }
304 }
305}