use viewport_lib::{
AttributeKind, BuiltinColourmap, BuiltinMatcap, ColourmapId, ParamVis, ParamVisMode,
};
#[derive(Debug, Clone, PartialEq)]
pub struct TransferFunction {
pub opacity_scale: f32,
pub threshold: Option<(f32, f32)>,
}
impl Default for TransferFunction {
fn default() -> Self {
Self {
opacity_scale: 0.5,
threshold: None,
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum ColourMode {
Solid([f32; 4]),
Colormap {
colormap: ColormapSource,
scalar_range: Option<(f32, f32)>,
},
ByAttribute {
name: String,
kind: AttributeKind,
},
}
impl Default for ColourMode {
fn default() -> Self {
Self::Solid([0.4, 0.6, 1.0, 1.0])
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ColormapSource {
Builtin(BuiltinColourmap),
Uploaded(ColourmapId),
}
impl Default for ColormapSource {
fn default() -> Self {
Self::Builtin(BuiltinColourmap::Viridis)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum ShadingMode {
Flat,
#[default]
Smooth,
Unlit,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MatcapSource {
Builtin(BuiltinMatcap),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SurfaceFaceQuantity {
AngleDistortion,
AreaDistortion,
}
impl SurfaceFaceQuantity {
pub fn attribute_name(self) -> &'static str {
match self {
Self::AngleDistortion => "angle_distortion",
Self::AreaDistortion => "area_distortion",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ParamVisSettings {
pub mode: ParamVisMode,
pub scale: f32,
}
impl Default for ParamVisSettings {
fn default() -> Self {
Self {
mode: ParamVisMode::Checker,
scale: 8.0,
}
}
}
impl From<ParamVisSettings> for ParamVis {
fn from(value: ParamVisSettings) -> Self {
Self {
mode: value.mode,
scale: value.scale,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SurfaceLicVectorField {
TangentU,
TangentV,
Diagonal,
Saddle,
}
impl SurfaceLicVectorField {
pub fn attribute_name(self) -> &'static str {
match self {
Self::TangentU => "tangent_u",
Self::TangentV => "tangent_v",
Self::Diagonal => "tangent_diagonal",
Self::Saddle => "tangent_saddle",
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct SurfaceLicSettings {
pub vector_field: SurfaceLicVectorField,
pub steps: u32,
pub step_size: f32,
pub strength: f32,
}
impl Default for SurfaceLicSettings {
fn default() -> Self {
Self {
vector_field: SurfaceLicVectorField::TangentU,
steps: 20,
step_size: 1.5,
strength: 2.0,
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct PlotStyle {
pub colour_mode: ColourMode,
pub opacity: f32,
pub two_sided: bool,
pub line_width: f32,
pub point_size: f32,
pub glyph_scale: f32,
pub shading: ShadingMode,
pub tube_radius: Option<f32>,
pub transfer_function: Option<TransferFunction>,
pub matcap: Option<MatcapSource>,
pub param_vis: Option<ParamVisSettings>,
pub face_quantity: Option<SurfaceFaceQuantity>,
pub surface_lic: Option<SurfaceLicSettings>,
}
impl Default for PlotStyle {
fn default() -> Self {
Self {
colour_mode: ColourMode::default(),
opacity: 1.0,
two_sided: false,
line_width: 2.0,
point_size: 4.0,
glyph_scale: 1.0,
shading: ShadingMode::Smooth,
tube_radius: None,
transfer_function: None,
matcap: None,
param_vis: None,
face_quantity: None,
surface_lic: None,
}
}
}