scenes.in: extract scale from blender scene files

This commit is contained in:
yuni 2024-11-17 17:28:34 +01:00
parent 080e14c7ee
commit 26e5d3456c
3 changed files with 39 additions and 54 deletions

View file

@ -40,6 +40,8 @@ fn main() -> std::io::Result<()> {
}
fn extract_scene(file: &mut File, scene_name: &str, blend_file: &str) -> std::io::Result<()> {
// Info about .blender file format:
// https://www.janwalter.org/jekyll/blender/rust/blendinfo/2019/05/28/blend_info.html
let blend = Blend::from_path(blend_file).expect("error loading blend file");
for obj in blend.instances_with_code(*b"OB") {
let loc: Vec<f32> = if obj.is_valid("loc") {
@ -52,9 +54,14 @@ fn extract_scene(file: &mut File, scene_name: &str, blend_file: &str) -> std::io
} else {
vec![0.0, 0.0, 0.0]
};
let scale: Vec<f32> = if obj.is_valid("size") {
obj.get_f32_vec("size")
} else {
vec![1.0, 1.0, 1.0]
};
let name = obj.get("id").get_string("name");
if let Some(name) = get_scene_object_name(name.as_str()) {
write!(file, "({scene_name:?}, {name:?}, {loc:?}, {rot:?}),\n")?;
write!(file, "({scene_name:?}, {name:?}, {loc:?}, {rot:?}, {scale:?}),\n")?;
}
}
Ok(())

View file

@ -749,7 +749,7 @@ fn spawn_scenes(
.clone()
.unwrap_or_else(|| String::from("ERROR_NO_SCENE_NAME"));
let scene_defs = include!("data/scenes.in");
for (name, template, pos, rot) in scene_defs {
for (name, template, pos, rot, scale) in scene_defs {
let pos = DVec3::new(
root_state.pos[0] + pos[0],
root_state.pos[1] + pos[2],
@ -760,6 +760,7 @@ fn spawn_scenes(
let mut state = ParserState::default();
state.class = DefClass::Actor;
state.pos = pos;
state.model_scale = scale[0];
state.relative_to = root_state.relative_to.clone();
// Bevy's X is Blender's X (rot[0])
@ -813,9 +814,6 @@ fn spawn_scenes(
// command: name Cruiser
state.name = Some("Shipping Container".to_string());
// command: scale 8
state.model_scale = 8.0;
// command: angularmomentum 0 0 0
state.angular_momentum = DVec3::ZERO;
@ -827,20 +825,12 @@ fn spawn_scenes(
ew_spawn.send(SpawnEvent(state));
}
"fueltank" | "fueltanksmall" => {
"fueltank" => {
state.model = Some("fueltank".to_string());
// command: name "Fuel Tank"
state.name = Some("Fuel Tank".to_string());
if template == "fueltank" {
// command: scale 8
state.model_scale = 8.0;
} else {
// command: scale 4
state.model_scale = 4.0;
}
// command: angularmomentum 0 0 0
state.angular_momentum = DVec3::ZERO;
@ -868,9 +858,6 @@ fn spawn_scenes(
// command: id lunaplatform
state.id = String::from("lunaplatform");
// command: scale 30
state.model_scale = 30.0;
// command: angularmomentum 0 0 0
state.angular_momentum = DVec3::ZERO;
@ -893,9 +880,6 @@ fn spawn_scenes(
state.collider_is_one_mesh_of_scene = true;
state.collider_is_mesh = true;
// command: scale 0.25
state.model_scale = 0.25;
// command: light FF8F4A 4000000
state.light_color = Some(Color::Srgba(Srgba::hex("FF8F4A").unwrap()));
state.light_brightness = 4000000.0;
@ -923,9 +907,6 @@ fn spawn_scenes(
// command: mirror yes
state.is_mirror = true;
// command: scale 10.0
state.model_scale = 10.0;
ew_spawn.send(SpawnEvent(state));
}
"greenhouse" => {
@ -950,9 +931,6 @@ fn spawn_scenes(
// command: angularmomentum 0 0 0
state.angular_momentum = DVec3::ZERO;
// command: scale 10.0
state.model_scale = 10.0;
ew_spawn.send(SpawnEvent(state));
}
_ => {

View file

@ -1,32 +1,32 @@
// THIS FILE IS AUTOGENERATED BY build.rs BASED ON DATA IN src/blender/scene_*.blend FILES!
// DO NOT MODIFY MANUALLY, CHANGES WILL BE OVERWRITTEN!
[
("test", "cruiser", [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]),
("workshop", "frameflat", [0.0, 0.0, -21.541874], [0.0, 0.0, 0.0]),
("workshop", "fueltank", [21.074543, -2.4312592, -4.7432747], [1.2519244, -0.0, -0.6819759]),
("workshop", "lightorb", [-15.720036, -32.41476, 4.1765304], [0.0, 0.0, 0.0]),
("workshop", "lightorb", [11.5042095, -21.65356, -4.566242], [0.0, 0.0, 0.0]),
("workshop", "shippingcontainer", [-0.52376616, 12.351211, -2.6598575], [-0.11791781, -0.02345992, 1.5838965]),
("workshop", "shippingcontainer", [-13.479424, 10.191104, -8.136984], [-0.05393797, -0.013098141, 1.7229813]),
("workshop", "shippingcontainer", [12.42811, 14.157182, -4.2369785], [-0.02553346, 0.042504273, 1.5108364]),
("greenhouse", "fueltank", [74.5485, 54.473938, 23.183126], [1.1660392, -0.0, -0.48993048]),
("greenhouse", "greenhouse", [56.82031, 0.0, 0.0], [0.0, -1.5707964, 0.0]),
("greenhouse", "mirror", [0.0, -17.0, -10.0], [-0.07591219, 0.0049197352, 1.7143301]),
("greenhouse", "mirror", [0.0, 17.0, -10.0], [-0.07587019, -0.0054108524, 1.4372792]),
("greenhouse", "mirror", [0.0, -17.0, 10.0], [0.08589277, -0.0056050196, 1.7142922]),
("greenhouse", "mirror", [0.0, 0.0, 20.0], [0.15707964, 0.0, 1.5707964]),
("greenhouse", "mirror", [0.0, 0.0, -20.0], [-0.15707964, -0.0, 1.5707964]),
("greenhouse", "mirror", [3.0, 34.0, 0.0], [-9.270864e-18, 6.3488335e-17, 1.2807964]),
("greenhouse", "mirror", [3.0, -34.0, 0.0], [0.0, 0.0, 1.8607775]),
("greenhouse", "mirror", [3.0, -34.0, 20.0], [0.16684353, -0.02862187, 1.8691753]),
("greenhouse", "mirror", [3.0, 34.0, 20.0], [0.14792228, 0.021559132, 1.2818513]),
("greenhouse", "mirror", [3.0, -34.0, -20.0], [-0.1775151, 0.02585048, 1.859278]),
("greenhouse", "mirror", [3.0, 34.0, -20.0], [-0.1592269, -0.013994377, 1.3089968]),
("greenhouse", "mirror", [3.0, -17.0, -30.0], [-0.25917134, 0.018069137, 1.7092348]),
("greenhouse", "mirror", [3.0, -17.0, 30.0], [0.22926316, -0.01600367, 1.7095735]),
("greenhouse", "mirror", [3.0, 17.0, 30.0], [0.22926316, 0.016003652, 1.4320191]),
("greenhouse", "mirror", [3.0, 17.0, -30.0], [-0.25917134, -0.018069115, 1.4323579]),
("greenhouse", "mirror", [3.0, 0.0, -40.0], [-0.33143952, -7.651644e-10, 1.5707964]),
("greenhouse", "mirror", [3.0, 0.0, 40.0], [0.34906584, -3.5681582e-9, 1.5707964]),
("greenhouse", "mirrorrotating", [0.0, 17.0, 10.0], [0.0073764813, -0.009006099, 1.2773504]),
("test", "cruiser", [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [5.0, 5.0, 5.0]),
("workshop", "frameflat", [0.0, 0.0, -21.541874], [0.0, 0.0, 0.0], [30.0, 30.0, 30.0]),
("workshop", "fueltank", [21.074543, -2.4312592, -4.7432747], [1.2519244, -0.0, -0.6819759], [8.0, 8.0, 8.0]),
("workshop", "lightorb", [-15.720036, -32.41476, 4.1765304], [0.0, 0.0, 0.0], [1.0, 1.0, 1.0]),
("workshop", "lightorb", [11.5042095, -21.65356, -4.566242], [0.0, 0.0, 0.0], [1.0, 1.0, 1.0]),
("workshop", "shippingcontainer", [-0.52376616, 12.351211, -2.6598575], [-0.11791781, -0.02345992, 1.5838965], [8.0, 8.0, 8.0]),
("workshop", "shippingcontainer", [-13.479424, 10.191104, -8.136984], [-0.05393797, -0.013098141, 1.7229813], [8.0, 8.0, 8.0]),
("workshop", "shippingcontainer", [12.42811, 14.157182, -4.2369785], [-0.02553346, 0.042504273, 1.5108364], [8.0, 8.0, 8.0]),
("greenhouse", "fueltank", [74.5485, 54.473938, 23.183126], [1.1660392, -0.0, -0.48993048], [8.0, 8.0, 8.0]),
("greenhouse", "greenhouse", [56.82031, 0.0, 0.0], [0.0, -1.5707964, 0.0], [10.0, 10.0, 10.0]),
("greenhouse", "mirror", [0.0, -17.0, -10.0], [-0.07591219, 0.0049197352, 1.7143301], [10.0, 10.0, 10.0]),
("greenhouse", "mirror", [0.0, 17.0, -10.0], [-0.07587019, -0.0054108524, 1.4372792], [10.0, 10.0, 10.0]),
("greenhouse", "mirror", [0.0, -17.0, 10.0], [0.08589277, -0.0056050196, 1.7142922], [10.0, 10.0, 10.0]),
("greenhouse", "mirror", [0.0, 0.0, 20.0], [0.15707964, 0.0, 1.5707964], [10.0, 9.999999, 9.999999]),
("greenhouse", "mirror", [0.0, 0.0, -20.0], [-0.15707964, -0.0, 1.5707964], [10.0, 9.999999, 9.999999]),
("greenhouse", "mirror", [3.0, 34.0, 0.0], [-9.270864e-18, 6.3488335e-17, 1.2807964], [10.0, 10.0, 10.0]),
("greenhouse", "mirror", [3.0, -34.0, 0.0], [0.0, 0.0, 1.8607775], [10.0, 10.0, 10.0]),
("greenhouse", "mirror", [3.0, -34.0, 20.0], [0.16684353, -0.02862187, 1.8691753], [10.0, 10.0, 10.0]),
("greenhouse", "mirror", [3.0, 34.0, 20.0], [0.14792228, 0.021559132, 1.2818513], [10.0, 10.0, 10.0]),
("greenhouse", "mirror", [3.0, -34.0, -20.0], [-0.1775151, 0.02585048, 1.859278], [10.0, 10.0, 10.0]),
("greenhouse", "mirror", [3.0, 34.0, -20.0], [-0.1592269, -0.013994377, 1.3089968], [10.0, 10.0, 10.0]),
("greenhouse", "mirror", [3.0, -17.0, -30.0], [-0.25917134, 0.018069137, 1.7092348], [10.0, 10.0, 10.0]),
("greenhouse", "mirror", [3.0, -17.0, 30.0], [0.22926316, -0.01600367, 1.7095735], [10.0, 10.0, 10.0]),
("greenhouse", "mirror", [3.0, 17.0, 30.0], [0.22926316, 0.016003652, 1.4320191], [10.0, 10.0, 10.0]),
("greenhouse", "mirror", [3.0, 17.0, -30.0], [-0.25917134, -0.018069115, 1.4323579], [10.0, 10.0, 10.0]),
("greenhouse", "mirror", [3.0, 0.0, -40.0], [-0.33143952, -7.651644e-10, 1.5707964], [10.0, 10.0, 10.0]),
("greenhouse", "mirror", [3.0, 0.0, 40.0], [0.34906584, -3.5681582e-9, 1.5707964], [10.0, 10.0, 10.0]),
("greenhouse", "mirrorrotating", [0.0, 17.0, 10.0], [0.0073764813, -0.009006099, 1.2773504], [10.0, 10.0, 10.0]),
]