Skip to content

Commit

Permalink
Merge pull request #49 from bytestring-net/dev
Browse files Browse the repository at this point in the history
Added shapes
  • Loading branch information
IDEDARY authored Jul 1, 2024
2 parents 70751d5 + 088c5a3 commit 66a3b85
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{
"type": "cargo",
"command": "run",
"args": ["--bin", "minimal"],
"args": ["--bin", "mesh2d"],
"problemMatcher": [
"$rustc"
],
Expand Down
38 changes: 25 additions & 13 deletions crates/bevy_lunex/src/systems.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::*;
use bevy::{math::Vec3A, render::primitives::Aabb, text::TextLayoutInfo, window::PrimaryWindow};
use bevy::{math::Vec3A, render::primitives::Aabb, sprite::Mesh2dHandle, text::TextLayoutInfo, window::PrimaryWindow};
use lunex_engine::*;


Expand Down Expand Up @@ -331,7 +331,7 @@ pub fn fetch_dimension_from_node<T:Component, N:Default + Component>(
if let Some(container) = node.obtain_data() {
if dimension.as_ref().size != container.rectangle.size {
#[cfg(feature = "verbose")]
info!("{} {} - Linked {} fetched Dimension data from node", "<-".bright_green(), link.path.yellow().bold(), "ENTITY".blue());
info!("{} {} - Linked {} fetched Dimension data from node: {:?}", "<-".bright_green(), link.path.yellow().bold(), "ENTITY".blue(), container.rectangle.size);
dimension.size = container.rectangle.size;
}
}
Expand Down Expand Up @@ -405,24 +405,36 @@ pub fn element_image_size_from_dimension<T: Component>(
/// * Generic `(T)` - Marker component grouping entities into one widget type
pub fn element_reconstruct_mesh<T: Component>(
mut msh: ResMut<Assets<Mesh>>,
mut query: Query<(&Dimension, &mut Handle<Mesh>, &mut Aabb), (With<UiLink<T>>, With<Element>, Changed<Dimension>)>,
mut query: Query<(&Dimension, Option<&mut Handle<Mesh>>, Option<&mut Mesh2dHandle>, Option<&mut Aabb>), (With<UiLink<T>>, With<Element>, Or<(Changed<Dimension>, Added<Mesh2dHandle>)>)>,
) {
for (dimension, mut mesh, mut aabb) in &mut query {
for (dimension, mut mesh_option, mut mesh2d_option, mut aabb_option) in &mut query {

#[cfg(feature = "verbose")]
info!("{} {} - Reconstructed mesh size", "--".yellow(), "ELEMENT".red());

// Unload old mesh
let _ = msh.remove(mesh.id());
if let Some(aabb) = aabb_option.as_mut() {
// Create new culling boundary
**aabb = Aabb {
center: Vec3A::ZERO,
half_extents: Vec3A::new(dimension.size.x/2.0, dimension.size.y/2.0, 1.0),
};
}

if let Some(mesh) = mesh_option.as_mut() {
// Unload old mesh
let _ = msh.remove(mesh.id());

// Create new culling boundary
*aabb = Aabb {
center: Vec3A::ZERO,
half_extents: Vec3A::new(dimension.size.x/2.0, dimension.size.y/2.0, 1.0),
};
// Create new mesh
**mesh = msh.add(Rectangle {half_size: dimension.size / 2.0});
}

// Create new mesh
*mesh = msh.add(Rectangle {half_size: dimension.size / 2.0})
if let Some(mesh2d) = mesh2d_option.as_mut() {
// Unload old mesh
let _ = msh.remove(mesh2d.0.id());

// Create new mesh
**mesh2d = Mesh2dHandle(msh.add(Rectangle {half_size: dimension.size / 2.0}));
}
}
}

Expand Down
28 changes: 28 additions & 0 deletions examples/mesh2d/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "mesh2d"
authors.workspace = true
version.workspace = true
edition.workspace = true
publish = false

[dependencies]
bevy = { version = "0.14.0-rc.2", default_features = false, features = [
"bevy_asset",
"bevy_gilrs",
"bevy_winit",
"bevy_core_pipeline",
"bevy_pbr",
"bevy_render",
"bevy_sprite",
"bevy_text",
"multi_threaded",
"png",
"hdr",
"x11",
"bevy_gizmos",
"tonemapping_luts",
"default_font",

"dynamic_linking",
] }
bevy_lunex = { workspace = true, features=["debug"] }
Binary file added examples/mesh2d/assets/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions examples/mesh2d/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use bevy::{prelude::*, sprite::{MaterialMesh2dBundle, Mesh2dHandle}};
use bevy_lunex::prelude::*;


fn main() {
App::new()
.add_plugins((DefaultPlugins, UiPlugin))
.add_systems(Startup, setup)
.run();
}

fn setup(mut cmd: Commands, mut meshes: ResMut<Assets<Mesh>>, mut materials: ResMut<Assets<ColorMaterial>>) {

cmd.spawn((
MainUi,
Camera2dBundle {
transform: Transform::from_xyz(0.0, 0.0, 1000.0),
camera: Camera::default(),
..default()
}
));

cmd.spawn((
UiTreeBundle::<MainUi> {
tree: UiTree::new("MyUiSystem"),
..default()
},
MovableByCamera,
)).with_children(|ui| {

ui.spawn((
UiLink::<MainUi>::path("Root"),
UiLayout::boundary().pos1(Ab(20.0)).pos2(Rl(100.0) - Ab(20.0)).pack::<Base>(),
));

ui.spawn((
UiLink::<MainUi>::path("Root/Rectangle"),
UiLayout::solid().size((Ab(1920.0), Ab(1080.0))).pack::<Base>(),
Element,
Dimension::default(),
MaterialMesh2dBundle {
mesh: Mesh2dHandle(meshes.add(Rectangle { half_size: Vec2::splat(50.0) })),
material: materials.add(Color::srgb(1.0, 0.5, 0.5)),
..default()
}
));

});

}

0 comments on commit 66a3b85

Please sign in to comment.