@@ -9,23 +9,19 @@ use crate::{
9
9
} ;
10
10
11
11
/// Builder for point clouds, making it easy to create [`crate::renderer::PointCloudDrawData`].
12
- pub struct PointCloudBuilder < PerPointUserData > {
13
- // Size of `point`/color`/`per_point_user_data` must be equal.
12
+ pub struct PointCloudBuilder {
13
+ // Size of `point`/color` must be equal.
14
14
pub vertices : Vec < PointCloudVertex > ,
15
15
16
16
pub ( crate ) color_buffer : CpuWriteGpuReadBuffer < Color32 > ,
17
17
pub ( crate ) picking_instance_ids_buffer : CpuWriteGpuReadBuffer < PickingLayerInstanceId > ,
18
- pub user_data : Vec < PerPointUserData > ,
19
18
20
19
pub ( crate ) batches : Vec < PointCloudBatchInfo > ,
21
20
22
21
pub ( crate ) radius_boost_in_ui_points_for_outlines : f32 ,
23
22
}
24
23
25
- impl < PerPointUserData > PointCloudBuilder < PerPointUserData >
26
- where
27
- PerPointUserData : Default + Copy ,
28
- {
24
+ impl PointCloudBuilder {
29
25
pub fn new ( ctx : & RenderContext ) -> Self {
30
26
const RESERVE_SIZE : usize = 512 ;
31
27
48
44
vertices : Vec :: with_capacity ( RESERVE_SIZE ) ,
49
45
color_buffer,
50
46
picking_instance_ids_buffer,
51
- user_data : Vec :: with_capacity ( RESERVE_SIZE ) ,
52
47
batches : Vec :: with_capacity ( 16 ) ,
53
48
radius_boost_in_ui_points_for_outlines : 0.0 ,
54
49
}
65
60
66
61
/// Start of a new batch.
67
62
#[ inline]
68
- pub fn batch (
69
- & mut self ,
70
- label : impl Into < DebugLabel > ,
71
- ) -> PointCloudBatchBuilder < ' _ , PerPointUserData > {
63
+ pub fn batch ( & mut self , label : impl Into < DebugLabel > ) -> PointCloudBatchBuilder < ' _ > {
72
64
self . batches . push ( PointCloudBatchInfo {
73
65
label : label. into ( ) ,
74
66
world_from_obj : glam:: Mat4 :: IDENTITY ,
@@ -105,30 +97,6 @@ where
105
97
} )
106
98
}
107
99
108
- // Iterate over all batches, yielding the batch info and a point vertex iterator zipped with its user data.
109
- pub fn iter_vertices_and_userdata_by_batch (
110
- & self ,
111
- ) -> impl Iterator <
112
- Item = (
113
- & PointCloudBatchInfo ,
114
- impl Iterator < Item = ( & PointCloudVertex , & PerPointUserData ) > ,
115
- ) ,
116
- > {
117
- let mut vertex_offset = 0 ;
118
- self . batches . iter ( ) . map ( move |batch| {
119
- let out = (
120
- batch,
121
- self . vertices
122
- . iter ( )
123
- . zip ( self . user_data . iter ( ) )
124
- . skip ( vertex_offset)
125
- . take ( batch. point_count as usize ) ,
126
- ) ;
127
- vertex_offset += batch. point_count as usize ;
128
- out
129
- } )
130
- }
131
-
132
100
/// Finalizes the builder and returns a point cloud draw data with all the points added so far.
133
101
pub fn to_draw_data (
134
102
self ,
@@ -138,16 +106,9 @@ where
138
106
}
139
107
}
140
108
141
- pub struct PointCloudBatchBuilder < ' a , PerPointUserData > (
142
- & ' a mut PointCloudBuilder < PerPointUserData > ,
143
- )
144
- where
145
- PerPointUserData : Default + Copy ;
109
+ pub struct PointCloudBatchBuilder < ' a > ( & ' a mut PointCloudBuilder ) ;
146
110
147
- impl < ' a , PerPointUserData > Drop for PointCloudBatchBuilder < ' a , PerPointUserData >
148
- where
149
- PerPointUserData : Default + Copy ,
150
- {
111
+ impl < ' a > Drop for PointCloudBatchBuilder < ' a > {
151
112
fn drop ( & mut self ) {
152
113
// Remove batch again if it wasn't actually used.
153
114
if self . 0 . batches . last ( ) . unwrap ( ) . point_count == 0 {
@@ -157,10 +118,7 @@ where
157
118
}
158
119
}
159
120
160
- impl < ' a , PerPointUserData > PointCloudBatchBuilder < ' a , PerPointUserData >
161
- where
162
- PerPointUserData : Default + Copy ,
163
- {
121
+ impl < ' a > PointCloudBatchBuilder < ' a > {
164
122
#[ inline]
165
123
fn batch_mut ( & mut self ) -> & mut PointCloudBatchInfo {
166
124
self . 0
@@ -200,13 +158,6 @@ where
200
158
self . 0 . vertices . len ( ) - self . 0 . picking_instance_ids_buffer . num_written ( ) ,
201
159
) ) ;
202
160
}
203
-
204
- if self . 0 . user_data . len ( ) < self . 0 . vertices . len ( ) {
205
- self . 0 . user_data . extend (
206
- std:: iter:: repeat ( PerPointUserData :: default ( ) )
207
- . take ( self . 0 . vertices . len ( ) - self . 0 . user_data . len ( ) ) ,
208
- ) ;
209
- }
210
161
}
211
162
212
163
#[ inline]
@@ -222,7 +173,7 @@ where
222
173
& mut self ,
223
174
size_hint : usize ,
224
175
positions : impl Iterator < Item = glam:: Vec3 > ,
225
- ) -> PointsBuilder < ' _ , PerPointUserData > {
176
+ ) -> PointsBuilder < ' _ > {
226
177
// TODO(jleibs): Figure out if we can plumb-through proper support for `Iterator::size_hints()`
227
178
// or potentially make `FixedSizedIterator` work correctly. This should be possible size the
228
179
// underlying arrow structures are of known-size, but carries some complexity with the amount of
@@ -232,7 +183,6 @@ where
232
183
self . extend_defaults ( ) ;
233
184
234
185
debug_assert_eq ! ( self . 0 . vertices. len( ) , self . 0 . color_buffer. num_written( ) ) ;
235
- debug_assert_eq ! ( self . 0 . vertices. len( ) , self . 0 . user_data. len( ) ) ;
236
186
237
187
let old_size = self . 0 . vertices . len ( ) ;
238
188
@@ -245,8 +195,6 @@ where
245
195
let num_points = self . 0 . vertices . len ( ) - old_size;
246
196
self . batch_mut ( ) . point_count += num_points as u32 ;
247
197
248
- self . 0 . user_data . reserve ( num_points) ;
249
-
250
198
let new_range = old_size..self . 0 . vertices . len ( ) ;
251
199
252
200
let max_points = self . 0 . vertices . len ( ) ;
@@ -256,7 +204,6 @@ where
256
204
max_points,
257
205
colors : & mut self . 0 . color_buffer ,
258
206
picking_instance_ids : & mut self . 0 . picking_instance_ids_buffer ,
259
- user_data : & mut self . 0 . user_data ,
260
207
additional_outline_mask_ids : & mut self
261
208
. 0
262
209
. batches
@@ -268,24 +215,22 @@ where
268
215
}
269
216
270
217
#[ inline]
271
- pub fn add_point ( & mut self , position : glam:: Vec3 ) -> PointBuilder < ' _ , PerPointUserData > {
218
+ pub fn add_point ( & mut self , position : glam:: Vec3 ) -> PointBuilder < ' _ > {
272
219
self . extend_defaults ( ) ;
273
220
274
221
debug_assert_eq ! ( self . 0 . vertices. len( ) , self . 0 . color_buffer. num_written( ) ) ;
275
- debug_assert_eq ! ( self . 0 . vertices. len( ) , self . 0 . user_data. len( ) ) ;
276
222
277
223
let vertex_index = self . 0 . vertices . len ( ) as u32 ;
278
224
self . 0 . vertices . push ( PointCloudVertex {
279
225
position,
280
226
radius : Size :: AUTO ,
281
227
} ) ;
282
- self . 0 . user_data . push ( Default :: default ( ) ) ;
283
228
self . batch_mut ( ) . point_count += 1 ;
284
229
285
230
PointBuilder {
286
231
vertex : self . 0 . vertices . last_mut ( ) . unwrap ( ) ,
287
232
color : & mut self . 0 . color_buffer ,
288
- user_data : self . 0 . user_data . last_mut ( ) . unwrap ( ) ,
233
+ picking_instance_id : & mut self . 0 . picking_instance_ids_buffer ,
289
234
vertex_index,
290
235
additional_outline_mask_ids : & mut self
291
236
. 0
@@ -308,13 +253,13 @@ where
308
253
& mut self ,
309
254
size_hint : usize ,
310
255
positions : impl Iterator < Item = glam:: Vec2 > ,
311
- ) -> PointsBuilder < ' _ , PerPointUserData > {
256
+ ) -> PointsBuilder < ' _ > {
312
257
self . add_points ( size_hint, positions. map ( |p| p. extend ( 0.0 ) ) )
313
258
}
314
259
315
260
/// Adds a single 2D point. Uses an autogenerated depth value.
316
261
#[ inline]
317
- pub fn add_point_2d ( & mut self , position : glam:: Vec2 ) -> PointBuilder < ' _ , PerPointUserData > {
262
+ pub fn add_point_2d ( & mut self , position : glam:: Vec2 ) -> PointBuilder < ' _ > {
318
263
self . add_point ( position. extend ( 0.0 ) )
319
264
}
320
265
@@ -331,19 +276,17 @@ where
331
276
}
332
277
333
278
// TODO(andreas): Should remove single-point builder, practically this never makes sense as we're almost always dealing with arrays of points.
334
- pub struct PointBuilder < ' a , PerPointUserData > {
279
+ pub struct PointBuilder < ' a > {
335
280
vertex : & ' a mut PointCloudVertex ,
336
281
color : & ' a mut CpuWriteGpuReadBuffer < Color32 > ,
337
- user_data : & ' a mut PerPointUserData ,
282
+ picking_instance_id : & ' a mut CpuWriteGpuReadBuffer < PickingLayerInstanceId > ,
338
283
vertex_index : u32 ,
284
+
339
285
additional_outline_mask_ids : & ' a mut Vec < ( std:: ops:: Range < u32 > , OutlineMaskPreference ) > ,
340
286
outline_mask_id : OutlineMaskPreference ,
341
287
}
342
288
343
- impl < ' a , PerPointUserData > PointBuilder < ' a , PerPointUserData >
344
- where
345
- PerPointUserData : Clone ,
346
- {
289
+ impl < ' a > PointBuilder < ' a > {
347
290
#[ inline]
348
291
pub fn radius ( self , radius : Size ) -> Self {
349
292
self . vertex . radius = radius;
@@ -357,21 +300,24 @@ where
357
300
self
358
301
}
359
302
360
- pub fn user_data ( self , data : PerPointUserData ) -> Self {
361
- * self . user_data = data;
362
- self
363
- }
364
-
365
303
/// Pushes additional outline mask ids for this point
366
304
///
367
305
/// Prefer the `overall_outline_mask_ids` setting to set the outline mask ids for the entire batch whenever possible!
306
+ #[ inline]
368
307
pub fn outline_mask_id ( mut self , outline_mask_id : OutlineMaskPreference ) -> Self {
369
308
self . outline_mask_id = outline_mask_id;
370
309
self
371
310
}
311
+
312
+ /// This mustn't call this more than once.
313
+ #[ inline]
314
+ pub fn picking_instance_id ( self , picking_instance_id : PickingLayerInstanceId ) -> Self {
315
+ self . picking_instance_id . push ( picking_instance_id) ;
316
+ self
317
+ }
372
318
}
373
319
374
- impl < ' a , PerPointUserData > Drop for PointBuilder < ' a , PerPointUserData > {
320
+ impl < ' a > Drop for PointBuilder < ' a > {
375
321
fn drop ( & mut self ) {
376
322
if self . outline_mask_id . is_some ( ) {
377
323
self . additional_outline_mask_ids . push ( (
@@ -382,21 +328,17 @@ impl<'a, PerPointUserData> Drop for PointBuilder<'a, PerPointUserData> {
382
328
}
383
329
}
384
330
385
- pub struct PointsBuilder < ' a , PerPointUserData > {
331
+ pub struct PointsBuilder < ' a > {
386
332
// Vertices is a slice, which radii will update
387
333
vertices : & ' a mut [ PointCloudVertex ] ,
388
334
max_points : usize ,
389
335
colors : & ' a mut CpuWriteGpuReadBuffer < Color32 > ,
390
336
picking_instance_ids : & ' a mut CpuWriteGpuReadBuffer < PickingLayerInstanceId > ,
391
- user_data : & ' a mut Vec < PerPointUserData > ,
392
337
additional_outline_mask_ids : & ' a mut Vec < ( std:: ops:: Range < u32 > , OutlineMaskPreference ) > ,
393
338
start_vertex_index : u32 ,
394
339
}
395
340
396
- impl < ' a , PerPointUserData > PointsBuilder < ' a , PerPointUserData >
397
- where
398
- PerPointUserData : Clone ,
399
- {
341
+ impl < ' a > PointsBuilder < ' a > {
400
342
/// Assigns radii to all points.
401
343
///
402
344
/// This mustn't call this more than once.
@@ -440,19 +382,6 @@ where
440
382
self
441
383
}
442
384
443
- /// Assigns user data for all points in this builder.
444
- ///
445
- /// This mustn't call this more than once.
446
- ///
447
- /// User data is currently not available on the GPU.
448
- #[ inline]
449
- pub fn user_data ( self , data : impl Iterator < Item = PerPointUserData > ) -> Self {
450
- crate :: profile_function!( ) ;
451
- self . user_data
452
- . extend ( data. take ( self . max_points - self . user_data . len ( ) ) ) ;
453
- self
454
- }
455
-
456
385
/// Pushes additional outline mask ids for a specific range of points.
457
386
/// The range is relative to this builder's range, not the entire batch.
458
387
///
0 commit comments