diff --git a/doc/scripts/generate_starchart.py b/doc/scripts/generate_starchart.py index 9dd3295..1b06e3f 100755 --- a/doc/scripts/generate_starchart.py +++ b/doc/scripts/generate_starchart.py @@ -44,6 +44,8 @@ def render(ra, dec, mag, ci, dist, name): dec = float(dec) mag = float(mag) name = re.sub(r'\s+', ' ', name) + if name == 'Sol': + return distance = 1.0 ra_radians = math.radians(ra * 15) # ra is in [0, 24], multiplying by 15 gives degrees in [0, 360] diff --git a/src/commands.rs b/src/commands.rs index 94cab3f..195de2d 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -39,7 +39,7 @@ struct ParserState { // Actor fields id: String, pos: DVec3, - model: String, + model: Option, model_scale: f32, rotation: Quat, velocity: DVec3, @@ -53,6 +53,7 @@ struct ParserState { is_vehicle: bool, is_clickable: bool, is_targeted_on_startup: bool, + is_sun: bool, has_physics: bool, wants_maxrotation: Option, wants_maxvelocity: Option, @@ -84,7 +85,7 @@ impl Default for ParserState { id: "".to_string(), pos: DVec3::new(0.0, 0.0, 0.0), - model: "".to_string(), + model: None, model_scale: 1.0, rotation: Quat::IDENTITY, velocity: DVec3::splat(0.0), @@ -98,6 +99,7 @@ impl Default for ParserState { is_vehicle: false, is_clickable: true, is_targeted_on_startup: false, + is_sun: false, has_physics: true, wants_maxrotation: None, wants_maxvelocity: None, @@ -177,7 +179,21 @@ pub fn load_defs( ew_spawn.send(SpawnEvent(state)); state = ParserState::default(); state.class = DefClass::Actor; - state.model = model.to_string(); + state.model = Some(model.to_string()); + if let (Ok(x_float), Ok(y_float), Ok(z_float)) = + (x.parse::(), y.parse::(), z.parse::()) { + state.pos = DVec3::new(x_float, y_float, z_float); + } + else { + error!("Can't parse coordinates as floats in def: {line}"); + state = ParserState::default(); + continue; + } + } + ["actor", x, y, z] => { + ew_spawn.send(SpawnEvent(state)); + state = ParserState::default(); + state.class = DefClass::Actor; if let (Ok(x_float), Ok(y_float), Ok(z_float)) = (x.parse::(), y.parse::(), z.parse::()) { state.pos = DVec3::new(x_float, y_float, z_float); @@ -237,6 +253,10 @@ pub fn load_defs( ["moon", "yes"] => { state.model_scale *= 3.0; } + ["sun", "yes"] => { + state.is_sun = true; + state.model_scale *= 5.0; + } ["oxygen", amount] => { if let Ok(amount) = amount.parse::() { state.is_lifeform = true; @@ -461,10 +481,14 @@ fn spawn_entities( actor.insert(Position::from(state.pos)); actor.insert(Rotation::from(state.rotation)); if state.is_sphere { - let sphere_texture_handle: Handle = asset_server.load(format!("textures/{}.jpg", state.model)); + let sphere_texture_handle = if let Some(model) = &state.model { + Some(asset_server.load(format!("textures/{}.jpg", model))) + } else { + None + }; let sphere_handle = meshes.add(Sphere::new(1.0).mesh().uv(128, 128)); let sphere_material_handle = materials.add(StandardMaterial { - base_color_texture: Some(sphere_texture_handle.clone()), + base_color_texture: sphere_texture_handle, perceptual_roughness: 1.0, metallic: 0.0, ..default() @@ -478,13 +502,13 @@ fn spawn_entities( }, ..default() }); - } else { + } else if let Some(model) = &state.model { actor.insert(SceneBundle { transform: Transform { scale: Vec3::splat(state.model_scale), ..default() }, - scene: asset_server.load(world::asset_name_to_path(state.model.as_str())), + scene: asset_server.load(world::asset_name_to_path(model.as_str())), ..default() }); } @@ -524,6 +548,14 @@ fn spawn_entities( actor.insert(actor::Player); actor.insert(actor::PlayerCamera); } + if state.is_sun { + let (r, g, b) = nature::star_color_index_to_rgb(0.656); + actor.insert(materials.add(StandardMaterial { + base_color: Color::rgb(r, g, b) * 13.0, + unlit: true, + ..default() + })); + } if state.is_targeted_on_startup { actor.insert(hud::IsTargeted); } diff --git a/src/data/stars.in b/src/data/stars.in index 6357004..4a1ec14 100644 --- a/src/data/stars.in +++ b/src/data/stars.in @@ -3,7 +3,6 @@ // License: CC BY-SA 4.0: https://creativecommons.org/licenses/by-sa/4.0/ // Each star's values: (x, y, z, magnitude, color index, distance, name) [ -(1.0,0.0,-0.0,-26.7,0.656,0.0,"Sol"), (-0.1875,-0.2876,-0.9392,-1.44,0.009,2.6371,"Sirius"), (-0.06322,-0.7954,-0.6027,-0.62,0.164,94.7867,"Canopus"), (-0.7838,0.3286,0.527,-0.05,1.239,11.2575,"Arcturus"), diff --git a/src/defs.txt b/src/defs.txt index 87ff221..b4956c3 100644 --- a/src/defs.txt +++ b/src/defs.txt @@ -1,4 +1,14 @@ +actor 0 0 0 + id sol + name Sol + scale 696300e3 + sphere yes + sun yes + physics off + actor 0 0 0 jupiter + relativeto sol + orbit 778479000e3 0.5 id jupiter name Jupiter scale 71492e3