View backgrounds: image colours as stored, viewport style name, adjust automation

- The background image texture is not an sRGB view: the image is drawn with
  its own colours, as the solid and gradient colours are.
- An entered paper-space viewport shows its named visual style (Realistic,
  ...) in the render-mode picker, and a mode picked there is recorded as the
  viewport's visual style.
- The view_background automation action takes offset=x,y and scale=x,y.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
ramox81andClaude Opus 5.5 committed 2026-10-13 09:44:49 +03:00
1 parent b5b505ee9d
commit 064da8829e
8 files changed
+80 -19

No files matched your search

+16 -1
View File
@@ -336,6 +336,12 @@ impl Scene {
/// The visual style of the active Model tile's viewport record.
pub fn active_visual_style(&self) -> Handle {
if self.current_layout != "Model" {
return match self.active_viewport.and_then(|handle| self.document.get_entity(handle)) {
Some(EntityType::Viewport(value)) => value.visual_style_handle,
_ => Handle::NULL,
};
}
self.active_tile_vport_handle()
.and_then(|handle| self.document.vports.iter().find(|value| value.handle == handle))
.map_or(Handle::NULL, |value| value.visual_style_handle)
@@ -348,7 +354,16 @@ impl Scene {
codec::objects::ObjectType::VisualStyle(style) if style.description == name => Some(*handle),
_ => None,
});
let (Some(style), Some(handle)) = (style, self.active_tile_vport_handle()) else { return };
let Some(style) = style else { return };
if self.current_layout != "Model" {
if let Some(handle) = self.active_viewport {
if let Some(EntityType::Viewport(value)) = self.document.get_entity_mut(handle) {
value.visual_style_handle = style;
}
}
return;
}
let Some(handle) = self.active_tile_vport_handle() else { return };
if let Some(value) = self.document.vports.iter_mut().find(|value| value.handle == handle) {
value.visual_style_handle = style;
}
+18 -4
View File
@@ -3996,7 +3996,8 @@ analytic={:.1} regular={:.1} blocks={:.1}",
}
let upload = |label: &'static str,
image: Option<&crate::scene::model::image_model::DecodedImage>,
fallback: [u8; 4]| {
fallback: [u8; 4],
format: wgpu::TextureFormat| {
let (width, height, pixels) = image
.map(|image| (image.width, image.height, image.pixels.as_slice()))
.unwrap_or((1, 1, fallback.as_slice()));
@@ -4010,7 +4011,7 @@ analytic={:.1} regular={:.1} blocks={:.1}",
mip_level_count: 1,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Rgba8UnormSrgb,
format,
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
view_formats: &[],
});
@@ -4030,8 +4031,21 @@ analytic={:.1} regular={:.1} blocks={:.1}",
);
texture
};
self.background_texture = upload("background.texture", background, [0, 0, 0, 255]);
self.environment_texture = upload("environment.texture", environment, [128, 128, 128, 255]);
// The background image is drawn as it is, like the solid and gradient
// colours (an sRGB view would darken it a second time); the
// environment map stays sRGB for lighting.
self.background_texture = upload(
"background.texture",
background,
[0, 0, 0, 255],
wgpu::TextureFormat::Rgba8Unorm,
);
self.environment_texture = upload(
"environment.texture",
environment,
[128, 128, 128, 255],
wgpu::TextureFormat::Rgba8UnormSrgb,
);
self.rebuild_frame_bind_group(device);
self.background_source_id = background_id;
self.environment_source_id = environment_id;