A Quadrilateral Cowboy clone intended to help me learn Game Dev

Got the render UI to texture tutorial working, does weird things with the worldinspector plugin

+104 -10
+1
assets/fonts/NotoSans.ttf
··· 1 + /usr/share/fonts/truetype/noto/NotoSans-Regular.ttf
+102 -6
src/level.rs
··· 1 - use bevy::prelude::*; 2 - 1 + use bevy::{asset::RenderAssetUsages, camera::{RenderTarget}, prelude::*, render::render_resource::{Extent3d, TextureDimension, TextureFormat, TextureUsages}}; 3 2 use crate::game::{GameAssets, GameState}; 4 3 5 4 pub fn plugin(app: &mut App) { ··· 46 45 next_state.set(GameState::Test); 47 46 } 48 47 49 - fn run_test(mut commands: Commands, game_assets: Res<GameAssets>) { 50 - println!("in run_test"); 48 + fn run_test(mut commands: Commands, _game_assets: Res<GameAssets>, mut images: ResMut<Assets<Image>>, mut materials: ResMut<Assets<StandardMaterial>>, mut meshes: ResMut<Assets<Mesh>>, asset_server: Res<AssetServer>) { 49 + let size = Extent3d{ 50 + width: 512, 51 + height: 512, 52 + ..default() 53 + }; 54 + 55 + let mut image = Image::new_fill( 56 + size, 57 + TextureDimension::D2, 58 + &[0, 0, 0, 0], 59 + TextureFormat::Bgra8UnormSrgb, 60 + RenderAssetUsages::default() 61 + ); 62 + 63 + image.texture_descriptor.usage = 64 + TextureUsages::TEXTURE_BINDING | TextureUsages::COPY_DST | TextureUsages::RENDER_ATTACHMENT; 65 + 66 + let image_handle = images.add(image); 67 + 68 + commands.spawn(DirectionalLight::default()); 69 + 70 + let texture_camera = commands.spawn(( 71 + Camera2d, 72 + Camera{ 73 + order: -1, 74 + ..default() 75 + }, 76 + RenderTarget::Image(image_handle.clone().into()), 77 + )).id(); 78 + 79 + commands.spawn(( 80 + Node{ 81 + width: percent(100), 82 + height: percent(100), 83 + flex_direction: FlexDirection::Column, 84 + justify_content: JustifyContent::Center, 85 + align_items: AlignItems::Center, 86 + ..default() 87 + }, 88 + BackgroundColor(bevy::color::palettes::css::GRAY.into()), 89 + UiTargetCamera(texture_camera) 90 + )).with_children(|parent| { 91 + parent.spawn(( 92 + Node{ 93 + position_type: PositionType::Absolute, 94 + width: Val::Auto, 95 + height: Val::Auto, 96 + align_items: AlignItems::Center, 97 + padding: UiRect::all(Val::Px(20.)), 98 + border_radius: BorderRadius::all(Val::Px(10.)), 99 + ..default() 100 + }, 101 + BackgroundColor(bevy::color::palettes::css::BLUE.into()) 102 + )).with_children(|parent| { 103 + parent.spawn(( 104 + Text::new("hi\nbevy!"), 105 + TextFont{ 106 + font_size: 40.0, 107 + font: asset_server.load("fonts/NotoSans.ttf"), 108 + ..default() 109 + }, 110 + Underline, 111 + TextColor::WHITE 112 + )); 113 + }); 114 + }); 115 + 116 + let mesh_handle = meshes.add(Cuboid::default()); 117 + 118 + let material_handle = materials.add(StandardMaterial{ 119 + base_color_texture: Some(image_handle), 120 + reflectance: 0.02, 121 + unlit: false, 122 + ..default() 123 + }); 124 + 125 + commands.spawn(( 126 + Mesh3d(mesh_handle), 127 + MeshMaterial3d(material_handle), 128 + Transform::from_xyz(0.0, 0.0, 1.5).with_rotation(Quat::from_rotation_x(std::f32::consts::PI)) 129 + )); 130 + 131 + commands.spawn(( 132 + Camera3d::default(), 133 + Transform::from_xyz(0.0, 0.0, 5.0).looking_at(Vec3::ZERO, Vec3::Y), 134 + Camera{ 135 + order: 0, 136 + ..default() 137 + } 138 + )); 139 + 140 + /* 51 141 // terminal mesh 52 142 commands.spawn(( 53 143 SceneRoot(game_assets.terminal.clone()), ··· 64 154 // camera 65 155 commands.spawn(( 66 156 Camera3d::default(), 67 - Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y), 68 - AmbientLight::default() 157 + Camera{ 158 + order: -1, 159 + clear_color: Color::WHITE.into(), 160 + ..default() 161 + }, 162 + RenderTarget::Image(image_handle.clone().into()), 163 + Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y) 69 164 )); 165 + */ 70 166 }
+1 -4
src/main.rs
··· 1 - use bevy::prelude::*; 2 - use bevy_inspector_egui::{bevy_egui::EguiPlugin, quick::WorldInspectorPlugin}; 1 + use bevy::{prelude::*, input::common_conditions::input_toggle_active}; 3 2 4 3 mod game; 5 4 mod level; ··· 7 6 fn main() { 8 7 App::new() 9 8 .add_plugins(DefaultPlugins) 10 - .add_plugins(EguiPlugin::default()) 11 - .add_plugins(WorldInspectorPlugin::new()) 12 9 .init_state::<game::GameState>() 13 10 .add_plugins(level::plugin) 14 11 .init_resource::<level::LevelManifest>()