[Bf-blender-cvs] [81ac9f61b61] sculpt-dev: Implement boundary expand

Pablo Dobarro noreply at git.blender.org
Thu Jan 14 01:40:45 CET 2021


Commit: 81ac9f61b61947e0ad0d7136e1b1f58a35832c74
Author: Pablo Dobarro
Date:   Thu Jan 14 01:40:32 2021 +0100
Branches: sculpt-dev
https://developer.blender.org/rB81ac9f61b61947e0ad0d7136e1b1f58a35832c74

Implement boundary expand

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

M	source/blender/editors/sculpt_paint/sculpt_boundary.c
M	source/blender/editors/sculpt_paint/sculpt_expand.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h

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

diff --git a/source/blender/editors/sculpt_paint/sculpt_boundary.c b/source/blender/editors/sculpt_paint/sculpt_boundary.c
index 5dcaf7d9468..e8a2c0c3340 100644
--- a/source/blender/editors/sculpt_paint/sculpt_boundary.c
+++ b/source/blender/editors/sculpt_paint/sculpt_boundary.c
@@ -517,11 +517,12 @@ SculptBoundary *SCULPT_boundary_data_init(Object *object,
 
   SculptBoundary *boundary = MEM_callocN(sizeof(SculptBoundary), "Boundary edit data");
 
-  const bool init_boundary_distances = brush->boundary_falloff_type !=
-                                       BRUSH_BOUNDARY_FALLOFF_CONSTANT;
+  const bool init_boundary_distances = brush ? brush->boundary_falloff_type !=
+                                                   BRUSH_BOUNDARY_FALLOFF_CONSTANT :
+                                               false;
   sculpt_boundary_indices_init(ss, boundary, init_boundary_distances, boundary_initial_vertex);
 
-  const float boundary_radius = radius * (1.0f + brush->boundary_offset);
+  const float boundary_radius = brush ? radius * (1.0f + brush->boundary_offset) : radius;
   sculpt_boundary_edit_data_init(ss, boundary, boundary_initial_vertex, boundary_radius);
 
   return boundary;
diff --git a/source/blender/editors/sculpt_paint/sculpt_expand.c b/source/blender/editors/sculpt_paint/sculpt_expand.c
index 465ed91bf1f..73458d4590e 100644
--- a/source/blender/editors/sculpt_paint/sculpt_expand.c
+++ b/source/blender/editors/sculpt_paint/sculpt_expand.c
@@ -68,6 +68,7 @@
 #include <math.h>
 #include <stdlib.h>
 
+#define SCULPT_EXPAND_VERTEX_NONE -1
 
 static EnumPropertyItem prop_sculpt_expand_faloff_type_items[] = {
     {SCULPT_EXPAND_FALLOFF_GEODESICS, "GEODESICS", 0, "Surface", ""},
@@ -78,8 +79,9 @@ static EnumPropertyItem prop_sculpt_expand_faloff_type_items[] = {
     {0, NULL, 0, NULL, NULL},
 };
 
-static float *sculpt_expand_geodesic_falloff_create(Sculpt *sd, Object *ob, const int vertex) {
-    return SCULPT_geodesic_from_vertex_and_symm(sd, ob, vertex, FLT_MAX);
+static float *sculpt_expand_geodesic_falloff_create(Sculpt *sd, Object *ob, const int vertex)
+{
+  return SCULPT_geodesic_from_vertex_and_symm(sd, ob, vertex, FLT_MAX);
 }
 
 typedef struct ExpandFloodFillData {
@@ -103,10 +105,11 @@ static bool mask_expand_topology_floodfill_cb(
   return true;
 }
 
-static float *sculpt_expand_topology_falloff_create(Sculpt *sd, Object *ob, const int vertex) {
+static float *sculpt_expand_topology_falloff_create(Sculpt *sd, Object *ob, const int vertex)
+{
   SculptSession *ss = ob->sculpt;
   const int totvert = SCULPT_vertex_count_get(ss);
-  float *dists = MEM_malloc_arrayN(sizeof (float), totvert, "spherical dist");
+  float *dists = MEM_malloc_arrayN(sizeof(float), totvert, "spherical dist");
 
   SculptFloodFill flood;
   SCULPT_floodfill_init(ss, &flood);
@@ -121,20 +124,19 @@ static float *sculpt_expand_topology_falloff_create(Sculpt *sd, Object *ob, cons
   return dists;
 }
 
-static bool mask_expand_normals_floodfill_cb(
+static bool mask_expand_normal_floodfill_cb(
     SculptSession *ss, int from_v, int to_v, bool is_duplicate, void *userdata)
 {
   ExpandFloodFillData *data = userdata;
   if (!is_duplicate) {
-      float current_normal[3], prev_normal[3];
-      SCULPT_vertex_normal_get(ss, to_v, current_normal);
-      SCULPT_vertex_normal_get(ss, from_v, prev_normal);
-      const float from_edge_factor = data->edge_factor[from_v];
-      data->edge_factor[to_v] = dot_v3v3(current_normal, prev_normal) *
-                                            from_edge_factor;
-      data->dists[to_v] = dot_v3v3(data->original_normal, current_normal) *
-                                              powf(from_edge_factor, data->edge_sensitivity);
-      CLAMP(data->dists[to_v], 0.0f, 1.0f);
+    float current_normal[3], prev_normal[3];
+    SCULPT_vertex_normal_get(ss, to_v, current_normal);
+    SCULPT_vertex_normal_get(ss, from_v, prev_normal);
+    const float from_edge_factor = data->edge_factor[from_v];
+    data->edge_factor[to_v] = dot_v3v3(current_normal, prev_normal) * from_edge_factor;
+    data->dists[to_v] = dot_v3v3(data->original_normal, current_normal) *
+                        powf(from_edge_factor, data->edge_sensitivity);
+    CLAMP(data->dists[to_v], 0.0f, 1.0f);
   }
   else {
     /* PBVH_GRIDS duplicate handling. */
@@ -145,15 +147,18 @@ static bool mask_expand_normals_floodfill_cb(
   return true;
 }
 
-static float *sculpt_expand_normal_falloff_create(Sculpt *sd, Object *ob, const int vertex, const float edge_sensitivity) {
+static float *sculpt_expand_normal_falloff_create(Sculpt *sd,
+                                                  Object *ob,
+                                                  const int vertex,
+                                                  const float edge_sensitivity)
+{
   SculptSession *ss = ob->sculpt;
   const int totvert = SCULPT_vertex_count_get(ss);
-  float *dists = MEM_malloc_arrayN(sizeof (float), totvert, "normal dist");
-   float *edge_factor = MEM_callocN(sizeof(float) * totvert,
-                                                "mask edge factor");
-    for (int i = 0; i < totvert; i++) {
-      edge_factor[i] = 1.0f;
-    }
+  float *dists = MEM_malloc_arrayN(sizeof(float), totvert, "normal dist");
+  float *edge_factor = MEM_callocN(sizeof(float) * totvert, "mask edge factor");
+  for (int i = 0; i < totvert; i++) {
+    edge_factor[i] = 1.0f;
+  }
 
   SculptFloodFill flood;
   SCULPT_floodfill_init(ss, &flood);
@@ -165,53 +170,54 @@ static float *sculpt_expand_normal_falloff_create(Sculpt *sd, Object *ob, const
   fdata.edge_sensitivity = edge_sensitivity;
   SCULPT_vertex_normal_get(ss, vertex, fdata.original_normal);
 
-  SCULPT_floodfill_execute(ss, &flood, mask_expand_topology_floodfill_cb, &fdata);
+  SCULPT_floodfill_execute(ss, &flood, mask_expand_normal_floodfill_cb, &fdata);
   SCULPT_floodfill_free(&flood);
 
-    for (int repeat = 0; repeat < 2; repeat++) {
-      for (int i = 0; i < totvert; i++) {
-        float avg = 0.0f;
-        SculptVertexNeighborIter ni;
-        SCULPT_VERTEX_NEIGHBORS_ITER_BEGIN (ss, i, ni) {
-          avg += dists[ni.index];
-        }
-        SCULPT_VERTEX_NEIGHBORS_ITER_END(ni);
-        dists[i] = avg / ni.size;
+  for (int repeat = 0; repeat < 2; repeat++) {
+    for (int i = 0; i < totvert; i++) {
+      float avg = 0.0f;
+      SculptVertexNeighborIter ni;
+      SCULPT_VERTEX_NEIGHBORS_ITER_BEGIN (ss, i, ni) {
+        avg += dists[ni.index];
       }
+      SCULPT_VERTEX_NEIGHBORS_ITER_END(ni);
+      dists[i] = avg / ni.size;
     }
+  }
 
-    MEM_SAFE_FREE(edge_factor);
+  MEM_SAFE_FREE(edge_factor);
 
   return dists;
 }
 
-
-static float *sculpt_expand_spherical_falloff_create(Sculpt *sd, Object *ob, const int vertex) {
+static float *sculpt_expand_spherical_falloff_create(Sculpt *sd, Object *ob, const int vertex)
+{
   SculptSession *ss = ob->sculpt;
   const int totvert = SCULPT_vertex_count_get(ss);
 
-  float *dists = MEM_malloc_arrayN(sizeof (float), totvert, "spherical dist");
+  float *dists = MEM_malloc_arrayN(sizeof(float), totvert, "spherical dist");
   for (int i = 0; i < totvert; i++) {
-     dists[i] = FLT_MAX;
+    dists[i] = FLT_MAX;
   }
   const char symm = SCULPT_mesh_symmetry_xyz_get(ob);
 
   for (char symm_it = 0; symm_it <= symm; symm_it++) {
-    if (SCULPT_is_symmetry_iteration_valid(symm_it, symm)) {
-      int v = -1;
-      if (symm_it == 0) {
-        v = vertex;
-      }
-      else {
-        float location[3];
-        flip_v3_v3(location, SCULPT_vertex_co_get(ss, vertex), symm_it);
-        v = SCULPT_nearest_vertex_get(sd, ob, location, FLT_MAX, false);
-      }
-      if (v != -1) {
-          const float *co = SCULPT_vertex_co_get(ss, v);
-          for (int i = 0; i < totvert; i++) {
-              dists[i] = min_ff(dists[i], len_v3v3(co, SCULPT_vertex_co_get(ss, i)));
-          }
+    if (!SCULPT_is_symmetry_iteration_valid(symm_it, symm)) {
+      continue;
+    }
+    int v = SCULPT_EXPAND_VERTEX_NONE;
+    if (symm_it == 0) {
+      v = vertex;
+    }
+    else {
+      float location[3];
+      flip_v3_v3(location, SCULPT_vertex_co_get(ss, vertex), symm_it);
+      v = SCULPT_nearest_vertex_get(sd, ob, location, FLT_MAX, false);
+    }
+    if (v != -1) {
+      const float *co = SCULPT_vertex_co_get(ss, v);
+      for (int i = 0; i < totvert; i++) {
+        dists[i] = min_ff(dists[i], len_v3v3(co, SCULPT_vertex_co_get(ss, i)));
       }
     }
   }
@@ -219,59 +225,123 @@ static float *sculpt_expand_spherical_falloff_create(Sculpt *sd, Object *ob, con
   return dists;
 }
 
-static void sculpt_expand_update_max_falloff_factor(SculptSession *ss, ExpandCache *expand_cache) {
-    const int totvert = SCULPT_vertex_count_get(ss);
-    expand_cache->max_falloff_factor = -FLT_MAX;
-    for (int i = 0; i < totvert; i++) {
-        expand_cache->max_falloff_factor = max_ff(expand_cache->max_falloff_factor, expand_cache->falloff_factor[i]);
-    }
-}
+static float *sculpt_expand_boundary_topology_falloff_create(Sculpt *sd,
+                                                             Object *ob,
+                                                             const int vertex)
+{
+  SculptSession *ss = ob->sculpt;
+  const int totvert = SCULPT_vertex_count_get(ss);
+  float *dists = MEM_calloc_arrayN(sizeof(float), totvert, "spherical dist");
+  BLI_bitmap *visited_vertices = BLI_BITMAP_NEW(totvert, "visited vertices");
+  GSQueue *queue = BLI_gsqueue_new(sizeof(int));
 
+  const char symm = SCULPT_mesh_symmetry_xyz_get(ob);
+  for (char symm_it = 0; symm_it <= symm; symm_it++) {
+    if (!SCULPT_is_symmetry_iteration_valid(symm_it, symm)) {
+      continue;
+    }
+    int v = SCULPT_EXPAND_VERTEX_NONE;
+    if (symm_it == 0) {
+      v = vertex;
+    }
+    else {
+      float location[3];
+      flip_v3_v3(location, SCULPT_vertex_co_get(ss, vertex), symm_it);
+      v = SCULPT_nearest_vertex_get(sd, ob, location, FLT_MAX, false);
+    }
 
-static void sculpt_expand_falloff_factors_from_vertex_and_symm_create(ExpandCache *expand_cache, Sculpt *sd, Object *ob, const int vertex, eSculptExpandFalloffType falloff_type) {
-    if (expand_cache->falloff_factor && expand_cache->falloff_factor

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list