use super::RenderContext;
use crate::{
bridge::sample_cursor::LiveEpoch,
settings::model::{LiveComputeTarget, LocalComputeTarget, LocalPreviewScale},
};
use glam::Vec3;
use indicatrix::{
geometry::{plane::GpuFacetPlane, tool::ToolPrimitive},
optics::{fluorescence::Fluorescence, materials::GemMaterial, raytracer::LightingPreset},
renderer::env_map::EnvironmentMap,
};
use std::sync::{Arc, Mutex};
pub fn load_env_map(path: &str) -> Result<Arc<EnvironmentMap>, String> {
crate::bridge::remote::hdr_asset::load_hdr_file(std::path::Path::new(path)).map(|(map, _)| map)
}
pub(in crate::bridge::render_thread) struct FrameInputs {
pub(in crate::bridge::render_thread) width: u32,
pub(in crate::bridge::render_thread) height: u32,
pub(in crate::bridge::render_thread) yaw: f32,
pub(in crate::bridge::render_thread) pitch: f32,
pub(in crate::bridge::render_thread) distance: f32,
pub(in crate::bridge::render_thread) light_yaw: f32,
pub(in crate::bridge::render_thread) light_pitch: f32,
pub(in crate::bridge::render_thread) material_name: String,
pub(in crate::bridge::render_thread) material_override: Option<GemMaterial>,
pub(in crate::bridge::render_thread) material_unresolved: Option<String>,
pub(in crate::bridge::render_thread) lighting_preset: LightingPreset,
pub(in crate::bridge::render_thread) backdrop: crate::settings::model::Backdrop,
pub(in crate::bridge::render_thread) surface_glare: f32,
pub(in crate::bridge::render_thread) head_shadow_deg: f32,
pub(in crate::bridge::render_thread) target_samples: u32,
pub(in crate::bridge::render_thread) max_bounces: u32,
pub(in crate::bridge::render_thread) exposure: f32,
pub(in crate::bridge::render_thread) inclusion_sigma_s: f32,
pub(in crate::bridge::render_thread) c_axis_override: Option<Vec3>,
pub(in crate::bridge::render_thread) girdle_frosted: bool,
pub(in crate::bridge::render_thread) edge_rounding_radius: f32,
pub(in crate::bridge::render_thread) stone_width_mm: f32,
pub(in crate::bridge::render_thread) active_planes: Arc<Vec<GpuFacetPlane>>,
pub(in crate::bridge::render_thread) active_tools: Arc<Vec<ToolPrimitive>>,
pub(in crate::bridge::render_thread) custom_materials: Arc<Vec<GemMaterial>>,
pub(in crate::bridge::render_thread) fluorescence: Option<Arc<Fluorescence>>,
pub(in crate::bridge::render_thread) running: bool,
pub(in crate::bridge::render_thread) dirty: bool,
pub(in crate::bridge::render_thread) paused: bool,
pub(in crate::bridge::render_thread) tab_visible: bool,
pub(in crate::bridge::render_thread) denoise_enabled: bool,
pub(in crate::bridge::render_thread) redisplay_requested: bool,
pub(in crate::bridge::render_thread) remote_active: bool,
pub(in crate::bridge::render_thread) live_epoch: Option<Arc<LiveEpoch>>,
pub(in crate::bridge::render_thread) export_active: bool,
pub(in crate::bridge::render_thread) live_compute_target: LiveComputeTarget,
pub(in crate::bridge::render_thread) local_compute_target: LocalComputeTarget,
pub(in crate::bridge::render_thread) local_preview_scale: LocalPreviewScale,
pub(in crate::bridge::render_thread) camera_moving: bool,
pub(in crate::bridge::render_thread) env_map: Option<Arc<EnvironmentMap>>,
pub(in crate::bridge::render_thread) scene_generation: u64,
}
pub(in crate::bridge::render_thread) fn snapshot_frame_inputs(
ctx: &Arc<Mutex<RenderContext>>,
) -> FrameInputs {
let mut ctx = RenderContext::lock(ctx);
let dirty = ctx.dirty;
ctx.dirty = false;
let redisplay_requested = ctx.redisplay_requested;
ctx.redisplay_requested = false;
let scene_generation = ctx.scene_generation();
FrameInputs {
width: ctx.width,
height: ctx.height,
yaw: ctx.yaw,
pitch: ctx.pitch,
distance: ctx.distance,
light_yaw: ctx.light_yaw,
light_pitch: ctx.light_pitch,
material_name: ctx.material_name.clone(),
material_override: ctx.tinted_material_override(),
material_unresolved: ctx.material_unresolved.clone(),
lighting_preset: ctx.lighting_preset,
backdrop: ctx.backdrop,
surface_glare: ctx.surface_glare,
head_shadow_deg: ctx.head_shadow_deg,
target_samples: ctx.target_samples,
max_bounces: ctx.max_bounces,
exposure: ctx.exposure,
inclusion_sigma_s: ctx.inclusion_sigma_s,
c_axis_override: ctx.c_axis_override,
girdle_frosted: ctx.girdle_frosted,
edge_rounding_radius: ctx.edge_rounding_radius,
stone_width_mm: ctx.stone_width_mm,
active_planes: Arc::clone(&ctx.active_planes),
active_tools: Arc::clone(&ctx.active_tools),
custom_materials: Arc::clone(&ctx.custom_materials),
fluorescence: ctx.active_fluorescence(),
running: ctx.running,
dirty,
paused: ctx.paused,
tab_visible: ctx.tab_visible,
denoise_enabled: ctx.denoise_enabled,
redisplay_requested,
remote_active: ctx.remote_active,
live_epoch: ctx.live_epoch.clone(),
export_active: ctx.export_active(),
live_compute_target: ctx.effective_live_target(),
local_compute_target: ctx.local_compute_target,
local_preview_scale: ctx.local_preview_scale,
camera_moving: ctx.camera_moving,
env_map: ctx.env_map.clone(),
scene_generation,
}
}