[Bf-blender-cvs] [1b029b790b2] sculpt-dev: Sculpt Expand: Refactor, more comments
Pablo Dobarro
noreply at git.blender.org
Wed Feb 17 00:18:21 CET 2021
Commit: 1b029b790b22b51b1586bf4fb62b5f3426b08a50
Author: Pablo Dobarro
Date: Tue Feb 16 21:03:34 2021 +0100
Branches: sculpt-dev
https://developer.blender.org/rB1b029b790b22b51b1586bf4fb62b5f3426b08a50
Sculpt Expand: Refactor, more comments
===================================================================
M source/blender/editors/sculpt_paint/sculpt_expand.c
===================================================================
diff --git a/source/blender/editors/sculpt_paint/sculpt_expand.c b/source/blender/editors/sculpt_paint/sculpt_expand.c
index 10e6b17706b..d8076b40e8c 100644
--- a/source/blender/editors/sculpt_paint/sculpt_expand.c
+++ b/source/blender/editors/sculpt_paint/sculpt_expand.c
@@ -330,6 +330,56 @@ static float sculpt_expand_gradient_value_get(SculptSession *ss,
return BKE_brush_curve_strength(expand_cache->brush, linear_falloff, 1.0f);
}
+/* Utility functions for getting all vertices state during expand. */
+
+/* Returns a bitmap indexed by vertex index which contains if the vertex was enabled or not for a
+ * give expand_cache state. */
+static BLI_bitmap *sculpt_expand_bitmap_from_enabled(SculptSession *ss, ExpandCache *expand_cache)
+{
+ const int totvert = SCULPT_vertex_count_get(ss);
+ BLI_bitmap *enabled_vertices = BLI_BITMAP_NEW(totvert, "enabled vertices");
+ for (int i = 0; i < totvert; i++) {
+ const bool enabled = sculpt_expand_state_get(ss, expand_cache, i);
+ BLI_BITMAP_SET(enabled_vertices, i, enabled);
+ }
+ return enabled_vertices;
+}
+
+/* Returns a bitmap indexed by vertex index which contains if the vertex is in the boundary of the
+ * enabled vertices. This is defined as vertices that are enabled and at least have one connected
+ * vertex that is not enabled. */
+static BLI_bitmap *sculpt_expand_boundary_from_enabled(SculptSession *ss,
+ BLI_bitmap *enabled_vertices,
+ const bool use_mesh_boundary)
+{
+ const int totvert = SCULPT_vertex_count_get(ss);
+ BLI_bitmap *boundary_vertices = BLI_BITMAP_NEW(totvert, "boundary vertices");
+ for (int i = 0; i < totvert; i++) {
+ if (!BLI_BITMAP_TEST(enabled_vertices, i)) {
+ continue;
+ }
+
+ bool is_expand_boundary = false;
+ SculptVertexNeighborIter ni;
+ SCULPT_VERTEX_NEIGHBORS_ITER_BEGIN (ss, i, ni) {
+ if (!BLI_BITMAP_TEST(enabled_vertices, ni.index)) {
+ is_expand_boundary = true;
+ }
+ }
+ SCULPT_VERTEX_NEIGHBORS_ITER_END(ni);
+
+ if (use_mesh_boundary && SCULPT_vertex_is_boundary(ss, i)) {
+ is_expand_boundary = true;
+ }
+
+ BLI_BITMAP_SET(boundary_vertices, i, is_expand_boundary);
+ }
+
+ return boundary_vertices;
+}
+
+
+
/* Functions implementing differnt algorithms for initializing the falloff values. */
/* Geodesic: Initializes the falloff with geodesic distances from the given active vertex, taking
@@ -722,56 +772,9 @@ static void sculpt_expand_mesh_face_falloff_from_vertex_falloff(SculptSession *s
}
}
-/* Utility functions for getting all vertices state during expand. */
-
-/* Returns a bitmap indexed by vertex index which contains if the vertex was enabled or not for a
- * give expand_cache state. */
-static BLI_bitmap *sculpt_expand_bitmap_from_enabled(SculptSession *ss, ExpandCache *expand_cache)
-{
- const int totvert = SCULPT_vertex_count_get(ss);
- BLI_bitmap *enabled_vertices = BLI_BITMAP_NEW(totvert, "enabled vertices");
- for (int i = 0; i < totvert; i++) {
- const bool enabled = sculpt_expand_state_get(ss, expand_cache, i);
- BLI_BITMAP_SET(enabled_vertices, i, enabled);
- }
- return enabled_vertices;
-}
-
-/* Returns a bitmap indexed by vertex index which contains if the vertex is in the boundary of the
- * enabled vertices. This is defined as vertices that are enabled and at least have one connected
- * vertex that is not enabled. */
-static BLI_bitmap *sculpt_expand_boundary_from_enabled(SculptSession *ss,
- BLI_bitmap *enabled_vertices,
- const bool use_mesh_boundary)
-{
- const int totvert = SCULPT_vertex_count_get(ss);
- BLI_bitmap *boundary_vertices = BLI_BITMAP_NEW(totvert, "boundary vertices");
- for (int i = 0; i < totvert; i++) {
- if (!BLI_BITMAP_TEST(enabled_vertices, i)) {
- continue;
- }
-
- bool is_expand_boundary = false;
- SculptVertexNeighborIter ni;
- SCULPT_VERTEX_NEIGHBORS_ITER_BEGIN (ss, i, ni) {
- if (!BLI_BITMAP_TEST(enabled_vertices, ni.index)) {
- is_expand_boundary = true;
- }
- }
- SCULPT_VERTEX_NEIGHBORS_ITER_END(ni);
-
- if (use_mesh_boundary && SCULPT_vertex_is_boundary(ss, i)) {
- is_expand_boundary = true;
- }
-
- BLI_BITMAP_SET(boundary_vertices, i, is_expand_boundary);
- }
-
- return boundary_vertices;
-}
-
-/* Recursions:
+/* Recursions. These functions will generate new falloff values based on the state of the vertices from the current ExpandCache options and falloff values. */
+/* Geodesic recursion: Initializes falloff values using geodesic distances from the boundary of the current vertices state. */
static void sculpt_expand_geodesics_from_state_boundary(Object *ob,
ExpandCache *expand_cache,
BLI_bitmap *enabled_vertices)
@@ -797,6 +800,7 @@ static void sculpt_expand_geodesics_from_state_boundary(Object *ob,
BLI_gset_free(initial_vertices, NULL);
}
+/* Geodesic recursion: Initializes falloff values using topology steps from the boundary of the current vertices state, increasing the value by 1 each time a new vertex is visited. */
static void sculpt_expand_topology_from_state_boundary(Object *ob,
ExpandCache *expand_cache,
BLI_bitmap *enabled_vertices)
@@ -828,6 +832,40 @@ static void sculpt_expand_topology_from_state_boundary(Object *ob,
expand_cache->falloff = dists;
}
+/* Main function to create a recursion step from the current ExpandCache state. */
+static void sculpt_expand_resursion_step_add(Object *ob,
+ ExpandCache *expand_cache,
+ const eSculptExpandRecursionType recursion_type)
+{
+ SculptSession *ss = ob->sculpt;
+ if (BKE_pbvh_type(ss->pbvh) != PBVH_FACES) {
+ return;
+ }
+
+ BLI_bitmap *enabled_vertices = sculpt_expand_bitmap_from_enabled(ss, expand_cache);
+
+ /* Each time a new recursion step is created, reset the distortion strength. This is the expedted result from the recursion, as otherwise the new falloff will render with undesired distortion from the beginning */
+ expand_cache->texture_distortion_strength = 0.0f;
+
+ switch (recursion_type) {
+ case SCULPT_EXPAND_RECURSION_GEODESICS:
+ sculpt_expand_geodesics_from_state_boundary(ob, expand_cache, enabled_vertices);
+ break;
+ case SCULPT_EXPAND_RECURSION_TOPOLOGY:
+ sculpt_expand_topology_from_state_boundary(ob, expand_cache, enabled_vertices);
+ break;
+ }
+
+ sculpt_expand_update_max_falloff_value(ss, expand_cache);
+ if (expand_cache->target == SCULPT_EXPAND_TARGET_FACE_SETS) {
+ sculpt_expand_mesh_face_falloff_from_vertex_falloff(ss, ob->data, expand_cache);
+ sculpt_expand_update_max_face_falloff_factor(ss, expand_cache);
+ }
+
+ MEM_freeN(enabled_vertices);
+}
+
+/* Face Set Boundary falloff: */
static void sculpt_expand_initialize_from_face_set_boundary(Object *ob,
ExpandCache *expand_cache,
const int active_face_set,
@@ -885,54 +923,13 @@ static void sculpt_expand_initialize_from_face_set_boundary(Object *ob,
}
}
-static void sculpt_expand_snap_initialize_from_enabled(SculptSession *ss,
- ExpandCache *expand_cache)
-{
- if (BKE_pbvh_type(ss->pbvh) != PBVH_FACES) {
- return;
- }
-
- const bool prev_snap_state = expand_cache->snap;
- const bool prev_invert_state = expand_cache->invert;
-
- expand_cache->snap = false;
- expand_cache->invert = false;
-
- BLI_bitmap *enabled_vertices = sculpt_expand_bitmap_from_enabled(ss, expand_cache);
-
- const int totface = ss->totfaces;
- for (int i = 0; i < totface; i++) {
- const int face_set = expand_cache->initial_face_sets[i];
- BLI_gset_add(expand_cache->snap_enabled_face_sets, POINTER_FROM_INT(face_set));
- }
-
- for (int p = 0; p < totface; p++) {
- MPoly *poly = &ss->mpoly[p];
- bool any_disabled = false;
- for (int l = 0; l < poly->totloop; l++) {
- MLoop *loop = &ss->mloop[l + poly->loopstart];
- if (!BLI_BITMAP_TEST(enabled_vertices, loop->v)) {
- any_disabled = true;
- }
- }
- if (any_disabled) {
- const int face_set = expand_cache->initial_face_sets[p];
- if (BLI_gset_haskey(expand_cache->snap_enabled_face_sets, POINTER_FROM_INT(face_set))) {
- BLI_gset_remove(expand_cache->snap_enabled_face_sets, POINTER_FROM_INT(face_set), NULL);
- }
- }
- }
-
- MEM_freeN(enabled_vertices);
- expand_cache->snap = prev_snap_state;
- expand_cache->invert = prev_invert_state;
-}
+/* Main function to initialize new falloff values in a ExpandCache given an initial vertex and a falloff type. */
static void sculpt_expand_falloff_factors_from_vertex_and_symm_create(
ExpandCache *expand_cache,
Sculpt *sd,
Object *ob,
- const int vertex,
+ const int v,
eSculptExpandFalloffType falloff_type)
{
MEM_SAFE_FREE(expand_cache->falloff);
@@ -944,25 +941,25 @@ static void sculpt_expand_falloff_factors_from_vertex_and_symm_create(
switch (falloff_type) {
case SCULPT_EXPAND_FALLOFF_GEODESIC:
expand_cache->falloff = has_topology_info ?
- sculpt_expand_geodesic_falloff_create(sd, ob, vertex) :
- sculpt_expand_spherical_falloff_create(sd, ob, vertex);
+ sculpt_expand_geodesic_falloff_create(sd, ob, v) :
+ sculpt_expand_spherical_falloff_create(sd, ob, v);
break;
case SCULPT_EXPAND_FALLOFF_TOPOLOGY:
- expand_cache->falloff = sculpt_expand_topology_falloff_create(sd, ob, vertex);
+ expand_cache->falloff = sculpt_expand_topology_falloff_create(sd, ob, v);
break;
case SCULPT_EXPAND_FALLOFF_TOPOLOGY_DIAGONALS:
expand_c
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list