2024-04-22 17:42:51 +00:00
|
|
|
// ▄████████▄ + ███ + ▄█████████ ███ +
|
|
|
|
// ███▀ ▀███ + + ███ ███▀ + ███ + +
|
|
|
|
// ███ + ███ ███ ███ █████████ ███ ███ ███ ███
|
|
|
|
// ███ +███ ███ ███ ███ ███▐██████ ███ ███ ███
|
|
|
|
// ███ + ███ ███+ ███ +███ ███ + ███ ███ + ███
|
|
|
|
// ███▄ ▄███ ███▄ ███ ███ + ███ + ███ ███▄ ███
|
|
|
|
// ▀████████▀ + ▀███████ ███▄ ███▄ ▀████ ▀███████
|
|
|
|
// + + + ███
|
|
|
|
// + ▀████████████████████████████████████████████████████▀
|
2024-04-23 15:33:36 +00:00
|
|
|
//
|
2024-05-10 08:25:03 +00:00
|
|
|
// This module manages asset loading.
|
2024-04-22 17:42:51 +00:00
|
|
|
|
2024-04-22 19:01:27 +00:00
|
|
|
use bevy::ecs::system::EntityCommands;
|
2024-05-10 08:27:52 +00:00
|
|
|
use bevy::pbr::{ExtendedMaterial, MaterialExtension, OpaqueRendererMethod};
|
2024-04-22 17:42:51 +00:00
|
|
|
use bevy::prelude::*;
|
2024-05-22 02:57:20 +00:00
|
|
|
use bevy::render::render_resource::{AsBindGroup, ShaderRef};
|
2024-04-22 19:01:27 +00:00
|
|
|
|
2024-05-10 08:27:52 +00:00
|
|
|
pub struct LoadPlugin;
|
|
|
|
impl Plugin for LoadPlugin {
|
|
|
|
fn build(&self, app: &mut App) {
|
|
|
|
app.add_plugins(MaterialPlugin::<JupitersRing>::default());
|
|
|
|
app.add_plugins(MaterialPlugin::<SkyBox>::default());
|
2024-05-22 02:57:20 +00:00
|
|
|
app.add_plugins(MaterialPlugin::<
|
|
|
|
ExtendedMaterial<StandardMaterial, AsteroidSurface>,
|
|
|
|
>::default());
|
2024-05-10 08:27:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-22 19:01:27 +00:00
|
|
|
pub fn asset_name_to_path(name: &str) -> &'static str {
|
|
|
|
match name {
|
2024-04-24 01:03:57 +00:00
|
|
|
"suitv2" => "models/suit_v2/suit_v2.glb#Scene0",
|
2024-04-24 01:03:18 +00:00
|
|
|
"suit_ar_chefhat" => "models/suit_v2/ar_chefhat.glb#Scene0",
|
2024-05-23 03:23:31 +00:00
|
|
|
"suit_ar_wings" => "models/suit_v2/ar_wings.glb#Scene0",
|
2024-06-14 13:51:31 +00:00
|
|
|
"sus" => "models/sus.glb#Scene0",
|
2024-04-22 19:01:27 +00:00
|
|
|
"asteroid1" => "models/asteroid.glb#Scene0",
|
|
|
|
"asteroid2" => "models/asteroid2.glb#Scene0",
|
|
|
|
"asteroid_lum" => "models/asteroid_lum.glb#Scene0",
|
2024-05-01 01:31:30 +00:00
|
|
|
"hollow_asteroid" => "models/hollow_asteroid.glb#Scene0",
|
2024-04-22 19:01:27 +00:00
|
|
|
"moonlet" => "models/moonlet.glb#Scene0",
|
|
|
|
"monolith" => "models/monolith_neon.glb#Scene0",
|
|
|
|
"lightorb" => "models/lightorb.glb#Scene0",
|
|
|
|
"orb_busstop" => "models/orb_busstop.glb#Scene0",
|
|
|
|
"orb_busstop_dim" => "models/orb_busstop_dim.glb#Scene0",
|
2024-05-01 01:31:30 +00:00
|
|
|
"crate" => "models/crate.glb#Scene0",
|
2024-04-22 19:01:27 +00:00
|
|
|
"MeteorAceGT" => "models/MeteorAceGT.glb#Scene0",
|
2024-05-08 03:50:35 +00:00
|
|
|
"cruiser" => "models/cruiser.glb#Scene0",
|
2024-07-31 02:49:11 +00:00
|
|
|
"shippingcontainer" => "models/shippingcontainer.glb#Scene0",
|
2024-04-22 19:01:27 +00:00
|
|
|
"satellite" => "models/satellite.glb#Scene0",
|
|
|
|
"pizzeria" => "models/pizzeria2.glb#Scene0",
|
|
|
|
"pizzasign" => "models/pizzasign.glb#Scene0",
|
|
|
|
"selectagon" => "models/selectagon.glb#Scene0",
|
|
|
|
"orbitring" => "models/orbitring.glb#Scene0",
|
2024-04-22 21:36:19 +00:00
|
|
|
"clippy" => "models/clippy/clippy.glb#Scene0",
|
|
|
|
"clippy_ar" => "models/clippy/ar_happy.glb#Scene0",
|
2024-04-22 19:01:27 +00:00
|
|
|
"whale" => "models/whale.glb#Scene0",
|
2024-05-01 15:43:16 +00:00
|
|
|
"marker_satellites" => "models/marker_satellites.glb#Scene0",
|
2024-05-01 16:07:51 +00:00
|
|
|
"marker_planets" => "models/marker_planets.glb#Scene0",
|
2024-04-22 19:01:27 +00:00
|
|
|
"point_of_interest" => "models/point_of_interest.glb#Scene0",
|
|
|
|
_ => "models/error.glb#Scene0",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-22 02:57:20 +00:00
|
|
|
pub fn load_asset(name: &str, entity_commands: &mut EntityCommands, asset_server: &AssetServer) {
|
2024-05-10 08:15:05 +00:00
|
|
|
entity_commands.insert(load_scene_by_path(asset_name_to_path(name), asset_server));
|
2024-04-22 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2024-05-22 02:57:20 +00:00
|
|
|
pub fn load_scene_by_path(path: &str, asset_server: &AssetServer) -> Handle<Scene> {
|
2024-04-22 19:01:27 +00:00
|
|
|
let path_string = path.to_string();
|
|
|
|
if let Some(handle) = asset_server.get_handle(&path_string) {
|
|
|
|
handle
|
|
|
|
} else {
|
|
|
|
asset_server.load(&path_string)
|
|
|
|
}
|
|
|
|
}
|
2024-05-10 08:27:52 +00:00
|
|
|
|
|
|
|
// Jupiter's Ring
|
|
|
|
#[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
|
|
|
|
pub struct JupitersRing {
|
|
|
|
pub alpha_mode: AlphaMode,
|
|
|
|
#[uniform(0)]
|
|
|
|
pub ring_radius: f32,
|
|
|
|
#[uniform(1)]
|
|
|
|
pub jupiter_radius: f32,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Material for JupitersRing {
|
|
|
|
fn fragment_shader() -> ShaderRef {
|
|
|
|
"shaders/jupiters_rings.wgsl".into()
|
|
|
|
}
|
|
|
|
fn alpha_mode(&self) -> AlphaMode {
|
|
|
|
self.alpha_mode
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sky Box
|
|
|
|
#[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
|
|
|
|
pub struct SkyBox {}
|
|
|
|
impl Material for SkyBox {
|
|
|
|
fn fragment_shader() -> ShaderRef {
|
|
|
|
"shaders/skybox.wgsl".into()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Asteroid Surface
|
|
|
|
#[derive(Asset, Reflect, AsBindGroup, Debug, Clone)]
|
|
|
|
pub struct AsteroidSurface {
|
|
|
|
#[uniform(100)]
|
2024-05-22 02:57:20 +00:00
|
|
|
quantize_steps: u32,
|
2024-05-10 08:27:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl MaterialExtension for AsteroidSurface {
|
|
|
|
fn fragment_shader() -> ShaderRef {
|
|
|
|
"shaders/material_asteroid.wgsl".into()
|
|
|
|
}
|
|
|
|
fn deferred_fragment_shader() -> ShaderRef {
|
|
|
|
"shaders/material_asteroid.wgsl".into()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AsteroidSurface {
|
|
|
|
pub fn material() -> ExtendedMaterial<StandardMaterial, AsteroidSurface> {
|
|
|
|
ExtendedMaterial {
|
|
|
|
base: StandardMaterial {
|
2024-07-09 00:32:38 +00:00
|
|
|
base_color: Color::srgb(0.29, 0.255, 0.208),
|
2024-05-10 08:27:52 +00:00
|
|
|
perceptual_roughness: 1.0,
|
|
|
|
opaque_render_method: OpaqueRendererMethod::Auto,
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
extension: Self::default(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl Default for AsteroidSurface {
|
|
|
|
fn default() -> Self {
|
2024-05-22 02:57:20 +00:00
|
|
|
Self { quantize_steps: 3 }
|
2024-05-10 08:27:52 +00:00
|
|
|
}
|
|
|
|
}
|