Merge branch 'blender-v2.81-release'
[blender.git] / source / blender / blenkernel / BKE_editmesh_bvh.h
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19
20 /** \file
21  * \ingroup bke
22  */
23
24 #ifndef __BKE_EDITMESH_BVH_H__
25 #define __BKE_EDITMESH_BVH_H__
26
27 struct BMBVHTree;
28 struct BMEditMesh;
29 struct BMFace;
30 struct BMLoop;
31 struct BMVert;
32 struct BMesh;
33 struct BVHTree;
34
35 typedef struct BMBVHTree BMBVHTree;
36
37 typedef bool (*BMBVHTree_FaceFilter)(struct BMFace *f, void *userdata);
38
39 BMBVHTree *BKE_bmbvh_new_from_editmesh(struct BMEditMesh *em,
40                                        int flag,
41                                        const float (*cos_cage)[3],
42                                        const bool cos_cage_free);
43 BMBVHTree *BKE_bmbvh_new_ex(struct BMesh *bm,
44                             struct BMLoop *(*looptris)[3],
45                             int looptris_tot,
46                             int flag,
47                             const float (*cos_cage)[3],
48                             const bool cos_cage_free,
49                             bool (*test_fn)(struct BMFace *, void *user_data),
50                             void *user_data);
51 BMBVHTree *BKE_bmbvh_new(struct BMesh *bm,
52                          struct BMLoop *(*looptris)[3],
53                          int looptris_tot,
54                          int flag,
55                          const float (*cos_cage)[3],
56                          const bool cos_cage_free);
57 void BKE_bmbvh_free(BMBVHTree *tree);
58 struct BVHTree *BKE_bmbvh_tree_get(BMBVHTree *tree);
59
60 struct BMFace *BKE_bmbvh_ray_cast(BMBVHTree *tree,
61                                   const float co[3],
62                                   const float dir[3],
63                                   const float radius,
64                                   float *r_dist,
65                                   float r_hitout[3],
66                                   float r_cagehit[3]);
67
68 struct BMFace *BKE_bmbvh_ray_cast_filter(BMBVHTree *tree,
69                                          const float co[3],
70                                          const float dir[3],
71                                          const float radius,
72                                          float *r_dist,
73                                          float r_hitout[3],
74                                          float r_cagehit[3],
75                                          BMBVHTree_FaceFilter filter_cb,
76                                          void *filter_userdata);
77
78 /* find a vert closest to co in a sphere of radius dist_max */
79 struct BMVert *BKE_bmbvh_find_vert_closest(BMBVHTree *tree,
80                                            const float co[3],
81                                            const float dist_max);
82 struct BMFace *BKE_bmbvh_find_face_closest(BMBVHTree *tree,
83                                            const float co[3],
84                                            const float dist_max);
85
86 struct BVHTreeOverlap *BKE_bmbvh_overlap(const BMBVHTree *bmtree_a,
87                                          const BMBVHTree *bmtree_b,
88                                          unsigned int *r_overlap_tot);
89
90 /** #BKE_bmbvh_new flag parameter. */
91 enum {
92   /** Use with 'cos_cage', returns hits in relation to original geometry. */
93   BMBVH_RETURN_ORIG = (1 << 0),
94   /** Restrict to hidden geometry (overrides BMBVH_RESPECT_HIDDEN). */
95   BMBVH_RESPECT_SELECT = (1 << 1),
96   /** Omit hidden geometry. */
97   BMBVH_RESPECT_HIDDEN = (1 << 2),
98 };
99
100 #endif /* __BKE_EDITMESH_BVH_H__ */