Crate bevy_shatter

Crate bevy_shatter 

Source
Expand description

§bevy_shatter

Procedural glass shattering plugin for the Bevy game engine

Note: This plugin uses avian3d for collider generation, but rapier3d integration should be trivial to add in the future

§Usage

Plugin

Add the ShatterPlugin to register the needed hooks and resources.

Creating glass

Add the Glass component to an entity, using the Transform::scale as width, height and thickness. A helper is available in AutoGlass to add other needed components automatically, such as a mesh and a transform with the correct scale.

Shattering glass

Add the Shattered component to an entity that has Glass, and glass shards will automatically be created.

§Customizing behaviour

This plugin prioritizes user control instead of guessing what the user wants to do, at a cost of convenience for the simpler use cases. You are responsible, for example, for adding RigidBody::Dynamic to each shard of glass (if that’s what you need), and you can customize the entities using hooks.

Making the original glass entity hidden

This plugin does not assume what you want to do with the original Glass entity. If you want it to be hidden when the glass shatters, this will have to be done manually by inserting Visibility::Hidden.

Shards

Are entities with the Shard component. You can use this to, for example, make an OnAdd hook that automatically makes shards have a dynamic rigid body when added.

Shard relationship

Shards and their Glass are related using ShardOf and Shards. You can use this to delete all the shards belonging to a glass, make all the shards have the same material as their glass, etc.

§Examples

See the examples/ folder.

§Compatibility

bevy_shatterbevy
0.1.00.16

§How it works

Currently, the glass is broken into cells using a voronoi diagram. These cells are then extruded to 3D, creating a shard.

Each cell’s position is chosen by dividing the glass into a grid, to ensure they are all roughly the same size, and then picking random points within each cell of the grid.

§Contributing

This plugin is in very early development. PRs and forks are welcome. See TODO.md for a list of things that are missing

Structs§

AutoGlass
Allows simpler glass spawning, by automatically adding the necessary components. Requires ShatterPlugin to have been added.
Glass
The component that marks an entity as glass that can be shattered. No other components are added to the entity, so you should add a material, mesh, etc. Feel free to take the mesh from GlassMesh. See AutoGlass for a quick way to spawn glass with some default components.
GlassMesh
Resource created by the plugin with a 1x1x1 cube mesh. Used by AutoGlass, but you can use it too.
Shard
Every glass shard has this component, so you can use it with a hook to customize the shards.
ShardOf
A glass shard is a ShardOf a certain glass. This allows you to get information on what glass caused certain shards to spawn.
Shards
A glass will have shards as its children. This allows you to get all the shards originating from a glass. With this, you could, for example, despawn the glass entity along with all of its shards.
ShatterPlugin
This plugin must be added for everything to work properly
Shattered
Add this component to an entity with the Glass component to shatter it, which creates all the glass shards.