Sculpt: Un-invert expand normal falloff
Normals falloff mask is created inverted compared to how other falloffs work. It's now un-inverted in a final step at the end. Also exposed the normals falloff smooth steps as an RNA property.
This commit is contained in:
parent
11a9578a19
commit
0a9520ce84
|
@ -517,11 +517,12 @@ static bool mask_expand_normal_floodfill_cb(
|
|||
static float *sculpt_expand_normal_falloff_create(Sculpt *sd,
|
||||
Object *ob,
|
||||
const PBVHVertRef v,
|
||||
const float edge_sensitivity)
|
||||
const float edge_sensitivity,
|
||||
const int blur_steps)
|
||||
{
|
||||
SculptSession *ss = ob->sculpt;
|
||||
const int totvert = SCULPT_vertex_count_get(ss);
|
||||
float *dists = static_cast<float *>(MEM_malloc_arrayN(totvert, sizeof(float), __func__));
|
||||
float *dists = static_cast<float *>(MEM_calloc_arrayN(totvert, sizeof(float), __func__));
|
||||
float *edge_factor = static_cast<float *>(MEM_callocN(sizeof(float) * totvert, __func__));
|
||||
for (int i = 0; i < totvert; i++) {
|
||||
edge_factor[i] = 1.0f;
|
||||
|
@ -540,7 +541,7 @@ static float *sculpt_expand_normal_falloff_create(Sculpt *sd,
|
|||
SCULPT_floodfill_execute(ss, &flood, mask_expand_normal_floodfill_cb, &fdata);
|
||||
SCULPT_floodfill_free(&flood);
|
||||
|
||||
for (int repeat = 0; repeat < 2; repeat++) {
|
||||
for (int repeat = 0; repeat < blur_steps; repeat++) {
|
||||
for (int i = 0; i < totvert; i++) {
|
||||
PBVHVertRef vertex = BKE_pbvh_index_to_vertex(ss->pbvh, i);
|
||||
|
||||
|
@ -550,10 +551,17 @@ static float *sculpt_expand_normal_falloff_create(Sculpt *sd,
|
|||
avg += dists[ni.index];
|
||||
}
|
||||
SCULPT_VERTEX_NEIGHBORS_ITER_END(ni);
|
||||
dists[i] = avg / ni.size;
|
||||
|
||||
if (ni.size > 0.0f) {
|
||||
dists[i] = avg / ni.size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < totvert; i++) {
|
||||
dists[i] = 1.0 - dists[i];
|
||||
}
|
||||
|
||||
MEM_SAFE_FREE(edge_factor);
|
||||
|
||||
return dists;
|
||||
|
@ -1049,7 +1057,11 @@ static void sculpt_expand_falloff_factors_from_vertex_and_symm_create(
|
|||
break;
|
||||
case SCULPT_EXPAND_FALLOFF_NORMALS:
|
||||
expand_cache->vert_falloff = sculpt_expand_normal_falloff_create(
|
||||
sd, ob, v, SCULPT_EXPAND_NORMALS_FALLOFF_EDGE_SENSITIVITY);
|
||||
sd,
|
||||
ob,
|
||||
v,
|
||||
SCULPT_EXPAND_NORMALS_FALLOFF_EDGE_SENSITIVITY,
|
||||
expand_cache->normal_falloff_blur_steps);
|
||||
break;
|
||||
case SCULPT_EXPAND_FALLOFF_SPHERICAL:
|
||||
expand_cache->vert_falloff = sculpt_expand_spherical_falloff_create(ob, v);
|
||||
|
@ -2066,6 +2078,7 @@ static void sculpt_expand_cache_initial_config_set(bContext *C,
|
|||
ExpandCache *expand_cache)
|
||||
{
|
||||
/* RNA properties. */
|
||||
expand_cache->normal_falloff_blur_steps = RNA_int_get(op->ptr, "normal_falloff_smooth");
|
||||
expand_cache->invert = RNA_boolean_get(op->ptr, "invert");
|
||||
expand_cache->preserve = RNA_boolean_get(op->ptr, "use_mask_preserve");
|
||||
expand_cache->auto_mask = RNA_boolean_get(op->ptr, "use_auto_mask");
|
||||
|
@ -2415,4 +2428,13 @@ void SCULPT_OT_expand(wmOperatorType *ot)
|
|||
false,
|
||||
"Auto Create",
|
||||
"Fill in mask if nothing is already masked");
|
||||
ot->prop = RNA_def_int(ot->srna,
|
||||
"normal_falloff_smooth",
|
||||
2,
|
||||
0,
|
||||
10,
|
||||
"Normal Smooth",
|
||||
"Blurring steps for normal falloff",
|
||||
0,
|
||||
10);
|
||||
}
|
||||
|
|
|
@ -822,6 +822,7 @@ typedef struct ExpandCache {
|
|||
float (*original_colors)[4];
|
||||
|
||||
bool check_islands;
|
||||
int normal_falloff_blur_steps;
|
||||
} ExpandCache;
|
||||
/** \} */
|
||||
|
||||
|
|
Loading…
Reference in New Issue