2024-04-21 16:23:40 +00:00
|
|
|
// ▄████████▄ + ███ + ▄█████████ ███ +
|
|
|
|
// ███▀ ▀███ + + ███ ███▀ + ███ + +
|
|
|
|
// ███ + ███ ███ ███ █████████ ███ ███ ███ ███
|
2024-04-21 17:34:00 +00:00
|
|
|
// ███ +███ ███ ███ ███ ███▐██████ ███ ███ ███
|
2024-04-21 16:23:40 +00:00
|
|
|
// ███ + ███ ███+ ███ +███ ███ + ███ ███ + ███
|
|
|
|
// ███▄ ▄███ ███▄ ███ ███ + ███ + ███ ███▄ ███
|
|
|
|
// ▀████████▀ + ▀███████ ███▄ ███▄ ▀████ ▀███████
|
|
|
|
// + + + ███
|
|
|
|
// + ▀████████████████████████████████████████████████████▀
|
|
|
|
|
2024-06-11 02:40:57 +00:00
|
|
|
use blend::Blend;
|
|
|
|
use std::fs::File;
|
|
|
|
use std::io::Write;
|
|
|
|
|
2024-06-11 03:04:55 +00:00
|
|
|
fn main() -> std::io::Result<()> {
|
2024-04-19 21:47:40 +00:00
|
|
|
let target = std::env::var("TARGET").unwrap();
|
|
|
|
if target.contains("windows") {
|
|
|
|
println!("cargo:warning=Embedding Windows Icon");
|
2024-05-12 21:15:17 +00:00
|
|
|
embed_resource::compile("build/windows/icon.rc");
|
2024-04-19 21:47:40 +00:00
|
|
|
}
|
2024-06-11 02:40:57 +00:00
|
|
|
|
|
|
|
let file = File::create("src/data/scenes.in");
|
|
|
|
if let Ok(mut file) = file {
|
2024-07-31 04:43:11 +00:00
|
|
|
write!(&file, "// THIS FILE IS AUTOGENERATED BY build.rs BASED ON DATA IN src/blender/scene_*.blend FILES!\n")?;
|
2024-09-13 21:40:03 +00:00
|
|
|
write!(
|
|
|
|
&file,
|
|
|
|
"// DO NOT MODIFY MANUALLY, CHANGES WILL BE OVERWRITTEN!\n"
|
|
|
|
)?;
|
2024-06-11 03:04:55 +00:00
|
|
|
write!(&file, "[\n")?;
|
|
|
|
extract_scene(&mut file, "test", "src/blender/scene_test.blend")?;
|
2024-07-31 02:49:11 +00:00
|
|
|
extract_scene(&mut file, "workshop", "src/blender/scene_workshop.blend")?;
|
2024-11-05 03:47:26 +00:00
|
|
|
extract_scene(
|
|
|
|
&mut file,
|
|
|
|
"greenhouse",
|
|
|
|
"src/blender/scene_greenhouse.blend",
|
|
|
|
)?;
|
2024-06-11 03:04:55 +00:00
|
|
|
write!(&file, "]\n")?;
|
2024-06-11 02:40:57 +00:00
|
|
|
}
|
2024-06-11 03:04:55 +00:00
|
|
|
Ok(())
|
2024-06-11 02:40:57 +00:00
|
|
|
}
|
|
|
|
|
2024-06-11 03:04:55 +00:00
|
|
|
fn extract_scene(file: &mut File, scene_name: &str, blend_file: &str) -> std::io::Result<()> {
|
2024-11-17 16:28:34 +00:00
|
|
|
// Info about .blender file format:
|
|
|
|
// https://www.janwalter.org/jekyll/blender/rust/blendinfo/2019/05/28/blend_info.html
|
2024-06-11 03:04:55 +00:00
|
|
|
let blend = Blend::from_path(blend_file).expect("error loading blend file");
|
|
|
|
for obj in blend.instances_with_code(*b"OB") {
|
2024-06-11 02:40:57 +00:00
|
|
|
let loc: Vec<f32> = if obj.is_valid("loc") {
|
|
|
|
obj.get_f32_vec("loc")
|
|
|
|
} else {
|
|
|
|
vec![0.0, 0.0, 0.0]
|
|
|
|
};
|
|
|
|
let rot: Vec<f32> = if obj.is_valid("rot") {
|
|
|
|
obj.get_f32_vec("rot")
|
|
|
|
} else {
|
|
|
|
vec![0.0, 0.0, 0.0]
|
|
|
|
};
|
2024-11-17 16:28:34 +00:00
|
|
|
let scale: Vec<f32> = if obj.is_valid("size") {
|
|
|
|
obj.get_f32_vec("size")
|
|
|
|
} else {
|
|
|
|
vec![1.0, 1.0, 1.0]
|
|
|
|
};
|
2024-06-11 02:40:57 +00:00
|
|
|
let name = obj.get("id").get_string("name");
|
2024-06-11 03:04:55 +00:00
|
|
|
if let Some(name) = get_scene_object_name(name.as_str()) {
|
2024-11-17 16:28:34 +00:00
|
|
|
write!(file, "({scene_name:?}, {name:?}, {loc:?}, {rot:?}, {scale:?}),\n")?;
|
2024-06-11 02:40:57 +00:00
|
|
|
}
|
|
|
|
}
|
2024-06-11 03:04:55 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_scene_object_name(full_id: &str) -> Option<&str> {
|
|
|
|
let prefix = "OBLOAD=";
|
|
|
|
if full_id.starts_with(prefix) {
|
|
|
|
let remainder: &str = &full_id[prefix.len()..];
|
|
|
|
let parts: Vec<&str> = remainder.split('.').collect();
|
|
|
|
let name = parts[0];
|
|
|
|
return Some(name);
|
|
|
|
}
|
|
|
|
return None;
|
2024-04-19 21:47:40 +00:00
|
|
|
}
|