[Bf-blender-cvs] [ca9f462a599] sculpt-dev: sculpt-dev: Fix anchored stroke mode

Joseph Eagar noreply at git.blender.org
Mon Mar 7 21:56:08 CET 2022


Commit: ca9f462a599b6e80a50004cccbe8ab5fecb0dc71
Author: Joseph Eagar
Date:   Mon Mar 7 12:54:05 2022 -0800
Branches: sculpt-dev
https://developer.blender.org/rBca9f462a599b6e80a50004cccbe8ab5fecb0dc71

sculpt-dev: Fix anchored stroke mode

* Anchored stroke mode now works with
  new brush command system
* Fixed original normal calc for anchored
  brushes.
* Added yet more code in my as-yet vain
  attempt to enforce seperation of
  graphic drivers and ASAN.

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

M	intern/ghost/CMakeLists.txt
M	source/blender/draw/CMakeLists.txt
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_brush_types.c
M	source/blender/gpu/CMakeLists.txt

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

diff --git a/intern/ghost/CMakeLists.txt b/intern/ghost/CMakeLists.txt
index 9421edecf12..a750ca34ff5 100644
--- a/intern/ghost/CMakeLists.txt
+++ b/intern/ghost/CMakeLists.txt
@@ -520,4 +520,7 @@ endif()
 
 add_definitions(${GL_DEFINITIONS})
 
