Blender  V3.3
pbvh_intern.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #pragma once
4 
5 struct PBVHGPUFormat;
6 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 struct MLoop;
16 struct MLoopTri;
17 struct MPoly;
18 struct MVert;
19 
20 /* Axis-aligned bounding box */
21 typedef struct {
22  float bmin[3], bmax[3];
23 } BB;
24 
25 /* Axis-aligned bounding box with centroid */
26 typedef struct {
27  float bmin[3], bmax[3], bcentroid[3];
28 } BBC;
29 
30 struct MeshElemMap;
31 
32 /* NOTE: this structure is getting large, might want to split it into
33  * union'd structs */
34 struct PBVHNode {
35  /* Opaque handle for drawing code */
37 
38  /* Voxel bounds */
39  BB vb;
41 
42  /* For internal nodes, the offset of the children in the PBVH
43  * 'nodes' array. */
45 
46  /* List of primitives for this node. Semantics depends on
47  * PBVH type:
48  *
49  * - PBVH_FACES: Indices into the PBVH.looptri array.
50  * - PBVH_GRIDS: Multires grid indices.
51  * - PBVH_BMESH: Unused. See PBVHNode.bm_faces.
52  *
53  * NOTE: This is a pointer inside of PBVH.prim_indices; it
54  * is not allocated separately per node.
55  */
57  unsigned int totprim; /* Number of primitives inside prim_indices. */
58 
59  /* Array of indices into the mesh's MVert array. Contains the
60  * indices of all vertices used by faces that are within this
61  * node's bounding box.
62  *
63  * Note that a vertex might be used by a multiple faces, and
64  * these faces might be in different leaf nodes. Such a vertex
65  * will appear in the vert_indices array of each of those leaf
66  * nodes.
67  *
68  * In order to support cases where you want access to multiple
69  * nodes' vertices without duplication, the vert_indices array
70  * is ordered such that the first part of the array, up to
71  * index 'uniq_verts', contains "unique" vertex indices. These
72  * vertices might not be truly unique to this node, but if
73  * they appear in another node's vert_indices array, they will
74  * be above that node's 'uniq_verts' value.
75  *
76  * Used for leaf nodes in a mesh-based PBVH (not multires.)
77  */
78  const int *vert_indices;
79  unsigned int uniq_verts, face_verts;
80 
81  /* Array of indices into the Mesh's MLoop array.
82  * PBVH_FACES only.
83  */
85  unsigned int loop_indices_num;
86 
87  /* An array mapping face corners into the vert_indices
88  * array. The array is sized to match 'totprim', and each of
89  * the face's corners gets an index into the vert_indices
90  * array, in the same order as the corners in the original
91  * MLoopTri.
92  *
93  * Used for leaf nodes in a mesh-based PBVH (not multires.)
94  */
95  const int (*face_vert_indices)[3];
96 
97  /* Indicates whether this node is a leaf or not; also used for
98  * marking various updates that need to be applied. */
100 
101  /* Used for raycasting: how close bb is to the ray point. */
102  float tmin;
103 
104  /* Scalar displacements for sculpt mode's layer brush. */
105  float *layer_disp;
106 
109 
110  /* Dyntopo */
111 
112  /* GSet of pointers to the BMFaces used by this node.
113  * NOTE: PBVH_BMESH only. Faces are always triangles
114  * (dynamic topology forcibly triangulates the mesh).
115  */
119  float (*bm_orco)[3];
120  int (*bm_ortri)[3];
122 
123  /* Used to store the brush color during a stroke and composite it over the original color */
126 };
127 
129 
130 typedef struct PBVHBMeshLog PBVHBMeshLog;
131 
132 struct PBVH {
135 
138 
139  /* Memory backing for PBVHNode.prim_indices. */
141  int totprim;
142  int totvert;
143 
145 
146  /* Mesh data */
147  const struct Mesh *mesh;
148 
149  /* NOTE: Normals are not `const` because they can be updated for drawing by sculpt code. */
151  struct MVert *verts;
152  const struct MPoly *mpoly;
153  const struct MLoop *mloop;
154  const struct MLoopTri *looptri;
158 
161  int *face_sets;
162 
163  /* Grid Data */
166  void **gridfaces;
168  int totgrid;
170 
171  /* Used during BVH build and later to mark that a vertex needs to update
172  * (its normal must be recalculated). */
173  bool *vert_bitmap;
174 
175 #ifdef PERFCNTRS
176  int perf_modified;
177 #endif
178 
179  /* flag are verts/faces deformed */
180  bool deformed;
181  bool show_mask;
184 
185  /* Dynamic topology */
191 
192  float planes[6][4];
194 
195  struct BMLog *bm_log;
197 
198  const struct MeshElemMap *pmap;
199 
202 
204 
205  /* Used by DynTopo to invalidate the draw cache. */
207 
209 };
210 
211 /* pbvh.c */
212 
213 void BB_reset(BB *bb);
217 void BB_expand(BB *bb, const float co[3]);
221 void BB_expand_with_bb(BB *bb, BB *bb2);
222 void BBC_update_centroid(BBC *bbc);
226 int BB_widest_axis(const BB *bb);
227 void pbvh_grow_nodes(PBVH *bvh, int totnode);
228 bool ray_face_intersection_quad(const float ray_start[3],
229  struct IsectRayPrecalc *isect_precalc,
230  const float t0[3],
231  const float t1[3],
232  const float t2[3],
233  const float t3[3],
234  float *depth);
235 bool ray_face_intersection_tri(const float ray_start[3],
236  struct IsectRayPrecalc *isect_precalc,
237  const float t0[3],
238  const float t1[3],
239  const float t2[3],
240  float *depth);
241 
242 bool ray_face_nearest_quad(const float ray_start[3],
243  const float ray_normal[3],
244  const float t0[3],
245  const float t1[3],
246  const float t2[3],
247  const float t3[3],
248  float *r_depth,
249  float *r_dist_sq);
250 bool ray_face_nearest_tri(const float ray_start[3],
251  const float ray_normal[3],
252  const float t0[3],
253  const float t1[3],
254  const float t2[3],
255  float *r_depth,
256  float *r_dist_sq);
257 
258 void pbvh_update_BB_redraw(PBVH *bvh, PBVHNode **nodes, int totnode, int flag);
259 
260 /* pbvh_bmesh.c */
261 
263  const float ray_start[3],
264  const float ray_normal[3],
265  struct IsectRayPrecalc *isect_precalc,
266  float *dist,
267  bool use_original,
268  int *r_active_vertex_index,
269  float *r_face_normal);
271  const float ray_start[3],
272  const float ray_normal[3],
273  float *depth,
274  float *dist_sq,
275  bool use_original);
276 
277 void pbvh_bmesh_normals_update(PBVHNode **nodes, int totnode);
278 
279 /* pbvh_pixels.hh */
280 
284 
285 #ifdef __cplusplus
286 }
287 #endif
typedef float(TangentPoint)[2]
eAttrDomain
Definition: BKE_attribute.h:25
struct CCGElem CCGElem
Definition: BKE_ccg.h:30
PBVHType
Definition: BKE_pbvh.h:233
PBVHNodeFlags
Definition: BKE_pbvh.h:63
unsigned int BLI_bitmap
Definition: BLI_bitmap.h:16
struct GSet GSet
Definition: BLI_ghash.h:340
OperationNode * node
PBVHFlags
Definition: pbvh_intern.h:128
@ PBVH_DYNTOPO_SMOOTH_SHADING
Definition: pbvh_intern.h:128
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:1606
void pbvh_pixels_free_brush_test(PBVHNode *node)
void BB_expand_with_bb(BB *bb, BB *bb2)
Definition: pbvh.c:77
int BB_widest_axis(const BB *bb)
Definition: pbvh.c:85
void pbvh_pixels_free(PBVHNode *node)
Definition: pbvh_pixels.cc:388
bool ray_face_intersection_tri(const float ray_start[3], struct IsectRayPrecalc *isect_precalc, const float t0[3], const float t1[3], const float t2[3], float *depth)
Definition: pbvh.c:2205
void pbvh_grow_nodes(PBVH *bvh, int totnode)
Definition: pbvh.c:224
struct PBVHBMeshLog PBVHBMeshLog
Definition: pbvh_intern.h:130
bool ray_face_intersection_quad(const float ray_start[3], struct IsectRayPrecalc *isect_precalc, const float t0[3], const float t1[3], const float t2[3], const float t3[3], float *depth)
Definition: pbvh.c:2184
void pbvh_free_draw_buffers(PBVH *pbvh, PBVHNode *node)
Definition: pbvh.c:1389
void pbvh_bmesh_normals_update(PBVHNode **nodes, int totnode)
Definition: pbvh_bmesh.c:1647
void pbvh_update_BB_redraw(PBVH *bvh, PBVHNode **nodes, int totnode, int flag)
Definition: pbvh.c:1250
bool ray_face_nearest_quad(const float ray_start[3], const float ray_normal[3], const float t0[3], const float t1[3], const float t2[3], const float t3[3], float *r_depth, float *r_dist_sq)
Definition: pbvh.c:2247
void BBC_update_centroid(BBC *bbc)
Definition: pbvh.c:108
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:1498
bool ray_face_nearest_tri(const float ray_start[3], const float ray_normal[3], const float t0[3], const float t1[3], const float t2[3], float *r_depth, float *r_dist_sq)
Definition: pbvh.c:2274
void BB_reset(BB *bb)
Definition: pbvh.c:63
void BB_expand(BB *bb, const float co[3])
Definition: pbvh.c:69
Definition: pbvh_intern.h:21
Definition: BKE_ccg.h:32
const int(* face_vert_indices)[3]
Definition: pbvh_intern.h:95
unsigned int loop_indices_num
Definition: pbvh_intern.h:85
int proxy_count
Definition: pbvh_intern.h:107
unsigned int totprim
Definition: pbvh_intern.h:57
GSet * bm_faces
Definition: pbvh_intern.h:116
struct GPU_PBVH_Buffers * draw_buffers
Definition: pbvh_intern.h:36
float tmin
Definition: pbvh_intern.h:102
int * prim_indices
Definition: pbvh_intern.h:56
unsigned int face_verts
Definition: pbvh_intern.h:79
GSet * bm_unique_verts
Definition: pbvh_intern.h:117
BB orig_vb
Definition: pbvh_intern.h:40
float * layer_disp
Definition: pbvh_intern.h:105
int * loop_indices
Definition: pbvh_intern.h:84
const int * vert_indices
Definition: pbvh_intern.h:78
PBVHProxyNode * proxies
Definition: pbvh_intern.h:108
float(* bm_orco)[3]
Definition: pbvh_intern.h:119
PBVHPixelsNode pixels
Definition: pbvh_intern.h:125
PBVHColorBufferNode color_buffer
Definition: pbvh_intern.h:124
unsigned int uniq_verts
Definition: pbvh_intern.h:79
int children_offset
Definition: pbvh_intern.h:44
int(* bm_ortri)[3]
Definition: pbvh_intern.h:120
int bm_tot_ortri
Definition: pbvh_intern.h:121
PBVHNodeFlags flag
Definition: pbvh_intern.h:99
GSet * bm_other_verts
Definition: pbvh_intern.h:118
PBVHType type
Definition: pbvh_intern.h:133
float planes[6][4]
Definition: pbvh_intern.h:192
int totvert
Definition: pbvh_intern.h:142
int * prim_indices
Definition: pbvh_intern.h:140
CustomData * ldata
Definition: pbvh_intern.h:156
const DMFlagMat * grid_flag_mats
Definition: pbvh_intern.h:167
CustomData * pdata
Definition: pbvh_intern.h:157
float(* vert_normals)[3]
Definition: pbvh_intern.h:150
bool respect_hide
Definition: pbvh_intern.h:183
BLI_bitmap ** grid_hidden
Definition: pbvh_intern.h:169
int cd_face_node_offset
Definition: pbvh_intern.h:190
bool deformed
Definition: pbvh_intern.h:180
bool * vert_bitmap
Definition: pbvh_intern.h:173
struct MVert * verts
Definition: pbvh_intern.h:151
const struct MPoly * mpoly
Definition: pbvh_intern.h:152
bool show_mask
Definition: pbvh_intern.h:181
int face_sets_color_seed
Definition: pbvh_intern.h:159
CCGElem ** grids
Definition: pbvh_intern.h:165
const struct Mesh * mesh
Definition: pbvh_intern.h:147
struct BMLog * bm_log
Definition: pbvh_intern.h:195
const struct MeshElemMap * pmap
Definition: pbvh_intern.h:198
bool is_drawing
Definition: pbvh_intern.h:203
CCGKey gridkey
Definition: pbvh_intern.h:164
int totprim
Definition: pbvh_intern.h:141
float bm_min_edge_len
Definition: pbvh_intern.h:188
int num_planes
Definition: pbvh_intern.h:193
int node_mem_count
Definition: pbvh_intern.h:137
int totgrid
Definition: pbvh_intern.h:168
void ** gridfaces
Definition: pbvh_intern.h:166
int leaf_limit
Definition: pbvh_intern.h:144
bool draw_cache_invalid
Definition: pbvh_intern.h:206
struct PBVHGPUFormat * vbo_id
Definition: pbvh_intern.h:208
const struct MLoop * mloop
Definition: pbvh_intern.h:153
bool show_face_sets
Definition: pbvh_intern.h:182
eAttrDomain color_domain
Definition: pbvh_intern.h:201
int * face_sets
Definition: pbvh_intern.h:161
PBVHFlags flags
Definition: pbvh_intern.h:134
float bm_max_edge_len
Definition: pbvh_intern.h:187
const struct MLoopTri * looptri
Definition: pbvh_intern.h:154
struct SubdivCCG * subdiv_ccg
Definition: pbvh_intern.h:196
BMesh * bm
Definition: pbvh_intern.h:186
int totnode
Definition: pbvh_intern.h:137
CustomData * vdata
Definition: pbvh_intern.h:155
int cd_vert_node_offset
Definition: pbvh_intern.h:189
PBVHNode * nodes
Definition: pbvh_intern.h:136
int face_sets_color_default
Definition: pbvh_intern.h:160
CustomDataLayer * color_layer
Definition: pbvh_intern.h:200