Blender  V2.93
pbvh_intern.h
Go to the documentation of this file.
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 
17 #pragma once
18 
23 /* Axis-aligned bounding box */
24 typedef struct {
25  float bmin[3], bmax[3];
26 } BB;
27 
28 /* Axis-aligned bounding box with centroid */
29 typedef struct {
30  float bmin[3], bmax[3], bcentroid[3];
31 } BBC;
32 
33 /* Note: this structure is getting large, might want to split it into
34  * union'd structs */
35 struct PBVHNode {
36  /* Opaque handle for drawing code */
38 
39  /* Voxel bounds */
40  BB vb;
42 
43  /* For internal nodes, the offset of the children in the PBVH
44  * 'nodes' array. */
46 
47  /* Pointer into the PBVH prim_indices array and the number of
48  * primitives used by this leaf node.
49  *
50  * Used for leaf nodes in both mesh- and multires-based PBVHs.
51  */
53  unsigned int totprim;
54 
55  /* Array of indices into the mesh's MVert array. Contains the
56  * indices of all vertices used by faces that are within this
57  * node's bounding box.
58  *
59  * Note that a vertex might be used by a multiple faces, and
60  * these faces might be in different leaf nodes. Such a vertex
61  * will appear in the vert_indices array of each of those leaf
62  * nodes.
63  *
64  * In order to support cases where you want access to multiple
65  * nodes' vertices without duplication, the vert_indices array
66  * is ordered such that the first part of the array, up to
67  * index 'uniq_verts', contains "unique" vertex indices. These
68  * vertices might not be truly unique to this node, but if
69  * they appear in another node's vert_indices array, they will
70  * be above that node's 'uniq_verts' value.
71  *
72  * Used for leaf nodes in a mesh-based PBVH (not multires.)
73  */
74  const int *vert_indices;
75  unsigned int uniq_verts, face_verts;
76 
77  /* An array mapping face corners into the vert_indices
78  * array. The array is sized to match 'totprim', and each of
79  * the face's corners gets an index into the vert_indices
80  * array, in the same order as the corners in the original
81  * MLoopTri.
82  *
83  * Used for leaf nodes in a mesh-based PBVH (not multires.)
84  */
85  const int (*face_vert_indices)[3];
86 
87  /* Indicates whether this node is a leaf or not; also used for
88  * marking various updates that need to be applied. */
90 
91  /* Used for raycasting: how close bb is to the ray point. */
92  float tmin;
93 
94  /* Scalar displacements for sculpt mode's layer brush. */
95  float *layer_disp;
96 
99 
100  /* Dyntopo */
104  float (*bm_orco)[3];
105  int (*bm_ortri)[3];
107 
108  /* Used to store the brush color during a stroke and composite it over the original color */
110 };
111 
112 typedef enum {
114 } PBVHFlags;
115 
116 typedef struct PBVHBMeshLog PBVHBMeshLog;
117 
118 struct PBVH {
121 
124 
126  int totprim;
127  int totvert;
128 
130 
131  /* Mesh data */
132  const struct Mesh *mesh;
134  const MPoly *mpoly;
135  const MLoop *mloop;
140 
143  int *face_sets;
144 
145  /* Grid Data */
148  void **gridfaces;
150  int totgrid;
152 
153  /* Only used during BVH build and update,
154  * don't need to remain valid after */
156 
157 #ifdef PERFCNTRS
158  int perf_modified;
159 #endif
160 
161  /* flag are verts/faces deformed */
162  bool deformed;
163  bool show_mask;
166 
167  /* Dynamic topology */
173 
174  float planes[6][4];
176 
177  struct BMLog *bm_log;
179 };
180 
181 /* pbvh.c */
182 void BB_reset(BB *bb);
183 void BB_expand(BB *bb, const float co[3]);
184 void BB_expand_with_bb(BB *bb, BB *bb2);
185 void BBC_update_centroid(BBC *bbc);
186 int BB_widest_axis(const BB *bb);
187 void pbvh_grow_nodes(PBVH *bvh, int totnode);
188 bool ray_face_intersection_quad(const float ray_start[3],
189  struct IsectRayPrecalc *isect_precalc,
190  const float *t0,
191  const float *t1,
192  const float *t2,
193  const float *t3,
194  float *depth);
195 bool ray_face_intersection_tri(const float ray_start[3],
196  struct IsectRayPrecalc *isect_precalc,
197  const float *t0,
198  const float *t1,
199  const float *t2,
200  float *depth);
201 
202 bool ray_face_nearest_quad(const float ray_start[3],
203  const float ray_normal[3],
204  const float *t0,
205  const float *t1,
206  const float *t2,
207  const float *t3,
208  float *r_depth,
209  float *r_dist_sq);
210 bool ray_face_nearest_tri(const float ray_start[3],
211  const float ray_normal[3],
212  const float *t0,
213  const float *t1,
214  const float *t2,
215  float *r_depth,
216  float *r_dist_sq);
217 
218 void pbvh_update_BB_redraw(PBVH *bvh, PBVHNode **nodes, int totnode, int flag);
219 
220 /* pbvh_bmesh.c */
222  const float ray_start[3],
223  const float ray_normal[3],
224  struct IsectRayPrecalc *isect_precalc,
225  float *dist,
226  bool use_original,
227  int *r_active_vertex_index,
228  float *r_face_normal);
230  const float ray_start[3],
231  const float ray_normal[3],
232  float *depth,
233  float *dist_sq,
234  bool use_original);
235 
236 void pbvh_bmesh_normals_update(PBVHNode **nodes, int totnode);
typedef float(TangentPoint)[2]
struct CCGElem CCGElem
Definition: BKE_ccg.h:46
PBVHType
Definition: BKE_pbvh.h:209
PBVHNodeFlags
Definition: BKE_pbvh.h:63
unsigned int BLI_bitmap
Definition: BLI_bitmap.h:32
struct GSet GSet
Definition: BLI_ghash.h:189
OperationNode * node
PBVHFlags
Definition: pbvh_intern.h:112
@ PBVH_DYNTOPO_SMOOTH_SHADING
Definition: pbvh_intern.h:113
bool pbvh_bmesh_node_nearest_to_ray(PBVHNode *node, const float ray_start[3], const float ray_normal[3], float *depth, float *dist_sq, bool use_original)
Definition: pbvh_bmesh.c:1618
void BB_expand_with_bb(BB *bb, BB *bb2)
Definition: pbvh.c:91
int BB_widest_axis(const BB *bb)
Definition: pbvh.c:100
void pbvh_grow_nodes(PBVH *bvh, int totnode)
Definition: pbvh.c:239
struct PBVHBMeshLog PBVHBMeshLog
Definition: pbvh_intern.h:116
bool ray_face_intersection_tri(const float ray_start[3], struct IsectRayPrecalc *isect_precalc, const float *t0, const float *t1, const float *t2, float *depth)
bool ray_face_nearest_tri(const float ray_start[3], const float ray_normal[3], const float *t0, const float *t1, const float *t2, float *r_depth, float *r_dist_sq)
void pbvh_bmesh_normals_update(PBVHNode **nodes, int totnode)
Definition: pbvh_bmesh.c:1659
void pbvh_update_BB_redraw(PBVH *bvh, PBVHNode **nodes, int totnode, int flag)
Definition: pbvh.c:1240
void BBC_update_centroid(BBC *bbc)
Definition: pbvh.c:123
bool pbvh_bmesh_node_raycast(PBVHNode *node, const float ray_start[3], const float ray_normal[3], struct IsectRayPrecalc *isect_precalc, float *dist, bool use_original, int *r_active_vertex_index, float *r_face_normal)
Definition: pbvh_bmesh.c:1510
void BB_reset(BB *bb)
Definition: pbvh.c:75
bool ray_face_intersection_quad(const float ray_start[3], struct IsectRayPrecalc *isect_precalc, const float *t0, const float *t1, const float *t2, const float *t3, float *depth)
bool ray_face_nearest_quad(const float ray_start[3], const float ray_normal[3], const float *t0, const float *t1, const float *t2, const float *t3, float *r_depth, float *r_dist_sq)
void BB_expand(BB *bb, const float co[3])
Definition: pbvh.c:82
Definition: pbvh_intern.h:24
Definition: BKE_ccg.h:48
const int(* face_vert_indices)[3]
Definition: pbvh_intern.h:85
int proxy_count
Definition: pbvh_intern.h:97
unsigned int totprim
Definition: pbvh_intern.h:53
GSet * bm_faces
Definition: pbvh_intern.h:101
struct GPU_PBVH_Buffers * draw_buffers
Definition: pbvh_intern.h:37
float tmin
Definition: pbvh_intern.h:92
int * prim_indices
Definition: pbvh_intern.h:52
unsigned int face_verts
Definition: pbvh_intern.h:75
GSet * bm_unique_verts
Definition: pbvh_intern.h:102
BB orig_vb
Definition: pbvh_intern.h:41
float * layer_disp
Definition: pbvh_intern.h:95
const int * vert_indices
Definition: pbvh_intern.h:74
PBVHProxyNode * proxies
Definition: pbvh_intern.h:98
float(* bm_orco)[3]
Definition: pbvh_intern.h:104
PBVHColorBufferNode color_buffer
Definition: pbvh_intern.h:109
unsigned int uniq_verts
Definition: pbvh_intern.h:75
int children_offset
Definition: pbvh_intern.h:45
int(* bm_ortri)[3]
Definition: pbvh_intern.h:105
int bm_tot_ortri
Definition: pbvh_intern.h:106
PBVHNodeFlags flag
Definition: pbvh_intern.h:89
GSet * bm_other_verts
Definition: pbvh_intern.h:103
PBVHType type
Definition: pbvh_intern.h:119
float planes[6][4]
Definition: pbvh_intern.h:174
int totvert
Definition: pbvh_intern.h:127
int * prim_indices
Definition: pbvh_intern.h:125
CustomData * ldata
Definition: pbvh_intern.h:138
const DMFlagMat * grid_flag_mats
Definition: pbvh_intern.h:149
CustomData * pdata
Definition: pbvh_intern.h:139
bool respect_hide
Definition: pbvh_intern.h:165
BLI_bitmap ** grid_hidden
Definition: pbvh_intern.h:151
int cd_face_node_offset
Definition: pbvh_intern.h:172
bool deformed
Definition: pbvh_intern.h:162
bool show_mask
Definition: pbvh_intern.h:163
int face_sets_color_seed
Definition: pbvh_intern.h:141
const MPoly * mpoly
Definition: pbvh_intern.h:134
CCGElem ** grids
Definition: pbvh_intern.h:147
const MLoopTri * looptri
Definition: pbvh_intern.h:136
const struct Mesh * mesh
Definition: pbvh_intern.h:132
struct BMLog * bm_log
Definition: pbvh_intern.h:177
CCGKey gridkey
Definition: pbvh_intern.h:146
int totprim
Definition: pbvh_intern.h:126
BLI_bitmap * vert_bitmap
Definition: pbvh_intern.h:155
float bm_min_edge_len
Definition: pbvh_intern.h:170
int num_planes
Definition: pbvh_intern.h:175
int node_mem_count
Definition: pbvh_intern.h:123
int totgrid
Definition: pbvh_intern.h:150
void ** gridfaces
Definition: pbvh_intern.h:148
int leaf_limit
Definition: pbvh_intern.h:129
MVert * verts
Definition: pbvh_intern.h:133
bool show_face_sets
Definition: pbvh_intern.h:164
int * face_sets
Definition: pbvh_intern.h:143
PBVHFlags flags
Definition: pbvh_intern.h:120
float bm_max_edge_len
Definition: pbvh_intern.h:169
struct SubdivCCG * subdiv_ccg
Definition: pbvh_intern.h:178
BMesh * bm
Definition: pbvh_intern.h:168
int totnode
Definition: pbvh_intern.h:123
CustomData * vdata
Definition: pbvh_intern.h:137
const MLoop * mloop
Definition: pbvh_intern.h:135
int cd_vert_node_offset
Definition: pbvh_intern.h:171
PBVHNode * nodes
Definition: pbvh_intern.h:122
int face_sets_color_default
Definition: pbvh_intern.h:142