+remove_cc_flag("-fsanitize=address")
+remove_cc_flag("/fsanitize=address")
+
 blender_add_lib(bf_intern_ghost "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index 98f75ad6106..d8bbfc2860f 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -566,6 +566,8 @@ if(WITH_GTESTS)
   endif()
 endif()
 
+remove_cc_flag("-fsanitize=address")
+remove_cc_flag("/fsanitize=address")
 
 blender_add_lib(bf_draw "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
 
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index eed304f5c8b..85396a67789 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -106,8 +106,8 @@
 #include "UI_resources.h"
 
 #include "bmesh.h"
-#include "bmesh_tools.h"
 #include "bmesh_log.h"
+#include "bmesh_tools.h"
 
 #include <math.h>
 #include <stdlib.h>
@@ -3058,7 +3058,7 @@ bool SCULPT_stroke_is_dynamic_topology(const SculptSession *ss, const Brush *bru
 
       /* Requires mesh restore, which doesn't work with
        * dynamic-topology. */
-      !(brush->flag & BRUSH_ANCHORED) && !(brush->flag & BRUSH_DRAG_DOT) &&
+      //!(brush->flag & BRUSH_ANCHORED) && !(brush->flag & BRUSH_DRAG_DOT) &&
       (brush->cached_dyntopo.flag & (DYNTOPO_SUBDIVIDE | DYNTOPO_COLLAPSE | DYNTOPO_CLEANUP)) &&
       !(brush->cached_dyntopo.flag & DYNTOPO_DISABLED) &&
       SCULPT_TOOL_HAS_DYNTOPO(SCULPT_get_tool(ss, brush)));
@@ -4405,10 +4405,12 @@ static void update_sculpt_normal(Sculpt *sd, Object *ob, PBVHNode **nodes, int t
 
   /* Grab brush does not update the sculpt normal during a stroke. */
   const bool update_normal = !(brush->flag & BRUSH_ORIGINAL_NORMAL) &&
-                             !(tool == SCULPT_TOOL_GRAB) &&
-                             !(tool == SCULPT_TOOL_THUMB && !(brush->flag & BRUSH_ANCHORED)) &&
-                             !(tool == SCULPT_TOOL_ELASTIC_DEFORM) &&
-                             !(tool == SCULPT_TOOL_SNAKE_HOOK && cache->normal_weight > 0.0f);
+                                 !(tool == SCULPT_TOOL_GRAB) &&
+                                 !(tool == SCULPT_TOOL_THUMB && !(brush->flag & BRUSH_ANCHORED)) &&
+                                 !(tool == SCULPT_TOOL_ELASTIC_DEFORM) &&
+                                 !(tool == SCULPT_TOOL_SNAKE_HOOK &&
+                                   cache->normal_weight > 0.0f) ||
+                             dot_v3v3(cache->sculpt_normal, cache->sculpt_normal) == 0.0f;
 
   if (cache->mirror_symmetry_pass == 0 && cache->radial_symmetry_pass == 0 &&
       (SCULPT_stroke_is_first_brush_step_of_symmetry_pass(cache) || update_normal)) {
@@ -5129,511 +5131,6 @@ static void do_brush_action_task_cb(void *__restrict userdata,
   }
 }
 
-static bool brush_uses_commandlist(Brush *brush, int tool)
-{
-  bool ok = false;
-
-  switch (tool) {
-    case SCULPT_TOOL_DRAW:
-    case SCULPT_TOOL_DRAW_SHARP:
-    case SCULPT_TOOL_CLAY_STRIPS:
-    case SCULPT_TOOL_CLAY:
-    case SCULPT_TOOL_CREASE:
-    case SCULPT_TOOL_ROTATE:
-    case SCULPT_TOOL_ELASTIC_DEFORM:
-    case SCULPT_TOOL_FAIRING:
-    case SCULPT_TOOL_FILL:
-    case SCULPT_TOOL_BLOB:
-    case SCULPT_TOOL_FLATTEN:
-    case SCULPT_TOOL_SCRAPE:
-    case SCULPT_TOOL_GRAB:
-    case SCULPT_TOOL_LAYER:
-    case SCULPT_TOOL_DRAW_FACE_SETS:
-    case SCULPT_TOOL_CLOTH:
-    case SCULPT_TOOL_SMOOTH:
-    case SCULPT_TOOL_PINCH:
-    case SCULPT_TOOL_SIMPLIFY:
-    case SCULPT_TOOL_SNAKE_HOOK:
-    case SCULPT_TOOL_SLIDE_RELAX:
-    case SCULPT_TOOL_RELAX:
-    case SCULPT_TOOL_INFLATE:
-    case SCULPT_TOOL_PAINT:
-    case SCULPT_TOOL_TWIST:
-    case SCULPT_TOOL_SMEAR:
-      ok = true;
-      break;
-  }
-
-  ok = ok && !(brush->flag & (BRUSH_ANCHORED | BRUSH_DRAG_DOT));
-
-  return ok;
-}
-
-void do_brush_action(
-    Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSettings *ups, void *UNUSED(userdata))
-{
-  SculptSession *ss = ob->sculpt;
-
-  int totnode;
-  PBVHNode **nodes;
-
-  float radius_scale = 1.0f;
-
-  if (!ELEM(SCULPT_get_tool(ss, brush), SCULPT_TOOL_SMOOTH, SCULPT_TOOL_MASK) &&
-      brush->autosmooth_factor > 0 && brush->autosmooth_radius_factor != 1.0f) {
-    radius_scale = MAX2(radius_scale, brush->autosmooth_radius_factor);
-  }
-
-  if (sculpt_brush_use_topology_rake(ss, brush)) {
-    radius_scale = MAX2(radius_scale, brush->topology_rake_radius_factor);
-  }
-
-  /* Check for unsupported features. */
-  PBVHType type = BKE_pbvh_type(ss->pbvh);
-  if (ELEM(SCULPT_get_tool(ss, brush), SCULPT_TOOL_PAINT, SCULPT_TOOL_SMEAR) &&
-      !ELEM(type, PBVH_BMESH, PBVH_FACES)) {
-    return;
-  }
-
-  if (SCULPT_get_tool(ss, brush) == SCULPT_TOOL_ARRAY && !ELEM(type, PBVH_FACES, PBVH_BMESH)) {
-    return;
-  }
-
-  /* Build a list of all nodes that are potentially within the brush's area of influence */
-  const bool use_original = sculpt_tool_needs_original(SCULPT_get_tool(ss, brush)) ?
-                                true :
-                                ss->cache->original;
-
-  if (SCULPT_tool_needs_all_pbvh_nodes(brush)) {
-    /* These brushes need to update all nodes as they are not constrained by the brush radius */
-    BKE_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnode);
-  }
-  else if (SCULPT_get_tool(ss, brush) == SCULPT_TOOL_CLOTH) {
-    nodes = SCULPT_cloth_brush_affected_nodes_gather(ss, brush, &totnode);
-  }
-  else {
-    /* With these options enabled not all required nodes are inside the original brush radius, so
-     * the brush can produce artifacts in some situations. */
-    if (SCULPT_get_tool(ss, brush) == SCULPT_TOOL_DRAW && brush->flag & BRUSH_ORIGINAL_NORMAL) {
-      radius_scale = MAX2(radius_scale, 2.0f);
-    }
-    nodes = sculpt_pbvh_gather_generic(ob, sd, brush, use_original, radius_scale * 1.2, &totnode);
-  }
-
-  /* Draw Face Sets in draw mode makes a single undo push, in alt-smooth mode deforms the
-   * vertices and uses regular coords undo. */
-  /* It also assigns the paint_face_set here as it needs to be done regardless of the stroke type
-   * and the number of nodes under the brush influence. */
-  if (SCULPT_get_tool(ss, brush) == SCULPT_TOOL_DRAW_FACE_SETS &&
-      SCULPT_stroke_is_first_brush_step(ss->cache) && !ss->cache->alt_smooth) {
-
-    // faceset undo node is created below for pbvh_bmesh
-    if (BKE_pbvh_type(ss->pbvh) != PBVH_BMESH) {
-      SCULPT_undo_push_node(ob, NULL, SCULPT_UNDO_FACE_SETS);
-    }
-
-    if (ss->cache->invert) {
-      /* When inverting the brush, pick the paint face mask ID from the mesh. */
-      ss->cache->paint_face_set = SCULPT_active_face_set_get(ss);
-    }
-    else {
-      /* By default create a new Face Sets. */
-      ss->cache->paint_face_set = SCULPT_face_set_next_available_get(ss);
-    }
-  }
-
-  /*
-   * Check that original data is for anchored and drag dot modes
-   */
-  if (brush->flag & (BRUSH_ANCHORED | BRUSH_DRAG_DOT)) {
-    if (SCULPT_stroke_is_first_brush_step(ss->cache) &&
-        SCULPT_get_tool(ss, brush) == SCULPT_TOOL_DRAW_FACE_SETS) {
-
-      SCULPT_face_ensure_original(ss, ob);
-
-      for (int i = 0; i < ss->totfaces; i++) {
-        SculptFaceRef face = BKE_pbvh_table_index_to_face(ss->pbvh, i);
-        SCULPT_face_check_origdata(ss, face);
-      }
-    }
-
-    for (int i = 0; i < totnode; i++) {
-      PBVHVertexIter vd;
-
-      BKE_pbvh_vertex_iter_begin (ss->pbvh, nodes[i], vd, PBVH_ITER_UNIQUE) {
-        SCULPT_vertex_check_origdata(ss, vd.vertex);
-      }
-      BKE_pbvh_vertex_iter_end;
-    }
-  }
-
-  /* Initialize automasking cache. For anchored brushes with spherical falloff, we start off with
-   * zero radius, thus we have no pbvh nodes on the first brush step. */
-  if (totnode ||
-      ((brush->falloff_shape == PAINT_FALLOFF_SHAPE_SPHERE) && (brush->flag & BRUSH_ANCHORED))) {
-    if (SCULPT_stroke_is_first_brush_step(ss->cache)) {
-      if (SCULPT_is_automasking_enabled(sd, ss, brush)) {
-        ss->cache->automasking = SCULPT_automasking_cache_init(sd, brush, ob);
-      }
-    }
-  }
-
-  /* Only act if some verts are inside the brush area. */
-  if (totnode == 0) {
-    return;
-  }
-  float location[3];
-
-  // dyntopo can't push undo nodes inside a thread
-  if (ss->bm) {
-    if (ELEM(SCULPT_get_tool(ss, brush), SCULPT_TOOL_PAINT, SCULPT_TOOL_SMEAR)) {
-      for (int i = 0; i < totnode; i++) {
-        int other = brush->vcol_boundary_factor > 0.0f ? SCULPT_UNDO_COORDS : -1;
-
-        SCULPT_ensure_dyntopo_node_undo(ob, nodes[i], SCULPT_UNDO_COLOR, other);
-        BKE_pbvh_node_mark_update_color(nodes[i]);
-      }
-    }
-    else if (SCULPT_get_tool(ss, brush) == SCULPT_TOOL_DRAW_FACE_SETS) {
-      for (int i = 0; i < totnode; i++) {
-        if (ss->cache->alt_smooth) {
-          SCULPT_ensure_dyntopo_node_undo(ob, nodes[i], SCULPT_UNDO_FACE_SETS, SCULPT_UNDO_COORDS);
-        }
-        else {
-          SCULPT_ensure_dyntopo_node_undo(ob, nodes[i], SCULPT_UNDO_FACE_SETS, -1);
-        }
-
-        BKE_pbvh_node_mark_update(nodes[i]);
-      }
-    }
-    else if (SCULPT_get_tool(ss, brush) != SCULPT_TOOL_ARRAY) {
-      for (int i = 0; i < totnode; i++) {
-        SCULPT_ensure_dyntopo_node_undo(ob, nodes[i], SCULPT_UNDO_COORDS, -1);
-
-        BKE_pbvh_node_mark_update(nodes[i]);
-      }
-    }
-  }
-  else {
-    SculptThreadedTaskData task_data = {
-        .sd = sd,
-        .ob = ob,
-        .brush = brush,
-        .nodes = nodes,
-    };
-
-    TaskParallelSettings settings;
-    BKE_pbvh_parallel_range_settings(&settings, true, totnode);
-    BLI_task_parallel_range(0, totnode, &task_data, do_brush_action_task_cb, &settings);
-  }
-
-  if (sculpt_brush_needs_normal(ss, brush)) {
-    update_sculpt_normal(sd, ob, nodes, totnode);
-  }
-
-  if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_AREA) {
-    update_brush_local_mat(sd, ob);
-  }
-
-  if (SCULPT_get_tool(ss,

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list