Skip to content

Commit

Permalink
Fixed examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ManevilleF committed Feb 21, 2024
1 parent 8feaa17 commit 1130996
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 37 deletions.
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ default-features = false
features = ["3d", "f32", "async-collider", "default-collider", "parry-f32"]

[dev-dependencies]
bevy-inspector-egui = "0.22"
bevy-inspector-egui = "0.23"
rand = "0.8"
bevy_xpbd_3d = "0.4"
bevy_rapier3d = "0.25"
Expand All @@ -56,8 +56,6 @@ features = [
"png",
"x11",
"tonemapping_luts",
# Faster compilation
"dynamic_linking"
]
default-features = false

Expand Down
2 changes: 1 addition & 1 deletion examples/anchors_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn main() {
App::new()
.insert_resource(AmbientLight {
color: Color::WHITE,
brightness: 1.0,
brightness: 500.0,
})
.add_plugins(DefaultPlugins)
.add_plugins(ResourceInspectorPlugin::<ClothConfig>::new())
Expand Down
2 changes: 1 addition & 1 deletion examples/balloon_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn main() {
App::new()
.insert_resource(AmbientLight {
color: Color::WHITE,
brightness: 1.0,
brightness: 100.0,
})
.add_plugins(DefaultPlugins)
.add_plugins(WorldInspectorPlugin::default())
Expand Down
60 changes: 33 additions & 27 deletions examples/camera_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,62 @@ use bevy::{

pub struct CameraPlugin;

#[derive(Debug, Component)]
pub struct OrbitController;

#[derive(Debug, Component)]
pub struct CameraController;

impl Plugin for CameraPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Startup, setup)
.add_systems(PostUpdate, handle_camera);
.add_systems(PostUpdate, (handle_rotation, handle_zoom));
log::info!("Camera Plugin loaded");
}
}

pub fn setup(mut commands: Commands) {
commands.spawn((
Camera3dBundle {
transform: Transform::from_xyz(-30.0, 30.0, -30.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
},
CameraController,
));
commands
.spawn((
TransformBundle::from_transform(Transform::from_rotation(Quat::from_rotation_z(-1.0))),
OrbitController,
))
.with_children(|b| {
b.spawn((
Camera3dBundle {
transform: Transform::from_xyz(0.0, 30.0, 0.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
},
CameraController,
));
});
}

pub fn handle_camera(
mut cam_controls: Query<&mut Transform, With<CameraController>>,
pub fn handle_rotation(
mut cam_controls: Query<&mut Transform, With<OrbitController>>,
mut motion_evr: EventReader<MouseMotion>,
mut scroll_evr: EventReader<MouseWheel>,
buttons: Res<ButtonInput<MouseButton>>,
time: Res<Time>,
) {
let delta_time = time.delta_seconds();
let mut transform = cam_controls.single_mut();
let forward = transform.local_z();
let right = transform.local_x();
let up = transform.local_y();
// Rotate
if buttons.pressed(MouseButton::Left) {
for ev in motion_evr.read() {
let delta = -ev.delta * delta_time * 0.1;
transform.rotate_y(delta.x);
transform.rotate_local_x(delta.y);
let delta = ev.delta * delta_time * 0.1;
transform.rotate_y(-delta.x);
transform.rotate_local_z(delta.y);
}
}
// Pan
if buttons.pressed(MouseButton::Right) {
for ev in motion_evr.read() {
let delta = ev.delta * delta_time;
transform.translation += -right * delta.x;
transform.translation += up * delta.y;
}
}
// Zoom
}

pub fn handle_zoom(
mut cam_controls: Query<&mut Transform, With<CameraController>>,
mut scroll_evr: EventReader<MouseWheel>,
time: Res<Time>,
) {
let delta_time = time.delta_seconds();
let mut transform = cam_controls.single_mut();
let forward = transform.forward();
for ev in scroll_evr.read() {
transform.translation += forward * ev.y * delta_time * 10.0;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/flag_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn main() {
App::new()
.insert_resource(AmbientLight {
color: Color::WHITE,
brightness: 1.0,
brightness: 100.0,
})
.add_plugins(DefaultPlugins)
.add_plugins(WorldInspectorPlugin::default())
Expand Down
2 changes: 1 addition & 1 deletion examples/moving_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn main() {
.register_type::<MovingAnimation>()
.insert_resource(AmbientLight {
color: Color::WHITE,
brightness: 1.0,
brightness: 500.0,
})
.add_plugins(DefaultPlugins)
.add_plugins(WorldInspectorPlugin::default())
Expand Down
2 changes: 1 addition & 1 deletion examples/rapier_collision_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn main() {
App::new()
.insert_resource(AmbientLight {
color: Color::WHITE,
brightness: 1.0,
brightness: 100.0,
})
.add_plugins(DefaultPlugins)
.add_plugins(RapierPhysicsPlugin::<NoUserData>::default())
Expand Down
2 changes: 1 addition & 1 deletion examples/xpbd_collision_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn main() {
App::new()
.insert_resource(AmbientLight {
color: Color::WHITE,
brightness: 1.0,
brightness: 100.0,
})
.add_plugins(DefaultPlugins)
.add_plugins(PhysicsPlugins::default())
Expand Down
2 changes: 1 addition & 1 deletion src/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub fn rectangle_mesh(

Mesh::new(
PrimitiveTopology::TriangleList,
RenderAssetUsages::MAIN_WORLD,
RenderAssetUsages::MAIN_WORLD | RenderAssetUsages::RENDER_WORLD,
)
.with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, points)
.with_inserted_attribute(Mesh::ATTRIBUTE_NORMAL, normals)
Expand Down

0 comments on commit 1130996

Please sign in to comment.