graphics 0.5.12

A 3D rendering engine for rust programs, with GUI integration
Documentation
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
//! https://sotrh.github.io/learn-wgpu/beginner/tutorial9-models/#rendering-a-mesh

#[cfg(feature = "app_utils")]
use bincode::{Decode, Encode};
use lin_alg::f32::{Mat4, Quaternion, Vec3, Vec4};
use wgpu::{VertexAttribute, VertexBufferLayout, VertexFormat};

use crate::{
    EntityUpdate, camera::Camera, gauss::Gaussian, lighting::Lighting, text_overlay::TextOverlay,
    viewport_rect,
};

// These sizes are in bytes. We do this, since that's the data format expected by the shader.
pub const F32_SIZE: usize = 4;

pub const VEC3_SIZE: usize = 3 * F32_SIZE;
pub const VEC4_SIZE: usize = 4 * F32_SIZE;
pub const VEC3_UNIFORM_SIZE: usize = 4 * F32_SIZE;
pub const MAT4_SIZE: usize = 16 * F32_SIZE;
pub const MAT3_SIZE: usize = 9 * F32_SIZE;

pub const VERTEX_SIZE: usize = 14 * F32_SIZE + 4; // ast 4 are per-vertex color

// Note that position, orientation, and scale are combined into a single 4x4 transformation
// matrix. Note that unlike uniforms, we don't need alignment padding, and can use Vec3 directly.
pub const INSTANCE_SIZE: usize = MAT4_SIZE + MAT3_SIZE + VEC4_SIZE + F32_SIZE;

// Create the vertex buffer memory layout, for our vertexes passed from CPU
// to the vertex shader. Corresponds to `VertexIn` in the shader. Each
// item here is for a single vertex.
pub(crate) const VERTEX_LAYOUT: VertexBufferLayout<'static> = VertexBufferLayout {
    array_stride: VERTEX_SIZE as wgpu::BufferAddress,
    step_mode: wgpu::VertexStepMode::Vertex,
    attributes: &[
        // Vertex position
        VertexAttribute {
            offset: 0,
            shader_location: 0,
            format: VertexFormat::Float32x3,
        },
        // Texture coordinates
        VertexAttribute {
            offset: VEC3_SIZE as wgpu::BufferAddress,
            shader_location: 1,
            format: VertexFormat::Float32x2,
        },
        // Normal vector
        VertexAttribute {
            offset: (2 * F32_SIZE + VEC3_SIZE) as wgpu::BufferAddress,
            shader_location: 2,
            format: VertexFormat::Float32x3,
        },
        // Tangent (Used to align textures)
        VertexAttribute {
            offset: (2 * F32_SIZE + 2 * VEC3_SIZE) as wgpu::BufferAddress,
            shader_location: 3,
            format: VertexFormat::Float32x3,
        },
        // Bitangent (Used to align textures)
        VertexAttribute {
            offset: (2 * F32_SIZE + 3 * VEC3_SIZE) as wgpu::BufferAddress,
            shader_location: 4,
            format: VertexFormat::Float32x3,
        },
        // Per-vertex color.
        VertexAttribute {
            offset: (2 * F32_SIZE + 4 * VEC3_SIZE) as wgpu::BufferAddress,
            shader_location: 5,
            format: VertexFormat::Unorm8x4,
        },
    ],
};

