sculpt-dev: Fix bugs from merge:

* MSculptVert->valence was not initialized for PBVH_FACES
* PBVH_BMESH did not draw color attributes.
* Crashes related to active mesh attributes.
This commit is contained in:
Joseph Eagar 2023-01-26 21:22:45 -08:00
parent 6c0c339da9
commit 390b6492e7
4 changed files with 25 additions and 19 deletions

View File

@ -2786,21 +2786,14 @@ extern "C" bool BKE_sculptsession_check_sculptverts(Object *ob, struct PBVH *pbv
sculpt_boundary_flags_ensure(ob, pbvh, totvert);
if (!ss->attrs.sculpt_vert) {
if (!ss->attrs.sculpt_vert || !ss->attrs.sculpt_vert->data) {
SculptAttributeParams params = {0};
ss->attrs.sculpt_vert = sculpt_attribute_ensure_ex(
ob, ATTR_DOMAIN_POINT, CD_DYNTOPO_VERT, "", &params, BKE_pbvh_type(pbvh));
}
if (!ss->bm && (!ss->msculptverts || totvert != ss->last_msculptverts_count)) {
ss->last_msculptverts_count = totvert;
ss->msculptverts = static_cast<MSculptVert *>(ss->attrs.sculpt_vert->data);
init_sculptvert_layer(ss, pbvh, totvert);
return true;
}
ss->msculptverts = static_cast<MSculptVert *>(ss->attrs.sculpt_vert->data);
BKE_pbvh_set_sculpt_verts(pbvh, ss->msculptverts);
return false;

View File

@ -830,6 +830,10 @@ static void pbvh_draw_args_init(PBVH *pbvh, PBVH_GPU_Args *args, PBVHNode *node)
break;
case PBVH_BMESH:
args->bm = pbvh->header.bm;
args->active_color = pbvh->mesh->active_color_attribute;
args->render_color = pbvh->mesh->default_color_attribute;
args->me = pbvh->mesh;
args->vdata = &args->bm->vdata;
args->ldata = &args->bm->ldata;
@ -980,6 +984,11 @@ void BKE_pbvh_build_mesh(PBVH *pbvh,
/* For each face, store the AABB and the AABB centroid */
prim_bbc = MEM_mallocN(sizeof(BBC) * looptri_num, "prim_bbc");
for (int i = 0; i < mesh->totvert; i++) {
msculptverts[i].flag &= ~SCULPTVERT_NEED_VALENCE;
msculptverts[i].valence = pmap->pmap[i].count;
}
for (int i = 0; i < looptri_num; i++) {
const MLoopTri *lt = &looptri[i];
const int sides = 3;
@ -1794,6 +1803,7 @@ static void pbvh_update_draw_buffer_cb(void *__restrict userdata,
Mesh me_query;
BKE_id_attribute_copy_domains_temp(ID_ME, vdata, NULL, ldata, NULL, NULL, &me_query.id);
me_query.active_color_attribute = me->active_color_attribute;
if (!pbvh->header.bm) {
vdata = pbvh->vdata;
@ -5374,6 +5384,8 @@ void BKE_pbvh_update_active_vcol(PBVH *pbvh, const Mesh *mesh)
}
BKE_id_attribute_copy_domains_temp(ID_ME, vdata, NULL, ldata, NULL, NULL, &me_query.id);
me_query.active_color_attribute = mesh->active_color_attribute;
BKE_pbvh_get_color_layer(&me_query, &pbvh->color_layer, &pbvh->color_domain);
if (pbvh->color_layer && pbvh->header.bm) {

View File

@ -760,7 +760,7 @@ struct PBVHBatches {
}
}
void fill_vbo_bmesh(PBVHVbo &vbo, PBVH_GPU_Args *args)
ATTR_NO_OPT void fill_vbo_bmesh(PBVHVbo &vbo, PBVH_GPU_Args *args)
{
auto foreach_bmesh_normal = [&](std::function<void(BMLoop * l)> callback) {
for (int i : IndexRange(args->tribuf->tottri)) {
@ -931,6 +931,7 @@ struct PBVHBatches {
const bool do_loop = vbo.domain == ATTR_DOMAIN_CORNER;
const int cd_color = CustomData_get_offset_named(cdata, CD_PROP_COLOR, vbo.name.c_str());
foreach_bmesh([&](BMLoop *l) {
MPropCol *col;

View File

@ -1991,14 +1991,14 @@ void SCULPT_bound_smooth_ensure(SculptSession *ss, Object *ob)
}
}
void SCULPT_smooth(Sculpt *sd,
Object *ob,
PBVHNode **nodes,
const int totnode,
float bstrength,
const bool smooth_mask,
float projection,
bool do_origco)
ATTR_NO_OPT void SCULPT_smooth(Sculpt *sd,
Object *ob,
PBVHNode **nodes,
const int totnode,
float bstrength,
const bool smooth_mask,
float projection,
bool do_origco)
{
SculptSession *ss = ob->sculpt;
Brush *brush = ss->cache && ss->cache->brush ? ss->cache->brush : BKE_paint_brush(&sd->paint);
@ -2114,7 +2114,7 @@ void SCULPT_smooth(Sculpt *sd,
};
TaskParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, true, totnode);
BKE_pbvh_parallel_range_settings(&settings, false /* XXX */, totnode);
BLI_task_parallel_range(0, totnode, &data, do_smooth_brush_task_cb_ex, &settings);
#ifndef SMOOTH_ITER_IN_THREADS