Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenkernel/intern/pbvh.c')
-rw-r--r--source/blender/blenkernel/intern/pbvh.c132
1 files changed, 62 insertions, 70 deletions
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 6cebcdfea4e..0ec7a79f890 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -555,7 +555,7 @@ void BKE_pbvh_build_mesh(PBVH *pbvh,
BB cb;
pbvh->mesh = mesh;
- pbvh->type = PBVH_FACES;
+ pbvh->header.type = PBVH_FACES;
pbvh->mpoly = mpoly;
pbvh->mloop = mloop;
pbvh->looptri = looptri;
@@ -615,7 +615,7 @@ void BKE_pbvh_build_grids(PBVH *pbvh,
{
const int gridsize = key->grid_size;
- pbvh->type = PBVH_GRIDS;
+ pbvh->header.type = PBVH_GRIDS;
pbvh->grids = grids;
pbvh->gridfaces = gridfaces;
pbvh->grid_flag_mats = flagmats;
@@ -1305,17 +1305,17 @@ static void pbvh_update_draw_buffer_cb(void *__restrict userdata,
CustomData *vdata, *ldata;
- if (!pbvh->bm) {
+ if (!pbvh->header.bm) {
vdata = pbvh->vdata;
ldata = pbvh->ldata;
}
else {
- vdata = &pbvh->bm->vdata;
- ldata = &pbvh->bm->ldata;
+ vdata = &pbvh->header.bm->vdata;
+ ldata = &pbvh->header.bm->ldata;
}
if (node->flag & PBVH_RebuildDrawBuffers) {
- switch (pbvh->type) {
+ switch (pbvh->header.type) {
case PBVH_GRIDS: {
bool smooth = node->totprim > 0 ?
pbvh->grid_flag_mats[node->prim_indices[0]].flag & ME_SMOOTH :
@@ -1344,7 +1344,7 @@ static void pbvh_update_draw_buffer_cb(void *__restrict userdata,
if (node->flag & PBVH_UpdateDrawBuffers) {
const int update_flags = pbvh_get_buffers_update_flags(pbvh);
- switch (pbvh->type) {
+ switch (pbvh->header.type) {
case PBVH_GRIDS:
GPU_pbvh_grid_buffers_update(pbvh->vbo_id,
node->draw_buffers,
@@ -1376,7 +1376,7 @@ static void pbvh_update_draw_buffer_cb(void *__restrict userdata,
case PBVH_BMESH:
GPU_pbvh_bmesh_buffers_update(pbvh->vbo_id,
node->draw_buffers,
- pbvh->bm,
+ pbvh->header.bm,
node->bm_faces,
node->bm_unique_verts,
node->bm_other_verts,
@@ -1405,15 +1405,15 @@ static void pbvh_check_draw_layout(PBVH *pbvh)
pbvh->vbo_id = GPU_pbvh_make_format();
}
- switch (pbvh->type) {
+ switch (pbvh->header.type) {
case PBVH_BMESH:
- if (!pbvh->bm) {
+ if (!pbvh->header.bm) {
/* BMesh hasn't been created yet */
return;
}
- vdata = &pbvh->bm->vdata;
- ldata = &pbvh->bm->ldata;
+ vdata = &pbvh->header.bm->vdata;
+ ldata = &pbvh->header.bm->ldata;
break;
case PBVH_FACES:
vdata = pbvh->vdata;
@@ -1431,7 +1431,7 @@ static void pbvh_check_draw_layout(PBVH *pbvh)
* (there's no guarantee there isn't another EEVEE viewport which would
* free the draw buffers and corrupt the draw cache).
*/
- if (GPU_pbvh_attribute_names_update(pbvh->type, pbvh->vbo_id, vdata, ldata, false)) {
+ if (GPU_pbvh_attribute_names_update(pbvh->header.type, pbvh->vbo_id, vdata, ldata, false)) {
/* attribute layout changed; force rebuild */
for (int i = 0; i < pbvh->totnode; i++) {
PBVHNode *node = pbvh->nodes + i;
@@ -1451,14 +1451,14 @@ static void pbvh_update_draw_buffers(PBVH *pbvh, PBVHNode **nodes, int totnode,
pbvh->vbo_id = GPU_pbvh_make_format();
}
- switch (pbvh->type) {
+ switch (pbvh->header.type) {
case PBVH_BMESH:
- if (!pbvh->bm) {
+ if (!pbvh->header.bm) {
/* BMesh hasn't been created yet */
return;
}
- vdata = &pbvh->bm->vdata;
+ vdata = &pbvh->header.bm->vdata;
break;
case PBVH_FACES:
vdata = pbvh->vdata;
@@ -1469,7 +1469,7 @@ static void pbvh_update_draw_buffers(PBVH *pbvh, PBVHNode **nodes, int totnode,
}
UNUSED_VARS(vdata);
- if ((update_flag & PBVH_RebuildDrawBuffers) || ELEM(pbvh->type, PBVH_GRIDS, PBVH_BMESH)) {
+ if ((update_flag & PBVH_RebuildDrawBuffers) || ELEM(pbvh->header.type, PBVH_GRIDS, PBVH_BMESH)) {
/* Free buffers uses OpenGL, so not in parallel. */
for (int n = 0; n < totnode; n++) {
PBVHNode *node = nodes[n];
@@ -1477,11 +1477,11 @@ static void pbvh_update_draw_buffers(PBVH *pbvh, PBVHNode **nodes, int totnode,
pbvh_free_draw_buffers(pbvh, node);
}
else if ((node->flag & PBVH_UpdateDrawBuffers) && node->draw_buffers) {
- if (pbvh->type == PBVH_GRIDS) {
+ if (pbvh->header.type == PBVH_GRIDS) {
GPU_pbvh_grid_buffers_update_free(
node->draw_buffers, pbvh->grid_flag_mats, node->prim_indices);
}
- else if (pbvh->type == PBVH_BMESH) {
+ else if (pbvh->header.type == PBVH_BMESH) {
GPU_pbvh_bmesh_buffers_update_free(node->draw_buffers);
}
}
@@ -1795,15 +1795,10 @@ void BKE_pbvh_get_grid_updates(PBVH *pbvh, bool clear, void ***r_gridfaces, int
/***************************** PBVH Access ***********************************/
-PBVHType BKE_pbvh_type(const PBVH *pbvh)
-{
- return pbvh->type;
-}
-
bool BKE_pbvh_has_faces(const PBVH *pbvh)
{
- if (pbvh->type == PBVH_BMESH) {
- return (pbvh->bm->totface != 0);
+ if (pbvh->header.type == PBVH_BMESH) {
+ return (pbvh->header.bm->totface != 0);
}
return (pbvh->totprim != 0);
@@ -1824,46 +1819,40 @@ void BKE_pbvh_bounding_box(const PBVH *pbvh, float min[3], float max[3])
BLI_bitmap **BKE_pbvh_grid_hidden(const PBVH *pbvh)
{
- BLI_assert(pbvh->type == PBVH_GRIDS);
+ BLI_assert(pbvh->header.type == PBVH_GRIDS);
return pbvh->grid_hidden;
}
const CCGKey *BKE_pbvh_get_grid_key(const PBVH *pbvh)
{
- BLI_assert(pbvh->type == PBVH_GRIDS);
+ BLI_assert(pbvh->header.type == PBVH_GRIDS);
return &pbvh->gridkey;
}
struct CCGElem **BKE_pbvh_get_grids(const PBVH *pbvh)
{
- BLI_assert(pbvh->type == PBVH_GRIDS);
+ BLI_assert(pbvh->header.type == PBVH_GRIDS);
return pbvh->grids;
}
BLI_bitmap **BKE_pbvh_get_grid_visibility(const PBVH *pbvh)
{
- BLI_assert(pbvh->type == PBVH_GRIDS);
+ BLI_assert(pbvh->header.type == PBVH_GRIDS);
return pbvh->grid_hidden;
}
int BKE_pbvh_get_grid_num_vertices(const PBVH *pbvh)
{
- BLI_assert(pbvh->type == PBVH_GRIDS);
+ BLI_assert(pbvh->header.type == PBVH_GRIDS);
return pbvh->totgrid * pbvh->gridkey.grid_area;
}
int BKE_pbvh_get_grid_num_faces(const PBVH *pbvh)
{
- BLI_assert(pbvh->type == PBVH_GRIDS);
+ BLI_assert(pbvh->header.type == PBVH_GRIDS);
return pbvh->totgrid * (pbvh->gridkey.grid_size - 1) * (pbvh->gridkey.grid_size - 1);
}
-BMesh *BKE_pbvh_get_bmesh(PBVH *pbvh)
-{
- BLI_assert(pbvh->type == PBVH_BMESH);
- return pbvh->bm;
-}
-
/***************************** Node Access ***********************************/
void BKE_pbvh_node_mark_update(PBVHNode *node)
@@ -1964,10 +1953,10 @@ bool BKE_pbvh_node_fully_unmasked_get(PBVHNode *node)
return (node->flag & PBVH_Leaf) && (node->flag & PBVH_FullyUnmasked);
}
-void BKE_pbvh_vert_mark_update(PBVH *pbvh, int index)
+void BKE_pbvh_vert_mark_update(PBVH *pbvh, PBVHVertRef index)
{
- BLI_assert(pbvh->type == PBVH_FACES);
- pbvh->vert_bitmap[index] = true;
+ BLI_assert(pbvh->header.type == PBVH_FACES);
+ pbvh->vert_bitmap[index.i] = true;
}
void BKE_pbvh_node_get_loops(PBVH *pbvh,
@@ -2004,7 +1993,7 @@ void BKE_pbvh_node_num_verts(PBVH *pbvh, PBVHNode *node, int *r_uniquevert, int
{
int tot;
- switch (pbvh->type) {
+ switch (pbvh->header.type) {
case PBVH_GRIDS:
tot = node->totprim * pbvh->gridkey.grid_area;
if (r_totvert) {
@@ -2042,7 +2031,7 @@ void BKE_pbvh_node_get_grids(PBVH *pbvh,
int *r_gridsize,
CCGElem ***r_griddata)
{
- switch (pbvh->type) {
+ switch (pbvh->header.type) {
case PBVH_GRIDS:
if (r_grid_indices) {
*r_grid_indices = node->prim_indices;
@@ -2125,7 +2114,7 @@ void BKE_pbvh_node_get_bm_orco_data(PBVHNode *node,
bool BKE_pbvh_node_vert_update_check_any(PBVH *pbvh, PBVHNode *node)
{
- BLI_assert(pbvh->type == PBVH_FACES);
+ BLI_assert(pbvh->header.type == PBVH_FACES);
const int *verts = node->vert_indices;
const int totvert = node->uniq_verts + node->face_verts;
@@ -2299,7 +2288,7 @@ static bool pbvh_faces_node_raycast(PBVH *pbvh,
const float ray_normal[3],
struct IsectRayPrecalc *isect_precalc,
float *depth,
- int *r_active_vertex_index,
+ PBVHVertRef *r_active_vertex,
int *r_active_face_index,
float *r_face_normal)
{
@@ -2339,7 +2328,7 @@ static bool pbvh_faces_node_raycast(PBVH *pbvh,
normal_tri_v3(r_face_normal, co[0], co[1], co[2]);
}
- if (r_active_vertex_index) {
+ if (r_active_vertex) {
float location[3] = {0.0f};
madd_v3_v3v3fl(location, ray_start, ray_normal, *depth);
for (int j = 0; j < 3; j++) {
@@ -2349,7 +2338,7 @@ static bool pbvh_faces_node_raycast(PBVH *pbvh,
if (j == 0 ||
len_squared_v3v3(location, co[j]) < len_squared_v3v3(location, nearest_vertex_co)) {
copy_v3_v3(nearest_vertex_co, co[j]);
- *r_active_vertex_index = mloop[lt->tri[j]].v;
+ r_active_vertex->i = mloop[lt->tri[j]].v;
*r_active_face_index = lt->poly;
}
}
@@ -2367,7 +2356,7 @@ static bool pbvh_grids_node_raycast(PBVH *pbvh,
const float ray_normal[3],
struct IsectRayPrecalc *isect_precalc,
float *depth,
- int *r_active_vertex_index,
+ PBVHVertRef *r_active_vertex,
int *r_active_grid_index,
float *r_face_normal)
{
@@ -2419,7 +2408,7 @@ static bool pbvh_grids_node_raycast(PBVH *pbvh,
normal_quad_v3(r_face_normal, co[0], co[1], co[2], co[3]);
}
- if (r_active_vertex_index) {
+ if (r_active_vertex) {
float location[3] = {0.0};
madd_v3_v3v3fl(location, ray_start, ray_normal, *depth);
@@ -2434,8 +2423,8 @@ static bool pbvh_grids_node_raycast(PBVH *pbvh,
len_squared_v3v3(location, nearest_vertex_co)) {
copy_v3_v3(nearest_vertex_co, co[j]);
- *r_active_vertex_index = gridkey->grid_area * grid_index +
- (y + y_it[j]) * gridkey->grid_size + (x + x_it[j]);
+ r_active_vertex->i = gridkey->grid_area * grid_index +
+ (y + y_it[j]) * gridkey->grid_size + (x + x_it[j]);
}
}
}
@@ -2462,7 +2451,7 @@ bool BKE_pbvh_node_raycast(PBVH *pbvh,
const float ray_normal[3],
struct IsectRayPrecalc *isect_precalc,
float *depth,
- int *active_vertex_index,
+ PBVHVertRef *active_vertex,
int *active_face_grid_index,
float *face_normal)
{
@@ -2472,7 +2461,7 @@ bool BKE_pbvh_node_raycast(PBVH *pbvh,
return false;
}
- switch (pbvh->type) {
+ switch (pbvh->header.type) {
case PBVH_FACES:
hit |= pbvh_faces_node_raycast(pbvh,
node,
@@ -2481,7 +2470,7 @@ bool BKE_pbvh_node_raycast(PBVH *pbvh,
ray_normal,
isect_precalc,
depth,
- active_vertex_index,
+ active_vertex,
active_face_grid_index,
face_normal);
break;
@@ -2493,19 +2482,19 @@ bool BKE_pbvh_node_raycast(PBVH *pbvh,
ray_normal,
isect_precalc,
depth,
- active_vertex_index,
+ active_vertex,
active_face_grid_index,
face_normal);
break;
case PBVH_BMESH:
- BM_mesh_elem_index_ensure(pbvh->bm, BM_VERT);
+ BM_mesh_elem_index_ensure(pbvh->header.bm, BM_VERT);
hit = pbvh_bmesh_node_raycast(node,
ray_start,
ray_normal,
isect_precalc,
depth,
use_origco,
- active_vertex_index,
+ active_vertex,
face_normal);
break;
}
@@ -2729,7 +2718,7 @@ bool BKE_pbvh_node_find_nearest_to_ray(PBVH *pbvh,
return false;
}
- switch (pbvh->type) {
+ switch (pbvh->header.type) {
case PBVH_FACES:
hit |= pbvh_faces_node_nearest_to_ray(
pbvh, node, origco, ray_start, ray_normal, depth, dist_sq);
@@ -2820,13 +2809,13 @@ void BKE_pbvh_update_normals(PBVH *pbvh, struct SubdivCCG *subdiv_ccg)
pbvh, update_search_cb, POINTER_FROM_INT(PBVH_UpdateNormals), &nodes, &totnode);
if (totnode > 0) {
- if (pbvh->type == PBVH_BMESH) {
+ if (pbvh->header.type == PBVH_BMESH) {
pbvh_bmesh_normals_update(nodes, totnode);
}
- else if (pbvh->type == PBVH_FACES) {
+ else if (pbvh->header.type == PBVH_FACES) {
pbvh_faces_update_normals(pbvh, nodes, totnode);
}
- else if (pbvh->type == PBVH_GRIDS) {
+ else if (pbvh->header.type == PBVH_GRIDS) {
struct CCGFace **faces;
int num_faces;
BKE_pbvh_get_grid_updates(pbvh, true, (void ***)&faces, &num_faces);
@@ -2991,7 +2980,7 @@ void BKE_pbvh_vert_coords_apply(PBVH *pbvh, const float (*vertCos)[3], const int
/* no need for float comparison here (memory is exactly equal or not) */
if (memcmp(mvert->co, vertCos[a], sizeof(float[3])) != 0) {
copy_v3_v3(mvert->co, vertCos[a]);
- BKE_pbvh_vert_mark_update(pbvh, a);
+ BKE_pbvh_vert_mark_update(pbvh, BKE_pbvh_make_vref(a));
}
}
@@ -3108,6 +3097,7 @@ void pbvh_vertex_iter_init(PBVH *pbvh, PBVHNode *node, PBVHVertexIter *vi, int m
vi->no = NULL;
vi->fno = NULL;
vi->mvert = NULL;
+ vi->vertex.i = 0LL;
vi->respect_hide = pbvh->respect_hide;
if (pbvh->respect_hide == false) {
@@ -3134,10 +3124,10 @@ void pbvh_vertex_iter_init(PBVH *pbvh, PBVHNode *node, PBVHVertexIter *vi, int m
vi->vert_indices = vert_indices;
vi->mverts = verts;
- if (pbvh->type == PBVH_BMESH) {
+ if (pbvh->header.type == PBVH_BMESH) {
BLI_gsetIterator_init(&vi->bm_unique_verts, node->bm_unique_verts);
BLI_gsetIterator_init(&vi->bm_other_verts, node->bm_other_verts);
- vi->bm_vdata = &pbvh->bm->vdata;
+ vi->bm_vdata = &pbvh->header.bm->vdata;
vi->cd_vert_mask_offset = CustomData_get_offset(vi->bm_vdata, CD_PAINT_MASK);
}
@@ -3147,7 +3137,7 @@ void pbvh_vertex_iter_init(PBVH *pbvh, PBVHNode *node, PBVHVertexIter *vi, int m
}
vi->mask = NULL;
- if (pbvh->type == PBVH_FACES) {
+ if (pbvh->header.type == PBVH_FACES) {
vi->vert_normals = pbvh->vert_normals;
vi->vmask = CustomData_get_layer(pbvh->vdata, CD_PAINT_MASK);
@@ -3156,13 +3146,14 @@ void pbvh_vertex_iter_init(PBVH *pbvh, PBVHNode *node, PBVHVertexIter *vi, int m
bool pbvh_has_mask(const PBVH *pbvh)
{
- switch (pbvh->type) {
+ switch (pbvh->header.type) {
case PBVH_GRIDS:
return (pbvh->gridkey.has_mask != 0);
case PBVH_FACES:
return (pbvh->vdata && CustomData_get_layer(pbvh->vdata, CD_PAINT_MASK));
case PBVH_BMESH:
- return (pbvh->bm && (CustomData_get_offset(&pbvh->bm->vdata, CD_PAINT_MASK) != -1));
+ return (pbvh->header.bm &&
+ (CustomData_get_offset(&pbvh->header.bm->vdata, CD_PAINT_MASK) != -1));
}
return false;
@@ -3170,7 +3161,7 @@ bool pbvh_has_mask(const PBVH *pbvh)
bool pbvh_has_face_sets(PBVH *pbvh)
{
- switch (pbvh->type) {
+ switch (pbvh->header.type) {
case PBVH_GRIDS:
return (pbvh->pdata && CustomData_get_layer(pbvh->pdata, CD_SCULPT_FACE_SETS));
case PBVH_FACES:
@@ -3218,13 +3209,13 @@ void BKE_pbvh_parallel_range_settings(TaskParallelSettings *settings,
MVert *BKE_pbvh_get_verts(const PBVH *pbvh)
{
- BLI_assert(pbvh->type == PBVH_FACES);
+ BLI_assert(pbvh->header.type == PBVH_FACES);
return pbvh->verts;
}
const float (*BKE_pbvh_get_vert_normals(const PBVH *pbvh))[3]
{
- BLI_assert(pbvh->type == PBVH_FACES);
+ BLI_assert(pbvh->header.type == PBVH_FACES);
return pbvh->vert_normals;
}
@@ -3242,6 +3233,7 @@ void BKE_pbvh_respect_hide_set(PBVH *pbvh, bool respect_hide)
{
pbvh->respect_hide = respect_hide;
}
+
bool BKE_pbvh_is_drawing(const PBVH *pbvh)
{
return pbvh->is_drawing;