oxihuman_export/
world_export.rs1#![allow(dead_code)]
4
5#[derive(Debug, Clone)]
9pub struct WorldData {
10 pub name: String,
11 pub horizon_color: [f32; 3],
12 pub ambient_color: [f32; 3],
13 pub ambient_energy: f32,
14 pub fog_start: f32,
15 pub fog_end: f32,
16 pub hdri_path: Option<String>,
17}
18
19pub fn new_world_data(name: &str) -> WorldData {
21 WorldData {
22 name: name.to_string(),
23 horizon_color: [0.05, 0.05, 0.05],
24 ambient_color: [0.0, 0.0, 0.0],
25 ambient_energy: 1.0,
26 fog_start: 5.0,
27 fog_end: 50.0,
28 hdri_path: None,
29 }
30}
31
32pub fn world_to_json(w: &WorldData) -> String {
34 format!(
35 "{{\"name\":\"{}\",\"ambient_energy\":{},\"fog_start\":{},\"fog_end\":{},\"has_hdri\":{}}}",
36 w.name,
37 w.ambient_energy,
38 w.fog_start,
39 w.fog_end,
40 w.hdri_path.is_some()
41 )
42}
43
44pub fn world_has_hdri(w: &WorldData) -> bool {
46 w.hdri_path.is_some()
47}
48
49pub fn world_ambient_energy(w: &WorldData) -> f32 {
51 w.ambient_energy
52}
53
54pub fn world_fog_visibility(w: &WorldData) -> f32 {
56 (w.fog_end - w.fog_start).max(0.0)
57}
58
59#[cfg(test)]
60mod tests {
61 use super::*;
62
63 #[test]
64 fn test_new_world_data() {
65 let w = new_world_data("world");
66 assert_eq!(w.name, "world");
67 }
68
69 #[test]
70 fn test_world_to_json() {
71 let w = new_world_data("env");
72 let j = world_to_json(&w);
73 assert!(j.contains("env"));
74 }
75
76 #[test]
77 fn test_world_has_hdri_false() {
78 let w = new_world_data("w");
79 assert!(!world_has_hdri(&w));
80 }
81
82 #[test]
83 fn test_world_ambient_energy() {
84 let w = new_world_data("w");
85 assert!((world_ambient_energy(&w) - 1.0).abs() < 1e-5);
86 }
87
88 #[test]
89 fn test_world_fog_visibility() {
90 let w = new_world_data("w");
91 assert!(world_fog_visibility(&w) > 0.0);
92 }
93}