// Create the vertex buffer memory layout, for our vertexes passed from the
// vertex to the fragment shader. Corresponds to `VertexOut` in the shader. Each
// item here is for a single vertex. Cannot share locations with `VertexIn`, so
// we start locations after `VertexIn`'s last one.
pub(crate) const INSTANCE_LAYOUT: VertexBufferLayout<'static> = VertexBufferLayout {
    array_stride: INSTANCE_SIZE as wgpu::BufferAddress,
    // We need to switch from using a step mode of Vertex to Instance
    // This means that our shaders will only change to use the next
    // instance when the shader starts processing a new instance
    step_mode: wgpu::VertexStepMode::Instance,
    attributes: &[
        // A mat4 takes up 4 vertex slots as it is technically 4 vec4s. We need to define a slot
        // for each vec4. We'll have to reassemble the mat4 in
        // the shader.

        // Model matrix, col 0
        VertexAttribute {
            offset: 0,
            shader_location: 6,
            format: VertexFormat::Float32x4,
        },
        // Model matrix, col 1
        VertexAttribute {
            offset: (F32_SIZE * 4) as wgpu::BufferAddress,
            shader_location: 7,
            format: VertexFormat::Float32x4,
        },
        // Model matrix, col 2
        VertexAttribute {
            offset: (F32_SIZE * 8) as wgpu::BufferAddress,
            shader_location: 8,
            format: VertexFormat::Float32x4,
        },
        // Model matrix, col 3
        VertexAttribute {
            offset: (F32_SIZE * 12) as wgpu::BufferAddress,
            shader_location: 9,
            format: VertexFormat::Float32x4,
        },
        // Normal matrix, col 0
        VertexAttribute {
            offset: (MAT4_SIZE) as wgpu::BufferAddress,
            shader_location: 10,
            format: VertexFormat::Float32x3,
        },
        // Normal matrix, col 1
        VertexAttribute {
            offset: (MAT4_SIZE + VEC3_SIZE) as wgpu::BufferAddress,
            shader_location: 11,
            format: VertexFormat::Float32x3,
        },
        // Normal matrix, col 2
        VertexAttribute {
            offset: (MAT4_SIZE + VEC3_SIZE * 2) as wgpu::BufferAddress,
            shader_location: 12,
            format: VertexFormat::Float32x3,
        },
        // model (and vertex) color
        VertexAttribute {
            offset: (MAT4_SIZE + MAT3_SIZE) as wgpu::BufferAddress,
            shader_location: 13,
            format: VertexFormat::Float32x4,
        },
        // Shinyness
        VertexAttribute {
            offset: (MAT4_SIZE + MAT3_SIZE + VEC4_SIZE) as wgpu::BufferAddress,
            shader_location: 14,
            format: VertexFormat::Float32,
        },
    ],
};

#[cfg_attr(feature = "app_utils", derive(Encode, Decode))]
#[derive(Clone, Copy, Debug)]
/// A general mesh. This should be sufficiently versatile to use for a number of purposes.
pub struct Vertex {
    /// Where the vertex is located in space
    pub position: [f32; 3],
    /// AKA UV mapping. https://en.wikipedia.org/wiki/UV_mapping
    pub tex_coords: [f32; 2],
    /// The direction the vertex normal is facing in
    pub normal: Vec3,
    /// "Tangent and Binormal vectors are vectors that are perpendicular to each other
    /// and the normal vector which essentially describe the direction of the u,v texture
    /// coordinates with respect to the surface that you are trying to render. Typically
    /// they can be used alongside normal maps which allow you to create sub surface
    /// lighting detail to your model(bumpiness)."
    /// This is used to orient normal maps; corresponds to the +X texture direction.
    pub tangent: Vec3,
    /// A bitangent vector is the result of the Cross Product between Vertex Normal and Vertex
    /// Tangent which is a unit vector perpendicular to both vectors at a given point.
    /// This is used to orient normal maps; corresponds to the +Y texture direction.
    pub bitangent: Vec3,
    /// For per-vertex coloring. If opacity is 0, the entity color will be used instead.
    pub color: Option<(u8, u8, u8, u8)>,
}

impl Vertex {
    /// Initialize position; change the others after init.
    pub fn new(position: [f32; 3], normal: Vec3) -> Self {
        Self {
            position,
            tex_coords: [0., 0.],
            normal,
            tangent: Vec3::new_zero(),
            bitangent: Vec3::new_zero(),
            color: None,
        }
    }

