From c510c904ad9d42605d337e9936d527adb70adfec Mon Sep 17 00:00:00 2001 From: shnewto Date: Thu, 29 Feb 2024 19:21:28 -0700 Subject: [PATCH 1/8] first pass at generating more than just rapier2d colliders --- Cargo.toml | 16 +- .../{colliders.rs => rapier2d_colliders.rs} | 4 + examples/xpbd_2d_colliders.rs | 379 ++++++++++++++++++ src/collider/mod.rs | 5 + src/{collider.rs => collider/rapier2d.rs} | 0 src/collider/xpbd_2d.rs | 165 ++++++++ src/lib.rs | 40 +- 7 files changed, 583 insertions(+), 26 deletions(-) rename examples/{colliders.rs => rapier2d_colliders.rs} (97%) create mode 100644 examples/xpbd_2d_colliders.rs create mode 100644 src/collider/mod.rs rename src/{collider.rs => collider/rapier2d.rs} (100%) create mode 100644 src/collider/xpbd_2d.rs diff --git a/Cargo.toml b/Cargo.toml index fbfc489..89982ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,14 +11,24 @@ description = "a library for generating bevy_rapier2d colliders, for bevy apps, keywords = ["bevy", "rapier", "png", "collider", "2d"] readme = "README.md" +[features] +default = ["xpbd_2d", "rapier2d"] +xpbd_2d = ["dep:bevy_xpbd_2d"] +rapier2d = ["dep:bevy_rapier2d"] + [dependencies] bevy = "0.13.0" -bevy_rapier2d = "0.25.0" +bevy_rapier2d = { version = "0.25.0", optional = true } +bevy_xpbd_2d = { version = "0.4.2", optional = true } [dev-dependencies] bevy_prototype_lyon = "0.11.0" indoc = "2.0.4" [[example]] -name = "colliders" -path = "examples/colliders.rs" +name = "xpbd_2d_colliders" +path = "examples/xpbd_2d_colliders.rs" + +[[example]] +name = "rapier2d_colliders" +path = "examples/rapier2d_colliders.rs" \ No newline at end of file diff --git a/examples/colliders.rs b/examples/rapier2d_colliders.rs similarity index 97% rename from examples/colliders.rs rename to examples/rapier2d_colliders.rs index 7070baf..288a7fc 100644 --- a/examples/colliders.rs +++ b/examples/rapier2d_colliders.rs @@ -1,3 +1,6 @@ +#[cfg(not(feature = "rapier2d"))] +compile_error!("rapier2d` feature must be enabled."); + use bevy::asset::LoadState; use bevy::pbr::wireframe::WireframePlugin; use bevy::prelude::*; @@ -6,6 +9,7 @@ use bevy::render::RenderPlugin; use bevy_prototype_lyon::prelude::{Fill, GeometryBuilder, ShapePlugin}; use bevy_prototype_lyon::shapes; use bevy_rapier2d::prelude::*; +use bevy_rapier_collider_gen::rapier2d::{multi_convex_polyline_collider_translated, single_convex_polyline_collider_translated, single_heightfield_collider_translated}; use bevy_rapier_collider_gen::*; use indoc::indoc; use std::collections::HashMap; diff --git a/examples/xpbd_2d_colliders.rs b/examples/xpbd_2d_colliders.rs new file mode 100644 index 0000000..efe6f2f --- /dev/null +++ b/examples/xpbd_2d_colliders.rs @@ -0,0 +1,379 @@ +#[cfg(not(feature = "xpbd_2d"))] +compile_error!("xpbd_2d` feature must be enabled."); + +use bevy::asset::LoadState; +use bevy::pbr::wireframe::WireframePlugin; +use bevy::prelude::*; +use bevy::render::settings::{RenderCreation, WgpuFeatures, WgpuSettings}; +use bevy::render::RenderPlugin; +use bevy_prototype_lyon::prelude::{Fill, GeometryBuilder, ShapePlugin}; +use bevy_prototype_lyon::shapes; +use bevy_rapier_collider_gen::xpbd_2d::{multi_convex_hull_collider_translated, single_convex_hull_collider_translated, single_heightfield_collider_raw, single_heightfield_collider_translated, single_polyline_collider_translated}; +use bevy_rapier_collider_gen::*; +use bevy_xpbd_2d::components::{CoefficientCombine, ColliderDensity, Friction, GravityScale, Restitution, RigidBody}; +use bevy_xpbd_2d::math::Vector; +use bevy_xpbd_2d::plugins::debug::DebugRender; +use bevy_xpbd_2d::plugins::{PhysicsDebugPlugin, PhysicsPlugins}; +use bevy_xpbd_2d::resources::Gravity; +use indoc::indoc; +use std::collections::HashMap; + +/// Colliders (or, with no png path specified, Car + Boulder + Terrain) +/// Illustrating how to use PNG files w transparency to generate colliders (and geometry) +/// for 2d sprites. +/// +/// Controls +/// ← ↑ ↓ → (pan camera) +/// w (zoom in) +/// d (zoom out) + +/// Custom PNG: convex_polyline collider +/// from png path specified as cli argument +pub fn custom_png_spawn( + mut commands: Commands, + game_assets: Res, + image_assets: Res>, +) { + let sprite_handle = game_assets.image_handles.get("custom_png"); + if sprite_handle.is_none() { + return; + } + let sprite_image = image_assets.get(sprite_handle.unwrap()).unwrap(); + + let colliders = multi_convex_hull_collider_translated(sprite_image); + for collider in colliders { + commands.spawn(( + collider.unwrap(), + RigidBody::Static, + SpriteBundle { + texture: sprite_handle.unwrap().clone(), + transform: Transform::from_xyz(0.0, 0.0, 0.0), + ..default() + }, + DebugRender::default().with_collider_color(Color::VIOLET), + )); + } +} + +/// for the movement system +#[derive(Component, Resource)] +pub struct Car { + pub initial_xyz: Vec3, +} + +/// Car: convex_hull collider +/// from assets/sprite/car.png +pub fn car_spawn( + mut commands: Commands, + game_assets: Res, + image_assets: Res>, +) { + let initial_xyz = Vec3::new(-200.0, -4.0, 0.0); + let sprite_handle = game_assets.image_handles.get("car_handle"); + if sprite_handle.is_none() { + return; + } + let sprite_image = image_assets.get(sprite_handle.unwrap()).unwrap(); + let collider = single_convex_hull_collider_translated(sprite_image).unwrap(); + commands.spawn(( + collider, + SpriteBundle { + texture: sprite_handle.unwrap().clone(), + transform: Transform::from_xyz(initial_xyz.x, initial_xyz.y, initial_xyz.z), + ..default() + }, + Car { initial_xyz }, + RigidBody::Dynamic, + Friction::ZERO.with_combine_rule(CoefficientCombine::Min), + Restitution::ZERO.with_combine_rule(CoefficientCombine::Min), + ColliderDensity(2.0), + GravityScale(1.5), + DebugRender::default().with_collider_color(Color::VIOLET), + )); +} + +/// Terrain: heightfield collider +/// from assets/sprite/terrain.png +pub fn terrain_spawn( + mut commands: Commands, + game_assets: Res, + image_assets: Res>, +) { + let sprite_handle = game_assets.image_handles.get("terrain_handle"); + if sprite_handle.is_none() { + return; + } + let sprite_image = image_assets.get(sprite_handle.unwrap()).unwrap(); + let collider = single_heightfield_collider_raw(sprite_image); + commands.spawn(( + collider, + RigidBody::Static, + SpriteBundle { + texture: sprite_handle.unwrap().clone(), + ..default() + }, + DebugRender::default().with_collider_color(Color::VIOLET), + )); +} + +/// Boulder: using groups of edge coordinates to create geometry to color fill +/// multiple convex_polyline colliders +/// from assets/sprite/boulders.png +pub fn boulders_spawn( + mut commands: Commands, + game_assets: Res, + image_assets: Res>, +) { + let sprite_handle = game_assets.image_handles.get("boulders"); + if sprite_handle.is_none() { + return; + } + let sprite_image = image_assets.get(sprite_handle.unwrap()).unwrap(); + + let coord_group = multi_image_edge_translated(sprite_image); + let colliders = multi_convex_hull_collider_translated(sprite_image); + + for (coords, collider) in coord_group.iter().zip(colliders.into_iter()) { + let shape = shapes::Polygon { + points: coords.clone(), + closed: true, + }; + let geometry = GeometryBuilder::build_as(&shape); + let fill = Fill::color(Color::hex("545454").unwrap()); + let transform = Transform::from_xyz(0., 40., 0.); + + commands.spawn(( + collider.unwrap(), + geometry, + fill, + transform, + RigidBody::Dynamic, + Friction::ZERO.with_combine_rule(CoefficientCombine::Min), + Restitution::ZERO.with_combine_rule(CoefficientCombine::Min), + ColliderDensity(2.0), + GravityScale(1.5), + DebugRender::default().with_collider_color(Color::VIOLET), + )); + } +} + +/// +/// After this, things don't differ in a way related to this crate, it's just some of my +/// personal boilerplate +/// +#[derive(States, Debug, Clone, Eq, PartialEq, Hash, Default)] +pub enum AppState { + #[default] + Loading, + Running, +} + +#[derive(Component, Resource, Default)] +pub struct GameAsset { + pub font_handle: Handle, + pub image_handles: HashMap>, +} + +fn main() { + App::new() + .init_state::() + .add_plugins( + DefaultPlugins + .set(WindowPlugin { + primary_window: Some(Window { + title: "colliders".to_string(), + ..default() + }), + ..default() + }) + .set(AssetPlugin { + file_path: ".".to_string(), + ..default() + }) + .set(RenderPlugin { + render_creation: RenderCreation::Automatic(WgpuSettings { + features: WgpuFeatures::POLYGON_MODE_LINE, + ..default() + }), + ..default() + }), + ) + .insert_resource(GameAsset::default()) + .insert_resource(ClearColor(Color::rgb(0.0, 0.0, 0.0))) + .insert_resource(Gravity(Vector::NEG_Y * 1000.0)) + .add_plugins(ShapePlugin) + .add_plugins(WireframePlugin) + .add_plugins(PhysicsPlugins::default()) + .add_plugins(PhysicsDebugPlugin::default()) + .add_systems(OnEnter(AppState::Loading), load_assets) + .add_systems( + OnExit(AppState::Loading), + ( + camera_spawn, + custom_png_spawn, + car_spawn, + terrain_spawn, + boulders_spawn, + controls_text_spawn, + ), + ) + .add_systems( + Update, + ( + check_assets.run_if(in_state(AppState::Loading)), + camera_movement.run_if(in_state(AppState::Running)), + car_movement.run_if(in_state(AppState::Running)), + ), + ) + .run(); +} + +pub fn check_assets( + asset_server: Res, + game_assets: Res, + mut state: ResMut>, +) { + for h in game_assets.image_handles.values() { + if Some(LoadState::Loaded) != asset_server.get_load_state(h) { + return; + } + } + + if Some(LoadState::Loaded) != asset_server.get_load_state(game_assets.font_handle.clone()) { + return; + } + + state.set(AppState::Running) +} + +pub fn camera_spawn(mut commands: Commands) { + commands.spawn(Camera2dBundle::default()); +} + +pub fn camera_movement( + mut query: Query<(&Camera, &mut OrthographicProjection, &mut Transform)>, + keys: Res>, +) { + for (_, mut projection, mut transform) in query.iter_mut() { + if keys.pressed(KeyCode::ArrowLeft) { + transform.translation.x += 10.0; + } + if keys.pressed(KeyCode::ArrowRight) { + transform.translation.x -= 10.0; + } + + if keys.pressed(KeyCode::ArrowUp) { + transform.translation.y -= 10.0; + } + + if keys.pressed(KeyCode::ArrowDown) { + transform.translation.y += 10.0; + } + + if keys.pressed(KeyCode::KeyW) { + projection.scale -= 0.01; + } + + if keys.pressed(KeyCode::KeyS) { + projection.scale += 0.01; + } + } +} + +pub fn load_assets(asset_server: Res, mut game_assets: ResMut) { + let custom_png_path = std::env::args().nth(1); + game_assets.font_handle = asset_server.load("assets/font/NotoSansMono-Bold.ttf"); + + if let Some(png_path) = custom_png_path { + info!("Loading {}", png_path); + game_assets.image_handles = + HashMap::from([("custom_png".into(), asset_server.load(&png_path))]); + return; + } + + game_assets.image_handles = HashMap::from([ + ( + "car_handle".into(), + asset_server.load("assets/sprite/car.png"), + ), + ( + "terrain_handle".into(), + asset_server.load("assets/sprite/terrain.png"), + ), + ( + "boulders".into(), + asset_server.load("assets/sprite/boulders.png"), + ), + ]); +} + +pub fn controls_text_spawn(mut commands: Commands, game_assets: Res) { + let mut tips_text: String = indoc! {" + controls + -------------------- + ← ↑ ↓ → (pan camera) + w (zoom in) + s (zoom out) + "} + .into(); + + if game_assets.image_handles.get("car_handle").is_some() { + let car_controls: String = indoc! {" + a d (move car) + 1 (reset car transform to initial) + "} + .into(); + + tips_text.push_str(&car_controls); + } + + let node_bundle = NodeBundle { + style: Style { + width: Val::Px(100.), + height: Val::Px(10.), + position_type: PositionType::Absolute, + justify_content: JustifyContent::FlexStart, + align_items: AlignItems::FlexStart, + left: Val::Px(80.0), + bottom: Val::Px(600.0), + ..default() + }, + ..Default::default() + }; + let text_bundle = TextBundle { + text: Text { + sections: vec![TextSection { + value: tips_text.to_string(), + style: TextStyle { + font: game_assets.font_handle.clone(), + font_size: 20.0, + color: Color::rgb(0.9, 0.9, 0.9), + }, + }], + justify: JustifyText::Left, + ..default() + }, + ..Default::default() + }; + + commands.spawn(node_bundle).with_children(|parent| { + parent.spawn(text_bundle); + }); +} + +pub fn car_movement(mut query: Query<(&Car, &mut Transform)>, keys: Res>) { + for (car, mut transform) in query.iter_mut() { + if keys.pressed(KeyCode::KeyD) { + transform.translation.x += 5.0; + } + + if keys.pressed(KeyCode::KeyA) { + transform.translation.x -= 5.0; + } + + if keys.pressed(KeyCode::Digit1) { + *transform = + Transform::from_xyz(car.initial_xyz.x, car.initial_xyz.y, car.initial_xyz.z); + } + } +} diff --git a/src/collider/mod.rs b/src/collider/mod.rs new file mode 100644 index 0000000..5ef0c1d --- /dev/null +++ b/src/collider/mod.rs @@ -0,0 +1,5 @@ +#[cfg(feature = "xpbd_2d")] +pub mod xpbd_2d; + +#[cfg(feature = "rapier2d")] +pub mod rapier2d; diff --git a/src/collider.rs b/src/collider/rapier2d.rs similarity index 100% rename from src/collider.rs rename to src/collider/rapier2d.rs diff --git a/src/collider/xpbd_2d.rs b/src/collider/xpbd_2d.rs new file mode 100644 index 0000000..be8aaf4 --- /dev/null +++ b/src/collider/xpbd_2d.rs @@ -0,0 +1,165 @@ +use crate::{ + multi_image_edge_translated, multi_image_edges_raw, single_image_edge_raw, + single_image_edge_translated, +}; +use bevy::prelude::{Image, Vec2}; +use bevy_xpbd_2d::{parry::math::Real, prelude::Collider}; + +/// Generate a single polyline collider from the image, +/// coordinates translated to either side of (0, 0) +pub fn single_polyline_collider_translated(image: &Image) -> Collider { + Collider::polyline(single_image_edge_translated(image), None) +} + +/// Generate a single polyline collider from the image, +/// coordinates left alone and all in positive x and y +pub fn single_polyline_collider_raw(image: &Image) -> Collider { + Collider::polyline(single_image_edge_raw(image), None) +} + +// Is there an xpbd equivalent for this? +// +// Generate a single convex_polyline collider from the image, +// coordinates translated to either side of (0, 0) +// pub fn single_convex_polyline_collider_translated(image: &Image) -> Option { +// Collider::convex_polyline(single_image_edge_translated(image)) +// } + +// Is there an xpbd equivalent for this? +// +// Generate a single convex_polyline collider from the image, +// coordinates left alone and all in positive x and y +// pub fn single_convex_polyline_collider_raw(image: &Image) -> Option { +// Collider::convex_polyline(single_image_edge_raw(image)) +// } + +/// Generate a single convex_hull collider from the image, +/// coordinates translated to either side of (0, 0) +pub fn single_convex_hull_collider_translated(image: &Image) -> Option { + let points = single_image_edge_translated(image); + Collider::convex_hull(points) +} + +/// Generate a single convex_hull collider from the image, +/// coordinates left alone and all in positive x and y +pub fn single_convex_hull_collider_raw(image: &Image) -> Option { + let points = single_image_edge_translated(image); + Collider::convex_hull(points) +} + +/// Generate a single heightfield collider from the image, +/// coordinates translated to either side of (0, 0) +pub fn single_heightfield_collider_translated(image: &Image) -> Collider { + heightfield_collider_from_points(&single_image_edge_translated(image)) +} + +/// Generate a single heightfield collider from the image, +/// coordinates left alone and all in positive x and y +pub fn single_heightfield_collider_raw(image: &Image) -> Collider { + heightfield_collider_from_points(&single_image_edge_raw(image)) +} + +/// Generate as many polyline colliders as it can find in the image, +/// coordinates translated to either side of (0, 0) +pub fn multi_polyline_collider_translated(image: &Image) -> Vec { + multi_image_edge_translated(image) + .into_iter() + .map(|e| Collider::polyline(e, None)) + .collect() +} + +/// Generate as many polyline colliders as it can find in the image, +/// coordinates left alone and all in positive x and y +pub fn multi_polyline_collider_raw(image: &Image) -> Vec { + multi_image_edges_raw(image) + .into_iter() + .map(|e| Collider::polyline(e, None)) + .collect() +} + + +// Is there an xpbd equivalent for this? +// +// Generate as many convex_polyline colliders as it can find in the image, +// coordinates translated to either side of (0, 0) +// pub fn multi_convex_polyline_collider_translated(image: &Image) -> Vec> { +// multi_image_edge_translated(image) +// .into_iter() +// .map(Collider::convex_polyline) +// .collect() +// } + +// Is there an xpbd equivalent for this? +// +/// Generate as many convex_polyline colliders as it can find in the image, +/// coordinates left alone and all in positive x and y +// pub fn multi_convex_polyline_collider_raw(image: &Image) -> Vec> { +// multi_image_edges_raw(image) +// .into_iter() +// .map(Collider::convex_polyline) +// .collect() +// } + +/// Generate as many heightfield colliders as it can find in the image, +/// coordinates translated to either side of (0, 0) +pub fn multi_heightfield_collider_translated(image: &Image) -> Vec { + multi_image_edge_translated(image) + .into_iter() + .map(|e| heightfield_collider_from_points(&e)) + .collect() +} + +/// Generate as many heightfield colliders as it can find in the image, +/// coordinates left alone and all in positive x and y +pub fn multi_heightfield_collider_raw(image: &Image) -> Vec { + multi_image_edges_raw(image) + .into_iter() + .map(|e| heightfield_collider_from_points(&e)) + .collect() +} + +/// Generate as many convex_hull colliders as it can find in the image, +/// coordinates translated to either side of (0, 0) +pub fn multi_convex_hull_collider_translated(image: &Image) -> Vec> { + multi_image_edge_translated(image) + .into_iter() + .map(|e| Collider::convex_hull(e)) + .collect() +} + +/// Generate as many convex_hull colliders as it can find in the image, +/// coordinates left alone and all in positive x and y +pub fn multi_convex_hull_collider_raw(image: &Image) -> Vec> { + multi_image_edges_raw(image) + .into_iter() + .map(|e| Collider::convex_hull(e)) + .collect() +} + +/// parses x,y points into y values at the top of the image (smallest y) and creates a +/// heightfield collider +fn heightfield_collider_from_points(v: &[Vec2]) -> Collider { + let hf = heights_from_points(v); + // convert v into a vector + let x_scale = hf.len() as f32 - 1.0; + Collider::heightfield(hf, x_scale) +} + +/// takes x,y points collects the y values at the top of the image (smallest y) +fn heights_from_points(points: &[Vec2]) -> Vec { + let mut heights: Vec = vec![]; + + for p in points { + let elem = heights.iter().enumerate().find(|(_, e)| e.x == p.x); + if let Some((i, e)) = elem { + if e.y < p.y { + heights.remove(i); + heights.insert(i, *p); + } + } else { + heights.push(*p); + } + } + + heights.iter().map(|e| e.y).collect::>() +} diff --git a/src/lib.rs b/src/lib.rs index 452bd7b..6345463 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,28 +1,22 @@ #![doc = include_str!("../README.md")] + +#[cfg(all(not(feature = "rapier2d"), not(feature = "xpbd_2d")))] +compile_error!("At least one of the features `rapier2d` or `xpbd_2d` must be enabled."); + mod collider; mod edge; -pub use crate::collider::multi_convex_hull_collider_raw; -pub use crate::collider::multi_convex_hull_collider_translated; -pub use crate::collider::multi_convex_polyline_collider_raw; -pub use crate::collider::multi_convex_polyline_collider_translated; -pub use crate::collider::multi_heightfield_collider_raw; -pub use crate::collider::multi_heightfield_collider_translated; -pub use crate::collider::multi_polyline_collider_raw; -pub use crate::collider::multi_polyline_collider_translated; -pub use crate::collider::single_convex_hull_collider_raw; -pub use crate::collider::single_convex_hull_collider_translated; -pub use crate::collider::single_convex_polyline_collider_raw; -pub use crate::collider::single_convex_polyline_collider_translated; -pub use crate::collider::single_heightfield_collider_raw; -pub use crate::collider::single_heightfield_collider_translated; -pub use crate::collider::single_polyline_collider_raw; -pub use crate::collider::single_polyline_collider_translated; -pub use crate::edge::image_to_edges; -pub use crate::edge::march_edges; -pub use crate::edge::multi_image_edge_translated; -pub use crate::edge::multi_image_edges_raw; -pub use crate::edge::single_image_edge_raw; -pub use crate::edge::single_image_edge_translated; -pub use crate::edge::translate_vec; +#[cfg(feature = "rapier2d")] +pub use collider::rapier2d; + +#[cfg(feature = "xpbd_2d")] +pub use collider::xpbd_2d; + +pub use edge::image_to_edges; +pub use edge::march_edges; +pub use edge::multi_image_edge_translated; +pub use edge::multi_image_edges_raw; +pub use edge::single_image_edge_raw; +pub use edge::single_image_edge_translated; +pub use edge::translate_vec; From e06c8c4e837de4c3f3e43e8c63b7690454ba94d4 Mon Sep 17 00:00:00 2001 From: shnewto Date: Thu, 29 Feb 2024 19:45:31 -0700 Subject: [PATCH 2/8] fmt and clippy --- examples/rapier2d_colliders.rs | 5 ++++- examples/xpbd_2d_colliders.rs | 12 +++++++++--- src/collider/xpbd_2d.rs | 7 +++---- src/lib.rs | 1 - 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/examples/rapier2d_colliders.rs b/examples/rapier2d_colliders.rs index 288a7fc..52c3808 100644 --- a/examples/rapier2d_colliders.rs +++ b/examples/rapier2d_colliders.rs @@ -9,7 +9,10 @@ use bevy::render::RenderPlugin; use bevy_prototype_lyon::prelude::{Fill, GeometryBuilder, ShapePlugin}; use bevy_prototype_lyon::shapes; use bevy_rapier2d::prelude::*; -use bevy_rapier_collider_gen::rapier2d::{multi_convex_polyline_collider_translated, single_convex_polyline_collider_translated, single_heightfield_collider_translated}; +use bevy_rapier_collider_gen::rapier2d::{ + multi_convex_polyline_collider_translated, single_convex_polyline_collider_translated, + single_heightfield_collider_translated, +}; use bevy_rapier_collider_gen::*; use indoc::indoc; use std::collections::HashMap; diff --git a/examples/xpbd_2d_colliders.rs b/examples/xpbd_2d_colliders.rs index efe6f2f..7301953 100644 --- a/examples/xpbd_2d_colliders.rs +++ b/examples/xpbd_2d_colliders.rs @@ -8,9 +8,15 @@ use bevy::render::settings::{RenderCreation, WgpuFeatures, WgpuSettings}; use bevy::render::RenderPlugin; use bevy_prototype_lyon::prelude::{Fill, GeometryBuilder, ShapePlugin}; use bevy_prototype_lyon::shapes; -use bevy_rapier_collider_gen::xpbd_2d::{multi_convex_hull_collider_translated, single_convex_hull_collider_translated, single_heightfield_collider_raw, single_heightfield_collider_translated, single_polyline_collider_translated}; +use bevy_rapier_collider_gen::xpbd_2d::{ + multi_convex_hull_collider_translated, single_convex_hull_collider_translated, + single_heightfield_collider_raw, single_heightfield_collider_translated, + single_polyline_collider_translated, +}; use bevy_rapier_collider_gen::*; -use bevy_xpbd_2d::components::{CoefficientCombine, ColliderDensity, Friction, GravityScale, Restitution, RigidBody}; +use bevy_xpbd_2d::components::{ + CoefficientCombine, ColliderDensity, Friction, GravityScale, Restitution, RigidBody, +}; use bevy_xpbd_2d::math::Vector; use bevy_xpbd_2d::plugins::debug::DebugRender; use bevy_xpbd_2d::plugins::{PhysicsDebugPlugin, PhysicsPlugins}; @@ -87,7 +93,7 @@ pub fn car_spawn( Friction::ZERO.with_combine_rule(CoefficientCombine::Min), Restitution::ZERO.with_combine_rule(CoefficientCombine::Min), ColliderDensity(2.0), - GravityScale(1.5), + GravityScale(1.5), DebugRender::default().with_collider_color(Color::VIOLET), )); } diff --git a/src/collider/xpbd_2d.rs b/src/collider/xpbd_2d.rs index be8aaf4..5ddfefa 100644 --- a/src/collider/xpbd_2d.rs +++ b/src/collider/xpbd_2d.rs @@ -77,7 +77,6 @@ pub fn multi_polyline_collider_raw(image: &Image) -> Vec { .collect() } - // Is there an xpbd equivalent for this? // // Generate as many convex_polyline colliders as it can find in the image, @@ -123,7 +122,7 @@ pub fn multi_heightfield_collider_raw(image: &Image) -> Vec { pub fn multi_convex_hull_collider_translated(image: &Image) -> Vec> { multi_image_edge_translated(image) .into_iter() - .map(|e| Collider::convex_hull(e)) + .map(Collider::convex_hull) .collect() } @@ -132,7 +131,7 @@ pub fn multi_convex_hull_collider_translated(image: &Image) -> Vec Vec> { multi_image_edges_raw(image) .into_iter() - .map(|e| Collider::convex_hull(e)) + .map(Collider::convex_hull) .collect() } @@ -140,7 +139,7 @@ pub fn multi_convex_hull_collider_raw(image: &Image) -> Vec> { /// heightfield collider fn heightfield_collider_from_points(v: &[Vec2]) -> Collider { let hf = heights_from_points(v); - // convert v into a vector + // convert v into a vector let x_scale = hf.len() as f32 - 1.0; Collider::heightfield(hf, x_scale) } diff --git a/src/lib.rs b/src/lib.rs index 6345463..e7af258 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,5 @@ #![doc = include_str!("../README.md")] - #[cfg(all(not(feature = "rapier2d"), not(feature = "xpbd_2d")))] compile_error!("At least one of the features `rapier2d` or `xpbd_2d` must be enabled."); From 0628bf68d33e0721825a1a2124774d2873a86dff Mon Sep 17 00:00:00 2001 From: shnewto Date: Thu, 29 Feb 2024 21:24:51 -0700 Subject: [PATCH 3/8] good docs! found out how to convex polyline in xpbd --- README.md | 16 +++++-- examples/xpbd_2d_colliders.rs | 15 ++++--- src/collider/xpbd_2d.rs | 78 ++++++++++++++++++++--------------- 3 files changed, 64 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index 6586489..60c40ab 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![Crates.io]()]() [![MIT/Apache 2.0]()]() -a library for generating bevy_rapier2d colliders, for bevy apps, from images with transparency +a library for generating bevy_rapier2d and bevy_xpbd_2d colliders, for bevy apps, from images with transparency ## example @@ -12,11 +12,19 @@ a library for generating bevy_rapier2d colliders, for bevy apps, from images wit to see this in action you can run the example, with no args it generates a scene with various colliders using pngs in the `assets/sprite` directory +### bevy_rapier2d + +```sh +cargo run --example rapier2d_colliders +``` + +### bevy_xpbd_2d + ```sh -cargo run --example colliders +cargo run --example xpbd_2d_colliders ``` -you can also specify a path to an image yourself the example will attempt to generate one or more bevy_rapier_2d convex polylines for the objects it finds +you can also specify a path to an image yourself the example will attempt to generate one or more for the objects it finds ## about / why @@ -45,7 +53,7 @@ from any pixel in an existing group, that pixel begins a new group. (as in pictures of the sort of thing you can expect, not the runnable bevy app example. that's a couple headings up) -### convex polyline +### convex polyline (bevy_raiper2d only) ![convex polyline collider on an upside down car sprite]() diff --git a/examples/xpbd_2d_colliders.rs b/examples/xpbd_2d_colliders.rs index 7301953..be298bd 100644 --- a/examples/xpbd_2d_colliders.rs +++ b/examples/xpbd_2d_colliders.rs @@ -9,9 +9,8 @@ use bevy::render::RenderPlugin; use bevy_prototype_lyon::prelude::{Fill, GeometryBuilder, ShapePlugin}; use bevy_prototype_lyon::shapes; use bevy_rapier_collider_gen::xpbd_2d::{ - multi_convex_hull_collider_translated, single_convex_hull_collider_translated, - single_heightfield_collider_raw, single_heightfield_collider_translated, - single_polyline_collider_translated, + multi_convex_polyline_collider_translated, single_convex_polyline_collider_translated, + single_heightfield_collider_translated, }; use bevy_rapier_collider_gen::*; use bevy_xpbd_2d::components::{ @@ -46,7 +45,7 @@ pub fn custom_png_spawn( } let sprite_image = image_assets.get(sprite_handle.unwrap()).unwrap(); - let colliders = multi_convex_hull_collider_translated(sprite_image); + let colliders = multi_convex_polyline_collider_translated(sprite_image); for collider in colliders { commands.spawn(( collider.unwrap(), @@ -67,7 +66,7 @@ pub struct Car { pub initial_xyz: Vec3, } -/// Car: convex_hull collider +/// Car: convex_polyline collider /// from assets/sprite/car.png pub fn car_spawn( mut commands: Commands, @@ -80,7 +79,7 @@ pub fn car_spawn( return; } let sprite_image = image_assets.get(sprite_handle.unwrap()).unwrap(); - let collider = single_convex_hull_collider_translated(sprite_image).unwrap(); + let collider = single_convex_polyline_collider_translated(sprite_image).unwrap(); commands.spawn(( collider, SpriteBundle { @@ -110,7 +109,7 @@ pub fn terrain_spawn( return; } let sprite_image = image_assets.get(sprite_handle.unwrap()).unwrap(); - let collider = single_heightfield_collider_raw(sprite_image); + let collider = single_heightfield_collider_translated(sprite_image); commands.spawn(( collider, RigidBody::Static, @@ -137,7 +136,7 @@ pub fn boulders_spawn( let sprite_image = image_assets.get(sprite_handle.unwrap()).unwrap(); let coord_group = multi_image_edge_translated(sprite_image); - let colliders = multi_convex_hull_collider_translated(sprite_image); + let colliders = multi_convex_polyline_collider_translated(sprite_image); for (coords, collider) in coord_group.iter().zip(colliders.into_iter()) { let shape = shapes::Polygon { diff --git a/src/collider/xpbd_2d.rs b/src/collider/xpbd_2d.rs index 5ddfefa..e81999d 100644 --- a/src/collider/xpbd_2d.rs +++ b/src/collider/xpbd_2d.rs @@ -3,7 +3,13 @@ use crate::{ single_image_edge_translated, }; use bevy::prelude::{Image, Vec2}; -use bevy_xpbd_2d::{parry::math::Real, prelude::Collider}; +use bevy_xpbd_2d::{ + parry::{ + math::{Point, Real}, + shape::SharedShape, + }, + prelude::Collider, +}; /// Generate a single polyline collider from the image, /// coordinates translated to either side of (0, 0) @@ -17,21 +23,25 @@ pub fn single_polyline_collider_raw(image: &Image) -> Collider { Collider::polyline(single_image_edge_raw(image), None) } -// Is there an xpbd equivalent for this? -// -// Generate a single convex_polyline collider from the image, -// coordinates translated to either side of (0, 0) -// pub fn single_convex_polyline_collider_translated(image: &Image) -> Option { -// Collider::convex_polyline(single_image_edge_translated(image)) -// } +/// Generate a single convex_polyline collider from the image, +/// coordinates translated to either side of (0, 0) +pub fn single_convex_polyline_collider_translated(image: &Image) -> Option { + let points = single_image_edge_translated(image) + .into_iter() + .map(Point::from) + .collect::>>(); + SharedShape::convex_polyline(points).map(Collider::from) +} -// Is there an xpbd equivalent for this? -// -// Generate a single convex_polyline collider from the image, -// coordinates left alone and all in positive x and y -// pub fn single_convex_polyline_collider_raw(image: &Image) -> Option { -// Collider::convex_polyline(single_image_edge_raw(image)) -// } +/// Generate a single convex_polyline collider from the image, +/// coordinates left alone and all in positive x and y +pub fn single_convex_polyline_collider_raw(image: &Image) -> Option { + let points = single_image_edge_raw(image) + .into_iter() + .map(Point::from) + .collect::>>(); + SharedShape::convex_polyline(points).map(Collider::from) +} /// Generate a single convex_hull collider from the image, /// coordinates translated to either side of (0, 0) @@ -77,27 +87,29 @@ pub fn multi_polyline_collider_raw(image: &Image) -> Vec { .collect() } -// Is there an xpbd equivalent for this? -// -// Generate as many convex_polyline colliders as it can find in the image, -// coordinates translated to either side of (0, 0) -// pub fn multi_convex_polyline_collider_translated(image: &Image) -> Vec> { -// multi_image_edge_translated(image) -// .into_iter() -// .map(Collider::convex_polyline) -// .collect() -// } +/// Generate as many convex_polyline colliders as it can find in the image, +/// coordinates translated to either side of (0, 0) +pub fn multi_convex_polyline_collider_translated(image: &Image) -> Vec> { + multi_image_edge_translated(image) + .into_iter() + .map(|e| { + let points = e.into_iter().map(Point::from).collect::>>(); + SharedShape::convex_polyline(points).map(Collider::from) + }) + .collect() +} -// Is there an xpbd equivalent for this? -// /// Generate as many convex_polyline colliders as it can find in the image, /// coordinates left alone and all in positive x and y -// pub fn multi_convex_polyline_collider_raw(image: &Image) -> Vec> { -// multi_image_edges_raw(image) -// .into_iter() -// .map(Collider::convex_polyline) -// .collect() -// } +pub fn multi_convex_polyline_collider_raw(image: &Image) -> Vec> { + multi_image_edges_raw(image) + .into_iter() + .map(|e| { + let points = e.into_iter().map(Point::from).collect::>>(); + SharedShape::convex_polyline(points).map(Collider::from) + }) + .collect() +} /// Generate as many heightfield colliders as it can find in the image, /// coordinates translated to either side of (0, 0) From b0eee4751fd11b3cbfd06476ef000ecf4567fabe Mon Sep 17 00:00:00 2001 From: shnewto Date: Thu, 29 Feb 2024 22:06:43 -0700 Subject: [PATCH 4/8] used parry::SharedShape for heightfeild and it works great --- Cargo.toml | 6 ++++-- examples/rapier2d_colliders.rs | 3 --- examples/xpbd_2d_colliders.rs | 3 --- src/collider/xpbd_2d.rs | 12 +++++++----- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 89982ea..81cc292 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ keywords = ["bevy", "rapier", "png", "collider", "2d"] readme = "README.md" [features] -default = ["xpbd_2d", "rapier2d"] +default = ["xpbd_2d"] xpbd_2d = ["dep:bevy_xpbd_2d"] rapier2d = ["dep:bevy_rapier2d"] @@ -28,7 +28,9 @@ indoc = "2.0.4" [[example]] name = "xpbd_2d_colliders" path = "examples/xpbd_2d_colliders.rs" +required-features = ["xpbd_2d"] [[example]] name = "rapier2d_colliders" -path = "examples/rapier2d_colliders.rs" \ No newline at end of file +path = "examples/rapier2d_colliders.rs" +required-features = ["rapier2d"] diff --git a/examples/rapier2d_colliders.rs b/examples/rapier2d_colliders.rs index 52c3808..d37da92 100644 --- a/examples/rapier2d_colliders.rs +++ b/examples/rapier2d_colliders.rs @@ -1,6 +1,3 @@ -#[cfg(not(feature = "rapier2d"))] -compile_error!("rapier2d` feature must be enabled."); - use bevy::asset::LoadState; use bevy::pbr::wireframe::WireframePlugin; use bevy::prelude::*; diff --git a/examples/xpbd_2d_colliders.rs b/examples/xpbd_2d_colliders.rs index be298bd..cbc4a6f 100644 --- a/examples/xpbd_2d_colliders.rs +++ b/examples/xpbd_2d_colliders.rs @@ -1,6 +1,3 @@ -#[cfg(not(feature = "xpbd_2d"))] -compile_error!("xpbd_2d` feature must be enabled."); - use bevy::asset::LoadState; use bevy::pbr::wireframe::WireframePlugin; use bevy::prelude::*; diff --git a/src/collider/xpbd_2d.rs b/src/collider/xpbd_2d.rs index e81999d..0bd4514 100644 --- a/src/collider/xpbd_2d.rs +++ b/src/collider/xpbd_2d.rs @@ -4,8 +4,10 @@ use crate::{ }; use bevy::prelude::{Image, Vec2}; use bevy_xpbd_2d::{ + math::Vector2, parry::{ - math::{Point, Real}, + math::{Point, Real, Vector}, + na::DVector, shape::SharedShape, }, prelude::Collider, @@ -150,10 +152,10 @@ pub fn multi_convex_hull_collider_raw(image: &Image) -> Vec> { /// parses x,y points into y values at the top of the image (smallest y) and creates a /// heightfield collider fn heightfield_collider_from_points(v: &[Vec2]) -> Collider { - let hf = heights_from_points(v); - // convert v into a vector - let x_scale = hf.len() as f32 - 1.0; - Collider::heightfield(hf, x_scale) + let hf: DVector = heights_from_points(v).into(); + let x_scale: Real = hf.len() as f32 - 1.0; + let scale: Vector = Vector2::new(x_scale, 1.0).into(); + Collider::from(SharedShape::heightfield(hf, scale)) } /// takes x,y points collects the y values at the top of the image (smallest y) From c37b512a767dad6bbd3a86b34a87ca4b60aace98 Mon Sep 17 00:00:00 2001 From: shnewto Date: Thu, 29 Feb 2024 22:26:45 -0700 Subject: [PATCH 5/8] reduce some of the stuff spawned with colliders in the xpbd example --- examples/xpbd_2d_colliders.rs | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/examples/xpbd_2d_colliders.rs b/examples/xpbd_2d_colliders.rs index cbc4a6f..09e4db8 100644 --- a/examples/xpbd_2d_colliders.rs +++ b/examples/xpbd_2d_colliders.rs @@ -10,9 +10,7 @@ use bevy_rapier_collider_gen::xpbd_2d::{ single_heightfield_collider_translated, }; use bevy_rapier_collider_gen::*; -use bevy_xpbd_2d::components::{ - CoefficientCombine, ColliderDensity, Friction, GravityScale, Restitution, RigidBody, -}; +use bevy_xpbd_2d::components::RigidBody; use bevy_xpbd_2d::math::Vector; use bevy_xpbd_2d::plugins::debug::DebugRender; use bevy_xpbd_2d::plugins::{PhysicsDebugPlugin, PhysicsPlugins}; @@ -86,10 +84,6 @@ pub fn car_spawn( }, Car { initial_xyz }, RigidBody::Dynamic, - Friction::ZERO.with_combine_rule(CoefficientCombine::Min), - Restitution::ZERO.with_combine_rule(CoefficientCombine::Min), - ColliderDensity(2.0), - GravityScale(1.5), DebugRender::default().with_collider_color(Color::VIOLET), )); } @@ -150,10 +144,6 @@ pub fn boulders_spawn( fill, transform, RigidBody::Dynamic, - Friction::ZERO.with_combine_rule(CoefficientCombine::Min), - Restitution::ZERO.with_combine_rule(CoefficientCombine::Min), - ColliderDensity(2.0), - GravityScale(1.5), DebugRender::default().with_collider_color(Color::VIOLET), )); } From a3347ce1d825d2eb602b1169fe596510bee6530a Mon Sep 17 00:00:00 2001 From: shnewto Date: Fri, 1 Mar 2024 09:42:27 -0700 Subject: [PATCH 6/8] remove the misuse compile check, there will be plenty of compile errors downstream if nothing's enabled --- Cargo.toml | 2 +- README.md | 8 ++++++-- src/lib.rs | 3 --- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 81cc292..ca72ece 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ keywords = ["bevy", "rapier", "png", "collider", "2d"] readme = "README.md" [features] -default = ["xpbd_2d"] +default = ["xpbd_2d","rapier2d"] xpbd_2d = ["dep:bevy_xpbd_2d"] rapier2d = ["dep:bevy_rapier2d"] diff --git a/README.md b/README.md index 60c40ab..88bf01c 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![Crates.io]()]() [![MIT/Apache 2.0]()]() -a library for generating bevy_rapier2d and bevy_xpbd_2d colliders, for bevy apps, from images with transparency +a library for generating 2d colliders, for bevy apps, from images with transparency ## example @@ -14,17 +14,21 @@ to see this in action you can run the example, with no args it generates a scene ### bevy_rapier2d +#### note that you must have the rapier2d feature enabled + ```sh cargo run --example rapier2d_colliders ``` ### bevy_xpbd_2d +#### note that you must have the xpbd_2d feature enabled + ```sh cargo run --example xpbd_2d_colliders ``` -you can also specify a path to an image yourself the example will attempt to generate one or more for the objects it finds +you can also specify a path to an image yourself the example will attempt to generate one or more convex_polyline colliders for the objects it finds ## about / why diff --git a/src/lib.rs b/src/lib.rs index e7af258..a8ed647 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,5 @@ #![doc = include_str!("../README.md")] -#[cfg(all(not(feature = "rapier2d"), not(feature = "xpbd_2d")))] -compile_error!("At least one of the features `rapier2d` or `xpbd_2d` must be enabled."); - mod collider; mod edge; From 10bf06b1a81b16b152f22d656c8139a284879843 Mon Sep 17 00:00:00 2001 From: shnewto Date: Fri, 1 Mar 2024 17:33:17 -0700 Subject: [PATCH 7/8] some prep for becoming a new crate --- Cargo.toml | 10 ++++---- README.md | 42 ++++++++++++++++++++++++++-------- examples/rapier2d_colliders.rs | 4 ++-- examples/xpbd_2d_colliders.rs | 4 ++-- 4 files changed, 41 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ca72ece..68530ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,13 +1,13 @@ [package] -name = "bevy_rapier_collider_gen" +name = "bevy_collider_gen" # don't manually edit this version unless you're sure you want to circumvent the process documented in RELEASE.md -version = "0.3.1" +version = "0.1.0" edition = "2021" -homepage = "https://github.com/shnewto/bevy_rapier_collider_gen" +homepage = "https://github.com/shnewto/bevy_collider_gen" license = "MIT OR Apache-2.0" -repository = "https://github.com/shnewto/bevy_rapier_collider_gen" +repository = "https://github.com/shnewto/bevy_collider_gen" -description = "a library for generating bevy_rapier2d colliders, for bevy apps, from images with transparency" +description = "a library for generating colliders, for bevy apps, from images with transparency" keywords = ["bevy", "rapier", "png", "collider", "2d"] readme = "README.md" diff --git a/README.md b/README.md index 88bf01c..c5e0db3 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,36 @@ -# bevy_rapier_collider_gen +# bevy_collider_gen -[![Crates.io]()]() -[![Crates.io]()]() -[![MIT/Apache 2.0]()]() +[![Crates.io]()]() +[![Crates.io]()]() +[![MIT/Apache 2.0]()]() a library for generating 2d colliders, for bevy apps, from images with transparency +## specifying your dependency + +by default, both bevy_rapier2d and bevy_xpbd_2d are enabled. this is to help with the out of box experience, specifically, being able to run both examples and tinker. + +but you'll probably only want to just use one of the physics engines supported so when you use it in your own crate fill in in the `bevy_collider_gen` dependencies with something like this for `bevy_rapier2d` + +```toml +[dependencies.bevy_collider_gen] +version = "*" +features = ["rapier2d"] +default-features = false +``` + +or this for `bevy_xpbd_2d` + +```toml +[dependencies.bevy_collider_gen] +version = "*" +features = ["xpbd_2d"] +default-features = false +``` + ## example -![example with a car, terrain, and boulders]() +![example with a car, terrain, and boulders]() to see this in action you can run the example, with no args it generates a scene with various colliders using pngs in the `assets/sprite` directory @@ -59,22 +81,22 @@ from any pixel in an existing group, that pixel begins a new group. ### convex polyline (bevy_raiper2d only) -![convex polyline collider on an upside down car sprite]() +![convex polyline collider on an upside down car sprite]() ### polyline -![polyline collider on an upside down car sprite]() +![polyline collider on an upside down car sprite]() ### convex hull -![convex hull collider on an upside down car sprite]() +![convex hull collider on an upside down car sprite]() ### heightfield the current implementation does best if the image you're generating a heightfield from is either centered in the image or spans the entire width of the image... -![heightfield collider on an upside down car sprite]() +![heightfield collider on an upside down car sprite]() ### convex decomposition @@ -98,7 +120,7 @@ for coords in edge_coordinate_groups { } ``` -![convex decomposition collider on an upside down car sprite]() +![convex decomposition collider on an upside down car sprite]() ## license diff --git a/examples/rapier2d_colliders.rs b/examples/rapier2d_colliders.rs index d37da92..4115d27 100644 --- a/examples/rapier2d_colliders.rs +++ b/examples/rapier2d_colliders.rs @@ -3,14 +3,14 @@ use bevy::pbr::wireframe::WireframePlugin; use bevy::prelude::*; use bevy::render::settings::{RenderCreation, WgpuFeatures, WgpuSettings}; use bevy::render::RenderPlugin; +use bevy_collider_gen::multi_image_edge_translated; use bevy_prototype_lyon::prelude::{Fill, GeometryBuilder, ShapePlugin}; use bevy_prototype_lyon::shapes; use bevy_rapier2d::prelude::*; -use bevy_rapier_collider_gen::rapier2d::{ +use bevy_collider_gen::rapier2d::{ multi_convex_polyline_collider_translated, single_convex_polyline_collider_translated, single_heightfield_collider_translated, }; -use bevy_rapier_collider_gen::*; use indoc::indoc; use std::collections::HashMap; diff --git a/examples/xpbd_2d_colliders.rs b/examples/xpbd_2d_colliders.rs index 09e4db8..2a76f26 100644 --- a/examples/xpbd_2d_colliders.rs +++ b/examples/xpbd_2d_colliders.rs @@ -3,13 +3,13 @@ use bevy::pbr::wireframe::WireframePlugin; use bevy::prelude::*; use bevy::render::settings::{RenderCreation, WgpuFeatures, WgpuSettings}; use bevy::render::RenderPlugin; +use bevy_collider_gen::multi_image_edge_translated; use bevy_prototype_lyon::prelude::{Fill, GeometryBuilder, ShapePlugin}; use bevy_prototype_lyon::shapes; -use bevy_rapier_collider_gen::xpbd_2d::{ +use bevy_collider_gen::xpbd_2d::{ multi_convex_polyline_collider_translated, single_convex_polyline_collider_translated, single_heightfield_collider_translated, }; -use bevy_rapier_collider_gen::*; use bevy_xpbd_2d::components::RigidBody; use bevy_xpbd_2d::math::Vector; use bevy_xpbd_2d::plugins::debug::DebugRender; From 913f3bab03ed39645254b4fdc6647a6fc292cad3 Mon Sep 17 00:00:00 2001 From: shnewto Date: Fri, 1 Mar 2024 17:36:17 -0700 Subject: [PATCH 8/8] cargo fmt --- examples/rapier2d_colliders.rs | 6 +++--- examples/xpbd_2d_colliders.rs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/rapier2d_colliders.rs b/examples/rapier2d_colliders.rs index 4115d27..3c57a3b 100644 --- a/examples/rapier2d_colliders.rs +++ b/examples/rapier2d_colliders.rs @@ -4,13 +4,13 @@ use bevy::prelude::*; use bevy::render::settings::{RenderCreation, WgpuFeatures, WgpuSettings}; use bevy::render::RenderPlugin; use bevy_collider_gen::multi_image_edge_translated; -use bevy_prototype_lyon::prelude::{Fill, GeometryBuilder, ShapePlugin}; -use bevy_prototype_lyon::shapes; -use bevy_rapier2d::prelude::*; use bevy_collider_gen::rapier2d::{ multi_convex_polyline_collider_translated, single_convex_polyline_collider_translated, single_heightfield_collider_translated, }; +use bevy_prototype_lyon::prelude::{Fill, GeometryBuilder, ShapePlugin}; +use bevy_prototype_lyon::shapes; +use bevy_rapier2d::prelude::*; use indoc::indoc; use std::collections::HashMap; diff --git a/examples/xpbd_2d_colliders.rs b/examples/xpbd_2d_colliders.rs index 2a76f26..96ebdae 100644 --- a/examples/xpbd_2d_colliders.rs +++ b/examples/xpbd_2d_colliders.rs @@ -4,12 +4,12 @@ use bevy::prelude::*; use bevy::render::settings::{RenderCreation, WgpuFeatures, WgpuSettings}; use bevy::render::RenderPlugin; use bevy_collider_gen::multi_image_edge_translated; -use bevy_prototype_lyon::prelude::{Fill, GeometryBuilder, ShapePlugin}; -use bevy_prototype_lyon::shapes; use bevy_collider_gen::xpbd_2d::{ multi_convex_polyline_collider_translated, single_convex_polyline_collider_translated, single_heightfield_collider_translated, }; +use bevy_prototype_lyon::prelude::{Fill, GeometryBuilder, ShapePlugin}; +use bevy_prototype_lyon::shapes; use bevy_xpbd_2d::components::RigidBody; use bevy_xpbd_2d::math::Vector; use bevy_xpbd_2d::plugins::debug::DebugRender;