Commit current code state

This commit is contained in:
Joseph Eagar 2021-04-14 15:55:09 -07:00
parent a5fa9ec310
commit 384a0930d1
7 changed files with 78 additions and 96 deletions

View File

@ -1286,6 +1286,8 @@ static void pbvh_update_draw_buffer_cb(void *__restrict userdata,
PBVHNode *node = data->nodes[n];
if (node->flag & PBVH_RebuildDrawBuffers) {
node->updategen++;
switch (pbvh->type) {
case PBVH_GRIDS:
node->draw_buffers = GPU_pbvh_grid_buffers_build(node->totprim, pbvh->grid_hidden);
@ -1309,6 +1311,7 @@ static void pbvh_update_draw_buffer_cb(void *__restrict userdata,
}
if (node->flag & PBVH_UpdateDrawBuffers) {
node->updategen++;
const int update_flags = pbvh_get_buffers_update_flags(pbvh);
switch (pbvh->type) {
@ -1337,11 +1340,13 @@ static void pbvh_update_draw_buffer_cb(void *__restrict userdata,
update_flags);
break;
case PBVH_BMESH:
BKE_pbvh_bmesh_check_tris(pbvh, node);
GPU_pbvh_bmesh_buffers_update(node->draw_buffers,
pbvh->bm,
node->bm_faces,
node->bm_unique_verts,
node->bm_other_verts,
node->tribuf,
update_flags,
pbvh->cd_vert_node_offset,
pbvh->face_sets_color_seed,
@ -2891,7 +2896,9 @@ void BKE_pbvh_draw_debug_cb(
for (int a = 0; a < pbvh->totnode; a++) {
PBVHNode *node = &pbvh->nodes[a];
draw_fn(user_data, node->vb.bmin, node->vb.bmax, node->flag);
int num = a + node->updategen;
draw_fn(&num, node->vb.bmin, node->vb.bmax, node->flag);
}
}

View File

@ -2702,7 +2702,7 @@ bool BKE_pbvh_bmesh_check_origdata(PBVH *pbvh, BMVert *v, int stroke_id)
MDynTopoVert *mv = BKE_PBVH_DYNVERT(pbvh->cd_dyn_vert, v);
if (mv->stroke_id != stroke_id) {
void *dummy;
float *dummy;
BKE_pbvh_bmesh_update_origvert(pbvh, v, &dummy, &dummy, &dummy, false);
mv->stroke_id = stroke_id;
@ -2825,7 +2825,7 @@ bool BKE_pbvh_bmesh_node_raycast_detail(PBVH *pbvh,
BKE_pbvh_bmesh_check_tris(pbvh, node);
for (int i = 0; i < node->tribuf->tottri; i++) {
PBVHTri *tri = node->tribuf + i;
PBVHTri *tri = node->tribuf->tris + i;
BMVert *v1 = (BMVert *)node->tribuf->verts[tri->v[0]].i;
BMVert *v2 = (BMVert *)node->tribuf->verts[tri->v[1]].i;
BMVert *v3 = (BMVert *)node->tribuf->verts[tri->v[2]].i;
@ -2869,7 +2869,7 @@ bool pbvh_bmesh_node_nearest_to_ray(PBVH *pbvh,
const int cd_dyn_vert = pbvh->cd_dyn_vert;
for (int i = 0; i < tribuf->tottri; i++) {
PBVHTri *tri = tribuf + i;
PBVHTri *tri = tribuf->tris + i;
BMFace *f = (BMFace *)tri->f.i;
if (BM_elem_flag_test(f, BM_ELEM_HIDDEN)) {
@ -3736,7 +3736,7 @@ static bool pbvh_bmesh_split_tris(PBVH *pbvh, PBVHNode *node)
MLoopUV *uv1 = BM_ELEM_CD_GET_VOID_P(l, cd_uv + cd_size * i);
MLoopUV *uv2 = BM_ELEM_CD_GET_VOID_P(l2, cd_uv + cd_size * i);
if (len_v3v3(uv1, uv2) > 0.001) {
if (len_v3v3(uv1->uv, uv2->uv) > 0.001) {
ok = false;
break;
}

View File

@ -109,6 +109,8 @@ struct PBVHNode {
PBVHTriBuf *tribuf;
int updategen;
/* Used to store the brush color during a stroke and composite it over the original color */
PBVHColorBufferNode color_buffer;
#ifdef PROXY_ADVANCED

View File

@ -4518,6 +4518,7 @@ static void do_elastic_deform_brush_task_cb_ex(void *__restrict userdata,
const float bstrength = ss->cache->bstrength;
SCULPT_orig_vert_data_init(&orig_data, data->ob, data->nodes[n], SCULPT_UNDO_COORDS);
bool update = false;
proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co;
@ -4575,11 +4576,13 @@ static void do_elastic_deform_brush_task_cb_ex(void *__restrict userdata,
mul_v3_fl(final_disp, SCULPT_automasking_factor_get(ss->cache->automasking, ss, vd.vertex));
copy_v3_v3(proxy[vd.i], final_disp);
if (vd.mvert) {
vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
if (dot_v3v3(final_disp, final_disp) > 0.0000001) {
if (vd.mvert) {
vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
}
}
copy_v3_v3(proxy[vd.i], final_disp);
}
BKE_pbvh_vertex_iter_end;
}
@ -6552,6 +6555,7 @@ static void do_brush_action(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSe
else {
for (int i = 0; i < totnode; i++) {
SCULPT_ensure_dyntopo_node_undo(ob, nodes[i], SCULPT_UNDO_COORDS, -1);
BKE_pbvh_node_mark_update(nodes[i]);
}
}

View File

@ -126,7 +126,7 @@ static SculptVertRef sculpt_boundary_get_closest_boundary_vertex(
BoundaryInitialVertexFloodFillData fdata = {
.initial_vertex = initial_vertex,
.initial_vertex_index = initial_vertex_index,
.boundary_initial_vertex = BOUNDARY_VERTEX_NONE,
.boundary_initial_vertex = {BOUNDARY_VERTEX_NONE},
.boundary_initial_vertex_steps = INT_MAX,
.radius_sq = radius * radius,
};
@ -297,7 +297,7 @@ static void sculpt_boundary_indices_init(SculptSession *ss,
BoundaryFloodFillData fdata = {
.boundary = boundary,
.included_vertices = included_vertices,
.last_visited_vertex = BOUNDARY_VERTEX_NONE,
.last_visited_vertex = {BOUNDARY_VERTEX_NONE},
};
@ -414,7 +414,8 @@ static void sculpt_boundary_edit_data_init(SculptSession *ss,
boundary->edit_info[ni.index].num_propagation_steps =
boundary->edit_info[from_v_i].num_propagation_steps + 1;
BLI_gsqueue_push(next_iteration, &ni.index);
BLI_gsqueue_push(next_iteration, &ni.vertex);
/* When copying the data to the neighbor for the next iteration, it has to be copied to
* all its duplicates too. This is because it is not possible to know if the updated
@ -569,6 +570,8 @@ SculptBoundary *SCULPT_boundary_data_init(Object *object,
void SCULPT_boundary_data_free(SculptBoundary *boundary)
{
printf(" ======================= boundary free!\n\n");
MEM_SAFE_FREE(boundary->vertices);
MEM_SAFE_FREE(boundary->edges);
MEM_SAFE_FREE(boundary->distance);

View File

@ -93,6 +93,7 @@ void GPU_pbvh_bmesh_buffers_update(GPU_PBVH_Buffers *buffers,
struct TableGSet *bm_faces,
struct TableGSet *bm_unique_verts,
struct TableGSet *bm_other_verts,
struct PBVHTriBuf *tribuf,
const int update_flags,
const int cd_vert_node_offset,
int face_sets_color_seed,

View File

@ -135,10 +135,11 @@ static bool gpu_pbvh_vert_buf_data_set(GPU_PBVH_Buffers *buffers, uint vert_len)
if (buffers->vert_buf == NULL) {
/* Initialize vertex buffer (match 'VertexBufferFormat'). */
buffers->vert_buf = GPU_vertbuf_create_with_format_ex(&g_vbo_id.format, GPU_USAGE_DYNAMIC);
GPU_vertbuf_data_alloc(buffers->vert_buf, vert_len);
}
else if (vert_len != buffers->vert_buf->vertex_len) {
GPU_vertbuf_data_resize(buffers->vert_buf, vert_len);
if (GPU_vertbuf_get_data(buffers->vert_buf) == NULL ||
GPU_vertbuf_get_vertex_len(buffers->vert_buf) != vert_len) {
/* Allocate buffer if not allocated yet or size changed. */
GPU_vertbuf_data_alloc(buffers->vert_buf, vert_len);
}
#else
if (buffers->vert_buf == NULL) {
@ -817,34 +818,14 @@ static void gpu_bmesh_vert_to_buffer_copy(BMVert *v,
if (show_vcol && cd_vcol_offset >= 0) {
ushort vcol[4] = {USHRT_MAX, USHRT_MAX, USHRT_MAX, USHRT_MAX};
int col[4] = {0, 0, 0, 0};
int tot = 0;
MPropCol *col = BM_ELEM_CD_GET_VOID_P(v, cd_vcol_offset);
BMIter iter;
BMLoop *l;
vcol[0] = unit_float_to_ushort_clamp(col->color[0]);
vcol[1] = unit_float_to_ushort_clamp(col->color[1]);
vcol[2] = unit_float_to_ushort_clamp(col->color[2]);
vcol[3] = unit_float_to_ushort_clamp(col->color[3]);
BM_ITER_ELEM (l, &iter, v, BM_LOOPS_OF_VERT) {
MLoopCol *ml = BM_ELEM_CD_GET_VOID_P(l, cd_vcol_offset);
col[0] += ml->r;
col[1] += ml->g;
col[2] += ml->b;
col[3] += ml->a;
tot++;
}
if (tot) {
col[0] /= tot;
col[1] /= tot;
col[2] /= tot;
col[3] /= tot;
vcol[0] = (ushort)(col[0] * 257);
vcol[1] = (ushort)(col[1] * 257);
vcol[2] = (ushort)(col[2] * 257);
vcol[3] = (ushort)(col[3] * 257);
// printf("%d %d %d %d %d\n", vcol[0], vcol[1], vcol[2], vcol[3], tot);
}
// const ushort vcol[4] = {USHRT_MAX, USHRT_MAX, USHRT_MAX, USHRT_MAX};
GPU_vertbuf_attr_set(vert_buf, g_vbo_id.col[0], v_index, vcol);
}
@ -1185,16 +1166,15 @@ static void GPU_pbvh_bmesh_buffers_update_flat_vcol(GPU_PBVH_Buffers *buffers,
gpu_flat_vcol_make_vert(
cos[prev], v[j], buffers->vert_buf, v_index + 5, cd_vcols, cd_vcol_count, f->no);
/*
v1
|\
| \
v3 v4
| v6 \
| \
v0---v5---v2
*/
/*
v1
|\
| \
v3 v4
| v6 \
| \
v0---v5---v2
*/
next = j == 2 ? v_start : v_index + 6;
@ -1233,6 +1213,7 @@ void GPU_pbvh_bmesh_buffers_update(GPU_PBVH_Buffers *buffers,
TableGSet *bm_faces,
TableGSet *bm_unique_verts,
TableGSet *bm_other_verts,
PBVHTriBuf *tribuf,
const int update_flags,
const int cd_vert_node_offset,
int face_sets_color_seed,
@ -1271,12 +1252,13 @@ void GPU_pbvh_bmesh_buffers_update(GPU_PBVH_Buffers *buffers,
int cd_vcol_count = gpu_pbvh_bmesh_make_vcol_offs(bm, cd_vcols, active_vcol_only);
/* Count visible triangles */
tottri = gpu_bmesh_face_visible_count(bm_faces);
const bool indexed = buffers->smooth && tribuf && !have_uv;
tottri = indexed ? tribuf->tottri : gpu_bmesh_face_visible_count(bm_faces);
// XXX disable indexed verts for now
if (0 && buffers->smooth) {
if (indexed) {
/* Count visible vertices */
totvert = gpu_bmesh_vert_visible_count(bm_unique_verts, bm_other_verts);
totvert = tribuf->totvert;
}
else {
totvert = tottri * 3;
@ -1308,8 +1290,7 @@ void GPU_pbvh_bmesh_buffers_update(GPU_PBVH_Buffers *buffers,
int v_index = 0;
// disable shared vertex mode for now
if (0 && buffers->smooth) {
if (indexed) {
/* Fill the vertex and triangle buffer in one pass over faces. */
GPUIndexBufBuilder elb, elb_lines;
GPU_indexbuf_init(&elb, GPU_PRIM_TRIS, tottri, totvert);
@ -1318,51 +1299,35 @@ void GPU_pbvh_bmesh_buffers_update(GPU_PBVH_Buffers *buffers,
GHash *bm_vert_to_index = BLI_ghash_int_new_ex("bm_vert_to_index", totvert);
BMFace *f;
TGSET_ITER (f, bm_faces) {
if (!BM_elem_flag_test(f, BM_ELEM_HIDDEN)) {
BMVert *v[3];
BM_face_as_array_vert_tri(f, v);
for (int i=0; i<tribuf->totvert; i++) {
BMVert *v = (BMVert*) tribuf->verts[i].i;
uint idx[3];
for (int i = 0; i < 3; i++) {
void **idx_p;
if (!BLI_ghash_ensure_p(bm_vert_to_index, v[i], &idx_p)) {
/* Add vertex to the vertex buffer each time a new one is encountered */
*idx_p = POINTER_FROM_UINT(v_index);
gpu_bmesh_vert_to_buffer_copy(v[i],
buffers->vert_buf,
v_index,
NULL,
NULL,
cd_vert_mask_offset,
cd_vert_node_offset,
show_mask,
show_vcol,
&empty_mask,
cd_mcol_offset);
idx[i] = v_index;
v_index++;
}
else {
/* Vertex already in the vertex buffer, just get the index. */
idx[i] = POINTER_AS_UINT(*idx_p);
}
}
GPU_indexbuf_add_tri_verts(&elb, idx[0], idx[1], idx[2]);
GPU_indexbuf_add_line_verts(&elb_lines, idx[0], idx[1]);
GPU_indexbuf_add_line_verts(&elb_lines, idx[1], idx[2]);
GPU_indexbuf_add_line_verts(&elb_lines, idx[2], idx[0]);
}
gpu_bmesh_vert_to_buffer_copy(v,
buffers->vert_buf,
i,
NULL,
NULL,
cd_vert_mask_offset,
cd_vert_node_offset,
show_mask,
show_vcol,
&empty_mask,
cd_vcol_offset);
}
TGSET_ITER_END
BLI_ghash_free(bm_vert_to_index, NULL, NULL);
for (int i=0; i<tribuf->tottri; i++) {
PBVHTri *tri = tribuf->tris + i;
GPU_indexbuf_add_tri_verts(&elb, tri->v[0], tri->v[1], tri->v[2]);
GPU_indexbuf_add_line_verts(&elb_lines, tri->v[0], tri->v[1]);
GPU_indexbuf_add_line_verts(&elb_lines, tri->v[1], tri->v[2]);
GPU_indexbuf_add_line_verts(&elb_lines, tri->v[2], tri->v[0]);
}
buffers->tot_tri = tottri;
if (buffers->index_buf == NULL) {
buffers->index_buf = GPU_indexbuf_build(&elb);
}