Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/sculpt_paint/sculpt_filter_color.c
| Show First 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | static void color_filter_task_cb(void *__restrict userdata, | ||||
| SculptThreadedTaskData *data = userdata; | SculptThreadedTaskData *data = userdata; | ||||
| SculptSession *ss = data->ob->sculpt; | SculptSession *ss = data->ob->sculpt; | ||||
| const int mode = data->filter_type; | const int mode = data->filter_type; | ||||
| SculptOrigVertData orig_data; | SculptOrigVertData orig_data; | ||||
| SCULPT_orig_vert_data_init(&orig_data, data->ob, data->nodes[n], SCULPT_UNDO_COLOR); | SCULPT_orig_vert_data_init(&orig_data, data->ob, data->nodes[n], SCULPT_UNDO_COLOR); | ||||
| AutomaskingNodeData automask_data; | |||||
| SCULPT_automasking_node_begin( | |||||
| data->ob, ss, ss->filter_cache->automasking, &automask_data, data->nodes[n]); | |||||
| PBVHVertexIter vd; | PBVHVertexIter vd; | ||||
| BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { | BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { | ||||
| SCULPT_orig_vert_data_update(&orig_data, &vd); | SCULPT_orig_vert_data_update(&orig_data, &vd); | ||||
| SCULPT_automasking_node_update(ss, &automask_data, &vd); | |||||
| float orig_color[3], final_color[4], hsv_color[3]; | float orig_color[3], final_color[4], hsv_color[3]; | ||||
| int hue; | int hue; | ||||
| float brightness, contrast, gain, delta, offset; | float brightness, contrast, gain, delta, offset; | ||||
| float fade = vd.mask ? *vd.mask : 0.0f; | float fade = vd.mask ? *vd.mask : 0.0f; | ||||
| fade = 1.0f - fade; | fade = 1.0f - fade; | ||||
| fade *= data->filter_strength; | fade *= data->filter_strength; | ||||
| fade *= SCULPT_automasking_factor_get(ss->filter_cache->automasking, ss, vd.vertex); | fade *= SCULPT_automasking_factor_get( | ||||
| ss->filter_cache->automasking, ss, vd.vertex, &automask_data); | |||||
| if (fade == 0.0f) { | if (fade == 0.0f) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| copy_v3_v3(orig_color, orig_data.col); | copy_v3_v3(orig_color, orig_data.col); | ||||
| final_color[3] = orig_data.col[3]; /* Copy alpha */ | final_color[3] = orig_data.col[3]; /* Copy alpha */ | ||||
| switch (mode) { | switch (mode) { | ||||
| ▲ Show 20 Lines • Show All 213 Lines • ▼ Show 20 Lines | static int sculpt_color_filter_invoke(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| SculptSession *ss = ob->sculpt; | SculptSession *ss = ob->sculpt; | ||||
| PBVH *pbvh = ob->sculpt->pbvh; | PBVH *pbvh = ob->sculpt->pbvh; | ||||
| if (v3d->shading.type == OB_SOLID) { | if (v3d->shading.type == OB_SOLID) { | ||||
| v3d->shading.color_type = V3D_SHADING_VERTEX_COLOR; | v3d->shading.color_type = V3D_SHADING_VERTEX_COLOR; | ||||
| } | } | ||||
| const bool use_automasking = SCULPT_is_automasking_enabled(sd, ss, NULL); | const bool use_automasking = SCULPT_is_automasking_enabled(sd, ss, NULL); | ||||
| if (use_automasking) { | if (use_automasking) { | ||||
| /* Increment stroke id for automasking system. */ | |||||
| SCULPT_stroke_id_next(ob); | |||||
| /* Update the active face set manually as the paint cursor is not enabled when using the Mesh | /* Update the active face set manually as the paint cursor is not enabled when using the Mesh | ||||
| * Filter Tool. */ | * Filter Tool. */ | ||||
| float mval_fl[2] = {UNPACK2(event->mval)}; | float mval_fl[2] = {UNPACK2(event->mval)}; | ||||
| SculptCursorGeometryInfo sgi; | SculptCursorGeometryInfo sgi; | ||||
| SCULPT_cursor_geometry_info_update(C, &sgi, mval_fl, false); | SCULPT_cursor_geometry_info_update(C, &sgi, mval_fl, false); | ||||
| } | } | ||||
| /* Disable for multires and dyntopo for now */ | /* Disable for multires and dyntopo for now */ | ||||
| if (!ss->pbvh || !SCULPT_handles_colors_report(ss, op->reports)) { | if (!ss->pbvh || !SCULPT_handles_colors_report(ss, op->reports)) { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| SCULPT_undo_push_begin(ob, op); | SCULPT_undo_push_begin(ob, op); | ||||
| BKE_sculpt_color_layer_create_if_needed(ob); | BKE_sculpt_color_layer_create_if_needed(ob); | ||||
| /* CTX_data_ensure_evaluated_depsgraph should be used at the end to include the updates of | /* CTX_data_ensure_evaluated_depsgraph should be used at the end to include the updates of | ||||
| * earlier steps modifying the data. */ | * earlier steps modifying the data. */ | ||||
| Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); | Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); | ||||
| BKE_sculpt_update_object_for_edit(depsgraph, ob, true, false, true); | BKE_sculpt_update_object_for_edit(depsgraph, ob, true, false, true); | ||||
| if (BKE_pbvh_type(pbvh) == PBVH_FACES && !ob->sculpt->pmap) { | if (BKE_pbvh_type(pbvh) == PBVH_FACES && !ob->sculpt->pmap) { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| SCULPT_filter_cache_init(C, ob, sd, SCULPT_UNDO_COLOR); | SCULPT_filter_cache_init( | ||||
| C, ob, sd, SCULPT_UNDO_COLOR, event->mval, RNA_float_get(op->ptr, "area_normal_radius")); | |||||
| FilterCache *filter_cache = ss->filter_cache; | FilterCache *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 = SCULPT_automasking_cache_init(sd, NULL, ob); | filter_cache->automasking = SCULPT_automasking_cache_init(sd, NULL, ob); | ||||
| ED_paint_tool_update_sticky_shading_color(C, ob); | ED_paint_tool_update_sticky_shading_color(C, ob); | ||||
| WM_event_add_modal_handler(C, op); | WM_event_add_modal_handler(C, op); | ||||
| return OPERATOR_RUNNING_MODAL; | return OPERATOR_RUNNING_MODAL; | ||||
| } | } | ||||
| void SCULPT_OT_color_filter(struct wmOperatorType *ot) | void SCULPT_OT_color_filter(struct wmOperatorType *ot) | ||||
| { | { | ||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->name = "Filter Color"; | ot->name = "Filter Color"; | ||||
| ot->idname = "SCULPT_OT_color_filter"; | ot->idname = "SCULPT_OT_color_filter"; | ||||
| ot->description = "Applies a filter to modify the active color attribute"; | ot->description = "Applies a filter to modify the active color attribute"; | ||||
| /* api callbacks */ | /* api callbacks */ | ||||
| ot->invoke = sculpt_color_filter_invoke; | ot->invoke = sculpt_color_filter_invoke; | ||||
| ot->modal = sculpt_color_filter_modal; | ot->modal = sculpt_color_filter_modal; | ||||
| ot->poll = SCULPT_mode_poll; | ot->poll = SCULPT_mode_poll; | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ||||
| /* rna */ | /* rna */ | ||||
| SCULPT_mesh_filter_properties(ot); | |||||
| RNA_def_enum(ot->srna, "type", prop_color_filter_types, COLOR_FILTER_HUE, "Filter Type", ""); | RNA_def_enum(ot->srna, "type", prop_color_filter_types, COLOR_FILTER_HUE, "Filter Type", ""); | ||||
| RNA_def_float( | |||||
| ot->srna, "strength", 1.0f, -10.0f, 10.0f, "Strength", "Filter strength", -10.0f, 10.0f); | |||||
| PropertyRNA *prop = RNA_def_float_color( | PropertyRNA *prop = RNA_def_float_color( | ||||
| ot->srna, "fill_color", 3, NULL, 0.0f, FLT_MAX, "Fill Color", "", 0.0f, 1.0f); | ot->srna, "fill_color", 3, NULL, 0.0f, FLT_MAX, "Fill Color", "", 0.0f, 1.0f); | ||||
| RNA_def_property_subtype(prop, PROP_COLOR_GAMMA); | RNA_def_property_subtype(prop, PROP_COLOR_GAMMA); | ||||
| } | } | ||||