flesh out scene loader
This commit is contained in:
parent
0047c4eda4
commit
2c1dacbf03
33
build.rs
33
build.rs
|
@ -12,7 +12,7 @@ use blend::Blend;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
fn main() {
|
fn main() -> std::io::Result<()> {
|
||||||
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");
|
||||||
|
@ -21,14 +21,16 @@ fn main() {
|
||||||
|
|
||||||
let file = File::create("src/data/scenes.in");
|
let file = File::create("src/data/scenes.in");
|
||||||
if let Ok(mut file) = file {
|
if let Ok(mut file) = file {
|
||||||
generate_scenes(&mut file, "src/blender/suit_v2.blend");
|
write!(&file, "[\n")?;
|
||||||
generate_scenes(&mut file, "src/blender/cruiser.blend");
|
extract_scene(&mut file, "test", "src/blender/scene_test.blend")?;
|
||||||
|
write!(&file, "]\n")?;
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_scenes(stream: &mut File, source_blend_file: &str) {
|
fn extract_scene(file: &mut File, scene_name: &str, blend_file: &str) -> std::io::Result<()> {
|
||||||
let blend = Blend::from_path(source_blend_file).expect("error loading blend file");
|
let blend = Blend::from_path(blend_file).expect("error loading blend file");
|
||||||
for obj in blend.root_instances() {
|
for obj in blend.instances_with_code(*b"OB") {
|
||||||
let loc: Vec<f32> = if obj.is_valid("loc") {
|
let loc: Vec<f32> = if obj.is_valid("loc") {
|
||||||
obj.get_f32_vec("loc")
|
obj.get_f32_vec("loc")
|
||||||
} else {
|
} else {
|
||||||
|
@ -40,11 +42,20 @@ fn generate_scenes(stream: &mut File, source_blend_file: &str) {
|
||||||
vec![0.0, 0.0, 0.0]
|
vec![0.0, 0.0, 0.0]
|
||||||
};
|
};
|
||||||
let name = obj.get("id").get_string("name");
|
let name = obj.get("id").get_string("name");
|
||||||
|
if let Some(name) = get_scene_object_name(name.as_str()) {
|
||||||
let result = write!(stream, "(\"{}\", {:?}, {:?}),\n", name, loc, rot);
|
write!(file, "({scene_name:?}, {name:?}, {loc:?}, {rot:?}),\n")?;
|
||||||
if result.is_err() {
|
|
||||||
println!("{:?}", result);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
BIN
src/blender/scene_test.blend
Normal file
BIN
src/blender/scene_test.blend
Normal file
Binary file not shown.
6
src/data/scenes.in
Normal file
6
src/data/scenes.in
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
[
|
||||||
|
("test", "cruiser", [0.0, 10.971298, 1.222765], [-0.27833763, 0.74558806, 0.31813696]),
|
||||||
|
("test", "cruiser", [-0.46667862, -1.2666901, -7.938822], [1.7932074, 0.10752687, 0.15762906]),
|
||||||
|
("test", "cruiser", [-7.409776, -1.4187636, 11.451159], [-0.27833763, 0.74558806, 0.31813696]),
|
||||||
|
("test", "cruiser", [6.8125467, -11.003204, 0.5323599], [-0.019556522, -1.0606266, -3.0019674]),
|
||||||
|
]
|
Loading…
Reference in a new issue