sandbox
Loading...
Searching...
No Matches
mesh_collider.hpp
1// SPDX-License-Identifier: MIT
2#ifndef LIBSBX_PHYSICS_MESH_COLLIDER_HPP_
3#define LIBSBX_PHYSICS_MESH_COLLIDER_HPP_
4
5#include <vector>
6#include <optional>
7#include <cstdint>
8#include <filesystem>
9
10#include <assimp/Importer.hpp>
11#include <assimp/scene.h>
12#include <assimp/postprocess.h>
13
14#include <libsbx/math/vector3.hpp>
15#include <libsbx/math/volume.hpp>
16#include <libsbx/math/quaternion.hpp>
17
18#include <libsbx/physics/shape_collider.hpp>
19
20namespace sbx::physics {
21
23
24public:
25
26 struct bvh_node {
27 math::volume volume;
28 std::uint32_t first; // child index if internal, triangle_indices offset if leaf
29 std::uint32_t count; // 0 = internal, >0 = leaf triangle count
30 }; // struct bvh_node
31
32 mesh_collider(const std::filesystem::path& path);
33
34 mesh_collider(std::vector<math::vector3> vertices, std::vector<std::uint32_t> indices);
35
36 auto triangle_count() const noexcept -> std::uint32_t;
37
38 auto get_triangle(std::uint32_t triangle_index) const -> triangle;
39
40 auto query_bvh(const math::volume& volume) const -> std::vector<std::uint32_t>;
41
42private:
43
44 auto _build_bvh() -> void;
45
46 auto _build_bvh_recursive(std::uint32_t node_index, std::uint32_t triangle_begin, std::uint32_t triangle_count) -> void;
47
48 auto _triangle_centroid(std::uint32_t triangle_index) const -> math::vector3;
49
50 auto _triangle_volume(std::uint32_t triangle_index) const -> math::volume;
51
52 std::vector<math::vector3> _vertices;
53 std::vector<std::uint32_t> _indices;
54
55 std::vector<bvh_node> _nodes;
56 std::vector<std::uint32_t> _triangle_indices;
57
58}; // class mesh_collider
59
60} // namespace sbx::physics
61
62#endif // LIBSBX_PHYSICS_MESH_COLLIDER_HPP_
Definition: volume.hpp:14
Definition: mesh_collider.hpp:22
Definition: mesh_collider.hpp:26
Definition: shape_collider.hpp:36