diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2018-09-03 18:06:50 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2018-09-03 18:07:46 +0300 |
commit | b0067db85274b8d0775c4c096a14e2ab6d5d47ff (patch) | |
tree | 4f410d84c3fbac64e9c37b67ef16ba3350445b43 /source/blender/blenkernel/intern/paint.c | |
parent | b812dfd1611e045a1446c70b81f830ae67fa3eab (diff) |
Cleanup: Split function up
We would need to at least support one more PBVH building
here, trying to squeeze everything into one function will
make it really hard to read and follow.
Diffstat (limited to 'source/blender/blenkernel/intern/paint.c')
-rw-r--r-- | source/blender/blenkernel/intern/paint.c | 111 |
1 files changed, 56 insertions, 55 deletions
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index 6ccf4c1b761..12cdb4586c1 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -1127,69 +1127,70 @@ static bool check_sculpt_object_deformed(Object *object, const bool for_construc return deformed; } -PBVH *BKE_sculpt_object_pbvh_ensure(Object *ob, Mesh *me_eval_deform) +static PBVH *build_pbvh_for_dynamic_topology(Object *ob) { - if (!ob) { - return NULL; + PBVH *pbvh = BKE_pbvh_new(); + BKE_pbvh_build_bmesh(pbvh, ob->sculpt->bm, + ob->sculpt->bm_smooth_shading, + ob->sculpt->bm_log, ob->sculpt->cd_vert_node_offset, + ob->sculpt->cd_face_node_offset); + pbvh_show_diffuse_color_set(pbvh, ob->sculpt->show_diffuse_color); + pbvh_show_mask_set(pbvh, ob->sculpt->show_mask); + return pbvh; +} + +static PBVH *build_regular_mesh_pbvh(Object *ob, Mesh *me_eval_deform) +{ + Mesh *me = BKE_object_get_original_mesh(ob); + const int looptris_num = poly_to_tri_count(me->totpoly, me->totloop); + PBVH *pbvh = BKE_pbvh_new(); + + MLoopTri *looptri = MEM_malloc_arrayN( + looptris_num, sizeof(*looptri), __func__); + + BKE_mesh_recalc_looptri( + me->mloop, me->mpoly, + me->mvert, + me->totloop, me->totpoly, + looptri); + + BKE_pbvh_build_mesh( + pbvh, + me->mpoly, me->mloop, + me->mvert, me->totvert, &me->vdata, + looptri, looptris_num); + + pbvh_show_diffuse_color_set(pbvh, ob->sculpt->show_diffuse_color); + pbvh_show_mask_set(pbvh, ob->sculpt->show_mask); + + const bool is_deformed = check_sculpt_object_deformed(ob, true); + if (is_deformed && me_eval_deform != NULL) { + int totvert; + float (*v_cos)[3] = BKE_mesh_vertexCos_get(me_eval_deform, &totvert); + BKE_pbvh_apply_vertCos(pbvh, v_cos, totvert); + MEM_freeN(v_cos); } - if (!ob->sculpt) { + return pbvh; +} + +PBVH *BKE_sculpt_object_pbvh_ensure(Object *ob, Mesh *me_eval_deform) +{ + if (ob == NULL || ob->sculpt == NULL) { return NULL; } - PBVH *pbvh = ob->sculpt->pbvh; - - /* Sculpting on a BMesh (dynamic-topology) gets a special PBVH */ - if (!pbvh && ob->sculpt->bm) { - pbvh = BKE_pbvh_new(); - - BKE_pbvh_build_bmesh(pbvh, ob->sculpt->bm, - ob->sculpt->bm_smooth_shading, - ob->sculpt->bm_log, ob->sculpt->cd_vert_node_offset, - ob->sculpt->cd_face_node_offset); - - pbvh_show_diffuse_color_set(pbvh, ob->sculpt->show_diffuse_color); - pbvh_show_mask_set(pbvh, ob->sculpt->show_mask); + if (pbvh != NULL) { + /* Nothing to do, PBVH is already up to date. */ + return pbvh; } - /* always build pbvh from original mesh, and only use it for drawing if - * this evaluated mesh is just original mesh. it's the multires subsurf dm - * that this is actually for, to support a pbvh on a modified mesh */ - if (!pbvh && ob->type == OB_MESH) { - Mesh *me = BKE_object_get_original_mesh(ob); - const int looptris_num = poly_to_tri_count(me->totpoly, me->totloop); - MLoopTri *looptri; - bool deformed; - - pbvh = BKE_pbvh_new(); - - looptri = MEM_malloc_arrayN(looptris_num, sizeof(*looptri), __func__); - - BKE_mesh_recalc_looptri( - me->mloop, me->mpoly, - me->mvert, - me->totloop, me->totpoly, - looptri); - - BKE_pbvh_build_mesh( - pbvh, - me->mpoly, me->mloop, - me->mvert, me->totvert, &me->vdata, - looptri, looptris_num); - - pbvh_show_diffuse_color_set(pbvh, ob->sculpt->show_diffuse_color); - pbvh_show_mask_set(pbvh, ob->sculpt->show_mask); - - deformed = check_sculpt_object_deformed(ob, true); - - if (deformed && me_eval_deform) { - int totvert; - float (*v_cos)[3]; - - v_cos = BKE_mesh_vertexCos_get(me_eval_deform, &totvert); - BKE_pbvh_apply_vertCos(pbvh, v_cos, totvert); - MEM_freeN(v_cos); - } + if (ob->sculpt->bm != NULL) { + /* Sculpting on a BMesh (dynamic-topology) gets a special PBVH. */ + pbvh = build_pbvh_for_dynamic_topology(ob); + } + else if (ob->type == OB_MESH) { + pbvh = build_regular_mesh_pbvh(ob, me_eval_deform); } ob->sculpt->pbvh = pbvh; |