Skip to content
This repository was archived by the owner on Oct 5, 2023. It is now read-only.

Commit c1de23b

Browse files
0.3.0
1 parent 245fb38 commit c1de23b

11 files changed

+357
-650
lines changed

CHANGELOG.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Changelog
2+
3+
> Dates are formatted as DD.MM.YYYY
4+
5+
## Version 0.3.0 (18.01.2023)
6+
7+
### Added
8+
9+
- Hover gizmo interactions
10+
11+
### Changed
12+
13+
- Much simpler API
14+
- Updated example
15+
- Entire backend
16+
17+
### Fixed
18+
19+
- Framerate was being limited to ~60
20+
- Gizmo flickering

Cargo.toml

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
[package]
22
name = "bevy_mod_gizmos"
3+
version = "0.3.0"
34
description = "Visual gizmos to aid with development and debugging in Bevy"
45
license = "MIT OR Apache-2.0"
56
repository = "https://github.com/LiamGallagher737/bevy_gizmos"
67
readme = "README.md"
7-
version = "0.2.0"
88
edition = "2021"
99
exclude = [".github/"]
1010

11-
[workspace]
12-
members = [
13-
"examples/*",
14-
]
15-
1611
[dependencies]
1712
bevy = "0.9"
18-
bevy_mod_picking = "0.10"
1913
lazy_static = "1.4"

README.md

