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.
This commit is contained in:
Sergey Sharybin 2018-09-18 17:46:00 +02:00
parent 7016f11d92
commit ebcbb50420
3 changed files with 46 additions and 1 deletions

View File

@ -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__ */

View File

@ -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);
}

View File

@ -657,3 +657,42 @@ void BKE_subdiv_ccg_average_grids(SubdivCCG *subdiv_ccg)
subdiv_ccg_average_inner_grids_task,
&parallel_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(&parallel_range_settings);
BLI_task_parallel_range(0, num_effected_faces,
&data,
subdiv_ccg_stitch_face_inner_grids_task,
&parallel_range_settings);
}