Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/sculpt_paint/sculpt_filter_mesh.c
| Show All 27 Lines | |||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_task.h" | #include "BLI_task.h" | ||||
| #include "DNA_mesh_types.h" | #include "DNA_mesh_types.h" | ||||
| #include "DNA_meshdata_types.h" | #include "DNA_meshdata_types.h" | ||||
| #include "BKE_brush.h" | #include "BKE_brush.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_image.h" | |||||
| #include "BKE_mesh.h" | #include "BKE_mesh.h" | ||||
| #include "BKE_mesh_mapping.h" | #include "BKE_mesh_mapping.h" | ||||
| #include "BKE_object.h" | #include "BKE_object.h" | ||||
| #include "BKE_paint.h" | #include "BKE_paint.h" | ||||
| #include "BKE_pbvh.h" | #include "BKE_pbvh.h" | ||||
| #include "BKE_scene.h" | #include "BKE_scene.h" | ||||
| #include "BKE_texture.h" | |||||
| #include "DEG_depsgraph.h" | #include "DEG_depsgraph.h" | ||||
| #include "WM_api.h" | #include "WM_api.h" | ||||
| #include "WM_message.h" | #include "WM_message.h" | ||||
| #include "WM_toolsystem.h" | #include "WM_toolsystem.h" | ||||
| #include "WM_types.h" | #include "WM_types.h" | ||||
| ▲ Show 20 Lines • Show All 162 Lines • ▼ Show 20 Lines | static void mesh_filter_task_cb(void *__restrict userdata, | ||||
| BKE_pbvh_vertex_iter_begin(ss->pbvh, node, vd, PBVH_ITER_UNIQUE) | BKE_pbvh_vertex_iter_begin(ss->pbvh, node, vd, PBVH_ITER_UNIQUE) | ||||
| { | { | ||||
| SCULPT_orig_vert_data_update(&orig_data, &vd); | SCULPT_orig_vert_data_update(&orig_data, &vd); | ||||
| float orig_co[3], val[3], avg[3], normal[3], disp[3], disp2[3], transform[3][3], final_pos[3]; | float orig_co[3], val[3], avg[3], normal[3], disp[3], disp2[3], transform[3][3], final_pos[3]; | ||||
| 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; | ||||
| if (data->filter_texture) { | |||||
| float rgba[4]; | |||||
| fade *= BKE_brush_filter_sample_tex_3d( | |||||
| data->filter_texture, orig_data.co, rgba, 0, ss->tex_pool); | |||||
| } | |||||
| if (fade == 0.0f) { | if (fade == 0.0f) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (ss->filter_cache->active_face_set != SCULPT_FACE_SET_NONE) { | if (ss->filter_cache->active_face_set != SCULPT_FACE_SET_NONE) { | ||||
| if (!SCULPT_vertex_has_face_set(ss, vd.index, ss->filter_cache->active_face_set)) { | if (!SCULPT_vertex_has_face_set(ss, vd.index, ss->filter_cache->active_face_set)) { | ||||
| /* Surface Smooth can't skip the loop for this vertex as it needs to calculate its | /* Surface Smooth can't skip the loop for this vertex as it needs to calculate its | ||||
| * laplacian_disp. This value is accessed from the vertex neighbors when deforming the | * laplacian_disp. This value is accessed from the vertex neighbors when deforming the | ||||
| ▲ Show 20 Lines • Show All 263 Lines • ▼ Show 20 Lines | static int sculpt_mesh_filter_modal(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| SculptThreadedTaskData data = { | SculptThreadedTaskData data = { | ||||
| .sd = sd, | .sd = sd, | ||||
| .ob = ob, | .ob = ob, | ||||
| .nodes = ss->filter_cache->nodes, | .nodes = ss->filter_cache->nodes, | ||||
| .filter_type = filter_type, | .filter_type = filter_type, | ||||
| .filter_strength = filter_strength, | .filter_strength = filter_strength, | ||||
| }; | }; | ||||
| if (sd->filter_texture) { | |||||
| MTex filter_mtex = {0}; | |||||
| BKE_texture_mtex_default(&filter_mtex); | |||||
| copy_v3_fl(filter_mtex.size, RNA_float_get(op->ptr, "texture_size")); | |||||
| filter_mtex.tex = sd->filter_texture; | |||||
| filter_mtex.mapping = MTEX_CUBE; | |||||
| data.filter_texture = &filter_mtex; | |||||
| if (!ss->tex_pool) { | |||||
| ss->tex_pool = BKE_image_pool_new(); | |||||
| } | |||||
| } | |||||
| else { | |||||
| data.filter_texture = NULL; | |||||
| } | |||||
| PBVHParallelSettings settings; | PBVHParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings( | BKE_pbvh_parallel_range_settings( | ||||
| &settings, (sd->flags & SCULPT_USE_OPENMP), ss->filter_cache->totnode); | &settings, (sd->flags & SCULPT_USE_OPENMP), ss->filter_cache->totnode); | ||||
| BKE_pbvh_parallel_range(0, ss->filter_cache->totnode, &data, mesh_filter_task_cb, &settings); | BKE_pbvh_parallel_range(0, ss->filter_cache->totnode, &data, mesh_filter_task_cb, &settings); | ||||
| if (filter_type == MESH_FILTER_SURFACE_SMOOTH) { | if (filter_type == MESH_FILTER_SURFACE_SMOOTH) { | ||||
| BKE_pbvh_parallel_range(0, | BKE_pbvh_parallel_range(0, | ||||
| ss->filter_cache->totnode, | ss->filter_cache->totnode, | ||||
| ▲ Show 20 Lines • Show All 158 Lines • ▼ Show 20 Lines | RNA_def_float(ot->srna, | ||||
| "sharpen_smooth_ratio", | "sharpen_smooth_ratio", | ||||
| 0.35f, | 0.35f, | ||||
| 0.0f, | 0.0f, | ||||
| 1.0f, | 1.0f, | ||||
| "Smooth Ratio", | "Smooth Ratio", | ||||
| "How much smoothing is applied to polished surfaces", | "How much smoothing is applied to polished surfaces", | ||||
| 0.0f, | 0.0f, | ||||
| 1.0f); | 1.0f); | ||||
| RNA_def_float(ot->srna, | |||||
| "texture_size", | |||||
| 1.0f, | |||||
| -100.0f, | |||||
| 100.0f, | |||||
| "Texture Size", | |||||
| "Scale of the filter texture", | |||||
| -10.0f, | |||||
| 10.0f); | |||||
| } | } | ||||