[Bf-blender-cvs] [9aea7dc7c65] blender-v2.83-release: Fix Pose Brush origin position with large brush size

Pablo Dobarro noreply at git.blender.org
Tue May 26 20:45:55 CEST 2020


Commit: 9aea7dc7c65b94aff0dda299c7269a252bf04b05
Author: Pablo Dobarro
Date:   Wed May 20 01:41:47 2020 +0200
Branches: blender-v2.83-release
https://developer.blender.org/rB9aea7dc7c65b94aff0dda299c7269a252bf04b05

Fix Pose Brush origin position with large brush size

When the brush size is bigger than the entire mesh, fdata.tot_co can be
0, so the pose origin will default to (0,0,0), which does not make much
sense. After this patch, the pose origin will be set to the farthest
vertex from the pose origin, which at least should be in the surface of
the mesh and in most cases in the direction the pose brush was already
detecting the origin.

Reviewed By: sergey

Differential Revision: https://developer.blender.org/D7773

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

M	source/blender/editors/sculpt_paint/sculpt_pose.c

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

diff --git a/source/blender/editors/sculpt_paint/sculpt_pose.c b/source/blender/editors/sculpt_paint/sculpt_pose.c
index fde4a9d1d23..8ef059183e3 100644
--- a/source/blender/editors/sculpt_paint/sculpt_pose.c
+++ b/source/blender/editors/sculpt_paint/sculpt_pose.c
@@ -367,6 +367,10 @@ typedef struct PoseFloodFillData {
 
   bool is_first_iteration;
 
+  /* In topology mode this stores the furthest point from the stroke origin for cases when a pose
+   * origin based on the brush radius can't be set. */
+  float fallback_floodfill_origin[3];
+
   /* Fallback origin. If we can't find any face set to continue, use the position of all vertices
    * that have the current face set. */
   float fallback_origin[3];
@@ -377,12 +381,17 @@ static bool pose_topology_floodfill_cb(
     SculptSession *ss, int UNUSED(from_v), int to_v, bool is_duplicate, void *userdata)
 {
   PoseFloodFillData *data = userdata;
+  const float *co = SCULPT_vertex_co_get(ss, to_v);
 
   if (data->pose_factor) {
     data->pose_factor[to_v] = 1.0f;
   }
 
-  const float *co = SCULPT_vertex_co_get(ss, to_v);
+  if (len_squared_v3v3(data->pose_initial_co, data->fallback_floodfill_origin) <
+      len_squared_v3v3(data->pose_initial_co, co)) {
+    copy_v3_v3(data->fallback_floodfill_origin, co);
+  }
+
   if (sculpt_pose_brush_is_vertex_inside_brush_radius(
           co, data->pose_initial_co, data->radius, data->symm)) {
     return true;
@@ -521,12 +530,16 @@ void SCULPT_pose_calc_pose_data(Sculpt *sd,
   };
   zero_v3(fdata.pose_origin);
   copy_v3_v3(fdata.pose_initial_co, initial_location);
+  copy_v3_v3(fdata.fallback_floodfill_origin, initial_location);
   SCULPT_floodfill_execute(ss, &flood, pose_topology_floodfill_cb, &fdata);
   SCULPT_floodfill_free(&flood);
 
   if (fdata.tot_co > 0) {
     mul_v3_fl(fdata.pose_origin, 1.0f / (float)fdata.tot_co);
   }
+  else {
+    copy_v3_v3(fdata.pose_origin, fdata.fallback_floodfill_origin);
+  }
 
   /* Offset the pose origin. */
   float pose_d[3];



More information about the Bf-blender-cvs mailing list