WIP scene definitions from blender files

This commit is contained in:
yuni 2024-06-11 04:40:57 +02:00
parent 28cb1c09fd
commit 0047c4eda4
3 changed files with 51 additions and 0 deletions

17
Cargo.lock generated
View file

@ -1097,6 +1097,16 @@ dependencies = [
"constant_time_eq", "constant_time_eq",
] ]
[[package]]
name = "blend"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56036f5e6c7ce6edb901e7a75ec34d6da2472ad3a2cbcd00df60a518b071a5b2"
dependencies = [
"linked-hash-map",
"nom",
]
[[package]] [[package]]
name = "block" name = "block"
version = "0.1.6" version = "0.1.6"
@ -2296,6 +2306,12 @@ dependencies = [
"redox_syscall 0.4.1", "redox_syscall 0.4.1",
] ]
[[package]]
name = "linked-hash-map"
version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f"
[[package]] [[package]]
name = "linux-raw-sys" name = "linux-raw-sys"
version = "0.4.13" version = "0.4.13"
@ -2772,6 +2788,7 @@ dependencies = [
"bevy", "bevy",
"bevy_embedded_assets", "bevy_embedded_assets",
"bevy_xpbd_3d", "bevy_xpbd_3d",
"blend",
"embed-resource", "embed-resource",
"fastrand", "fastrand",
"regex", "regex",

View file

@ -64,6 +64,7 @@ features = ["3d", "f64", "parry-f64", "parallel", "async-collider"]
# a [target[...]build-dependencies] block because in case of cross-compiling, the # a [target[...]build-dependencies] block because in case of cross-compiling, the
# build.rs will be compiled for a different, non-windows target than the main executable. # build.rs will be compiled for a different, non-windows target than the main executable.
embed-resource = "1.6.3" # embedding of .exe metadata embed-resource = "1.6.3" # embedding of .exe metadata
blend = "0.8.0"
[features] [features]
default = ["x11", "embed_assets"] default = ["x11", "embed_assets"]

View file

@ -8,10 +8,43 @@
// + + + ███ // + + + ███
// + ▀████████████████████████████████████████████████████▀ // + ▀████████████████████████████████████████████████████▀
use blend::Blend;
use std::fs::File;
use std::io::Write;
fn main() { fn main() {
let target = std::env::var("TARGET").unwrap(); let target = std::env::var("TARGET").unwrap();
if target.contains("windows") { if target.contains("windows") {
println!("cargo:warning=Embedding Windows Icon"); println!("cargo:warning=Embedding Windows Icon");
embed_resource::compile("build/windows/icon.rc"); embed_resource::compile("build/windows/icon.rc");
} }
let file = File::create("src/data/scenes.in");
if let Ok(mut file) = file {
generate_scenes(&mut file, "src/blender/suit_v2.blend");
generate_scenes(&mut file, "src/blender/cruiser.blend");
}
}
fn generate_scenes(stream: &mut File, source_blend_file: &str) {
let blend = Blend::from_path(source_blend_file).expect("error loading blend file");
for obj in blend.root_instances() {
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]
};
let name = obj.get("id").get_string("name");
let result = write!(stream, "(\"{}\", {:?}, {:?}),\n", name, loc, rot);
if result.is_err() {
println!("{:?}", result);
break;
}
}
} }