Skip to content

Commit

Permalink
Egui.
Browse files Browse the repository at this point in the history
  • Loading branch information
tychedelia committed May 9, 2024
1 parent ee2e01f commit 92e5afb
Show file tree
Hide file tree
Showing 148 changed files with 1,242 additions and 1,691 deletions.
1,882 changes: 708 additions & 1,174 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ members = [
resolver = "2"

[workspace.dependencies]
bevy = { path = "../../bevyengine/bevy" }
bevy = { git = "https://github.com/bevyengine/bevy" }
1 change: 1 addition & 0 deletions bevy_nannou/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod prelude {
pub use bevy::prelude::*;
pub use bevy_nannou_draw::render::blend::*;
pub use bevy_nannou_draw::*;
pub use bevy_nannou_draw::draw::*;
}

pub struct NannouPlugin;
Expand Down
2 changes: 1 addition & 1 deletion bevy_nannou_draw/src/draw/background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ where

/// Specify the color via red, green, blue and alpha channels.
pub fn rgba(self, r: f32, g: f32, b: f32, a: f32) -> Self {
self.color(Color::rgba(r, g, b, a))
self.color(Color::srgba(r, g, b, a))
}

/// Specify the color via hue, saturation and luminance.
Expand Down
2 changes: 1 addition & 1 deletion bevy_nannou_draw/src/draw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub mod instanced;
pub mod mesh;
pub mod primitive;
pub mod properties;
pub mod render;
pub(crate) mod render;
pub mod theme;

/// A simple API for drawing 2D and 3D graphics.
Expand Down
4 changes: 2 additions & 2 deletions bevy_nannou_draw/src/draw/properties/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ pub trait SetColor: Sized {

/// Specify the color via red, green, blue and alpha channels.
fn rgba(self, r: f32, g: f32, b: f32, a: f32) -> Self {
self.color(Color::rgba(r, g, b, a))
self.color(Color::srgba(r, g, b, a))
}

/// Specify the color via red, green, blue and alpha channels as bytes
fn rgba8(self, r: u8, g: u8, b: u8, a: u8) -> Self {
self.color(Color::rgba_u8(r, g, b, a))
self.color(Color::srgba_u8(r, g, b, a))
}

/// Specify the color via hue, saturation and luminance.
Expand Down
4 changes: 2 additions & 2 deletions bevy_nannou_draw/src/draw/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ impl Theme {
impl Default for Theme {
fn default() -> Self {
// TODO: This should be pub const.
let default_fill = Color::rgba(1.0, 1.0, 1.0, 1.0);
let default_stroke = Color::rgba(0.0, 0.0, 0.0, 1.0);
let default_fill = Color::srgba(1.0, 1.0, 1.0, 1.0);
let default_stroke = Color::srgba(0.0, 0.0, 0.0, 1.0);

let fill_color = ThemeColor {
default: default_fill,
Expand Down
6 changes: 3 additions & 3 deletions bevy_nannou_draw/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl Plugin for NannouDrawPlugin {
}
}

fn reset_draw(mut draw_q: Query<&mut Draw>) {
fn reset_draw(mut draw_q: Query<&mut DrawHolder>) {
for mut draw in draw_q.iter_mut() {
draw.reset();
}
Expand All @@ -29,9 +29,9 @@ fn spawn_draw(mut commands: Commands, query: Query<Entity, Added<Window>>) {
for entity in query.iter() {
commands
.entity(entity)
.insert(Draw(draw::Draw::new(entity)));
.insert(DrawHolder(draw::Draw::new(entity)));
}
}

#[derive(Component, Clone, Deref, DerefMut)]
pub struct Draw(pub draw::Draw);
pub struct DrawHolder(pub draw::Draw);
6 changes: 3 additions & 3 deletions bevy_nannou_draw/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::draw::mesh::MeshExt;
use crate::draw::primitive::Primitive;
use crate::draw::render::{GlyphCache, RenderContext, RenderPrimitive};
use crate::draw::{DrawCommand, DrawContext};
use crate::{draw, Draw};
use crate::{draw, DrawHolder};

pub struct NannouRenderPlugin;

Expand Down Expand Up @@ -169,7 +169,7 @@ fn setup_default_texture(mut commands: Commands, mut images: ResMut<Assets<Image
pub struct UntypedMaterialId(UntypedAssetId);

fn update_material<M>(
draw_q: Query<&Draw>,
draw_q: Query<&DrawHolder>,
mut commands: Commands,
mut materials: ResMut<Assets<M>>,
mut materials_q: Query<(Entity, &UntypedMaterialId)>,
Expand Down Expand Up @@ -197,7 +197,7 @@ fn update_material<M>(

fn update_draw_mesh(
mut commands: Commands,
draw_q: Query<&Draw>,
draw_q: Query<&DrawHolder>,
mut cameras_q: Query<(&mut Camera, &RenderLayers), With<NannouCamera>>,
windows: Query<&Window>,
mut glyph_cache: ResMut<GlyphCache>,
Expand Down
14 changes: 8 additions & 6 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,25 @@ audrey = "0.3"
hotglsl = "0.2"
hrtf = "0.2"
nannou = { version ="0.19.0", path = "../nannou" }
#nannou_audio = { version ="0.19.0", path = "../nannou_audio" }
#nannou_egui = { version ="0.19.0", path = "../nannou_egui" }
#nannou_isf = { version ="0.1.0", path = "../nannou_isf" }
#nannou_laser = { version ="0.19.0", features = ["ffi", "ilda-idtf"], path = "../nannou_laser" }
#nannou_osc = { version ="0.19.0", path = "../nannou_osc" }
nannou_audio = { version ="0.19.0", path = "../nannou_audio" }
nannou_laser = { version ="0.19.0", features = ["ffi", "ilda-idtf"], path = "../nannou_laser" }
nannou_osc = { version ="0.19.0", path = "../nannou_osc" }
pitch_calc = { version = "0.12", features = ["serde"] }
time_calc = { version= "0.13", features = ["serde"] }
walkdir = "2"
hound = "3.4.0"
ringbuf = "0.2.2"
futures = "0.3"
bevy_nannou = { version = "0.1.0", path = "../bevy_nannou" }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "1", features = ["full"]}
[target.'cfg(target_arch = "wasm32")'.dependencies]
tokio = { version = "1", features = ["rt"]}

[features]
egui = ["nannou/egui"]


# Audio
[[example]]
name = "hrtf-noise"
Expand Down Expand Up @@ -202,6 +203,7 @@ path = "ui/egui/tune_color.rs"
[[example]]
name = "simple_ui"
path = "ui/egui/simple_ui.rs"
required-features = ["egui"]

# WebGPU
[[example]]
Expand Down
4 changes: 2 additions & 2 deletions examples/audio/feedback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn pass_out(model: &mut OutputModel, buffer: &mut Buffer) {

fn key_pressed(_app: &App, model: &mut Model, key: Key) {
match key {
Key::Space => {
KeyCode::Space => {
if model.in_stream.is_paused() {
model.in_stream.play().unwrap();
model.out_stream.play().unwrap();
Expand All @@ -105,5 +105,5 @@ fn key_pressed(_app: &App, model: &mut Model, key: Key) {
}

fn view(_app: &App, _model: &Model, frame: Frame) {
frame.clear(DIMGRAY);
draw.background().color(DIMGRAY);
}
8 changes: 4 additions & 4 deletions examples/audio/hrtf-noise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ fn audio(audio: &mut Audio, output: &mut Buffer) {

fn key_pressed(_app: &App, model: &mut Model, key: Key) {
// Pause or unpause the audio when Space is pressed.
if let Key::Space = key {
if let KeyCode::Space = key {
if model.stream.is_playing() {
model.stream.pause().unwrap();
} else {
Expand All @@ -179,8 +179,8 @@ fn mouse_moved(_app: &App, model: &mut Model, p: Point2) {
.ok();
}

fn view(app: &App, model: &Model, frame: Frame) {
frame.clear(rgb(0.1, 0.12, 0.13));
fn view(app: &App, model: &Model) {
draw.background().color(rgb(0.1, 0.12, 0.13));
let draw = app.draw();

// Listenable area.
Expand All @@ -199,7 +199,7 @@ fn view(app: &App, model: &Model, frame: Frame) {
let text = format!("Noise Source:\n[{:.2}, {:.2}, {:.2}]", x, y, z);
draw.text(&text).xy(app.mouse.position() + vec2(0.0, 20.0));

draw.to_frame(app, &frame).unwrap();

}

// Simple function for determining a gain based on the distance from the listener.
Expand Down
8 changes: 4 additions & 4 deletions examples/audio/record_wav.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fn capture_fn(audio: &mut CaptureModel, buffer: &Buffer) {

fn key_pressed(_app: &App, model: &mut Model, key: Key) {
match key {
Key::Space => {
KeyCode::Space => {
if model.stream.is_paused() {
model.stream.play().unwrap();
} else if model.stream.is_playing() {
Expand All @@ -76,14 +76,14 @@ fn key_pressed(_app: &App, model: &mut Model, key: Key) {
}
}

fn view(app: &App, model: &Model, frame: Frame) {
frame.clear(DIMGRAY);
fn view(app: &App, model: &Model) {
draw.background().color(DIMGRAY);

if model.stream.is_playing() && app.elapsed_frames() % 30 < 20 {
let draw = app.draw();
draw.ellipse().w_h(100.0, 100.0).color(RED);

draw.to_frame(app, &frame).unwrap();

}
}

Expand Down
8 changes: 4 additions & 4 deletions examples/audio/simple_audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ fn audio(audio: &mut Audio, buffer: &mut Buffer) {
fn key_pressed(_app: &App, model: &mut Model, key: Key) {
match key {
// Pause or unpause the audio when Space is pressed.
Key::Space => {
KeyCode::Space => {
if model.stream.is_playing() {
model.stream.pause().unwrap();
} else {
model.stream.play().unwrap();
}
}
// Raise the frequency when the up key is pressed.
Key::Up => {
KeyCode::Up => {
model
.stream
.send(|audio| {
Expand All @@ -79,7 +79,7 @@ fn key_pressed(_app: &App, model: &mut Model, key: Key) {
.unwrap();
}
// Lower the frequency when the down key is pressed.
Key::Down => {
KeyCode::Down => {
model
.stream
.send(|audio| {
Expand All @@ -92,5 +92,5 @@ fn key_pressed(_app: &App, model: &mut Model, key: Key) {
}

fn view(_app: &App, _model: &Model, frame: Frame) {
frame.clear(DIMGRAY);
draw.background().color(DIMGRAY);
}
6 changes: 3 additions & 3 deletions examples/audio/simple_audio_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ fn audio(audio: &mut Audio, buffer: &mut Buffer) {
}
}

fn key_pressed(app: &App, model: &mut Model, key: Key) {
fn key_pressed(app: &App, model: &mut Model, key: KeyCode) {
match key {
// Start playing another instance of the sound.
Key::Space => {
KeyCode::Space => {
let assets = app.assets_path().expect("could not find assets directory");
let path = assets.join("sounds").join("thumbpiano.wav");
let sound = audrey::open(path).expect("failed to load sound");
Expand All @@ -87,5 +87,5 @@ fn key_pressed(app: &App, model: &mut Model, key: Key) {
}

fn view(_app: &App, _model: &Model, frame: Frame) {
frame.clear(DIMGRAY);
draw.background().color(DIMGRAY);
}
6 changes: 3 additions & 3 deletions examples/communication/osc_receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn model(app: &App) -> Model {
}
}

fn update(_app: &App, model: &mut Model, _update: Update) {
fn update(_app: &App, model: &mut Model) {
// Receive any pending osc packets.
for (packet, addr) in model.receiver.try_iter() {
model.received_packets.push((addr, packet));
Expand All @@ -48,7 +48,7 @@ fn update(_app: &App, model: &mut Model, _update: Update) {
}

// Draw the state of your `Model` into the given `Frame` here.
fn view(app: &App, model: &Model, frame: Frame) {
fn view(app: &App, model: &Model) {
let draw = app.draw();
draw.background().color(DARKBLUE);

Expand All @@ -65,5 +65,5 @@ fn view(app: &App, model: &Model, frame: Frame) {
.left_justify()
.wh(rect.wh());

draw.to_frame(app, &frame).unwrap();

}
4 changes: 2 additions & 2 deletions examples/communication/osc_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn event(_app: &App, model: &mut Model, event: WindowEvent) {
}
}

fn view(app: &App, _model: &Model, frame: Frame) {
fn view(app: &App, _model: &Model) {
let draw = app.draw();
draw.background().color(DARKRED);

Expand All @@ -77,5 +77,5 @@ fn view(app: &App, _model: &Model, frame: Frame) {
.line_spacing(10.0)
.wh(rect.wh());

draw.to_frame(app, &frame).unwrap();

}
2 changes: 1 addition & 1 deletion examples/draw/draw_blend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn view(app: &App) {
let w = app.window_rect();
let lum = map_range(app.mouse().x, w.left(), w.right(), 0.0, 1.0);
let clear = gray(lum);
// frame.clear(clear);
// draw.background().color(clear);

// Put all the provided blend modes in a list.
let blends = [
Expand Down
8 changes: 4 additions & 4 deletions examples/draw/draw_capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn main() {
nannou::sketch(view).run()
}

fn view(app: &App, frame: Frame) {
fn view(app: &App) {
let draw = app.draw();

draw.background().color(CORNFLOWERBLUE);
Expand All @@ -17,7 +17,7 @@ fn view(app: &App, frame: Frame) {
.points(win.bottom_left(), win.top_left(), win.top_right())
.color(VIOLET);

let t = frame.nth() as f32 / 60.0;
let t = app.elapsed_frames() as f32 / 60.0;
draw.ellipse()
.x_y(app.mouse().x * t.cos(), app.mouse().y)
.radius(win.w() * 0.125 * t.sin())
Expand All @@ -39,7 +39,7 @@ fn view(app: &App, frame: Frame) {
.w(app.mouse().x * 0.25)
.hsv(t, 1.0, 1.0);

draw.to_frame(app, &frame).unwrap();


// Capture the frame!
let file_path = captured_frame_path(app, &frame);
Expand All @@ -53,7 +53,7 @@ fn captured_frame_path(app: &App, frame: &Frame) -> std::path::PathBuf {
// Capture all frames to a directory called `/<path_to_nannou>/nannou/simple_capture`.
.join(app.exe_name().unwrap())
// Name each file after the number of the frame.
.join(format!("{:03}", frame.nth()))
.join(format!("{:03}", app.elapsed_frames()))
// The extension will be PNG. We also support tiff, bmp, gif, jpeg, webp and some others.
.with_extension("png")
}
2 changes: 1 addition & 1 deletion examples/draw/draw_capture_hi_res.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fn model(app: &App) -> Model {
}
}

fn update(app: &App, model: &mut Model, _update: Update) {
fn update(app: &App, model: &mut Model) {
// First, reset the `draw` state.
let draw = &model.draw;
draw.reset();
Expand Down
6 changes: 3 additions & 3 deletions examples/draw/draw_mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ fn main() {
nannou::sketch(view).run()
}

fn view(app: &App, frame: Frame) {
fn view(app: &App) {
// Begin drawing
let win = app.window_rect();
let t = app.time;
Expand Down Expand Up @@ -48,6 +48,6 @@ fn view(app: &App, frame: Frame) {
// Draw the mesh!
draw.mesh().tris_colored(tris);

// Write the result of our drawing to the window's frame.
draw.to_frame(app, &frame).unwrap();


}
Loading

0 comments on commit 92e5afb

Please sign in to comment.