correctly setup bevy_lunex 2d/3d composite
This commit is contained in:
@@ -61,7 +61,6 @@ fn setup(mut commands: Commands, mut msaa: ResMut<Msaa>) {
|
|||||||
MainCamera,
|
MainCamera,
|
||||||
DepthPrepass,
|
DepthPrepass,
|
||||||
PhosOrbitCamera::default(),
|
PhosOrbitCamera::default(),
|
||||||
MainUi,
|
|
||||||
))
|
))
|
||||||
// .insert(RenderLayers::layer(0))
|
// .insert(RenderLayers::layer(0))
|
||||||
.insert(TemporalAntiAliasBundle::default());
|
.insert(TemporalAntiAliasBundle::default());
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use crate::camera_system::components::PhosCamera;
|
|||||||
use crate::map_rendering::map_init::MapInitPlugin;
|
use crate::map_rendering::map_init::MapInitPlugin;
|
||||||
use crate::map_rendering::render_distance_system::RenderDistancePlugin;
|
use crate::map_rendering::render_distance_system::RenderDistancePlugin;
|
||||||
use crate::ui::game::build_ui::BuildUiPlugin;
|
use crate::ui::game::build_ui::BuildUiPlugin;
|
||||||
|
use crate::ui::lunex_setup_plugin::LunexSetupPlugin;
|
||||||
use crate::utlis::editor_plugin::EditorPlugin;
|
use crate::utlis::editor_plugin::EditorPlugin;
|
||||||
use crate::utlis::tile_selection_plugin::TileSelectionPlugin;
|
use crate::utlis::tile_selection_plugin::TileSelectionPlugin;
|
||||||
use crate::{camera_system::camera_plugin::PhosCameraPlugin, utlis::debug_plugin::DebugPlugin};
|
use crate::{camera_system::camera_plugin::PhosCameraPlugin, utlis::debug_plugin::DebugPlugin};
|
||||||
@@ -40,7 +41,8 @@ impl Plugin for PhosGamePlugin {
|
|||||||
RenderDistancePlugin,
|
RenderDistancePlugin,
|
||||||
BuildingPugin,
|
BuildingPugin,
|
||||||
SimpleAnimationPlugin,
|
SimpleAnimationPlugin,
|
||||||
// BuildUiPlugin,
|
LunexSetupPlugin,
|
||||||
|
BuildUiPlugin,
|
||||||
UnitsPlugin,
|
UnitsPlugin,
|
||||||
DespawnPuglin,
|
DespawnPuglin,
|
||||||
TileSelectionPlugin,
|
TileSelectionPlugin,
|
||||||
|
|||||||
@@ -1,29 +1,15 @@
|
|||||||
use bevy::{prelude::*, render::view::RenderLayers};
|
use bevy::prelude::*;
|
||||||
use bevy_lunex::prelude::*;
|
use bevy_lunex::prelude::*;
|
||||||
use shared::tags::MainCamera;
|
|
||||||
|
|
||||||
pub struct BuildUiPlugin;
|
pub struct BuildUiPlugin;
|
||||||
|
|
||||||
impl Plugin for BuildUiPlugin {
|
impl Plugin for BuildUiPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
// app.add_plugins(UiDefaultPlugins)
|
|
||||||
// .add_plugins(UiDebugPlugin::<MainUi>::new());
|
|
||||||
|
|
||||||
app.add_systems(PostStartup, setup_ui);
|
app.add_systems(PostStartup, setup_ui);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup_ui(mut commands: Commands, assets: Res<AssetServer>) {
|
fn setup_ui(mut commands: Commands, assets: Res<AssetServer>, mut material: ResMut<Assets<StandardMaterial>>) {
|
||||||
commands
|
|
||||||
.spawn((
|
|
||||||
Camera2dBundle {
|
|
||||||
transform: Transform::from_xyz(0.0, 0.0, 1000.0),
|
|
||||||
..default()
|
|
||||||
},
|
|
||||||
MainUi,
|
|
||||||
))
|
|
||||||
.insert(RenderLayers::layer(1));
|
|
||||||
|
|
||||||
commands
|
commands
|
||||||
.spawn((
|
.spawn((
|
||||||
UiTreeBundle::<MainUi> {
|
UiTreeBundle::<MainUi> {
|
||||||
@@ -32,23 +18,17 @@ fn setup_ui(mut commands: Commands, assets: Res<AssetServer>) {
|
|||||||
},
|
},
|
||||||
Name::new("Build UI"),
|
Name::new("Build UI"),
|
||||||
SourceFromCamera,
|
SourceFromCamera,
|
||||||
RenderLayers::layer(1),
|
|
||||||
))
|
))
|
||||||
.with_children(|ui| {
|
.with_children(|ui| {
|
||||||
ui.spawn((
|
ui.spawn((
|
||||||
UiLink::<MainUi>::path("Root"),
|
UiLink::<MainUi>::path("Root"),
|
||||||
UiLayout::boundary()
|
UiLayout::boundary().pos1(Rl(20.0)).pos2(Rl(80.0)).pack::<Base>(),
|
||||||
.pos1(Ab(20.0))
|
|
||||||
.pos2(Rl(100.0) - Ab(20.0))
|
|
||||||
.pack::<Base>(),
|
|
||||||
RenderLayers::layer(1),
|
|
||||||
));
|
));
|
||||||
|
|
||||||
ui.spawn((
|
ui.spawn((
|
||||||
UiLink::<MainUi>::path("Root/Rect"),
|
UiLink::<MainUi>::path("Root/Rect"),
|
||||||
UiLayout::solid().size((Ab(1920.0), Ab(1080.0))).pack::<Base>(),
|
UiLayout::solid().size((Ab(1920.0), Ab(1080.0))).pack::<Base>(),
|
||||||
UiImage2dBundle::from(assets.load("textures/world/test2.png")),
|
UiImage2dBundle::from(assets.load("textures/world/test2.png")),
|
||||||
RenderLayers::layer(1),
|
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
84
game/main/src/ui/lunex_setup_plugin.rs
Normal file
84
game/main/src/ui/lunex_setup_plugin.rs
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
use bevy::{
|
||||||
|
prelude::*,
|
||||||
|
render::render_resource::{Extent3d, TextureDescriptor, TextureDimension, TextureFormat, TextureUsages},
|
||||||
|
window::PrimaryWindow,
|
||||||
|
};
|
||||||
|
use bevy_lunex::prelude::*;
|
||||||
|
use shared::tags::MainCamera;
|
||||||
|
|
||||||
|
pub struct LunexSetupPlugin;
|
||||||
|
|
||||||
|
impl Plugin for LunexSetupPlugin {
|
||||||
|
fn build(&self, app: &mut App) {
|
||||||
|
app.add_plugins(UiDefaultPlugins);
|
||||||
|
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
app.add_plugins(UiDebugPlugin::<MainUi>::new());
|
||||||
|
app.add_systems(PostStartup, setup_cameras);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn setup_cameras(
|
||||||
|
mut commands: Commands,
|
||||||
|
assets: Res<AssetServer>,
|
||||||
|
mut camera_query: Query<&mut Camera, With<MainCamera>>,
|
||||||
|
window_query: Query<&Window, With<PrimaryWindow>>,
|
||||||
|
) {
|
||||||
|
//Prepare Render Texture
|
||||||
|
let win = window_query.single();
|
||||||
|
let size = Extent3d {
|
||||||
|
width: win.physical_width(),
|
||||||
|
height: win.physical_height(),
|
||||||
|
..default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut image = Image {
|
||||||
|
texture_descriptor: TextureDescriptor {
|
||||||
|
label: None,
|
||||||
|
size,
|
||||||
|
dimension: TextureDimension::D2,
|
||||||
|
format: TextureFormat::Bgra8UnormSrgb,
|
||||||
|
mip_level_count: 1,
|
||||||
|
sample_count: 1,
|
||||||
|
usage: TextureUsages::TEXTURE_BINDING | TextureUsages::COPY_DST | TextureUsages::RENDER_ATTACHMENT,
|
||||||
|
view_formats: &[],
|
||||||
|
},
|
||||||
|
..default()
|
||||||
|
};
|
||||||
|
image.resize(size);
|
||||||
|
|
||||||
|
//Configure 3D Camera
|
||||||
|
let mut cam = camera_query.single_mut();
|
||||||
|
let render_image = assets.add(image);
|
||||||
|
cam.target = render_image.clone().into();
|
||||||
|
cam.order = -1;
|
||||||
|
cam.clear_color = ClearColorConfig::Custom(LinearRgba::NONE.into());
|
||||||
|
|
||||||
|
//Add Render Texture image
|
||||||
|
commands
|
||||||
|
.spawn((UiTreeBundle::<MainUi>::from(UiTree::new2d("Main UI")), SourceFromCamera))
|
||||||
|
.with_children(|ui| {
|
||||||
|
ui.spawn((
|
||||||
|
UiLink::<MainUi>::path("Root"),
|
||||||
|
UiLayout::window_full().size((win.width(), win.height())).pack::<Base>(),
|
||||||
|
));
|
||||||
|
ui.spawn((
|
||||||
|
UiLink::<MainUi>::path("Root/Camera3D"),
|
||||||
|
UiLayout::solid()
|
||||||
|
.size((win.width(), win.height()))
|
||||||
|
.scaling(Scaling::Fill)
|
||||||
|
.pack::<Base>(),
|
||||||
|
UiImage2dBundle::from(render_image),
|
||||||
|
PickingPortal,
|
||||||
|
));
|
||||||
|
});
|
||||||
|
|
||||||
|
//Spawn 2d UI Camera
|
||||||
|
commands.spawn((
|
||||||
|
MainUi,
|
||||||
|
Camera2dBundle {
|
||||||
|
transform: Transform::from_xyz(0.0, 0.0, 1000.0),
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
));
|
||||||
|
}
|
||||||
@@ -1 +1,2 @@
|
|||||||
pub mod game;
|
pub mod game;
|
||||||
|
pub mod lunex_setup_plugin;
|
||||||
|
|||||||
@@ -13,6 +13,6 @@ impl Plugin for SimpleAnimationPlugin {
|
|||||||
fn rotate(mut query: Query<(&mut Transform, &RotationAnimation)>, time: Res<Time>) {
|
fn rotate(mut query: Query<(&mut Transform, &RotationAnimation)>, time: Res<Time>) {
|
||||||
for (mut transform, rot) in query.iter_mut() {
|
for (mut transform, rot) in query.iter_mut() {
|
||||||
let cur_rot = transform.rotation;
|
let cur_rot = transform.rotation;
|
||||||
transform.rotation = cur_rot * Quat::from_axis_angle(rot.axis, rot.speed.to_radians() * time.elapsed_seconds());
|
transform.rotation = cur_rot * Quat::from_axis_angle(rot.axis, rot.speed.to_radians() * time.delta_seconds());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user