[Bf-blender-cvs] [65c358851dc] sculpt-dev: Sculpt Expand: Recursivity, move and falloff switching
Pablo Dobarro
noreply at git.blender.org
Sat Jan 16 22:22:56 CET 2021
Commit: 65c358851dc9ff2a72053b3218059d5940111410
Author: Pablo Dobarro
Date: Sat Jan 16 18:38:05 2021 +0100
Branches: sculpt-dev
https://developer.blender.org/rB65c358851dc9ff2a72053b3218059d5940111410
Sculpt Expand: Recursivity, move and falloff switching
===================================================================
M release/scripts/presets/keyconfig/keymap_data/blender_default.py
M source/blender/editors/sculpt_paint/sculpt_expand.c
M source/blender/editors/sculpt_paint/sculpt_intern.h
===================================================================
diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index 8d9f1876980..74303aec546 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -5533,8 +5533,13 @@ def km_sculpt_expand_modal(_params):
("CANCEL", {"type": 'RIGHTMOUSE', "value": 'PRESS', "any": True}, None),
("CONFIRM", {"type": 'LEFTMOUSE', "value": 'PRESS', "any": True}, None),
("INVERT", {"type": 'F', "value": 'PRESS', "any": True, "repeat" : False}, None),
- ("MASK_PRESERVE", {"type": 'P', "value": 'PRESS', "any": True, "repeat" : False}, None),
+ ("PRESERVE", {"type": 'E', "value": 'PRESS', "any": True, "repeat" : False}, None),
("GRADIENT", {"type": 'G', "value": 'PRESS', "any": True, "repeat" : False}, None),
+ ("RECURSION_STEP", {"type": 'R', "value": 'PRESS', "any": True, "repeat" : False}, None),
+ ("MOVE_TOGGLE", {"type": 'SPACE', "value": 'ANY', "any": True, "repeat" : False}, None),
+ ("FALLOFF_GEODESICS", {"type": 'ONE', "value": 'PRESS', "any": True, "repeat" : False}, None),
+ ("FALLOFF_TOPOLOGY", {"type": 'TWO', "value": 'PRESS', "any": True, "repeat" : False}, None),
+ ("FALLOFF_SPHERICAL", {"type": 'THREE', "value": 'PRESS', "any": True, "repeat" : False}, None),
])
return keymap
diff --git a/source/blender/editors/sculpt_paint/sculpt_expand.c b/source/blender/editors/sculpt_paint/sculpt_expand.c
index 95d87b92c20..0ab8b22b184 100644
--- a/source/blender/editors/sculpt_paint/sculpt_expand.c
+++ b/source/blender/editors/sculpt_paint/sculpt_expand.c
@@ -77,9 +77,14 @@ enum {
SCULPT_EXPAND_MODAL_CONFIRM = 1,
SCULPT_EXPAND_MODAL_CANCEL,
SCULPT_EXPAND_MODAL_INVERT,
- SCULPT_EXPAND_MODAL_MASK_PRESERVE_TOGGLE,
+ SCULPT_EXPAND_MODAL_PRESERVE_TOGGLE,
SCULPT_EXPAND_MODAL_GRADIENT_TOGGLE,
SCULPT_EXPAND_MODAL_FALLOFF_CYCLE,
+ SCULPT_EXPAND_MODAL_RECURSION_STEP,
+ SCULPT_EXPAND_MODAL_MOVE_TOGGLE,
+ SCULPT_EXPAND_MODAL_FALLOFF_GEODESICS,
+ SCULPT_EXPAND_MODAL_FALLOFF_TOPOLOGY,
+ SCULPT_EXPAND_MODAL_FALLOFF_SPHERICAL,
};
static EnumPropertyItem prop_sculpt_expand_falloff_type_items[] = {
@@ -115,7 +120,7 @@ static bool mask_expand_topology_floodfill_cb(
{
ExpandFloodFillData *data = userdata;
if (!is_duplicate) {
- const int to_it = data->dists[from_v] + 1;
+ const float to_it = data->dists[from_v] + 1.0f;
data->dists[to_v] = to_it;
}
else {
@@ -128,7 +133,7 @@ static float *sculpt_expand_topology_falloff_create(Sculpt *sd, Object *ob, cons
{
SculptSession *ss = ob->sculpt;
const int totvert = SCULPT_vertex_count_get(ss);
- float *dists = MEM_malloc_arrayN(sizeof(float), totvert, "spherical dist");
+ float *dists = MEM_calloc_arrayN(sizeof(float), totvert, "topology dist");
SculptFloodFill flood;
SCULPT_floodfill_init(ss, &flood);
@@ -366,11 +371,6 @@ static void sculpt_expand_falloff_factors_from_vertex_and_symm_create(
const int vertex,
eSculptExpandFalloffType falloff_type)
{
- if (expand_cache->falloff_factor && expand_cache->falloff_factor_type == falloff_type) {
- /* Falloffs are already initialize with the current falloff type, nothing to do. */
- return;
- }
-
if (expand_cache->falloff_factor) {
MEM_freeN(expand_cache->falloff_factor);
}
@@ -519,7 +519,7 @@ static void sculpt_expand_mask_update_task_cb(void *__restrict userdata,
new_mask = 0.0f;
}
- if (expand_cache->mask_preserve) {
+ if (expand_cache->preserve) {
new_mask = max_ff(new_mask, expand_cache->initial_mask[vd.index]);
}
@@ -581,7 +581,7 @@ static void sculpt_expand_face_sets_update(SculptSession *ss, ExpandCache *expan
if (!enabled) {
continue;
}
- if (expand_cache->falloff_gradient) {
+ if (expand_cache->preserve) {
ss->face_sets[f] += expand_cache->next_face_set;
}
else {
@@ -754,11 +754,10 @@ static void sculpt_expand_update_for_vertex(bContext *C, Object *ob, const int v
static int sculpt_expand_target_vertex_update_and_get(bContext *C,
Object *ob,
- const wmEvent *event)
+ const float mouse[2])
{
SculptSession *ss = ob->sculpt;
SculptCursorGeometryInfo sgi;
- float mouse[2] = {event->mval[0], event->mval[1]};
if (SCULPT_cursor_geometry_info_update(C, &sgi, mouse, false)) {
return SCULPT_active_vertex_get(ss);
}
@@ -789,12 +788,111 @@ static void sculpt_expand_finish(bContext *C)
ED_workspace_status_text(C, NULL);
}
+static void sculpt_mask_expand_resursion_step_add(Object *ob, ExpandCache *expand_cache)
+{
+ SculptSession *ss = ob->sculpt;
+ const int totvert = SCULPT_vertex_count_get(ss);
+ BLI_bitmap *enabled_vertices = BLI_BITMAP_NEW(totvert, "boundary vertices");
+ GSet *initial_vertices = BLI_gset_int_new("initial_vertices");
+
+ for (int i = 0; i < totvert; i++) {
+ const bool enabled = sculpt_expand_state_get(expand_cache, i);
+ BLI_BITMAP_SET(enabled_vertices, i, enabled);
+ }
+
+ SculptFloodFill flood;
+ SCULPT_floodfill_init(ss, &flood);
+
+ for (int i = 0; i < totvert; i++) {
+ SculptVertexNeighborIter ni;
+ if (!BLI_BITMAP_TEST(enabled_vertices, i)) {
+ continue;
+ }
+
+ bool is_expand_boundary = false;
+ SCULPT_VERTEX_NEIGHBORS_ITER_BEGIN (ss, i, ni) {
+ if (!BLI_BITMAP_TEST(enabled_vertices, ni.index)) {
+ is_expand_boundary = true;
+ }
+ }
+ SCULPT_VERTEX_NEIGHBORS_ITER_END(ni);
+ if (is_expand_boundary) {
+ BLI_gset_add(initial_vertices, POINTER_FROM_INT(i));
+ SCULPT_floodfill_add_initial(&flood, i);
+ }
+ }
+
+ MEM_SAFE_FREE(expand_cache->falloff_factor);
+ MEM_SAFE_FREE(expand_cache->face_falloff_factor);
+ MEM_freeN(enabled_vertices);
+
+ float *dists = MEM_calloc_arrayN(sizeof(float), totvert, "topology dist");
+ ExpandFloodFillData fdata;
+ fdata.dists = dists;
+
+ SCULPT_floodfill_execute(ss, &flood, mask_expand_topology_floodfill_cb, &fdata);
+ SCULPT_floodfill_free(&flood);
+
+ expand_cache->falloff_factor = SCULPT_geodesic_distances_create(ob, initial_vertices, FLT_MAX);
+
+ sculpt_expand_update_max_falloff_factor(ss, expand_cache);
+
+ BLI_gset_free(initial_vertices, NULL);
+
+ if (expand_cache->target == SCULPT_EXPAND_TARGET_FACE_SETS) {
+ sculpt_expand_mesh_face_falloff_from_vertex_falloff(ob->data, expand_cache);
+ sculpt_expand_update_max_face_falloff_factor(ss, expand_cache);
+ }
+}
+
+static void sculpt_expand_set_initial_components_for_mouse(bContext *C,
+ Object *ob,
+ ExpandCache *expand_cache,
+ const float mouse[2])
+{
+ SculptSession *ss = ob->sculpt;
+ int initial_vertex = sculpt_expand_target_vertex_update_and_get(C, ob, mouse);
+ if (initial_vertex == SCULPT_EXPAND_VERTEX_NONE) {
+ /* Cursor not over the mesh, for creating valid initial falloffs, fallback to the last active
+ * vertex in the sculpt session. */
+ initial_vertex = SCULPT_active_vertex_get(ss);
+ }
+ copy_v2_v2(ss->expand_cache->initial_mouse, mouse);
+ expand_cache->initial_active_vertex = initial_vertex;
+ expand_cache->initial_active_face_set = SCULPT_active_face_set_get(ss);
+ expand_cache->next_face_set = ED_sculpt_face_sets_find_next_available_id(ob->data);
+}
+
+static void sculpt_expand_move_propagation_origin(bContext *C,
+ Object *ob,
+ const wmEvent *event,
+ ExpandCache *expand_cache)
+{
+ Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
+
+ const float mouse[2] = {event->mval[0], event->mval[1]};
+ float move_disp[2];
+ sub_v2_v2v2(move_disp, mouse, expand_cache->initial_mouse_move);
+
+ float new_mouse[2];
+ add_v2_v2v2(new_mouse, move_disp, expand_cache->original_mouse_move);
+
+ sculpt_expand_set_initial_components_for_mouse(C, ob, expand_cache, new_mouse);
+ sculpt_expand_falloff_factors_from_vertex_and_symm_create(expand_cache,
+ sd,
+ ob,
+ expand_cache->initial_active_vertex,
+ expand_cache->falloff_factor_type);
+}
+
static int sculpt_expand_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
Object *ob = CTX_data_active_object(C);
SculptSession *ss = ob->sculpt;
+ Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
- const int target_expand_vertex = sculpt_expand_target_vertex_update_and_get(C, ob, event);
+ const float mouse[2] = {event->mval[0], event->mval[1]};
+ const int target_expand_vertex = sculpt_expand_target_vertex_update_and_get(C, ob, mouse);
ExpandCache *expand_cache = ss->expand_cache;
if (event->type == EVT_MODAL_MAP) {
@@ -803,19 +901,61 @@ static int sculpt_expand_modal(bContext *C, wmOperator *op, const wmEvent *event
expand_cache->invert = !expand_cache->invert;
break;
}
- case SCULPT_EXPAND_MODAL_MASK_PRESERVE_TOGGLE: {
- expand_cache->mask_preserve = !expand_cache->mask_preserve;
+ case SCULPT_EXPAND_MODAL_PRESERVE_TOGGLE: {
+ expand_cache->preserve = !expand_cache->preserve;
break;
}
case SCULPT_EXPAND_MODAL_GRADIENT_TOGGLE: {
expand_cache->falloff_gradient = !expand_cache->falloff_gradient;
break;
}
+ case SCULPT_EXPAND_MODAL_MOVE_TOGGLE: {
+ if (expand_cache->move) {
+ expand_cache->move = false;
+ }
+ else {
+ expand_cache->move = true;
+ copy_v2_v2(expand_cache->initial_mouse_move, mouse);
+ copy_v2_v2(expand_cache->original_mouse_move, expand_cache->initial_mouse);
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list