[Bf-blender-cvs] [820d0867199] sculpt-dev: Array Brush: Count and deform mode brush properties

aousdfh noreply at git.blender.org
Thu Jul 15 21:12:25 CEST 2021


Commit: 820d0867199f352b6207d9adb68c0864760df631
Author: aousdfh
Date:   Wed Jul 7 03:26:52 2021 +0200
Branches: sculpt-dev
https://developer.blender.org/rB820d0867199f352b6207d9adb68c0864760df631

Array Brush: Count and deform mode brush properties

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

M	release/scripts/startup/bl_ui/properties_paint_common.py
M	source/blender/editors/sculpt_paint/sculpt_array.c
M	source/blender/makesdna/DNA_brush_enums.h
M	source/blender/makesdna/DNA_brush_types.h
M	source/blender/makesrna/intern/rna_brush.c

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

diff --git a/release/scripts/startup/bl_ui/properties_paint_common.py b/release/scripts/startup/bl_ui/properties_paint_common.py
index c31355c1f3c..0da1dce95c2 100644
--- a/release/scripts/startup/bl_ui/properties_paint_common.py
+++ b/release/scripts/startup/bl_ui/properties_paint_common.py
@@ -760,6 +760,11 @@ def brush_settings(layout, context, brush, popover=False):
             col = layout.column()
             col.prop(brush, "scene_project_direction_type")
 
+        elif sculpt_tool == 'ARRAY':
+            col = layout.column()
+            col.prop(brush, "array_deform_type")
+            col.prop(brush, "array_count")
+
         elif sculpt_tool == 'SMOOTH':
             col = layout.column()
             col.prop(brush, "smooth_deform_type")
diff --git a/source/blender/editors/sculpt_paint/sculpt_array.c b/source/blender/editors/sculpt_paint/sculpt_array.c
index f90a9ae7d42..1b4515c3954 100644
--- a/source/blender/editors/sculpt_paint/sculpt_array.c
+++ b/source/blender/editors/sculpt_paint/sculpt_array.c
@@ -196,7 +196,7 @@ static void sculpt_array_final_mesh_write(Object *ob, BMesh *final_mesh) {
   ss->needs_pbvh_rebuild = true;
 }
 
