ntoes for shapes and grid fills screen
This commit is contained in:
parent
ad05e6d1f2
commit
38261fbf54
7 changed files with 54 additions and 57 deletions
|
@ -24,7 +24,8 @@ Eventually, this will be a level editor... But until then, I guess it's just fun
|
|||
- [x] Snap to grid
|
||||
- [x] Change grid size
|
||||
- [x] Show/Hide grid(also make a visible grid in the first place)
|
||||
- [ ] Make grid fill the screen at all times
|
||||
- [x] Make grid fill the screen at all times
|
||||
- [x] Comment/Editor note for shapes
|
||||
- [ ] Save? (maybe just import and export directly?)
|
||||
- [ ] Export
|
||||
- [ ] Import
|
||||
|
@ -34,6 +35,7 @@ Eventually, this will be a level editor... But until then, I guess it's just fun
|
|||
- [ ] Double click on shape in tree view will center the relevant shape
|
||||
- [ ] Grab shapes instead of center points
|
||||
- [ ] Reorder items tree
|
||||
- [ ] Select item by clicking/double clicking on the relevant shape/image
|
||||
|
||||
## Maybe, just maybe todo
|
||||
|
||||
|
|
|
@ -8,55 +8,6 @@ let grid_color: vec4<f32> = vec4<f32>(1.0, 1.0, 1.0, 0.3);
|
|||
let x_color: vec4<f32> = vec4<f32>(1.0, 0.0, 0.0, 1.0);
|
||||
let y_color :vec4<f32> = vec4<f32>(0.0, 1.0, 0.0, 1.0);
|
||||
|
||||
|
||||
#import bevy_sprite::mesh2d_view_bindings
|
||||
#import bevy_sprite::mesh2d_bindings
|
||||
|
||||
// NOTE: Bindings must come before functions that use them!
|
||||
#import bevy_sprite::mesh2d_functions
|
||||
|
||||
struct Vertex {
|
||||
@location(0) position: vec3<f32>,
|
||||
@location(1) normal: vec3<f32>,
|
||||
@location(2) uv: vec2<f32>,
|
||||
#ifdef VERTEX_TANGENTS
|
||||
@location(3) tangent: vec4<f32>,
|
||||
#endif
|
||||
#ifdef VERTEX_COLORS
|
||||
@location(4) color: vec4<f32>,
|
||||
#endif
|
||||
@builtin(vertex_index) index: u32,
|
||||
};
|
||||
|
||||
struct VertexOutput {
|
||||
@builtin(position) clip_position: vec4<f32>,
|
||||
#import bevy_sprite::mesh2d_vertex_output
|
||||
}
|
||||
|
||||
@vertex
|
||||
fn vertex(vertex: Vertex) -> VertexOutput {
|
||||
var out: VertexOutput;
|
||||
out.uv = vertex.uv;
|
||||
out.world_position = mesh2d_position_local_to_world(mesh.model, vec4<f32>(vertex.position, 1.0));
|
||||
out.clip_position = mesh2d_position_world_to_clip(out.world_position);
|
||||
var grid_plane = array<vec3<f32>, 4>(
|
||||
vec3<f32>(-1., -1., 1.),
|
||||
vec3<f32>(-1., 1., 1.),
|
||||
vec3<f32>(1., -1., 1.),
|
||||
vec3<f32>(1., 1., 1.)
|
||||
);
|
||||
out.clip_position = vec4<f32>(grid_plane[vertex.index].xyz, 1.0);
|
||||
|
||||
out.world_normal = mesh2d_normal_local_to_world(vertex.normal);
|
||||
#ifdef VERTEX_TANGENTS
|
||||
out.world_tangent = mesh2d_tangent_local_to_world(vertex.tangent);
|
||||
#endif
|
||||
#ifdef VERTEX_COLORS
|
||||
out.color = vertex.color;
|
||||
#endif
|
||||
return out;
|
||||
}
|
||||
|
||||
@fragment
|
||||
fn fragment(
|
||||
@builtin(position) position: vec4<f32>,
|
||||
|
|
|
@ -328,5 +328,5 @@ fn create_new_shape(coms: &mut Commands, pos: Vec2, create_shape: CreateShape, p
|
|||
};
|
||||
let edges = if center.is_none() { Vec::from([fp]) } else { Vec::new() };
|
||||
|
||||
ShapeData { shape: create_shape, main_shape, edges, center, name: "shape".to_string() }
|
||||
ShapeData { shape: create_shape, main_shape, edges, center, name: "shape".to_string(), note: String::new() }
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
use bevy::prelude::*;
|
||||
use bevy::reflect::TypeUuid;
|
||||
use bevy::render::render_resource::AsBindGroup;
|
||||
use bevy::sprite::{MaterialMesh2dBundle, Material2d};
|
||||
use bevy::sprite::{MaterialMesh2dBundle, Material2d, Mesh2dHandle};
|
||||
|
||||
use crate::MainCamera;
|
||||
|
||||
|
@ -29,8 +29,7 @@ pub fn spawn_grid(
|
|||
) {
|
||||
|
||||
coms.spawn().insert_bundle(MaterialMesh2dBundle {
|
||||
mesh: meshes.add(Mesh::from(shape::Plane { size: 1000.0 })).into(),
|
||||
transform: Transform::from_rotation(Quat::from_rotation_x(std::f32::consts::FRAC_PI_2)),
|
||||
mesh: meshes.add(Mesh::from(shape::Quad::new(Vec2::splat(100.0)))).into(),
|
||||
material: mats.add(GridMaterial { width: 2.0, size: Vec2::splat(15.0), visible: 1 }),
|
||||
..default()
|
||||
});
|
||||
|
@ -62,4 +61,27 @@ pub fn update_grid_position(
|
|||
for mut t in grid.iter_mut() {
|
||||
t.translation = cam_pos;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_grid_size(
|
||||
mut last_size: Local<Vec2>,
|
||||
windows: Res<Windows>,
|
||||
projection: Query<&OrthographicProjection, With<MainCamera>>,
|
||||
grid: Query<&Mesh2dHandle, With<Handle<GridMaterial>>>,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
) {
|
||||
let size = windows.get_primary().map(|w| Vec2::new(w.width(), w.height())).unwrap_or(Vec2::splat(100.0));
|
||||
let zoom = projection.get_single().map(|p| p.scale).unwrap_or(1.0);
|
||||
|
||||
let size = size * zoom * Vec2::new(0.9, 1.0);
|
||||
|
||||
if size != *last_size {
|
||||
for h in grid.iter() {
|
||||
if let Some(m) = meshes.get_mut(&h.0) {
|
||||
*m = Mesh::from(shape::Quad::new(size));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*last_size = size;
|
||||
}
|
|
@ -33,7 +33,7 @@ impl SnapGrid {
|
|||
}
|
||||
impl Default for SnapGrid {
|
||||
fn default() -> Self {
|
||||
Self { width: 15.0, height: 15.0, snap: false, offset: Vec2::ZERO, visible: true }
|
||||
Self { width: 50.0, height: 50.0, snap: false, offset: Vec2::ZERO, visible: true }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,6 +52,7 @@ pub struct ShapeData {
|
|||
pub main_shape: Entity,
|
||||
pub edges: Vec<Entity>,
|
||||
pub center: Option<Entity>,
|
||||
pub note: String,
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
|
|
20
src/main.rs
20
src/main.rs
|
@ -7,6 +7,7 @@ use bevy_egui::{egui, EguiContext, EguiPlugin};
|
|||
use bevy_prototype_lyon::prelude::*;
|
||||
|
||||
use shape_maker::*;
|
||||
use shape_maker::ui::SelectedItem;
|
||||
|
||||
fn main() {
|
||||
let mut app = App::new();
|
||||
|
@ -59,6 +60,10 @@ fn main() {
|
|||
.add_system(scale_points)
|
||||
.add_system(infinite_grid::update_grid_shader)
|
||||
.add_system(infinite_grid::update_grid_position)
|
||||
.add_system(infinite_grid::update_grid_size)
|
||||
.add_system(delete_selected_item_on_del_sys.with_run_criteria(|mut ec: ResMut<EguiContext>|
|
||||
if ec.ctx_mut().wants_keyboard_input() { ShouldRun::No } else { ShouldRun::Yes }
|
||||
))
|
||||
;
|
||||
|
||||
app.run();
|
||||
|
@ -73,11 +78,24 @@ fn basic_setup_sys(
|
|||
|
||||
fn configure_visuals(mut egui_ctx: ResMut<EguiContext>) {
|
||||
egui_ctx.ctx_mut().set_visuals(egui::Visuals {
|
||||
window_rounding: 0.0.into(),
|
||||
window_rounding: 0.5.into(),
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
|
||||
fn delete_selected_item_on_del_sys(
|
||||
mut coms: Commands,
|
||||
mut selected: ResMut<SelectedItem>,
|
||||
keyboard: Res<Input<KeyCode>>,
|
||||
) {
|
||||
if keyboard.just_pressed(KeyCode::Delete) || keyboard.just_pressed(KeyCode::X) {
|
||||
if let Some(e) = selected.0 {
|
||||
coms.entity(e).despawn_recursive();
|
||||
selected.0 = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn zoom_camera_sys(
|
||||
mut mouse_scroll: EventReader<MouseWheel>,
|
||||
mut cam: Query<&mut OrthographicProjection, With<MainCamera>>,
|
||||
|
|
|
@ -200,7 +200,7 @@ pub fn inspector_sys(
|
|||
let mut open = true;
|
||||
|
||||
egui::Window::new("Inspector")
|
||||
.default_pos((350.0, 350.0))
|
||||
.default_pos((20.0, 350.0))
|
||||
.fixed_size((150.0, f32::INFINITY))
|
||||
.title_bar(true)
|
||||
.collapsible(false)
|
||||
|
@ -280,6 +280,9 @@ pub fn inspector_sys(
|
|||
});
|
||||
}
|
||||
}
|
||||
ui.separator();
|
||||
ui.label("Notes");
|
||||
ui.text_edit_multiline(&mut sd.note);
|
||||
|
||||
|
||||
ui.separator();
|
||||
|
|
Loading…
Reference in a new issue