Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/sculpt_paint/sculpt_face_set.c
| Show First 20 Lines • Show All 322 Lines • ▼ Show 20 Lines | static int sculpt_face_set_create_exec(bContext *C, wmOperator *op) | ||||
| PBVHNode **nodes; | PBVHNode **nodes; | ||||
| int totnode; | int totnode; | ||||
| BKE_pbvh_search_gather(pbvh, NULL, NULL, &nodes, &totnode); | BKE_pbvh_search_gather(pbvh, NULL, NULL, &nodes, &totnode); | ||||
| if (!nodes) { | if (!nodes) { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| SCULPT_undo_push_begin("face set change"); | SCULPT_undo_push_begin(C, "face set change"); | ||||
| SCULPT_undo_push_node(ob, nodes[0], SCULPT_UNDO_FACE_SETS); | SCULPT_undo_push_node(ob, nodes[0], SCULPT_UNDO_FACE_SETS); | ||||
| const int next_face_set = SCULPT_face_set_next_available_get(ss); | const int next_face_set = SCULPT_face_set_next_available_get(ss); | ||||
| if (mode == SCULPT_FACE_SET_MASKED) { | if (mode == SCULPT_FACE_SET_MASKED) { | ||||
| for (int i = 0; i < tot_vert; i++) { | for (int i = 0; i < tot_vert; i++) { | ||||
| if (SCULPT_vertex_mask_get(ss, i) >= threshold && SCULPT_vertex_visible_get(ss, i)) { | if (SCULPT_vertex_mask_get(ss, i) >= threshold && SCULPT_vertex_visible_get(ss, i)) { | ||||
| SCULPT_vertex_face_set_set(ss, i, next_face_set); | SCULPT_vertex_face_set_set(ss, i, next_face_set); | ||||
| ▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | static int sculpt_face_set_create_exec(bContext *C, wmOperator *op) | ||||
| } | } | ||||
| for (int i = 0; i < totnode; i++) { | for (int i = 0; i < totnode; i++) { | ||||
| BKE_pbvh_node_mark_redraw(nodes[i]); | BKE_pbvh_node_mark_redraw(nodes[i]); | ||||
| } | } | ||||
| MEM_SAFE_FREE(nodes); | MEM_SAFE_FREE(nodes); | ||||
| SCULPT_undo_push_end(); | SCULPT_undo_push_end(C); | ||||
| SCULPT_tag_update_overlays(C); | SCULPT_tag_update_overlays(C); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| void SCULPT_OT_face_sets_create(wmOperatorType *ot) | void SCULPT_OT_face_sets_create(wmOperatorType *ot) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 262 Lines • ▼ Show 20 Lines | static int sculpt_face_set_init_exec(bContext *C, wmOperator *op) | ||||
| PBVHNode **nodes; | PBVHNode **nodes; | ||||
| int totnode; | int totnode; | ||||
| BKE_pbvh_search_gather(pbvh, NULL, NULL, &nodes, &totnode); | BKE_pbvh_search_gather(pbvh, NULL, NULL, &nodes, &totnode); | ||||
| if (!nodes) { | if (!nodes) { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| SCULPT_undo_push_begin("face set change"); | SCULPT_undo_push_begin(C, "face set change"); | ||||
| SCULPT_undo_push_node(ob, nodes[0], SCULPT_UNDO_FACE_SETS); | SCULPT_undo_push_node(ob, nodes[0], SCULPT_UNDO_FACE_SETS); | ||||
| const float threshold = RNA_float_get(op->ptr, "threshold"); | const float threshold = RNA_float_get(op->ptr, "threshold"); | ||||
| switch (mode) { | switch (mode) { | ||||
| case SCULPT_FACE_SETS_FROM_LOOSE_PARTS: | case SCULPT_FACE_SETS_FROM_LOOSE_PARTS: | ||||
| sculpt_face_sets_init_flood_fill(ob, sculpt_face_sets_init_loose_parts_test, threshold); | sculpt_face_sets_init_flood_fill(ob, sculpt_face_sets_init_loose_parts_test, threshold); | ||||
| break; | break; | ||||
| Show All 15 Lines | switch (mode) { | ||||
| case SCULPT_FACE_SETS_FROM_BEVEL_WEIGHT: | case SCULPT_FACE_SETS_FROM_BEVEL_WEIGHT: | ||||
| sculpt_face_sets_init_flood_fill(ob, sculpt_face_sets_init_bevel_weight_test, threshold); | sculpt_face_sets_init_flood_fill(ob, sculpt_face_sets_init_bevel_weight_test, threshold); | ||||
| break; | break; | ||||
| case SCULPT_FACE_SETS_FROM_FACE_MAPS: | case SCULPT_FACE_SETS_FROM_FACE_MAPS: | ||||
| sculpt_face_sets_init_loop(ob, SCULPT_FACE_SETS_FROM_FACE_MAPS); | sculpt_face_sets_init_loop(ob, SCULPT_FACE_SETS_FROM_FACE_MAPS); | ||||
| break; | break; | ||||
| } | } | ||||
| SCULPT_undo_push_end(); | SCULPT_undo_push_end(C); | ||||
| /* Sync face sets visibility and vertex visibility as now all Face Sets are visible. */ | /* Sync face sets visibility and vertex visibility as now all Face Sets are visible. */ | ||||
| SCULPT_visibility_sync_all_face_sets_to_vertices(ob); | SCULPT_visibility_sync_all_face_sets_to_vertices(ob); | ||||
| for (int i = 0; i < totnode; i++) { | for (int i = 0; i < totnode; i++) { | ||||
| BKE_pbvh_node_mark_update_visibility(nodes[i]); | BKE_pbvh_node_mark_update_visibility(nodes[i]); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | static int sculpt_face_sets_change_visibility_exec(bContext *C, wmOperator *op) | ||||
| } | } | ||||
| BKE_sculpt_update_object_for_edit(depsgraph, ob, true, true, false); | BKE_sculpt_update_object_for_edit(depsgraph, ob, true, true, false); | ||||
| const int tot_vert = SCULPT_vertex_count_get(ss); | const int tot_vert = SCULPT_vertex_count_get(ss); | ||||
| const int mode = RNA_enum_get(op->ptr, "mode"); | const int mode = RNA_enum_get(op->ptr, "mode"); | ||||
| const int active_face_set = SCULPT_active_face_set_get(ss); | const int active_face_set = SCULPT_active_face_set_get(ss); | ||||
| SCULPT_undo_push_begin("Hide area"); | SCULPT_undo_push_begin(C, "Hide area"); | ||||
| PBVH *pbvh = ob->sculpt->pbvh; | PBVH *pbvh = ob->sculpt->pbvh; | ||||
| PBVHNode **nodes; | PBVHNode **nodes; | ||||
| int totnode; | int totnode; | ||||
| BKE_pbvh_search_gather(pbvh, NULL, NULL, &nodes, &totnode); | BKE_pbvh_search_gather(pbvh, NULL, NULL, &nodes, &totnode); | ||||
| if (totnode == 0) { | if (totnode == 0) { | ||||
| ▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | if (ELEM(mode, SCULPT_FACE_SET_VISIBILITY_TOGGLE, SCULPT_FACE_SET_VISIBILITY_SHOW_ACTIVE)) { | ||||
| copy_v3_v3(ups->average_stroke_accum, location); | copy_v3_v3(ups->average_stroke_accum, location); | ||||
| ups->average_stroke_counter = 1; | ups->average_stroke_counter = 1; | ||||
| ups->last_stroke_valid = true; | ups->last_stroke_valid = true; | ||||
| } | } | ||||
| /* Sync face sets visibility and vertex visibility. */ | /* Sync face sets visibility and vertex visibility. */ | ||||
| SCULPT_visibility_sync_all_face_sets_to_vertices(ob); | SCULPT_visibility_sync_all_face_sets_to_vertices(ob); | ||||
| SCULPT_undo_push_end(); | SCULPT_undo_push_end(C); | ||||
| for (int i = 0; i < totnode; i++) { | for (int i = 0; i < totnode; i++) { | ||||
| BKE_pbvh_node_mark_update_visibility(nodes[i]); | BKE_pbvh_node_mark_update_visibility(nodes[i]); | ||||
| } | } | ||||
| BKE_pbvh_update_vertex_data(ss->pbvh, PBVH_UpdateVisibility); | BKE_pbvh_update_vertex_data(ss->pbvh, PBVH_UpdateVisibility); | ||||
| MEM_SAFE_FREE(nodes); | MEM_SAFE_FREE(nodes); | ||||
| ▲ Show 20 Lines • Show All 313 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| static void sculpt_face_set_edit_modify_geometry(bContext *C, | static void sculpt_face_set_edit_modify_geometry(bContext *C, | ||||
| Object *ob, | Object *ob, | ||||
| const int active_face_set, | const int active_face_set, | ||||
| const eSculptFaceSetEditMode mode, | const eSculptFaceSetEditMode mode, | ||||
| const bool modify_hidden) | const bool modify_hidden) | ||||
| { | { | ||||
| ED_sculpt_undo_geometry_begin(ob, "edit face set delete geometry"); | ED_sculpt_undo_geometry_begin(C, ob, "edit face set delete geometry"); | ||||
| sculpt_face_set_apply_edit(ob, abs(active_face_set), mode, modify_hidden); | sculpt_face_set_apply_edit(ob, abs(active_face_set), mode, modify_hidden); | ||||
| ED_sculpt_undo_geometry_end(ob); | ED_sculpt_undo_geometry_end(C, ob); | ||||
| BKE_mesh_batch_cache_dirty_tag(ob->data, BKE_MESH_BATCH_DIRTY_ALL); | BKE_mesh_batch_cache_dirty_tag(ob->data, BKE_MESH_BATCH_DIRTY_ALL); | ||||
| DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); | DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); | ||||
| WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data); | WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data); | ||||
| } | } | ||||
| static void face_set_edit_do_post_visibility_updates(Object *ob, PBVHNode **nodes, int totnode) | static void face_set_edit_do_post_visibility_updates(Object *ob, PBVHNode **nodes, int totnode) | ||||
| { | { | ||||
| SculptSession *ss = ob->sculpt; | SculptSession *ss = ob->sculpt; | ||||
| PBVH *pbvh = ss->pbvh; | PBVH *pbvh = ss->pbvh; | ||||
| /* Sync face sets visibility and vertex visibility as now all Face Sets are visible. */ | /* Sync face sets visibility and vertex visibility as now all Face Sets are visible. */ | ||||
| SCULPT_visibility_sync_all_face_sets_to_vertices(ob); | SCULPT_visibility_sync_all_face_sets_to_vertices(ob); | ||||
| for (int i = 0; i < totnode; i++) { | for (int i = 0; i < totnode; i++) { | ||||
| BKE_pbvh_node_mark_update_visibility(nodes[i]); | BKE_pbvh_node_mark_update_visibility(nodes[i]); | ||||
| } | } | ||||
| BKE_pbvh_update_vertex_data(ss->pbvh, PBVH_UpdateVisibility); | BKE_pbvh_update_vertex_data(ss->pbvh, PBVH_UpdateVisibility); | ||||
| if (BKE_pbvh_type(pbvh) == PBVH_FACES) { | if (BKE_pbvh_type(pbvh) == PBVH_FACES) { | ||||
| BKE_mesh_flush_hidden_from_verts(ob->data); | BKE_mesh_flush_hidden_from_verts(ob->data); | ||||
| } | } | ||||
| } | } | ||||
| static void sculpt_face_set_edit_modify_face_sets(Object *ob, | static void sculpt_face_set_edit_modify_face_sets(const bContext *C, | ||||
| Object *ob, | |||||
| const int active_face_set, | const int active_face_set, | ||||
| const eSculptFaceSetEditMode mode, | const eSculptFaceSetEditMode mode, | ||||
| const bool modify_hidden) | const bool modify_hidden) | ||||
| { | { | ||||
| PBVH *pbvh = ob->sculpt->pbvh; | PBVH *pbvh = ob->sculpt->pbvh; | ||||
| PBVHNode **nodes; | PBVHNode **nodes; | ||||
| int totnode; | int totnode; | ||||
| BKE_pbvh_search_gather(pbvh, NULL, NULL, &nodes, &totnode); | BKE_pbvh_search_gather(pbvh, NULL, NULL, &nodes, &totnode); | ||||
| if (!nodes) { | if (!nodes) { | ||||
| return; | return; | ||||
| } | } | ||||
| SCULPT_undo_push_begin("face set edit"); | SCULPT_undo_push_begin(C, "face set edit"); | ||||
| SCULPT_undo_push_node(ob, nodes[0], SCULPT_UNDO_FACE_SETS); | SCULPT_undo_push_node(ob, nodes[0], SCULPT_UNDO_FACE_SETS); | ||||
| sculpt_face_set_apply_edit(ob, abs(active_face_set), mode, modify_hidden); | sculpt_face_set_apply_edit(ob, abs(active_face_set), mode, modify_hidden); | ||||
| SCULPT_undo_push_end(); | SCULPT_undo_push_end(C); | ||||
| face_set_edit_do_post_visibility_updates(ob, nodes, totnode); | face_set_edit_do_post_visibility_updates(ob, nodes, totnode); | ||||
| MEM_freeN(nodes); | MEM_freeN(nodes); | ||||
| } | } | ||||
| static int sculpt_face_set_edit_invoke(bContext *C, wmOperator *op, const wmEvent *event) | static int sculpt_face_set_edit_invoke(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| { | { | ||||
| Object *ob = CTX_data_active_object(C); | Object *ob = CTX_data_active_object(C); | ||||
| SculptSession *ss = ob->sculpt; | SculptSession *ss = ob->sculpt; | ||||
| Show All 16 Lines | static int sculpt_face_set_edit_invoke(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| const int active_face_set = SCULPT_active_face_set_get(ss); | const int active_face_set = SCULPT_active_face_set_get(ss); | ||||
| switch (mode) { | switch (mode) { | ||||
| case SCULPT_FACE_SET_EDIT_DELETE_GEOMETRY: | case SCULPT_FACE_SET_EDIT_DELETE_GEOMETRY: | ||||
| sculpt_face_set_edit_modify_geometry(C, ob, active_face_set, mode, modify_hidden); | sculpt_face_set_edit_modify_geometry(C, ob, active_face_set, mode, modify_hidden); | ||||
| break; | break; | ||||
| case SCULPT_FACE_SET_EDIT_GROW: | case SCULPT_FACE_SET_EDIT_GROW: | ||||
| case SCULPT_FACE_SET_EDIT_SHRINK: | case SCULPT_FACE_SET_EDIT_SHRINK: | ||||
| sculpt_face_set_edit_modify_face_sets(ob, active_face_set, mode, modify_hidden); | sculpt_face_set_edit_modify_face_sets(C, ob, active_face_set, mode, modify_hidden); | ||||
| break; | break; | ||||
| } | } | ||||
| SCULPT_tag_update_overlays(C); | SCULPT_tag_update_overlays(C); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| Show All 21 Lines | |||||