Skip to content

Commit

Permalink
updated to bevy 0.15
Browse files Browse the repository at this point in the history
  • Loading branch information
Lommix committed Nov 30, 2024
1 parent 74f50a3 commit 64cd2a4
Show file tree
Hide file tree
Showing 11 changed files with 276 additions and 388 deletions.
422 changes: 135 additions & 287 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The default material allows not only for custom textures, but also sprite sheet

| bevy | bevy_enoki |
| ---: | ---------: |
| 0.15 | main |
| 0.15 | 0.3.0 |
| 0.14 | 0.2.2 |
| 0.13 | 0.1 |

Expand Down
51 changes: 49 additions & 2 deletions crates/editor/src/gui.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,57 @@
#![allow(unused)]

use bevy::prelude::*;
use bevy::{core_pipeline::bloom::Bloom, prelude::*};
use bevy_egui::egui::{self, Ui, WidgetText};
use bevy_enoki::prelude::*;
use egui_plot::{Line, PlotPoints};

use crate::{bevy_to_egui_color, egui_to_bevy_color};

pub(crate) fn scene_gui(ui: &mut Ui, camera: &mut Camera, bloom: &mut Bloom) {
egui::Grid::new("scene_setting")
.num_columns(2)
.show(ui, |ui| {
ui.label("Background");

let mut color32 = match camera.clear_color {
ClearColorConfig::Custom(color) => bevy_to_egui_color(color),
_ => bevy_to_egui_color(Color::LinearRgba(LinearRgba::GREEN)),
};
egui::color_picker::color_edit_button_srgba(
ui,
&mut color32,
egui::color_picker::Alpha::Opaque,
);
camera.clear_color = ClearColorConfig::Custom(egui_to_bevy_color(color32));

ui.end_row();
ui.label("Bloom Settings");
ui.end_row();

ui.label("Intensity");
ui.add(egui::Slider::new(&mut bloom.intensity, (0.)..=5.));
ui.end_row();

ui.label("Threshold");
ui.add(egui::Slider::new(&mut bloom.prefilter.threshold, (0.)..=1.));
ui.end_row();

ui.label("Softness");
ui.add(egui::Slider::new(
&mut bloom.prefilter.threshold_softness,
(0.)..=1.,
));
ui.end_row();

ui.label("low freq");
ui.add(egui::Slider::new(&mut bloom.low_frequency_boost, (0.)..=1.));
ui.end_row();

ui.label("high freq");
ui.add(egui::Slider::new(&mut bloom.high_pass_frequency, (0.)..=1.));
ui.end_row();
});
}

#[derive(PartialEq, Eq, Clone, Copy)]
enum Shape {
Point,
Expand Down
138 changes: 59 additions & 79 deletions crates/editor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use bevy::{
};
pub(crate) use bevy_egui::egui::{self, Color32};
use bevy_enoki::prelude::*;
// use file::FileResource;
// use wasm_bindgen::prelude::wasm_bindgen;

// mod bindings;
// mod file;
Expand Down Expand Up @@ -42,7 +40,7 @@ fn zoom(mut camera: Query<&mut Transform, With<Camera>>, mut events: EventReader
})
}

