Skip to content

Commit b20ff3e

Browse files
authored
refactor: remove DebugVisualizations (#123)
To be merged AFTER #121 . This PR would close #122 and #41 . <img width="1294" alt="image" src="https://github.com/user-attachments/assets/a79ea53e-7a72-475d-85c0-a526688d81b6" />
1 parent 7f58c0b commit b20ff3e

File tree

17 files changed

+93
-232
lines changed

17 files changed

+93
-232
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ This release supports Bevy version 0.14 and has an [MSRV][] of 1.80.
3636

3737
### Removed
3838

39+
- Removed `DebugVisualizations`. Now you should use `BorderColor` for UI Nodes and `Gizmos` for world assets. Several examples show this capability, such as the `svg` and `svg_ui` examples.
3940
- Removed `CoordinateSpace`. If you wish to render scene or asset UI, insert a `Node` component. For more information, see the `scene_ui`, `svg_ui`, or `lottie_ui` examples.
4041
- `VelloText` (with `CoordinateSpace::ScreenSpace`) can no longer render text in screen space. You should be using bevy's native `Text` for UI text, which is more feature rich and widely used.
4142

Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ bevy = { version = "0.15.2", default-features = false, features = [
3434
"multi_threaded",
3535
"x11",
3636
"tonemapping_luts",
37-
"bevy_gizmos",
3837
] }
3938

4039
[package]

examples/lottie/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ publish = false
99
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1010
[dependencies]
1111
bevy_vello = { path = "../../", features = ["lottie"] }
12-
bevy = { workspace = true }
12+
bevy = { workspace = true, features = ["bevy_gizmos"] }

examples/lottie/src/main.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ fn main() {
1111
..default()
1212
}))
1313
.add_plugins(VelloPlugin::default())
14-
.add_systems(Startup, load_lottie);
14+
.add_systems(Startup, load_lottie)
15+
.add_systems(Update, gizmos);
1516
embedded_asset!(app, "assets/Tiger.json");
1617
app.run();
1718
}
@@ -26,3 +27,23 @@ fn load_lottie(mut commands: Commands, asset_server: ResMut<AssetServer>) {
2627
))
2728
.insert(Transform::from_scale(Vec3::splat(0.5)));
2829
}
30+
31+
fn gizmos(
32+
svg: Single<(&VelloLottieHandle, &GlobalTransform)>,
33+
assets: Res<Assets<VelloLottie>>,
34+
mut gizmos: Gizmos,
35+
) {
36+
let (lottie, gtransform) = *svg;
37+
let Some(lottie) = assets.get(lottie.id()) else {
38+
return;
39+
};
40+
41+
gizmos.rect_2d(
42+
Isometry2d::new(
43+
gtransform.translation().xy(),
44+
Rot2::radians(gtransform.rotation().to_scaled_axis().z),
45+
),
46+
Vec2::new(lottie.width, lottie.height) * gtransform.scale().xy(),
47+
Color::WHITE,
48+
);
49+
}

examples/lottie_player/src/main.rs

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ fn setup_vector_graphics(mut commands: Commands, asset_server: ResMut<AssetServe
3333
),
3434
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 0.0))
3535
.with_scale(Vec3::splat(20.0)),
36-
debug_visualizations: DebugVisualizations::Visible,
3736
..default()
3837
})
3938
.insert(

examples/svg/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ publish = false
99
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1010
[dependencies]
1111
bevy_vello = { path = "../../", features = ["svg"] }
12-
bevy = { workspace = true }
12+
bevy = { workspace = true, features = ["bevy_gizmos"] }

examples/svg/src/main.rs

+26-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ fn main() {
1111
..default()
1212
}))
1313
.add_plugins(VelloPlugin::default())
14-
.add_systems(Startup, load_svg);
14+
.add_systems(Startup, load_svg)
15+
.add_systems(Update, (rotate, gizmos));
1516
embedded_asset!(app, "assets/fountain.svg");
1617
app.run();
1718
}
@@ -26,3 +27,27 @@ fn load_svg(mut commands: Commands, asset_server: ResMut<AssetServer>) {
2627
))
2728
.insert(Transform::from_scale(Vec3::splat(5.0)));
2829
}
30+
31+
fn rotate(mut svg: Single<&mut Transform, With<VelloSvgHandle>>, time: Res<Time>) {
32+
svg.rotate_z(-0.5 * time.delta_secs());
33+
}
34+
35+
fn gizmos(
36+
svg: Single<(&VelloSvgHandle, &GlobalTransform)>,
37+
assets: Res<Assets<VelloSvg>>,
38+
mut gizmos: Gizmos,
39+
) {
40+
let (svg, gtransform) = *svg;
41+
let Some(svg) = assets.get(svg.id()) else {
42+
return;
43+
};
44+
45+
gizmos.rect_2d(
46+
Isometry2d::new(
47+
gtransform.translation().xy(),
48+
Rot2::radians(gtransform.rotation().to_scaled_axis().z),
49+
),
50+
Vec2::new(svg.width, svg.height) * gtransform.scale().xy(),
51+
Color::WHITE,
52+
);
53+
}

examples/text/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ publish = false
99
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1010
[dependencies]
1111
bevy_vello = { path = "../../", features = ["default_font"] }
12-
bevy = { workspace = true, features = ["default_font"] }
12+
bevy = { workspace = true, features = ["default_font", "bevy_gizmos"] }

examples/text/src/main.rs

+38-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::f32::consts::PI;
2+
13
use bevy::{
24
asset::{embedded_asset, AssetMetaCheck},
35
prelude::*,
@@ -14,7 +16,8 @@ fn main() {
1416
.add_systems(
1517
Startup,
1618
(setup_camera, setup_screenspace_text, setup_worldspace_text),
17-
);
19+
)
20+
.add_systems(Update, gizmos);
1821
embedded_asset!(app, "assets/Rubik-Medium.ttf");
1922
app.run();
2023
}
@@ -29,7 +32,6 @@ fn setup_worldspace_text(mut commands: Commands, asset_server: ResMut<AssetServe
2932
value: "Default font\nand multi-line support.".to_string(),
3033
..default()
3134
})
32-
.insert(DebugVisualizations::Visible)
3335
.insert(VelloTextAnchor::Center);
3436

3537
commands.spawn(VelloTextBundle {
@@ -42,25 +44,51 @@ fn setup_worldspace_text(mut commands: Commands, asset_server: ResMut<AssetServe
4244
},
4345
},
4446
text_anchor: VelloTextAnchor::Center,
45-
transform: Transform::from_xyz(0.0, -100.0, 0.0),
46-
debug_visualizations: DebugVisualizations::Visible,
47+
transform: Transform::from_xyz(0.0, -100.0, 0.0)
48+
.with_rotation(Quat::from_rotation_z(PI / 12.0)),
4749
..default()
4850
});
4951
}
5052

5153
fn setup_screenspace_text(mut commands: Commands) {
5254
// Bevy text
5355
commands
54-
.spawn(Node {
55-
position_type: PositionType::Absolute,
56-
top: Val::Px(100.0),
57-
left: Val::Px(100.0),
58-
..default()
59-
})
56+
.spawn((
57+
Node {
58+
position_type: PositionType::Absolute,
59+
top: Val::Px(100.0),
60+
left: Val::Px(100.0),
61+
..default()
62+
},
63+
BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
64+
))
6065
.insert(Text::new("Use bevy's Text for UI text!"))
6166
.insert(TextFont {
6267
font_size: 24.,
6368
..default()
6469
})
6570
.insert(TextLayout::new_with_justify(JustifyText::Left));
6671
}
72+
73+
fn gizmos(
74+
texts: Query<(&VelloTextSection, &GlobalTransform)>,
75+
assets: Res<Assets<VelloFont>>,
76+
mut gizmos: Gizmos,
77+
) {
78+
for (text, gtransform) in texts.iter() {
79+
let Some(font) = assets.get(text.style.font.id()) else {
80+
continue;
81+
};
82+
83+
let bb_size = font.sizeof(text);
84+
85+
gizmos.rect_2d(
86+
Isometry2d::new(
87+
gtransform.translation().xy(),
88+
Rot2::radians(gtransform.rotation().to_scaled_axis().z),
89+
),
90+
bb_size * gtransform.scale().xy(),
91+
Color::WHITE,
92+
);
93+
}
94+
}

src/debug.rs

-199
This file was deleted.

0 commit comments

Comments
 (0)