use glam::Mat4;
use crate::color::Color;
use crate::scene::axes::{Axes, AxisKind};
use crate::scene::camera::{CameraControls, CameraState, Focus, Framing};
use crate::scene::data::{LineDraw, MeshDraw, PointDraw};
use crate::scene::geometry::{LinesHandle, MeshHandle, PointsHandle};
use crate::scene::style::{GridPlanes, LightRig, LineStyle, Material, PointStyle, SceneStyle};
#[derive(Clone, Debug, Default)]
pub struct SceneSpec {
pub meshes: Vec<MeshDraw>,
pub points: Vec<PointDraw>,
pub lines: Vec<LineDraw>,
pub lights: LightRig,
pub style: SceneStyle,
pub camera: Option<CameraState>,
pub framing: Framing,
pub focus: Option<Focus>,
pub controls: CameraControls,
pub axes: Option<Axes>,
}
impl SceneSpec {
pub fn new() -> Self {
Self::default()
}
pub fn points(mut self, handle: PointsHandle) -> Self {
self.points.push(PointDraw {
geometry: handle,
transform: Mat4::IDENTITY,
style: PointStyle::default(),
labels: None,
});
self
}
pub fn points_styled(mut self, handle: PointsHandle, style: PointStyle) -> Self {
self.points.push(PointDraw {
geometry: handle,
transform: Mat4::IDENTITY,
style,
labels: None,
});
self
}
pub fn points_labeled(
mut self,
handle: PointsHandle,
style: PointStyle,
labels: crate::scene::labels::PointLabels,
) -> Self {
self.points.push(PointDraw {
geometry: handle,
transform: Mat4::IDENTITY,
style,
labels: Some(labels),
});
self
}
pub fn add_points(mut self, draw: PointDraw) -> Self {
self.points.push(draw);
self
}
pub fn mesh(mut self, handle: MeshHandle) -> Self {
self.meshes.push(MeshDraw {
geometry: handle,
transform: Mat4::IDENTITY,
material: Material::default(),
});
self
}
pub fn mesh_with(mut self, handle: MeshHandle, material: Material) -> Self {
self.meshes.push(MeshDraw {
geometry: handle,
transform: Mat4::IDENTITY,
material,
});
self
}
pub fn add_mesh(mut self, draw: MeshDraw) -> Self {
self.meshes.push(draw);
self
}
pub fn lines(mut self, handle: LinesHandle) -> Self {
self.lines.push(LineDraw {
geometry: handle,
transform: Mat4::IDENTITY,
style: Default::default(),
});
self
}
pub fn lines_styled(mut self, handle: LinesHandle, style: LineStyle) -> Self {
self.lines.push(LineDraw {
geometry: handle,
transform: Mat4::IDENTITY,
style,
});
self
}
pub fn add_lines(mut self, draw: LineDraw) -> Self {
self.lines.push(draw);
self
}
pub fn grid(mut self, planes: GridPlanes) -> Self {
self.style.grid.planes = planes;
self
}
pub fn no_grid(mut self) -> Self {
self.style.grid.planes = GridPlanes::NONE;
self
}
pub fn axis_bounds(mut self, axis: AxisKind, min: f32, max: f32) -> Self {
let b = &mut self.style.grid.bounds;
match axis {
AxisKind::X => b.x = Some((min, max)),
AxisKind::Y => b.y = Some((min, max)),
AxisKind::Z => b.z = Some((min, max)),
}
self
}
pub fn background(mut self, color: Color) -> Self {
self.style.background = Some(color);
self
}
pub fn style(mut self, style: SceneStyle) -> Self {
self.style = style;
self
}
pub fn lights(mut self, rig: LightRig) -> Self {
self.lights = rig;
self
}
pub fn camera(mut self, state: CameraState) -> Self {
self.camera = Some(state);
self
}
pub fn framing(mut self, framing: Framing) -> Self {
self.framing = framing;
self
}
pub fn focus(mut self, focus: Focus) -> Self {
self.focus = Some(focus);
self
}
pub fn controls(mut self, controls: CameraControls) -> Self {
self.controls = controls;
self
}
pub fn axes(mut self, axes: Axes) -> Self {
self.axes = Some(axes);
self
}
pub fn axis_titles(
mut self,
x: impl Into<String>,
y: impl Into<String>,
z: impl Into<String>,
) -> Self {
self.axes = Some(Axes::titles(x, y, z));
self
}
}