Skip to content

Commit

Permalink
Migrate to Bevy 0.15.0-rc.2 (no Bevy Egui yet).
Browse files Browse the repository at this point in the history
  • Loading branch information
n3vu0r committed Oct 28, 2024
1 parent 3453d23 commit 14a8ee0
Show file tree
Hide file tree
Showing 12 changed files with 224 additions and 233 deletions.
9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_trackball"
version = "0.8.0"
version = "0.9.0"
rust-version = "1.80.0"
authors = ["Rouven Spreckels <[email protected]>"]
edition = "2021"
Expand Down Expand Up @@ -42,15 +42,16 @@ serialize = ["bevy/serialize", "trackball/serde"]
c11-orbit = ["trackball/cc"]

[dependencies]
bevy = { version = "0.14.2", default-features = false, features = ["bevy_render"] }
bevy = { version = "0.15.0-rc.2", default-features = false, features = ["bevy_render", "custom_cursor", "wayland"] }
bevy_egui = { version = "0.30.0", default-features = false, features = ["render"], optional = true }
trackball = { version = "0.14.0", features = ["glam"] }
trackball = { git = "https://github.com/qu1x/trackball", features = ["glam"] }

[dev-dependencies.bevy]
version = "0.14.2"
version = "0.15.0-rc.2"
default-features = false
features = [
"bevy_winit",
"custom_cursor",
"bevy_core_pipeline",
"bevy_pbr",
"ktx2",
Expand Down
112 changes: 49 additions & 63 deletions examples/constellation_clamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,14 @@ fn setup(

for (i, shape) in shapes.into_iter().enumerate() {
commands.spawn((
PbrBundle {
mesh: shape,
material: debug_material.clone(),
transform: Transform::from_xyz(
-SHAPES_X_EXTENT / 2. + i as f32 / (num_shapes - 1) as f32 * SHAPES_X_EXTENT,
2.0,
Z_EXTENT / 2.0,
)
.with_rotation(Quat::from_rotation_x(-PI / 4.)),
..default()
},
Mesh3d(shape),
MeshMaterial3d(debug_material.clone()),
Transform::from_xyz(
-SHAPES_X_EXTENT / 2. + i as f32 / (num_shapes - 1) as f32 * SHAPES_X_EXTENT,
2.0,
Z_EXTENT / 2.0,
)
.with_rotation(Quat::from_rotation_x(-PI / 4.)),
Shape,
));
}
Expand All @@ -121,41 +118,36 @@ fn setup(

for (i, shape) in extrusions.into_iter().enumerate() {
commands.spawn((
PbrBundle {
mesh: shape,
material: debug_material.clone(),
transform: Transform::from_xyz(
-EXTRUSION_X_EXTENT / 2.
+ i as f32 / (num_extrusions - 1) as f32 * EXTRUSION_X_EXTENT,
2.0,
-Z_EXTENT / 2.,
)
.with_rotation(Quat::from_rotation_x(-PI / 4.)),
..default()
},
Mesh3d(shape),
MeshMaterial3d(debug_material.clone()),
Transform::from_xyz(
-EXTRUSION_X_EXTENT / 2.
+ i as f32 / (num_extrusions - 1) as f32 * EXTRUSION_X_EXTENT,
2.0,
-Z_EXTENT / 2.,
)
.with_rotation(Quat::from_rotation_x(-PI / 4.)),
Shape,
));
}

// light
commands.spawn(PointLightBundle {
point_light: PointLight {
commands.spawn((
PointLight {
shadows_enabled: true,
intensity: 10_000_000.,
range: 100.0,
shadow_depth_bias: 0.2,
..default()
},
transform: Transform::from_xyz(8.0, 16.0, 8.0),
..default()
});
Transform::from_xyz(8.0, 16.0, 8.0),
));

// ground plane
commands.spawn(PbrBundle {
mesh: meshes.add(Plane3d::default().mesh().size(50.0, 50.0)),
material: materials.add(Color::from(SILVER)),
..default()
});
commands.spawn((
Mesh3d(meshes.add(Plane3d::default().mesh().size(50.0, 50.0))),
MeshMaterial3d(materials.add(Color::from(SILVER))),
));

// cameras and boundary conditions
let mut bound = Bound::default();
Expand All @@ -168,7 +160,7 @@ fn setup(
.spawn((
TrackballController::default(),
TrackballCamera::look_at(target, eye, up).with_clamp(bound.clone()),
Camera3dBundle::default(),
Camera3d::default(),
))
.id();
let window = windows.single();
Expand All @@ -180,50 +172,45 @@ fn setup(
TrackballCamera::look_at(target, down * (eye - target) + target, up)
.with_clamp(bound)
.add_controller(maximap, true),
Camera3dBundle {
camera: Camera {
order: 1,
clear_color: ClearColorConfig::None,
viewport: Some(Viewport {
physical_position: UVec2::new(
window.resolution.physical_width() - width,
window.resolution.physical_height() - height,
),
physical_size: UVec2::new(width, height),
..default()
}),
Camera {
order: 1,
clear_color: ClearColorConfig::None,
viewport: Some(Viewport {
physical_position: UVec2::new(
window.resolution.physical_width() - width,
window.resolution.physical_height() - height,
),
physical_size: UVec2::new(width, height),
..default()
},
}),
..default()
},
Camera3d::default(),
MinimapCamera,
));

// UI
#[cfg(not(target_arch = "wasm32"))]
commands.spawn((
TargetCamera(maximap),
TextBundle::from_section("Press space to toggle wireframes", TextStyle::default())
.with_style(Style {
position_type: PositionType::Absolute,
top: Val::Px(12.0),
left: Val::Px(12.0),
..default()
}),
Text::new("Press space to toggle wireframes"),
Node {
position_type: PositionType::Absolute,
top: Val::Px(12.0),
left: Val::Px(12.0),
..default()
},
));
commands.spawn((
Clamp,
TargetCamera(maximap),
TextBundle::from_section(
"Rigid Constellation Clamp (Toggle: Q)",
TextStyle::default(),
)
.with_style(Style {
Text::new("Rigid Constellation Clamp (Toggle: Q)"),
Node {
position_type: PositionType::Absolute,
bottom: Val::Px(10.0),
left: Val::Px(10.0),
..default()
}),
},
));
}

Expand Down Expand Up @@ -262,8 +249,7 @@ fn toggle_rigid_loose(
keycode: Res<ButtonInput<KeyCode>>,
) {
if keycode.just_pressed(KeyCode::KeyQ) {
let mut text = text.single_mut();
let text = &mut text.sections[0].value;
let text = &mut text.single_mut().0;
let mut minimap = minimap.single_mut();
let rigid = minimap.group.values_mut().next().unwrap();
if *rigid {
Expand All @@ -277,7 +263,7 @@ fn toggle_rigid_loose(

fn rotate(mut query: Query<&mut Transform, With<Shape>>, time: Res<Time>) {
for mut transform in &mut query {
transform.rotate_y(time.delta_seconds() / 2.);
transform.rotate_y(time.delta_secs() / 2.);
}
}

Expand Down
47 changes: 21 additions & 26 deletions examples/egui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,11 @@ fn setup(

// The cube that will be rendered to the texture.
commands
.spawn(PbrBundle {
mesh: cube_handle,
material: preview_material_handle,
transform: cube_transform,
..default()
})
.spawn((
Mesh3d(cube_handle),
MeshMaterial3d(preview_material_handle),
cube_transform,
))
.insert(PreviewPassCube)
.insert(preview_pass_layer.clone());

Expand All @@ -121,12 +120,11 @@ fn setup(
// Main pass cube.
let main_material_handle = materials.add(default_material);
commands
.spawn(PbrBundle {
mesh: cube_handle,
material: main_material_handle,
transform: cube_transform,
..default()
})
.spawn((
Mesh3d(cube_handle),
MeshMaterial3d(main_material_handle),
cube_transform,
))
.insert(MainPassCube);

// Defines initial transform of cameras and light.
Expand All @@ -137,15 +135,14 @@ fn setup(
// The same light is reused for both passes, you can specify different lights for preview and
// main pass by setting appropriate `RenderLayers`.
commands
.spawn(SpotLightBundle {
transform: Transform::from_translation(eye).looking_at(target, up),
spot_light: SpotLight {
.spawn((
Transform::from_translation(eye).looking_at(target, up),
SpotLight {
intensity: 10_000_000.0,
range: 100.0,
..default()
},
..default()
})
))
.insert(RenderLayers::default().with(1));

// The main pass camera with controller.
Expand All @@ -160,17 +157,15 @@ fn setup(
// UI camera sensitive to main pass camera's `controller`.
commands
.spawn((
Camera3dBundle {
camera: Camera {
// Render before the main pass camera.
order: -1,
target: RenderTarget::Image(image_handle),
clear_color: ClearColorConfig::Custom(Color::srgba(1.0, 1.0, 1.0, 0.0)),
..default()
},
TrackballCamera::look_at(target, eye, up).add_controller(controller, true),
Camera {
// Render before the main pass camera.
order: -1,
target: RenderTarget::Image(image_handle),
clear_color: ClearColorConfig::Custom(Color::srgba(1.0, 1.0, 1.0, 0.0)),
..default()
},
TrackballCamera::look_at(target, eye, up).add_controller(controller, true),
Camera3d::default(),
))
.insert(preview_pass_layer);
}
Expand Down
33 changes: 15 additions & 18 deletions examples/exponential_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,29 @@ fn setup(
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// circular base
commands.spawn(PbrBundle {
mesh: meshes.add(Circle::new(4.0)),
material: materials.add(Color::WHITE),
transform: Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
..default()
});
commands.spawn((
Mesh3d(meshes.add(Circle::new(4.0))),
MeshMaterial3d(materials.add(Color::WHITE)),
Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
));
// cube
commands.spawn(PbrBundle {
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)),
material: materials.add(Color::srgb_u8(124, 144, 255)),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default()
});
commands.spawn((
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
MeshMaterial3d(materials.add(Color::srgb_u8(124, 144, 255))),
Transform::from_xyz(0.0, 0.5, 0.0),
));
// light
commands.spawn(PointLightBundle {
point_light: PointLight {
commands.spawn((
PointLight {
shadows_enabled: true,
..default()
},
transform: Transform::from_xyz(4.0, 8.0, 4.0),
..default()
});
Transform::from_xyz(4.0, 8.0, 4.0),
));
// camera
commands.spawn((
TrackballController::default(),
TrackballCamera::look_at(Vec3::Y * 0.5, Vec3::new(-2.5, 4.5, 9.0), Vec3::Y),
Camera3dBundle::default(),
Camera3d::default(),
));
}
Loading

0 comments on commit 14a8ee0

Please sign in to comment.