Compare commits

...

2 commits

Author SHA1 Message Date
yuni 26e5d3456c scenes.in: extract scale from blender scene files 2024-11-17 17:29:08 +01:00
yuni 080e14c7ee add texture to The Whale 2024-11-17 16:58:10 +01:00
8 changed files with 749 additions and 55 deletions

BIN
assets/models/whale.bin Normal file

Binary file not shown.

Binary file not shown.

709
assets/models/whale.gltf Normal file
View file

@ -0,0 +1,709 @@
{
"asset":{
"generator":"Khronos glTF Blender I/O v4.2.70",
"version":"2.0"
},
"extensionsUsed":[
"KHR_materials_emissive_strength"
],
"scene":0,
"scenes":[
{
"name":"Scene",
"nodes":[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12
]
}
],
"nodes":[
{
"mesh":0,
"name":"Collider",
"rotation":[
0.70710688829422,
0,
0,
0.7071066498756409
],
"scale":[
0.12038252502679825,
0.06697691231966019,
0.12038250267505646
],
"translation":[
0,
0,
-0.8517786860466003
]
},
{
"mesh":1,
"name":"SphereShadeAsteroid"
},
{
"mesh":2,
"name":"Cylinder",
"rotation":[
0.70710688829422,
0,
0,
0.7071066498756409
],
"scale":[
0.12038252502679825,
0.06697691231966019,
0.12038250267505646
],
"translation":[
0,
0,
-0.8517786860466003
]
},
{
"mesh":2,
"name":"Cylinder.001",
"rotation":[
0.70710688829422,
0,
0,
0.7071066498756409
],
"scale":[
0.12038252502679825,
0.06697691231966019,
0.12038250267505646
],
"translation":[
0,
0.25,
-0.8517786860466003
]
},
{
"mesh":2,
"name":"Cylinder.002",
"rotation":[
0.70710688829422,
0,
0,
0.7071066498756409
],
"scale":[
0.12038252502679825,
0.06697691231966019,
0.12038250267505646
],
"translation":[
0,
-0.25,
-0.8517786860466003
]
},
{
"mesh":2,
"name":"Cylinder.003",
"rotation":[
0.70710688829422,
0,
0,
0.7071066498756409
],
"scale":[
0.12038252502679825,
0.06697691231966019,
0.12038250267505646
],
"translation":[
-0.22000011801719666,
0.12999999523162842,
-0.8517786860466003
]
},
{
"mesh":2,
"name":"Cylinder.004",
"rotation":[
0.70710688829422,
0,
0,
0.7071066498756409
],
"scale":[
0.12038252502679825,
0.06697696447372437,
0.12038250267505646
],
"translation":[
-0.22000011801719666,
-0.12999999523162842,
-0.8517786860466003
]
},
{
"mesh":2,
"name":"Cylinder.005",
"rotation":[
0.70710688829422,
0,
0,
0.7071066498756409
],
"scale":[
0.12038252502679825,
0.06697691231966019,
0.12038250267505646
],
"translation":[
0.21999987959861755,
0.12999999523162842,
-0.8517786860466003
]
},
{
"mesh":2,
"name":"Cylinder.006",
"rotation":[
0.70710688829422,
0,
0,
0.7071066498756409
],
"scale":[
0.12038252502679825,
0.06697691231966019,
0.12038250267505646
],
"translation":[
0.21999987959861755,
-0.12999999523162842,
-0.8517786860466003
]
},
{
"mesh":2,
"name":"Cylinder.007",
"rotation":[
0.40557974576950073,
0.5792279243469238,
-0.5792279839515686,
0.40557974576950073
],
"scale":[
0.12038256227970123,
0.044512517750263214,
0.12038254737854004
],
"translation":[
-0.9712018370628357,
0,
0.062312301248311996
]
},
{
"mesh":2,
"name":"Cylinder.008",
"rotation":[
0.4055797755718231,
-0.5792279839515686,
0.5792280435562134,
0.40557974576950073
],
"scale":[
0.12038251012563705,
0.04451249539852142,
0.12038248777389526
],
"translation":[
0.9712016582489014,
0,
0.06231236085295677
]
},
{
"mesh":2,
"name":"Cylinder.009",
"rotation":[
0,
-0.17364823818206787,
0.9848078489303589,
7.590405637358799e-09
],
"scale":[
0.12038246542215347,
0.04451249539852142,
0.12038251012563705
],
"translation":[
0,
0.9712017178535461,
0.06231239065527916
]
},
{
"mesh":2,
"name":"Cylinder.010",
"rotation":[
0,
-0.9848077893257141,
0.1736481636762619,
4.304728307147343e-08
],
"scale":[
0.1203826293349266,
0.04451251029968262,
0.12038261443376541
],
"translation":[
0,
-0.9712018370628357,
0.062312301248311996
]
}
],
"materials":[
{
"doubleSided":true,
"name":"Asteroid",
"pbrMetallicRoughness":{
"baseColorTexture":{
"index":0
},
"metallicFactor":0.871999979019165,
"roughnessFactor":0.8320000171661377
}
},
{
"doubleSided":true,
"name":"Inside",
"pbrMetallicRoughness":{
"baseColorTexture":{
"index":1
},
"metallicFactor":0.800000011920929,
"roughnessFactor":0.800000011920929
}
},
{
"doubleSided":true,
"emissiveFactor":[
0.007861939258873463,
0.6351664066314697,
1
],
"extensions":{
"KHR_materials_emissive_strength":{
"emissiveStrength":32
}
},
"name":"Thruster",
"pbrMetallicRoughness":{
"baseColorFactor":[
0.006291341036558151,
0.5082777142524719,
0.8002276420593262,
1
],
"metallicFactor":0,
"roughnessFactor":0.5
}
},
{
"doubleSided":true,
"name":"Engine",
"pbrMetallicRoughness":{
"baseColorFactor":[
0.01483176089823246,
0.01483176089823246,
0.01483176089823246,
1
],
"metallicFactor":0.46000000834465027,
"roughnessFactor":0.875
}
}
],
"meshes":[
{
"name":"Collider",
"primitives":[
{
"attributes":{
"POSITION":0,
"NORMAL":1
},
"indices":2
}
]
},
{
"name":"Sphere",
"primitives":[
{
"attributes":{
"POSITION":3,
"NORMAL":4,
"TEXCOORD_0":5
},
"indices":6,
"material":0
},
{
"attributes":{
"POSITION":7,
"NORMAL":8,
"TEXCOORD_0":9
},
"indices":10,
"material":1
}
]
},
{
"name":"Cylinder",
"primitives":[
{
"attributes":{
"POSITION":11,
"NORMAL":12,
"TEXCOORD_0":13
},
"indices":14,
"material":2
},
{
"attributes":{
"POSITION":15,
"NORMAL":16,
"TEXCOORD_0":17
},
"indices":18,
"material":3
}
]
}
],
"textures":[
{
"sampler":0,
"source":0
},
{
"sampler":0,
"source":0
}
],
"images":[
{
"mimeType":"image/jpeg",
"name":"mercury",
"uri":"textures/mercury.jpg"
}
],
"accessors":[
{
"bufferView":0,
"componentType":5126,
"count":3190,
"max":[
8.269089698791504,
26.76024627685547,
8.217630386352539
],
"min":[
-8.439277648925781,
-1.0000009536743164,
-8.282991409301758
],
"type":"VEC3"
},
{
"bufferView":1,
"componentType":5126,
"count":3190,
"type":"VEC3"
},
{
"bufferView":2,
"componentType":5123,
"count":4182,
"type":"SCALAR"
},
{
"bufferView":3,
"componentType":5126,
"count":4943,
"max":[
1.0023242235183716,
0.9883838295936584,
0.9643056988716125
],
"min":[
-1.020846962928772,
-0.9929111003875732,
-0.8851138949394226
],
"type":"VEC3"
},
{
"bufferView":4,
"componentType":5126,
"count":4943,
"type":"VEC3"
},
{
"bufferView":5,
"componentType":5126,
"count":4943,
"type":"VEC2"
},
{
"bufferView":6,
"componentType":5123,
"count":29046,
"type":"SCALAR"
},
{
"bufferView":7,
"componentType":5126,
"count":2667,
"max":[
0.7215039730072021,
0.5917508602142334,
0.8757549524307251
],
"min":[
-0.698997974395752,
-0.8130655884742737,
-0.7327467203140259
],
"type":"VEC3"
},
{
"bufferView":8,
"componentType":5126,
"count":2667,
"type":"VEC3"
},
{
"bufferView":9,
"componentType":5126,
"count":2667,
"type":"VEC2"
},
{
"bufferView":10,
"componentType":5123,
"count":15498,
"type":"SCALAR"
},
{
"bufferView":11,
"componentType":5126,
"count":32,
"max":[
0.16796797513961792,
-1,
0.16796797513961792
],
"min":[
-0.16796797513961792,
-1,
-0.16796797513961792
],
"type":"VEC3"
},
{
"bufferView":12,
"componentType":5126,
"count":32,
"type":"VEC3"
},
{
"bufferView":13,
"componentType":5126,
"count":32,
"type":"VEC2"
},
{
"bufferView":14,
"componentType":5123,
"count":90,
"type":"SCALAR"
},
{
"bufferView":15,
"componentType":5126,
"count":288,
"max":[
1,
1,
1
],
"min":[
-1,
-1,
-1
],
"type":"VEC3"
},
{
"bufferView":16,
"componentType":5126,
"count":288,
"type":"VEC3"
},
{
"bufferView":17,
"componentType":5126,
"count":288,
"type":"VEC2"
},
{
"bufferView":18,
"componentType":5123,
"count":666,
"type":"SCALAR"
}
],
"bufferViews":[
{
"buffer":0,
"byteLength":38280,
"byteOffset":0,
"target":34962
},
{
"buffer":0,
"byteLength":38280,
"byteOffset":38280,
"target":34962
},
{
"buffer":0,
"byteLength":8364,
"byteOffset":76560,
"target":34963
},
{
"buffer":0,
"byteLength":59316,
"byteOffset":84924,
"target":34962
},
{
"buffer":0,
"byteLength":59316,
"byteOffset":144240,
"target":34962
},
{
"buffer":0,
"byteLength":39544,
"byteOffset":203556,
"target":34962
},
{
"buffer":0,
"byteLength":58092,
"byteOffset":243100,
"target":34963
},
{
"buffer":0,
"byteLength":32004,
"byteOffset":301192,
"target":34962
},
{
"buffer":0,
"byteLength":32004,
"byteOffset":333196,
"target":34962
},
{
"buffer":0,
"byteLength":21336,
"byteOffset":365200,
"target":34962
},
{
"buffer":0,
"byteLength":30996,
"byteOffset":386536,
"target":34963
},
{
"buffer":0,
"byteLength":384,
"byteOffset":417532,
"target":34962
},
{
"buffer":0,
"byteLength":384,
"byteOffset":417916,
"target":34962
},
{
"buffer":0,
"byteLength":256,
"byteOffset":418300,
"target":34962
},
{
"buffer":0,
"byteLength":180,
"byteOffset":418556,
"target":34963
},
{
"buffer":0,
"byteLength":3456,
"byteOffset":418736,
"target":34962
},
{
"buffer":0,
"byteLength":3456,
"byteOffset":422192,
"target":34962
},
{
"buffer":0,
"byteLength":2304,
"byteOffset":425648,
"target":34962
},
{
"buffer":0,
"byteLength":1332,
"byteOffset":427952,
"target":34963
}
],
"samplers":[
{
"magFilter":9729,
"minFilter":9987
}
],
"buffers":[
{
"byteLength":429284,
"uri":"whale.bin"
}
]
}

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(())

BIN
src/blender/whale.blend Normal file

Binary file not shown.

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]),
]

View file

@ -65,7 +65,7 @@ pub fn asset_name_to_path(name: &str) -> &'static str {
"orbitring" => "models/orbitring.glb#Scene0",
"clippy" => "models/clippy/clippy.glb#Scene0",
"clippy_ar" => "models/clippy/ar_happy.glb#Scene0",
"whale" => "models/whale.glb#Scene0",
"whale" => "models/whale.gltf#Scene0",
"marker_satellites" => "models/marker_satellites.glb#Scene0",
"marker_planets" => "models/marker_planets.glb#Scene0",
"point_of_interest" => "models/point_of_interest.glb#Scene0",