fn setup(mut cmd: Commands) {
fn setup(mut cmd: Commands, mut particle_materials: ResMut<Assets<ColorParticle2dMaterial>>) {
cmd.spawn((
Camera2d,
Camera {
Expand All @@ -56,6 +54,11 @@ fn setup(mut cmd: Commands) {
..default()
},
));

cmd.spawn((
ParticleSpawner(particle_materials.add(ColorParticle2dMaterial::default())),
Transform::from_xyz(-100., 0., 0.),
));
}

fn gui(
Expand All @@ -74,84 +77,61 @@ fn gui(
return;
};

egui::Window::new("Particle Config")
.scroll([false, true])
.show(context.ctx_mut(), |ui| {
// file::file_panel(ui, &mut effect_instance, &mut file);
egui::Grid::new("one_shot")
.spacing([4., 4.])
.num_columns(2)
.min_col_width(100.)
.show(ui, |ui| {
if ui.checkbox(&mut one_shot_mode, "One Shot").changed() {
if *one_shot_mode {
cmd.entity(entity).insert(OneShot::Deactivate);
} else {
cmd.entity(entity).remove::<OneShot>();
let central = egui::CentralPanel::default().frame(egui::Frame { ..default() });

central.show(context.ctx_mut(), |ui| {
egui::TopBottomPanel::top("Enoki particle editor").show_inside(ui, |ui| {
ui.horizontal(|ui| {
ui.style_mut().spacing.item_spacing = [4., 4.].into();
ui.label("Enoki Editor");

if ui.button("export effect").clicked() {
info!("exporting!");
}

if ui.button("import effect").clicked() {
info!("importing!");
}

if ui.button("select shader").clicked() {
info!("importing!");
}
});
});

egui::SidePanel::right("Config").show_inside(ui, |ui| {
egui::scroll_area::ScrollArea::new([false, true]).show(ui, |ui| {
egui::Grid::new("one_shot")
.spacing([4., 4.])
.num_columns(2)
.min_col_width(100.)
.show(ui, |ui| {
if ui.checkbox(&mut one_shot_mode, "One Shot").changed() {
if *one_shot_mode {
cmd.entity(entity).insert(OneShot::Deactivate);
} else {
cmd.entity(entity).remove::<OneShot>();
}
}

if ui
.add_sized([100., 30.], egui::Button::new("Spawn Once"))
.clicked()
{
state.active = true;
}
}

if ui
.add_sized([100., 30.], egui::Button::new("Spawn Once"))
.clicked()
{
state.active = true;
}
});

if let Ok((mut camera, mut bloom)) = camera_query.get_single_mut() {
ui.collapsing("Scene Setting", |ui| {
egui::Grid::new("scene_setting")
.num_columns(2)
.show(ui, |ui| {
ui.label("Background");

let mut color32 = match camera.clear_color {
ClearColorConfig::Custom(color) => bevy_to_egui_color(color),
_ => bevy_to_egui_color(Color::LinearRgba(LinearRgba::GREEN)),
};
egui::color_picker::color_edit_button_srgba(
ui,
&mut color32,
egui::color_picker::Alpha::Opaque,
);
camera.clear_color =
ClearColorConfig::Custom(egui_to_bevy_color(color32));

ui.end_row();
ui.label("Bloom Settings");
ui.end_row();

ui.label("Intensity");
ui.add(egui::Slider::new(&mut bloom.intensity, (0.)..=5.));
ui.end_row();

ui.label("Threshold");
ui.add(egui::Slider::new(&mut bloom.prefilter.threshold, (0.)..=1.));
ui.end_row();

ui.label("Softness");
ui.add(egui::Slider::new(
&mut bloom.prefilter.threshold_softness,
(0.)..=1.,
));
ui.end_row();

ui.label("low freq");
ui.add(egui::Slider::new(&mut bloom.low_frequency_boost, (0.)..=1.));
ui.end_row();

ui.label("high freq");
ui.add(egui::Slider::new(&mut bloom.high_pass_frequency, (0.)..=1.));
ui.end_row();
});
});
}

if let Some(effect) = effect_instance.0.as_mut() {
gui::config_gui(ui, effect, &mut state);
}
});

if let Ok((mut camera, mut bloom)) = camera_query.get_single_mut() {
gui::scene_gui(ui, &mut camera, &mut bloom);
}

if let Some(effect) = effect_instance.0.as_mut() {
gui::config_gui(ui, effect, &mut state);
}
});
});
});
}

pub(crate) fn bevy_to_egui_color(color: Color) -> Color32 {
Expand Down
19 changes: 10 additions & 9 deletions crates/enoki2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ description = "2D Particle system plugin, that works well on wasm and mobile"
keywords = ["bevy", "particles", "shader", "2d", "particle"]
repository = "https://github.com/Lommix/bevy_enoki"
license = "MIT"
readme = "README.md"

[profile.dev]
opt-level = 1
Expand All @@ -16,18 +17,18 @@ opt-level = 3

[features]
dev = [
"bevy/file_watcher",
"bevy/dynamic_linking",
"bevy/multi_threaded",
"bevy/embedded_watcher",
"bevy/file_watcher",
"bevy/dynamic_linking",
"bevy/multi_threaded",
"bevy/embedded_watcher",
]

[dependencies]
bevy = { version = "0.15.0-rc.3", default-features = false, features = [
"bevy_core_pipeline",
"bevy_asset",
"bevy_sprite",
"png",
bevy = { version = "0.15", default-features = false, features = [
"bevy_core_pipeline",
"bevy_asset",
"bevy_sprite",
"png",
] }
serde = { version = "1.0.197", features = ["derive"] }
interpolation = "0.3.0"
Expand Down
7 changes: 6 additions & 1 deletion crates/enoki2d/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![allow(rustdoc::redundant_explicit_links)]
#![doc = include_str!("../../../README.md")]

use self::prelude::{
Particle2dMaterial, ParticleEffectInstance, ParticleSpawnerState, ParticleStore,
};
Expand Down Expand Up @@ -33,7 +37,8 @@ pub mod prelude {
pub use super::update::{OneShot, ParticleEffectInstance, ParticleSpawnerState, ParticleStore};
pub use super::values::{Random, Rval};
pub use super::{
EmissionShape, NoAutoAabb, Particle2dEffect, ParticleEffectHandle, ParticleSpawner,
EmissionShape, EnokiPlugin, NoAutoAabb, Particle2dEffect, ParticleEffectHandle,
ParticleSpawner,
};
}

Expand Down
3 changes: 2 additions & 1 deletion crates/enoki2d/src/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use bevy::{
},
renderer::{RenderDevice, RenderQueue},
sync_world::RenderEntity,
texture::BevyDefault,
view::{
ExtractedView, RenderVisibleEntities, ViewTarget, ViewUniform, ViewUniformOffset,
ViewUniforms,
Expand Down Expand Up @@ -457,7 +456,9 @@ impl<M: Particle2dMaterial> SpecializedRenderPipeline for Particle2dPipeline<M>
} else {
TextureFormat::bevy_default()
};

RenderPipelineDescriptor {
zero_initialize_workgroup_memory: true,
vertex: bevy::render::render_resource::VertexState {
shader: self.vertex_shader.clone(),
shader_defs: vec![],
Expand Down
2 changes: 1 addition & 1 deletion example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
bevy = "0.15.0-rc.3"
bevy = "0.15"
bevy_enoki = { path = "../crates/enoki2d" }
rand = "0.8.5"

Expand Down
7 changes: 5 additions & 2 deletions example/src/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
/// dynamic example
/// how to update effect behavior dynamiclly
/// ----------------------------------------------
use bevy::{core_pipeline::bloom::Bloom, diagnostic::DiagnosticsStore, prelude::*};
use bevy::{
core_pipeline::bloom::Bloom, diagnostic::DiagnosticsStore, image::ImageSamplerDescriptor,
prelude::*,
};
use bevy_enoki::{prelude::*, EnokiPlugin};
use std::time::Duration;

fn main() {
App::new()
.add_plugins(DefaultPlugins.set(ImagePlugin {
default_sampler: bevy::render::texture::ImageSamplerDescriptor::nearest(),
default_sampler: ImageSamplerDescriptor::nearest(),
}))
.add_plugins(bevy::diagnostic::FrameTimeDiagnosticsPlugin)
.add_plugins(EnokiPlugin)
Expand Down
6 changes: 3 additions & 3 deletions example/src/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
/// how to add a custom material
/// ----------------------------------------------
use bevy::{
core_pipeline::bloom::Bloom, diagnostic::DiagnosticsStore, prelude::*,
render::render_resource::AsBindGroup,
core_pipeline::bloom::Bloom, diagnostic::DiagnosticsStore, image::ImageSamplerDescriptor,
prelude::*, render::render_resource::AsBindGroup,
};
use bevy_enoki::{prelude::*, EnokiPlugin};

fn main() {
App::new()
.add_plugins(DefaultPlugins.set(ImagePlugin {
default_sampler: bevy::render::texture::ImageSamplerDescriptor::nearest(),
default_sampler: ImageSamplerDescriptor::nearest(),
}))
.add_plugins(bevy::diagnostic::FrameTimeDiagnosticsPlugin)
.add_plugins(EnokiPlugin)
Expand Down
7 changes: 5 additions & 2 deletions example/src/sprites.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
/// sprite example
/// how to display a sprite animation/texture
/// ----------------------------------------------
use bevy::{core_pipeline::bloom::Bloom, diagnostic::DiagnosticsStore, prelude::*};
use bevy::{
core_pipeline::bloom::Bloom, diagnostic::DiagnosticsStore, image::ImageSamplerDescriptor,
prelude::*,
};
use bevy_enoki::{prelude::*, EnokiPlugin};
use std::time::Duration;

fn main() {
App::new()
.add_plugins(DefaultPlugins.set(ImagePlugin {
default_sampler: bevy::render::texture::ImageSamplerDescriptor::nearest(),
default_sampler: ImageSamplerDescriptor::nearest(),
}))
.add_plugins(bevy::diagnostic::FrameTimeDiagnosticsPlugin)
.add_plugins(EnokiPlugin)
Expand Down

0 comments on commit 64cd2a4

Please sign in to comment.