spawn a textured earth
This commit is contained in:
parent
188aba8bcf
commit
34d2cabf67
6 changed files with 181 additions and 24 deletions
17
Cargo.lock
generated
17
Cargo.lock
generated
|
@ -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",
|
||||
]
|
||||
|
|
|
@ -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
|
||||
|
|
BIN
assets/2k_earth_daymap.jpeg
Normal file
BIN
assets/2k_earth_daymap.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 452 KiB |
BIN
assets/earth.bin
Normal file
BIN
assets/earth.bin
Normal file
Binary file not shown.
143
assets/earth.gltf
Normal file
143
assets/earth.gltf
Normal file
|
@ -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"
|
||||
}
|
||||
]
|
||||
}
|
43
src/main.rs
43
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<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
) {
|
||||
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<AssetServer>) {
|
||||
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 => {
|
||||
|
|
Loading…
Reference in a new issue