Tesbted physx backend: add heightfield, trimesh, and convex mesh support.

This commit is contained in:
Crozet Sébastien
2021-01-06 12:22:46 +01:00
parent 1e9a962d34
commit d1ed279c4e
8 changed files with 129 additions and 31 deletions

View File

@@ -1,4 +1,6 @@
use na::Point3;
use rand::distributions::{Distribution, Standard};
use rand::{rngs::StdRng, SeedableRng};
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
use rapier_testbed3d::Testbed;
@@ -28,14 +30,19 @@ pub fn init_world(testbed: &mut Testbed) {
* Create the cubes
*/
let num = 8;
let scale = 2.0;
let rad = 1.0;
let border_rad = 0.1;
let shift = rad * 2.0 + rad;
let shift = border_rad * 2.0 + scale;
let centerx = shift * (num / 2) as f32;
let centery = shift / 2.0;
let centerz = shift * (num / 2) as f32;
let mut offset = -(num as f32) * (rad * 2.0 + rad) * 0.5;
let mut offset = -(num as f32) * shift * 0.5;
let mut rng = StdRng::seed_from_u64(0);
let distribution = Standard;
for j in 0usize..47 {
for i in 0..num {
@@ -44,11 +51,16 @@ pub fn init_world(testbed: &mut Testbed) {
let y = j as f32 * shift + centery + 3.0;
let z = k as f32 * shift - centerz + offset;
let mut points = Vec::new();
for _ in 0..10 {
let pt: Point3<f32> = distribution.sample(&mut rng);
points.push(pt * scale);
}
// Build the rigid body.
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build();
let handle = bodies.insert(rigid_body);
let cylinder = rapier3d::cdl::shape::Cylinder::new(rad, rad).to_trimesh(4);
let collider = ColliderBuilder::round_convex_hull(&cylinder.0, 0.1)
let collider = ColliderBuilder::round_convex_hull(&points, border_rad)
.unwrap()
.build();
colliders.insert(collider, handle, &mut bodies);