//! This example demonstrates the built-in 3d shapes in Bevy. //! The scene includes a patterned texture and a rotation for visualizing the normals and UVs. use std::f32::consts::PI; use bevy::asset::AssetPath; use bevy::core_pipeline::prepass::DepthPrepass; //use bevy::pbr::{ExtendedMaterial, OpaqueRendererMethod}; use bevy::{gltf::GltfMesh, utils::HashMap}; //use bevy::gltf::Gltf; use bevy::core_pipeline::bloom::BloomSettings; use bevy::core_pipeline::tonemapping::Tonemapping; use bevy::{core_pipeline::bloom::BloomCompositeMode, prelude::*}; use bevy_magic_fx::magic_fx::MagicFxVariantComponent; use bevy_magic_fx::{ MagicFxPlugin}; //use bevy_magic_fx::magic_fx::{ MagicFxVariantComponent, }; use bevy_magic_fx::animated_material::{build_animated_material, AnimatedMaterial}; use bevy_magic_fx::{ magic_fx_variant::{MagicFxVariant, MagicFxVariantManifest}, shader_variant::ShaderVariantManifest, }; fn main() { App::new() .insert_resource(AssetHandlesResource::default()) .insert_resource(AssetLoadingResource::default()) .add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest())) .add_plugins(bevy_obj::ObjPlugin) .add_plugins( MagicFxPlugin ) .add_systems(Update, update_loading_shader_variant_manifest) .add_systems(Update, update_loading_magic_fx_variant_manifest) .add_systems(Startup, setup) .add_systems(Update, rotate) .run(); } #[derive(Resource, Default)] struct AssetHandlesResource { magic_fx_variant_manifest_handle: Handle, // shader_variant_manifest_handle: Handle, // mesh_handle: Handle, // anim_material: Handle , // particle_texture_handle: Handle } #[derive(Resource, Default)] struct AssetLoadingResource { texture_handles_map: HashMap>, mesh_handles_map: HashMap>, shader_variants_map: HashMap>, animated_material_map: HashMap>, } fn setup( mut commands: Commands, asset_server: ResMut, mut asset_handles_resource: ResMut, mut asset_loading_resource: ResMut, mut meshes: ResMut>, mut materials: ResMut>, ) { /* Simulate our bevy asset loader with 'asset_loading_resource' */ let particle_texture_handle = asset_server.load("textures/kenney/fire_01.png"); asset_loading_resource .texture_handles_map .insert("textures/fire_01.png".to_string(), particle_texture_handle); let shards_texture_handle = asset_server.load("textures/kenney/shards.png"); asset_loading_resource .texture_handles_map .insert("textures/shards.png".to_string(), shards_texture_handle); let blast_texture_handle = asset_server.load("textures/blast_01.png"); asset_loading_resource .texture_handles_map .insert("textures/blast_01.png".to_string(), blast_texture_handle); let magic_texture_handle = asset_server.load("textures/magic_01.png"); asset_loading_resource .texture_handles_map .insert("textures/magic_01.png".to_string(), magic_texture_handle); let particle_beam_handle = asset_server.load("textures/beam_01.png"); asset_loading_resource .texture_handles_map .insert("textures/beam_01.png".to_string(), particle_beam_handle); let shader_variant_manifest_handle = asset_server.load("shader_variants/purple.shadvar.ron"); asset_loading_resource.shader_variants_map.insert( "shader_variants/purple.shadvar.ron".to_string(), shader_variant_manifest_handle.clone(), ); // asset_handles_resource.shader_variant_manifest_handle = shader_variant_manifest_handle.clone(); let beam_shader_variant_manifest_handle = asset_server.load("shader_variants/beam.shadvar.ron"); asset_loading_resource.shader_variants_map.insert( "shader_variants/beam.shadvar.ron".to_string(), beam_shader_variant_manifest_handle.clone(), ); let blast_shader_variant_manifest_handle = asset_server.load("shader_variants/blast.shadvar.ron"); asset_loading_resource.shader_variants_map.insert( "shader_variants/blast.shadvar.ron".to_string(), blast_shader_variant_manifest_handle.clone(), ); // asset_handles_resource.shader_variant_manifest_handle = beam_shader_variant_manifest_handle.clone(); let mesh_handle: Handle = asset_server.load("meshes/projectile.obj"); asset_loading_resource .mesh_handles_map .insert("meshes/projectile.obj".to_string(), mesh_handle); let mesh_handle: Handle = asset_server.load("meshes/shatter.obj"); asset_loading_resource .mesh_handles_map .insert("meshes/shatter.obj".to_string(), mesh_handle); commands.spawn(PointLightBundle { point_light: PointLight { intensity: 2000.0, range: 100., shadows_enabled: false, ..default() }, transform: Transform::from_xyz(8.0, 16.0, 8.0), ..default() }); let material_color : Color = LinearRgba::rgb(0.5, 0.5, 0.5).into(); // ground plane commands.spawn(PbrBundle { mesh: meshes.add(Plane3d::default().mesh().size(50.0, 50.0)), material: materials.add( material_color ), ..default() }); commands.spawn(( Camera3dBundle { camera: Camera { hdr: true, // 1. HDR must be enabled on the camera ..default() }, tonemapping: Tonemapping::TonyMcMapface, transform: Transform::from_xyz(0.0, 6., 12.0) .looking_at(Vec3::new(0., 1., 0.), Vec3::Y), ..default() }, BloomSettings::default(), // 2. Enable bloom for the camera DepthPrepass )); } fn rotate(mut query: Query<&mut Transform, With>>, time: Res