+22-30
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Visual gizmos to aid with development and debugging in [Bevy](https://bevyengine.org/)
66

77
[<img alt="bevy tracking" src="https://img.shields.io/badge/Bevy%20tracking-released%20version-lightblue?style=for-the-badge" height="24">](https://github.com/bevyengine/bevy/blob/main/docs/plugins_guidelines.md#main-branch-tracking)
8-
[<img alt="build status" src="https://img.shields.io/github/workflow/status/LiamGallagher737/bevy_mod_gizmos/CI/main?style=for-the-badge" height="24">](https://github.com/LiamGallagher737/bevy_mod_gizmos/actions)
8+
[<img alt="build status" src="https://img.shields.io/github/actions/workflow/status/LiamGallagher737/bevy_mod_gizmos/rust.yml?branch=main&style=for-the-badge" height="24">](https://github.com/LiamGallagher737/bevy_mod_gizmos/actions)
99
[<img alt="github" src="https://img.shields.io/badge/github-bevy__mod__gizmos-8da0cb?style=for-the-badge&labelColor=555555&logo=github" height="24">](https://github.com/LiamGallagher737/bevy_mod_gizmos)
1010
[<img alt="crates.io" src="https://img.shields.io/crates/v/bevy_mod_gizmos.svg?style=for-the-badge&color=fc8d62&logo=rust" height="24">](https://crates.io/crates/bevy_mod_gizmos)
1111
[<img alt="docs.rs" src="https://img.shields.io/badge/docs.rs-bevy__mod__gizmos-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs" height="24">](https://docs.rs/bevy_mod_gizmos)
@@ -18,7 +18,7 @@ Visual gizmos to aid with development and debugging in [Bevy](https://bevyengine
1818

1919
Add the following to your `Cargo.toml`
2020
```toml
21-
bevy_mod_gizmos = "0.2.0"
21+
bevy_mod_gizmos = "0.3.0"
2222
```
2323

2424
Add this to any file you want to use gizmos in
@@ -46,7 +46,7 @@ opt-level = 3
4646

4747
# Demo
4848

49-
This exampels showcases all built-in gizmmo types and interactions. Click on a gizmo and it will print to the console its name.
49+
This examples showcases all built-in gizmo types and interactions. Click on a gizmo and it will print to the console its name.
5050

5151
```
5252
cargo run --example demo
@@ -56,53 +56,47 @@ cargo run --example demo
5656

5757
# Usage
5858

59-
Render a single gizmo
59+
Draw a single gizmo
6060
```rs
6161
draw_gizmo(gizmo);
6262
```
6363

64-
Render multiple gizmos and a connecting line
64+
Draw multiple gizmos
6565
```rs
66-
draw_gizmos(vec![gizmo, gizmo, gizmo], true);
66+
draw_gizmos(vec![gizmo, gizmo, gizmo]);
6767
```
6868

69-
Render a line
69+
Draw multiple gizmos and a connecting line
7070
```rs
71-
draw_line(points, color);
71+
draw_gizmos_with_line(vec![gizmo, gizmo, gizmo]);
7272
```
7373

74-
75-
76-
# Gizmos
77-
74+
Draw a line
7875
```rs
79-
Gizmo::sphere(position, size, color)
80-
```
81-
```rs
82-
Gizmo::cube(position, size, color)
83-
```
84-
```rs
85-
Gizmo::cubiod(position, scale, color)
86-
```
87-
```rs
88-
Gizmo::capsule(position, width, height, color)
76+
draw_line(points, color);
8977
```
78+
79+
Draw a closed line
9080
```rs
91-
Gizmo::torus(position, size, color)
81+
draw_closed_line(points, color);
9282
```
83+
84+
85+
86+
# Interactions
87+
9388
```rs
94-
Gizmo::new(position, scale, color, mesh_handle)
89+
Gizmo::new(translation, size, color).on_click(|| println!("Clicked!"))
90+
Gizmo::new(translation, size, color).on_hover(|| println!("Hovered!"))
9591
```
9692

97-
[More Info](https://docs.rs/bevy_mod_gizmos/latest/bevy_mod_gizmos/gizmo/struct.Gizmo.html)
98-
9993

10094

10195
# Bevy Tracking
10296

10397
|Bevy|bevy_mod_gizmos|
10498
|---|---|
105-
|0.9|0.2.0|
99+
|0.9|0.3.0|
106100
|0.7|0.1.1|
107101

108102

@@ -116,6 +110,4 @@ All code in this repository is dual-licensed under either:
116110

117111
at your option. This means you can select the license you prefer! This dual-licensing approach is the de-facto standard in the Rust ecosystem and there are [very good reasons](https://github.com/bevyengine/bevy/issues/2373) to include both.
118112

119-
Unless you explicitly state otherwise, any contribution intentionally submitted
120-
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any
121-
additional terms or conditions.
113+
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

examples/demo.rs

+22-35
Original file line numberDiff line numberDiff line change
@@ -9,51 +9,38 @@ fn main() {
99
.add_plugin(GizmosPlugin)
1010

1111
.add_startup_system(setup)
12-
.add_system(move_entities)
13-
.add_system(gizmos)
12+
.add_system(update)
13+
14+
.add_plugin(bevy::diagnostic::LogDiagnosticsPlugin::default())
15+
.add_plugin(bevy::diagnostic::EntityCountDiagnosticsPlugin::default())
1416

1517
.run();
1618
}
1719

18-
fn gizmos(query: Query<&Transform, Without<Camera>>) {
19-
let positions: Vec<Vec3> = query.iter().map(|t| t.translation).collect();
20-
draw_gizmos(
21-
vec![
22-
Gizmo::sphere(positions[0], 1.0, Color::GREEN).on_click(|_| println!("Clicked Sphere")),
23-
Gizmo::cube(positions[1], 1.0, Color::RED).on_click(|_| println!("Clicked Cube")),
24-
Gizmo::cubiod(positions[2], Vec3::new(1.0, 0.5, 1.5), Color::BLUE)
25-
.on_click(|_| println!("Clicked Cubiod")),
26-
Gizmo::capsule(positions[3], 1.0, 1.5, Color::ORANGE)
27-
.on_click(|_| println!("Clicked Capsule")),
28-
Gizmo::torus(positions[4], 1.0, Color::YELLOW).on_click(|_| println!("Clicked Torus")),
29-
],
30-
false, // Draw a line?
31-
);
32-
}
33-
3420
fn setup(mut commands: Commands) {
35-
// Spawn camera
36-
let cam_transform = Transform::from_xyz(4.0, 5.0, 8.0);
21+
println!("Trying hoering and clicking the center gizmo");
22+
23+
let cam_transform = Transform::from_xyz(0.0, 0.0, 8.0);
3724
commands.spawn((
3825
Camera3dBundle {
39-
transform: cam_transform.looking_at([4.0, 0.0, 0.0].into(), Vec3::Y),
26+
transform: cam_transform.looking_at(Vec3::ZERO, Vec3::Y),
4027
..Default::default()
4128
},
42-
GizmoInteractionCamera::default(),
29+
GizmoInteractionCamera,
4330
));
44-
45-
// Create one entity for each gizmo type
46-
for i in 0..5 {
47-
commands.spawn(TransformBundle::from_transform(Transform::from_xyz(
48-
i as f32 * 2.0,
49-
0.0,
50-
0.0,
51-
)));
52-
}
5331
}
5432

55-
fn move_entities(mut query: Query<&mut Transform, Without<Camera>>, time: Res<Time>) {
56-
for (i, mut transform) in query.iter_mut().enumerate() {
57-
transform.translation.y = (time.elapsed_seconds() + i as f32).sin();
58-
}
33+
fn update() {
34+
draw_gizmo(
35+
Gizmo::new(Vec3::ZERO, 1.0, Color::WHITE)
36+
.on_click(|| println!("Clicked!"))
37+
.on_hover(|| println!("Hovered")),
38+
);
39+
40+
draw_gizmos_with_line(vec![
41+
(Vec3::new(2.0, 2.0, 0.0), 0.5),
42+
(Vec3::new(-2.0, 2.0, 0.0), 0.25),
43+
(Vec3::new(-2.0, -2.0, 0.0), 0.75),
44+
(Vec3::new(2.0, -2.0, 0.0), 1.0),
45+
]);
5946
}

src/api.rs

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
use crate::{
2+
spawning::{GIZMO_SPAWN_BUFFER, LINE_SPAWN_BUFFER},
3+
Gizmo, Line,
4+
};
5+
use bevy::prelude::*;
6+
7+
/// Draw a single gizmo, it takes anything that implements `Into<Gizmo>`
8+
pub fn draw_gizmo<G: Into<Gizmo>>(gizmo: G) {
9+
if let Ok(mut gizmos) = GIZMO_SPAWN_BUFFER.write() {
10+
gizmos.push(gizmo.into());
11+
}
12+
}
13+
14+
/// Draw multiple gizmos, it takes a vec of anything that implements `Into<Gizmo>`
15+
pub fn draw_gizmos<G: Into<Gizmo>>(gizmos: Vec<G>) {
16+
if let Ok(mut gizmos_buf) = GIZMO_SPAWN_BUFFER.write() {
17+
for gizmo in gizmos {
18+
gizmos_buf.push(gizmo.into());
19+
}
20+
}
21+
}
22+
23+
/// Draw multiple gizmos with a connecting line, it takes a vec of anything that implements `Into<Gizmo>`
24+
pub fn draw_gizmos_with_line<G: Into<Gizmo>>(mut gizmos: Vec<G>) {
25+
let gizmos: Vec<Gizmo> = gizmos.drain(..).map(|g| g.into()).collect();
26+
draw_line(
27+
gizmos.iter().map(|g| g.translation).collect(),
28+
gizmos[0].color,
29+
);
30+
draw_gizmos(gizmos);
31+
}
32+
33+
/// Draw a line, it takes a vec of Vec3 points and a color
34+
pub fn draw_line(points: Vec<Vec3>, color: Color) {
35+
if let Ok(mut lines) = LINE_SPAWN_BUFFER.write() {
36+
lines.push(Line::new(points, color));
37+
}
38+
}
39+
40+
/// Draw a closed line, it takes a vec of Vec3 points and a color
41+
pub fn draw_closed_line(mut points: Vec<Vec3>, color: Color) {
42+
if points.is_empty() {
43+
return;
44+
}
45+
points.push(points[0]);
46+
if let Ok(mut lines) = LINE_SPAWN_BUFFER.write() {
47+
lines.push(Line::new(points, color));
48+
}
49+
}

src/basic.rs

-66
This file was deleted.

0 commit comments

Comments
 (0)