41 const Span<std::array<BMLoop *, 3>> looptris,
44 const bool cos_cage_free,
45 bool (*test_fn)(
BMFace *,
void *user_data),
51 BMBVHTree *bmtree = MEM_new<BMBVHTree>(
"BMBVHTree");
56 BMFace *f_test, *f_test_prev;
76 f_test_prev =
nullptr;
80 for (
const int i : looptris.index_range()) {
81 f_test = looptris[i][0]->f;
82 if (f_test != f_test_prev) {
83 test_fn_ret = test_fn(f_test, user_data);
93 tottri = looptris.size();
98 f_test_prev =
nullptr;
101 for (
const int i : looptris.index_range()) {
104 f_test = looptris[i][0]->f;
105 if (f_test != f_test_prev) {
106 test_fn_ret = test_fn(f_test, user_data);
107 f_test_prev = f_test;
145 const Span<std::array<BMLoop *, 3>> looptris,
148 const bool cos_cage_free)
150 bool (*test_fn)(
BMFace *,
void *user_data);
164 return BKE_bmbvh_new_ex(
bm, looptris, flag, cos_cage, cos_cage_free, test_fn,
nullptr);
190 const std::array<BMLoop *, 3> <ri,
193 if (cos_cage ==
nullptr) {
194 cos[0] = ltri[0]->v->co;
195 cos[1] = ltri[1]->v->co;
196 cos[2] = ltri[2]->v->co;
228 const std::array<BMLoop *, 3> <ri = bmtree->
looptris[hit->
index];
250 const std::array<BMLoop *, 3> <ri = bmcb_data->
looptris[
index];
252 const float *tri_cos[3];
267#ifdef USE_KDOPBVH_WATERTIGHT
272 ray->
origin, ray->
direction, tri_cos[0], tri_cos[1], tri_cos[2], &dist, uv));
275 if (isect && dist < hit->dist) {
297 const float dist = r_dist ? *r_dist :
FLT_MAX;
312 if (hit.
index != -1 && hit.
dist != dist) {
339 const std::array<BMLoop *, 3> <ri = bmcb_data->
looptris[
index];
353 void *filter_userdata)
359 const float dist = r_dist ? *r_dist :
FLT_MAX;
377 if (hit.
index != -1 && hit.
dist != dist) {
403 const std::array<BMLoop *, 3> <ri = bmcb_data->
looptris[
index];
406 const float *tri_cos[3];
409 for (
int i = 0; i < 3; i++) {
411 if (dist_sq < hit->dist_sq && dist_sq < dist_max_sq) {
424 const float dist_max)
428 const float dist_max_sq = dist_max * dist_max;
442 if (hit.
index != -1) {
443 const std::array<BMLoop *, 3> <ri = bmtree->
looptris[hit.
index];
465 const std::array<BMLoop *, 3> <ri = bmcb_data->
looptris[
index];
468 const float *tri_cos[3];
475 if (dist_sq < hit->dist_sq && dist_sq < dist_max_sq) {
485 const float dist_max)
489 const float dist_max_sq = dist_max * dist_max;
503 if (hit.
index != -1) {
504 const std::array<BMLoop *, 3> <ri = bmtree->
looptris[hit.
index];
525 const std::array<BMLoop *, 3> <ri_a = bmtree_a->
looptris[index_a];
526 const std::array<BMLoop *, 3> <ri_b = bmtree_b->
looptris[index_b];
527 const float *tri_a_co[3] = {ltri_a[0]->v->co, ltri_a[1]->v->co, ltri_a[2]->v->co};
528 const float *tri_b_co[3] = {ltri_b[0]->v->co, ltri_b[1]->v->co, ltri_b[2]->v->co};
530 int verts_shared = 0;
533 if (ltri_a[0]->f == ltri_b[0]->f) [[unlikely]] {
541 if (verts_shared >= 2) {
557 data.tree_pair[0] = bmtree_a;
558 data.tree_pair[1] = bmtree_b;
568 if (index_a < index_b) {
578 data.tree_pair[0] = bmtree;
579 data.tree_pair[1] = bmtree;
Read Blender memory allocation and freeing.
#define BM_elem_index_get(ele)
#define BM_elem_flag_test(ele, hflag)
MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], float f)
static void bmbvh_ray_cast_cb(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
MINLINE float len_squared_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
void BKE_bmbvh_free(BMBVHTree *tree)
void BM_mesh_elem_index_ensure(BMesh *bm, const char htype)
BMBVHTree * BKE_bmbvh_new_ex(struct BMesh *bm, Span< std::array< BMLoop *, 3 > > looptris, int flag, const float3 *cos_cage, bool cos_cage_free, bool(*test_fn)(struct BMFace *, void *user_data), void *user_data)
bool isect_tri_tri_v3(const float t_a0[3], const float t_a1[3], const float t_a2[3], const float t_b0[3], const float t_b1[3], const float t_b2[3], float r_i1[3], float r_i2[3])
MINLINE void copy_v3_v3(float r[3], const float a[3])
int BLI_bvhtree_find_nearest(const BVHTree *tree, const float co[3], BVHTreeNearest *nearest, BVHTree_NearestPointCallback callback, void *userdata)
struct BMFace * BKE_bmbvh_find_face_closest(const BMBVHTree *tree, const float co[3], float dist_max)
BVHTreeOverlap * BLI_bvhtree_overlap(const BVHTree *tree1, const BVHTree *tree2, unsigned int *r_overlap_num, BVHTree_OverlapCallback callback, void *userdata)
static bool bmbvh_overlap_self_cb(void *userdata, int index_a, int index_b, int thread)
float BLI_bvhtree_get_epsilon(const BVHTree *tree)
bool isect_ray_tri_watertight_v3(const float ray_origin[3], const struct IsectRayPrecalc *isect_precalc, const float v0[3], const float v1[3], const float v2[3], float *r_lambda, float r_uv[2])
struct BMFace * BKE_bmbvh_ray_cast(const BMBVHTree *tree, const float co[3], const float dir[3], float radius, float *r_dist, float r_hitout[3], float r_cagehit[3])
MINLINE void copy_v2_v2(float r[2], const float a[2])
void BLI_bvhtree_free(BVHTree *tree)
void BLI_bvhtree_balance(BVHTree *tree)
ATTR_WARN_UNUSED_RESULT const BMVert * v
struct BVHTree * BKE_bmbvh_tree_get(BMBVHTree *tree)
int BLI_bvhtree_ray_cast(const BVHTree *tree, const float co[3], const float dir[3], float radius, BVHTreeRayHit *hit, BVHTree_RayCastCallback callback, void *userdata)
static void bmbvh_find_vert_closest_cb(void *userdata, int index, const float co[3], BVHTreeNearest *hit)
BMBVHTree * BKE_bmbvh_new(struct BMesh *bm, Span< std::array< BMLoop *, 3 > > looptris, int flag, const float3 *cos_cage, bool cos_cage_free)
struct BMVert * BKE_bmbvh_find_vert_closest(const BMBVHTree *tree, const float co[3], float dist_max)
static bool bm_face_is_not_hidden(BMFace *f, void *)
struct BVHTreeOverlap * BKE_bmbvh_overlap(const BMBVHTree *bmtree_a, const BMBVHTree *bmtree_b, unsigned int *r_overlap_tot)
void interp_v3_v3v3v3_uv(float p[3], const float v1[3], const float v2[3], const float v3[3], const float uv[2])
BMesh const char void * data
BMBVHTree * BKE_bmbvh_new_from_editmesh(struct BMEditMesh *em, struct BMesh *bm, int flag, const float3 *cos_cage, bool cos_cage_free)
static bool bmbvh_overlap_cb(void *userdata, int index_a, int index_b, int)
BVHTree * BLI_bvhtree_new(int maxsize, float epsilon, char tree_type, char axis)
static BMFace * bmbvh_ray_cast_handle_hit(const BMBVHTree *bmtree, RayCastUserData *bmcb_data, const BVHTreeRayHit *hit, float *r_dist, float r_hitout[3], float r_cagehit[3])
bool isect_ray_tri_v3(const float ray_origin[3], const float ray_direction[3], const float v0[3], const float v1[3], const float v2[3], float *r_lambda, float r_uv[2])
static void bmbvh_tri_from_face(const float *cos[3], const std::array< BMLoop *, 3 > <ri, const float3 *cos_cage)
static void bmbvh_find_face_closest_cb(void *userdata, int index, const float co[3], BVHTreeNearest *hit)
MINLINE float max_ff(float a, float b)
void closest_on_tri_to_point_v3(float r[3], const float p[3], const float v1[3], const float v2[3], const float v3[3])
void BLI_bvhtree_insert(BVHTree *tree, int index, const float co[3], int numpoints)
bool isect_ray_tri_epsilon_v3(const float ray_origin[3], const float ray_direction[3], const float v0[3], const float v1[3], const float v2[3], float *r_lambda, float r_uv[2], float epsilon)
struct BMFace * BKE_bmbvh_ray_cast_filter(const BMBVHTree *tree, const float co[3], const float dir[3], float radius, float *r_dist, float r_hitout[3], float r_cagehit[3], BMBVHTree_FaceFilter filter_cb, void *filter_userdata)
VecBase< float, 3 > float3
bool(*) BMBVHTree_FaceFilter(struct BMFace *f, void *userdata)
static void bmbvh_ray_cast_cb_filter(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
struct BVHTreeOverlap * BKE_bmbvh_overlap_self(const BMBVHTree *bmtree, unsigned int *r_overlap_tot)
static bool bm_face_is_select(BMFace *f, void *)
const BMBVHTree * tree_pair[2]
Span< std::array< BMLoop *, 3 > > looptris
Array< std::array< BMLoop *, 3 > > looptris
struct IsectRayPrecalc * isect_precalc
Span< std::array< BMLoop *, 3 > > looptris
BMBVHTree_FaceFilter filter_cb
RayCastUserData bmcb_data
Span< std::array< BMLoop *, 3 > > looptris
Span< std::array< BMLoop *, 3 > > looptris