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

Update of examples and doc #23

Merged
merged 8 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.3.0](https://github.com/shnewto/bevy_collider_gen/compare/0.2.2...0.3.0) - 2024-11-20

### Added

- Feature `parallel` for parallel work with data
([594e767](https://github.com/shnewto/bevy_collider_gen/commit/594e767586494e821009f18fe8cbd96fe1b3703e)).
- [`rayon`] dependency for `parallel` features
([594e767](https://github.com/shnewto/bevy_collider_gen/commit/594e767586494e821009f18fe8cbd96fe1b3703e))
([1019ba6](https://github.com/shnewto/bevy_collider_gen/commit/1019ba697f0c3b20a633eaa55af7446193ab6e9e)).
- `ColliderType` enumeration
([618b5f7](https://github.com/shnewto/bevy_collider_gen/commit/618b5f7d081744a9f1eafee10ce9c0d21b95e1a9)).
- Functions `generate colliders`, `generate collider` for code maintainability
([618b5f7](https://github.com/shnewto/bevy_collider_gen/commit/618b5f7d081744a9f1eafee10ce9c0d21b95e1a9))
([56f3a2f](https://github.com/shnewto/bevy_collider_gen/commit/56f3a2faebab3190c170ecf68e2067fa51b1ce1c)).

### Changed

- Upgrade dependencies: [`edges`] 0.4
([e4c501f](https://github.com/shnewto/edges/commit/e4c501fa701a47c9ac67bd17e805ede77ad6485a)).
- The `rapier2d`, `parallel` features are enabled and `avian2d` are disabled by default
([f000104](https://github.com/shnewto/bevy_collider_gen/commit/f0001048d5000b34ef888fca76ccd26f3edeb3e9)).
- Dependencies [`bevy`] replaced by [`bevy_math`]
([d2079cb](https://github.com/shnewto/bevy_collider_gen/commit/d2079cb293d6aad43588ef849539c2e885de3e0c))
([42c750e](https://github.com/shnewto/bevy_collider_gen/commit/42c750ecdd9b4d8f167a20e204a6692ea1cd6bee)).
- `Edges` structure now in public external crate [`edges`]
([618b5f7](https://github.com/shnewto/bevy_collider_gen/commit/618b5f7d081744a9f1eafee10ce9c0d21b95e1a9)).

### Removed

- [`thiserror`] from dependencies
([2f1f35b](https://github.com/shnewto/bevy_collider_gen/commit/2f1f35b4f6275ad079b1fe76e1a976ba6a2c3b04)).
- Functions are removed for code maintainability
([618b5f7](https://github.com/shnewto/bevy_collider_gen/commit/618b5f7d081744a9f1eafee10ce9c0d21b95e1a9)):
- `single_polyline_collider_translated`
- `single_polyline_collider_raw`
- `single_convex_polyline_collider_translated`
- `single_convex_polyline_collider_raw`
- etc.

## [0.2.2](https://github.com/shnewto/bevy_collider_gen/compare/0.2.1...0.2.2) - 2024-08-14

### Added

- Feature `avian2d` and enabled by default for support [`avian2d`] colliders
([9cd6ac9](https://github.com/shnewto/bevy_collider_gen/commit/9cd6ac9f362fa867e6d1bf38b4f8681ac9d09754)).

### Changed

- Upgrade dependencies: [`bevy`] 0.14, [`bevy_prototype_lyon`] 0.12
([9cd6ac9](https://github.com/shnewto/bevy_collider_gen/commit/9cd6ac9f362fa867e6d1bf38b4f8681ac9d09754)).

### Removed

- Feature `xpbd_2d` and support for [`bevy_xpbd_2d`] colliders
([9cd6ac9](https://github.com/shnewto/bevy_collider_gen/commit/9cd6ac9f362fa867e6d1bf38b4f8681ac9d09754)).

## [0.2.1](https://github.com/shnewto/bevy_collider_gen/compare/0.2.0...0.2.1) - 2024-05-13

### Changed

- Upgrade dependencies: [`edges`] 0.3.2
([cbb8c5c](https://github.com/shnewto/bevy_collider_gen/commit/cbb8c5c1474f08bed0b405c76da3f99bd2b27540)).

## [0.2.0](https://github.com/shnewto/bevy_collider_gen/compare/0.1.0...0.2.0) - 2024-03-04

### Added

- Dependencies: [`thiserror`], [`edges`]
([01dc9be](https://github.com/shnewto/bevy_collider_gen/commit/01dc9be747fb971d3222702d203eb471d5b156d7)).
- `Edges` structure from [`edges`] crate
([01dc9be](https://github.com/shnewto/bevy_collider_gen/commit/01dc9be747fb971d3222702d203eb471d5b156d7)).

### Removed

- Functions ([01dc9be](https://github.com/shnewto/bevy_collider_gen/commit/01dc9be747fb971d3222702d203eb471d5b156d7)):
- `image_to_edges`
- `march_edges`
- `multi_image_edge_translated`
- `multi_image_edges_raw`
- `single_image_edge_raw`
- `single_image_edge_translated`
- `translate_vec`

[`bevy`]: https://crates.io/crates/bevy
[`bevy_math`]: https://crates.io/crates/bevy_math
[`avian2d`]: https://crates.io/crates/avian2d
[`rayon`]: https://crates.io/crates/rayon
[`edges`]: https://crates.io/crates/edges
[`thiserror`]: https://crates.io/crates/thiserror
[`bevy_prototype_lyon`]: https://crates.io/crates/bevy_prototype_lyon
[`bevy_xpbd_2d`]: https://crates.io/crates/bevy_xpbd_2d
23 changes: 18 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ description = "a library for generating colliders, for bevy apps, from images wi
keywords = ["bevy", "rapier", "png", "collider", "2d"]
readme = "README.md"

exclude = ["assets/*", ".github/*", "examples/*"]
include = ["/LICENSE-APACHE", "/LICENSE-MIT", "/README.md", "/src/"]

[lints.clippy]
cast_precision_loss = { level = "allow", priority = 1 }
pedantic = { level = "warn", priority = 0 }
Expand All @@ -22,9 +25,9 @@ rapier2d = ["dep:bevy_rapier2d"]
parallel = ["dep:rayon", "avian2d/parallel", "bevy_rapier2d/parallel"]

[dependencies]
edges = "0.4.0"
edges = "0.4"
salam99823 marked this conversation as resolved.
Show resolved Hide resolved
bevy_math = { version = "0.14", default-features = false }
rayon = { version = "1.10.0", optional = true }
rayon = { version = "1", optional = true }

[dependencies.bevy_rapier2d]
version = "0.27"
Expand All @@ -40,15 +43,25 @@ features = ["2d", "parry-f32"]

[dev-dependencies]
bevy = "0.14"
bevy_prototype_lyon = "0.12.0"
bevy_prototype_lyon = "0.12"
indoc = "2.0.4"

[dev-dependencies.bevy_rapier2d]
version = "0.27"
default-features = false
features = ["dim2", "headless", "debug-render-2d"]

[dev-dependencies.avian2d]
version = "0.1"
default-features = false
features = ["2d", "parry-f32", "debug-plugin"]

[[example]]
name = "avian2d_colliders"
path = "examples/avian2d_colliders.rs"
required-features = ["avian2d", "avian2d/debug-plugin"]
required-features = ["avian2d"]

[[example]]
name = "rapier2d_colliders"
path = "examples/rapier2d_colliders.rs"
required-features = ["rapier2d", "bevy_rapier2d/debug-render-2d"]
required-features = ["rapier2d"]
72 changes: 43 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@
[![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 2d colliders, for bevy apps, from images with transparency
A library for generating 2d colliders, for bevy apps, from images with transparency

## specifying your dependency
## Specifying your dependency

by default, both bevy_rapier2d and avian2d (formerly bevy_xpbd_2d) are enabled. this is to help with the out of box experience, specifically, being able to run both examples and tinker.
By default, both bevy_rapier2d and avian2d (formerly 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`
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]
# replace "*" with the most recent version of bevy_collider_gen
version = "*"
```

or this for `avian2d`
Or this for `avian2d`

```toml
[dependencies.bevy_collider_gen]
Expand All @@ -28,48 +32,54 @@ features = ["avian2d", "parallel"]
default-features = false
```

## example
## Example

![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
To see this in action you can run the example, with no arguments
it generates a scene with various colliders using PNG's in the `assets/sprite` directory

### bevy_rapier2d

#### note that you must have the rapier2d feature enabled

```sh
cargo run --example rapier2d_colliders -F "bevy_rapier2d/debug-render-2d"
cargo run --example rapier2d_colliders
```

### avian2d

#### note that you must have the avian2d feature enabled

```sh
cargo run --example avian2d_colliders -F "avian2d, avian2d/debug-plugin"
cargo run --example avian2d_colliders -F avian2d
```

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
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
## About / why

i was looking for a way to iterate on some 2d scenes with colliders on things with more sophisticated shapes than simple
geometry, i figured there should be enough info in an image with transparency to generate colliders, and... there is! so i
I was looking for a way to iterate on some 2d scenes with colliders
on things with more sophisticated shapes than simple
geometry, I figured there should be enough info in an image with
transparency to generate colliders, and... there is! So i
packaged up my approach here in case anyone else could benefit.

## how it works
## How it works

😄 head on over to the edges crate to learn more <https://github.com/shnewto/edges>

## caveats
## Caveats

- as mentioned here and there in these docs, this implementation requires images to have transparency in order to distinguish object from non-object :)
- i imagine for generating things at a larger scale, i.e. colliders for sets of sprites bigger than pixel counts in the hundreds, this implementation won't be performant to do at runtime. i'll suggest serializing the colliders you like and deserializing in your app instead of doing all the number crunching on load when you need a performance boost
- as mentioned here and there in these docs, this implementation requires
images to have transparency in order to distinguish object from non-object :)
- i imagine for generating things at a larger scale, i.e. colliders
for sets of sprites bigger than pixel counts in the hundreds, this implementation
won't be performant to do at runtime. I'll suggest serializing the colliders
you like and deserializing in your app instead of doing all the number crunching
on load when you need a performance boost

## examples of colliders generated for assets/sprite/car.png
## Examples of colliders generated for assets/sprite/car.png

(as in pictures of the sort of thing you can expect, not the runnable bevy app example. that's a couple headings up)
(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 (bevy_raiper2d only)

Expand All @@ -85,15 +95,19 @@ packaged up my approach here in case anyone else could benefit.

### heightfield

the current implementation does best if the image you're generating a heightfield from is either centered in the image
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_collider_gen/blob/main/img/heightfield.png?raw=true)

### convex decomposition

I didn't add support for convex decomposition directly because when sprites were small, and collisions were forceful, they were sort of unreliable (occasional panics because of bounds indexing in rapier's dependencies 💀). But if you wanted to use
convex decomposition colliders you could construct them with the edge coordinates from your image with something like this
I didn't add support for convex decomposition directly because when
sprites were small, and collisions were forceful, they were sort of unreliable
(occasional panics because of bounds indexing in rapier's dependencies 💀).
But if you wanted to use convex decomposition colliders you could construct
them with the edge coordinates from your image with something like this

```rust
let sprite_image = image_assets.get(sprite_handle.unwrap()).unwrap();
Expand All @@ -115,11 +129,11 @@ for coords in edge_coordinate_groups {

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

## license
## License

all code in this repository is dual-licensed under either:
All code in this repository is dual-licensed under either:

- MIT License (LICENSE-MIT or <http://opensource.org/licenses/MIT>)
- Apache License, Version 2.0 (LICENSE-APACHE or <http://www.apache.org/licenses/LICENSE-2.0>)

at your option.
At your option.
21 changes: 14 additions & 7 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
# Release Process

- leave the Cargo.toml package version alone :)
- trigger the `tag and publish crate [manual]` action and specify the release increment (major, minor, or patch)
- once the action completes, the Cargo.toml will be updated and the crate will be live on crates.io
- create a release (with title, notes, thanks, etc) and tie it to the tag that was created by the action / new crate version
- leave the `Cargo.toml` package version alone :)
- trigger the `tag and publish crate [manual]` action and specify
the release increment (major, minor, or patch)
- once the action completes, the `Cargo.toml`
will be updated and the crate will be live on `crates.io`
- create a release (with title, notes, thanks, etc)
and tie it to the tag that was created by the action / new crate version

## Execution

The order of operations for tagging and publishing in the action is this

1. run all checks, i.e. fmt, clippy, tests, etc
1. push change / update to the Cargo.toml
1. push change / update to the `Cargo.toml`
1. push the new tag to the repo
1. publish the new version to crates.io

## Troubleshooting

- if step 1 of execution fails, after addressing the error, you run the action again
- if step 2 of execution fails, after addressing the error, you run the action again
- if step 3 of execution fails (the Cargo.toml version was incremented), after addressing the error, you should manually tag (github's ux or the cli) and manually publish the crate with `cargo publish`
- if step 4 of execution fails (the Cargo.toml version was incremented and there's a new corresponding tag), after addressing the error, you should manually publish the crate with `cargo publish`
- if step 3 of execution fails (the `Cargo.toml` version was incremented),
after addressing the error, you should manually tag (github's ui or the cli)
and manually publish the crate with `cargo publish`
- if step 4 of execution fails
(the `Cargo.toml` version was incremented and there's a new corresponding tag),
after addressing the error, you should manually publish the crate with `cargo publish`
Loading
Loading