Tesbted physx backend: add heightfield, trimesh, and convex mesh support.
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user