feat: complete M2 content workspace and inspector

This commit is contained in:
Rbanh committed 2026-07-17 23:40:49 -04:00
1 parent 931f561e7f
commit cf6eaba534
438 files changed
+59749 -19043

No files matched your search

+53 -2
View File
@@ -1,7 +1,7 @@
//! Shared HDR render-to-texture helpers for editor viewport panels.
use bevy::prelude::*;
use bevy::render::render_resource::TextureFormat;
use bevy::render::render_resource::{Extent3d, TextureFormat};
/// Offscreen render target displayed by the primary editor viewport.
#[derive(Debug, Clone)]
@@ -13,16 +13,33 @@ pub struct ViewportTarget {
#[derive(Resource, Default, Debug, Clone)]
pub struct ViewportRenderTarget(pub Option<ViewportTarget>);
/// Allocates or reuses an HDR offscreen color target when the panel size changes.
/// Allocates or resizes the HDR offscreen color target when the panel size changes.
///
/// The asset identity remains stable across ordinary panel resizing. Besides avoiding needless
/// camera and bind-group churn, this prevents Egui's strong image registration from retaining one
/// full-resolution HDR target for every splitter movement.
pub fn ensure_hdr_panel_target(
physical_size: UVec2,
last_size: &mut Option<UVec2>,
current: Option<&Handle<Image>>,
images: &mut Assets<Image>,
) -> Option<Handle<Image>> {
if *last_size == Some(physical_size) {
return None;
}
*last_size = Some(physical_size);
if let Some(current) = current {
if let Some(mut image) = images.get_mut(current) {
image.resize(Extent3d {
width: physical_size.x,
height: physical_size.y,
depth_or_array_layers: 1,
});
return None;
}
}
Some(images.add(Image::new_target_texture(
physical_size.x,
physical_size.y,
@@ -33,3 +50,37 @@ pub fn ensure_hdr_panel_target(
/// Standard HDR format for editor panel render targets.
pub const PANEL_TARGET_FORMAT: TextureFormat = TextureFormat::Rgba16Float;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn repeated_panel_resize_reuses_one_hdr_image_asset() {
let mut images = Assets::<Image>::default();
let mut last_size = None;
let initial =
ensure_hdr_panel_target(UVec2::new(1920, 1080), &mut last_size, None, &mut images)
.expect("first size allocates the viewport target");
let initial_id = initial.id();
for width in [1600, 1280, 900, 1280, 1600, 1920] {
assert!(
ensure_hdr_panel_target(
UVec2::new(width, 1080),
&mut last_size,
Some(&initial),
&mut images,
)
.is_none(),
"resize should mutate the existing image"
);
assert_eq!(initial.id(), initial_id);
assert_eq!(
images.get(&initial).expect("target remains live").width(),
width
);
assert_eq!(images.len(), 1);
}
}
}