[Bf-blender-cvs] [47cbb9b1ac5] sculpt-dev: Sculpt: fix rotate brush

Joseph Eagar noreply at git.blender.org
Tue Oct 5 23:20:06 CEST 2021


Commit: 47cbb9b1ac5e78bdca4d03dd9d794df4fdfcc9af
Author: Joseph Eagar
Date:   Tue Oct 5 14:19:53 2021 -0700
Branches: sculpt-dev
https://developer.blender.org/rB47cbb9b1ac5e78bdca4d03dd9d794df4fdfcc9af

Sculpt: fix rotate brush

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

M	source/blender/blenkernel/intern/brush_engine.c
M	source/blender/blenkernel/intern/pbvh_bmesh.c
M	source/blender/bmesh/bmesh_class.h
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_array.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h

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

diff --git a/source/blender/blenkernel/intern/brush_engine.c b/source/blender/blenkernel/intern/brush_engine.c
index 2accea81659..3075e3a9758 100644
--- a/source/blender/blenkernel/intern/brush_engine.c
+++ b/source/blender/blenkernel/intern/brush_engine.c
@@ -1547,11 +1547,11 @@ void BKE_builtin_apply_hard_edge_mode(BrushChannelSet *chset, bool do_apply)
   }
 }
 
-ATTR_NO_OPT void BKE_builtin_commandlist_create(Brush *brush,
-                                                BrushChannelSet *chset,
-                                                BrushCommandList *cl,
-                                                int tool,
-                                                BrushMappingData *mapdata)
+void BKE_builtin_commandlist_create(Brush *brush,
+                                    BrushChannelSet *chset,
+                                    BrushCommandList *cl,
+                                    int tool,
+                                    BrushMappingData *mapdata)
 {
   BrushCommand *cmd;
   BrushChannel *ch;
diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c
index ce25fb8780c..bfaea1b9aee 100644
--- a/source/blender/blenkernel/intern/pbvh_bmesh.c
+++ b/source/blender/blenkernel/intern/pbvh_bmesh.c
@@ -5155,7 +5155,7 @@ void pbvh_bmesh_do_cache_test()
 }
 
 /* saves all bmesh references to internal indices, to be restored later */
-ATTR_NO_OPT void BKE_pbvh_bmesh_save_indices(PBVH *pbvh)
+void BKE_pbvh_bmesh_save_indices(PBVH *pbvh)
 {
   BM_mesh_elem_index_ensure(pbvh->bm, BM_VERT | BM_EDGE | BM_FACE);
 
@@ -5242,7 +5242,7 @@ ATTR_NO_OPT void BKE_pbvh_bmesh_save_indices(PBVH *pbvh)
 }
 
 /* restore bmesh references from previously indices saved by BKE_pbvh_bmesh_save_indices */
