JFLib

physics/src/shape.rs#

Source: lib/physics/src/shape.rs

shape -- the collision shapes: sphere, capsule, box, convex hull (convex, solid) and the static triangle
mesh (two-sided triangles)
  • enum Shape A collision shape in its own frame. Hulls and meshes are shared ([Arc]): cloning a shape is cheap, one map mesh can sit in several worlds (server, prediction, tests).
    • Sphere { radius: f64 } -- a ball around the origin
    • Capsule { half_height: f64, radius: f64 } -- the points within radius of the segment (0, -half_height, 0) .. (0, half_height, 0): upright, total height 2 (half_height + radius)
    • Box { half: Vec3 } -- a box around the origin with half sizes half
    • Hull(Arc<ConvexHull>) -- a convex hull (shared)
    • Mesh(Arc<TriMesh>) -- a triangle mesh: a static or kinematic body (never dynamic), not a query shape

impl Shape

  • fn sphere(radius: f64) -> Shape a ball of radius
  • fn capsule(half_height: f64, radius: f64) -> Shape an upright capsule: the segment (0, ±half_height, 0) grown by radius
  • fn cuboid(half: Vec3) -> Shape a box with half sizes half
  • fn hull(hull: ConvexHull) -> Shape a convex hull, shared
  • fn hull_from_points(points: &[Vec3]) -> Result<Shape, HullError> the convex hull of points
  • fn mesh(mesh: TriMesh) -> Shape a triangle mesh (for a static or kinematic body), shared
  • fn sizes_ok(&self) -> bool whether its sizes can make a body: a radius and a box's half sizes finite and positive, a capsule's half height finite and not negative (hulls and meshes check theirs when they are made)
  • fn is_convex(&self) -> bool everything but a mesh
  • fn margin(&self) -> f64 the radius around the core (spheres and capsules), 0 for the others
  • fn aabb(&self, iso: &Iso) -> Aabb the box around the shape placed by iso

Source: docs/API.md in the JFLib repository.