Upgrade to Bevy 0.19 and harden editor workflows
CI / Format, lint, test, build (push) Has been cancelled

This commit is contained in:
Rbanh committed 2026-07-09 23:43:47 -04:00
1 parent 3f85d25cc7
commit b5e561904c
204 files changed
+6972 -29907

No files matched your search

+54 -1
View File
@@ -67,6 +67,10 @@ pub fn hydrate_brushes(
}
}
#[expect(
clippy::too_many_arguments,
reason = "hydration keeps Bevy asset stores and authored brush inputs explicit"
)]
pub fn spawn_brush_mesh(
commands: &mut Commands,
asset_server: &AssetServer,
@@ -243,7 +247,12 @@ fn append_face(
for vertex in &face.vertices {
positions.push([vertex.x, vertex.y, vertex.z]);
normals.push([normal.x, normal.y, normal.z]);
let uv = Vec2::new(vertex.dot(u_axis), vertex.dot(v_axis)) * face.uv_scale + face.uv_offset;
let uv = transform_face_uv(
Vec2::new(vertex.dot(u_axis), vertex.dot(v_axis)),
face.uv_scale,
face.uv_rotation,
face.uv_offset,
);
uvs.push([uv.x, uv.y]);
}
@@ -262,6 +271,29 @@ fn append_face(
Some(())
}
fn transform_face_uv(base: Vec2, scale: Vec2, rotation_degrees: f32, offset: Vec2) -> Vec2 {
let scale = if scale.is_finite() { scale } else { Vec2::ONE };
let rotation_degrees = if rotation_degrees.is_finite() {
rotation_degrees
} else {
0.0
};
let offset = if offset.is_finite() {
offset
} else {
Vec2::ZERO
};
let scaled = base * scale;
if rotation_degrees == 0.0 {
return scaled + offset;
}
let (sin, cos) = rotation_degrees.to_radians().sin_cos();
Vec2::new(
scaled.x * cos - scaled.y * sin,
scaled.x * sin + scaled.y * cos,
) + offset
}
fn face_axes(normal: Vec3) -> (Vec3, Vec3) {
let tangent_seed = if normal.y.abs() > 0.9 {
Vec3::X
@@ -319,6 +351,27 @@ mod tests {
}));
}
#[test]
fn brush_face_uv_transform_applies_scale_rotation_and_offset() {
let uv = transform_face_uv(
Vec2::new(2.0, 1.0),
Vec2::new(2.0, 3.0),
90.0,
Vec2::new(0.25, -0.5),
);
assert!((uv.x + 2.75).abs() < 0.0001);
assert!((uv.y - 3.5).abs() < 0.0001);
let sanitized = transform_face_uv(
Vec2::new(2.0, 1.0),
Vec2::new(f32::NAN, 3.0),
f32::INFINITY,
Vec2::new(0.25, f32::NAN),
);
assert_eq!(sanitized, Vec2::new(2.0, 1.0));
}
#[test]
fn invalid_brush_returns_none() {
let mut brush = BrushDesc::default();
+17 -11
View File
@@ -77,6 +77,10 @@ pub(crate) fn normalized_directional_lux(intensity: f32) -> f32 {
/// Re-applies runtime lights when authoring [`LightDesc`] exists but hydration was stripped.
#[allow(clippy::type_complexity)]
#[expect(
clippy::too_many_arguments,
reason = "Bevy systems expose independent resource and query parameters"
)]
pub fn reconcile_missing_runtime_lights(
mut commands: Commands,
settings: Res<settings::ProjectSettings>,
@@ -140,7 +144,7 @@ pub(crate) fn insert_light_from_desc(
color,
intensity: light.intensity,
range: light.range,
shadows_enabled: light.shadows,
shadow_maps_enabled: light.shadows,
..default()
},
Visibility::Visible,
@@ -152,7 +156,7 @@ pub(crate) fn insert_light_from_desc(
color,
intensity: light.intensity,
range: light.range,
shadows_enabled: light.shadows,
shadow_maps_enabled: light.shadows,
outer_angle: light.outer_angle_deg.to_radians(),
inner_angle: light.inner_angle_deg.to_radians(),
..default()
@@ -165,7 +169,7 @@ pub(crate) fn insert_light_from_desc(
DirectionalLight {
color,
illuminance: normalized_directional_lux(light.intensity),
shadows_enabled: light.shadows,
shadow_maps_enabled: light.shadows,
..default()
},
Visibility::Visible,
@@ -192,7 +196,7 @@ mod tests {
let rendering = RenderingSettings::default();
let spot = LightDesc::for_kind(AuthoringLightKind::Spot);
{
let mut commands = Commands::new(&mut queue, &mut world);
let mut commands = Commands::new(&mut queue, &world);
let mut entity_commands = commands.entity(entity);
insert_light_from_desc(&mut entity_commands, &spot, &rendering);
}
@@ -202,7 +206,7 @@ mod tests {
let point = LightDesc::for_kind(AuthoringLightKind::Point);
queue = CommandQueue::default();
{
let mut commands = Commands::new(&mut queue, &mut world);
let mut commands = Commands::new(&mut queue, &world);
let mut entity_commands = commands.entity(entity);
strip_light_components(&mut entity_commands);
insert_light_from_desc(&mut entity_commands, &point, &rendering);
@@ -221,7 +225,7 @@ mod tests {
let mut light = LightDesc::for_kind(AuthoringLightKind::Directional);
light.shadows = true;
{
let mut commands = Commands::new(&mut queue, &mut world);
let mut commands = Commands::new(&mut queue, &world);
let mut entity_commands = commands.entity(entity);
insert_light_from_desc(&mut entity_commands, &light, &rendering);
}
@@ -239,10 +243,12 @@ mod tests {
#[test]
fn scene_directional_cascades_match_project_shadow_settings() {
let mut rendering = RenderingSettings::default();
rendering.shadow_cascades = 3;
rendering.shadow_first_cascade = 12.0;
rendering.shadow_max_distance = 400.0;
let rendering = RenderingSettings {
shadow_cascades: 3,
shadow_first_cascade: 12.0,
shadow_max_distance: 400.0,
..Default::default()
};
let config = cascade_config_from_rendering(&rendering);
let expected = cascade_config_from_rendering(&rendering);
assert_eq!(config.bounds, expected.bounds);
@@ -257,7 +263,7 @@ mod tests {
let spot_entity = world.spawn(LevelObject).id();
let rendering = RenderingSettings::default();
{
let mut commands = Commands::new(&mut queue, &mut world);
let mut commands = Commands::new(&mut queue, &world);
insert_light_from_desc(
&mut commands.entity(point_entity),
&LightDesc::for_kind(AuthoringLightKind::Point),
+5 -3
View File
@@ -79,9 +79,11 @@ mod tests {
let mut app = App::new();
app.add_plugins((MinimalPlugins, AssetPlugin::default()));
let asset_server = app.world().resource::<AssetServer>();
let mut desc = MaterialDesc::default();
desc.emissive_color = ColorDesc::srgb(0.5, 0.25, 1.0);
desc.emissive_intensity = 1000.0;
let desc = MaterialDesc {
emissive_color: ColorDesc::srgb(0.5, 0.25, 1.0),
emissive_intensity: 1000.0,
..Default::default()
};
let material = material_from_desc(asset_server, &desc);
+56 -11
View File
@@ -29,7 +29,10 @@ use static_meshes::{
hydrate_static_mesh_renderers, spawn_static_mesh_parts, HydratedStaticMeshPart,
StaticMeshArtifactCache,
};
use visibility::{init_editor_visibility_on_spawn, sync_editor_visibility};
use visibility::{
ensure_level_object_visibility_hierarchy, init_editor_visibility_on_spawn,
sync_editor_visibility, visibility_from_editor,
};
use crate::{
inspector_component_active, BrushDesc, ColliderDesc, EditorVisibility, InspectorOrder,
@@ -61,12 +64,21 @@ impl Plugin for HydrationPlugin {
)
.add_systems(
Update,
(sync_editor_visibility, init_editor_visibility_on_spawn).chain(),
(
ensure_level_object_visibility_hierarchy,
sync_editor_visibility,
init_editor_visibility_on_spawn,
)
.chain(),
);
}
}
/// Runs the full hydration chain immediately (e.g. after scene load in the editor).
#[expect(
clippy::type_complexity,
reason = "exclusive hydration snapshots several authored component combinations"
)]
pub fn flush_level_object_hydration(world: &mut World) {
if !world.contains_resource::<StaticMeshArtifactCache>() {
world.insert_resource(StaticMeshArtifactCache::default());
@@ -227,8 +239,9 @@ pub fn flush_level_object_hydration(world: &mut World) {
)> = SystemState::new(world);
{
let (mut commands, asset_server, mut meshes, mut materials, mut artifact_cache) =
state.get_mut(world);
let (mut commands, asset_server, mut meshes, mut materials, mut artifact_cache) = state
.get_mut(world)
.expect("hydrate_level_objects system params should be valid");
for (entity, primitive) in primitives {
let mesh = meshes.add(primitive_mesh(&primitive));
@@ -285,12 +298,21 @@ pub fn flush_level_object_hydration(world: &mut World) {
state.apply(world);
for (entity, editor) in visibility_targets {
let visibility = visibility_from_editor(editor);
if let Some(mut vis) = world.get_mut::<Visibility>(entity) {
*vis = if editor.visible {
Visibility::Visible
} else {
Visibility::Hidden
};
*vis = visibility;
} else if let Ok(mut entity_mut) = world.get_entity_mut(entity) {
entity_mut.insert(visibility);
}
if world.get::<InheritedVisibility>(entity).is_none() {
if let Ok(mut entity_mut) = world.get_entity_mut(entity) {
entity_mut.insert(InheritedVisibility::default());
}
}
if world.get::<ViewVisibility>(entity).is_none() {
if let Ok(mut entity_mut) = world.get_entity_mut(entity) {
entity_mut.insert(ViewVisibility::default());
}
}
}
}
@@ -300,8 +322,8 @@ mod tests {
use super::flush_level_object_hydration;
use super::strip::strip_hydrated_entity;
use crate::{
AuthoringLightKind, ColorDesc, InspectorOrder, LevelObject, LightDesc, MaterialDesc,
Primitive, COMPONENT_LIGHT_DESC,
AuthoringLightKind, ColorDesc, EditorVisibility, InspectorOrder, LevelObject, LightDesc,
MaterialDesc, Primitive, COMPONENT_LIGHT_DESC,
};
use avian3d::prelude::*;
use bevy::prelude::*;
@@ -324,6 +346,29 @@ mod tests {
assert!(app.world().get::<PointLight>(entity).is_some());
}
#[test]
fn flush_hydration_initializes_level_object_visibility_hierarchy() {
let mut app = App::new();
app.add_plugins(MinimalPlugins);
app.add_plugins(AssetPlugin::default());
app.add_plugins(bevy::pbr::MaterialPlugin::<StandardMaterial>::default());
app.init_asset::<Mesh>();
let entity = app
.world_mut()
.spawn((LevelObject, EditorVisibility { visible: false }))
.id();
flush_level_object_hydration(app.world_mut());
assert_eq!(
app.world().get::<Visibility>(entity),
Some(&Visibility::Hidden)
);
assert!(app.world().get::<InheritedVisibility>(entity).is_some());
assert!(app.world().get::<ViewVisibility>(entity).is_some());
}
#[test]
fn flush_hydration_skips_point_light_when_solari_is_active() {
let mut app = App::new();
+3 -3
View File
@@ -1,8 +1,8 @@
//! Imported model scenes from [`ModelRef`] authoring data.
use bevy::gltf::GltfAssetLabel;
use bevy::prelude::WorldAssetRoot;
use bevy::prelude::*;
use bevy::scene::SceneRoot;
use crate::{asset_server_path, LevelObject, ModelRef};
@@ -23,7 +23,7 @@ pub fn hydrate_models(
despawn_generated_children(&mut commands, entity, child_list);
}
commands.entity(entity).remove::<SceneRoot>();
commands.entity(entity).remove::<WorldAssetRoot>();
let path = asset_server_path(&model.path);
let handle = if path.ends_with(".fbx") {
@@ -31,6 +31,6 @@ pub fn hydrate_models(
} else {
asset_server.load(GltfAssetLabel::Scene(model.scene_index).from_asset(path))
};
commands.entity(entity).insert(SceneRoot(handle));
commands.entity(entity).insert(WorldAssetRoot(handle));
}
}
+3 -3
View File
@@ -1,7 +1,7 @@
//! Prefab scene roots from [`PrefabRef`] / [`PrefabInstance`] authoring data.
use bevy::prelude::DynamicWorldRoot;
use bevy::prelude::*;
use bevy::scene::DynamicSceneRoot;
use crate::{LevelObject, PrefabInstance, PrefabRef};
@@ -28,7 +28,7 @@ pub fn hydrate_prefabs(
>,
) {
for (entity, prefab) in &prefabs {
commands.entity(entity).insert(DynamicSceneRoot(
commands.entity(entity).insert(DynamicWorldRoot(
asset_server.load(asset_server_path(&prefab.path)),
));
}
@@ -37,7 +37,7 @@ pub fn hydrate_prefabs(
let path = asset_server_path(&instance.source_path);
commands.entity(entity).insert((
PrefabRef::new(instance.source_path.clone()),
DynamicSceneRoot(asset_server.load(path)),
DynamicWorldRoot(asset_server.load(path)),
));
}
}
@@ -202,6 +202,10 @@ pub fn hydrate_static_mesh_renderers(
}
}
#[expect(
clippy::too_many_arguments,
reason = "hydration keeps Bevy asset stores and authored mesh inputs explicit"
)]
pub fn spawn_static_mesh_parts(
commands: &mut Commands,
asset_server: &AssetServer,
+5 -6
View File
@@ -2,7 +2,6 @@
use avian3d::prelude::*;
use bevy::prelude::*;
use bevy::scene::{DynamicSceneRoot, SceneRoot};
/// Strips hydrated components via [`EntityWorldMut`] (e.g. before scene save).
pub fn strip_hydrated_entity(entity: &mut EntityWorldMut<'_>) {
@@ -12,8 +11,8 @@ pub fn strip_hydrated_entity(entity: &mut EntityWorldMut<'_>) {
.remove::<PointLight>()
.remove::<SpotLight>()
.remove::<DirectionalLight>()
.remove::<SceneRoot>()
.remove::<DynamicSceneRoot>()
.remove::<WorldAssetRoot>()
.remove::<DynamicWorldRoot>()
.remove::<RigidBody>()
.remove::<Collider>();
}
@@ -26,13 +25,13 @@ pub fn strip_hydrated(entity_commands: &mut EntityCommands<'_>) {
.remove::<PointLight>()
.remove::<SpotLight>()
.remove::<DirectionalLight>()
.remove::<SceneRoot>()
.remove::<DynamicSceneRoot>()
.remove::<WorldAssetRoot>()
.remove::<DynamicWorldRoot>()
.remove::<RigidBody>()
.remove::<Collider>();
}
/// Despawns all child entities (e.g. prior `SceneRoot` instance hierarchy).
/// Despawns all child entities (e.g. prior `WorldAssetRoot` instance hierarchy).
pub fn despawn_generated_children(commands: &mut Commands, entity: Entity, children: &Children) {
for child in children.iter() {
commands.entity(child).despawn();
+74 -10
View File
@@ -3,6 +3,41 @@
use crate::{EditorVisibility, LevelObject};
use bevy::prelude::*;
#[expect(
clippy::type_complexity,
reason = "the query mirrors Bevy's three visibility hierarchy components"
)]
pub fn ensure_level_object_visibility_hierarchy(
mut commands: Commands,
query: Query<
(
Entity,
&EditorVisibility,
Option<&Visibility>,
Option<&InheritedVisibility>,
Option<&ViewVisibility>,
),
With<LevelObject>,
>,
) {
for (entity, editor, visibility, inherited_visibility, view_visibility) in &query {
let mut entity_commands = commands.entity(entity);
if visibility.is_none() {
entity_commands.insert(visibility_from_editor(*editor));
}
if inherited_visibility.is_none() {
entity_commands.insert(InheritedVisibility::default());
}
if view_visibility.is_none() {
entity_commands.insert(ViewVisibility::default());
}
}
}
#[expect(
clippy::type_complexity,
reason = "the query expresses Bevy change detection at the system boundary"
)]
pub fn sync_editor_visibility(
mut query: Query<
(&EditorVisibility, &mut Visibility),
@@ -13,14 +48,14 @@ pub fn sync_editor_visibility(
>,
) {
for (editor, mut visibility) in query.iter_mut() {
*visibility = if editor.visible {
Visibility::Visible
} else {
Visibility::Hidden
};
*visibility = visibility_from_editor(*editor);
}
}
#[expect(
clippy::type_complexity,
reason = "the query expresses Bevy spawn detection at the system boundary"
)]
pub fn init_editor_visibility_on_spawn(
mut query: Query<
(&EditorVisibility, &mut Visibility),
@@ -32,10 +67,39 @@ pub fn init_editor_visibility_on_spawn(
>,
) {
for (editor, mut visibility) in query.iter_mut() {
*visibility = if editor.visible {
Visibility::Visible
} else {
Visibility::Hidden
};
*visibility = visibility_from_editor(*editor);
}
}
pub fn visibility_from_editor(editor: EditorVisibility) -> Visibility {
if editor.visible {
Visibility::Visible
} else {
Visibility::Hidden
}
}
#[cfg(test)]
mod tests {
use super::ensure_level_object_visibility_hierarchy;
use crate::{EditorVisibility, LevelObject};
use bevy::prelude::*;
#[test]
fn level_object_visibility_hierarchy_is_inserted_for_generated_children() {
let mut app = App::new();
app.add_systems(Update, ensure_level_object_visibility_hierarchy);
let entity = app
.world_mut()
.spawn((LevelObject, EditorVisibility { visible: false }))
.id();
app.update();
let world = app.world();
assert_eq!(world.get::<Visibility>(entity), Some(&Visibility::Hidden));
assert!(world.get::<InheritedVisibility>(entity).is_some());
assert!(world.get::<ViewVisibility>(entity).is_some());
}
}