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

Interactive branch on bevy 0.13 #24

Open
wants to merge 22 commits into
base: interactive
Choose a base branch
from
Open
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
14 changes: 10 additions & 4 deletions .github/workflows/deploy.yml
Expand Up @@ -31,18 +31,24 @@ jobs:

- name: Build
run: |
cargo build --target wasm32-unknown-unknown --release --example moving
cargo build --target wasm32-unknown-unknown --release --example moving --features bevy/webgl2
wasm-bindgen --no-typescript --out-dir wasm --target web target/wasm32-unknown-unknown/release/examples/moving.wasm

cargo build --target wasm32-unknown-unknown --release --example lines
cargo build --target wasm32-unknown-unknown --release --example lines --features bevy/webgl2
wasm-bindgen --no-typescript --out-dir wasm --target web target/wasm32-unknown-unknown/release/examples/lines.wasm

cargo build --target wasm32-unknown-unknown --release --example many
cargo build --target wasm32-unknown-unknown --release --example many --features bevy/webgl2
wasm-bindgen --no-typescript --out-dir wasm --target web target/wasm32-unknown-unknown/release/examples/many.wasm

cargo build --target wasm32-unknown-unknown --release --example gltf
cargo build --target wasm32-unknown-unknown --release --example gltf --features bevy/webgl2
wasm-bindgen --no-typescript --out-dir wasm --target web target/wasm32-unknown-unknown/release/examples/gltf.wasm

cargo build --target wasm32-unknown-unknown --release --package interactive --features bevy/webgl2
wasm-bindgen --no-typescript --out-dir wasm --target web target/wasm32-unknown-unknown/release/interactive.wasm

cargo build --target wasm32-unknown-unknown --release --package physics_xpbd --features bevy/webgl2
wasm-bindgen --no-typescript --out-dir wasm --target web target/wasm32-unknown-unknown/release/physics_xpbd.wasm

- name: Copy Assets
run: cp -r assets wasm/

Expand Down
31 changes: 19 additions & 12 deletions Cargo.toml
@@ -1,33 +1,37 @@
[package]
name = "bevy_pathmesh"
version = "0.5.0"
authors = ["François Mockers <mockersf@gmail.com>"]
name = "vleue_navigator"
version = "0.7.1"
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]
itertools = "0.11"
itertools = "0.12"
tracing = { version = "0.1", optional = true }

[dependencies.polyanya]
version = "0.4"
version = "0.5"
# path = "../polyanya"
git = "https://github.com/vleue/polyanya"
branch = "radius-baking"

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

[dev-dependencies]
rand = "0.8"

[dev-dependencies.bevy]
version = "0.11"
version = "0.13"
features = [
"bevy_ui",
"bevy_text",
Expand All @@ -38,10 +42,10 @@ features = [
"bevy_pbr",
"bevy_sprite",
"bevy_gizmos",
# Required for TonyMcMapface
"tonemapping_luts",
"ktx2",
"zstd",
"multi-threaded",
]
default-features = false

Expand All @@ -51,3 +55,6 @@ linuxci = ["bevy/x11"]

[profile.dev.package."*"]
opt-level = 3

[workspace]
members = ["examples/interactive", "examples/physics_xpbd"]
35 changes: 17 additions & 18 deletions README.md
@@ -1,38 +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)
[![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/bevy_pathmesh/)
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 @@ -43,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 navmeshes: ResMut<Assets<NavMesh>>,
) {
if handles.1.is_none() {
// Get the gltf struct loaded from the file
Expand All @@ -58,11 +58,11 @@ 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(navmeshes.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 {
// Get the navmesh, then search for a path
let Some(navmesh) = navmeshes.get(handles.1.as_ref().unwrap()) else {
return
};
// Find two random point
Expand All @@ -74,7 +74,7 @@ fn get_path(
rand::thread_rng().gen_range(-50.0..50.0),
rand::thread_rng().gen_range(-50.0..50.0),
);
if let Some(path) = path_mesh.path(from, to) {
if let Some(path) = navmesh.path(from, to) {
info!("path from {} to {}: {:?}", from, to, path);
} else {
info!("no path between {} and {}", from, to)
Expand All @@ -83,7 +83,6 @@ fn get_path(
}
```

|Bevy|bevy_pathmesh|
|Bevy|vleue_navigator|
|---|---|
|0.11|0.5|
|0.10|0.4|
|0.13|0.7|