Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to update for Bevy 0.2 #10

Merged
merged 4 commits into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bevy_rapier2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ serde-serialize = [ "rapier2d/serde-serialize" ]
enhanced-determinism = [ "rapier2d/enhanced-determinism" ]

[dependencies]
bevy = "0.1"
bevy = "0.2"
nalgebra = "0.22"
rapier2d = "0.1"
concurrent-queue = "1"

[dev-dependencies]
bevy_fly_camera = "0.1"

6 changes: 3 additions & 3 deletions bevy_rapier2d/examples/boxes2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn main() {
0xF9 as f32 / 255.0,
0xFF as f32 / 255.0,
)))
.add_resource(Msaa { samples: 2 })
Copy link
Contributor Author

@CleanCut CleanCut Sep 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On macOS this crashes with the following error on both Bevy 0.1.x and Bevy 0.2.x:

thread 'main' panicked at 'attachment's sample count 2 is invalid', /Users/nathan/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/wgpu-0.6.0/src/backend/direct.rs:1323:35

.add_resource(Msaa::default())
.add_default_plugins()
.add_plugin(RapierPhysicsPlugin)
.add_plugin(RapierRenderPlugin)
Expand All @@ -39,11 +39,11 @@ fn setup_graphics(mut commands: Commands, mut scale: ResMut<RapierPhysicsScale>)

commands
.spawn(LightComponents {
translation: Translation::new(1000.0, 100.0, 2000.0),
transform: Transform::from_translation(Vec3::new(1000.0, 100.0, 2000.0)),
..Default::default()
})
.spawn(Camera2dComponents {
translation: Translation::new(0.0, 200.0, 0.0),
transform: Transform::from_translation(Vec3::new(0.0, 200.0, 0.0)),
..Camera2dComponents::default()
});
}
Expand Down
6 changes: 3 additions & 3 deletions bevy_rapier2d/examples/events2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn main() {
0xF9 as f32 / 255.0,
0xFF as f32 / 255.0,
)))
.add_resource(Msaa { samples: 2 })
.add_resource(Msaa::default())
.add_default_plugins()
.add_plugin(RapierPhysicsPlugin)
.add_plugin(RapierRenderPlugin)
Expand All @@ -40,11 +40,11 @@ fn setup_graphics(mut commands: Commands, mut scale: ResMut<RapierPhysicsScale>)

commands
.spawn(LightComponents {
translation: Translation::new(1000.0, 100.0, 2000.0),
transform: Transform::from_translation(Vec3::new(1000.0, 100.0, 2000.0)),
..Default::default()
})
.spawn(Camera2dComponents {
translation: Translation::new(0.0, 0.0, 0.0),
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 0.0)),
..Camera2dComponents::default()
});
}
Expand Down
6 changes: 3 additions & 3 deletions bevy_rapier2d/examples/joints2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn main() {
0xF9 as f32 / 255.0,
0xFF as f32 / 255.0,
)))
.add_resource(Msaa { samples: 2 })
.add_resource(Msaa::default())
.add_default_plugins()
.add_plugin(RapierPhysicsPlugin)
.add_plugin(RapierRenderPlugin)
Expand All @@ -41,11 +41,11 @@ fn setup_graphics(mut commands: Commands, mut scale: ResMut<RapierPhysicsScale>)

commands
.spawn(LightComponents {
translation: Translation::new(1000.0, 100.0, 2000.0),
transform: Transform::from_translation(Vec3::new(1000.0, 100.0, 2000.0)),
..Default::default()
})
.spawn(Camera2dComponents {
translation: Translation::new(200.0, -200.0, 0.0),
transform: Transform::from_translation(Vec3::new(200.0, -200.0, 0.0)),
..Camera2dComponents::default()
});
}
Expand Down
3 changes: 1 addition & 2 deletions bevy_rapier3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ serde-serialize = [ "rapier3d/serde-serialize" ]
enhanced-determinism = [ "rapier3d/enhanced-determinism" ]

[dependencies]
bevy = "0.1"
bevy = "0.2"
nalgebra = "0.22"
rapier3d = "0.1"
concurrent-queue = "1"

