Cleanup: Perform cleanup on sculpt_automasking.cc #117651
|
@ -632,10 +632,10 @@ static bool floodfill_cb(
|
||||||
SCULPT_vertex_co_get(ss, to_v), data->location, data->radius, data->symm));
|
SCULPT_vertex_co_get(ss, to_v), data->location, data->radius, data->symm));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void topology_automasking_init(Sculpt *sd, Object *ob)
|
static void topology_automasking_init(const Sculpt *sd, Object *ob)
|
||||||
{
|
{
|
||||||
SculptSession *ss = ob->sculpt;
|
SculptSession *ss = ob->sculpt;
|
||||||
Brush *brush = BKE_paint_brush(&sd->paint);
|
const Brush *brush = BKE_paint_brush_for_read(&sd->paint);
|
||||||
|
|
||||||
const int totvert = SCULPT_vertex_count_get(ss);
|
const int totvert = SCULPT_vertex_count_get(ss);
|
||||||
for (int i : IndexRange(totvert)) {
|
for (int i : IndexRange(totvert)) {
|
||||||
|
@ -661,10 +661,10 @@ static void topology_automasking_init(Sculpt *sd, Object *ob)
|
||||||
flood_fill::execute(ss, &flood, floodfill_cb, &fdata);
|
flood_fill::execute(ss, &flood, floodfill_cb, &fdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init_face_sets_masking(Sculpt *sd, Object *ob)
|
static void init_face_sets_masking(const Sculpt *sd, Object *ob)
|
||||||
{
|
{
|
||||||
SculptSession *ss = ob->sculpt;
|
SculptSession *ss = ob->sculpt;
|
||||||
Brush *brush = BKE_paint_brush(&sd->paint);
|
const Brush *brush = BKE_paint_brush_for_read(&sd->paint);
|
||||||
|
|
||||||
if (!is_enabled(sd, ss, brush)) {
|
if (!is_enabled(sd, ss, brush)) {
|
||||||
return;
|
return;
|
||||||
|
@ -740,7 +740,10 @@ static void init_boundary_masking(Object *ob, eBoundaryAutomaskMode mode, int pr
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Updates the cached values, preferring brush settings over tool-level settings. */
|
/* Updates the cached values, preferring brush settings over tool-level settings. */
|
||||||
static void cache_settings_update(Cache &automasking, SculptSession *ss, Sculpt *sd, Brush *brush)
|
static void cache_settings_update(Cache &automasking,
|
||||||
|
SculptSession *ss,
|
||||||
|
const Sculpt *sd,
|
||||||
|
const Brush *brush)
|
||||||
{
|
{
|
||||||
automasking.settings.flags = calc_effective_bits(sd, brush);
|
automasking.settings.flags = calc_effective_bits(sd, brush);
|
||||||
automasking.settings.initial_face_set = face_set::active_face_set_get(ss);
|
automasking.settings.initial_face_set = face_set::active_face_set_get(ss);
|
||||||
|
@ -816,10 +819,14 @@ bool tool_can_reuse_automask(int sculpt_tool)
|
||||||
SCULPT_TOOL_DRAW_FACE_SETS);
|
SCULPT_TOOL_DRAW_FACE_SETS);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Cache> cache_init(Sculpt *sd, Brush *brush, Object *ob)
|
std::unique_ptr<Cache> cache_init(const Sculpt *sd, Object *ob)
|
||||||
|
{
|
||||||
|
return cache_init(sd, nullptr, ob);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<Cache> cache_init(const Sculpt *sd, const Brush *brush, Object *ob)
|
||||||
{
|
{
|
||||||
SculptSession *ss = ob->sculpt;
|
SculptSession *ss = ob->sculpt;
|
||||||
const int totvert = SCULPT_vertex_count_get(ss);
|
|
||||||
|
|
||||||
if (!is_enabled(sd, ss, brush)) {
|
if (!is_enabled(sd, ss, brush)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -831,7 +838,6 @@ std::unique_ptr<Cache> cache_init(Sculpt *sd, Brush *brush, Object *ob)
|
||||||
|
|
||||||
automasking->current_stroke_id = ss->stroke_id;
|
automasking->current_stroke_id = ss->stroke_id;
|
||||||
|
|
||||||
bool use_stroke_id = false;
|
|
||||||
int mode = calc_effective_bits(sd, brush);
|
int mode = calc_effective_bits(sd, brush);
|
||||||
|
|
||||||
if (mode & BRUSH_AUTOMASKING_TOPOLOGY && ss->active_vertex.i != PBVH_REF_NONE) {
|
if (mode & BRUSH_AUTOMASKING_TOPOLOGY && ss->active_vertex.i != PBVH_REF_NONE) {
|
||||||
|
@ -839,6 +845,7 @@ std::unique_ptr<Cache> cache_init(Sculpt *sd, Brush *brush, Object *ob)
|
||||||
automasking->settings.initial_island_nr = SCULPT_vertex_island_get(ss, ss->active_vertex);
|
automasking->settings.initial_island_nr = SCULPT_vertex_island_get(ss, ss->active_vertex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool use_stroke_id = false;
|
||||||
if ((mode & BRUSH_AUTOMASKING_VIEW_OCCLUSION) && (mode & BRUSH_AUTOMASKING_VIEW_NORMAL)) {
|
if ((mode & BRUSH_AUTOMASKING_VIEW_OCCLUSION) && (mode & BRUSH_AUTOMASKING_VIEW_NORMAL)) {
|
||||||
use_stroke_id = true;
|
use_stroke_id = true;
|
||||||
|
|
||||||
|
@ -895,6 +902,8 @@ std::unique_ptr<Cache> cache_init(Sculpt *sd, Brush *brush, Object *ob)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Avoid precomputing data on the vertex level if the current auto-masking modes do not require
|
||||||
|
* it to function. */
|
||||||
if (!needs_factors_cache(sd, brush)) {
|
if (!needs_factors_cache(sd, brush)) {
|
||||||
if (ss->attrs.automasking_factor) {
|
if (ss->attrs.automasking_factor) {
|
||||||
BKE_sculpt_attribute_destroy(ob, ss->attrs.automasking_factor);
|
BKE_sculpt_attribute_destroy(ob, ss->attrs.automasking_factor);
|
||||||
|
@ -912,19 +921,11 @@ std::unique_ptr<Cache> cache_init(Sculpt *sd, Brush *brush, Object *ob)
|
||||||
SCULPT_ATTRIBUTE_NAME(automasking_factor),
|
SCULPT_ATTRIBUTE_NAME(automasking_factor),
|
||||||
¶ms);
|
¶ms);
|
||||||
|
|
||||||
float initial_value;
|
/* Topology builds up the mask from zero which other modes can subtract from.
|
||||||
|
* If it isn't enabled, initialize to 1. */
|
||||||
/* Topology, boundary and boundary face sets build up the mask
|
float initial_value = !(mode & BRUSH_AUTOMASKING_TOPOLOGY) ? 1.0f : 0.0f;
|
||||||
* from zero which other modes can subtract from. If none of them are
|
|
||||||
* enabled initialize to 1.
|
|
||||||
*/
|
|
||||||
if (!(mode & BRUSH_AUTOMASKING_TOPOLOGY)) {
|
|
||||||
initial_value = 1.0f;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
initial_value = 0.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
const int totvert = SCULPT_vertex_count_get(ss);
|
||||||
for (int i : IndexRange(totvert)) {
|
for (int i : IndexRange(totvert)) {
|
||||||
PBVHVertRef vertex = BKE_pbvh_index_to_vertex(ss->pbvh, i);
|
PBVHVertRef vertex = BKE_pbvh_index_to_vertex(ss->pbvh, i);
|
||||||
|
|
||||||
|
|
|
@ -1556,7 +1556,7 @@ static int sculpt_cloth_filter_invoke(bContext *C, wmOperator *op, const wmEvent
|
||||||
RNA_float_get(op->ptr, "area_normal_radius"),
|
RNA_float_get(op->ptr, "area_normal_radius"),
|
||||||
RNA_float_get(op->ptr, "strength"));
|
RNA_float_get(op->ptr, "strength"));
|
||||||
|
|
||||||
ss->filter_cache->automasking = auto_mask::cache_init(sd, nullptr, ob);
|
ss->filter_cache->automasking = auto_mask::cache_init(sd, ob);
|
||||||
|
|
||||||
const float cloth_mass = RNA_float_get(op->ptr, "cloth_mass");
|
const float cloth_mass = RNA_float_get(op->ptr, "cloth_mass");
|
||||||
const float cloth_damping = RNA_float_get(op->ptr, "cloth_damping");
|
const float cloth_damping = RNA_float_get(op->ptr, "cloth_damping");
|
||||||
|
|
|
@ -371,7 +371,7 @@ static int sculpt_color_filter_init(bContext *C, wmOperator *op)
|
||||||
RNA_float_get(op->ptr, "strength"));
|
RNA_float_get(op->ptr, "strength"));
|
||||||
filter::Cache *filter_cache = ss->filter_cache;
|
filter::Cache *filter_cache = ss->filter_cache;
|
||||||
filter_cache->active_face_set = SCULPT_FACE_SET_NONE;
|
filter_cache->active_face_set = SCULPT_FACE_SET_NONE;
|
||||||
filter_cache->automasking = auto_mask::cache_init(sd, nullptr, ob);
|
filter_cache->automasking = auto_mask::cache_init(sd, ob);
|
||||||
|
|
||||||
return OPERATOR_PASS_THROUGH;
|
return OPERATOR_PASS_THROUGH;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1010,7 +1010,7 @@ static int sculpt_mesh_filter_start(bContext *C, wmOperator *op)
|
||||||
|
|
||||||
filter::Cache *filter_cache = ss->filter_cache;
|
filter::Cache *filter_cache = ss->filter_cache;
|
||||||
filter_cache->active_face_set = SCULPT_FACE_SET_NONE;
|
filter_cache->active_face_set = SCULPT_FACE_SET_NONE;
|
||||||
filter_cache->automasking = auto_mask::cache_init(sd, nullptr, ob);
|
filter_cache->automasking = auto_mask::cache_init(sd, ob);
|
||||||
|
|
||||||
sculpt_filter_specific_init(filter_type, op, ss);
|
sculpt_filter_specific_init(filter_type, op, ss);
|
||||||
|
|
||||||
|
|
|
@ -1285,8 +1285,14 @@ float factor_get(Cache *automasking,
|
||||||
* brushes and filter. */
|
* brushes and filter. */
|
||||||
Cache *active_cache_get(SculptSession *ss);
|
Cache *active_cache_get(SculptSession *ss);
|
||||||
|
|
||||||
/* Brush can be null. */
|
/**
|
||||||
std::unique_ptr<Cache> cache_init(Sculpt *sd, Brush *brush, Object *ob);
|
* Creates and initializes an automasking cache.
|
||||||
|
*
|
||||||
|
* For automasking modes that cannot be calculated in real time,
|
||||||
|
* data is also stored at the vertex level prior to the stroke starting.
|
||||||
|
*/
|
||||||
|
std::unique_ptr<Cache> cache_init(const Sculpt *sd, Object *ob);
|
||||||
Sean-Kim marked this conversation as resolved
Outdated
|
|||||||
|
std::unique_ptr<Cache> cache_init(const Sculpt *sd, const Brush *brush, Object *ob);
|
||||||
void cache_free(Cache *automasking);
|
void cache_free(Cache *automasking);
|
||||||
|
|
||||||
bool mode_enabled(const Sculpt *sd, const Brush *br, eAutomasking_flag mode);
|
bool mode_enabled(const Sculpt *sd, const Brush *br, eAutomasking_flag mode);
|
||||||
|
|
Loading…
Reference in New Issue
Typically we won't add descriptions for parameters that are "obvious". IMO they just add noise. I would just remove the "param" and "return" comments here. The "brush can be null" part is better "documented" by making every non-null pointer into a reference
I'll remove the boilerplate parameters - for the non-null pointer to reference, do you just mean changing the callers to be
cache_init(s, &brush, ... )
andcache_init(s, nullptr, ...)
?Yeah, that sounds good. Could be done here or later, as part of a more general "Use references instead of pointers in sculpt code" cleanup
I suppose an alternate option would be to have some form of overload:
Where the former method just passes in
nullptr
to the latter. I'm mainly thinking about this from the POV of someone working on thesculpt_automasking.cc
file where it may not be obvious that the null checks are required forbrush
but notsd
An overload seems even better!