[Bf-blender-cvs] [f2f30db98da] master: Cleanup: Move Mesh Filter, Smooth and Automasking to their own files

Pablo Dobarro noreply at git.blender.org
Fri Apr 3 21:06:15 CEST 2020


Commit: f2f30db98dacf2821fce3389952798c597bffe11
Author: Pablo Dobarro
Date:   Fri Apr 3 21:05:20 2020 +0200
Branches: master
https://developer.blender.org/rBf2f30db98dacf2821fce3389952798c597bffe11

Cleanup: Move Mesh Filter, Smooth and Automasking to their own files

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

M	source/blender/editors/sculpt_paint/CMakeLists.txt
M	source/blender/editors/sculpt_paint/sculpt.c
A	source/blender/editors/sculpt_paint/sculpt_automasking.c
A	source/blender/editors/sculpt_paint/sculpt_filter_mesh.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h
A	source/blender/editors/sculpt_paint/sculpt_smooth.c

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

diff --git a/source/blender/editors/sculpt_paint/CMakeLists.txt b/source/blender/editors/sculpt_paint/CMakeLists.txt
index f793a775e05..81dafd5ded4 100644
--- a/source/blender/editors/sculpt_paint/CMakeLists.txt
+++ b/source/blender/editors/sculpt_paint/CMakeLists.txt
@@ -59,10 +59,13 @@ set(SRC
   paint_vertex_weight_ops.c
   paint_vertex_weight_utils.c
   sculpt.c
+  sculpt_automasking.c
   sculpt_cloth.c
   sculpt_face_set.c
+  sculpt_filter_mesh.c
   sculpt_multiplane_scrape.c
   sculpt_pose.c
+  sculpt_smooth.c
   sculpt_transform.c
   sculpt_undo.c
   sculpt_uv.c
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index da1174c3a0d..a53c9aed36d 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -674,7 +674,7 @@ void SCULPT_vertex_neighbors_get(SculptSession *ss,
   }
 }
 
-static bool sculpt_vertex_is_boundary(SculptSession *ss, const int index)
+bool SCULPT_vertex_is_boundary(SculptSession *ss, const int index)
 {
   switch (BKE_pbvh_type(ss->pbvh)) {
     case PBVH_FACES: {
@@ -824,10 +824,10 @@ bool SCULPT_is_symmetry_iteration_valid(char i, char symm)
 }
 
 /* Checks if a vertex is inside the brush radius from any of its mirrored axis. */
-static bool sculpt_is_vertex_inside_brush_radius_symm(const float vertex[3],
-                                                      const float br_co[3],
-                                                      float radius,
-                                                      char symm)
+bool SCULPT_is_vertex_inside_brush_radius_symm(const float vertex[3],
+                                               const float br_co[3],
+                                               float radius,
+                                               char symm)
 {
   for (char i = 0; i <= symm; ++i) {
     if (SCULPT_is_symmetry_iteration_valid(i, symm)) {
@@ -854,7 +854,7 @@ void SCULPT_floodfill_init(SculptSession *ss, SculptFloodFill *flood)
   flood->visited_vertices = MEM_callocN(vertex_count * sizeof(char), "visited vertices");
 }
 
-void sculpt_floodfill_add_initial(SculptFloodFill *flood, int index)
+void SCULPT_floodfill_add_initial(SculptFloodFill *flood, int index)
 {
   BLI_gsqueue_push(flood->queue, &index);
 }
@@ -877,7 +877,7 @@ void SCULPT_floodfill_add_initial_with_symmetry(
         v = SCULPT_nearest_vertex_get(sd, ob, location, radius_squared, false);
       }
       if (v != -1) {
-        sculpt_floodfill_add_initial(flood, v);
+        SCULPT_floodfill_add_initial(flood, v);
       }
     }
   }
@@ -901,7 +901,7 @@ void SCULPT_floodfill_add_active(
         v = SCULPT_nearest_vertex_get(sd, ob, location, radius_squared, false);
       }
       if (v != -1) {
-        sculpt_floodfill_add_initial(flood, v);
+        SCULPT_floodfill_add_initial(flood, v);
       }
     }
   }
