mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 20:53:53 +00:00
f6b40a6e43
# Objective This PR aims to implement multiple configs for gizmos as discussed in #9187. ## Solution Configs for the new `GizmoConfigGroup`s are stored in a `GizmoConfigStore` resource and can be accesses using a type based key or iterated over. This type based key doubles as a standardized location where plugin authors can put their own configuration not covered by the standard `GizmoConfig` struct. For example the `AabbGizmoGroup` has a default color and toggle to show all AABBs. New configs can be registered using `app.init_gizmo_group::<T>()` during startup. When requesting the `Gizmos<T>` system parameter the generic type determines which config is used. The config structs are available through the `Gizmos` system parameter allowing for easy access while drawing your gizmos. Internally, resources and systems used for rendering (up to an including the extract system) are generic over the type based key and inserted on registering a new config. ## Alternatives The configs could be stored as components on entities with markers which would make better use of the ECS. I also implemented this approach ([here](https://github.com/jeliag/bevy/tree/gizmo-multiconf-comp)) and believe that the ergonomic benefits of a central config store outweigh the decreased use of the ECS. ## Unsafe Code Implementing system parameter by hand is unsafe but seems to be required to access the config store once and not on every gizmo draw function call. This is critical for performance. ~Is there a better way to do this?~ ## Future Work New gizmos (such as #10038, and ideas from #9400) will require custom configuration structs. Should there be a new custom config for every gizmo type, or should we group them together in a common configuration? (for example `EditorGizmoConfig`, or something more fine-grained) ## Changelog - Added `GizmoConfigStore` resource and `GizmoConfigGroup` trait - Added `init_gizmo_group` to `App` - Added early returns to gizmo drawing increasing performance when gizmos are disabled - Changed `GizmoConfig` and aabb gizmos to use new `GizmoConfigStore` - Changed `Gizmos` system parameter to use type based key to retrieve config - Changed resources and systems used for gizmo rendering to be generic over type based key - Changed examples (3d_gizmos, 2d_gizmos) to showcase new API ## Migration Guide - `GizmoConfig` is no longer a resource and has to be accessed through `GizmoConfigStore` resource. The default config group is `DefaultGizmoGroup`, but consider using your own custom config group if applicable. --------- Co-authored-by: Nicola Papale <nicopap@users.noreply.github.com>
32 lines
1.2 KiB
TOML
32 lines
1.2 KiB
TOML
[package]
|
|
name = "bevy_gizmos"
|
|
version = "0.12.0"
|
|
edition = "2021"
|
|
description = "Provides gizmos for Bevy Engine"
|
|
homepage = "https://bevyengine.org"
|
|
repository = "https://github.com/bevyengine/bevy"
|
|
license = "MIT OR Apache-2.0"
|
|
keywords = ["bevy"]
|
|
|
|
[features]
|
|
webgl = []
|
|
|
|
[dependencies]
|
|
# Bevy
|
|
bevy_pbr = { path = "../bevy_pbr", version = "0.12.0", optional = true }
|
|
bevy_sprite = { path = "../bevy_sprite", version = "0.12.0", optional = true }
|
|
bevy_app = { path = "../bevy_app", version = "0.12.0" }
|
|
bevy_ecs = { path = "../bevy_ecs", version = "0.12.0" }
|
|
bevy_math = { path = "../bevy_math", version = "0.12.0" }
|
|
bevy_asset = { path = "../bevy_asset", version = "0.12.0" }
|
|
bevy_render = { path = "../bevy_render", version = "0.12.0" }
|
|
bevy_utils = { path = "../bevy_utils", version = "0.12.0" }
|
|
bevy_core = { path = "../bevy_core", version = "0.12.0" }
|
|
bevy_reflect = { path = "../bevy_reflect", version = "0.12.0" }
|
|
bevy_core_pipeline = { path = "../bevy_core_pipeline", version = "0.12.0" }
|
|
bevy_transform = { path = "../bevy_transform", version = "0.12.0" }
|
|
bevy_log = { path = "../bevy_log", version = "0.12.0" }
|
|
bevy_gizmos_macros = { path = "macros", version = "0.12.0" }
|
|
|
|
[lints]
|
|
workspace = true
|