Antkeeper  0.0.1
Public Types | Public Member Functions | List of all members
physics::mesh_collider Class Reference

Mesh collision object. More...

#include <mesh-collider.hpp>

Inheritance diagram for physics::mesh_collider:
physics::collider

Public Types

using mesh_type = geom::brep_mesh
 Collision mesh type. More...
 
using bvh_type = geom::bvh
 Bounding volume hierarchy type. More...
 

Public Member Functions

constexpr collider_type type () const noexcept override
 Returns the collider type. More...
 
 mesh_collider (std::shared_ptr< mesh_type > mesh)
 Constructs a mesh collider from a mesh. More...
 
constexpr mesh_collider () noexcept=default
 Constructs an empty mesh collider. More...
 
void set_mesh (std::shared_ptr< mesh_type > mesh)
 Sets the collider's mesh. More...
 
constexpr const std::shared_ptr< mesh_type > & get_mesh () const noexcept
 Returns the collision mesh. More...
 
constexpr const bvh_typeget_bvh () const noexcept
 Returns the BVH of the collision mesh faces. More...
 
void rebuild_bvh ()
 Rebuilds the BVH of the collision mesh faces. More...
 
std::optional< std::tuple< float, std::uint32_t, math::fvec3 > > intersection (const geom::ray< float, 3 > &ray) const
 Finds the nearest point of intersection between a ray and this collision mesh. More...
 
- Public Member Functions inherited from physics::collider
constexpr void set_layer_mask (std::uint32_t mask) noexcept
 Sets the layer mask of the collider. More...
 
void set_material (std::shared_ptr< collider_material > material) noexcept
 Sets the collider material. More...
 
constexpr std::uint32_t get_layer_mask () const noexcept
 Returns the layer mask of the collider. More...
 
constexpr const std::shared_ptr< collider_material > & get_material () const noexcept
 Returns the collider material. More...
 

Detailed Description

Mesh collision object.

Definition at line 36 of file mesh-collider.hpp.

Member Typedef Documentation

◆ bvh_type

Bounding volume hierarchy type.

Definition at line 43 of file mesh-collider.hpp.

◆ mesh_type

Collision mesh type.

Definition at line 40 of file mesh-collider.hpp.

Constructor & Destructor Documentation

◆ mesh_collider() [1/2]

physics::mesh_collider::mesh_collider ( std::shared_ptr< mesh_type mesh)
explicit

Constructs a mesh collider from a mesh.

Parameters
meshCollision mesh.
Warning
mesh must contain the math::fvec3 vertex attribute "position".
mesh must be a triangle mesh.

Definition at line 28 of file mesh-collider.cpp.

◆ mesh_collider() [2/2]

constexpr physics::mesh_collider::mesh_collider ( )
constexprdefaultnoexcept

Constructs an empty mesh collider.

Member Function Documentation

◆ get_bvh()

constexpr const bvh_type& physics::mesh_collider::get_bvh ( ) const
inlineconstexprnoexcept

Returns the BVH of the collision mesh faces.

Definition at line 80 of file mesh-collider.hpp.

◆ get_mesh()

constexpr const std::shared_ptr<mesh_type>& physics::mesh_collider::get_mesh ( ) const
inlineconstexprnoexcept

Returns the collision mesh.

Definition at line 74 of file mesh-collider.hpp.

◆ intersection()

std::optional< std::tuple< float, std::uint32_t, math::fvec3 > > physics::mesh_collider::intersection ( const geom::ray< float, 3 > &  ray) const

Finds the nearest point of intersection between a ray and this collision mesh.

Parameters
rayMesh-space ray.
Returns
Tuple containing the distance along the ray to the nearest point of intersection, the index of the nearest mesh face, and the surface normal of the intersected face; or std::nullopt if no intersection occurred.

Definition at line 80 of file mesh-collider.cpp.

◆ rebuild_bvh()

void physics::mesh_collider::rebuild_bvh ( )

Rebuilds the BVH of the collision mesh faces.

Definition at line 68 of file mesh-collider.cpp.

◆ set_mesh()

void physics::mesh_collider::set_mesh ( std::shared_ptr< mesh_type mesh)

Sets the collider's mesh.

Parameters
meshCollision mesh.
Warning
mesh must contain the math::fvec3 vertex attribute "position".
mesh must be a triangle mesh.

@TODO: vertex normals aren't needed for mesh colliders, they're generated here for the locomotion system (remove later)

Definition at line 33 of file mesh-collider.cpp.

◆ type()

constexpr collider_type physics::mesh_collider::type ( ) const
inlineconstexproverridevirtualnoexcept

Returns the collider type.

Implements physics::collider.

Definition at line 45 of file mesh-collider.hpp.


The documentation for this class was generated from the following files: