diff --git a/Cargo.lock b/Cargo.lock index 8fbcd21..34effb3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3393,6 +3393,8 @@ dependencies = [ "byteorder-lite", "num-traits", "png", + "zune-core", + "zune-jpeg", ] [[package]] @@ -7702,3 +7704,18 @@ dependencies = [ "cc", "pkg-config", ] + +[[package]] +name = "zune-core" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f423a2c17029964870cfaabb1f13dfab7d092a62a29a89264f4d36990ca414a" + +[[package]] +name = "zune-jpeg" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99a5bab8d7dedf81405c4bb1f2b83ea057643d9cb28778cea9eecddeedd2e028" +dependencies = [ + "zune-core", +] diff --git a/Cargo.toml b/Cargo.toml index 11df28b..a2f60e9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ nyx-space = "2.1.0" [dependencies.bevy] version = "*" -features = ["dynamic_linking"] +features = ["dynamic_linking", "bevy_gltf", "bevy_image", "jpeg"] [profile.dev] opt-level = 1 diff --git a/assets/2k_earth_daymap.jpeg b/assets/2k_earth_daymap.jpeg new file mode 100644 index 0000000..6cdcffe Binary files /dev/null and b/assets/2k_earth_daymap.jpeg differ diff --git a/assets/earth.bin b/assets/earth.bin new file mode 100644 index 0000000..885ebff Binary files /dev/null and b/assets/earth.bin differ diff --git a/assets/earth.gltf b/assets/earth.gltf new file mode 100644 index 0000000..abc77c5 --- /dev/null +++ b/assets/earth.gltf @@ -0,0 +1,143 @@ +{ + "asset":{ + "generator":"Khronos glTF Blender I/O v4.0.44", + "version":"2.0" + }, + "scene":0, + "scenes":[ + { + "name":"Scene", + "nodes":[ + 0 + ] + } + ], + "nodes":[ + { + "mesh":0, + "name":"Sphere", + "rotation":[ + 0, + 0, + 0, + 0 + ] + } + ], + "materials":[ + { + "doubleSided":true, + "name":"Material", + "pbrMetallicRoughness":{ + "baseColorTexture":{ + "index":0 + }, + "metallicFactor":0, + "roughnessFactor":0.5 + } + } + ], + "meshes":[ + { + "name":"Sphere", + "primitives":[ + { + "attributes":{ + "POSITION":0, + "NORMAL":1, + "TEXCOORD_0":2 + }, + "indices":3, + "material":0 + } + ] + } + ], + "textures":[ + { + "sampler":0, + "source":0 + } + ], + "images":[ + { + "mimeType":"image/jpeg", + "name":"2k_earth_daymap", + "uri":"2k_earth_daymap.jpeg" + } + ], + "accessors":[ + { + "bufferView":0, + "componentType":5126, + "count":8064, + "max":[ + 100, + 100, + 100 + ], + "min":[ + -100, + -100, + -100 + ], + "type":"VEC3" + }, + { + "bufferView":1, + "componentType":5126, + "count":8064, + "type":"VEC3" + }, + { + "bufferView":2, + "componentType":5126, + "count":8064, + "type":"VEC2" + }, + { + "bufferView":3, + "componentType":5123, + "count":11904, + "type":"SCALAR" + } + ], + "bufferViews":[ + { + "buffer":0, + "byteLength":96768, + "byteOffset":0, + "target":34962 + }, + { + "buffer":0, + "byteLength":96768, + "byteOffset":96768, + "target":34962 + }, + { + "buffer":0, + "byteLength":64512, + "byteOffset":193536, + "target":34962 + }, + { + "buffer":0, + "byteLength":23808, + "byteOffset":258048, + "target":34963 + } + ], + "samplers":[ + { + "magFilter":9729, + "minFilter":9987 + } + ], + "buffers":[ + { + "byteLength":281856, + "uri":"earth.bin" + } + ] +} diff --git a/src/main.rs b/src/main.rs index 55c3c74..4ea2579 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,7 +29,7 @@ fn main() { .insert_gizmo_config(DefaultGizmoConfigGroup, GizmoConfig::default()) .insert_resource(DebugCamOffset::default()) .insert_resource(WireframeConfig { - global: true, + global: false, ..Default::default() }) .insert_resource(HomeCartesian::default()) @@ -85,28 +85,24 @@ fn polar2cart(lat: f32, long: f32, radius: f32) -> Vec3 { Vec3::new(x, y, z) } -fn spawn_earth( - mut commands: Commands, - mut meshes: ResMut>, - mut materials: ResMut>, -) { - let spatial_bundle = ( - Transform::from_rotation(Quat::from_rotation_x(90.0f32.to_radians())), - Visibility::default(), - ); - let mat = materials.add(StandardMaterial::from_color(Color::linear_rgba( - 0., 0., 0., 0., - ))); - commands.spawn(( - spatial_bundle, - Mesh3d(meshes.add(Sphere::new(100.0).mesh().uv(32, 18))), - MeshMaterial3d(mat), - WireframeColor { color: BLUE.into() }, - AmbientLight { - brightness: 2_000.0, - ..Default::default() - }, - )); +fn spawn_earth(mut commands: Commands, assets: Res) { + use std::f32::consts::PI; + let mut xform = Transform::from_rotation(Quat::from_rotation_z(180.0f32.to_radians())); + xform.rotate_y(PI); + + let spatial_bundle = (xform, Visibility::default()); + + let earth = assets.load("earth.gltf#Scene0"); + + commands + .spawn(( + spatial_bundle, + AmbientLight { + brightness: 20_000.0, + ..Default::default() + }, + )) + .with_child(SceneRoot(earth)); } fn close_on_esc( @@ -165,6 +161,7 @@ fn update_camera_offset( offset.lat += 0.5; } else { offset.dist -= 10.0; + offset.dist = offset.dist.max(RADIUS + 2.0); } } KeyCode::ArrowDown => {