|
|
|
@ -11,7 +11,7 @@ use bevy::{
|
|
|
|
},
|
|
|
|
},
|
|
|
|
window::PrimaryWindow,
|
|
|
|
window::PrimaryWindow,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
use serde::{Deserialize, Deserializer};
|
|
|
|
use serde::{Deserialize, Deserializer, de};
|
|
|
|
|
|
|
|
|
|
|
|
pub(crate) struct Display3dPlugin;
|
|
|
|
pub(crate) struct Display3dPlugin;
|
|
|
|
|
|
|
|
|
|
|
|
@ -83,13 +83,13 @@ impl Plugin for Display3dPlugin {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Deserialize, Default)]
|
|
|
|
#[derive(Debug, Deserialize, Default)]
|
|
|
|
struct Display3dTweaks {
|
|
|
|
pub(crate) struct Display3dTweaks {
|
|
|
|
#[serde(default)]
|
|
|
|
#[serde(default)]
|
|
|
|
fog: FogTweaks,
|
|
|
|
fog: FogTweaks,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
|
struct FogTweaks {
|
|
|
|
struct FogTweaks {
|
|
|
|
#[serde(default)]
|
|
|
|
#[serde(default)]
|
|
|
|
color: Color,
|
|
|
|
color: Color,
|
|
|
|
@ -101,6 +101,19 @@ struct FogTweaks {
|
|
|
|
falloff: FogFalloff,
|
|
|
|
falloff: FogFalloff,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl Default for FogTweaks {
|
|
|
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
|
|
|
FogTweaks {
|
|
|
|
|
|
|
|
color: Color::WHITE,
|
|
|
|
|
|
|
|
light_color: Color::WHITE,
|
|
|
|
|
|
|
|
exponent: 1.0,
|
|
|
|
|
|
|
|
falloff: FogFalloff::Exponential {
|
|
|
|
|
|
|
|
density: 1.0,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn default_fog_falloff() -> FogFalloff {
|
|
|
|
fn default_fog_falloff() -> FogFalloff {
|
|
|
|
FogFalloff::Exponential {
|
|
|
|
FogFalloff::Exponential {
|
|
|
|
density: 1.0,
|
|
|
|
density: 1.0,
|
|
|
|
@ -108,26 +121,51 @@ fn default_fog_falloff() -> FogFalloff {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn deserialize_fog_falloff<'de, D: Deserializer<'de>>(deserializer: D) -> Result<FogFalloff, D::Error> {
|
|
|
|
fn deserialize_fog_falloff<'de, D: Deserializer<'de>>(deserializer: D) -> Result<FogFalloff, D::Error> {
|
|
|
|
if let Ok(s) = String::deserailize(deserializer) {
|
|
|
|
if let Ok(s) = String::deserialize(deserializer) {
|
|
|
|
// Linear [start f32] [end f32]
|
|
|
|
// Linear [start f32] [end f32]
|
|
|
|
if s.starts_with("Linear") {
|
|
|
|
if s.starts_with("Linear") {
|
|
|
|
todo!("Parse linear parameters");
|
|
|
|
let mut parts = s.split(' ');
|
|
|
|
Ok(FogFalloff::Linear { ..default() })
|
|
|
|
let start: f32 = parts.nth(1).expect("Fog Linear Start").parse().expect("Floating point number");
|
|
|
|
|
|
|
|
let end: f32 = parts.nth(2).expect("Fog Linear End").parse().expect("Floating point number");
|
|
|
|
|
|
|
|
Ok(FogFalloff::Linear { start, end })
|
|
|
|
// Exponential [density f32]
|
|
|
|
// Exponential [density f32]
|
|
|
|
} else if s.starts_with("Exponential") {
|
|
|
|
} else if s.starts_with("Exponential") {
|
|
|
|
todo!("Parse exponential parameters");
|
|
|
|
let mut parts = s.split(' ');
|
|
|
|
Ok(FogFalloff::Exponential { ..default() })
|
|
|
|
let density: f32 = parts.nth(1).expect("Fog Exponential Density").parse().expect("Floating point number");
|
|
|
|
|
|
|
|
Ok(FogFalloff::Exponential { density })
|
|
|
|
// ExponentialSquared [density f32]
|
|
|
|
// ExponentialSquared [density f32]
|
|
|
|
} else if s.starts_with("ExponentialSquared") {
|
|
|
|
} else if s.starts_with("ExponentialSquared") {
|
|
|
|
todo!("Parse exponentialsquared parameters");
|
|
|
|
let mut parts = s.split(' ');
|
|
|
|
Ok(FogFalloff::ExponentialSquared { ..default() })
|
|
|
|
let density: f32 = parts.nth(1).expect("Fog Exponential Density Squared").parse().expect("Floating point number");
|
|
|
|
|
|
|
|
Ok(FogFalloff::ExponentialSquared { density })
|
|
|
|
// Atmospheric (extinction [r: f32] [g: f32] [b: f32]) (inscattering [r: f32] [g: f32] [b: f32])
|
|
|
|
// Atmospheric (extinction [r: f32] [g: f32] [b: f32]) (inscattering [r: f32] [g: f32] [b: f32])
|
|
|
|
} else if s.startswith("Atmospheric") {
|
|
|
|
} else if s.starts_with("Atmospheric") {
|
|
|
|
todo!("Parse atmospheric parameters");
|
|
|
|
let extinction = {
|
|
|
|
Ok(FogFalloff::Atmospheric { ..default() })
|
|
|
|
let start = s.find("extinction").expect("Extinction start");
|
|
|
|
|
|
|
|
let end = s[start..].match_indices(')').find_map(|(i, _)| Some(i)).expect("Extinction end");
|
|
|
|
|
|
|
|
let mut parts = s[start..start+end].split(' ');
|
|
|
|
|
|
|
|
let _ = parts.next();
|
|
|
|
|
|
|
|
let r: f32 = parts.next().expect("red value").parse().expect("Floating point number");
|
|
|
|
|
|
|
|
let g: f32 = parts.next().expect("green value").parse().expect("Floating point number");
|
|
|
|
|
|
|
|
let b: f32 = parts.next().expect("blue value").parse().expect("Floating point number");
|
|
|
|
|
|
|
|
Vec3::new(r, g, b)
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
let inscattering = {
|
|
|
|
|
|
|
|
let start = s.find("inscattering").expect("Inscattering start");
|
|
|
|
|
|
|
|
let end = s[start..].match_indices(')').find_map(|(i, _)| Some(i)).expect("Inscattering end");
|
|
|
|
|
|
|
|
let mut parts = s[start..start+end].split(' ');
|
|
|
|
|
|
|
|
let _ = parts.next();
|
|
|
|
|
|
|
|
let r: f32 = parts.next().expect("red value").parse().expect("Floating point number");
|
|
|
|
|
|
|
|
let g: f32 = parts.next().expect("green value").parse().expect("Floating point number");
|
|
|
|
|
|
|
|
let b: f32 = parts.next().expect("blue value").parse().expect("Floating point number");
|
|
|
|
|
|
|
|
Vec3::new(r, g, b)
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(FogFalloff::Atmospheric { extinction, inscattering })
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Err(D::Error)
|
|
|
|
Err(de::Error::custom("Failed to parse fog value"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Err(de::Error::custom("Failed to parse fog value"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|