Skip to content

Commit daf62fe

Browse files
authored
Merge pull request #20 from johanhelsing/f64-feature
Add `f64` feature
2 parents 11499ef + f0040c6 commit daf62fe

31 files changed

+1087
-768
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
uses: actions-rs/cargo@v1
4545
with:
4646
command: test
47-
args: --no-default-features --features enhanced_determinism,bevy_xpbd_2d/2d,bevy_xpbd_3d/3d
47+
args: --no-default-features --features enhanced_determinism,bevy_xpbd_2d/2d,bevy_xpbd_3d/3d,bevy_xpbd_2d/f64,bevy_xpbd_3d/f64
4848

4949
lints:
5050
name: Lints
@@ -71,4 +71,4 @@ jobs:
7171
uses: actions-rs/cargo@v1
7272
with:
7373
command: clippy
74-
args: -- -D warnings
74+
args: -- -D warnings

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
[workspace]
2-
members = [ "crates/bevy_xpbd_2d", "crates/bevy_xpbd_3d" ]
2+
members = [
3+
"crates/bevy_xpbd_2d",
4+
"crates/bevy_xpbd_3d"
5+
]
36
resolver = "2"
47

58
[profile.dev]

crates/bevy_xpbd_2d/Cargo.toml

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ version = "0.1.0"
44
edition = "2021"
55

66
[features]
7-
default = [ "2d", "simd" ]
7+
default = [ "2d", "f32", "simd" ]
88
2d = []
9-
debug-render-aabbs = [ "bevy_prototype_debug_lines" ]
10-
simd = [ "parry2d/simd-stable" ]
11-
enhanced_determinism = [ "parry2d/enhanced-determinism" ]
9+
f32 = [ "dep:parry2d" ]
10+
f64 = [ "dep:parry2d-f64" ]
11+
debug-render-aabbs = [ "dep:bevy_prototype_debug_lines" ]
12+
simd = [ "parry2d?/simd-stable", "parry2d-f64?/simd-stable" ]
13+
enhanced_determinism = [ "parry2d?/enhanced-determinism", "parry2d-f64?/enhanced-determinism" ]
1214

1315
[lib]
1416
name = "bevy_xpbd_2d"
@@ -18,7 +20,8 @@ required-features = [ "2d" ]
1820
[dependencies]
1921
bevy = { version = "0.10", default-features = false }
2022
bevy_prototype_debug_lines = { version = "0.10", optional = true }
21-
parry2d = "0.13.1"
23+
parry2d = { version = "0.13.1", optional = true }
24+
parry2d-f64 = { version = "0.13.1", optional = true }
2225
nalgebra = { version = "0.32.2", features = [ "convert-glam023" ] }
2326
console_error_panic_hook = "0.1.7"
2427
web-sys = "0.3.59"
@@ -30,3 +33,23 @@ approx = "0.5"
3033
glam = { version = "0.23", features = [ "approx" ] }
3134
insta = "1.0"
3235
itertools = "0.10"
36+
37+
[[example]]
38+
name = "chain2d"
39+
required-features = ["2d", "f32"]
40+
41+
[[example]]
42+
name = "fixed_joint_2d"
43+
required-features = ["2d", "f32"]
44+
45+
[[example]]
46+
name = "move_marbles"
47+
required-features = ["2d", "f32"]
48+
49+
[[example]]
50+
name = "prismatic_joint_2d"
51+
required-features = ["2d", "f32"]
52+
53+
[[example]]
54+
name = "revolute_joint_2d"
55+
required-features = ["2d", "f32"]