-static void sculpt_array_mesh_build(Sculpt *sd, Object *ob) {
+static void sculpt_array_mesh_build(Sculpt *sd, Object *ob, SculptArray *array) {
   Mesh *sculpt_mesh = BKE_object_get_original_mesh(ob);
   sculpt_array_datalayers_add(sculpt_mesh);
 
@@ -222,10 +222,9 @@ static void sculpt_array_mesh_build(Sculpt *sd, Object *ob) {
       continue;
     }
 
-  for (int copy_index = 0; copy_index < SCULPT_ARRAY_COUNT; copy_index++) {
+  for (int copy_index = 0; copy_index < array->num_copies; copy_index++) {
     sculpt_array_source_datalayer_update(srcbm, symm_it, copy_index);
 
-    /* TODO: ya tal */
     BM_mesh_copy_init_customdata(destbm, srcbm, &bm_mesh_allocsize_default);
   	const int opflag = (BMO_FLAG_DEFAULTS & ~BMO_FLAG_RESPECT_HIDE);
   	BMO_op_callf(srcbm, opflag, "duplicate geom=%avef dest=%p", destbm);
@@ -280,7 +279,7 @@ static void sculpt_array_init(Object *ob, SculptArray *array) {
 
 static void sculpt_array_position_in_path_search(float *r_position, float *r_direction, SculptArray *array, const int index) {
   const float path_length = array->path.points[array->path.tot_points-1].length;
-  const float step_distance = path_length / (float)SCULPT_ARRAY_COUNT;
+  const float step_distance = path_length / (float)array->num_copies;
   const float copy_distance = step_distance * (index + 1);
 
 
@@ -322,7 +321,7 @@ static void sculpt_array_linear_position_get(float *r_position, SculptArray *arr
 
 }
 
-static void sculpt_array_update_copy(StrokeCache *cache, SculptArray *array, SculptArrayCopy *copy) {
+static void sculpt_array_update_copy(StrokeCache *cache, SculptArray *array, SculptArrayCopy *copy, eBrushArrayDeformType array_type) {
   /*
   const float fade = ((float)copy->index + 1.0f) / (float)(array->num_copies);
   float delta[3];
@@ -333,13 +332,30 @@ static void sculpt_array_update_copy(StrokeCache *cache, SculptArray *array, Scu
   float copy_position[3];
   unit_m4(copy->mat);
 
-  //sculpt_array_position_in_path_search(copy->mat[3], NULL, array, copy->index);
-  
+  switch (array_type)
+  {
+  case BRUSH_ARRAY_DEFORM_LINEAR: {
+  const float fade = ((float)copy->index + 1.0f) / (float)(array->num_copies);
+  float delta[3];
+  flip_v3_v3(delta, cache->grab_delta, copy->symm_pass);
+  mul_v3_v3fl(copy->mat[3], delta, fade);
+  }
+    break;
 
+  case BRUSH_ARRAY_DEFORM_RADIAL: {
   float pos[3];
   const float fade = ((float)copy->index + 1.0f) / (float)(array->num_copies);
   copy_v3_v3(pos, cache->grab_delta);
   rotate_v3_v3v3fl(copy->mat[3], pos, cache->view_normal,  fade * M_PI * 2.0f);
+  }
+    break;
+
+  case BRUSH_ARRAY_DEFORM_PATH:
+    sculpt_array_position_in_path_search(copy->mat[3], NULL, array, copy->index);
+    break;
+  
+  }
+
  
  /*
   copy->mat[3][0] += (BLI_hash_int_01(copy->index) * 2.0f - 0.5f) * cache->radius;
@@ -357,14 +373,13 @@ static void sculpt_array_update_copy(StrokeCache *cache, SculptArray *array, Scu
 
 }
 
-
-static void sculpt_array_linear_update(Object *ob, Brush *brush, SculptArray *array) {
+static void sculpt_array_update(Object *ob, Brush *brush, SculptArray *array) {
   SculptSession *ss = ob->sculpt;
 
   /* Main symmetry pass. */
   for (int copy_index = 0; copy_index < array->num_copies; copy_index++) {
     SculptArrayCopy *copy = &array->copies[0][copy_index];
-    sculpt_array_update_copy(ss->cache, array, copy);
+    sculpt_array_update_copy(ss->cache, array, copy, brush->array_deform_type);
   }
 
   for (int symm_pass = 1; symm_pass < PAINT_SYMM_AREAS; symm_pass++) {
@@ -381,10 +396,6 @@ static void sculpt_array_linear_update(Object *ob, Brush *brush, SculptArray *ar
   }
 }
 
-static void sculpt_array_update(Object *ob, Brush *brush, SculptArray *array) {
-  sculpt_array_linear_update(ob, brush, array);
-}
-
 static void do_array_deform_task_cb_ex(void *__restrict userdata,
                                      const int n,
                                      const TaskParallelTLS *__restrict tls)
@@ -493,16 +504,21 @@ void SCULPT_do_array_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode
   SculptSession *ss = ob->sculpt;
   Brush *brush = BKE_paint_brush(&sd->paint);
 
+
+  if (brush->array_count == 0) {
+    return;
+  }
+
   if (!SCULPT_stroke_is_main_symmetry_pass(ss->cache)) {
       /* This brush manages its own symmetry. */
       return;
   }
 
   if (SCULPT_stroke_is_first_brush_step(ss->cache)) {
-    ss->cache->array = sculpt_array_cache_create(ob, SCULPT_ARRAY_COUNT);
+    ss->cache->array = sculpt_array_cache_create(ob, brush->array_count);
     sculpt_array_init(ob, ss->cache->array);
     sculpt_array_stroke_sample_add(ob, ss->cache->array);
-    sculpt_array_mesh_build(sd, ob);
+    sculpt_array_mesh_build(sd, ob, ss->cache->array);
     /* Original coordinates can't be stored yet as the SculptSession data needs to be updated after the mesh modifications performed when building the array geometry. */
 	  return;
   }
diff --git a/source/blender/makesdna/DNA_brush_enums.h b/source/blender/makesdna/DNA_brush_enums.h
index dd356c7fd8c..ab3597e10c5 100644
--- a/source/blender/makesdna/DNA_brush_enums.h
+++ b/source/blender/makesdna/DNA_brush_enums.h
@@ -268,6 +268,12 @@ typedef enum eBrushSmearDeformType {
   BRUSH_SMEAR_DEFORM_EXPAND = 2,
 } eBrushSmearDeformType;
 
+typedef enum eBrushArrayDeformType {
+  BRUSH_ARRAY_DEFORM_LINEAR = 0,
+  BRUSH_ARRAY_DEFORM_RADIAL = 1,
+  BRUSH_ARRAY_DEFORM_PATH = 2,
+} eBrushArrayDeformType;
+
 typedef enum eBrushSlideDeformType {
   BRUSH_SLIDE_DEFORM_DRAG = 0,
   BRUSH_SLIDE_DEFORM_PINCH = 1,
diff --git a/source/blender/makesdna/DNA_brush_types.h b/source/blender/makesdna/DNA_brush_types.h
index 250842e433f..75b932d5930 100644
--- a/source/blender/makesdna/DNA_brush_types.h
+++ b/source/blender/makesdna/DNA_brush_types.h
@@ -336,6 +336,10 @@ typedef struct Brush {
 
   float cloth_constraint_softbody_strength;
 
+  /* array */
+  int array_deform_type;
+  int array_count;
+
   /* smooth */
   int smooth_deform_type;
   float surface_smooth_shape_preservation;
diff --git a/source/blender/makesrna/intern/rna_brush.c b/source/blender/makesrna/intern/rna_brush.c
index a1e9614c2ed..c9d6383778f 100644
--- a/source/blender/makesrna/intern/rna_brush.c
+++ b/source/blender/makesrna/intern/rna_brush.c
@@ -2221,6 +2221,13 @@ static void rna_def_brush(BlenderRNA *brna)
       {0, NULL, 0, NULL, NULL},
   };
 
+  static const EnumPropertyItem brush_array_deform_type_items[] = {
+      {BRUSH_ARRAY_DEFORM_LINEAR, "LINEAR", 0, "Linear", ""},
+      {BRUSH_ARRAY_DEFORM_RADIAL, "RADIAL", 0, "Radial", ""},
+      {BRUSH_ARRAY_DEFORM_PATH, "PATH", 0, "Path", ""},
+      {0, NULL, 0, NULL, NULL},
+  };
+
   static const EnumPropertyItem brush_pose_origin_type_items[] = {
       {BRUSH_POSE_ORIGIN_TOPOLOGY,
        "TOPOLOGY",
@@ -2453,6 +2460,21 @@ static void rna_def_brush(BlenderRNA *brna)
       "Direction that is going to be used to project the vertices into the scene");
   RNA_def_property_update(prop, 0, "rna_Brush_update");
 
+
+  prop = RNA_def_property(srna, "array_deform_type", PROP_ENUM, PROP_NONE);
+  RNA_def_property_enum_items(prop, brush_array_deform_type_items);
+  RNA_def_property_ui_text(prop, "Deformation", "Deformation type that is used in the brush");
+  RNA_def_property_update(prop, 0, "rna_Brush_update");
+
+  prop = RNA_def_property(srna, "array_count", PROP_INT, PROP_UNSIGNED);
+  RNA_def_property_int_sdna(prop, NULL, "array_count");
+  RNA_def_property_range(prop, 1, 10000);
+  RNA_def_property_ui_range(prop, 1, 50, 1, -1);
+  RNA_def_property_ui_text(
+      prop, "Count", "Number of copies");
+  RNA_def_property_update(prop, 0, "rna_Brush_update");
+
+
   prop = RNA_def_property(srna, "jitter_unit", PROP_ENUM, PROP_NONE); /* as an enum */
   RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
   RNA_def_property_enum_items(prop, brush_jitter_unit_items);



More information about the Bf-blender-cvs mailing list