bevyengine / bevyengine/bevy

Gizmos as structs (and more !)

Open
#20,246 2 comments 1 reaction 0 assignees View on GitHub
A-Gizmos C-Feature S-Needs-Design-Doc X-Needs-SME
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

### Preface:

I love using gizmos, but they often feel like a closed ecosystem that doesn't integrate well with other parts of bevy.

I have a great plan that would make the system better integrated with bevy, more flexible, useful and make custom gizmos more accessible.

### Gizmos as trait

Currently, gizmo shapes are functions, that themselves call internal methods directly.
I think a saner and better way (for reasons that will be clear soon) would be to have gizmos internally use a intermediary struct, that other types can impl Into.
That would result in gizmos working similarly to how meshes do:

```rust
// mut gizmos: Gizmos,
// mut meshes: Res>

// In the same way that you can do
meshes.add(Circle::default())

// You could have
gizmos.draw(Circle::default().gizmo(Color::WHITE))
```

draw would take a `ìmpl Gizmoable` (WIP name) which is a trait that implements a `gizmo(&self, color: impl Into Color) -> Gizmo` method. (This doesn't play nice with multi color gizmos, but they could still be built with builders, and are a somewhat nich use in my experience)

### Gizmos as struct

So in my head Gizmo would look something like

```rust
pub struct Gizmo {
pub points: Vec,
pub colors: Vec
}
```

This would allow for every existing gizmo to be ported over, and would make it pretty trivial to port all of 'em.
We will also be able to have better organized gizmo composition patterns, allowing to easily combine existing gizmos into new gizmos, similar to how most gizmos are implemented today. (Gizmo::merge, etc..)

### Gizmos as Components

Now that we have this great Gizmo struct, we gain another superpower on top of all the others mentionned:
Gizmos as Components !
Drawing a gizmo becomes as simple as doing:
```rust
commands.spawn(
DrawGizmo(impl into Gizmo)
)
```
and bam, we now have the shortest way to draw an entity to the screen, easy debugging/prototyping/more for all !

With this more open system, it is simpler than ever to build on top of the great gizmos system to add new gizmos and expand it even further.

The actual code would be pretty simple, as only the frontend needs to change.

I am willing to take on the work myself.

PS: I'm no expert so pardon me if any/all of this is nonsense

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.