From ebcbb50420af437b6e68b64a6e6517de6edbfe6e Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 18 Sep 2018 17:46:00 +0200 Subject: Subdiv: CCG, implement stitching of given faces Will speed up (or rather bring speed back to what it is supposed to be) for brushes like smooth. --- source/blender/blenkernel/BKE_subdiv_ccg.h | 6 +++++ source/blender/blenkernel/intern/multires.c | 2 +- source/blender/blenkernel/intern/subdiv_ccg.c | 39 +++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) (limited to 'source') diff --git a/source/blender/blenkernel/BKE_subdiv_ccg.h b/source/blender/blenkernel/BKE_subdiv_ccg.h index 99037a25a64..83d97974a28 100644 --- a/source/blender/blenkernel/BKE_subdiv_ccg.h +++ b/source/blender/blenkernel/BKE_subdiv_ccg.h @@ -37,6 +37,7 @@ #include "BLI_sys_types.h" struct CCGElem; +struct CCGFace; struct CCGKey; struct DMFlagMat; struct Mesh; @@ -182,4 +183,9 @@ void BKE_subdiv_ccg_recalc_normals(SubdivCCG *subdiv_ccg); /* Average grid coordinates and normals along the grid boundatries. */ void BKE_subdiv_ccg_average_grids(SubdivCCG *subdiv_ccg); +/* Similar to above, but only updates given faces. */ +void BKE_subdiv_ccg_average_stitch_faces(SubdivCCG *subdiv_ccg, + struct CCGFace **effected_faces, + int num_effected_faces); + #endif /* __BKE_SUBDIV_CCG_H__ */ diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c index e8b1a5faa67..7453e963eae 100644 --- a/source/blender/blenkernel/intern/multires.c +++ b/source/blender/blenkernel/intern/multires.c @@ -1358,7 +1358,7 @@ void multires_stitch_grids(Object *ob) int num_faces; BKE_pbvh_get_grid_updates(pbvh, false, (void ***)&faces, &num_faces); if (num_faces) { - /* TODO(sergey): Only aveerage actually affected faces. */ + BKE_subdiv_ccg_average_stitch_faces(subdiv_ccg, faces, num_faces); BKE_subdiv_ccg_average_grids(subdiv_ccg); MEM_freeN(faces); } diff --git a/source/blender/blenkernel/intern/subdiv_ccg.c b/source/blender/blenkernel/intern/subdiv_ccg.c index bd8ccda789b..6744579d5c6 100644 --- a/source/blender/blenkernel/intern/subdiv_ccg.c +++ b/source/blender/blenkernel/intern/subdiv_ccg.c @@ -657,3 +657,42 @@ void BKE_subdiv_ccg_average_grids(SubdivCCG *subdiv_ccg) subdiv_ccg_average_inner_grids_task, ¶llel_range_settings); } + +typedef struct StitchFacesInnerGridsData { + SubdivCCG *subdiv_ccg; + CCGKey *key; + struct CCGFace **effected_ccg_faces; +} StitchFacesInnerGridsData; + +static void subdiv_ccg_stitch_face_inner_grids_task( + void *__restrict userdata_v, + const int face_index, + const ParallelRangeTLS *__restrict UNUSED(tls_v)) +{ + StitchFacesInnerGridsData *data = userdata_v; + SubdivCCG *subdiv_ccg = data->subdiv_ccg; + CCGKey *key = data->key; + struct CCGFace **effected_ccg_faces = data->effected_ccg_faces; + struct CCGFace *effected_ccg_face = effected_ccg_faces[face_index]; + SubdivCCGFace *face = (SubdivCCGFace *)effected_ccg_face; + subdiv_ccg_average_inner_face_grids(subdiv_ccg, key, face); +} + +void BKE_subdiv_ccg_average_stitch_faces(SubdivCCG *subdiv_ccg, + struct CCGFace **effected_faces, + int num_effected_faces) +{ + CCGKey key; + BKE_subdiv_ccg_key_top_level(&key, subdiv_ccg); + StitchFacesInnerGridsData data = { + .subdiv_ccg = subdiv_ccg, + .key = &key, + .effected_ccg_faces = effected_faces, + }; + ParallelRangeSettings parallel_range_settings; + BLI_parallel_range_settings_defaults(¶llel_range_settings); + BLI_task_parallel_range(0, num_effected_faces, + &data, + subdiv_ccg_stitch_face_inner_grids_task, + ¶llel_range_settings); +} -- cgit v1.2.3