[dev-dependencies]
bevy_fly_camera = "0.1"
6 changes: 3 additions & 3 deletions bevy_rapier3d/examples/boxes3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn main() {
0xF9 as f32 / 255.0,
0xFF as f32 / 255.0,
)))
.add_resource(Msaa { samples: 2 })
.add_resource(Msaa::default())
.add_default_plugins()
.add_plugin(RapierPhysicsPlugin)
.add_plugin(RapierRenderPlugin)
Expand All @@ -37,11 +37,11 @@ fn enable_physics_profiling(mut pipeline: ResMut<PhysicsPipeline>) {
fn setup_graphics(mut commands: Commands) {
commands
.spawn(LightComponents {
translation: Translation::new(1000.0, 100.0, 2000.0),
transform: Transform::from_translation(Vec3::new(1000.0, 100.0, 2000.0)),
..Default::default()
})
.spawn(Camera3dComponents {
transform: Transform::new_sync_disabled(Mat4::face_toward(
transform: Transform::new(Mat4::face_toward(
Vec3::new(-30.0, 30.0, 100.0),
Vec3::new(0.0, 10.0, 0.0),
Vec3::new(0.0, 1.0, 0.0),
Expand Down
6 changes: 3 additions & 3 deletions bevy_rapier3d/examples/events3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn main() {
0xF9 as f32 / 255.0,
0xFF as f32 / 255.0,
)))
.add_resource(Msaa { samples: 2 })
.add_resource(Msaa::default())
.add_default_plugins()
.add_plugin(RapierPhysicsPlugin)
.add_plugin(RapierRenderPlugin)
Expand All @@ -38,11 +38,11 @@ fn enable_physics_profiling(mut pipeline: ResMut<PhysicsPipeline>) {
fn setup_graphics(mut commands: Commands) {
commands
.spawn(LightComponents {
translation: Translation::new(1000.0, 100.0, 2000.0),
transform: Transform::from_translation(Vec3::new(1000.0, 100.0, 2000.0)),
..Default::default()
})
.spawn(Camera3dComponents {
transform: Transform::new_sync_disabled(Mat4::face_toward(
transform: Transform::new(Mat4::face_toward(
Vec3::new(0.0, 0.0, 25.0),
Vec3::new(0.0, 0.0, 0.0),
Vec3::new(0.0, 1.0, 0.0),
Expand Down
6 changes: 3 additions & 3 deletions bevy_rapier3d/examples/joints3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn main() {
0xF9 as f32 / 255.0,
0xFF as f32 / 255.0,
)))
.add_resource(Msaa { samples: 2 })
.add_resource(Msaa::default())
.add_default_plugins()
.add_plugin(RapierPhysicsPlugin)
.add_plugin(RapierRenderPlugin)
Expand All @@ -40,11 +40,11 @@ fn enable_physics_profiling(mut pipeline: ResMut<PhysicsPipeline>) {
fn setup_graphics(mut commands: Commands) {
commands
.spawn(LightComponents {
translation: Translation::new(1000.0, 100.0, 2000.0),
transform: Transform::from_translation(Vec3::new(1000.0, 100.0, 2000.0)),
..Default::default()
})
.spawn(Camera3dComponents {
transform: Transform::new_sync_disabled(Mat4::face_toward(
Copy link
Contributor Author

@CleanCut CleanCut Sep 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method was removed in Bevy 0.2.0.

Since the release blog post mentioned disabling sync was an unwanted workaround on the old transform system, I guessed that it was no longer necessary and switched to ::new():

  • Setting a Transform to a specific matrix value (ex: Mat4::look_at()) was extremely cumbersome, and the value would be immediately overwritten unless the user explicitly disabled component syncing.

transform: Transform::new(Mat4::face_toward(
Vec3::new(15.0, 5.0, 42.0),
Vec3::new(13.0, 1.0, 1.0),
Vec3::new(0.0, 1.0, 0.0),
Expand Down
17 changes: 7 additions & 10 deletions src/physics/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,35 +93,32 @@ pub fn sync_transform_system(
bodies: ResMut<RigidBodySet>,
scale: Res<RapierPhysicsScale>,
rigid_body: &RigidBodyHandleComponent,
mut translation: Mut<Translation>,
mut rotation: Mut<Rotation>,
mut transform: Mut<Transform>,
) {
if let Some(rb) = bodies.get(rigid_body.handle()) {
let pos = rb.position;

#[cfg(feature = "dim2")]
{
let rot = na::UnitQuaternion::new(na::Vector3::z() * pos.rotation.angle());

*translation.0.x_mut() = pos.translation.vector.x * scale.0;
*translation.0.y_mut() = pos.translation.vector.y * scale.0;
rotation.0 = Quat::from_xyzw(rot.i, rot.j, rot.k, rot.w);
transform.set_translation(Vec3::new(pos.translation.vector.x * scale.0, pos.translation.vector.y * scale.0, 0.0));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guessed that the z value for 2d should be 0.0 here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

z value is used in bevy for sprite layering, so I think rapier should not touch the value set originally by the user.

transform.set_rotation(Quat::from_xyzw(rot.i, rot.j, rot.k, rot.w));
}

#[cfg(feature = "dim3")]
{
translation.0 = Vec3::new(
transform.set_translation(Vec3::new(
pos.translation.vector.x,
pos.translation.vector.y,
pos.translation.vector.z,
) * scale.0;
) * scale.0);

rotation.0 = Quat::from_xyzw(
transform.set_rotation(Quat::from_xyzw(
pos.rotation.i,
pos.rotation.j,
pos.rotation.k,
pos.rotation.w,
);
));
}
}
}
16 changes: 2 additions & 14 deletions src/render/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,11 @@ pub fn create_collider_renders_system(
let ground_pbr = PbrComponents {
mesh: meshes.add(mesh),
material: materials.add(color.into()),
transform: Transform::from_non_uniform_scale(scale),
..Default::default()
};

commands.insert(
entity,
(
ground_pbr.mesh,
ground_pbr.material,
ground_pbr.main_pass,
ground_pbr.draw,
ground_pbr.render_pipelines,
ground_pbr.transform,
ground_pbr.translation,
ground_pbr.rotation,
NonUniformScale(scale),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not certain if there's some additional component that's supposed to be added to indicate that there's a non-uniform scale that should be looked at.

),
);
commands.insert(entity, ground_pbr);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src_debug_ui/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bevy::prelude::*;
use rapier::pipeline::PhysicsPipeline;

pub fn setup_ui(mut commands: Commands, asset_server: Res<AssetServer>) {
let font_handle = asset_server.load("assets/FiraSans-Bold.ttf").unwrap();
let font_handle = asset_server.load("../assets/FiraSans-Bold.ttf").unwrap();
commands
// 2d camera
.spawn(UiCameraComponents::default())
Expand Down