Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Bevy v0.13 #21

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.toml
Expand Up @@ -16,18 +16,18 @@ categories = ["game-development"]
itertools = "0.11"

[dependencies.polyanya]
version = "0.4"
version = "0.5"

[dependencies.bevy]
version = "0.12"
version = "0.13"
features = ["bevy_render", "bevy_asset"]
default-features = false

[dev-dependencies]
rand = "0.8"

[dev-dependencies.bevy]
version = "0.12"
version = "0.13"
features = [
"bevy_ui",
"bevy_text",
Expand Down
39 changes: 19 additions & 20 deletions examples/gltf.rs
@@ -1,7 +1,7 @@
use bevy::{
asset::LoadState,
gltf::{Gltf, GltfMesh},
math::Vec3Swizzles,
math::{primitives::Sphere, Vec3Swizzles},
pbr::NotShadowCaster,
prelude::*,
window::PrimaryWindow,
Expand All @@ -20,14 +20,14 @@ fn main() {
DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: "Navmesh with Polyanya".to_string(),
fit_canvas_to_parent: true,
canvas: Some("canvas { width: 100%; height: 100%; }".to_string()),
..default()
}),
..default()
}),
PathMeshPlugin,
))
.add_state::<AppState>()
.init_state::<AppState>()
.add_systems(OnEnter(AppState::Setup), setup)
.add_systems(Update, check_textures.run_if(in_state(AppState::Setup)))
.add_systems(OnExit(AppState::Setup), setup_scene)
Expand Down Expand Up @@ -64,7 +64,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {

commands.insert_resource(AmbientLight {
color: Color::SEA_GREEN,
brightness: 0.05,
brightness: 400.0,
});

commands.spawn(Camera3dBundle {
Expand Down Expand Up @@ -197,7 +197,7 @@ fn setup_scene(
commands.spawn((
SpotLightBundle {
spot_light: SpotLight {
intensity: 800.0,
intensity: 1000000.0,
color: Color::SEA_GREEN,
shadows_enabled: true,
inner_angle: 0.5,
Expand Down Expand Up @@ -254,8 +254,8 @@ fn setup_scene(
commands
.spawn((
PbrBundle {
mesh: meshes.add(Mesh::from(shape::Capsule { ..default() })),
material: materials.add(Color::BLUE.into()),
mesh: meshes.add(Mesh::from(Capsule3d { ..default() })),
material: materials.add(StandardMaterial::from(Color::BLUE)),
transform: Transform::from_xyz(-1.0, 0.0, -2.0),
..Default::default()
},
Expand All @@ -267,7 +267,7 @@ fn setup_scene(
point_light: PointLight {
color: Color::BLUE,
range: 500.0,
intensity: 2000.0,
intensity: 100000.0,
shadows_enabled: true,
..default()
},
Expand Down Expand Up @@ -309,11 +309,10 @@ fn give_target_auto(
let target_id = commands
.spawn((
PbrBundle {
mesh: meshes.add(Mesh::from(shape::UVSphere {
mesh: meshes.add(Mesh::from(Sphere {
radius: 0.5,
..default()
})),
material: materials.add(Color::RED.into()),
material: materials.add(StandardMaterial::from(Color::RED)),
transform: Transform::from_xyz(x, 0.0, z),
..Default::default()
},
Expand All @@ -334,14 +333,15 @@ fn give_target_auto(
})
.id();
commands.entity(entity).insert(Path {
current: first.clone(),
current: *first,
next: remaining,
});
object.0 = Some(target_id);
}
}
}

#[allow(clippy::too_many_arguments)]
fn give_target_on_click(
mut commands: Commands,
mut object_query: Query<(Entity, &Transform, &mut Object)>,
Expand All @@ -350,7 +350,7 @@ fn give_target_on_click(
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
current_mesh: Res<CurrentMesh>,
mouse_buttons: Res<Input<MouseButton>>,
mouse_buttons: Res<ButtonInput<MouseButton>>,
primary_window: Query<&Window, With<PrimaryWindow>>,
camera: Query<(&Camera, &GlobalTransform)>,
) {
Expand All @@ -360,7 +360,7 @@ fn give_target_on_click(
let position = primary_window.single().cursor_position()?;
let (camera, transform) = camera.get_single().ok()?;
let ray = camera.viewport_to_world(transform, position)?;
let denom = Vec3::Y.dot(ray.direction);
let denom = Vec3::Y.dot(*ray.direction);
let t = (Vec3::ZERO - ray.origin).dot(Vec3::Y) / denom;
let target = ray.origin + ray.direction * t;
navmesh.transformed_is_in_mesh(target).then_some(target)
Expand All @@ -378,11 +378,10 @@ fn give_target_on_click(
let target_id = commands
.spawn((
PbrBundle {
mesh: meshes.add(Mesh::from(shape::UVSphere {
mesh: meshes.add(Mesh::from(Sphere {
radius: 0.5,
..default()
})),
material: materials.add(Color::RED.into()),
material: materials.add(StandardMaterial::from(Color::RED)),
transform: Transform::from_translation(target),
..Default::default()
},
Expand All @@ -403,7 +402,7 @@ fn give_target_on_click(
})
.id();
commands.entity(entity).insert(Path {
current: first.clone(),
current: *first,
next: remaining,
});
object.0 = Some(target_id);
Expand Down Expand Up @@ -437,7 +436,7 @@ fn move_object(

fn trigger_navmesh_visibility(
mut query: Query<(&mut Visibility, &NavMeshDisp)>,
keyboard_input: ResMut<Input<KeyCode>>,
keyboard_input: ResMut<ButtonInput<KeyCode>>,
current_mesh: Res<CurrentMesh>,
) {
if keyboard_input.just_pressed(KeyCode::Space) {
Expand All @@ -460,7 +459,7 @@ fn target_activity(
) {
for children in &target {
point_light.get_mut(children[0]).unwrap().intensity =
(time.elapsed_seconds() * 10.0).sin().abs() * 100.0;
(time.elapsed_seconds() * 10.0).sin().abs() * 100000.0;
}
}

Expand Down
7 changes: 4 additions & 3 deletions examples/lines.rs
Expand Up @@ -12,7 +12,7 @@ fn main() {
DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: "Navmesh with Polyanya".to_string(),
fit_canvas_to_parent: true,
canvas: Some("canvas { width: 100%; height: 100%; }".to_string()),
..default()
}),
..default()
Expand Down Expand Up @@ -123,6 +123,7 @@ struct PathToDisplay {
steps: Vec<Vec2>,
}

#[allow(clippy::too_many_arguments)]
fn on_mesh_change(
mut path_to_display: ResMut<PathToDisplay>,
mesh: Res<MeshDetails>,
Expand Down Expand Up @@ -224,7 +225,7 @@ fn on_mesh_change(
});
}

fn mesh_change(mut mesh: ResMut<MeshDetails>, keyboard_input: Res<Input<KeyCode>>) {
fn mesh_change(mut mesh: ResMut<MeshDetails>, keyboard_input: Res<ButtonInput<KeyCode>>) {
if keyboard_input.just_pressed(KeyCode::Space) {
match mesh.mesh {
CurrentMesh::Simple => *mesh = ARENA,
Expand All @@ -239,7 +240,7 @@ struct NewPathStepEvent(Vec2);

fn on_click(
mut path_step_event: EventWriter<NewPathStepEvent>,
mouse_button_input: Res<Input<MouseButton>>,
mouse_button_input: Res<ButtonInput<MouseButton>>,
primary_window: Query<&Window, With<PrimaryWindow>>,
camera_q: Query<(&Camera, &GlobalTransform)>,
mesh: Res<MeshDetails>,
Expand Down
25 changes: 12 additions & 13 deletions examples/many.rs
Expand Up @@ -26,7 +26,7 @@ fn main() {
.set(WindowPlugin {
primary_window: Some(Window {
title: "Navmesh with Polyanya".to_string(),
fit_canvas_to_parent: true,
canvas: Some("canvas { width: 100%; height: 100%; }".to_string()),
present_mode: PresentMode::AutoNoVsync,
..default()
}),
Expand All @@ -43,7 +43,7 @@ fn main() {
..default()
},
}),
FrameTimeDiagnosticsPlugin::default(),
FrameTimeDiagnosticsPlugin,
LogDiagnosticsPlugin::default(),
PathMeshPlugin,
))
Expand Down Expand Up @@ -205,6 +205,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
});
}

#[allow(clippy::too_many_arguments)]
fn on_mesh_change(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
Expand Down Expand Up @@ -470,6 +471,7 @@ fn display_path(
}
}

#[allow(clippy::type_complexity)]
fn go_somewhere(
query: Query<
Entity,
Expand All @@ -488,7 +490,7 @@ fn go_somewhere(
rng.gen_range(0.0..MESH_SIZE.x),
rng.gen_range(0.0..MESH_SIZE.y),
);
commands.entity(navigator).insert(Target { target: target });
commands.entity(navigator).insert(Target { target });
}
}

Expand All @@ -507,7 +509,7 @@ fn update_ui(
text.sections[3].value = format!(
"{:.2}\n",
diagnostics
.get(FrameTimeDiagnosticsPlugin::FPS)
.get(&FrameTimeDiagnosticsPlugin::FPS)
.and_then(|d| d.average())
.unwrap_or_default()
);
Expand All @@ -526,18 +528,15 @@ fn update_ui(
)
);
text.sections[9].value = format!("{:?}\n", *task_mode);
text.sections[11].value = format!(
"{}",
match *display_mode {
DisplayMode::Line => "hide lines",
DisplayMode::Nothing => "display lines",
}
);
text.sections[11].value = match *display_mode {
DisplayMode::Line => "hide lines",
DisplayMode::Nothing => "display lines",
}.to_string();
*count = new_count;
}

fn mode_change(
keyboard_input: Res<Input<KeyCode>>,
keyboard_input: Res<ButtonInput<KeyCode>>,
mut task_mode: ResMut<TaskMode>,
mut display_mode: ResMut<DisplayMode>,
) {
Expand All @@ -547,7 +546,7 @@ fn mode_change(
TaskMode::Blocking => *task_mode = TaskMode::Async,
}
}
if keyboard_input.just_pressed(KeyCode::L) {
if keyboard_input.just_pressed(KeyCode::KeyL) {
match *display_mode {
DisplayMode::Line => *display_mode = DisplayMode::Nothing,
DisplayMode::Nothing => *display_mode = DisplayMode::Line,
Expand Down
10 changes: 6 additions & 4 deletions examples/moving.rs
Expand Up @@ -20,7 +20,7 @@ fn main() {
DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: "Navmesh with Polyanya".to_string(),
fit_canvas_to_parent: true,
canvas: Some("canvas { width: 100%; height: 100%; }".to_string()),
..default()
}),
..default()
Expand Down Expand Up @@ -126,6 +126,7 @@ fn setup(
commands.insert_resource(AURORA);
}

#[allow(clippy::too_many_arguments)]
fn on_mesh_change(
mesh: Res<MeshDetails>,
mut commands: Commands,
Expand Down Expand Up @@ -226,8 +227,8 @@ fn on_mesh_change(

fn mesh_change(
mut mesh: ResMut<MeshDetails>,
keyboard_input: Res<Input<KeyCode>>,
mouse_input: Res<Input<MouseButton>>,
keyboard_input: Res<ButtonInput<KeyCode>>,
mouse_input: Res<ButtonInput<MouseButton>>,
time: Res<Time>,
mut pressed_since: Local<Option<Duration>>,
) {
Expand Down Expand Up @@ -269,8 +270,9 @@ struct Path {
path: Vec<Vec2>,
}

#[allow(clippy::too_many_arguments)]
fn on_click(
mouse_button_input: Res<Input<MouseButton>>,
mouse_button_input: Res<ButtonInput<MouseButton>>,
primary_window: Query<&Window, With<PrimaryWindow>>,
camera_q: Query<(&Camera, &GlobalTransform)>,
mesh: Res<MeshDetails>,
Expand Down
13 changes: 7 additions & 6 deletions src/lib.rs
Expand Up @@ -16,6 +16,7 @@ use std::sync::Arc;
use bevy::math::Vec3Swizzles;
use bevy::reflect::TypePath;
use bevy::render::mesh::{MeshVertexAttributeId, VertexAttributeValues};
use bevy::render::render_asset::RenderAssetUsages;
use bevy::{
prelude::*,
render::{mesh::Indices, render_resource::PrimitiveTopology},
Expand Down Expand Up @@ -183,7 +184,7 @@ impl PathMesh {

/// Creates a [`Mesh`] from this [`PathMesh`], suitable for rendering the surface
pub fn to_mesh(&self) -> Mesh {
let mut new_mesh = Mesh::new(PrimitiveTopology::TriangleList);
let mut new_mesh = Mesh::new(PrimitiveTopology::TriangleList, RenderAssetUsages::all());
let inverse_transform = self.inverse_transform();
new_mesh.insert_attribute(
Mesh::ATTRIBUTE_POSITION,
Expand All @@ -194,7 +195,7 @@ impl PathMesh {
.map(|coords| inverse_transform.transform_point(coords.into()).into())
.collect::<Vec<[f32; 3]>>(),
);
new_mesh.set_indices(Some(Indices::U32(
new_mesh.insert_indices(Indices::U32(
self.mesh
.polygons
.iter()
Expand All @@ -203,13 +204,13 @@ impl PathMesh {
.flat_map(|i| [p.vertices[0], p.vertices[i - 1], p.vertices[i]])
})
.collect(),
)));
));
new_mesh
}

/// Creates a [`Mesh`] from this [`PathMesh`], showing the wireframe of the polygons
pub fn to_wireframe_mesh(&self) -> Mesh {
let mut new_mesh = Mesh::new(PrimitiveTopology::LineList);
let mut new_mesh = Mesh::new(PrimitiveTopology::LineList, RenderAssetUsages::all());
let inverse_transform = self.inverse_transform();
new_mesh.insert_attribute(
Mesh::ATTRIBUTE_POSITION,
Expand All @@ -220,7 +221,7 @@ impl PathMesh {
.map(|coords| inverse_transform.transform_point(coords.into()).into())
.collect::<Vec<[f32; 3]>>(),
);
new_mesh.set_indices(Some(Indices::U32(
new_mesh.insert_indices(Indices::U32(
self.mesh
.polygons
.iter()
Expand All @@ -231,7 +232,7 @@ impl PathMesh {
.unique_by(|[a, b]| if a < b { (*a, *b) } else { (*b, *a) })
.flatten()
.collect(),
)));
));
new_mesh
}

Expand Down