Skip to main content

pfx_scene/types/
sky.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
4#[serde(rename_all = "snake_case")]
5pub enum SkyKind {
6    Analytic,
7    Hdr,
8    Room,
9    Mix,
10}
11
12#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
13#[serde(deny_unknown_fields)]
14pub struct Sky {
15    pub kind: SkyKind,
16    #[serde(default, skip_serializing_if = "Option::is_none")]
17    pub path: Option<String>,
18    #[serde(default, skip_serializing_if = "Option::is_none")]
19    pub rotation_deg: Option<f32>,
20    #[serde(default, skip_serializing_if = "Option::is_none")]
21    pub intensity: Option<f32>,
22    #[serde(default, skip_serializing_if = "Option::is_none")]
23    pub turbidity: Option<f32>,
24    #[serde(default, skip_serializing_if = "Option::is_none")]
25    pub ground_albedo: Option<[f32; 3]>,
26    #[serde(default, skip_serializing_if = "Option::is_none")]
27    pub ambient: Option<f32>,
28    #[serde(default, skip_serializing_if = "Option::is_none")]
29    pub prepare: Option<Prepare>,
30    #[serde(default, skip_serializing_if = "Option::is_none")]
31    pub room: Option<Room>,
32    #[serde(default, skip_serializing_if = "Option::is_none")]
33    pub weight: Option<f32>,
34    #[serde(default, skip_serializing_if = "Vec::is_empty")]
35    pub layer: Vec<Sky>,
36}
37
38impl Sky {
39    pub const TURBIDITY: f32 = 3.0;
40    pub const GROUND_ALBEDO: [f32; 3] = [0.2; 3];
41    pub const AMBIENT: f32 = 1.0;
42    pub const INTENSITY: f32 = 1.0;
43    pub const WEIGHT: f32 = 1.0;
44}
45
46#[derive(Clone, Copy, Debug, Default, PartialEq, Serialize, Deserialize)]
47#[serde(deny_unknown_fields)]
48pub struct Prepare {
49    #[serde(default, skip_serializing_if = "Option::is_none")]
50    pub cap: Option<f32>,
51    #[serde(default, skip_serializing_if = "Option::is_none")]
52    pub balance: Option<[f32; 3]>,
53    #[serde(default, skip_serializing_if = "Option::is_none")]
54    pub mean: Option<f32>,
55}
56
57#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
58#[serde(deny_unknown_fields)]
59pub struct Room {
60    #[serde(default = "Room::width")]
61    pub width: u32,
62    #[serde(default = "Room::grey")]
63    pub floor: [f32; 3],
64    #[serde(default = "Room::grey")]
65    pub wall: [f32; 3],
66    #[serde(default = "Room::grey")]
67    pub ceiling: [f32; 3],
68    #[serde(default, skip_serializing_if = "Vec::is_empty")]
69    pub lights: Vec<RoomLamp>,
70}
71
72impl Room {
73    pub const MAX_WIDTH: u32 = 8192;
74
75    fn width() -> u32 {
76        64
77    }
78
79    fn grey() -> [f32; 3] {
80        [0.5; 3]
81    }
82}
83
84impl Default for Room {
85    fn default() -> Self {
86        Self {
87            width: Self::width(),
88            floor: Self::grey(),
89            wall: Self::grey(),
90            ceiling: Self::grey(),
91            lights: Vec::new(),
92        }
93    }
94}
95
96#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
97#[serde(deny_unknown_fields)]
98pub struct RoomLamp {
99    #[serde(default, skip_serializing_if = "String::is_empty")]
100    pub name: String,
101    #[serde(default)]
102    pub az: f32,
103    #[serde(default)]
104    pub el: f32,
105    #[serde(default = "RoomLamp::one")]
106    pub power: f32,
107    #[serde(default = "RoomLamp::white")]
108    pub color: [f32; 3],
109    #[serde(default = "RoomLamp::spread")]
110    pub width: f32,
111    #[serde(default = "RoomLamp::spread")]
112    pub height: f32,
113    #[serde(default = "RoomLamp::soft")]
114    pub soft: f32,
115    #[serde(default)]
116    pub slats: f32,
117    #[serde(default = "RoomLamp::one")]
118    pub open: f32,
119}
120
121impl RoomLamp {
122    fn one() -> f32 {
123        1.0
124    }
125
126    fn white() -> [f32; 3] {
127        [1.0; 3]
128    }
129
130    fn spread() -> f32 {
131        45.0
132    }
133
134    fn soft() -> f32 {
135        0.1
136    }
137}
138
139impl Default for RoomLamp {
140    fn default() -> Self {
141        Self {
142            name: String::new(),
143            az: 0.0,
144            el: 0.0,
145            power: Self::one(),
146            color: Self::white(),
147            width: Self::spread(),
148            height: Self::spread(),
149            soft: Self::soft(),
150            slats: 0.0,
151            open: Self::one(),
152        }
153    }
154}