show actual names of stars when targeting them

This commit is contained in:
yuni 2024-04-08 01:08:32 +02:00
parent 81187b4fe6
commit 9f15e78e07
5 changed files with 15591 additions and 15574 deletions

View file

@ -1,10 +1,13 @@
#!/usr/bin/env python
# This script requires the following file in the assets/tmp/ directory:
# This script requires the following file in the extra/ directory:
# https://github.com/astronexus/HYG-Database/blob/cbd21013d2bb89732b893be357a6f41836dbe614/hyg/CURRENT/hygdata_v41.csv
import csv
import sys
import math
import re
PATH = "extra/hygdata_v41.csv"
#def entry(ra_hour, ra_min, ra_sec, dec_deg, dec_min, dec_sec, mag, name, color_index):
# return [
@ -28,19 +31,20 @@ import math
# Meissa (orion's head, 8th brightest star in orion) = 3.33
MAX_APPARENT_MAGNITUDE = 7.0
print("// The \"STARS\" constant was autogenerated by \"genrate_starchart.py\" using data")
print("// from the HYG database: https://github.com/astronexus/HYG-Database/tree/main/hyg")
print("// This file was autogenerated by \"genrate_starchart.py\" using data from the")
print("// HYG database: https://github.com/astronexus/HYG-Database/tree/main/hyg")
print("// License: CC BY-SA 4.0: https://creativecommons.org/licenses/by-sa/4.0/")
print("")
print("// Each star's values: [x, y, z, magnitude, color index]")
print("pub const STARS: &[[f32; 5]] = &[")
print("// Each star's values: [x, y, z, magnitude, color index, distance, name]")
print("pub const STARS: &[(f32; f32, f32, f32, f32, f32, str)] = &[")
def render(ra, dec, mag, ci, proper):
def render(ra, dec, mag, ci, dist, name):
# Takes ra/deg in degrees
ra = float(ra)
dec = float(dec)
mag = float(mag)
name = re.sub(r'\s+', ' ', name)
distance = 1.0
ra_radians = math.radians(ra * 15) # ra is in [0, 24], multiplying by 15 gives degrees in [0, 360]
@ -53,18 +57,20 @@ def render(ra, dec, mag, ci, proper):
# Correct for differences in coordinate system axes
x, y, z = x, z, y
comment = f" // {proper}" if proper else ""
#brightness = 2.512 ** (0 - mag)
brightness = 2.512 ** (0 - mag)
print(f' ({x:.04}, {y:.04}, {z:.04}, {mag:.04}, {ci}, {dist}, "{name}"),')
print(f" [{x:.04}, {y:.04}, {z:.04}, {mag:.04}, {ci}],{comment}")
def clean_name(string):
return "".join([c for c in string if c.isalnum() or c in ' -_'])
total = 0
count = 0
count_extra = 0
entries = []
with open("assets/tmp/hygdata_v41.csv", "r", encoding="utf-8") as f:
with open(PATH, "r", encoding="utf-8") as f:
for entry in csv.DictReader(f):
entries.append(entry)
@ -76,13 +82,18 @@ for entry in entries:
dec = entry['dec']
mag = entry['mag']
ci = entry['ci']
proper = entry['proper']
proper = "".join([c for c in proper if c.isalnum() or c in ' -_'])
dist = entry['dist']
name = clean_name(entry['proper'])
if not name:
name = clean_name(entry['bf'])
if not name:
name = clean_name(entry['gl'])
if not all([ra, dec, mag, ci]):
continue
if float(mag) > MAX_APPARENT_MAGNITUDE:
continue
render(ra, dec, mag, ci, proper)
render(ra, dec, mag, ci, dist, name)
count += 1
#for entry in CUSTOM_ENTRIES:
# render(entry[0], entry[1], entry[2], entry[3], entry[4])

View file

@ -6,6 +6,7 @@ mod commands;
mod effects;
mod hud;
mod settings;
mod stars;
mod world;
#[allow(dead_code)]

File diff suppressed because it is too large Load diff

15551
src/stars.rs Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,4 @@
use crate::{actor, hud, nature, settings};
use crate::{actor, hud, nature, settings, stars};
use bevy::prelude::*;
use bevy::render::render_resource::{AsBindGroup, ShaderRef};
use bevy::math::{DVec3, I64Vec3};
@ -123,8 +123,8 @@ pub fn setup(
// Generate starmap
let sphere_handle = meshes.add(Sphere::new(1.0));
let mut starcount = 0;
for star in nature::STARS {
let mag = star[3];
for star in stars::STARS {
let mag = star.3;
if mag > STARS_MAX_MAGNITUDE {
continue;
}
@ -142,26 +142,31 @@ pub fn setup(
1000.0 * (0.230299 * mag * mag - 3.09013 * mag + 15.1782)
} * 100.0
};
let (r, g, b) = nature::star_color_index_to_rgb(star[4]);
let (r, g, b) = nature::star_color_index_to_rgb(star.4);
let star_color_handle = materials.add(StandardMaterial {
base_color: Color::rgb(scale_color(r), scale_color(g), scale_color(b)),
unlit: true,
..default()
});
let dist = 1e9;
let name = if star.6.is_empty() {
"Uncharted Star".to_string()
} else {
star.6.to_string()
};
commands.spawn((
Star,
hud::IsClickable {
name: Some("Star".to_string()),
distance: Some(10000000000.0),
name: Some(name),
distance: Some(nature::PARSEC2METER * star.5 as f64),
},
PbrBundle {
mesh: sphere_handle.clone(),
material: star_color_handle,
transform: Transform::from_xyz(
dist * star[0],
dist * star[1],
dist * star[2],
dist * star.0,
dist * star.1,
dist * star.2,
)
.with_scale(Vec3::splat(scale_size(mag))),
..default()