-ATTR_NO_OPT void BKE_pbvh_bmesh_from_saved_indices(PBVH *pbvh)
+void BKE_pbvh_bmesh_from_saved_indices(PBVH *pbvh)
 {
   BM_mesh_elem_table_ensure(pbvh->bm, BM_VERT | BM_EDGE | BM_FACE);
   BM_mesh_elem_index_ensure(pbvh->bm, BM_VERT | BM_EDGE | BM_FACE);
diff --git a/source/blender/bmesh/bmesh_class.h b/source/blender/bmesh/bmesh_class.h
index 42c0bec06a7..7aec1ea0721 100644
--- a/source/blender/bmesh/bmesh_class.h
+++ b/source/blender/bmesh/bmesh_class.h
@@ -292,7 +292,7 @@ typedef struct BMFlagLayer {
 
 struct RangeTreeUInt;
 
-#define WITH_BM_ID_FREELIST
+//#define WITH_BM_ID_FREELIST
 
 typedef struct BMesh {
   int totvert, totedge, totloop, totface;
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 2f3e0d7b495..3047e10aa0e 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -322,6 +322,23 @@ float *SCULPT_vertex_origco_get(SculptSession *ss, SculptVertRef vertex)
   return NULL;
 }
 
+float *SCULPT_vertex_origno_get(SculptSession *ss, SculptVertRef vertex)
+{
+  switch (BKE_pbvh_type(ss->pbvh)) {
+    case PBVH_BMESH: {
+      BMVert *v = (BMVert *)vertex.i;
+      return BKE_PBVH_DYNVERT(ss->cd_dyn_vert, v)->origno;
+    }
+
+    case PBVH_GRIDS:
+    case PBVH_FACES: {
+      return ss->mdyntopo_verts[vertex.i].origno;
+    }
+  }
+
+  return NULL;
+}
+
 const float *SCULPT_vertex_co_get(SculptSession *ss, SculptVertRef index)
 {
   if (ss->bm) {
@@ -3391,7 +3408,7 @@ static float calc_overlap(StrokeCache *cache, const char symm, const char axis,
 
   distsq = len_squared_v3v3(mirror, cache->true_location);
 
-  if (distsq <= 4.0f * (cache->radius_squared)) {
+  if (cache->radius > 0.0f && distsq <= 4.0f * (cache->radius_squared)) {
     return (2.0f * (cache->radius) - sqrtf(distsq)) / (2.0f * (cache->radius));
   }
   return 0.0f;
@@ -3432,7 +3449,9 @@ static float calc_symmetry_feather(Sculpt *sd, StrokeCache *cache)
     overlap += calc_radial_symmetry_feather(sd, cache, i, 'Y');
     overlap += calc_radial_symmetry_feather(sd, cache, i, 'Z');
   }
-  return 1.0f / overlap;
+
+  /* mathwise divice by zero is infinity, so use maximum value (1) in that case? */
+  return overlap != 0.0f ? 1.0f / overlap : 1.0f;
 }
 
 /* -------------------------------------------------------------------- */
@@ -4105,7 +4124,7 @@ float SCULPT_brush_strength_factor(SculptSession *ss,
 }
 
 /* Test AABB against sphere. */
-ATTR_NO_OPT bool SCULPT_search_sphere_cb(PBVHNode *node, void *data_v)
+bool SCULPT_search_sphere_cb(PBVHNode *node, void *data_v)
 {
   SculptSearchSphereData *data = data_v;
   const float *center;
@@ -6826,12 +6845,9 @@ static void do_rotate_brush_task_cb_ex(void *__restrict userdata,
   const float angle = data->angle;
 
   PBVHVertexIter vd;
-  SculptOrigVertData orig_data;
   float(*proxy)[3];
   const float bstrength = ss->cache->bstrength;
 
-  SCULPT_orig_vert_data_init(&orig_data, data->ob, data->nodes[n], SCULPT_UNDO_COORDS);
-
   proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co;
 
   SculptBrushTest test;
@@ -6840,33 +6856,39 @@ static void do_rotate_brush_task_cb_ex(void *__restrict userdata,
   const int thread_id = BLI_task_parallel_thread_id(tls);
 
   BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
-    SCULPT_orig_vert_data_update(&orig_data, vd.vertex);
+    SCULPT_vertex_check_origdata(ss, vd.vertex);
 
-    if (!sculpt_brush_test_sq_fn(&test, orig_data.co)) {
+    float *co = SCULPT_vertex_origco_get(ss, vd.vertex);
+    float *no = SCULPT_vertex_origno_get(ss, vd.vertex);
+
+    if (!sculpt_brush_test_sq_fn(&test, co)) {
       continue;
     }
+
     float vec[3], rot[3][3];
     const float fade = bstrength * SCULPT_brush_strength_factor(ss,
                                                                 brush,
-                                                                orig_data.co,
+                                                                co,
                                                                 sqrtf(test.dist),
-                                                                orig_data.no,
                                                                 NULL,
+                                                                no,
                                                                 vd.mask ? *vd.mask : 0.0f,
                                                                 vd.vertex,
                                                                 thread_id);
 
-    sub_v3_v3v3(vec, orig_data.co, ss->cache->location);
+    sub_v3_v3v3(vec, co, ss->cache->location);
     axis_angle_normalized_to_mat3(rot, ss->cache->sculpt_normal_symm, angle * fade);
     mul_v3_m3v3(proxy[vd.i], rot, vec);
     add_v3_v3(proxy[vd.i], ss->cache->location);
-    sub_v3_v3(proxy[vd.i], orig_data.co);
+    sub_v3_v3(proxy[vd.i], co);
 
     if (vd.mvert) {
       vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
     }
   }
   BKE_pbvh_vertex_iter_end;
+
+  BKE_pbvh_node_mark_update(data->nodes[n]);
 }
 
 static void do_rotate_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
diff --git a/source/blender/editors/sculpt_paint/sculpt_array.c b/source/blender/editors/sculpt_paint/sculpt_array.c
index b837f9a0dfd..38719514c3e 100644
--- a/source/blender/editors/sculpt_paint/sculpt_array.c
+++ b/source/blender/editors/sculpt_paint/sculpt_array.c
@@ -121,7 +121,7 @@ static void sculpt_array_datalayers_add(SculptArray *array, SculptSession *ss, M
   }
 }
 
-ATTR_NO_OPT void SCULPT_array_datalayers_free(SculptArray *array, Object *ob)
+void SCULPT_array_datalayers_free(SculptArray *array, Object *ob)
 {
   SculptSession *ss = ob->sculpt;
 
@@ -286,9 +286,7 @@ static BMesh *sculpt_array_source_build(Object *ob, Brush *brush, SculptArray *a
   return srcbm;
 }
 
-ATTR_NO_OPT void sculpt_array_source_datalayer_update(BMesh *bm,
-                                                      const int symm_pass,
-                                                      const int copy_index)
+void sculpt_array_source_datalayer_update(BMesh *bm, const int symm_pass, const int copy_index)
 {
   const int cd_array_instance_index = CustomData_get_named_layer_index(
       &bm->vdata, CD_PROP_INT32, array_instance_cd_name);
@@ -326,10 +324,8 @@ static void sculpt_array_final_mesh_write(Object *ob, BMesh *final_mesh)
   ss->needs_pbvh_rebuild = true;
 }
 
-ATTR_NO_OPT static void sculpt_array_ensure_geometry_indices(Object *ob, SculptArray *array)
+static void sculpt_array_ensure_geometry_indices(Object *ob, SculptArray *array)
 {
-  Mesh *mesh = BKE_object_get_original_mesh(ob);
-
   if (array->copy_index) {
     return;
   }
@@ -361,7 +357,7 @@ ATTR_NO_OPT static void sculpt_array_ensure_geometry_indices(Object *ob, SculptA
   SCULPT_array_datalayers_free(array, ob);
 }
 
-ATTR_NO_OPT static void sculpt_array_mesh_build(Sculpt *sd, Object *ob, SculptArray *array)
+static void sculpt_array_mesh_build(Sculpt *sd, Object *ob, SculptArray *array)
 {
   bool have_bmesh = ob->sculpt->bm && ob->sculpt->pbvh &&
                     BKE_pbvh_type(ob->sculpt->pbvh) == PBVH_BMESH;
@@ -566,7 +562,6 @@ static void sculpt_array_update_copy(StrokeCache *cache,
                                      Brush *brush)
 {
 
-  float copy_position[3];
   unit_m4(copy->mat);
 
   float scale = 1.0f;
@@ -663,16 +658,14 @@ static void sculpt_array_update(Object *ob, Brush *brush, SculptArray *array)
   }
 }
 
-ATTR_NO_OPT static void do_array_deform_task_cb_ex(void *__restrict userdata,
-                                                   const int n,
-                                                   const TaskParallelTLS *__restrict tls)
+static void do_array_deform_task_cb_ex(void *__restrict userdata,
+                                       const int n,
+                                       const TaskParallelTLS *__restrict tls)
 {
   SculptThreadedTaskData *data = userdata;
   SculptSession *ss = data->ob->sculpt;
   SculptArray *array = ss->array;
 
-  Mesh *mesh = BKE_object_get_original_mesh(data->ob);
-
   bool any_modified = false;
 
   PBVHVertexIter vd;
@@ -711,7 +704,6 @@ ATTR_NO_OPT static void do_array_deform_task_cb_ex(void *__restrict userdata,
 static void sculpt_array_deform(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
 {
   /* Threaded loop over nodes. */
-  SculptSession *ss = ob->sculpt;
   SculptThreadedTaskData d

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list