ncollide
ncollide copied to clipboard
Cylinder does not implement Shape
Since Cylinder
doesn't implement Shape
, it cannot be used with ShapeHandle
. This makes it difficult to use cylinders with nphysics
.
I tried to fix this by doing:
ncollide/src/shape/shape_impl.rs
+#[cfg(feature = "dim3")]
+impl<N: Real> Shape<N> for Cylinder<N> {
+ impl_shape_common!();
+ impl_as_support_map!();
+}
+
I'm not sure about support_map though
Then to nphysics (different crate):
src/volumetric/mod.rs
+#[cfg(feature = "dim3")]
+mod volumetric_cylinder;
This compiles fine, but I'm getting a runtime error:
thread 'main' panicked at 'The `Volumetric` is not implemented by the given shape.'
this is strange since the impl lies under volumetric_cylinder.rs
Seems like the code in both crates was commented out in sebcrozet/nphysics@c1ca0c759423e848910a91e26d32ef9d53753480 (nphysics)
@tatref This has been commented on nphysics
because nphysics itself does not support cylinders any more (it may be supported again at some point in the future, but that's a difficult task). The alternative is to use a polyhedral approximation with a ConvexHull
shape instead.
Note that constructors will be added to ConvexHull
to easily create polyhedral approximations of cylinders/cones (see #230).
I might take a look at this in early october.
Am I missing something, or does the procedural
module already contain the code to generate cones and cylinders?
Also, in the case of convex shapes, are the TriMesh and ConvexHull equivalent? If yes, could we use the ToTriMesh trait (already implemented for Cylinder...), then convert the TriMesh to ConvexHull?
The ToTriMesh
trait doesn't convert to a shape::TriMesh
it converts to a procedural::TriMesh
. I think it contains the same information (points, normals, etc) required by shape::TriMesh
, but the types are different.
I was able to successfully convert from the shape::Cylinder:: to
shape::ConvexHull` with the following snippet:
let cyl_trimesh = shape::Cylinder::new(half_length, radius).to_trimesh(32);
let cyl_shape = ShapeHandle::new(shape::ConvexHull::try_from_points(&cyl_trimesh.coords).unwrap());
I think you could do something similar to convert to a shape::TriMesh
, but the indices in the procedural::TriMesh
were in a different format and the convex hull conversion was easier.
I'm not sure what the computational differences for collision checking between TriMesh and ConvexHull are. I assume ConvexHull checks a bit faster than a generic TriMesh since the checker can assume convexity.
I believe that convex hulls have a well-defined interior, i.e. a shape will be considered colliding if it lies within a convex hull even if it does not intersect the surface. This makes it much less likely that a collision will be missed when objects are moving at high relative velocities.