@@ -1196,7 +1196,7 @@ static void sculpt_project_v3(const SculptProjectVector *spvc, const float vec[3
  * Factors: some brushes like grab cannot do dynamic topology.
  * Others, like smooth, are better without. Same goes for alt-
  * key smoothing. */
-static bool sculpt_stroke_is_dynamic_topology(const SculptSession *ss, const Brush *brush)
+bool SCULPT_stroke_is_dynamic_topology(const SculptSession *ss, const Brush *brush)
 {
   return ((BKE_pbvh_type(ss->pbvh) == PBVH_BMESH) &&
 
@@ -1585,254 +1585,6 @@ static bool sculpt_brush_test_cyl(SculptBrushTest *test,
 
 #endif
 
-/* Automasking */
-
-static bool sculpt_is_automasking_mode_enabled(const Sculpt *sd,
-                                               const Brush *br,
-                                               const eAutomasking_flag mode)
-{
-  return br->automasking_flags & mode || sd->automasking_flags & mode;
-}
-
-static bool sculpt_automasking_enabled(const Sculpt *sd, const SculptSession *ss, const Brush *br)
-{
-  if (sculpt_stroke_is_dynamic_topology(ss, br)) {
-    return false;
-  }
-  if (sculpt_is_automasking_mode_enabled(sd, br, BRUSH_AUTOMASKING_TOPOLOGY)) {
-    return true;
-  }
-  if (sculpt_is_automasking_mode_enabled(sd, br, BRUSH_AUTOMASKING_FACE_SETS)) {
-    return true;
-  }
-  if (sculpt_is_automasking_mode_enabled(sd, br, BRUSH_AUTOMASKING_BOUNDARY_EDGES)) {
-    return true;
-  }
-  if (sculpt_is_automasking_mode_enabled(sd, br, BRUSH_AUTOMASKING_BOUNDARY_FACE_SETS)) {
-    return true;
-  }
-  return false;
-}
-
-float SCULPT_automasking_factor_get(SculptSession *ss, int vert)
-{
-  if (ss->cache->automask) {
-    return ss->cache->automask[vert];
-  }
-  else {
-    return 1.0f;
-  }
-}
-
-static void sculpt_automasking_end(Object *ob)
-{
-  SculptSession *ss = ob->sculpt;
-  if (ss->cache && ss->cache->automask) {
-    MEM_freeN(ss->cache->automask);
-  }
-}
-
-static bool sculpt_automasking_is_constrained_by_radius(Brush *br)
-{
-  /* 2D falloff is not constrained by radius. */
-  if (br->falloff_shape == PAINT_FALLOFF_SHAPE_TUBE) {
-    return false;
-  }
-
-  if (ELEM(br->sculpt_tool, SCULPT_TOOL_GRAB, SCULPT_TOOL_THUMB, SCULPT_TOOL_ROTATE)) {
-    return true;
-  }
-  return false;
-}
-
-typedef struct AutomaskFloodFillData {
-  float *automask_factor;
-  float radius;
-  bool use_radius;
-  float location[3];
-  char symm;
-} AutomaskFloodFillData;
-
-static bool automask_floodfill_cb(
-    SculptSession *ss, int UNUSED(from_v), int to_v, bool UNUSED(is_duplicate), void *userdata)
-{
-  AutomaskFloodFillData *data = userdata;
-
-  data->automask_factor[to_v] = 1.0f;
-  return (!data->use_radius ||
-          sculpt_is_vertex_inside_brush_radius_symm(
-              SCULPT_vertex_co_get(ss, to_v), data->location, data->radius, data->symm));
-}
-
-static float *sculpt_topology_automasking_init(Sculpt *sd, Object *ob, float *automask_factor)
-{
-  SculptSession *ss = ob->sculpt;
-  Brush *brush = BKE_paint_brush(&sd->paint);
-
-  if (!sculpt_automasking_enabled(sd, ss, brush)) {
-    return NULL;
-  }
-
-  if (BKE_pbvh_type(ss->pbvh) == PBVH_FACES && !ss->pmap) {
-    BLI_assert(!"Topology masking: pmap missing");
-    return NULL;
-  }
-
-  const int totvert = SCULPT_vertex_count_get(ss);
-  for (int i = 0; i < totvert; i++) {
-    ss->cache->automask[i] = 0.0f;
-  }
-
-  /* Flood fill automask to connected vertices. Limited to vertices inside
-   * the brush radius if the tool requires it. */
-  SculptFloodFill flood;
-  SCULPT_floodfill_init(ss, &flood);
-  SCULPT_floodfill_add_active(sd, ob, ss, &flood, ss->cache->radius);
-
-  AutomaskFloodFillData fdata = {
-      .automask_factor = automask_factor,
-      .radius = ss->cache->radius,
-      .use_radius = sculpt_automasking_is_constrained_by_radius(brush),
-      .symm = sd->paint.symmetry_flags & PAINT_SYMM_AXIS_ALL,
-  };
-  copy_v3_v3(fdata.location, SCULPT_active_vertex_co_get(ss));
-  SCULPT_floodfill_execute(ss, &flood, automask_floodfill_cb, &fdata);
-  SCULPT_floodfill_free(&flood);
-
-  return automask_factor;
-}
-
-static float *sculpt_face_sets_automasking_init(Sculpt *sd, Object *ob, float *automask_factor)
-{
-  SculptSession *ss = ob->sculpt;
-  Brush *brush = BKE_paint_brush(&sd->paint);
-
-  if (!sculpt_automasking_enabled(sd, ss, brush)) {
-    return NULL;
-  }
-
-  if (BKE_pbvh_type(ss->pbvh) == PBVH_FACES && !ss->pmap) {
-    BLI_assert(!"Face Sets automasking: pmap missing");
-    return NULL;
-  }
-
-  int tot_vert = SCULPT_vertex_count_get(ss);
-  int active_face_set = SCULPT_vertex_face_set_get(ss, SCULPT_active_vertex_get(ss));
-  for (int i = 0; i < tot_vert; i++) {
-    if (!SCULPT_vertex_has_face_set(ss, i, active_face_set)) {
-      automask_factor[i] *= 0.0f;
-    }
-  }
-
-  return automask_factor;
-}
-
-#define EDGE_DISTANCE_INF -1
-
-typedef enum eBoundaryAutomaskMode {
-  AUTOMASK_INIT_BOUNDARY_EDGES = 1,
-  AUTOMASK_INIT_BOUNDARY_FACE_SETS = 2,
-} eBoundaryAutomaskMode;
-
-static float *sculpt_boundary_automasking_init(Object *ob,
-                                               eBoundaryAutomaskMode mode,
-                                               int propagation_steps,
-                                               float *automask_factor)
-{
-  SculptSession *ss = ob->sculpt;
-
-  if (BKE_pbvh_type(ss->pbvh) == PBVH_FACES && !ss->pmap) {
-    BLI_assert(!"Boundary Edges masking: pmap missing");
-    return NULL;
-  }
-
-  const int totvert = SCULPT_vertex_count_get(ss);
-  int *edge_distance = MEM_callocN(sizeof(int) * totvert, "automask_factor");
-
-  for (int i = 0; i < totvert; i++) {
-    edge_distance[i] = EDGE_DISTANCE_INF;
-    switch (mode) {
-      case AUTOMASK_INIT_BOUNDARY_EDGES:
-        if (!sculpt_vertex_is_boundary(ss, i)) {
-          edge_distance[i] = 0;
-        }
-        break;
-      case AUTOMASK_INIT_BOUNDARY_FACE_SETS:
-        if (!SCULPT_vertex_has_unique_face_set(ss, i)) {
-          edge_distance[i] = 0;
-        }
-        break;
-    }
-  }
-
-  for (int propagation_it = 0; propagation_it < propagation_steps; propagation_it++) {
-    for (int i = 0; i < totvert; i++) {
-      if (edge_distance[i] == EDGE_DISTANCE_INF) {
-        SculptVertexNeighborIter ni;
-        SCULPT_VERTEX_NEIGHBORS_ITER_BEGIN (ss, i, ni) {
-          if (edge_distance[ni.index] == propagation_it) {
-            edge_distance[i] = propagation_it + 1;
-          }
-        }
-        SCULPT_VERTEX_NEIGHBORS_ITER_END(ni);
-      }
-    }
-  }
-
-  for (int i = 0; i < totvert; i++) {
-    if (edge_distance[i] != EDGE_DISTANCE_INF) {
-      const float p = 1.0f - ((float)edge_distance[i] / (float)propagation_steps);
-      const float edge_boundary_automask = pow2f(p);
-      automask_factor[i] *= (1.0f - edge_boundary_automask);
-    }
-  }
-
-  MEM_SAFE_FREE(edge_distance);
-  return automask_factor;
-}
-
-static void sculpt_automasking_init(Sculpt *sd, Object *ob)
-{
-  SculptSession *ss = ob->sculpt;
-  Brush *brush = BKE_paint_brush(&sd->paint);
-  const int totvert = SCULPT_vertex_count_get(ss);
-
-  if (!sculpt_automasking_enabled(sd, ss, brush)) {
-    return;
-  }
-
-  ss->cache->automask = MEM_callocN(sizeof(float) * SCULPT_vertex_count_get(ss),
-                                    "automask_factor");
-
-  for (int i = 0; i < totvert; i++) {
-    ss->cache->automask[i] = 1.0f;
-  }
-
-  if (sculpt_is_automaskin

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list