MCPcopy Create free account
hub / github.com/Bloom-Engine/engine / parse_args

Function parse_args

tools/bloom-reference/src/main.rs:1998–2212  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1996}
1997
1998fn parse_args() -> Result<Args, String> {
1999 let mut scene_path: Option<String> = None;
2000 let mut out_path: Option<String> = None;
2001 let mut env_path: Option<String> = None;
2002 let mut env_intensity: f32 = 1.0;
2003 let mut sun_direction: Option<Vec3> = Some(Vec3::new(0.4, 0.8, 0.3).normalize());
2004 let mut sun_color = Vec3::new(1.0, 0.98, 0.93);
2005 let mut sun_intensity: f32 = 2.0;
2006 let mut camera_override: Option<CameraSpec> = None;
2007 let mut width: u32 = 512;
2008 let mut height: u32 = 512;
2009 let mut spp: u32 = 64;
2010 let mut max_bounces: u32 = 4;
2011 let mut seed: u64 = 0x12345;
2012 let mut spec_path: Option<String> = None;
2013
2014 let mut width_from_cli = false;
2015 let mut iter = env::args().skip(1);
2016 while let Some(arg) = iter.next() {
2017 match arg.as_str() {
2018 "--spec" => spec_path = iter.next(),
2019 "--scene" => scene_path = iter.next(),
2020 "--out" => out_path = iter.next(),
2021 "--env" => env_path = iter.next(),
2022 "--env-intensity" => {
2023 env_intensity = iter
2024 .next()
2025 .ok_or("--env-intensity needs a value")?
2026 .parse()
2027 .map_err(|e| format!("invalid --env-intensity: {e}"))?;
2028 }
2029 "--sun-dir" => {
2030 let x: f32 = iter
2031 .next()
2032 .ok_or("--sun-dir needs 3 values")?
2033 .parse()
2034 .map_err(|e| format!("invalid --sun-dir x: {e}"))?;
2035 let y: f32 = iter
2036 .next()
2037 .ok_or("--sun-dir needs 3 values")?
2038 .parse()
2039 .map_err(|e| format!("invalid --sun-dir y: {e}"))?;
2040 let z: f32 = iter
2041 .next()
2042 .ok_or("--sun-dir needs 3 values")?
2043 .parse()
2044 .map_err(|e| format!("invalid --sun-dir z: {e}"))?;
2045 sun_direction = Some(Vec3::new(x, y, z).normalize_or_zero());
2046 }
2047 "--no-sun" => {
2048 sun_direction = None;
2049 }
2050 "--sun-intensity" => {
2051 sun_intensity = iter
2052 .next()
2053 .ok_or("--sun-intensity needs a value")?
2054 .parse()
2055 .map_err(|e| format!("invalid --sun-intensity: {e}"))?;

Callers 1

mainFunction · 0.70

Calls 2

load_specFunction · 0.85
iter_mutMethod · 0.80

Tested by

no test coverage detected