sculpt-dev: Fix draw bug

This commit is contained in:
Joseph Eagar 2022-10-06 01:47:05 -07:00
parent 0598a4b360
commit 42948e2389
6 changed files with 39 additions and 21 deletions

View File

@ -820,6 +820,9 @@ typedef struct SculptSession {
/* BMesh for dynamic topology sculpting */
struct BMesh *bm;
/* TODO: get rid of these cd_ members and use
* .attrs.XXX.bmesh_cd_offset directly.
*/
int cd_sculpt_vert;
int cd_vert_node_offset;
int cd_face_node_offset;
@ -827,6 +830,7 @@ typedef struct SculptSession {
int cd_vert_mask_offset;
int cd_faceset_offset;
int cd_face_areas;
int cd_hide_poly;
int totuv;

View File

@ -432,7 +432,8 @@ void BKE_pbvh_update_offsets(PBVH *pbvh,
const int cd_vert_node_offset,
const int cd_face_node_offset,
const int cd_sculpt_vert,
const int cd_face_areas);
const int cd_face_areas,
const int cd_hide_poly);
void BKE_pbvh_update_bmesh_offsets(PBVH *pbvh, int cd_vert_node_offset, int cd_face_node_offset);

View File

@ -3532,12 +3532,14 @@ static void sculptsession_bmesh_attr_update_internal(Object *ob)
if (ss->pbvh) {
int cd_sculpt_vert = CustomData_get_offset(&ss->bm->vdata, CD_DYNTOPO_VERT);
int cd_face_area = ss->attrs.face_areas ? ss->attrs.face_areas->bmesh_cd_offset : -1;
int cd_hide_poly = ss->attrs.hide_poly ? ss->attrs.hide_poly->bmesh_cd_offset : -1;
BKE_pbvh_update_offsets(ss->pbvh,
ob->sculpt->attrs.dyntopo_node_id_vertex->bmesh_cd_offset,
ob->sculpt->attrs.dyntopo_node_id_face->bmesh_cd_offset,
ss->attrs.dyntopo_node_id_vertex->bmesh_cd_offset,
ss->attrs.dyntopo_node_id_face->bmesh_cd_offset,
cd_sculpt_vert,
cd_face_area);
cd_face_area,
cd_hide_poly);
}
}
@ -3580,6 +3582,7 @@ static void sculptsession_bmesh_add_layers(Object *ob)
ss->cd_face_node_offset = ss->attrs.dyntopo_node_id_face->bmesh_cd_offset;
ss->cd_face_areas = ss->attrs.face_areas->bmesh_cd_offset;
ss->cd_sculpt_vert = ss->attrs.sculpt_vert->bmesh_cd_offset;
ss->cd_hide_poly = ss->attrs.hide_poly ? ss->attrs.hide_poly->bmesh_cd_offset : -1;
}
void BKE_sculpt_attributes_destroy_temporary_stroke(Object *ob)
@ -3622,13 +3625,15 @@ static void update_bmesh_offsets(Mesh *me, SculptSession *ss)
ss->cd_faceset_offset = CustomData_get_offset_named(
&ss->bm->pdata, CD_PROP_INT32, ".sculpt_face_set");
ss->cd_face_areas = ss->attrs.face_areas ? ss->attrs.face_areas->bmesh_cd_offset : -1;
ss->cd_hide_poly = ss->attrs.hide_poly ? ss->attrs.hide_poly->bmesh_cd_offset : -1;
if (ss->pbvh) {
BKE_pbvh_update_offsets(ss->pbvh,
ss->cd_vert_node_offset,
ss->cd_face_node_offset,
ss->cd_sculpt_vert,
ss->cd_face_areas);
ss->cd_face_areas,
ss->cd_hide_poly);
}
}

View File

