1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
use crate::;
/// A struct to handle custom selection and custom modifier together.
///
/// ## Overview
///
/// This modifier holdes a [`SelectionBundle`] and a [`Modifier`] along with necessary
/// buffers, and applies the selection followed by the basic modifier in order.
///
/// The [`Modifier`] can use the [`SelectionModifier::selection_buffer`] to determine which
/// Gaussians to modify.
///
/// ## Usage
///
/// You can supply your own selection bundles and modifier when creating a
/// [`SelectionModifier`].
///
/// The creation expects a modifier factory function instead of a modifier,
/// so that the modifier can be created with a reference to the selection buffer.
///
/// ```rust no_run
/// # pollster::block_on(async {
/// # use wgpu_3dgs_editor::{
/// # Editor, Modifier, SelectionBuffer, SelectionBundle, SelectionModifier,
/// # core::{
/// # self, BufferWrapper, glam::*,
/// # },
/// # };
/// #
/// # type GaussianPod = core::GaussianPodWithShSingleCov3dSingleConfigs;
/// #
/// # let instance = wgpu::Instance::new(
/// # wgpu::InstanceDescriptor::new_without_display_handle_from_env()
/// # );
/// #
/// # let adapter = instance
/// # .request_adapter(&wgpu::RequestAdapterOptions::default())
/// # .await
/// # .expect("adapter");
/// #
/// # let (device, _queue) = adapter
/// # .request_device(&wgpu::DeviceDescriptor {
/// # label: Some("Device"),
/// # required_limits: adapter.limits(),
/// # ..Default::default()
/// # })
/// # .await
/// # .expect("device");
/// #
/// // Create an editor that holds the buffers for the Gaussians and will apply the modifier
/// let editor = Editor::new(
/// &device,
/// &vec![core::Gaussian {
/// rot: Quat::IDENTITY,
/// pos: Vec3::ZERO,
/// color: U8Vec4::ZERO,
/// sh: [Vec3::ZERO; 15],
/// scale: Vec3::ONE,
/// }],
/// );
///
/// // Create your selection bundles
/// let selection_bundles = vec![
/// // The built-in sphere selection bundle as example
/// SelectionBundle::<GaussianPod>::create_sphere_bundle(&device),
/// ];
///
/// struct MyCustomModifier(core::ComputeBundle);
///
/// impl MyCustomModifier {
/// pub fn new(
/// device: &wgpu::Device,
/// // My buffers,
/// selection: &SelectionBuffer,
/// ) -> Self {
/// // Build your compute bundle here,
/// // and include the selection buffer to only modify selected Gaussians
/// let compute_bundle = core::ComputeBundleBuilder::new()
/// // Configure the modifier compute bundle here
/// .build(
/// &device,
/// [
/// [selection.buffer().as_entire_binding()].to_vec(),
/// [/* Your buffers */].to_vec(),
/// ],
/// )
/// .unwrap();
/// Self(compute_bundle)
/// }
/// }
///
/// impl Modifier<GaussianPod> for MyCustomModifier {
/// fn apply(
/// &self,
/// _device: &wgpu::Device,
/// encoder: &mut wgpu::CommandEncoder,
/// gaussians: &core::GaussiansBuffer<GaussianPod>,
/// _model_transform: &core::ModelTransformBuffer,
/// _gaussian_transform: &core::GaussianTransformBuffer,
/// ) {
/// self.0.dispatch(encoder, gaussians.len() as u32);
/// }
/// }
///
/// let selection_modifier = SelectionModifier::new(
/// &device,
/// &editor.gaussians_buffer,
/// selection_bundles,
/// |selection_buffer| {
/// // The factory closure
/// MyCustomModifier::new(
/// &device,
/// // Your buffers,
/// selection_buffer,
/// )
/// },
/// );
/// # });
/// ```
///
/// Alternatively, you can use a modifier closure instead of a struct (but be reminded this could
/// harm readability of your code).
///
/// ```rust no_run
/// # pollster::block_on(async {
/// # use wgpu_3dgs_editor::{
/// # Editor, Modifier, SelectionBuffer, SelectionBundle, SelectionModifier,
/// # core::{
/// # self, BufferWrapper, glam::*,
/// # },
/// # };
/// #
/// # type GaussianPod = core::GaussianPodWithShSingleCov3dSingleConfigs;
/// #
/// # let instance = wgpu::Instance::new(
/// # wgpu::InstanceDescriptor::new_without_display_handle_from_env()
/// # );
/// #
/// # let adapter = instance
/// # .request_adapter(&wgpu::RequestAdapterOptions::default())
/// # .await
/// # .expect("adapter");
/// #
/// # let (device, _queue) = adapter
/// # .request_device(&wgpu::DeviceDescriptor {
/// # label: Some("Device"),
/// # required_limits: adapter.limits(),
/// # ..Default::default()
/// # })
/// # .await
/// # .expect("device");
/// #
/// # let editor = Editor::new(
/// # &device,
/// # &vec![core::Gaussian {
/// # rot: Quat::IDENTITY,
/// # pos: Vec3::ZERO,
/// # color: U8Vec4::ZERO,
/// # sh: [Vec3::ZERO; 15],
/// # scale: Vec3::ONE,
/// # }],
/// # );
/// #
/// # let selection_bundles = vec![
/// # // The built-in sphere selection bundle as example
/// # SelectionBundle::<GaussianPod>::create_sphere_bundle(&device),
/// # ];
/// #
/// let selection_modifier = SelectionModifier::new(
/// &device,
/// &editor.gaussians_buffer,
/// selection_bundles,
/// |selection_buffer| {
/// // The factory closure
/// // Build your compute bundle here,
/// // and include the selection buffer to only modify selected Gaussians
/// let modifier_bundle = core::ComputeBundleBuilder::new()
/// .build(
/// &device,
/// [
/// [selection_buffer.buffer().as_entire_binding()].to_vec(),
/// [/* Your buffers */].to_vec(),
/// ],
/// )
/// .unwrap();
///
/// // This function signature has blanket impl of the modifier trait
/// move |_device: &wgpu::Device,
/// encoder: &mut wgpu::CommandEncoder,
/// gaussians: &core::GaussiansBuffer<GaussianPod>,
/// _model_transform: &core::ModelTransformBuffer,
/// _gaussian_transform: &core::GaussianTransformBuffer| {
/// modifier_bundle.dispatch(encoder, gaussians.len() as u32);
/// }
/// },
/// );
/// # });
/// ```
/// A type alias of [`SelectionModifier`] with [`BasicModifier`].
pub type BasicSelectionModifier<G> = ;