crates/bevy_xpbd_2d/examples/chain2d.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ fn mouse_position(
109109
let window = windows.single();
110110
let (camera, camera_transform) = q_camera.single();
111111
if let Some(pos) = window.cursor_position() {
112-
let window_size = Vec2::new(window.width() as f32, window.height() as f32);
112+
let window_size = Vec2::new(window.width(), window.height());
113113

114114
// convert screen position [0..resolution] to ndc [-1..1] (gpu coordinates)
115115
let ndc = (pos / window_size) * 2.0 - Vec2::ONE;

crates/bevy_xpbd_2d/snapshots/bevy_xpbd_2d__tests__body_with_velocity_moves.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ expression: transform
44
---
55
Transform {
66
translation: Vec3(
7-
8.316475,
7+
8.316667,
88
0.0,
99
0.0,
1010
),

crates/bevy_xpbd_3d/Cargo.toml

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ version = "0.1.0"
44
edition = "2021"
55

66
[features]
7-
default = [ "3d", "simd" ]
7+
default = [ "3d", "f32", "simd" ]
88
3d = []
9-
debug-render-aabbs = [ "bevy_prototype_debug_lines" ]
10-
simd = [ "parry3d/simd-stable" ]
11-
enhanced_determinism = [ "parry3d/enhanced-determinism" ]
9+
f32 = [ "dep:parry3d" ]
10+
f64 = [ "dep:parry3d-f64" ]
11+
debug-render-aabbs = [ "dep:bevy_prototype_debug_lines" ]
12+
simd = [ "parry3d?/simd-stable", "parry3d-f64?/simd-stable" ]
13+
enhanced_determinism = [ "parry3d?/enhanced-determinism", "parry3d-f64?/enhanced-determinism" ]
1214

1315
[lib]
1416
name = "bevy_xpbd_3d"
@@ -18,7 +20,8 @@ required-features = [ "3d" ]
1820
[dependencies]
1921
bevy = { version = "0.10", default-features = false }
2022
bevy_prototype_debug_lines = { version = "0.10", optional = true, features = [ "3d" ] }
21-
parry3d = "0.13.1"
23+
parry3d = { version = "0.13.1", optional = true }
24+
parry3d-f64 = { version = "0.13.1", optional = true }
2225
nalgebra = { version = "0.32.2", features = [ "convert-glam023" ] }
2326
console_error_panic_hook = "0.1"
2427
web-sys = "0.3.59"
@@ -30,3 +33,31 @@ approx = "0.5"
3033
glam = { version = "0.23", features = [ "approx" ] }
3134
insta = "1.0"
3235
itertools = "0.10"
36+
37+
[[example]]
38+
name = "chain3d"
39+
required-features = ["3d", "f32"]
40+
41+
[[example]]
42+
name = "cubes"
43+
required-features = ["3d", "f32"]
44+
45+
[[example]]
46+
name = "cubes_f64"
47+
required-features = ["3d", "f64"]
48+
49+
[[example]]
50+
name = "fixed_joint_3d"
51+
required-features = ["3d", "f32"]
52+
53+
[[example]]
54+
name = "prismatic_joint_3d"
55+
required-features = ["3d", "f32"]
56+
57+
[[example]]
58+
name = "revolute_joint_3d"
59+
required-features = ["3d", "f32"]
60+
61+
[[example]]
62+
name = "rolling_balls"
63+
required-features = ["3d", "f32"]
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
use bevy::{math::DVec3, prelude::*};
2+
use bevy_xpbd_3d::prelude::*;
3+
use examples_common_3d::XpbdExamplePlugin;
4+
5+
#[derive(Component)]
6+
struct Player;
7+
8+
#[derive(Component, Deref, DerefMut)]
9+
pub struct MoveAcceleration(pub f64);
10+
11+
#[derive(Component, Deref, DerefMut)]
12+
pub struct MaxLinearVelocity(pub DVec3);
13+
14+
fn setup(
15+
mut commands: Commands,
16+
mut materials: ResMut<Assets<StandardMaterial>>,
17+
mut meshes: ResMut<Assets<Mesh>>,
18+
) {
19+
let cube = meshes.add(Mesh::from(shape::Cube { size: 1.0 }));
20+
21+
let white = materials.add(StandardMaterial {
22+
base_color: Color::rgb(0.8, 0.8, 1.0),
23+
..default()
24+
});
25+
26+
let blue = materials.add(StandardMaterial {
27+
base_color: Color::rgb(0.2, 0.6, 0.8),
28+
..default()
29+
});
30+
31+
let floor_size = DVec3::new(80.0, 1.0, 80.0);
32+
let _floor = commands
33+
.spawn(PbrBundle {
34+
mesh: cube.clone(),
35+
material: white,
36+
transform: Transform::from_scale(floor_size.as_vec3()),
37+
..default()
38+
})
39+
.insert(RigidBodyBundle::new_static().with_pos(DVec3::new(0.0, -1.0, 0.0)))
40+
.insert(ColliderBundle::new(
41+
&Shape::cuboid(floor_size.x * 0.5, floor_size.y * 0.5, floor_size.z * 0.5),
42+
1.0,
43+
));
44+
45+
let radius = 1.0;
46+
let count_x = 4;
47+
let count_y = 4;
48+
let count_z = 4;
49+
for y in 0..count_y {
50+
for x in 0..count_x {
51+
for z in 0..count_z {
52+
let pos = DVec3::new(
53+
(x as f64 - count_x as f64 * 0.5) * 2.1 * radius,
54+
10.0 * radius * y as f64,
55+
(z as f64 - count_z as f64 * 0.5) * 2.1 * radius,
56+
);
57+
commands
58+
.spawn(PbrBundle {
59+
mesh: cube.clone(),
60+
material: blue.clone(),
61+
transform: Transform {
62+
scale: Vec3::splat(radius as f32 * 2.0),
63+
..default()
64+
},
65+
..default()
66+
})
67+
.insert(RigidBodyBundle::new_dynamic().with_pos(pos + DVec3::Y * 5.0))
68+
.insert(ColliderBundle::new(
69+
&Shape::cuboid(radius, radius, radius),
70+
1.0,
71+
))
72+
.insert(Player)
73+
.insert(MoveAcceleration(0.1))
74+
.insert(MaxLinearVelocity(DVec3::new(30.0, 30.0, 30.0)));
75+
}
76+
}
77+
}
78+
79+
// Directional 'sun' light
80+
commands.spawn(DirectionalLightBundle {
81+
directional_light: DirectionalLight {
82+
illuminance: 20_000.0,
83+
shadows_enabled: true,
84+
..default()
85+
},
86+
transform: Transform {
87+
translation: Vec3::new(0.0, 10.0, 0.0),
88+
rotation: Quat::from_euler(
89+
EulerRot::XYZ,
90+
std::f32::consts::PI * 1.3,
91+
std::f32::consts::PI * 1.85,
92+
0.0,
93+
),
94+
..default()
95+
},
96+
..default()
97+
});
98+
99+
commands.spawn(Camera3dBundle {
100+
transform: Transform::from_translation(Vec3::new(0.0, 15.0, -50.0))
101+
.looking_at(Vec3::Y * 10.0, Vec3::Y),
102+
..default()
103+
});
104+
}
105+
106+
fn player_movement(
107+
keyboard_input: Res<Input<KeyCode>>,
108+
mut query: Query<(&mut LinVel, &MaxLinearVelocity, &MoveAcceleration), With<Player>>,
109+
) {
110+
for (mut lin_vel, max_vel, move_acceleration) in &mut query {
111+
if keyboard_input.pressed(KeyCode::Up) {
112+
lin_vel.z += move_acceleration.0;
113+
}
114+
if keyboard_input.pressed(KeyCode::Down) {
115+
lin_vel.z -= move_acceleration.0;
116+
}
117+
if keyboard_input.pressed(KeyCode::Left) {
118+
lin_vel.x += move_acceleration.0;
119+
}
120+
if keyboard_input.pressed(KeyCode::Right) {
121+
lin_vel.x -= move_acceleration.0;
122+
}
123+
lin_vel.0 = lin_vel.0.clamp(-max_vel.0, max_vel.0);
124+
}
125+
}
126+
127+
fn main() {
128+
#[cfg(target_arch = "wasm32")]
129+
console_error_panic_hook::set_once();
130+
131+
App::new()
132+
.insert_resource(ClearColor(Color::BLACK))
133+
.insert_resource(Msaa::Sample4)
134+
.insert_resource(Gravity::default())
135+
.add_plugins(DefaultPlugins)
136+
.add_plugin(XpbdExamplePlugin)
137+
.add_startup_system(setup)
138+
.add_system(player_movement)
139+
.run();
140+
}

crates/bevy_xpbd_3d/snapshots/bevy_xpbd_3d__tests__body_with_velocity_moves.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ expression: transform
44
---
55
Transform {
66
translation: Vec3(
7-
8.316475,
7+
8.316667,
88
0.0,
99
0.0,
1010
),

0 commit comments

Comments
 (0)