Face Sets Topology: Initial working version

This commit is contained in:
Pablo Dobarro 2021-03-16 23:17:08 +01:00
parent 02d482e8f2
commit e557e4d03c
4 changed files with 39 additions and 4 deletions

View File

@ -4476,6 +4476,9 @@ def km_sculpt(params):
{"properties": [("mode", 'INVERT')]}),
("sculpt.brush_stroke", {"type": 'LEFTMOUSE', "value": 'PRESS', "shift": True},
{"properties": [("mode", 'SMOOTH')]}),
# Face Set by Topology
("sculpt.face_set_by_topology", {"type": 'J', "value": 'PRESS'},
{"properties": [("mode", "POLY_LOOP")]}),
# Expand
("sculpt.expand", {"type": 'A', "value": 'PRESS', "shift": True},
{"properties": [("target", "MASK"), ("falloff_type", "GEODESIC"), ("invert", True)]}),

View File

@ -10055,6 +10055,7 @@ void ED_operatortypes_sculpt(void)
WM_operatortype_append(SCULPT_OT_face_sets_init);
WM_operatortype_append(SCULPT_OT_reset_brushes);
WM_operatortype_append(SCULPT_OT_ipmask_filter);
WM_operatortype_append(SCULPT_OT_face_set_by_topology);
WM_operatortype_append(SCULPT_OT_expand);
}

View File

@ -115,6 +115,9 @@ static bool sculpt_face_set_loop_step(SculptSession *ss, const int from_poly, co
if (next_poly == SCULPT_FACE_SET_LOOP_STEP_NONE) {
return false;
}
*r_next_poly = next_poly;
return true;
}
static int sculpt_face_set_loop_opposite_edge_in_quad(SculptSession *ss, const int poly, const int edge) {
@ -143,6 +146,7 @@ static void sculpt_face_set_by_topology_poly_loop(Object *ob, const int next_fac
MPoly *initial_poly = &mesh->mpoly[ss->active_face_index];
if (initial_poly->totloop != 4) {
printf("NO QUAD ON INITIAL\n");
return;
}
@ -184,24 +188,30 @@ static void sculpt_face_set_by_topology_poly_loop(Object *ob, const int next_fac
int current_poly = ss->active_face_index;
int current_edge = initial_edge_index;
int next_poly = SCULPT_FACE_SET_LOOP_STEP_NONE;
while(sculpt_face_set_loop_step(ss, current_poly, current_edge, &next_poly)) {
if (ss->face_sets[next_poly] == next_face_set_id) {
int max_steps = ss->totfaces;
while(max_steps && sculpt_face_set_loop_step(ss, current_poly, current_edge, &next_poly)) {
printf("LOOP STEP\n");
if (ss->face_sets[next_poly] == ss->active_face_index) {
printf("BREAK INITIAL\n");
break;
}
if (ss->face_sets[next_poly] < 0) {
printf("BREAK HIDDEN\n");
break;
}
if (ss->mpoly[next_poly].totloop != 4) {
printf("BREAK NON QUAD %d\n", next_poly);
break;
}
ss->face_sets[next_poly] = next_face_set_id;
current_edge = sculpt_face_set_loop_opposite_edge_in_quad(ss, next_poly, current_edge);
current_poly = next_poly;
max_steps--;
}
}
static int sculpt_face_set_by_topology_invok(bContext *C, wmOperator *op, const wmEvent *event)
static int sculpt_face_set_by_topology_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
Object *ob = CTX_data_active_object(C);
SculptSession *ss = ob->sculpt;
@ -209,6 +219,7 @@ static int sculpt_face_set_by_topology_invok(bContext *C, wmOperator *op, const
const int mode = RNA_enum_get(op->ptr, "mode");
BKE_sculpt_update_object_for_edit(depsgraph, ob, true, false, false);
printf("FACE SET TOPOLOGY\n");
/* Update the current active Face Set and Vertex as the operator can be used directly from the
* tool without brush cursor. */
@ -224,10 +235,11 @@ static int sculpt_face_set_by_topology_invok(bContext *C, wmOperator *op, const
BKE_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnode);
SCULPT_undo_push_begin(ob, "face set edit");
SCULPT_undo_push_node(ob, nodes[0], SCULPT_UNDO_FACE_SETS);
MEM_freeN(nodes);
Mesh *mesh = BKE_object_get_original_mesh(ob);
const int next_face_set = ED_sculpt_face_sets_find_next_available_id(mesh);
printf("NEXT FACE SET %d\n", next_face_set);
switch (mode) {
case SCULPT_FACE_SET_TOPOLOGY_LOOSE_PART:
@ -238,6 +250,22 @@ static int sculpt_face_set_by_topology_invok(bContext *C, wmOperator *op, const
break;
}
/* Sync face sets visibility and vertex visibility as now all Face Sets are visible. */
SCULPT_visibility_sync_all_face_sets_to_vertices(ob);
for (int i = 0; i < totnode; i++) {
BKE_pbvh_node_mark_update_visibility(nodes[i]);
}
BKE_pbvh_update_vertex_data(ss->pbvh, PBVH_UpdateVisibility);
if (BKE_pbvh_type(ss->pbvh) == PBVH_FACES) {
BKE_mesh_flush_hidden_from_verts(ob->data);
}
MEM_freeN(nodes);
SCULPT_undo_push_end();
SCULPT_tag_update_overlays(C);

View File

@ -1422,6 +1422,9 @@ bool SCULPT_get_redraw_rect(struct ARegion *region,
/* Operators. */
/* Face Set by Topology. */
void SCULPT_OT_face_set_by_topology(struct wmOperatorType *ot);
/* Expand. */
void SCULPT_OT_expand(struct wmOperatorType *ot);
void sculpt_expand_modal_keymap(struct wmKeyConfig *keyconf);