use super::{fan::FanGeometry, lighting::ExitLighting, ray_trace::StoneArena};
use crate::{
geometry::tool::{StoneGeometry, ToolPrimitive},
optics::{
materials::GemMaterial,
raytracer::{EnvironmentSource, build_plane_soa},
},
simd::PlanesSoA32,
};
pub(super) struct PreparedEval<'a> {
plane_soa: PlanesSoA32,
tools: &'a [ToolPrimitive],
pub(super) fan: FanGeometry,
pub(super) nd: f32,
pub(super) n_f: f32,
pub(super) n_c: f32,
pub(super) lighting: ExitLighting<'a>,
pub(super) diag_material: Option<String>,
}
impl<'a> PreparedEval<'a> {
pub(super) fn new(
geom: StoneGeometry<'a>,
material: &GemMaterial,
environment: EnvironmentSource<'a>,
) -> Option<Self> {
let planes = geom.planes;
if planes.is_empty() {
return None;
}
Some(Self {
plane_soa: build_plane_soa(planes),
tools: geom.tools,
fan: FanGeometry::for_planes(planes),
nd: material.dispersion.evaluate(589.3).max(1.1),
n_f: material.dispersion.evaluate(486.1).max(1.001),
n_c: material.dispersion.evaluate(656.3).max(1.001),
lighting: ExitLighting::new(environment),
diag_material: std::env::var("DIAG_FIRE_DEBUG")
.is_ok()
.then(|| material.name.clone()),
})
}
pub(super) const fn stone(&self) -> StoneArena<'_> {
StoneArena {
plane_soa: &self.plane_soa,
tools: self.tools,
}
}
}