Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--release/datafiles/icons/brush.sculpt.displacement_heal.datbin0 -> 2726 bytes
-rw-r--r--release/datafiles/icons/brush.sculpt.draw_sharp.datbin2492 -> 2492 bytes
-rw-r--r--source/blender/blenkernel/BKE_subdiv_ccg.h11
-rw-r--r--source/blender/blenkernel/intern/subdiv_ccg.c35
-rw-r--r--source/blender/editors/datafiles/CMakeLists.txt2
-rw-r--r--source/blender/editors/sculpt_paint/sculpt.c6
-rw-r--r--source/blender/editors/sculpt_paint/sculpt_brush_types.c178
-rw-r--r--source/blender/editors/sculpt_paint/sculpt_intern.h4
-rw-r--r--source/blender/makesdna/DNA_brush_enums.h1
-rw-r--r--source/blender/makesrna/intern/rna_brush.c1
10 files changed, 237 insertions, 1 deletions
diff --git a/release/datafiles/icons/brush.sculpt.displacement_heal.dat b/release/datafiles/icons/brush.sculpt.displacement_heal.dat
new file mode 100644
index 00000000000..24960495f21
--- /dev/null
+++ b/release/datafiles/icons/brush.sculpt.displacement_heal.dat
Binary files differ
diff --git a/release/datafiles/icons/brush.sculpt.draw_sharp.dat b/release/datafiles/icons/brush.sculpt.draw_sharp.dat
index 1877c0ae4d4..9bea1b02894 100644
--- a/release/datafiles/icons/brush.sculpt.draw_sharp.dat
+++ b/release/datafiles/icons/brush.sculpt.draw_sharp.dat
Binary files differ
diff --git a/source/blender/blenkernel/BKE_subdiv_ccg.h b/source/blender/blenkernel/BKE_subdiv_ccg.h
index b3aa966e0d0..2de16bbddd4 100644
--- a/source/blender/blenkernel/BKE_subdiv_ccg.h
+++ b/source/blender/blenkernel/BKE_subdiv_ccg.h
@@ -314,6 +314,17 @@ void BKE_subdiv_ccg_eval_limit_point(const SubdivCCG *subdiv_ccg,
const SubdivCCGCoord *coord,
float r_point[3]);
+void BKE_subdiv_ccg_eval_limit_point_and_derivatives(const SubdivCCG *subdiv_ccg,
+ const SubdivCCGCoord *coord,
+ float r_point[3],
+ float r_dPdu[3],
+ float r_dPdv[3]);
+
+void BKE_subdiv_ccg_get_tangent_matrix(const SubdivCCG *subdiv_ccg,
+ const SubdivCCGCoord *coord,
+ float mat[3][3],
+ float r_point[3]);
+
typedef enum SubdivCCGAdjacencyType {
SUBDIV_CCG_ADJACENT_NONE,
SUBDIV_CCG_ADJACENT_VERTEX,
diff --git a/source/blender/blenkernel/intern/subdiv_ccg.c b/source/blender/blenkernel/intern/subdiv_ccg.c
index 7d876acf776..2acf94cf7d1 100644
--- a/source/blender/blenkernel/intern/subdiv_ccg.c
+++ b/source/blender/blenkernel/intern/subdiv_ccg.c
@@ -37,6 +37,7 @@
#include "BKE_ccg.h"
#include "BKE_global.h"
#include "BKE_mesh.h"
+#include "BKE_multires.h"
#include "BKE_subdiv.h"
#include "BKE_subdiv_eval.h"
@@ -2102,4 +2103,38 @@ void BKE_subdiv_ccg_eval_limit_point(const SubdivCCG *subdiv_ccg,
BKE_subdiv_eval_limit_point(subdiv, ptex_face_index, u, v, r_point);
}
+void BKE_subdiv_ccg_eval_limit_point_and_derivatives(const SubdivCCG *subdiv_ccg,
+ const SubdivCCGCoord *coord,
+ float r_point[3],
+ float r_dPdu[3],
+ float r_dPdv[3])
+{
+ Subdiv *subdiv = subdiv_ccg->subdiv;
+ int ptex_face_index;
+ float u, v;
+ subdiv_ccg_coord_to_ptex_coord(subdiv_ccg, coord, &ptex_face_index, &u, &v);
+ BKE_subdiv_eval_limit_point_and_derivatives(
+ subdiv, ptex_face_index, u, v, r_point, r_dPdu, r_dPdv);
+}
+
+void BKE_subdiv_ccg_get_tangent_matrix(const SubdivCCG *subdiv_ccg,
+ const SubdivCCGCoord *coord,
+ float mat[3][3],
+ float r_point[3])
+{
+ int ptex_face_index;
+ float u, v;
+ float du[3], dv[3];
+
+ const int face_index = BKE_subdiv_ccg_grid_to_face_index(subdiv_ccg, coord->grid_index);
+ const SubdivCCGFace *faces = subdiv_ccg->faces;
+ const SubdivCCGFace *face = &faces[face_index];
+ const float corner = coord->grid_index - face->start_grid_index;
+
+ subdiv_ccg_coord_to_ptex_coord(subdiv_ccg, coord, &ptex_face_index, &u, &v);
+
+ BKE_subdiv_ccg_eval_limit_point_and_derivatives(subdiv_ccg, coord, r_point, du, dv);
+ BKE_multires_construct_tangent_matrix(mat, du, dv, corner);
+}
+
/** \} */
diff --git a/source/blender/editors/datafiles/CMakeLists.txt b/source/blender/editors/datafiles/CMakeLists.txt
index 8d32eba1766..1ec4b443bd2 100644
--- a/source/blender/editors/datafiles/CMakeLists.txt
+++ b/source/blender/editors/datafiles/CMakeLists.txt
@@ -751,7 +751,7 @@ set_property(GLOBAL PROPERTY ICON_GEOM_NAMES
brush.sculpt.cloth
brush.sculpt.crease
brush.sculpt.displacement_eraser
- brush.sculpt.displacement_smear
+ brush.sculpt.displacement_heal
brush.sculpt.draw
brush.sculpt.draw_face_sets
brush.sculpt.draw_sharp
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 5ac13ebdd93..9d07471c7bd 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -2229,6 +2229,7 @@ static float brush_strength(const Sculpt *sd,
case SCULPT_TOOL_DRAW_SHARP:
case SCULPT_TOOL_LAYER:
return alpha * flip * pressure * overlap * feather;
+ case SCULPT_TOOL_DISPLACEMENT_HEAL:
case SCULPT_TOOL_DISPLACEMENT_ERASER:
return alpha * pressure * overlap * feather;
case SCULPT_TOOL_CLOTH:
@@ -3400,6 +3401,9 @@ static void do_brush_action(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSe
case SCULPT_TOOL_DISPLACEMENT_SMEAR:
SCULPT_do_displacement_smear_brush(sd, ob, nodes, totnode);
break;
+ case SCULPT_TOOL_DISPLACEMENT_HEAL:
+ SCULPT_do_displacement_heal_brush(sd, ob, nodes, totnode);
+ break;
case SCULPT_TOOL_PAINT:
SCULPT_do_paint_brush(sd, ob, nodes, totnode);
break;
@@ -3950,6 +3954,8 @@ static const char *sculpt_tool_name(Sculpt *sd)
return "Multires Displacement Eraser";
case SCULPT_TOOL_DISPLACEMENT_SMEAR:
return "Multires Displacement Smear";
+ case SCULPT_TOOL_DISPLACEMENT_HEAL:
+ return "Multires Heal";
case SCULPT_TOOL_PAINT:
return "Paint Brush";
case SCULPT_TOOL_SMEAR:
diff --git a/source/blender/editors/sculpt_paint/sculpt_brush_types.c b/source/blender/editors/sculpt_paint/sculpt_brush_types.c
index c2acc361a79..5d0f4f2e30e 100644
--- a/source/blender/editors/sculpt_paint/sculpt_brush_types.c
+++ b/source/blender/editors/sculpt_paint/sculpt_brush_types.c
@@ -2845,3 +2845,181 @@ void SCULPT_do_mask_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
}
/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Multires Heal Brush
+ * \{ */
+
+BLI_INLINE int grid_xy_to_vertex(int x, int y, int grid_i, int gridsize)
+{
+ return grid_i * gridsize * gridsize + y * gridsize + x;
+}
+
+typedef struct DisplacementHealTaskData {
+ Object *ob;
+ Brush *brush;
+ Sculpt *sd;
+ PBVHNode **nodes;
+ BLI_bitmap *bitmap;
+ float plane_view[3];
+ float bstrength;
+} DisplacementHealTaskData;
+
+static void do_displacement_heal_cb(void *__restrict userdata,
+ const int n,
+ const TaskParallelTLS *__restrict tls)
+{
+ DisplacementHealTaskData *data = userdata;
+ SculptSession *ss = data->ob->sculpt;
+
+ PBVHNode *node = data->nodes[n];
+
+ CCGElem **grids;
+
+ int *grid_indices, totgrid, maxgrid, gridsize;
+ const float bstrength = data->bstrength;
+
+ BKE_pbvh_node_get_grids(ss->pbvh, node, &grid_indices, &totgrid, &maxgrid, &gridsize, &grids);
+
+ float(*disps)[3] = MEM_calloc_arrayN(gridsize * gridsize, sizeof(float) * 3, __func__);
+ float(*mats)[16] = MEM_calloc_arrayN(gridsize * gridsize, sizeof(float) * 16, __func__);
+ float(*limits)[3] = MEM_calloc_arrayN(gridsize * gridsize, sizeof(float) * 3, __func__);
+
+ bool modified = false;
+
+ for (int i = 0; i < totgrid; i++) {
+ const int grid_i = grid_indices[i];
+
+ for (int x = 0; x < gridsize; x++) {
+ for (int y = 0; y < gridsize; y++) {
+ int vertex = grid_xy_to_vertex(x, y, grid_i, gridsize);
+
+ SubdivCCGCoord coord = {.grid_index = grid_i, .x = x, .y = y};
+ int locali = y * gridsize + x;
+ float mat[3][3], p[3];
+
+ BKE_subdiv_ccg_get_tangent_matrix(ss->subdiv_ccg, &coord, mat, p);
+ copy_m3_m3(mats[locali], mat);
+
+ invert_m3(mat);
+
+ float disp[3];
+ copy_v3_v3(disp, SCULPT_vertex_co_get(ss, vertex));
+ sub_v3_v3(disp, p);
+ mul_v3_m3v3(disp, mat, disp);
+
+ float test = dot_v3v3(disp, disp);
+ if (isnan(test) || isinf(test)) {
+ zero_v3(disp);
+ }
+
+ copy_v3_v3(disps[locali], disp);
+ copy_v3_v3(limits[locali], p);
+ }
+ }
+
+ for (int x = 0; x < gridsize; x++) {
+ for (int y = 0; y < gridsize; y++) {
+ int locali = y * gridsize + x;
+
+ int vertex = grid_xy_to_vertex(x, y, grid_i, gridsize);
+ float *disp = disps[locali];
+ float avg[3] = {0.0f, 0.0f, 0.0f};
+ float tot = 0.0f;
+
+ for (int x2 = x - 1; x2 <= x + 1; x2++) {
+ for (int y2 = y - 1; y2 <= y + 1; y2++) {
+ if (x2 < 0 || y2 < 0 || x2 >= gridsize || y2 >= gridsize) {
+ continue;
+ }
+
+ int local2 = y2 * gridsize + x2;
+
+ add_v3_v3(avg, disps[local2]);
+ tot += 1.0f;
+ }
+ }
+
+ if (tot == 0.0f) {
+ continue;
+ }
+
+ mul_v3_fl(avg, 1.0 / tot);
+
+ if (dot_v3v3(avg, avg) == 0.0f || dot_v3v3(disp, disp) == 0.0f) {
+ continue;
+ }
+
+ float ratio = len_v3(disp) / len_v3(avg);
+
+ if (ratio < 1.0f) {
+ continue;
+ }
+
+ modified = true;
+
+ ratio = pow(ratio, 0.1f);
+ float tmp[3];
+
+ copy_v3_v3(tmp, disp);
+ mul_v3_fl(tmp, 1.0f / ratio);
+ mul_v3_m3v3(tmp, mats[locali], tmp);
+ add_v3_v3(tmp, limits[locali]);
+
+ float *co = (float *)SCULPT_vertex_co_get(ss, vertex);
+ float test = dot_v3v3(co, co);
+
+ if (isnan(test) || isinf(test)) {
+ copy_v3_v3(co, tmp);
+ }
+ else {
+ interp_v3_v3v3(co, co, tmp, bstrength);
+ }
+ }
+ }
+ }
+
+ MEM_SAFE_FREE(disps);
+ MEM_SAFE_FREE(mats);
+ MEM_SAFE_FREE(limits);
+
+ if (modified) {
+ BKE_pbvh_node_mark_update(node);
+ }
+}
+
+void SCULPT_do_displacement_heal_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
+{
+ SculptSession *ss = ob->sculpt;
+ Brush *brush = BKE_paint_brush(&sd->paint);
+
+ if (!ss->pbvh || BKE_pbvh_type(ss->pbvh) != PBVH_GRIDS) {
+ return;
+ }
+
+ SCULPT_boundary_info_ensure(ob);
+
+ const int totvert = SCULPT_vertex_count_get(ss);
+ BLI_bitmap *bitmap = BLI_BITMAP_NEW(totvert, __func__);
+ const float bstrength = fabsf(ss->cache->bstrength);
+
+ /* paranoia check */
+ ss->cache->radius_squared = ss->cache->radius * ss->cache->radius;
+
+ /* Threaded loop over nodes. */
+ DisplacementHealTaskData data = {.sd = sd,
+ .ob = ob,
+ .brush = brush,
+ .bstrength = bstrength,
+ .nodes = nodes,
+ .bitmap = bitmap};
+
+ copy_v3_v3(data.plane_view, ss->cache->view_normal);
+
+ TaskParallelSettings settings;
+ BKE_pbvh_parallel_range_settings(&settings, true, totnode);
+ BLI_task_parallel_range(0, totnode, &data, do_displacement_heal_cb, &settings);
+
+ MEM_SAFE_FREE(bitmap);
+}
+/** \} */
diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h
index f84380b4f64..99cc011ef1d 100644
--- a/source/blender/editors/sculpt_paint/sculpt_intern.h
+++ b/source/blender/editors/sculpt_paint/sculpt_intern.h
@@ -1719,6 +1719,10 @@ void SCULPT_do_slide_relax_brush(struct Sculpt *sd,
struct PBVHNode **nodes,
int totnode);
+void SCULPT_do_displacement_heal_brush(struct Sculpt *sd,
+ struct Object *ob,
+ struct PBVHNode **nodes,
+ int totnode);
void SCULPT_do_displacement_smear_brush(struct Sculpt *sd,
struct Object *ob,
struct PBVHNode **nodes,
diff --git a/source/blender/makesdna/DNA_brush_enums.h b/source/blender/makesdna/DNA_brush_enums.h
index 72b2db89cef..c74588bec4e 100644
--- a/source/blender/makesdna/DNA_brush_enums.h
+++ b/source/blender/makesdna/DNA_brush_enums.h
@@ -460,6 +460,7 @@ typedef enum eBrushSculptTool {
SCULPT_TOOL_BOUNDARY = 30,
SCULPT_TOOL_DISPLACEMENT_ERASER = 31,
SCULPT_TOOL_DISPLACEMENT_SMEAR = 32,
+ SCULPT_TOOL_DISPLACEMENT_HEAL = 45 /* use value from sculpt-dev */
} eBrushSculptTool;
/* Brush.uv_sculpt_tool */
diff --git a/source/blender/makesrna/intern/rna_brush.c b/source/blender/makesrna/intern/rna_brush.c
index b4cf15ebfc6..03f13abddd4 100644
--- a/source/blender/makesrna/intern/rna_brush.c
+++ b/source/blender/makesrna/intern/rna_brush.c
@@ -138,6 +138,7 @@ const EnumPropertyItem rna_enum_brush_sculpt_tool_items[] = {
{SCULPT_TOOL_PAINT, "PAINT", ICON_BRUSH_SCULPT_DRAW, "Paint", ""},
{SCULPT_TOOL_SMEAR, "SMEAR", ICON_BRUSH_SCULPT_DRAW, "Smear", ""},
{SCULPT_TOOL_DRAW_FACE_SETS, "DRAW_FACE_SETS", ICON_BRUSH_MASK, "Draw Face Sets", ""},
+ {SCULPT_TOOL_DISPLACEMENT_HEAL, "DISPLACEMENT_HEAL", ICON_BRUSH_MASK, "Multires Heal", ""},
{0, NULL, 0, NULL, NULL},
};
/* clang-format on */