WIP: Brush assets project #106303

Draft
Julian Eisel wants to merge 354 commits from brush-assets-project into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
5 changed files with 32 additions and 25 deletions
Showing only changes of commit 458716b675 - Show all commits

View File

@ -632,10 +632,10 @@ static bool floodfill_cb(
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;
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);
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);
}
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;
Brush *brush = BKE_paint_brush(&sd->paint);
const Brush *brush = BKE_paint_brush_for_read(&sd->paint);
if (!is_enabled(sd, ss, brush)) {
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. */
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.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);
}
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;
const int totvert = SCULPT_vertex_count_get(ss);
if (!is_enabled(sd, ss, brush)) {
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;
bool use_stroke_id = false;
int mode = calc_effective_bits(sd, brush);
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);
}
bool use_stroke_id = false;
if ((mode & BRUSH_AUTOMASKING_VIEW_OCCLUSION) && (mode & BRUSH_AUTOMASKING_VIEW_NORMAL)) {
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 (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),
&params);
float initial_value;
/* Topology, boundary and boundary face sets build up the mask
* 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;
}
/* Topology builds up the mask from zero which other modes can subtract from.
* If it isn't enabled, initialize to 1. */
float initial_value = !(mode & BRUSH_AUTOMASKING_TOPOLOGY) ? 1.0f : 0.0f;
const int totvert = SCULPT_vertex_count_get(ss);
for (int i : IndexRange(totvert)) {
PBVHVertRef vertex = BKE_pbvh_index_to_vertex(ss->pbvh, i);

View File

@ -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, "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_damping = RNA_float_get(op->ptr, "cloth_damping");

View File

@ -371,7 +371,7 @@ static int sculpt_color_filter_init(bContext *C, wmOperator *op)
RNA_float_get(op->ptr, "strength"));
filter::Cache *filter_cache = ss->filter_cache;
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;
}

View File

@ -1010,7 +1010,7 @@ static int sculpt_mesh_filter_start(bContext *C, wmOperator *op)
filter::Cache *filter_cache = ss->filter_cache;
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);

View File

@ -1285,8 +1285,14 @@ float factor_get(Cache *automasking,
* brushes and filter. */
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);
std::unique_ptr<Cache> cache_init(const Sculpt *sd, const Brush *brush, Object *ob);
void cache_free(Cache *automasking);
bool mode_enabled(const Sculpt *sd, const Brush *br, eAutomasking_flag mode);