    pub fn to_bytes(&self) -> [u8; VERTEX_SIZE] {
        let mut result = [0; VERTEX_SIZE];

        result[0..4].clone_from_slice(&self.position[0].to_ne_bytes());
        result[4..8].clone_from_slice(&self.position[1].to_ne_bytes());
        result[8..12].clone_from_slice(&self.position[2].to_ne_bytes());
        result[12..16].clone_from_slice(&self.tex_coords[0].to_ne_bytes());
        result[16..20].clone_from_slice(&self.tex_coords[1].to_ne_bytes());

        result[20..32].clone_from_slice(&self.normal.to_bytes());
        result[32..44].clone_from_slice(&self.tangent.to_bytes());
        result[44..56].clone_from_slice(&self.bitangent.to_bytes());

        if let Some(color) = self.color {
            result[56..60].copy_from_slice(&[color.0, color.1, color.2, color.3]);
        }

        result
    }
}

/// Instances allow the GPU to render the same object multiple times.
/// "Instancing allows us to draw the same object multiple times with different properties
/// (position, orientation, size, color, etc.). "
pub struct Instance {
    pub position: Vec3,
    pub orientation: Quaternion,
    pub pivot: Option<Vec3>,
    pub scale: Vec3,
    pub color: Vec3,
    pub opacity: f32,
    pub shinyness: f32,
}

impl Instance {
    /// Converts to a model matrix to a byte array, for passing to the GPU.
    pub fn to_bytes(&self) -> [u8; INSTANCE_SIZE] {
        let mut result = [0; INSTANCE_SIZE];

        let model_mat = match self.pivot {
            Some(p) => {
                Mat4::new_translation(self.position)
                    * Mat4::new_translation(p)
                    * self.orientation.to_matrix()
                    * Mat4::new_translation(-p)
                    * Mat4::new_scaler_partial(self.scale)
            }
            None => {
                Mat4::new_translation(self.position)
                    * self.orientation.to_matrix()
                    * Mat4::new_scaler_partial(self.scale)
            }
        };

        let normal_mat = self.orientation.to_matrix3();

        result[0..MAT4_SIZE].clone_from_slice(&model_mat.to_bytes());

        result[MAT4_SIZE..MAT4_SIZE + MAT3_SIZE].clone_from_slice(&normal_mat.to_bytes());

        // todo: fn to convert Vec3 to byte array?
        let mut color_buf = [0; VEC4_SIZE];
        color_buf[0..F32_SIZE].clone_from_slice(&self.color.x.to_ne_bytes());
        color_buf[F32_SIZE..2 * F32_SIZE].clone_from_slice(&self.color.y.to_ne_bytes());
        color_buf[2 * F32_SIZE..3 * F32_SIZE].clone_from_slice(&self.color.z.to_ne_bytes());
        color_buf[3 * F32_SIZE..4 * F32_SIZE].clone_from_slice(&self.opacity.to_ne_bytes());

        result[MAT4_SIZE + MAT3_SIZE..INSTANCE_SIZE - F32_SIZE].clone_from_slice(&color_buf);

        // todo
        // result[MAT4_SIZE + MAT3_SIZE..INSTANCE_SIZE - F32_SIZE]
        //     // .clone_from_slice(&self.color.to_bytes_uniform());
        //     .clone_from_slice(&self.color.to_bytes());

        result[INSTANCE_SIZE - F32_SIZE..INSTANCE_SIZE]
            .clone_from_slice(&self.shinyness.to_ne_bytes());

        result
    }
}

impl From<&Entity> for Instance {
    fn from(entity: &Entity) -> Self {
        let scale = match entity.scale_partial {
            Some(s) => s,
            None => Vec3::new(entity.scale, entity.scale, entity.scale),
        };

        Self {
            position: entity.position,
            orientation: entity.orientation,
            pivot: entity.pivot,
            scale,
            color: Vec3::new(entity.color.0, entity.color.1, entity.color.2),
            opacity: entity.opacity,
            shinyness: entity.shinyness,
        }
    }
}

