[Bf-blender-cvs] [c9de65679bb] master: Fix T83201: Cloth brush performance regression

Pablo Dobarro noreply at git.blender.org
Tue Dec 15 20:22:51 CET 2020


Commit: c9de65679bb0905e7f689b83931c9be9a8abfa02
Author: Pablo Dobarro
Date:   Sun Dec 6 23:11:33 2020 +0100
Branches: master
https://developer.blender.org/rBc9de65679bb0905e7f689b83931c9be9a8abfa02

Fix T83201: Cloth brush performance regression

The if statement of the dynamic area mode branch should be an else if.
When using local mode, this was running both the local and global code.

I moved this code to sculpt_cloth and refactored it to use a switch case
to prevent this from happening again.

Reviewed By: mont29

Maniphest Tasks: T83201

Differential Revision: https://developer.blender.org/D9762

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

M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_cloth.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 94f05560f79..80a32682325 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -5742,32 +5742,7 @@ static void do_brush_action(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSe
     BKE_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnode);
   }
   else if (brush->sculpt_tool == SCULPT_TOOL_CLOTH) {
-    if (brush->cloth_simulation_area_type == BRUSH_CLOTH_SIMULATION_AREA_LOCAL) {
-      SculptSearchSphereData data = {
-          .ss = ss,
-          .sd = sd,
-          .radius_squared = square_f(ss->cache->initial_radius * (1.0 + brush->cloth_sim_limit)),
-          .original = false,
-          .ignore_fully_ineffective = false,
-          .center = ss->cache->initial_location,
-      };
-      BKE_pbvh_search_gather(ss->pbvh, SCULPT_search_sphere_cb, &data, &nodes, &totnode);
-    }
-    if (brush->cloth_simulation_area_type == BRUSH_CLOTH_SIMULATION_AREA_DYNAMIC) {
-      SculptSearchSphereData data = {
-          .ss = ss,
-          .sd = sd,
-          .radius_squared = square_f(ss->cache->radius * (1.0 + brush->cloth_sim_limit)),
-          .original = false,
-          .ignore_fully_ineffective = false,
-          .center = ss->cache->location,
-      };
-      BKE_pbvh_search_gather(ss->pbvh, SCULPT_search_sphere_cb, &data, &nodes, &totnode);
-    }
-    else {
-      /* Gobal simulation, get all nodes. */
-      BKE_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnode);
-    }
+    nodes = SCULPT_cloth_brush_affected_nodes_gather(ss, brush, &totnode);
   }
   else {
     const bool use_original = sculpt_tool_needs_original(brush->sculpt_tool) ? true :
diff --git a/source/blender/editors/sculpt_paint/sculpt_cloth.c b/source/blender/editors/sculpt_paint/sculpt_cloth.c
index f8165890cc4..0ac0d796ca4 100644
--- a/source/blender/editors/sculpt_paint/sculpt_cloth.c
+++ b/source/blender/editors/sculpt_paint/sculpt_cloth.c
@@ -119,6 +119,43 @@ static void cloth_brush_simulation_location_get(SculptSession *ss,
   copy_v3_v3(r_location, ss->cache->location);
 }
 
+PBVHNode **SCULPT_cloth_brush_affected_nodes_gather(SculptSession *ss,
+                                                    Brush *brush,
+                                                    int *r_totnode)
+{
+  BLI_assert(ss->cache);
+  BLI_assert(brush->sculpt_tool == SCULPT_TOOL_CLOTH);
+  PBVHNode **nodes = NULL;
+
+  switch (brush->cloth_simulation_area_type) {
+    case BRUSH_CLOTH_SIMULATION_AREA_LOCAL: {
+      SculptSearchSphereData data = {
+          .ss = ss,
+          .radius_squared = square_f(ss->cache->initial_radius * (1.0 + brush->cloth_sim_limit)),
+          .original = false,
+          .ignore_fully_ineffective = false,
+          .center = ss->cache->initial_location,
+      };
+      BKE_pbvh_search_gather(ss->pbvh, SCULPT_search_sphere_cb, &data, &nodes, r_totnode);
+    } break;
+    case BRUSH_CLOTH_SIMULATION_AREA_GLOBAL:
+      BKE_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, r_totnode);
+      break;
+    case BRUSH_CLOTH_SIMULATION_AREA_DYNAMIC: {
+      SculptSearchSphereData data = {
+          .ss = ss,
+          .radius_squared = square_f(ss->cache->radius * (1.0 + brush->cloth_sim_limit)),
+          .original = false,
+          .ignore_fully_ineffective = false,
+          .center = ss->cache->location,
+      };
+      BKE_pbvh_search_gather(ss->pbvh, SCULPT_search_sphere_cb, &data, &nodes, r_totnode);
+    } break;
+  }
+
+  return nodes;
+}
+
 static float cloth_brush_simulation_falloff_get(const Brush *brush,
                                                 const float radius,
                                                 const float location[3],
diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h
index e0d413bc75f..bd5ba15b493 100644
--- a/source/blender/editors/sculpt_paint/sculpt_intern.h
+++ b/source/blender/editors/sculpt_paint/sculpt_intern.h
@@ -423,6 +423,10 @@ void SCULPT_cloth_plane_falloff_preview_draw(const uint gpuattr,
                                              const float outline_col[3],
                                              float outline_alpha);
 
+PBVHNode **SCULPT_cloth_brush_affected_nodes_gather(SculptSession *ss,
+                                                    Brush *brush,
+                                                    int *r_totnode);
+
 BLI_INLINE bool SCULPT_is_cloth_deform_brush(const Brush *brush)
 {
   return (brush->sculpt_tool == SCULPT_TOOL_CLOTH && ELEM(brush->cloth_deform_type,



More information about the Bf-blender-cvs mailing list