Skip to content

Commit

Permalink
rebranding (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
mockersf committed Mar 9, 2024
1 parent e62b6a4 commit e824cee
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 119 deletions.
14 changes: 7 additions & 7 deletions Cargo.toml
@@ -1,15 +1,15 @@
[package]
name = "bevy_pathmesh"
version = "0.6.0"
authors = ["François Mockers <mockersf@gmail.com>"]
name = "vleue_navigator"
version = "0.7.0"
authors = ["François Mockers <francois.mockers@vleue.com>"]
edition = "2021"
license = "MIT OR Apache-2.0"
keywords = ["pathfinding", "bevy", "navmesh"]
keywords = ["pathfinding", "bevy", "navmesh", "navigation"]
readme = "README.md"
description = "Navmesh plugin for Bevy"
repository = "https://github.com/vleue/bevy_pathmesh"
homepage = "https://github.com/vleue/bevy_pathmesh"
documentation = "https://docs.rs/bevy_pathmesh"
repository = "https://github.com/vleue/vleue_navigator"
homepage = "https://github.com/vleue/vleue_navigator"
documentation = "https://docs.rs/vleue_navigator"
categories = ["game-development"]

[dependencies]
Expand Down
30 changes: 13 additions & 17 deletions README.md
@@ -1,40 +1,38 @@
# NavMesh for Bevy
# Navigation for Bevy with NavMesh

![MIT/Apache 2.0](https://img.shields.io/badge/license-MIT%2FApache-blue.svg)
[![Release Doc](https://docs.rs/bevy_pathmesh/badge.svg)](https://docs.rs/bevy_pathmesh)
[![Crate](https://img.shields.io/crates/v/bevy_pathmesh.svg)](https://crates.io/crates/bevy_pathmesh)

> :warning: **This crate has been renamed to [vleue_navigator](https://github.com/vleue/vleue_navigator)**. For updates and continued support, change your dependency!
[![Release Doc](https://docs.rs/vleue_navigator/badge.svg)](https://docs.rs/vleue_navigator)
[![Crate](https://img.shields.io/crates/v/vleue_navigator.svg)](https://crates.io/crates/vleue_navigator)

Navigation mesh for [Bevy](http://github.com/bevyengine/bevy) using [Polyanya](https://github.com/vleue/polyanya).

![map with many points finding their paths](https://raw.githubusercontent.com/vleue/bevy_pathmesh/main/screenshots/many.png)
![map with many points finding their paths](https://raw.githubusercontent.com/vleue/vleue_navigator/main/screenshots/many.png)

Check out the [WASM demo](https://vleue.github.io/vleue_navigator/)

## Usage

Loading a mesh from a gLTF file, then building a `PathMesh` from it and using it for getting paths between random points.
Loading a mesh from a gLTF file, then building a `NavMesh` from it and using it for getting paths between random points.

```rust,no_run
use bevy::{
gltf::{Gltf, GltfMesh},
prelude::*,
};
use bevy_pathmesh::{PathMesh, PathMeshPlugin};
use vleue_navigator::{NavMesh, VleueNavigatorPlugin};
use rand::Rng;
fn main() {
App::new()
.add_plugins((DefaultPlugins, PathMeshPlugin))
.add_plugins((DefaultPlugins, VleueNavigatorPlugin))
.add_systems(Startup, load)
.add_systems(Update, get_path)
.run()
}
#[derive(Resource)]
struct Handles(Handle<Gltf>, Option<Handle<PathMesh>>);
struct Handles(Handle<Gltf>, Option<Handle<NavMesh>>);
fn load(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.insert_resource(Handles(asset_server.load("navmesh.glb"), None));
Expand All @@ -45,7 +43,7 @@ fn get_path(
gltfs: Res<Assets<Gltf>>,
gltf_meshes: Res<Assets<GltfMesh>>,
meshes: Res<Assets<Mesh>>,
mut path_meshes: ResMut<Assets<PathMesh>>,
mut path_meshes: ResMut<Assets<NavMesh>>,
) {
if handles.1.is_none() {
// Get the gltf struct loaded from the file
Expand All @@ -60,8 +58,8 @@ fn get_path(
let Some(mesh) = meshes.get(&gltf_mesh.primitives[0].mesh) else {
return
};
// Build a `PathMesh` from that mesh, then save it as an asset
handles.1 = Some(path_meshes.add(PathMesh::from_bevy_mesh(mesh)));
// Build a `NavMesh` from that mesh, then save it as an asset
handles.1 = Some(path_meshes.add(NavMesh::from_bevy_mesh(mesh)));
} else {
// Get the path mesh, then search for a path
let Some(path_mesh) = path_meshes.get(handles.1.as_ref().unwrap()) else {
Expand All @@ -85,8 +83,6 @@ fn get_path(
}
```

|Bevy|bevy_pathmesh|
|Bevy|vleue_navigator|
|---|---|
|0.13|0.6|
|0.11|0.5|
|0.10|0.4|
|0.13|0.7|
20 changes: 10 additions & 10 deletions examples/gltf.rs
Expand Up @@ -6,11 +6,11 @@ use bevy::{
prelude::*,
window::PrimaryWindow,
};
use bevy_pathmesh::{PathMesh, PathMeshPlugin};
use rand::Rng;
use std::f32::consts::FRAC_PI_2;
use vleue_navigator::{NavMesh, VleueNavigatorPlugin};

const HANDLE_TRIMESH_OPTIMIZED: Handle<PathMesh> = Handle::weak_from_u128(0);
const HANDLE_TRIMESH_OPTIMIZED: Handle<NavMesh> = Handle::weak_from_u128(0);

fn main() {
App::new()
Expand All @@ -24,7 +24,7 @@ fn main() {
}),
..default()
}),
PathMeshPlugin,
VleueNavigatorPlugin,
))
.init_state::<AppState>()
.add_systems(OnEnter(AppState::Setup), setup)
Expand Down Expand Up @@ -56,7 +56,7 @@ enum AppState {
struct GltfHandle(Handle<Gltf>);

#[derive(Resource)]
struct CurrentMesh(Handle<PathMesh>);
struct CurrentMesh(Handle<NavMesh>);

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.insert_resource(GltfHandle(asset_server.load("meshes/navmesh.glb")));
Expand Down Expand Up @@ -153,7 +153,7 @@ struct Target;
struct Hover(Vec2);

#[derive(Component, Clone)]
struct NavMeshDisp(Handle<PathMesh>);
struct NavMeshDisp(Handle<NavMesh>);

fn setup_scene(
mut commands: Commands,
Expand All @@ -162,7 +162,7 @@ fn setup_scene(
gltf_meshes: Res<Assets<GltfMesh>>,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
mut pathmeshes: ResMut<Assets<PathMesh>>,
mut navmeshes: ResMut<Assets<NavMesh>>,
) {
let mut material: StandardMaterial = Color::ALICE_BLUE.into();
material.perceptual_roughness = 1.0;
Expand Down Expand Up @@ -222,7 +222,7 @@ fn setup_scene(

if let Some(gltf) = gltfs.get(gltf.id()) {
{
let navmesh = bevy_pathmesh::PathMesh::from_bevy_mesh(
let navmesh = vleue_navigator::NavMesh::from_bevy_mesh(
meshes
.get(
&gltf_meshes
Expand All @@ -247,7 +247,7 @@ fn setup_scene(
},
NavMeshDisp(HANDLE_TRIMESH_OPTIMIZED),
));
pathmeshes.insert(HANDLE_TRIMESH_OPTIMIZED, navmesh);
navmeshes.insert(HANDLE_TRIMESH_OPTIMIZED, navmesh);
}

commands
Expand Down Expand Up @@ -284,7 +284,7 @@ fn setup_scene(
fn give_target_auto(
mut commands: Commands,
mut object_query: Query<(Entity, &Transform, &mut Object), Without<Path>>,
navmeshes: Res<Assets<PathMesh>>,
navmeshes: Res<Assets<NavMesh>>,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
current_mesh: Res<CurrentMesh>,
Expand Down Expand Up @@ -353,7 +353,7 @@ fn give_target_on_click(
mut commands: Commands,
mut object_query: Query<(Entity, &Transform, &mut Object)>,
targets: Query<Entity, With<Target>>,
navmeshes: Res<Assets<PathMesh>>,
navmeshes: Res<Assets<NavMesh>>,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
current_mesh: Res<CurrentMesh>,
Expand Down
30 changes: 15 additions & 15 deletions examples/lines.rs
Expand Up @@ -3,7 +3,7 @@ use bevy::{
sprite::MaterialMesh2dBundle,
window::{PrimaryWindow, WindowResized},
};
use bevy_pathmesh::{PathMesh, PathMeshPlugin};
use vleue_navigator::{NavMesh, VleueNavigatorPlugin};

fn main() {
App::new()
Expand All @@ -16,7 +16,7 @@ fn main() {
}),
..default()
}),
PathMeshPlugin,
VleueNavigatorPlugin,
))
.add_event::<NewPathStepEvent>()
.insert_resource(PathToDisplay::default())
Expand All @@ -36,9 +36,9 @@ fn main() {

#[derive(Resource)]
struct Meshes {
simple: Handle<PathMesh>,
arena: Handle<PathMesh>,
aurora: Handle<PathMesh>,
simple: Handle<NavMesh>,
arena: Handle<NavMesh>,
aurora: Handle<NavMesh>,
}

enum CurrentMesh {
Expand Down Expand Up @@ -70,12 +70,12 @@ const AURORA: MeshDetails = MeshDetails {

fn setup(
mut commands: Commands,
mut pathmeshes: ResMut<Assets<PathMesh>>,
mut navmeshes: ResMut<Assets<NavMesh>>,
asset_server: Res<AssetServer>,
) {
commands.spawn(Camera2dBundle::default());
commands.insert_resource(Meshes {
simple: pathmeshes.add(PathMesh::from_polyanya_mesh(polyanya::Mesh::new(
simple: navmeshes.add(NavMesh::from_polyanya_mesh(polyanya::Mesh::new(
vec![
polyanya::Vertex::new(Vec2::new(0., 6.), vec![0, -1]),
polyanya::Vertex::new(Vec2::new(2., 5.), vec![0, -1, 2]),
Expand Down Expand Up @@ -127,7 +127,7 @@ fn on_mesh_change(
mesh: Res<MeshDetails>,
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
pathmeshes: Res<Assets<PathMesh>>,
navmeshes: Res<Assets<NavMesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
path_meshes: Res<Meshes>,
mut current_mesh_entity: Local<Option<Entity>>,
Expand All @@ -145,7 +145,7 @@ fn on_mesh_change(
CurrentMesh::Arena => &path_meshes.arena,
CurrentMesh::Aurora => &path_meshes.aurora,
};
let pathmesh = pathmeshes.get(handle).unwrap();
let navmesh = navmeshes.get(handle).unwrap();
if let Some(entity) = *current_mesh_entity {
commands.entity(entity).despawn_recursive();
}
Expand All @@ -155,7 +155,7 @@ fn on_mesh_change(
*current_mesh_entity = Some(
commands
.spawn(MaterialMesh2dBundle {
mesh: meshes.add(pathmesh.to_mesh()).into(),
mesh: meshes.add(navmesh.to_mesh()).into(),
transform: Transform::from_translation(Vec3::new(
-mesh.size.x / 2.0 * factor,
-mesh.size.y / 2.0 * factor,
Expand All @@ -167,7 +167,7 @@ fn on_mesh_change(
})
.with_children(|main_mesh| {
main_mesh.spawn(MaterialMesh2dBundle {
mesh: meshes.add(pathmesh.to_wireframe_mesh()).into(),
mesh: meshes.add(navmesh.to_wireframe_mesh()).into(),
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 0.1)),
material: materials.add(ColorMaterial::from(Color::rgb(0.5, 0.5, 1.0))),
..default()
Expand Down Expand Up @@ -243,7 +243,7 @@ fn on_click(
camera_q: Query<(&Camera, &GlobalTransform)>,
mesh: Res<MeshDetails>,
meshes: Res<Meshes>,
pathmeshes: Res<Assets<PathMesh>>,
navmeshes: Res<Assets<NavMesh>>,
) {
if mouse_button_input.just_pressed(MouseButton::Left) {
let (camera, camera_transform) = camera_q.single();
Expand All @@ -257,7 +257,7 @@ fn on_click(
let factor = (screen.x / mesh.size.x).min(screen.y / mesh.size.y);

let in_mesh = position / factor + mesh.size / 2.0;
if pathmeshes
if navmeshes
.get(match mesh.mesh {
CurrentMesh::Simple => &meshes.simple,
CurrentMesh::Arena => &meshes.arena,
Expand All @@ -280,15 +280,15 @@ fn compute_paths(
mut path_to_display: ResMut<PathToDisplay>,
mesh: Res<MeshDetails>,
meshes: Res<Meshes>,
pathmeshes: Res<Assets<PathMesh>>,
navmeshes: Res<Assets<NavMesh>>,
) {
for ev in event_new_step_path.read() {
if path_to_display.steps.is_empty() {
path_to_display.steps.push(ev.0);
return;
}

let path_mesh = pathmeshes
let path_mesh = navmeshes
.get(match mesh.mesh {
CurrentMesh::Simple => &meshes.simple,
CurrentMesh::Arena => &meshes.arena,
Expand Down

0 comments on commit e824cee

Please sign in to comment.