Hidden PBVH nodes:

Set hidden when rebuilding the PBVH tree if all primitives are hidden.
This commit is contained in:
Antonis Ryakiotakis 2014-05-05 22:21:30 +03:00
parent 9088604811
commit 312d3edee5
4 changed files with 62 additions and 35 deletions

View File

@ -128,6 +128,10 @@ void BKE_pbvh_bounding_box(const PBVH *bvh, float min[3], float max[3]);
/* multires hidden data, only valid for type == PBVH_GRIDS */
unsigned int **BKE_pbvh_grid_hidden(const PBVH *bvh);
int BKE_pbvh_count_grid_quads(BLI_bitmap **grid_hidden,
int *grid_indices, int totgrid,
int gridsize);
/* multires level, only valid for type == PBVH_GRIDS */
void BKE_pbvh_get_grid_key(const PBVH *pbvh, struct CCGKey *key);

View File

@ -275,6 +275,7 @@ static void build_mesh_leaf_node(PBVH *bvh, PBVHNode *node)
GHashIterator *iter;
GHash *map;
int i, j, totface;
bool has_visible = false;
node->uniq_verts = node->face_verts = 0;
totface = node->totprim;
@ -294,6 +295,9 @@ static void build_mesh_leaf_node(PBVH *bvh, PBVHNode *node)
map_insert_vert(bvh, map, &node->face_verts,
&node->uniq_verts, (&f->v1)[j]);
}
if(!paint_is_face_hidden(f, bvh->verts))
has_visible = true;
}
node->vert_indices = MEM_callocN(sizeof(int) *
@ -331,6 +335,8 @@ static void build_mesh_leaf_node(PBVH *bvh, PBVHNode *node)
BKE_pbvh_node_mark_rebuild_draw(node);
BKE_pbvh_node_fully_hidden_set(node, !has_visible);
BLI_ghash_free(map, NULL, NULL);
}
@ -346,6 +352,45 @@ static void update_vb(PBVH *bvh, PBVHNode *node, BBC *prim_bbc,
node->orig_vb = node->vb;
}
/* Returns the number of visible quads in the nodes' grids. */
int BKE_pbvh_count_grid_quads(BLI_bitmap **grid_hidden,
int *grid_indices, int totgrid,
int gridsize)
{
int gridarea = (gridsize - 1) * (gridsize - 1);
int i, x, y, totquad;
/* grid hidden layer is present, so have to check each grid for
* visibility */
for (i = 0, totquad = 0; i < totgrid; i++) {
const BLI_bitmap *gh = grid_hidden[grid_indices[i]];
if (gh) {
/* grid hidden are present, have to check each element */
for (y = 0; y < gridsize - 1; y++) {
for (x = 0; x < gridsize - 1; x++) {
if (!paint_is_grid_face_hidden(gh, gridsize, x, y))
totquad++;
}
}
}
else
totquad += gridarea;
}
return totquad;
}
static void build_grid_leaf_node(PBVH *bvh, PBVHNode *node)
{
int totquads = BKE_pbvh_count_grid_quads(bvh->grid_hidden, node->prim_indices,
node->totprim, bvh->gridkey.grid_size);
BKE_pbvh_node_fully_hidden_set(node, (totquads == 0));
BKE_pbvh_node_mark_rebuild_draw(node);
}
static void build_leaf(PBVH *bvh, int node_index, BBC *prim_bbc,
int offset, int count)
{
@ -359,8 +404,9 @@ static void build_leaf(PBVH *bvh, int node_index, BBC *prim_bbc,
if (bvh->faces)
build_mesh_leaf_node(bvh, bvh->nodes + node_index);
else
BKE_pbvh_node_mark_rebuild_draw(bvh->nodes + node_index);
else {
build_grid_leaf_node(bvh, bvh->nodes + node_index);
}
}
/* Return zero if all primitives in the node can be drawn with the
@ -1033,7 +1079,7 @@ static void pbvh_update_draw_buffers(PBVH *bvh, PBVHNode **nodes, int totnode)
GPU_build_grid_pbvh_buffers(node->prim_indices,
node->totprim,
bvh->grid_hidden,
bvh->gridkey.grid_size);
bvh->gridkey.grid_size);
break;
case PBVH_FACES:
node->draw_buffers =

View File

@ -48,6 +48,7 @@ static void pbvh_bmesh_node_finalize(PBVH *bvh, int node_index, const int cd_ver
{
GSetIterator gs_iter;
PBVHNode *n = &bvh->nodes[node_index];
bool has_visible = false;
/* Create vert hash sets */
n->bm_unique_verts = BLI_gset_ptr_new("bm_unique_verts");
@ -80,6 +81,9 @@ static void pbvh_bmesh_node_finalize(PBVH *bvh, int node_index, const int cd_ver
/* Update node bounding box */
BB_expand(&n->vb, v->co);
} while ((l_iter = l_iter->next) != l_first);
if (!BM_elem_flag_test(f, BM_ELEM_HIDDEN))
has_visible = true;
}
BLI_assert(n->vb.bmin[0] <= n->vb.bmax[0] &&
@ -90,6 +94,8 @@ static void pbvh_bmesh_node_finalize(PBVH *bvh, int node_index, const int cd_ver
/* Build GPU buffers for new node and update vertex normals */
BKE_pbvh_node_mark_rebuild_draw(n);
BKE_pbvh_node_fully_hidden_set(n, !has_visible);
n->flag |= PBVH_UpdateNormals;
}

View File

@ -51,6 +51,7 @@
#include "BKE_ccg.h"
#include "BKE_DerivedMesh.h"
#include "BKE_paint.h"
#include "BKE_pbvh.h"
#include "DNA_userdef_types.h"
@ -1827,36 +1828,6 @@ void GPU_update_grid_pbvh_buffers(GPU_PBVH_Buffers *buffers, CCGElem **grids,
//printf("node updated %p\n", buffers);
}
/* Returns the number of visible quads in the nodes' grids. */
static int gpu_count_grid_quads(BLI_bitmap **grid_hidden,
int *grid_indices, int totgrid,
int gridsize)
{
int gridarea = (gridsize - 1) * (gridsize - 1);
int i, x, y, totquad;
/* grid hidden layer is present, so have to check each grid for
* visibility */
for (i = 0, totquad = 0; i < totgrid; i++) {
const BLI_bitmap *gh = grid_hidden[grid_indices[i]];
if (gh) {
/* grid hidden are present, have to check each element */
for (y = 0; y < gridsize - 1; y++) {
for (x = 0; x < gridsize - 1; x++) {
if (!paint_is_grid_face_hidden(gh, gridsize, x, y))
totquad++;
}
}
}
else
totquad += gridarea;
}
return totquad;
}
/* Build the element array buffer of grid indices using either
* unsigned shorts or unsigned ints. */
#define FILL_QUAD_BUFFER(type_, tot_quad_, buffer_) \
@ -1960,7 +1931,7 @@ static GLuint gpu_get_grid_buffer(int gridsize, GLenum *index_type, unsigned *to
}
GPU_PBVH_Buffers *GPU_build_grid_pbvh_buffers(int *grid_indices, int totgrid,
BLI_bitmap **grid_hidden, int gridsize)
BLI_bitmap **grid_hidden, int gridsize)
{
GPU_PBVH_Buffers *buffers;
int totquad;
@ -1974,7 +1945,7 @@ GPU_PBVH_Buffers *GPU_build_grid_pbvh_buffers(int *grid_indices, int totgrid,
buffers->use_matcaps = false;
/* Count the number of quads */
totquad = gpu_count_grid_quads(grid_hidden, grid_indices, totgrid, gridsize);
totquad = BKE_pbvh_count_grid_quads(grid_hidden, grid_indices, totgrid, gridsize);
/* totally hidden node, return here to avoid BufferData with zero below. */
if (totquad == 0)