@ -252,6 +252,8 @@ static void pbvh_bmesh_node_finalize(PBVH *pbvh,
BB_reset(&n->orig_vb);
BMFace *f;
int cd_hide_poly = pbvh->cd_hide_poly;
TGSET_ITER (f, n->bm_faces) {
/* Update ownership of faces */
BM_ELEM_CD_SET_INT(f, cd_face_node_offset, node_index);
@ -279,7 +281,7 @@ static void pbvh_bmesh_node_finalize(PBVH *pbvh,
BB_expand(&n->orig_vb, mv->origco);
} while ((l_iter = l_iter->next) != l_first);
if (!BM_elem_flag_test(f, BM_ELEM_HIDDEN)) {
if (cd_hide_poly == -1 || !BM_ELEM_CD_GET_BOOL(f, cd_hide_poly)) {
has_visible = true;
}
}
@ -876,6 +878,11 @@ void BKE_pbvh_bmesh_regen_node_verts(PBVH *pbvh)
/************************* Called from pbvh.c *************************/
static bool pbvh_poly_hidden(PBVH *pbvh, BMFace *f)
{
return pbvh->cd_hide_poly != -1 && BM_ELEM_CD_GET_BOOL(f, pbvh->cd_hide_poly);
}
bool BKE_pbvh_bmesh_check_origdata(PBVH *pbvh, BMVert *v, int stroke_id)
{
PBVHVertRef vertex = {(intptr_t)v};
@ -915,7 +922,7 @@ bool pbvh_bmesh_node_raycast(PBVH *pbvh,
BMFace *f = (BMFace *)tri->f.i;
if (BM_elem_flag_test(f, BM_ELEM_HIDDEN)) {
if (pbvh_poly_hidden(pbvh, f)) {
continue;
}
@ -1006,7 +1013,7 @@ bool BKE_pbvh_bmesh_node_raycast_detail(PBVH *pbvh,
BMVert *v3 = (BMVert *)node->tribuf->verts[tri->v[2]].i;
BMFace *f = (BMFace *)tri->f.i;
if (BM_elem_flag_test(f, BM_ELEM_HIDDEN)) {
if (pbvh_poly_hidden(pbvh, f)) {
continue;
}
@ -1047,7 +1054,7 @@ bool pbvh_bmesh_node_nearest_to_ray(PBVH *pbvh,
PBVHTri *tri = tribuf->tris + i;
BMFace *f = (BMFace *)tri->f.i;
if (BM_elem_flag_test(f, BM_ELEM_HIDDEN)) {
if (pbvh_poly_hidden(pbvh, f)) {
continue;
}
@ -1511,7 +1518,7 @@ static void pbvh_bmesh_create_leaf_fast_task_cb(void *__restrict userdata,
} while ((l_iter = l_iter->next) != l_first);
/* Update node bounding box */
if (!BM_elem_flag_test(f, BM_ELEM_HIDDEN)) {
if (!pbvh_poly_hidden(pbvh, f)) {
has_visible = true;
}
@ -2242,6 +2249,8 @@ void BKE_pbvh_build_bmesh(PBVH *pbvh,
{
// coalese_pbvh(pbvh, bm);
pbvh->cd_hide_poly = CustomData_get_offset_named(
&bm->pdata, CD_PROP_INT32, ".sculpt_face_areas");
pbvh->cd_face_area = cd_face_areas;
pbvh->cd_vert_node_offset = cd_vert_node_offset;
pbvh->cd_face_node_offset = cd_face_node_offset;
@ -2849,7 +2858,7 @@ bool BKE_pbvh_bmesh_check_tris(PBVH *pbvh, PBVHNode *node)
INIT_MINMAX(min, max);
TGSET_ITER (f, node->bm_faces) {
if (BM_elem_flag_test(f, BM_ELEM_HIDDEN)) {
if (pbvh_poly_hidden(pbvh, f)) {
continue;
}
@ -3002,7 +3011,7 @@ bool BKE_pbvh_bmesh_check_tris(PBVH *pbvh, PBVHNode *node)
TGSET_ITER_END
TGSET_ITER (f, node->bm_faces) {
if (BM_elem_flag_test(f, BM_ELEM_HIDDEN)) {
if (pbvh_poly_hidden(pbvh, f)) {
continue;
}
@ -3996,8 +4005,10 @@ void BKE_pbvh_update_offsets(PBVH *pbvh,
const int cd_vert_node_offset,
const int cd_face_node_offset,
const int cd_sculpt_vert,
const int cd_face_areas)
const int cd_face_areas,
const int cd_hide_poly)
{
pbvh->cd_hide_poly = cd_hide_poly;
pbvh->cd_face_node_offset = cd_face_node_offset;
pbvh->cd_vert_node_offset = cd_vert_node_offset;
pbvh->cd_face_area = cd_face_areas;

View File

@ -240,6 +240,7 @@ struct PBVH {
int cd_faceset_offset;
int cd_face_area;
int cd_vcol_offset;
int cd_hide_poly;
int totuv;

View File

@ -712,13 +712,9 @@ struct PBVHBatches {
for (int i : IndexRange(args->tribuf->tottri)) {
PBVHTri *tri = args->tribuf->tris + i;
BMLoop *l1 = reinterpret_cast<BMLoop *>(tri->l[0]);
BMLoop *l2 = reinterpret_cast<BMLoop *>(tri->l[1]);
BMLoop *l3 = reinterpret_cast<BMLoop *>(tri->l[2]);
callback(l1);
callback(l2);
callback(l3);
for (int j = 0; j < 3; j++) {
callback(reinterpret_cast<BMLoop *>(tri->l[j]));
}
}
};
@ -829,7 +825,7 @@ struct PBVHBatches {
int existing_num = GPU_vertbuf_get_vertex_len(vbo.vert_buf);
void *existing_data = GPU_vertbuf_get_data(vbo.vert_buf);
int vert_count = tris_count * 6;
int vert_count = tris_count * 3;
if (existing_data == nullptr || existing_num != vert_count) {
/* Allocate buffer if not allocated yet or size changed. */