2
// ---------------------------------------------------------
4
// broadphase_blenderbvh.h
7
// Broad phase collision detection culling using a K-DOP bvh structure
9
// ---------------------------------------------------------
11
#ifndef BROADPHASEGRID_H
12
#define BROADPHASEGRID_H
14
// ---------------------------------------------------------
16
// ---------------------------------------------------------
18
#include <broadphase.h>
19
#include "../../../source/blender/blenlib/BLI_kdopbvh.h"
21
// ---------------------------------------------------------
22
// Forwards and typedefs
23
// ---------------------------------------------------------
27
// ---------------------------------------------------------
28
// Interface declarations
29
// ---------------------------------------------------------
31
// --------------------------------------------------------
33
/// Broad phase collision detector using three regular grids: one grid each for vertices, edges and triangles.
35
// --------------------------------------------------------
37
class BroadPhaseBVH : public BroadPhase
52
/// Rebuild the broad phase using current vertex positions
54
void update_broad_phase_static( const DynamicSurface& surface );
56
/// Rebuild the broad phase using current and predicted vertex positions
58
void update_broad_phase_continuous( const DynamicSurface& surface );
60
inline void add_vertex( unsigned int index, const Vec3d& aabb_low, const Vec3d& aabb_high );
61
inline void add_edge( unsigned int index, const Vec3d& aabb_low, const Vec3d& aabb_high );
62
inline void add_triangle( unsigned int index, const Vec3d& aabb_low, const Vec3d& aabb_high );
64
inline void update_vertex( unsigned int index, const Vec3d& aabb_low, const Vec3d& aabb_high );
65
inline void update_edge( unsigned int index, const Vec3d& aabb_low, const Vec3d& aabb_high );
66
inline void update_triangle( unsigned int index, const Vec3d& aabb_low, const Vec3d& aabb_high );
68
inline void remove_vertex( unsigned int index );
69
inline void remove_edge( unsigned int index );
70
inline void remove_triangle( unsigned int index );
72
/// Get the set of vertices whose bounding volumes overlap the specified bounding volume
74
inline void get_potential_vertex_collisions( const Vec3d& aabb_low,
75
const Vec3d& aabb_high,
76
std::vector<unsigned int>& overlapping_vertices );
78
/// Get the set of edges whose bounding volumes overlap the specified bounding volume
80
inline void get_potential_edge_collisions( const Vec3d& aabb_low,
81
const Vec3d& aabb_high,
82
std::vector<unsigned int>& overlapping_edges );
84
/// Get the set of triangles whose bounding volumes overlap the specified bounding volume
86
inline void get_potential_triangle_collisions( const Vec3d& aabb_low,
87
const Vec3d& aabb_high,
88
std::vector<unsigned int>& overlapping_triangles );
90
/// Rebuild one of the grids
92
void build_acceleration_grid( AccelerationGrid& grid,
93
std::vector<Vec3d>& xmins,
94
std::vector<Vec3d>& xmaxs,
96
double grid_padding );
100
AccelerationGrid m_vertex_grid;
101
AccelerationGrid m_edge_grid;
102
AccelerationGrid m_triangle_grid;
106
// ---------------------------------------------------------
108
// ---------------------------------------------------------
110
// --------------------------------------------------------
112
/// Add a vertex to the broad phase
114
// --------------------------------------------------------
116
inline void BroadPhaseGrid::add_vertex( unsigned int index, const Vec3d& aabb_low, const Vec3d& aabb_high )
118
m_vertex_grid.add_element( index, aabb_low, aabb_high );
121
// --------------------------------------------------------
123
/// Add an edge to the broad phase
125
// --------------------------------------------------------
127
inline void BroadPhaseGrid::add_edge( unsigned int index, const Vec3d& aabb_low, const Vec3d& aabb_high )
129
m_edge_grid.add_element( index, aabb_low, aabb_high );
132
// --------------------------------------------------------
134
/// Add a triangle to the broad phase
136
// --------------------------------------------------------
138
inline void BroadPhaseGrid::add_triangle( unsigned int index, const Vec3d& aabb_low, const Vec3d& aabb_high )
140
m_triangle_grid.add_element( index, aabb_low, aabb_high );
144
inline void BroadPhaseGrid::update_vertex( unsigned int index, const Vec3d& aabb_low, const Vec3d& aabb_high )
146
m_vertex_grid.update_element( index, aabb_low, aabb_high );
149
inline void BroadPhaseGrid::update_edge( unsigned int index, const Vec3d& aabb_low, const Vec3d& aabb_high )
151
m_edge_grid.update_element( index, aabb_low, aabb_high );
154
inline void BroadPhaseGrid::update_triangle( unsigned int index, const Vec3d& aabb_low, const Vec3d& aabb_high )
156
m_triangle_grid.update_element( index, aabb_low, aabb_high );
160
// --------------------------------------------------------
162
/// Remove a vertex from the broad phase
164
// --------------------------------------------------------
166
inline void BroadPhaseGrid::remove_vertex( unsigned int index )
168
m_vertex_grid.remove_element( index );
171
// --------------------------------------------------------
173
/// Remove an edge from the broad phase
175
// --------------------------------------------------------
177
inline void BroadPhaseGrid::remove_edge( unsigned int index )
179
m_edge_grid.remove_element( index );
182
// --------------------------------------------------------
184
/// Remove a triangle from the broad phase
186
// --------------------------------------------------------
188
inline void BroadPhaseGrid::remove_triangle( unsigned int index )
190
m_triangle_grid.remove_element( index );
193
// --------------------------------------------------------
195
/// Query the broad phase to get the set of all vertices overlapping the given AABB
197
// --------------------------------------------------------
199
inline void BroadPhaseGrid::get_potential_vertex_collisions( const Vec3d& aabb_low, const Vec3d& aabb_high, std::vector<unsigned int>& overlapping_vertices )
201
m_vertex_grid.find_overlapping_elements( aabb_low, aabb_high, overlapping_vertices );
204
// --------------------------------------------------------
206
/// Query the broad phase to get the set of all edges overlapping the given AABB
208
// --------------------------------------------------------
210
inline void BroadPhaseGrid::get_potential_edge_collisions( const Vec3d& aabb_low, const Vec3d& aabb_high, std::vector<unsigned int>& overlapping_edges )
212
m_edge_grid.find_overlapping_elements( aabb_low, aabb_high, overlapping_edges );
215
// --------------------------------------------------------
217
/// Query the broad phase to get the set of all triangles overlapping the given AABB
219
// --------------------------------------------------------
221
inline void BroadPhaseGrid::get_potential_triangle_collisions( const Vec3d& aabb_low, const Vec3d& aabb_high, std::vector<unsigned int>& overlapping_triangles )
223
m_triangle_grid.find_overlapping_elements( aabb_low, aabb_high, overlapping_triangles );