[Bf-blender-cvs] [7217d1f3556] sculpt-dev: Sculpt-dev: Clean up brush test code

Joseph Eagar noreply at git.blender.org
Sat May 21 23:32:41 CEST 2022


Commit: 7217d1f3556d012de806ad779aebe9fbb8d7462f
Author: Joseph Eagar
Date:   Sat May 21 14:29:18 2022 -0700
Branches: sculpt-dev
https://developer.blender.org/rB7217d1f3556d012de806ad779aebe9fbb8d7462f

Sculpt-dev: Clean up brush test code

* The standard sculpt brush spot test
  API now supports square brushes.
* Supports tip scale x from paint brush.
* TODO: rewrite clay strips and paint
  brushes to use standard api.
* Roll texture mapping semi-works.

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

M	source/blender/blenkernel/BKE_paint.h
M	source/blender/blenkernel/intern/brush.c
M	source/blender/blenkernel/intern/brush_engine_presets.c
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/editors/sculpt_paint/paint_intern.h
M	source/blender/editors/sculpt_paint/paint_stroke.c
M	source/blender/editors/sculpt_paint/paint_vertex.cc
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt.hh
M	source/blender/editors/sculpt_paint/sculpt_brush_types.c
M	source/blender/editors/sculpt_paint/sculpt_cloth.c
M	source/blender/editors/sculpt_paint/sculpt_dyntopo.c
M	source/blender/editors/sculpt_paint/sculpt_face_set.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h
M	source/blender/editors/sculpt_paint/sculpt_multiplane_scrape.c
M	source/blender/editors/sculpt_paint/sculpt_paint_color.c
M	source/blender/editors/sculpt_paint/sculpt_paint_image.cc
M	source/blender/editors/sculpt_paint/sculpt_smooth.c
M	source/blender/editors/sculpt_paint/sculpt_symmetrize.c
M	source/blender/gpu/GPU_buffers.h
M	source/blender/gpu/intern/gpu_buffers.c
M	source/blender/makesdna/DNA_brush_enums.h
M	source/blender/makesrna/intern/rna_brush.c

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

diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index 90507325719..c9e16411dac 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -923,6 +923,9 @@ typedef struct SculptSession {
    * Last used painting canvas key.
    */
   char *last_paint_canvas_key;
+
+  /* Used to derive initial tip rotation. */
+  float last_grab_delta[3];
 } SculptSession;
 
 void BKE_sculptsession_free(struct Object *ob);
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index 376e7d9b445..2ca076b9998 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -2308,11 +2308,13 @@ float BKE_brush_sample_tex_3d(const Scene *scene,
       invradius = 1.0f / ups->pixel_radius;
     }
     else if (mtex->brush_map_mode == MTEX_MAP_MODE_ROLL) {
-      // XXX implement me
-      x = point_2d[0] - ups->tex_mouse[0];
-      y = point_2d[1] - ups->tex_mouse[1];
+      /* leave the coordinates relative to the screen */
 
-      invradius = 1.0f / ups->pixel_radius;
+      /* use unadjusted size for tiled mode */
+      invradius = 1.0f / BKE_brush_size_get(scene, br, false);
+
+      x = point_2d[0];
+      y = point_2d[1];
     }
 
     x *= invradius;
diff --git a/source/blender/blenkernel/intern/brush_engine_presets.c b/source/blender/blenkernel/intern/brush_engine_presets.c
index 0a1d6457a60..b4f232e34e8 100644
--- a/source/blender/blenkernel/intern/brush_engine_presets.c
+++ b/source/blender/blenkernel/intern/brush_engine_presets.c
@@ -324,6 +324,8 @@ static bool check_builtin_init()
   // SETCAT(direction, "Basic");
   SETCAT(accumulate, "Basic");
   SETCAT(use_frontface, "Basic");
+  SETCAT(tip_roundness, "Basic");
+  SETCAT(tip_scale_x, "Basic");
 
   SETCAT(smear_deform_type, "Smear");
   SETCAT(smear_deform_blend, "Smear");
@@ -435,6 +437,16 @@ static bool check_builtin_init()
 #  undef ADDCH
 #endif
 
