From 0047c4eda45351d8ba838f86167b307f140d846c Mon Sep 17 00:00:00 2001 From: yuni Date: Tue, 11 Jun 2024 04:40:57 +0200 Subject: [PATCH] WIP scene definitions from blender files --- Cargo.lock | 17 +++++++++++++++++ Cargo.toml | 1 + build.rs | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 47b337f..8bf4cd9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1097,6 +1097,16 @@ dependencies = [ "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]] name = "block" version = "0.1.6" @@ -2296,6 +2306,12 @@ dependencies = [ "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]] name = "linux-raw-sys" version = "0.4.13" @@ -2772,6 +2788,7 @@ dependencies = [ "bevy", "bevy_embedded_assets", "bevy_xpbd_3d", + "blend", "embed-resource", "fastrand", "regex", diff --git a/Cargo.toml b/Cargo.toml index 97812d8..7bd5b6a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -64,6 +64,7 @@ features = ["3d", "f64", "parry-f64", "parallel", "async-collider"] # 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. embed-resource = "1.6.3" # embedding of .exe metadata +blend = "0.8.0" [features] default = ["x11", "embed_assets"] diff --git a/build.rs b/build.rs index b7d8d5f..d7071fd 100644 --- a/build.rs +++ b/build.rs @@ -8,10 +8,43 @@ // + + + ███ // + ▀████████████████████████████████████████████████████▀ +use blend::Blend; +use std::fs::File; +use std::io::Write; + fn main() { let target = std::env::var("TARGET").unwrap(); if target.contains("windows") { println!("cargo:warning=Embedding Windows Icon"); 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 = if obj.is_valid("loc") { + obj.get_f32_vec("loc") + } else { + vec![0.0, 0.0, 0.0] + }; + let rot: Vec = 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; + } + } }