[Bf-blender-cvs] [acd99f12e72] sculpt-dev: Sculpt Expand: Cleanup, comments

Pablo Dobarro noreply at git.blender.org
Tue Feb 16 20:38:43 CET 2021


Commit: acd99f12e72edd331e40a381cbd8313fef0a3a21
Author: Pablo Dobarro
Date:   Tue Feb 16 20:38:06 2021 +0100
Branches: sculpt-dev
https://developer.blender.org/rBacd99f12e72edd331e40a381cbd8313fef0a3a21

Sculpt Expand: Cleanup, comments

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

M	source/blender/editors/sculpt_paint/sculpt.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.c b/source/blender/editors/sculpt_paint/sculpt.c
index fd90506f103..50d40402d06 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -10471,8 +10471,6 @@ static void SCULPT_OT_mask_init(wmOperatorType *ot)
                "");
 }
 
-
-
 static int sculpt_reset_brushes_exec(bContext *C, wmOperator *op)
 {
   Main *bmain = CTX_data_main(C);
diff --git a/source/blender/editors/sculpt_paint/sculpt_expand.c b/source/blender/editors/sculpt_paint/sculpt_expand.c
index bfcd07e4d84..10e6b17706b 100644
--- a/source/blender/editors/sculpt_paint/sculpt_expand.c
+++ b/source/blender/editors/sculpt_paint/sculpt_expand.c
@@ -75,8 +75,36 @@
 #include <math.h>
 #include <stdlib.h>
 
+/* Sculpt Expand. */
+/* Operator for creating selections and patterns in Scupt Mode. Expand can create masks, face sets
+ * and fill vertex colors. */
+/* The main functinality of the operator
+ * - The operator initializes a value per vertex, called "falloff". There are multiple algorithms
+ * to generate these falloff values which will create different patterns in the result when using
+ * the operator. These falloff values require algorithms that rely on mesh connectivity, so they
+ * are only valid on parts of the mesh that are in the same connected component as the given
+ * initial vertices. If needed, these falloff values are propagated from vertex or grids into the
+ * base mesh faces.
+ * - On each modal callback, the operator gets the active vertex and face and gets its falloff
+ * value from its precalculated falloff. This is now the active falloff value.
+ * - Using the active falloff value and the settings of the expand operation (which can be modified
+ * during execution using the modal keymap), the operator loops over all elements in the mesh to
+ * check if they are enabled of not.
+ * - Based on each element state after evaluating the settings, the desired mesh data (mask, face
+ * sets, colors...) is updated.
+ */
+
+/* Used for defining an invalid vertex state (for example, when the cursor is not over the mesh).
+ */
 #define SCULPT_EXPAND_VERTEX_NONE -1
 
+/* Defines how much each time the texture distortion is increased/decreased when using the modal
+ * keymap. */
+#define SCULPT_EXPAND_TEXTURE_DISTORTION_STEP 0.01f
+
+#define SCULPT_EXPAND_LOOP_THRESHOLD 0.00001f
+
+/* Expand Modal Keymap. */
 enum {
   SCULPT_EXPAND_MODAL_CONFIRM = 1,
   SCULPT_EXPAND_MODAL_CANCEL,
@@ -118,9 +146,10 @@ static EnumPropertyItem prop_sculpt_expand_target_type_items[] = {
     {0, NULL, 0, NULL, NULL},
 };
 
-#define SCULPT_EXPAND_TEXTURE_DISTORTION_STEP 0.01f
-#define SCULPT_EXPAND_LOOP_THRESHOLD 0.00001f
+/* Functions for getting the state of mesh elements (vertices and base mesh faces). */
 
+/* Returns true if the vertex is in a connected component with correctly initialized falloff
+ * values. */
 static bool sculpt_expand_is_vert_in_active_compoment(SculptSession *ss,
                                                       ExpandCache *expand_cache,
                                                       const int v)
@@ -133,6 +162,8 @@ static bool sculpt_expand_is_vert_in_active_compoment(SculptSession *ss,
   return false;
 }
 
+/* Returns true if the face is in a connected component with correctly initialized falloff values.
+ */
 static bool sculpt_expand_is_face_in_active_component(SculptSession *ss,
                                                       ExpandCache *expand_cache,
                                                       const int f)
@@ -141,49 +172,55 @@ static bool sculpt_expand_is_face_in_active_component(SculptSession *ss,
   return sculpt_expand_is_vert_in_active_compoment(ss, expand_cache, loop->v);
 }
 
+/* Returns the falloff value of a vertex. This function includes texture distortion, which is not
+ * precomputed into the initial falloff values. */
 static float sculpt_expand_falloff_value_vertex_get(SculptSession *ss,
                                                     ExpandCache *expand_cache,
-                                                    const int i)
+                                                    const int v)
 {
   if (expand_cache->texture_distortion_strength == 0.0f) {
-    return expand_cache->falloff_factor[i];
+    return expand_cache->falloff[v];
   }
 
   if (!expand_cache->brush->mtex.tex) {
-    return expand_cache->falloff_factor[i];
+    return expand_cache->falloff[v];
   }
 
   float rgba[4];
-  const float *vertex_co = SCULPT_vertex_co_get(ss, i);
+  const float *vertex_co = SCULPT_vertex_co_get(ss, v);
   const float avg = BKE_brush_sample_tex_3d(
       expand_cache->scene, expand_cache->brush, vertex_co, rgba, 0, ss->tex_pool);
 
   const float distortion = (avg - 0.5f) * expand_cache->texture_distortion_strength *
-                           expand_cache->max_falloff_factor;
-  return expand_cache->falloff_factor[i] + distortion;
+                           expand_cache->max_falloff;
+  return expand_cache->falloff[v] + distortion;
 }
 
-static float sculpt_expand_max_vertex_falloff_factor_get(ExpandCache *expand_cache)
+/* Returns the maximum valid falloff value stored in the falloff array, taking the maximum possible
+ * texture distortion into account. */
+static float sculpt_expand_max_vertex_falloff_get(ExpandCache *expand_cache)
 {
   if (expand_cache->texture_distortion_strength == 0.0f) {
-    return expand_cache->max_falloff_factor;
+    return expand_cache->max_falloff;
   }
 
   if (!expand_cache->brush->mtex.tex) {
-    return expand_cache->max_falloff_factor;
+    return expand_cache->max_falloff;
   }
 
-  return expand_cache->max_falloff_factor +
-         (0.5f * expand_cache->texture_distortion_strength * expand_cache->max_falloff_factor);
+  return expand_cache->max_falloff +
+         (0.5f * expand_cache->texture_distortion_strength * expand_cache->max_falloff);
 }
 
-static bool sculpt_expand_state_get(SculptSession *ss, ExpandCache *expand_cache, const int i)
+/* Main function to get the state of a vertex for the current state and settings of a ExpandCache.
+ */
+static bool sculpt_expand_state_get(SculptSession *ss, ExpandCache *expand_cache, const int v)
 {
-  if (!SCULPT_vertex_visible_get(ss, i)) {
+  if (!SCULPT_vertex_visible_get(ss, v)) {
     return false;
   }
 
-  if (!sculpt_expand_is_vert_in_active_compoment(ss, expand_cache, i)) {
+  if (!sculpt_expand_is_vert_in_active_compoment(ss, expand_cache, v)) {
     return false;
   }
 
@@ -194,17 +231,17 @@ static bool sculpt_expand_state_get(SculptSession *ss, ExpandCache *expand_cache
   bool enabled = false;
 
   if (expand_cache->snap) {
-    const int face_set = SCULPT_vertex_face_set_get(ss, i);
+    const int face_set = SCULPT_vertex_face_set_get(ss, v);
     enabled = BLI_gset_haskey(expand_cache->snap_enabled_face_sets, POINTER_FROM_INT(face_set));
   }
   else {
-    const float max_falloff_factor = sculpt_expand_max_vertex_falloff_factor_get(expand_cache);
+    const float max_falloff_factor = sculpt_expand_max_vertex_falloff_get(expand_cache);
     const float loop_len = (max_falloff_factor / expand_cache->loop_count) +
                            SCULPT_EXPAND_LOOP_THRESHOLD;
 
     const float vertex_falloff_factor = sculpt_expand_falloff_value_vertex_get(
-        ss, expand_cache, i);
-    const float active_factor = fmod(expand_cache->active_factor, loop_len);
+        ss, expand_cache, v);
+    const float active_factor = fmod(expand_cache->active_falloff, loop_len);
     const float falloff_factor = fmod(vertex_falloff_factor, loop_len);
 
     enabled = falloff_factor < active_factor;
@@ -216,6 +253,7 @@ static bool sculpt_expand_state_get(SculptSession *ss, ExpandCache *expand_cache
   return enabled;
 }
 
+/* Main function to get the state of a face for the current state and settings of a ExpandCache. */
 static bool sculpt_expand_face_state_get(SculptSession *ss, ExpandCache *expand_cache, const int f)
 {
   if (ss->face_sets[f] <= 0) {
@@ -237,15 +275,15 @@ static bool sculpt_expand_face_state_get(SculptSession *ss, ExpandCache *expand_
     enabled = BLI_gset_haskey(expand_cache->snap_enabled_face_sets, POINTER_FROM_INT(face_set));
   }
   else {
-    const float loop_len = (expand_cache->max_face_falloff_factor / expand_cache->loop_count) +
+    const float loop_len = (expand_cache->max_face_falloff / expand_cache->loop_count) +
                            SCULPT_EXPAND_LOOP_THRESHOLD;
 
-    const float active_factor = fmod(expand_cache->active_factor, loop_len);
-    const float falloff_factor = fmod(expand_cache->face_falloff_factor[f], loop_len);
+    const float active_factor = fmod(expand_cache->active_falloff, loop_len);
+    const float falloff_factor = fmod(expand_cache->face_falloff[f], loop_len);
     enabled = falloff_factor < active_factor;
   }
 
-  if (expand_cache->falloff_factor_type == SCULPT_EXPAND_FALLOFF_ACTIVE_FACE_SET) {
+  if (expand_cache->falloff_type == SCULPT_EXPAND_FALLOFF_ACTIVE_FACE_SET) {
     if (ss->face_sets[f] == expand_cache->initial_active_face_set) {
       enabled = false;
     }
@@ -258,20 +296,22 @@ static bool sculpt_expand_face_state_get(SculptSession *ss, ExpandCache *expand_
   return enabled;
 }
 
-static float sculpt_expand_gradient_falloff_get(SculptSession *ss,
-                                                ExpandCache *expand_cache,
-                                                const int i)
+/* For target modes that support gradients, this function returns the corresponding gradient value
+ * for a enabled vertex. */
+static float sculpt_expand_gradient_value_get(SculptSession *ss,
+                                              ExpandCache *expand_cache,
+                                              const int v)
 {
   if (!expand_cache->falloff_gradient) {
     return 1.0f;
   }
 
-  const float max_falloff_factor = sculpt_expand_max_vertex_falloff_factor_get(expand_cache);
+  const float max_falloff_factor = sculpt_expand_max_vertex_falloff_get(expand_cache);
   const float loop_len = (max_falloff_factor / expand_cache->loop_count) +
                          SCULPT_EXPAND_LOOP_THRESHOLD;
 
-  const float vertex_falloff_factor = sculpt_

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list