+/* TODO: Destroy these macros.*/
+
+#define ADDCH_EX(idname, category, visflag) \
+  do { \
+    BKE_brush_channelset_ensure_builtin(chset, BRUSH_BUILTIN_##idname); \
+    BrushChannel *ch = BKE_brush_channelset_lookup(chset, BRUSH_BUILTIN_##idname); \
+    SETCAT(idname, category); \
+    ch->flag |= visflag; \
+  } while (0);
+
 /* TODO: replace these two macros with equivalent BRUSHSET_XXX ones */
 #define ADDCH(name) \
   (BKE_brush_channelset_ensure_builtin(chset, BRUSH_BUILTIN_##name), \
@@ -1266,6 +1278,19 @@ void BKE_brush_builtin_patch(Brush *brush, int tool)
 
   ADDCH(deform_target);
 
+  /* Patch olds files. */
+  if (!BRUSHSET_LOOKUP(chset, tip_scale_x)) {
+    ADDCH_EX(tip_scale_x,
+             "Basic",
+             BRUSH_CHANNEL_SHOW_IN_WORKSPACE | BRUSH_CHANNEL_SHOW_IN_CONTEXT_MENU);
+    ADDCH_EX(tip_roundness,
+             "Basic",
+             BRUSH_CHANNEL_SHOW_IN_WORKSPACE | BRUSH_CHANNEL_SHOW_IN_CONTEXT_MENU);
+
+    if (tool == SCULPT_TOOL_CLAY_STRIPS) {
+      BRUSHSET_SET_FLOAT(chset, tip_roundness, 0.18f);
+    }
+  }
   /* stuff for deform_target cloth mode*/
   ADDCH(cloth_use_collision);
   ADDCH(cloth_solve_bending);
@@ -1306,8 +1331,6 @@ void BKE_brush_builtin_patch(Brush *brush, int tool)
       ADDCH(wet_paint_radius_factor);
       ADDCH(wet_persistence);
       ADDCH(density);
-      ADDCH(tip_scale_x);
-      ADDCH(tip_roundness);
       ADDCH(flow);
       ADDCH(rate);
       ADDCH(blend);
@@ -1489,6 +1512,11 @@ void BKE_brush_channelset_ui_init(Brush *brush, int tool)
   SHOWWRK(hardness);
   SHOWWRK(dyntopo_disabled);
 
+  SHOWWRK(tip_roundness);
+  SHOWCTX(tip_roundness);
+  SHOWWRK(tip_scale_x);
+  SHOWCTX(tip_scale_x);
+
   switch (tool) {
     case SCULPT_TOOL_DRAW_SHARP:
       SHOWWRK(sharp_mode);
@@ -1555,7 +1583,6 @@ void BKE_brush_channelset_ui_init(Brush *brush, int tool)
       SHOWWRK(area_radius_factor);
       SHOW_WRK_CTX(plane_offset);
       SHOW_WRK_CTX(plane_trim);
-      SHOWWRK(tip_roundness);
       SHOW_WRK_CTX(use_plane_trim);
 
       SHOWWRK(use_smoothed_rake);
@@ -1568,7 +1595,6 @@ void BKE_brush_channelset_ui_init(Brush *brush, int tool)
       SHOWWRK(area_radius_factor);
       SHOWWRK(plane_offset);
       SHOWWRK(plane_trim);
-      SHOWWRK(tip_roundness);
       SHOWWRK(use_plane_trim);
 
       SHOWCTX(autosmooth);
@@ -1661,10 +1687,8 @@ void BKE_brush_channelset_ui_init(Brush *brush, int tool)
       SHOWWRK(wet_paint_radius_factor);
       SHOWWRK(wet_persistence);
       SHOWWRK(density);
-      SHOWWRK(tip_scale_x);
       SHOWWRK(hardness);
       SHOWWRK(wet_mix);
-      SHOWWRK(tip_roundness);
       SHOWWRK(flow);
       SHOWWRK(rate);
       SHOWALL(blend);
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 37749572f14..c5127250d36 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -25,6 +25,7 @@
 
 #include "BKE_attribute.h"
 #include "BKE_ccg.h"
+#include "BKE_main.h"
 #include "BKE_mesh.h" /* for BKE_mesh_calc_normals */
 #include "BKE_mesh_mapping.h"
 #include "BKE_object.h"
@@ -1543,7 +1544,8 @@ static void pbvh_update_draw_buffer_cb(void *__restrict userdata,
                                      pbvh->face_sets_color_seed,
                                      pbvh->face_sets_color_default,
                                      update_flags,
-                                     pbvh->vert_normals);
+                                     pbvh->vert_normals,
+                                     pbvh->mdyntopo_verts);
       } break;
       case PBVH_BMESH:
         if (BKE_pbvh_bmesh_check_tris(pbvh, node)) {
@@ -1644,7 +1646,8 @@ void pbvh_update_free_all_draw_buffers(PBVH *pbvh, PBVHNode *node)
   }
 }
 
-static void pbvh_update_draw_buffers(PBVH *pbvh, Mesh *me, PBVHNode **nodes, int totnode, int update_flag)
+static void pbvh_update_draw_buffers(
+    PBVH *pbvh, Mesh *me, PBVHNode **nodes, int totnode, int update_flag)
 {
 
   CustomData *vdata;
@@ -2098,7 +2101,8 @@ void BKE_pbvh_node_mark_original_update(PBVHNode *node)
 void BKE_pbvh_node_mark_update(PBVHNode *node)
 {
   node->flag |= PBVH_UpdateNormals | PBVH_UpdateBB | PBVH_UpdateOriginalBB |
-                PBVH_UpdateDrawBuffers | PBVH_UpdateRedraw | PBVH_UpdateCurvatureDir | PBVH_RebuildPixels;
+                PBVH_UpdateDrawBuffers | PBVH_UpdateRedraw | PBVH_UpdateCurvatureDir |
+                PBVH_RebuildPixels | PBVH_UpdateTriAreas;
 }
 
 void BKE_pbvh_node_mark_update_mask(PBVHNode *node)
@@ -2503,15 +2507,15 @@ bool ray_update_depth_and_hit_count(const float depth_test,
   return false;
 }
 
-float ray_face_intersection_depth_quad(const float ray_start[3],
-                                       struct IsectRayPrecalc *isect_precalc,
-                                       const float t0[3],
-                                       const float t1[3],
-                                       const float t2[3],
-                                       const float t3[3],
-                                       float *r_depth,
-                                       float *r_back_depth,
-                                       int *hit_count)
+bool ray_face_intersection_depth_quad(const float ray_start[3],
+                                      struct IsectRayPrecalc *isect_precalc,
+                                      const float t0[3],
+                                      const float t1[3],
+                                      const float t2[3],
+                                      const float t3[3],
+                                      float *r_depth,
+                                      float *r_back_depth,
+                                      int *hit_count)
 {
   float depth_test;
   if (!(isect_ray_tri_watertight_v3(ray_start, isect_precalc, t0, t1, t2, &depth_test, NULL) ||
@@ -4907,10 +4911,21 @@ void BKE_pbvh_clear_cache(PBVH *preserve)
   pbvh_clear_cached_pbvhs(NULL);
 }
 
+#define PBVH_CACHE_KEY_SIZE 1024
+
+static void pbvh_make_cached_key(Object *ob, char out[PBVH_CACHE_KEY_SIZE])
+{
+  sprintf(out, "%s:%p", ob->id.name, G.main);
+}
+
 void BKE_pbvh_invalidate_cache(Object *ob)
 {
   Object *ob_orig = DEG_get_original_object(ob);
-  PBVH *pbvh = BLI_ghash_lookup(cached_pbvhs, ob_orig->id.name);
+
+  char key[PBVH_CACHE_KEY_SIZE];
+  pbvh_make_cached_key(ob_orig, key);
+
+  PBVH *pbvh = BLI_ghash_lookup(cached_pbvhs, key);
 
   if (pbvh) {
     BKE_pbvh_cache_remove(pbvh);
@@ -4921,7 +4936,10 @@ PBVH *BKE_pbvh_get_or_free_cached(Object *ob, Mesh *me, PBVHType pbvh_type)
 {
   Object *ob_orig = DEG_get_original_object(ob);
 
-  PBVH *pbvh = BLI_ghash_lookup(cached_pbvhs, ob_orig->id.name);
+  char key[PBVH_CACHE_KEY_SIZE];
+  pbvh_make_cached_key(ob_orig, key);
+
+  PBVH *pbvh = BLI_ghash_lookup(cached_pbvhs, key);
 
   if (!pbvh) {
     return NULL;
@@ -4966,7 +4984,10 @@ void BKE_pbvh_set_cached(Object *ob, PBVH *pbvh)
 
   Object *ob_orig = DEG_get_original_object(ob);
 
-  PBVH *exist = BLI_ghash_lookup(cached_pbvhs, ob_orig->id.name);
+  char key[PBVH_CACHE_KEY_SIZE];
+  pbvh_make_cached_key(ob_orig, key);
+
+  PBVH *exist = BLI_ghash_lookup(cached_pbvhs, key);
 
   if (pbvh->invalid) {
     printf("pbvh invalid!");
@@ -4978,7 +4999,11 @@ void BKE_pbvh_set_cached(Object *ob, PBVH *pbvh)
 
   if (!exist || exist != pbvh) {
     pbvh_clear_cached_pbvhs(pbvh);
-    BLI_ghash_insert(cached_pbvhs, BLI_strdup(ob_orig->id.name), pbvh);
+
+    char key[PBVH_CACHE_KEY_SIZE];
+    pbvh_make_cached_key(ob_orig, key);
+
+    BLI_ghash_insert(cached_pbvhs, BLI_strdup(key), pbvh);
   }
 
   BKE_pbvh_cache(BKE_object_get_original_mesh(ob_orig), pbvh);
diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h
index 73a2bb0a1e6..ffa010e7466 100644
--- a/source/blender/editors/sculpt_paint/paint_intern.h
+++ b/source/blender/editors/sculpt_paint/paint_intern.h
@@ -141,6 +141,7 @@ typedef struct PaintStroke {
   StrokeDone done;
 
   float spacing;
+  void *debug_draw_handle;
 } PaintStroke;
 
 struct PaintStroke *paint_stroke_new(struct bContext *C,
@@ -619,6 +620,8 @@ void paint_delete_blur_kernel(BlurKernel *);
 #define PAINT_CURVE_NUM_SEGMENTS 40
 
 bool paint_stro

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list