bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
35k stars 3.43k forks source link

Geometric primitives for UI #14187

Open viridia opened 2 months ago

viridia commented 2 months ago

What problem does this solve or what need does it fill?

There are many cases where it would be useful to draw geometric primitives within a UI context:

While Bevy has a rich set of geometric primitives, both 2d and 3d, they can't be used in a bevy_ui context but instead must be rendered on a separate layer. This means that you can't:

The reason this doesn't work is because bevy_ui nodes require certain components, such as Node and Style which are not present on 2d primitives. Simply inserting these components doesn't work either, for example adding Node will cause the entity to be rendered as a box, even if it also has a Mesh component.

What solution would you like?

Ideally, what I would like is a bundle (or whatever concept is going to replace bundles in the future). Just as we have various bevy_ui bundles for Node, ImageNode and so on, we'd have a UiGeometryBundle or something that would operate much like the current 2d primitives (with a Mesh, Material and so on), but would play nicely with bevy_ui.

What alternative(s) have you considered?

I've tried a number of workarounds to this, but none are satisfactory. The best approach so far is an SDF-based UiMaterial that renders geometric primitives, but it has a bunch of drawbacks:

alice-i-cecile commented 2 months ago

I think this is very reasonable, but I think this needs a bit more design on how UiGeometryBundle would be laid out, styled and so on.