[Bf-blender-cvs] [d93dd859510] master: Sculpt: split sculpt.c into three files

Joseph Eagar noreply at git.blender.org
Mon Dec 20 20:38:29 CET 2021


Commit: d93dd8595103ea0c0d483e90381f398bbeecf675
Author: Joseph Eagar
Date:   Mon Dec 20 14:04:53 2021 -0500
Branches: master
https://developer.blender.org/rBd93dd8595103ea0c0d483e90381f398bbeecf675

Sculpt: split sculpt.c into three files

Sculpt.c is now three files:

* Sculpt.c: main API methods and the brush stroke operator
* Sculpt_brushes.c: Code for individual brushes.
* Sculpt_ops.c: Sculpt operators other than the brush stroke operator.

TODO: split brush stroke operator into a new file (sculpt_stroke.c?).

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

M	source/blender/editors/sculpt_paint/CMakeLists.txt
M	source/blender/editors/sculpt_paint/paint_intern.h
M	source/blender/editors/sculpt_paint/paint_utils.c
M	source/blender/editors/sculpt_paint/sculpt.c
A	source/blender/editors/sculpt_paint/sculpt_brushes.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h
A	source/blender/editors/sculpt_paint/sculpt_ops.c

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

diff --git a/source/blender/editors/sculpt_paint/CMakeLists.txt b/source/blender/editors/sculpt_paint/CMakeLists.txt
index b826ff8701d..517125f016e 100644
--- a/source/blender/editors/sculpt_paint/CMakeLists.txt
+++ b/source/blender/editors/sculpt_paint/CMakeLists.txt
@@ -59,6 +59,7 @@ set(SRC
   sculpt.c
   sculpt_automasking.c
   sculpt_boundary.c
+  sculpt_brushes.c
   sculpt_cloth.c
   sculpt_detail.c
   sculpt_dyntopo.c
@@ -71,6 +72,7 @@ set(SRC
   sculpt_mask_expand.c
   sculpt_mask_init.c
   sculpt_multiplane_scrape.c
+  sculpt_ops.c
   sculpt_paint_color.c
   sculpt_pose.c
   sculpt_smooth.c
diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h
index 90887b9fc39..09ef1930736 100644
--- a/source/blender/editors/sculpt_paint/paint_intern.h
+++ b/source/blender/editors/sculpt_paint/paint_intern.h
@@ -26,6 +26,8 @@
 #include "BKE_paint.h"
 
 #include "BLI_rect.h"
+#include "BLI_compiler_compat.h"
+#include "BLI_math.h"
 
 #include "DNA_scene_types.h"
 
@@ -404,8 +406,61 @@ bool facemask_paint_poll(struct bContext *C);
 /**
  * Uses symm to selectively flip any axis of a coordinate.
  */
-void flip_v3_v3(float out[3], const float in[3], const enum ePaintSymmetryFlags symm);
-void flip_qt_qt(float out[4], const float in[4], const enum ePaintSymmetryFlags symm);
+
+BLI_INLINE void flip_v3_v3(float out[3], const float in[3], const ePaintSymmetryFlags symm)
+{
+  if (symm & PAINT_SYMM_X) {
+    out[0] = -in[0];
+  }
+  else {
+    out[0] = in[0];
+  }
+  if (symm & PAINT_SYMM_Y) {
+    out[1] = -in[1];
+  }
+  else {
+    out[1] = in[1];
+  }
+  if (symm & PAINT_SYMM_Z) {
+    out[2] = -in[2];
+  }
+  else {
+    out[2] = in[2];
+  }
+}
+
+BLI_INLINE void flip_qt_qt(float out[4], const float in[4], const ePaintSymmetryFlags symm)
+{
+  float axis[3], angle;
+
+  quat_to_axis_angle(axis, &angle, in);
+  normalize_v3(axis);
+
+  if (symm & PAINT_SYMM_X) {
+    axis[0] *= -1.0f;
+    angle *= -1.0f;
+  }
+  if (symm & PAINT_SYMM_Y) {
+    axis[1] *= -1.0f;
+    angle *= -1.0f;
+  }
+  if (symm & PAINT_SYMM_Z) {
+    axis[2] *= -1.0f;
+    angle *= -1.0f;
+  }
+
+  axis_angle_normalized_to_quat(out, axis, angle);
+}
+
+BLI_INLINE void flip_v3(float v[3], const ePaintSymmetryFlags symm)
+{
+  flip_v3_v3(v, v, symm);
+}
+
+BLI_INLINE void flip_qt(float quat[4], const ePaintSymmetryFlags symm)
+{
+  flip_qt_qt(quat, quat, symm);
+}
 
 /* stroke operator */
 typedef enum BrushStrokeMode {
diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c
index 541893f7957..95a0aba1ffb 100644
--- a/source/blender/editors/sculpt_paint/paint_utils.c
+++ b/source/blender/editors/sculpt_paint/paint_utils.c
@@ -397,51 +397,6 @@ static Image *imapaint_face_image(Object *ob, Mesh *me, int face_index)
   return ima;
 }
 
-void flip_v3_v3(float out[3], const float in[3], const ePaintSymmetryFlags symm)
-{
-  if (symm & PAINT_SYMM_X) {
-    out[0] = -in[0];
-  }
-  else {
-    out[0] = in[0];
-  }
-  if (symm & PAINT_SYMM_Y) {
-    out[1] = -in[1];
-  }
-  else {
-    out[1] = in[1];
-  }
-  if (symm & PAINT_SYMM_Z) {
-    out[2] = -in[2];
-  }
-  else {
-    out[2] = in[2];
-  }
-}
-
-void flip_qt_qt(float out[4], const float in[4], const ePaintSymmetryFlags symm)
-{
-  float axis[3], angle;
-
-  quat_to_axis_angle(axis, &angle, in);
-  normalize_v3(axis);
-
-  if (symm & PAINT_SYMM_X) {
-    axis[0] *= -1.0f;
-    angle *= -1.0f;
-  }
-  if (symm & PAINT_SYMM_Y) {
-    axis[1] *= -1.0f;
-    angle *= -1.0f;
-  }
-  if (symm & PAINT_SYMM_Z) {
-    axis[2] *= -1.0f;
-    angle *= -1.0f;
-  }
-
-  axis_angle_normalized_to_quat(out, axis, angle);
-}
-
 void paint_sample_color(
     bContext *C, ARegion *region, int x, int y, bool texpaint_proj, bool use_palette)
 {
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index b764d0e1b5b..19189fdc6c9 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -1329,103 +1329,6 @@ static void sculpt_rake_data_update(struct SculptRakeData *srd, const float co[3
   }
 }
 
-static void sculpt_rake_rotate(const SculptSession *ss,
-                               const float sculpt_co[3],
-                               const float v_co[3],
-                               float factor,
-                               float r_delta[3])
-{
-  float vec_rot[3];
-
-#if 0
-  /* lerp */
-  sub_v3_v3v3(vec_rot, v_co, sculpt_co);
-  mul_qt_v3(ss->cache->rake_rotation_symmetry, vec_rot);
-  add_v3_v3(vec_rot, sculpt_co);
-  sub_v3_v3v3(r_delta, vec_rot, v_co);
-  mul_v3_fl(r_delta, factor);
-#else
-  /* slerp */
-  float q_interp[4];
-  sub_v3_v3v3(vec_rot, v_co, sculpt_co);
-
-  copy_qt_qt(q_interp, ss->cache->rake_rotation_symmetry);
-  pow_qt_fl_normalized(q_interp, factor);
-  mul_qt_v3(q_interp, vec_rot);
-
-  add_v3_v3(vec_rot, sculpt_co);
-  sub_v3_v3v3(r_delta, vec_rot, v_co);
-#endif
-}
-
-/**
- * Align the grab delta to the brush normal.
- *
- * \param grab_delta: Typically from `ss->cache->grab_delta_symmetry`.
- */
-static void sculpt_project_v3_normal_align(SculptSession *ss,
-                                           const float normal_weight,
-                                           float grab_delta[3])
-{
-  /* Signed to support grabbing in (to make a hole) as well as out. */
-  const float len_signed = dot_v3v3(ss->cache->sculpt_normal_symm, grab_delta);
-
-  /* This scale effectively projects the offset so dragging follows the cursor,
-   * as the normal points towards the view, the scale increases. */
-  float len_view_scale;
-  {
-    float view_aligned_normal[3];
-    project_plane_v3_v3v3(
-        view_aligned_normal, ss->cache->sculpt_normal_symm, ss->cache->view_normal);
-    len_view_scale = fabsf(dot_v3v3(view_aligned_normal, ss->cache->sculpt_normal_symm));
-    len_view_scale = (len_view_scale > FLT_EPSILON) ? 1.0f / len_view_scale : 1.0f;
-  }
-
-  mul_v3_fl(grab_delta, 1.0f - normal_weight);
-  madd_v3_v3fl(
-      grab_delta, ss->cache->sculpt_normal_symm, (len_signed * normal_weight) * len_view_scale);
-}
-
-/** \} */
-
-/* -------------------------------------------------------------------- */
-/** \name SculptProjectVector
- *
- * Fast-path for #project_plane_v3_v3v3
- * \{ */
-
-typedef struct SculptProjectVector {
-  float plane[3];
-  float len_sq;
-  float len_sq_inv_neg;
-  bool is_valid;
-
-} SculptProjectVector;
-
-/**
- * \param plane: Direction, can be any length.
- */
-static void sculpt_project_v3_cache_init(SculptProjectVector *spvc, const float plane[3])
-{
-  copy_v3_v3(spvc->plane, plane);
-  spvc->len_sq = len_squared_v3(spvc->plane);
-  spvc->is_valid = (spvc->len_sq > FLT_EPSILON);
-  spvc->len_sq_inv_neg = (spvc->is_valid) ? -1.0f / spvc->len_sq : 0.0f;
-}
-
-/**
- * Calculate the projection.
- */
-static void sculpt_project_v3(const SculptProjectVector *spvc, const float vec[3], float r_vec[3])
-{
-#if 0
-  project_plane_v3_v3v3(r_vec, vec, spvc->plane);
-#else
-  /* inline the projection, cache `-1.0 / dot_v3_v3(v_proj, v_proj)` */
-  madd_v3_v3fl(r_vec, spvc->plane, dot_v3v3(vec, spvc->plane) * spvc->len_sq_inv_neg);
-#endif
-}
-
 /** \} */
 
 /* -------------------------------------------------------------------- */
@@ -1835,15 +1738,6 @@ static bool sculpt_brush_test_cyl(SculptBrushTest *test,
 
 /* ===== Sculpting =====
  */
-static void flip_v3(float v[3], const ePaintSymmetryFlags symm)
-{
-  flip_v3_v3(v, v, symm);
-}
-
-static void flip_qt(float quat[4], const ePaintSymmetryFlags symm)
-{
-  flip_qt_qt(quat, quat, symm);
-}
 
 static float calc_overlap(StrokeCache *cache, const char symm, const char axis, const float angle)
 {
@@ -1913,9 +1807,9 @@ static float calc_symmetry_feather(Sculpt *sd, StrokeCache *cache)
  * (optionally using original coordinates).
  *
  * Functions are:
- * - #calc_area_center
- * - #calc_area_normal
- * - #calc_area_normal_and_center
+ * - #SCULPT_calc_area_center
+ * - #SCULPT_calc_area_normal
+ * - #SCULPT_calc_area_normal_and_center
  *
  * \note These are all _very_ similar, when changing one, check others.
  * \{ */
@@ -2137,7 +2031,7 @@ static void calc_area_normal_and_center_reduce(const void *__restrict UNUSED(use
   add_v2_v2_int(join->count_co, anctd->count_co);
 }
 
-static void calc_area_center(
+void SCULPT_calc_area_center(
     Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float r_area_co[3])
 {
   const Brush *brush = BKE_paint_brush(&sd->paint);
@@ -2238,7 +2132,7 @@ bool SCULPT_pbvh_calc_area_normal(const Brush *brush,
  * This calculates flatten center and area normal together,
  * amortizing the memory bandwidth and loop overhead to calculate both at the same time.
  */
-static void calc_area_normal_and_center(
+void SCULPT_calc_area_normal_and_center(
     Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float r_area_no[3], float r_area_co[3])
 {
   const Brush *brush = BKE_paint_brush(&sd->paint);
@@ -2856,10 +2750,6 @@ static void update_brush_local_mat(Sculpt *sd, Object *ob)
 
 /** \} */
 
-/* -------------------------------------------------------------------- */
-/** \name Sculpt Topology Rake (Shared Utility)
- * \{ */
-
 typedef struct {
   SculptSession *ss;
   const float *ray_start;
@@ -2885,109 +2775,193 @@ typedef struct {
   bool original;
 } SculptFindNearestToRayData;
 
-static void do_topology_rake_bmesh_task_cb_ex(void *__restrict userdata,
-                                              const int n,
-                                              const TaskParallelTLS *__restrict tls)
-{
-  SculptThreadedTaskData *data = userdata;
-  SculptSession *ss = data->ob->sculpt;
-  Sculpt *sd = data->sd;
-  const Brush *brush = data->brush;
 
-  float direction[3];
-  copy_v3_v3(direction, ss->cache->grab_delta_symmetry);
+ePaintSymmetryAreas SCULPT_get_vertex_symm_area(const float co[3])
+{
+  ePaintSymmetryAreas symm_area = PAINT_SYMM_AREA_DEFAULT;
+  if (co[0] < 0.0f) {
+    symm_area |= PAINT_SYMM_AREA_X;
+  }
+  if (co[1] < 0.0f) {
+    symm_area |= PAINT_SYMM_AREA_Y;
+  }
+  if (co[2] < 0.0f) {
+    symm_area |= PAINT_SYMM_AREA_Z;
+  }
+  return symm_area;
+}
 
-  float tmp[3];


@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list