[Bf-blender-cvs] [142aba9485c] sculpt-dev: Sculpt: Grab brush surface falloff

Pablo Dobarro noreply at git.blender.org
Wed Jan 13 23:00:30 CET 2021


Commit: 142aba9485c9d3dd7dbc3dc7e5f43e2deb67960e
Author: Pablo Dobarro
Date:   Wed Jan 13 20:27:51 2021 +0100
Branches: sculpt-dev
https://developer.blender.org/rB142aba9485c9d3dd7dbc3dc7e5f43e2deb67960e

Sculpt: Grab brush surface falloff

===================================================================

M	release/scripts/startup/bl_ui/properties_paint_common.py
M	source/blender/blenkernel/BKE_paint.h
M	source/blender/blenkernel/intern/paint.c
M	source/blender/editors/sculpt_paint/paint_cursor.c
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h
M	source/blender/makesdna/DNA_brush_enums.h
M	source/blender/makesrna/intern/rna_brush.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/properties_paint_common.py b/release/scripts/startup/bl_ui/properties_paint_common.py
index 6b93b00c4fd..a34798494d9 100644
--- a/release/scripts/startup/bl_ui/properties_paint_common.py
+++ b/release/scripts/startup/bl_ui/properties_paint_common.py
@@ -703,6 +703,7 @@ def brush_settings(layout, context, brush, popover=False):
         elif sculpt_tool == 'GRAB':
             layout.prop(brush, "use_grab_active_vertex")
             layout.prop(brush, "use_grab_silhouette")
+            layout.prop(brush, "use_surface_falloff")
 
         elif sculpt_tool == 'PAINT':
             row = layout.row(align=True)
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index 5b074919d59..bf478e44f97 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -474,6 +474,12 @@ typedef struct SculptSession {
   struct MeshElemMap *pmap;
   int *pmap_mem;
 
+  struct MeshElemMap *epmap;
+  int *epmap_mem;
+
+  struct MeshElemMap *vemap;
+  int *vemap_mem;
+
   /* Mesh Face Sets */
   /* Total number of polys of the base mesh. */
   int totfaces;
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 4eecf3a3a87..5e4535ded56 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -1416,6 +1416,12 @@ static void sculptsession_free_pbvh(Object *object)
   MEM_SAFE_FREE(ss->pmap);
   MEM_SAFE_FREE(ss->pmap_mem);
 
+  MEM_SAFE_FREE(ss->epmap);
+  MEM_SAFE_FREE(ss->epmap_mem);
+
+  MEM_SAFE_FREE(ss->vemap);
+  MEM_SAFE_FREE(ss->vemap_mem);
+
   MEM_SAFE_FREE(ss->persistent_base);
 
   MEM_SAFE_FREE(ss->preview_vert_index_list);
@@ -1465,6 +1471,10 @@ void BKE_sculptsession_free(Object *ob)
 
     MEM_SAFE_FREE(ss->pmap);
     MEM_SAFE_FREE(ss->pmap_mem);
+    MEM_SAFE_FREE(ss->epmap);
+    MEM_SAFE_FREE(ss->epmap_mem);
+    MEM_SAFE_FREE(ss->vemap);
+    MEM_SAFE_FREE(ss->vemap_mem);
     if (ss->bm_log) {
       BM_log_free(ss->bm_log);
     }
diff --git a/source/blender/editors/sculpt_paint/paint_cursor.c b/source/blender/editors/sculpt_paint/paint_cursor.c
index 550913fc8af..75699ed572a 100644
--- a/source/blender/editors/sculpt_paint/paint_cursor.c
+++ b/source/blender/editors/sculpt_paint/paint_cursor.c
@@ -1367,7 +1367,7 @@ static void paint_cursor_sculpt_session_update_and_init(PaintCursorContext *pcon
   pcontext->prev_active_vertex_index = ss->active_vertex_index;
   if (!ups->stroke_active) {
     pcontext->is_cursor_over_mesh = SCULPT_cursor_geometry_info_update(
-        C, &gi, mouse, (pcontext->brush->falloff_shape == PAINT_FALLOFF_SHAPE_SPHERE));
+        C, &gi, mouse, pcontext->brush->falloff_shape == PAINT_FALLOFF_SHAPE_SPHERE);
     copy_v3_v3(pcontext->location, gi.location);
     copy_v3_v3(pcontext->normal, gi.normal);
   }
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index f29e0826af8..fb1efd10e1f 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -29,6 +29,7 @@
 #include "BLI_ghash.h"
 #include "BLI_gsqueue.h"
 #include "BLI_hash.h"
+#include "BLI_linklist_stack.h"
 #include "BLI_math.h"
 #include "BLI_math_color_blend.h"
 #include "BLI_task.h"
@@ -3574,93 +3575,107 @@ static void sculpt_stroke_cache_snap_context_init(bContext *C, Object *ob)
   cache->depsgraph = depsgraph;
 }
 
