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",
|
"byteorder-lite",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
"png",
|
"png",
|
||||||
|
"zune-core",
|
||||||
|
"zune-jpeg",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -7702,3 +7704,18 @@ dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
"pkg-config",
|
"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]
|
[dependencies.bevy]
|
||||||
version = "*"
|
version = "*"
|
||||||
features = ["dynamic_linking"]
|
features = ["dynamic_linking", "bevy_gltf", "bevy_image", "jpeg"]
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
opt-level = 1
|
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_gizmo_config(DefaultGizmoConfigGroup, GizmoConfig::default())
|
||||||
.insert_resource(DebugCamOffset::default())
|
.insert_resource(DebugCamOffset::default())
|
||||||
.insert_resource(WireframeConfig {
|
.insert_resource(WireframeConfig {
|
||||||
global: true,
|
global: false,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.insert_resource(HomeCartesian::default())
|
.insert_resource(HomeCartesian::default())
|
||||||
|
@ -85,28 +85,24 @@ fn polar2cart(lat: f32, long: f32, radius: f32) -> Vec3 {
|
||||||
Vec3::new(x, y, z)
|
Vec3::new(x, y, z)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn spawn_earth(
|
fn spawn_earth(mut commands: Commands, assets: Res<AssetServer>) {
|
||||||
mut commands: Commands,
|
use std::f32::consts::PI;
|
||||||
mut meshes: ResMut<Assets<Mesh>>,
|
let mut xform = Transform::from_rotation(Quat::from_rotation_z(180.0f32.to_radians()));
|
||||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
xform.rotate_y(PI);
|
||||||
) {
|
|
||||||
let spatial_bundle = (
|
let spatial_bundle = (xform, Visibility::default());
|
||||||
Transform::from_rotation(Quat::from_rotation_x(90.0f32.to_radians())),
|
|
||||||
Visibility::default(),
|
let earth = assets.load("earth.gltf#Scene0");
|
||||||
);
|
|
||||||
let mat = materials.add(StandardMaterial::from_color(Color::linear_rgba(
|
commands
|
||||||
0., 0., 0., 0.,
|
.spawn((
|
||||||
)));
|
spatial_bundle,
|
||||||
commands.spawn((
|
AmbientLight {
|
||||||
spatial_bundle,
|
brightness: 20_000.0,
|
||||||
Mesh3d(meshes.add(Sphere::new(100.0).mesh().uv(32, 18))),
|
..Default::default()
|
||||||
MeshMaterial3d(mat),
|
},
|
||||||
WireframeColor { color: BLUE.into() },
|
))
|
||||||
AmbientLight {
|
.with_child(SceneRoot(earth));
|
||||||
brightness: 2_000.0,
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn close_on_esc(
|
fn close_on_esc(
|
||||||
|
@ -165,6 +161,7 @@ fn update_camera_offset(
|
||||||
offset.lat += 0.5;
|
offset.lat += 0.5;
|
||||||
} else {
|
} else {
|
||||||
offset.dist -= 10.0;
|
offset.dist -= 10.0;
|
||||||
|
offset.dist = offset.dist.max(RADIUS + 2.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
KeyCode::ArrowDown => {
|
KeyCode::ArrowDown => {
|
||||||
|
|
Loading…
Reference in a new issue