Skip to content

Commit

Permalink
Merge pull request #11 from shnewto/xpbd-collider-gen
Browse files Browse the repository at this point in the history
support xpbd collider gen
  • Loading branch information
shnewto committed Mar 2, 2024
2 parents a4c9416 + 913f3ba commit 4525620
Show file tree
Hide file tree
Showing 8 changed files with 640 additions and 46 deletions.
28 changes: 20 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
[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.4.0"
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"

[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"
required-features = ["xpbd_2d"]

[[example]]
name = "rapier2d_colliders"
path = "examples/rapier2d_colliders.rs"
required-features = ["rapier2d"]
62 changes: 48 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,56 @@
# bevy_rapier_collider_gen
# bevy_collider_gen

[![Crates.io](<https://img.shields.io/crates/v/bevy_rapier_collider_gen.svg>)](<https://crates.io/crates/bevy_rapier_collider_gen>)
[![Crates.io](<https://img.shields.io/crates/d/bevy_rapier_collider_gen.svg>)](<https://crates.io/crates/bevy_rapier_collider_gen>)
[![MIT/Apache 2.0](<https://img.shields.io/badge/license-MIT%2FApache-blue.svg>)](<https://github.com/shnewto/bevy_rapier_collider_gen#license>)
[![Crates.io](<https://img.shields.io/crates/v/bevy_collider_gen.svg>)](<https://crates.io/crates/bevy_collider_gen>)
[![Crates.io](<https://img.shields.io/crates/d/bevy_collider_gen.svg>)](<https://crates.io/crates/bevy_collider_gen>)
[![MIT/Apache 2.0](<https://img.shields.io/badge/license-MIT%2FApache-blue.svg>)](<https://github.com/shnewto/bevy_collider_gen#license>)

a library for generating bevy_rapier2d colliders, for bevy apps, from images with transparency
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](<https://github.com/shnewto/bevy_rapier_collider_gen/blob/main/img/example-default.png?raw=true>)
![example with a car, terrain, and boulders](<https://github.com/shnewto/bevy_collider_gen/blob/main/img/example-default.png?raw=true>)

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

#### 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 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 convex_polyline colliders for the objects it finds

## about / why

Expand Down Expand Up @@ -45,24 +79,24 @@ 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](<https://github.com/shnewto/bevy_rapier_collider_gen/blob/main/img/convex-polyline.png?raw=true>)
![convex polyline collider on an upside down car sprite](<https://github.com/shnewto/bevy_collider_gen/blob/main/img/convex-polyline.png?raw=true>)

### polyline

![polyline collider on an upside down car sprite](<https://github.com/shnewto/bevy_rapier_collider_gen/blob/main/img/polyline.png?raw=true>)
![polyline collider on an upside down car sprite](<https://github.com/shnewto/bevy_collider_gen/blob/main/img/polyline.png?raw=true>)

### convex hull

![convex hull collider on an upside down car sprite](<https://github.com/shnewto/bevy_rapier_collider_gen/blob/main/img/convex-hull.png?raw=true>)
![convex hull collider on an upside down car sprite](<https://github.com/shnewto/bevy_collider_gen/blob/main/img/convex-hull.png?raw=true>)

### 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](<https://github.com/shnewto/bevy_rapier_collider_gen/blob/main/img/heightfield.png?raw=true>)
![heightfield collider on an upside down car sprite](<https://github.com/shnewto/bevy_collider_gen/blob/main/img/heightfield.png?raw=true>)

### convex decomposition

Expand All @@ -86,7 +120,7 @@ for coords in edge_coordinate_groups {
}
```

![convex decomposition collider on an upside down car sprite](<https://github.com/shnewto/bevy_rapier_collider_gen/blob/main/img/convex-decomposition.png?raw=true>)
![convex decomposition collider on an upside down car sprite](<https://github.com/shnewto/bevy_collider_gen/blob/main/img/convex-decomposition.png?raw=true>)

## license

Expand Down
6 changes: 5 additions & 1 deletion examples/colliders.rs → examples/rapier2d_colliders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +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_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 bevy_rapier_collider_gen::*;
use indoc::indoc;
use std::collections::HashMap;

Expand Down
Loading

0 comments on commit 4525620

Please sign in to comment.