#[cfg_attr(feature = "app_utils", derive(Encode, Decode))]
#[derive(Clone, Debug, Default)]
pub struct Mesh {
    pub vertices: Vec<Vertex>,
    /// These indices are relative to 0 for this mesh. When adding to a global index
    /// buffer, we offset them by previous meshes' vertex counts.
    pub indices: Vec<usize>,
    pub material: usize,
}

/// Represents an entity in the world. This is not fundamental to the WGPU system.
#[derive(Clone, Debug)]
pub struct Entity {
    /// Up to the application.
    pub id: u32,
    /// Up to the application
    pub class: u32,
    /// Index of the mesh this entity references. (or perhaps its index?)
    pub mesh: usize,
    /// Position in the world, relative to world origin
    pub position: Vec3,
    /// Rotation, relative to up.
    pub orientation: Quaternion,
    /// Point relative to the mesh coordinates where we rotate it. If omitted, the
    /// 0 vec is used.
    pub pivot: Option<Vec3>,
    pub scale: f32, // 1.0 is original.
    /// Scale by axis. If `Some`, overrides scale.
    /// Not set in the constructor; set after manually.
    pub scale_partial: Option<Vec3>,
    pub color: (f32, f32, f32),
    // /// If present, this overrides `color`.
    // pub color_by_vertex: Option<(u8, u8, u8)>,
    pub opacity: f32,
    pub shinyness: f32, // 0 to 1.
    // todo: Experimenting. Public so we can override defaults in applications,
    // todo, but should not be set by the user.
    /// Used for replacing entities without rebuilding the buffer.
    pub buf_i: Option<usize>,
    /// Used for replacing entities without rebuilding the buffer.
    /// Which buffer this slot is in.
    pub buf_is_transparent: bool,
    /// Display text over (or near) the element.
    pub overlay_text: Option<TextOverlay>,
}

impl Default for Entity {
    fn default() -> Self {
        Self {
            id: 0,
            class: 0,
            mesh: 0,
            position: Vec3::new_zero(),
            orientation: Quaternion::new_identity(),
            pivot: None,
            scale: 1.,
            scale_partial: None,
            color: (1., 1., 1.),
            // color_by_vertex: None,
            opacity: 1.,
            shinyness: 0.,
            buf_i: None,
            buf_is_transparent: false,
            overlay_text: None,
        }
    }
}

impl Entity {
    pub fn new(
        mesh: usize,
        position: Vec3,
        orientation: Quaternion,
        scale: f32,
        color: (f32, f32, f32),
        shinyness: f32,
    ) -> Self {
        Self {
            mesh,
            position,
            orientation,
            scale,
            color,
            shinyness,
            ..Default::default()
        }
    }
}

#[cfg_attr(feature = "app_utils", derive(Encode, Decode))]
#[derive(Clone, Copy, PartialEq, Debug, Default)]
/// Default controls. Provides easy defaults. For maximum flexibility, choose `None`,
/// and implement controls in the `event_handler` function.
pub enum ControlScheme {
    /// No controls; provide all controls in application code.
    None,
    #[default]
    /// Keyboard controls for movement along 3 axis, and rotation around the Z axis. Mouse
    /// for rotation around the X and Y axes. Shift to multiply speed of keyboard controls.
    FreeCamera,
    /// FPS-style camera. Ie, no Z-axis roll, no up/down movement, and can't look up past TAU/4.
    /// todo: Unimplemented
    Fps,
    /// The mouse rotates the camera around a fixed point.
    Arc { center: Vec3 },
}

#[derive(Clone, Debug)]
pub struct Scene {
    pub meshes: Vec<Mesh>,
    pub gaussians: Vec<Gaussian>,
    pub entities: Vec<Entity>,
    pub camera: Camera,
    pub lighting: Lighting,
    pub input_settings: InputSettings,
    pub background_color: (f32, f32, f32),
    pub window_title: String,
    pub window_size: (f32, f32),
    /// A duplicate of GUI.size, to be available to the application.
    pub gui_size: (f32, f32),
}