-
-static void sculpt_scene_project_view_ray_init(Object *ob, const int vertex_index, float r_ray_normal[3], float r_ray_origin[3]) {
-    SculptSession *ss = ob->sculpt;
-    float world_space_vertex_co[3];
-    mul_v3_m4v3(world_space_vertex_co, ob->obmat, SCULPT_vertex_co_get(ss, vertex_index));
-    sub_v3_v3v3(r_ray_normal, world_space_vertex_co, ss->cache->view_origin);
-    normalize_v3(r_ray_normal);
-    copy_v3_v3(r_ray_origin, ss->cache->view_origin);
+static void sculpt_scene_project_view_ray_init(Object *ob,
+                                               const int vertex_index,
+                                               float r_ray_normal[3],
+                                               float r_ray_origin[3])
+{
+  SculptSession *ss = ob->sculpt;
+  float world_space_vertex_co[3];
+  mul_v3_m4v3(world_space_vertex_co, ob->obmat, SCULPT_vertex_co_get(ss, vertex_index));
+  sub_v3_v3v3(r_ray_normal, world_space_vertex_co, ss->cache->view_origin);
+  normalize_v3(r_ray_normal);
+  copy_v3_v3(r_ray_origin, ss->cache->view_origin);
 }
 
-static void sculpt_scene_project_vertex_normal_ray_init(Object *ob, const int vertex_index, float r_ray_normal[3], float r_ray_origin[3]) {
-    SculptSession *ss = ob->sculpt;
-    float vertex_normal[3];
-    SCULPT_vertex_normal_get(ss, vertex_index, vertex_normal);
-    mul_v3_m4v3(r_ray_normal, ob->obmat, vertex_normal);
-    normalize_v3(r_ray_normal);
+static void sculpt_scene_project_vertex_normal_ray_init(Object *ob,
+                                                        const int vertex_index,
+                                                        float r_ray_normal[3],
+                                                        float r_ray_origin[3])
+{
+  SculptSession *ss = ob->sculpt;
+  float vertex_normal[3];
+  SCULPT_vertex_normal_get(ss, vertex_index, vertex_normal);
+  mul_v3_m4v3(r_ray_normal, ob->obmat, vertex_normal);
+  normalize_v3(r_ray_normal);
 
-    mul_v3_m4v3(r_ray_origin, ob->obmat, SCULPT_vertex_co_get(ss, vertex_index));
+  mul_v3_m4v3(r_ray_origin, ob->obmat, SCULPT_vertex_co_get(ss, vertex_index));
 }
 
-static void sculpt_scene_project_brush_normal_ray_init(Object *ob, const int vertex_index, float r_ray_normal[3], float r_ray_origin[3]) {
-    SculptSession *ss = ob->sculpt;
-    mul_v3_m4v3(r_ray_origin, ob->obmat, SCULPT_vertex_co_get(ss, vertex_index));
-    mul_v3_m4v3(r_ray_normal, ob->obmat, ss->cache->sculpt_normal);
-    normalize_v3(r_ray_normal);
-}
-
-static bool sculpt_scene_project_raycast(SculptSession *ss, const float ray_normal[3], const float ray_origin[3], const bool use_both_directions, float r_loc[3]) {
-   float hit_co[2][3];
-   float hit_len_squared[2];
-   bool any_hit = false;
-   bool hit = false;
-   hit = ED_transform_snap_object_project_ray(ss->cache->snap_context,
-                                                          ss->cache->depsgraph,
-                                                          &(const struct SnapObjectParams){
-                                                              .snap_select = SNAP_NOT_ACTIVE,
-                                                              .use_object_edit_cage = true,
-                                                          },
-                                                          ray_origin,
-                                                          ray_normal,
-                                                          NULL,
-                                                          hit_co[0],
-                                                          NULL);
-   if (hit) {
-      hit_len_squared[0] = len_squared_v3v3(hit_co[0], ray_origin);
-      any_hit |= hit;
-   }
-   else {
-      hit_len_squared[0] = FLT_MAX;
-   }
-
-
-   if (!use_both_directions) {
-       copy_v3_v3(r_loc, hit_co[0]);
-       return any_hit;
-   }
-
-   float ray_normal_flip[3];
-   mul_v3_v3fl(ray_normal_flip, ray_normal, -1.0f);
-
-   hit = ED_transform_snap_object_project_ray(ss->cache->snap_context,
-                                                          ss->cache->depsgraph,
-                                                          &(const struct SnapObjectParams){
-                                                              .snap_select = SNAP_NOT_ACTIVE,
-                                                              .use_object_edit_cage = true,
-                                                          },
-                                                          ray_origin,
-                                                          ray_normal_flip,
-                                                          NULL,
-                                                          hit_co[1],
-                                                          NULL);
-   if (hit) {
-      hit_len_squared[1] = len_squared_v3v3(hit_co[1], ray_origin);
-      any_hit |= hit;
-   }
-   else {
-      hit_len_squared[1] = FLT_MAX;
-   }
-
-   if (hit_len_squared[0] <= hit_len_squared[1]) {
-       copy_v3_v3(r_loc, hit_co[0]);
-   }
-   else {
-       copy_v3_v3(r_loc, hit_co[1]);
-   }
-   return any_hit;
+static void sculpt_scene_project_brush_normal_ray_init(Object *ob,
+                                                       const int vertex_index,
+                                                       float r_ray_normal[3],
+                                                       float r_ray_origin[3])
+{
+  SculptSession *ss = ob->sculpt;
+  mul_v3_m4v3(r_ray_origin, ob->obmat, SCULPT_vertex_co_get(ss, vertex_index));
+  mul_v3_m4v3(r_ray_normal, ob->obmat, ss->cache->sculpt_normal);
+  normalize_v3(r_ray_normal);
+}
+
+static bool sculpt_scene_project_raycast(SculptSession *ss,
+                                         const float ray_normal[3],
+                                         const float ray_origin[3],
+                                         const bool use_both_directions,
+                                         float r_loc[3])
+{
+  float hit_co[2][3];
+  float hit_len_squared[2];
+  bool any_hit = false;
+  bool hit = false;
+  hit = ED_transform_snap_object_project_ray(ss->cache->snap_context,
+                                             ss->cache->depsgraph,
+                                             &(const struct SnapObjectParams){
+                                                 .snap_select = SNAP_NOT_ACTIVE,
+                                                 .use_object_edit_cage = true,
+                                             },
+                                             ray_origin,
+                                             ray_normal,
+                                             NULL,
+                                             hit_co[0],
+   

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list