Skip to content

Commit

Permalink
fix 3d concave shape to use multiple of 3 faces (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ughuuu authored Jul 20, 2024
1 parent 71c1ae8 commit 9680d68
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/joints/rapier_revolute_joint.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use godot::classes::*;
use godot::prelude::*;
#[cfg(feature = "dim2")]
use physics_server_2d::JointType;
#[cfg(feature = "dim3")]
Expand Down
12 changes: 12 additions & 0 deletions src/rapier_wrapper/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ impl PhysicsEngine {
self.insert_shape(shape)
}

#[cfg(feature = "dim2")]
pub fn shape_create_concave_polyline(
&mut self,
points: &Vec<Vector<Real>>,
Expand All @@ -130,6 +131,17 @@ impl PhysicsEngine {
self.insert_shape(shape)
}

#[cfg(feature = "dim3")]
pub fn shape_create_concave_polyline(
&mut self,
points: &Vec<Vector<Real>>,
indices: Option<Vec<[u32; 3]>>,
) -> ShapeHandle {
let points_vec = point_array_to_vec(points);
let shape = SharedShape::trimesh(points_vec, indices.unwrap());
self.insert_shape(shape)
}

pub fn shape_get_aabb(&self, handle: ShapeHandle) -> rapier::prelude::Aabb {
if let Some(shape) = self.get_shape(handle) {
return shape.compute_local_aabb();
Expand Down
6 changes: 3 additions & 3 deletions src/servers/rapier_physics_server_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,7 @@ impl RapierPhysicsServerImpl {
from: Transform,
motion: Vector,
margin: f32,
max_collisions: i32,
_max_collisions: i32,
collide_separation_ray: bool,
recovery_as_collision: bool,
result: *mut PhysicsServerExtensionMotionResult,
Expand Down Expand Up @@ -1612,10 +1612,10 @@ impl RapierPhysicsServerImpl {
rid: Rid,
body_a: Rid,
pivot_a: Vector3,
axis_a: Vector3,
_axis_a: Vector3,
body_b: Rid,
pivot_b: Vector3,
axis_b: Vector3,
_axis_b: Vector3,
) {
let physics_data = physics_data();
let mut joint: Box<dyn IRapierJoint>;
Expand Down
6 changes: 6 additions & 0 deletions src/shapes/rapier_concave_polygon_shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,16 @@ impl IRapierShape for RapierConcavePolygonShape {
rapier_points.push(vector_to_rapier(self.points[i]));
}
let mut segments = Vec::new();
#[cfg(feature = "dim2")]
for i in (0..point_count).step_by(2) {
let s = [(i) as u32, (i + 1) as u32];
segments.push(s);
}
#[cfg(feature = "dim3")]
for i in (0..point_count).step_by(3) {
let s = [(i) as u32, (i + 1) as u32, (i + 2) as u32];
segments.push(s);
}
physics_engine.shape_create_concave_polyline(&rapier_points, Some(segments))
}

Expand Down

0 comments on commit 9680d68

Please sign in to comment.