impl Default for Scene {
    fn default() -> Self {
        Self {
            meshes: Vec::new(),
            gaussians: Vec::new(),
            entities: Vec::new(),
            camera: Default::default(),
            lighting: Default::default(),
            input_settings: Default::default(),
            // todo: Consider a separate window struct.
            background_color: (0.7, 0.7, 0.7),
            window_title: "(Window title here)".to_owned(),
            window_size: (900., 600.),
            gui_size: (0., 0.),
        }
    }
}

impl Scene {
    /// Convert a screen position (x, y) to a 3D ray in world space.
    ///
    /// The canonical use case for this is finding the object in 3D space a user is intending to select
    /// with the cursor.A follow-up operation, for example, may be to find all objects that this vector
    /// passes near, and possibly select the one closest to the camera.
    pub fn screen_to_render(&self, mut screen_pos: (f32, f32)) -> (Vec3, Vec3) {
        let proj_view = self.camera.proj_mat.clone() * self.camera.view_mat();

        let proj_view_inv = match proj_view.inverse() {
            Some(p) => p,
            None => {
                eprintln!("Error inverting the projection matrix.");
                return (Vec3::new_zero(), Vec3::new_zero());
            }
        };

        let (x, y, eff_width, eff_height) = viewport_rect(
            self.gui_size,
            // This should be the same as sys.surface_config.width and height.
            self.window_size.0 as u32,
            self.window_size.1 as u32,
            // state.ui_settings,
            &UiSettings::default(), // todo temp. OK as long as using GUI from top and left.
            0.,                     // Unused, for now.
        );

        screen_pos.0 -= x;
        screen_pos.1 -= y;

        let sx = screen_pos.0 / eff_width;
        let sy = screen_pos.1 / eff_height;

        let clip_x = 2.0 * sx - 1.0;
        let clip_y = 1.0 - 2.0 * sy; // Flips the Y so 0 is top, 1 is bottom

        let near_clip = Vec4::new(clip_x, clip_y, 0.0, 1.0);
        let far_clip = Vec4::new(clip_x, clip_y, 1.0, 1.0);

        // Un-project them to world space.
        let near_world_h = proj_view_inv.clone() * near_clip;
        let far_world_h = proj_view_inv * far_clip;

        // Perspective divide to go from homogenous -> 3D.
        let near_world = near_world_h.xyz() / near_world_h.w;
        let far_world = far_world_h.xyz() / far_world_h.w;

        (near_world, far_world)
    }
}

#[derive(Clone, Copy, Debug, Default)]
pub enum ScrollBehavior {
    #[default]
    None,
    /// Move forward and back, relative to the camera when scrolling.
    /// When the left mouse button is held, this behavior changes to camera rolling.
    MoveRoll { move_amt: f32, rotate_amt: f32 },
}

#[derive(Clone, Debug)]
/// These sensitivities are in units (position), or radians (orientation) per second.
pub struct InputSettings {
    pub move_sens: f32,
    pub rotate_sens: f32,
    pub rotate_key_sens: f32,
    /// How much the move speed is multiplied when holding the run key.
    pub run_factor: f32,
    pub control_scheme: ControlScheme,
    /// Move forward and backwards with the scroll wheel; largely independent from
    /// control scheme. For now
    pub scroll_behavior: ScrollBehavior,
    pub middle_click_pan: bool,
    /// If true, use device events, instead of window events for the engine's built-in
    /// camera controls. This is a lower-level API. Note that it's incompatible with the Linux
    /// Wayland UI backend.
    pub device_events_for_cam_controls: bool,
}

impl Default for InputSettings {
    fn default() -> Self {
        Self {
            control_scheme: Default::default(),
            move_sens: 1.5,
            rotate_sens: 0.45,
            rotate_key_sens: 1.0,
            run_factor: 5.,
            scroll_behavior: Default::default(),
            middle_click_pan: true,
            device_events_for_cam_controls: false,
        }
    }
}

