From e824ceef8b2a0c5dffba9d0b1a3d8e00bed4d40d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Sat, 9 Mar 2024 17:31:17 +0100 Subject: [PATCH] rebranding (#23) --- Cargo.toml | 14 ++++++------ README.md | 30 +++++++++++--------------- examples/gltf.rs | 20 ++++++++--------- examples/lines.rs | 30 +++++++++++++------------- examples/many.rs | 22 +++++++++---------- examples/moving.rs | 32 +++++++++++++-------------- src/asset_loaders.rs | 30 +++++++++++++------------- src/lib.rs | 51 +++++++++++++++++++++----------------------- wasm/index.html | 2 +- 9 files changed, 112 insertions(+), 119 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ccccc63..7af09d3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,15 +1,15 @@ [package] -name = "bevy_pathmesh" -version = "0.6.0" -authors = ["François Mockers "] +name = "vleue_navigator" +version = "0.7.0" +authors = ["François Mockers "] 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] diff --git a/README.md b/README.md index 55eba0b..e322af0 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,18 @@ -# 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::{ @@ -22,19 +20,19 @@ use bevy::{ 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, Option>); +struct Handles(Handle, Option>); fn load(mut commands: Commands, asset_server: Res) { commands.insert_resource(Handles(asset_server.load("navmesh.glb"), None)); @@ -45,7 +43,7 @@ fn get_path( gltfs: Res>, gltf_meshes: Res>, meshes: Res>, - mut path_meshes: ResMut>, + mut path_meshes: ResMut>, ) { if handles.1.is_none() { // Get the gltf struct loaded from the file @@ -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 { @@ -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| diff --git a/examples/gltf.rs b/examples/gltf.rs index 9cea619..82c71c0 100644 --- a/examples/gltf.rs +++ b/examples/gltf.rs @@ -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 = Handle::weak_from_u128(0); +const HANDLE_TRIMESH_OPTIMIZED: Handle = Handle::weak_from_u128(0); fn main() { App::new() @@ -24,7 +24,7 @@ fn main() { }), ..default() }), - PathMeshPlugin, + VleueNavigatorPlugin, )) .init_state::() .add_systems(OnEnter(AppState::Setup), setup) @@ -56,7 +56,7 @@ enum AppState { struct GltfHandle(Handle); #[derive(Resource)] -struct CurrentMesh(Handle); +struct CurrentMesh(Handle); fn setup(mut commands: Commands, asset_server: Res) { commands.insert_resource(GltfHandle(asset_server.load("meshes/navmesh.glb"))); @@ -153,7 +153,7 @@ struct Target; struct Hover(Vec2); #[derive(Component, Clone)] -struct NavMeshDisp(Handle); +struct NavMeshDisp(Handle); fn setup_scene( mut commands: Commands, @@ -162,7 +162,7 @@ fn setup_scene( gltf_meshes: Res>, mut meshes: ResMut>, mut materials: ResMut>, - mut pathmeshes: ResMut>, + mut navmeshes: ResMut>, ) { let mut material: StandardMaterial = Color::ALICE_BLUE.into(); material.perceptual_roughness = 1.0; @@ -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 @@ -247,7 +247,7 @@ fn setup_scene( }, NavMeshDisp(HANDLE_TRIMESH_OPTIMIZED), )); - pathmeshes.insert(HANDLE_TRIMESH_OPTIMIZED, navmesh); + navmeshes.insert(HANDLE_TRIMESH_OPTIMIZED, navmesh); } commands @@ -284,7 +284,7 @@ fn setup_scene( fn give_target_auto( mut commands: Commands, mut object_query: Query<(Entity, &Transform, &mut Object), Without>, - navmeshes: Res>, + navmeshes: Res>, mut meshes: ResMut>, mut materials: ResMut>, current_mesh: Res, @@ -353,7 +353,7 @@ fn give_target_on_click( mut commands: Commands, mut object_query: Query<(Entity, &Transform, &mut Object)>, targets: Query>, - navmeshes: Res>, + navmeshes: Res>, mut meshes: ResMut>, mut materials: ResMut>, current_mesh: Res, diff --git a/examples/lines.rs b/examples/lines.rs index 2ebe2af..20e213c 100644 --- a/examples/lines.rs +++ b/examples/lines.rs @@ -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() @@ -16,7 +16,7 @@ fn main() { }), ..default() }), - PathMeshPlugin, + VleueNavigatorPlugin, )) .add_event::() .insert_resource(PathToDisplay::default()) @@ -36,9 +36,9 @@ fn main() { #[derive(Resource)] struct Meshes { - simple: Handle, - arena: Handle, - aurora: Handle, + simple: Handle, + arena: Handle, + aurora: Handle, } enum CurrentMesh { @@ -70,12 +70,12 @@ const AURORA: MeshDetails = MeshDetails { fn setup( mut commands: Commands, - mut pathmeshes: ResMut>, + mut navmeshes: ResMut>, asset_server: Res, ) { 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]), @@ -127,7 +127,7 @@ fn on_mesh_change( mesh: Res, mut commands: Commands, mut meshes: ResMut>, - pathmeshes: Res>, + navmeshes: Res>, mut materials: ResMut>, path_meshes: Res, mut current_mesh_entity: Local>, @@ -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(); } @@ -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, @@ -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() @@ -243,7 +243,7 @@ fn on_click( camera_q: Query<(&Camera, &GlobalTransform)>, mesh: Res, meshes: Res, - pathmeshes: Res>, + navmeshes: Res>, ) { if mouse_button_input.just_pressed(MouseButton::Left) { let (camera, camera_transform) = camera_q.single(); @@ -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, @@ -280,7 +280,7 @@ fn compute_paths( mut path_to_display: ResMut, mesh: Res, meshes: Res, - pathmeshes: Res>, + navmeshes: Res>, ) { for ev in event_new_step_path.read() { if path_to_display.steps.is_empty() { @@ -288,7 +288,7 @@ fn compute_paths( return; } - let path_mesh = pathmeshes + let path_mesh = navmeshes .get(match mesh.mesh { CurrentMesh::Simple => &meshes.simple, CurrentMesh::Arena => &meshes.arena, diff --git a/examples/many.rs b/examples/many.rs index 81db7c7..492a193 100644 --- a/examples/many.rs +++ b/examples/many.rs @@ -16,7 +16,7 @@ use bevy::{ }; use rand::prelude::*; -use bevy_pathmesh::{PathMesh, PathMeshPlugin}; +use vleue_navigator::{NavMesh, VleueNavigatorPlugin}; fn main() { App::new() @@ -44,7 +44,7 @@ fn main() { }), FrameTimeDiagnosticsPlugin::default(), LogDiagnosticsPlugin::default(), - PathMeshPlugin, + VleueNavigatorPlugin, )) .init_resource::() .insert_resource(TaskMode::Blocking) @@ -81,7 +81,7 @@ enum DisplayMode { #[derive(Resource)] struct Meshes { - aurora: Handle, + aurora: Handle, } const MESH_SIZE: Vec2 = Vec2::new(1024.0, 768.0); @@ -207,7 +207,7 @@ fn setup(mut commands: Commands, asset_server: Res) { fn on_mesh_change( mut commands: Commands, mut meshes: ResMut>, - pathmeshes: Res>, + navmeshes: Res>, mut materials: ResMut>, path_meshes: Res, mut current_mesh_entity: Local>, @@ -217,7 +217,7 @@ fn on_mesh_change( ) { if !window_resized.is_empty() || *wait_for_mesh { let handle = &path_meshes.aurora; - if let Some(pathmesh) = pathmeshes.get(handle) { + if let Some(navmesh) = navmeshes.get(handle) { *wait_for_mesh = false; if let Some(entity) = *current_mesh_entity { commands.entity(entity).despawn(); @@ -227,7 +227,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, @@ -264,10 +264,10 @@ struct Path { fn spawn( primary_window: Query<&Window, With>, mut commands: Commands, - pathmeshes: Res>, + navmeshes: Res>, path_meshes: Res, ) { - if pathmeshes.contains(&path_meshes.aurora) { + if navmeshes.contains(&path_meshes.aurora) { let window = primary_window.single(); let mut rng = rand::thread_rng(); let screen = Vec2::new(window.width(), window.height()); @@ -330,7 +330,7 @@ struct FindingPath(Arc>); fn compute_paths( mut commands: Commands, with_target: Query<(Entity, &Target, &Transform), Changed>, - meshes: Res>, + meshes: Res>, primary_window: Query<&Window, With>, task_mode: Res, mesh: Res, @@ -382,7 +382,7 @@ fn poll_path_tasks( mut commands: Commands, computing: Query<(Entity, &FindingPath, &Transform)>, mut stats: ResMut, - pathmeshes: Res>, + navmeshes: Res>, meshes: Res, primary_window: Query<&Window, With>, ) { @@ -403,7 +403,7 @@ fn poll_path_tasks( let screen = Vec2::new(window.width(), window.height()); let factor = (screen.x / MESH_SIZE.x).min(screen.y / MESH_SIZE.y); - if !pathmeshes + if !navmeshes .get(&meshes.aurora) .unwrap() .is_in_mesh(transform.translation.xy() / factor + MESH_SIZE / 2.0) diff --git a/examples/moving.rs b/examples/moving.rs index 8563540..8f69534 100644 --- a/examples/moving.rs +++ b/examples/moving.rs @@ -11,7 +11,7 @@ use bevy::{ window::{PrimaryWindow, WindowResized}, }; -use bevy_pathmesh::{PathMesh, PathMeshPlugin}; +use vleue_navigator::{NavMesh, VleueNavigatorPlugin}; fn main() { App::new() @@ -24,7 +24,7 @@ fn main() { }), ..default() }), - PathMeshPlugin, + VleueNavigatorPlugin, )) .add_systems(Startup, setup) .add_systems( @@ -44,9 +44,9 @@ fn main() { #[derive(Resource)] struct Meshes { - simple: Handle, - arena: Handle, - aurora: Handle, + simple: Handle, + arena: Handle, + aurora: Handle, } enum CurrentMesh { @@ -78,12 +78,12 @@ const AURORA: MeshDetails = MeshDetails { fn setup( mut commands: Commands, - mut pathmeshes: ResMut>, + mut navmeshes: ResMut>, asset_server: Res, ) { 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]), @@ -129,7 +129,7 @@ fn on_mesh_change( mesh: Res, mut commands: Commands, mut meshes: ResMut>, - pathmeshes: Res>, + navmeshes: Res>, mut materials: ResMut>, path_meshes: Res, mut current_mesh_entity: Local>, @@ -146,7 +146,7 @@ fn on_mesh_change( CurrentMesh::Arena => &path_meshes.arena, CurrentMesh::Aurora => &path_meshes.aurora, }; - if let Some(pathmesh) = pathmeshes.get(handle) { + if let Some(navmesh) = navmeshes.get(handle) { *wait_for_mesh = false; if let Some(entity) = *current_mesh_entity { commands.entity(entity).despawn(); @@ -159,7 +159,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, @@ -260,7 +260,7 @@ struct Navigator { #[derive(Component)] struct Target { target: Vec2, - pathmesh: Handle, + navmesh: Handle, } #[derive(Component)] @@ -276,7 +276,7 @@ fn on_click( meshes: Res, mut commands: Commands, query: Query>, - pathmeshes: Res>, + navmeshes: Res>, ) { if mouse_button_input.just_pressed(MouseButton::Left) { let (camera, camera_transform) = camera_q.single(); @@ -289,7 +289,7 @@ fn on_click( let screen = Vec2::new(window.width(), window.height()); 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, @@ -302,7 +302,7 @@ fn on_click( info!("going to {}", in_mesh); commands.entity(navigator).insert(Target { target: in_mesh, - pathmesh: match mesh.mesh { + navmesh: match mesh.mesh { CurrentMesh::Simple => meshes.simple.clone_weak(), CurrentMesh::Arena => meshes.arena.clone_weak(), CurrentMesh::Aurora => meshes.aurora.clone_weak(), @@ -340,7 +340,7 @@ struct FindingPath(Arc, bool)>>); fn compute_paths( mut commands: Commands, with_target: Query<(Entity, &Target, &Transform), Changed>, - meshes: Res>, + meshes: Res>, mesh: Res, primary_window: Query<&Window, With>, ) { @@ -349,7 +349,7 @@ fn compute_paths( for (entity, target, transform) in &with_target { let in_mesh = transform.translation.truncate() / factor + mesh.size / 2.0; - let mesh = meshes.get(&target.pathmesh).unwrap(); + let mesh = meshes.get(&target.navmesh).unwrap(); let to = target.target; let mesh = mesh.clone(); diff --git a/src/asset_loaders.rs b/src/asset_loaders.rs index 78ff971..985cfcb 100644 --- a/src/asset_loaders.rs +++ b/src/asset_loaders.rs @@ -1,4 +1,4 @@ -//! Asset loaders that can load a [`PathMesh`] from a file +//! Asset loaders that can load a [`NavMesh`] from a file use std::{error::Error, fmt::Display, sync::Arc}; @@ -9,27 +9,27 @@ use bevy::{ }; use polyanya::PolyanyaFile; -use crate::PathMesh; +use crate::NavMesh; -/// Error that can happen while reading a `PathMesh` from a file +/// Error that can happen while reading a `NavMesh` from a file #[derive(Debug)] -pub enum PathMeshLoaderError { +pub enum NavMeshLoaderError { /// Error when reading file Io(std::io::Error), } -impl Display for PathMeshLoaderError { +impl Display for NavMeshLoaderError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - PathMeshLoaderError::Io(io_error) => write!(f, "IO error: {}", io_error), + NavMeshLoaderError::Io(io_error) => write!(f, "IO error: {}", io_error), } } } -impl Error for PathMeshLoaderError { +impl Error for NavMeshLoaderError { fn source(&self) -> Option<&(dyn Error + 'static)> { match self { - PathMeshLoaderError::Io(io_error) => Some(io_error), + NavMeshLoaderError::Io(io_error) => Some(io_error), } } } @@ -37,12 +37,12 @@ impl Error for PathMeshLoaderError { /// /// See for format description. #[derive(Default, Debug, Clone, Copy)] -pub struct PathMeshPolyanyaLoader; +pub struct NavMeshPolyanyaLoader; -impl AssetLoader for PathMeshPolyanyaLoader { - type Asset = PathMesh; +impl AssetLoader for NavMeshPolyanyaLoader { + type Asset = NavMesh; type Settings = (); - type Error = PathMeshLoaderError; + type Error = NavMeshLoaderError; fn load<'a>( &'a self, @@ -55,12 +55,12 @@ impl AssetLoader for PathMeshPolyanyaLoader { reader .read_to_end(&mut bytes) .await - .map_err(PathMeshLoaderError::Io)?; - let pathmesh = PathMesh { + .map_err(NavMeshLoaderError::Io)?; + let navmesh = NavMesh { mesh: Arc::new(PolyanyaFile::from_bytes(bytes.as_slice()).into()), transform: Transform::from_scale(Vec3::splat(1.)), }; - Ok(pathmesh) + Ok(navmesh) }) } diff --git a/src/lib.rs b/src/lib.rs index 52c2398..f5a864f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,18 +25,18 @@ use itertools::Itertools; pub mod asset_loaders; -/// Bevy plugin to add support for the [`PathMesh`] asset type. +/// Bevy plugin to add support for the [`NavMesh`] asset type. #[derive(Debug, Clone, Copy)] -pub struct PathMeshPlugin; +pub struct VleueNavigatorPlugin; -impl Plugin for PathMeshPlugin { +impl Plugin for VleueNavigatorPlugin { fn build(&self, app: &mut App) { - app.register_asset_loader(asset_loaders::PathMeshPolyanyaLoader) - .init_asset::(); + app.register_asset_loader(asset_loaders::NavMeshPolyanyaLoader) + .init_asset::(); } } -/// A path between two points, in 3 dimensions using [`PathMesh::transform`]. +/// A path between two points, in 3 dimensions using [`NavMesh::transform`]. #[derive(Debug, PartialEq)] pub struct TransformedPath { /// Length of the path. @@ -50,29 +50,26 @@ use polyanya::Trimesh; /// A navigation mesh #[derive(Debug, TypePath, Clone, Asset)] -pub struct PathMesh { +pub struct NavMesh { mesh: Arc, transform: Transform, } -impl PathMesh { - /// Builds a [`PathMesh`] from a Polyanya [`Mesh`](polyanya::Mesh) - pub fn from_polyanya_mesh(mesh: polyanya::Mesh) -> PathMesh { - PathMesh { +impl NavMesh { + /// Builds a [`NavMesh`] from a Polyanya [`Mesh`](polyanya::Mesh) + pub fn from_polyanya_mesh(mesh: polyanya::Mesh) -> NavMesh { + NavMesh { mesh: Arc::new(mesh), transform: Transform::IDENTITY, } } - /// Creates a [`PathMesh`] from a Bevy [`Mesh`], assuming it constructs a 2D structure. + /// Creates a [`NavMesh`] from a Bevy [`Mesh`], assuming it constructs a 2D structure. /// All triangle normals are aligned during the conversion, so the orientation of the [`Mesh`] does not matter. /// The [`polyanya::Mesh`] generated in the process can be modified via `callback`. /// /// Only supports meshes with the [`PrimitiveTopology::TriangleList`]. - pub fn from_bevy_mesh_and_then( - mesh: &Mesh, - callback: impl Fn(&mut polyanya::Mesh), - ) -> PathMesh { + pub fn from_bevy_mesh_and_then(mesh: &Mesh, callback: impl Fn(&mut polyanya::Mesh)) -> NavMesh { let normal = get_vectors(mesh, Mesh::ATTRIBUTE_NORMAL).next().unwrap(); let rotation = Quat::from_rotation_arc(normal, Vec3::Z); @@ -101,11 +98,11 @@ impl PathMesh { path_mesh } - /// Creates a [`PathMesh`] from a Bevy [`Mesh`], assuming it constructs a 2D structure. + /// Creates a [`NavMesh`] from a Bevy [`Mesh`], assuming it constructs a 2D structure. /// All triangle normals are aligned during the conversion, so the orientation of the [`Mesh`] does not matter. /// /// Only supports meshes with the [`PrimitiveTopology::TriangleList`]. - pub fn from_bevy_mesh(mesh: &Mesh) -> PathMesh { + pub fn from_bevy_mesh(mesh: &Mesh) -> NavMesh { Self::from_bevy_mesh_and_then(mesh, |_| {}) } @@ -122,7 +119,7 @@ impl PathMesh { /// Get a path between two points, in an async way. /// - /// Inputs and results are transformed using the [`PathMesh::transform`] + /// Inputs and results are transformed using the [`NavMesh::transform`] pub async fn get_transformed_path(&self, from: Vec3, to: Vec3) -> Option { let inner_from = self.transform.transform_point(from).xy(); let inner_to = self.transform.transform_point(to).xy(); @@ -138,7 +135,7 @@ impl PathMesh { /// Get a path between two points, in an async way. /// - /// Inputs and results are transformed using the [`PathMesh::transform`] + /// Inputs and results are transformed using the [`NavMesh::transform`] pub fn transformed_path(&self, from: Vec3, to: Vec3) -> Option { let inner_from = self.transform.transform_point(from).xy(); let inner_to = self.transform.transform_point(to).xy(); @@ -182,7 +179,7 @@ impl PathMesh { self.transform = transform; } - /// Creates a [`Mesh`] from this [`PathMesh`], suitable for rendering the surface + /// Creates a [`Mesh`] from this [`NavMesh`], suitable for rendering the surface pub fn to_mesh(&self) -> Mesh { let mut new_mesh = Mesh::new(PrimitiveTopology::TriangleList, RenderAssetUsages::all()); let inverse_transform = self.inverse_transform(); @@ -208,7 +205,7 @@ impl PathMesh { new_mesh } - /// Creates a [`Mesh`] from this [`PathMesh`], showing the wireframe of the polygons + /// Creates a [`Mesh`] from this [`NavMesh`], showing the wireframe of the polygons pub fn to_wireframe_mesh(&self) -> Mesh { let mut new_mesh = Mesh::new(PrimitiveTopology::LineList, RenderAssetUsages::all()); let inverse_transform = self.inverse_transform(); @@ -266,7 +263,7 @@ mod tests { #[test] fn generating_from_existing_path_mesh_results_in_same_path_mesh() { - let expected_path_mesh = PathMesh::from_polyanya_mesh( + let expected_path_mesh = NavMesh::from_polyanya_mesh( Trimesh { vertices: vec![ Vec2::new(1., 1.), @@ -286,14 +283,14 @@ mod tests { Mesh::ATTRIBUTE_NORMAL, (0..6).map(|_| [0.0, 0.0, 1.0]).collect::>(), ); - let actual_path_mesh = PathMesh::from_bevy_mesh(&bevy_mesh); + let actual_path_mesh = NavMesh::from_bevy_mesh(&bevy_mesh); assert_same_path_mesh(expected_path_mesh, actual_path_mesh); } #[test] fn rotated_mesh_generates_expected_path_mesh() { - let expected_path_mesh = PathMesh::from_polyanya_mesh( + let expected_path_mesh = NavMesh::from_polyanya_mesh( Trimesh { vertices: vec![ Vec2::new(-1., -1.), @@ -326,12 +323,12 @@ mod tests { ); bevy_mesh.insert_indices(Indices::U32(vec![0, 1, 3, 0, 3, 2])); - let actual_path_mesh = PathMesh::from_bevy_mesh(&bevy_mesh); + let actual_path_mesh = NavMesh::from_bevy_mesh(&bevy_mesh); assert_same_path_mesh(expected_path_mesh, actual_path_mesh); } - fn assert_same_path_mesh(expected: PathMesh, actual: PathMesh) { + fn assert_same_path_mesh(expected: NavMesh, actual: NavMesh) { let expected_mesh = expected.mesh; let actual_mesh = actual.mesh; diff --git a/wasm/index.html b/wasm/index.html index 235b437..3197046 100644 --- a/wasm/index.html +++ b/wasm/index.html @@ -15,7 +15,7 @@

Links

  • Polyanya - Compromise-free Pathfinding on a Navigation Mesh
  • Rust implementation of Polyanya
  • -
  • Integration with Bevy
  • +
  • Integration with Bevy