/// Dims areas "inside" a model. Can make things look much better, more realistic,
/// or help the viewer visually understand a 3d structure.
#[cfg_attr(feature = "app_utils", derive(Encode, Decode))]
#[derive(Clone, Copy, PartialEq, Debug, Default)]
pub enum AmbientOcclusion {
    None,
    #[default]
    /// Screen-space
    Ssao,
    // todo: Not implemented?
    /// Ground-truth AO. More accurate. Maybe slower or tougher to implement?
    Gtao,
}

/// Settings that affect visual quality, and appearance. Most of These
/// also impact performance. (i.e. frame rate)
/// [Article with some details](https://vcg.isti.cnr.it/Publications/2006/TCM06/Tarini_FinalVersionElec.pdf)
#[derive(Clone, Debug)]
pub struct GraphicsSettings {
    pub msaa_samples: u32,
    pub ambient_occlusion: AmbientOcclusion,
    /// Also known as cast shadows
    pub self_shadowing: bool,
    /// None = disabled. Some(strength) enables edge cueing at the given intensity (0.0–1.0 typical).
    pub edge_cueing: Option<f32>,
    /// Inflates meshes by this world-space amount (along normals) in a depth-only prepass,
    /// creating dark halo rings where foreground objects occlude background ones.
    /// None = disabled. Some(0.08) is a reasonable starting point.
    pub depth_aware_halos: Option<f32>,
    /// Contour lines whose opacity scales with the depth jump. None = off. Some(strength).
    pub depth_revealing_contour_lines: Option<f32>,
    /// Contour lines with fixed opacity wherever depth jumps at all. None = off. Some(strength).
    pub intersection_revealing_contour_lines: Option<f32>,
}

impl Default for GraphicsSettings {
    fn default() -> Self {
        Self {
            msaa_samples: 4,
            self_shadowing: true,
            edge_cueing: None,
            ambient_occlusion: AmbientOcclusion::Ssao,
            depth_aware_halos: None,
            depth_revealing_contour_lines: None,
            intersection_revealing_contour_lines: None,
        }
    }
}

#[derive(Clone, Copy, Debug, PartialEq)]
pub enum UiLayoutSides {
    Left,
    Right,
}

#[derive(Clone, Copy, Debug, PartialEq)]
pub enum UiLayoutTopBottom {
    Top,
    Bottom,
}

#[derive(Clone, Debug)]
/// GUI settings
pub struct UiSettings {
    // todo: Currently this only supports one of each ui; can't have both left and right for example.
    pub layout_sides: UiLayoutSides,
    pub layout_top_bottom: UiLayoutTopBottom,
    pub icon_path: Option<String>,
}

impl Default for UiSettings {
    fn default() -> Self {
        Self {
            layout_sides: UiLayoutSides::Left,
            layout_top_bottom: UiLayoutTopBottom::Top,
            icon_path: None,
        }
    }
}

/// This struct is exposed in the API, and passed by callers to indicate in the render,
/// event, GUI etc update functions, if the engine should update various things. When you change
/// the relevant part of the scene, the callbacks (event, etc) should set the corresponding
/// flag in this struct.
///
/// This process is required so certain internal structures like camera buffers, lighting buffers
/// etc are only computed and changed when necessary.
#[derive(Default)]
pub struct EngineUpdates {
    pub meshes: bool,
    pub entities: EntityUpdate,
    pub camera: bool,
    pub lighting: bool,
    /// X, Y. Reported by the UI, e.g. from SidePanel.response.rect.width()
    /// and TopBottomPanel.response.rect.heigh() etc.
    pub ui_reserved_px: (f32, f32),
    /// For updating graphics settings (MSAA etc) from the application.
    pub graphics_settings: Option<GraphicsSettings>,
}