[Bf-blender-cvs] [746af98b002] blender-v3.3-release: Fix T102992: GPencil Array doesn't respect restriction in Offset

2023-01-12 Thread frogstomp
Commit: 746af98b0022894ae352b2d9b3e8c356f80d92aa
Author: frogstomp
Date:   Fri Dec 9 16:27:52 2022 +0100
Branches: blender-v3.3-release
https://developer.blender.org/rB746af98b0022894ae352b2d9b3e8c356f80d92aa

Fix T102992: GPencil Array doesn't respect restriction in Offset

The problem was the bounding box was calculated using
all strokes, but if a filter is added, the bounding box must
include only selected strokes.

Fix by @frogstomp

===

M   source/blender/gpencil_modifiers/intern/MOD_gpencilarray.c

===

diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilarray.c 
b/source/blender/gpencil_modifiers/intern/MOD_gpencilarray.c
index 8bb61136cc2..6a25b301c6e 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencilarray.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilarray.c
@@ -113,7 +113,45 @@ static void 
BKE_gpencil_instance_modifier_instance_tfm(Object *ob,
 zero_v3(r_mat[3]);
   }
 }
+static bool gpencil_data_selected_minmax(ArrayGpencilModifierData *mmd,
+ Object *ob,
+ float r_min[3],
+ float r_max[3])
+{
+  bGPdata *gpd = (bGPdata *)ob->data;
+  bool changed = false;
+
+  INIT_MINMAX(r_min, r_max);
+
+  if (gpd == NULL) {
+return changed;
+  }
+
+  LISTBASE_FOREACH (bGPDlayer *, gpl, >layers) {
+bGPDframe *gpf = gpl->actframe;
+
+if (gpf != NULL) {
+  LISTBASE_FOREACH (bGPDstroke *, gps, >strokes) {
+if (is_stroke_affected_by_modifier(ob,
+   mmd->layername,
+   mmd->material,
+   mmd->pass_index,
+   mmd->layer_pass,
+   1,
+   gpl,
+   gps,
+   mmd->flag & GP_ARRAY_INVERT_LAYER,
+   mmd->flag & GP_ARRAY_INVERT_PASS,
+   mmd->flag & 
GP_ARRAY_INVERT_LAYERPASS,
+   mmd->flag & 
GP_ARRAY_INVERT_MATERIAL)) {
+  changed |= BKE_gpencil_stroke_minmax(gps, false, r_min, r_max);
+}
+  }
+}
+  }
 
+  return changed;
+}
 /* array modifier - generate geometry callback (for viewport/rendering) */
 static void generate_geometry(GpencilModifierData *md,
   Depsgraph *depsgraph,
@@ -131,7 +169,7 @@ static void generate_geometry(GpencilModifierData *md,
   if (mmd->flag & GP_ARRAY_USE_RELATIVE) {
 float min[3];
 float max[3];
-if (BKE_gpencil_data_minmax(gpd, min, max)) {
+if (gpencil_data_selected_minmax(mmd, ob, min, max)) {
   sub_v3_v3v3(size, max, min);
   /* Need a minimum size (for flat drawings). */
   CLAMP3_MIN(size, 0.01f);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [7d712dcd0bb] master: Gpencil: Add offset(Location, Rotation, Scale) by Layer, Stroke and Material to Offset modifier

2023-01-05 Thread frogstomp
Commit: 7d712dcd0bbdac04c7721bd616d8abaac806b53a
Author: frogstomp
Date:   Thu Jan 5 19:20:04 2023 +0100
Branches: master
https://developer.blender.org/rB7d712dcd0bbdac04c7721bd616d8abaac806b53a

Gpencil: Add offset(Location, Rotation, Scale) by Layer, Stroke and Material to 
Offset modifier

This patch adds two new panels in which users can control
offset (position, rotation, scale) by layer and by stroke number.

Use cases:
- if you want to create array of Suzannes and place them one behind 
another, in 2d mode, Z depth will be wrong. 
In 3d mode there will be Z fighting. With combination of stroke 
and layer offset we can fight this issue without touching original drawing.
- even easier way to create 2.5d environments.. 
simply draw on layers and then displace them in one panel 
instead fiddling with every layer individually

Possible improvements:
- add offset by material slot
- add step parameter, to allow displacing groups of N strokes.

{F13129598}

Reviewed By: mendio, antoniov

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

===

M   source/blender/gpencil_modifiers/intern/MOD_gpenciloffset.c
M   source/blender/makesdna/DNA_gpencil_modifier_defaults.h
M   source/blender/makesdna/DNA_gpencil_modifier_types.h
M   source/blender/makesrna/intern/rna_gpencil_modifier.c

===

diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpenciloffset.c 
b/source/blender/gpencil_modifiers/intern/MOD_gpenciloffset.c
index 8f0abd0a88e..b1079d1b292 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpenciloffset.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpenciloffset.c
@@ -15,12 +15,16 @@
 
 #include "BLT_translation.h"
 
+#include "BLI_hash.h"
+#include "BLI_math.h"
+#include "BLI_rand.h"
 #include "DNA_defaults.h"
 #include "DNA_gpencil_modifier_types.h"
 #include "DNA_gpencil_types.h"
 #include "DNA_meshdata_types.h"
 #include "DNA_object_types.h"
 #include "DNA_screen_types.h"
+#include "RNA_access.h"
 
 #include "BKE_context.h"
 #include "BKE_deform.h"
@@ -31,6 +35,8 @@
 #include "BKE_screen.h"
 
 #include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+#include "DEG_depsgraph_query.h"
 
 #include "UI_interface.h"
 #include "UI_resources.h"
@@ -46,6 +52,8 @@ static void initData(GpencilModifierData *md)
   BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(gpmd, modifier));
 
   MEMCPY_STRUCT_AFTER(gpmd, DNA_struct_default_get(OffsetGpencilModifierData), 
modifier);
+  /* Open the first subpanel too, because it's activated by default. */
+  md->ui_expand_flag = UI_PANEL_DATA_EXPAND_ROOT | UI_SUBPANEL_DATA_EXPAND_1;
 }
 
 static void copyData(const GpencilModifierData *md, GpencilModifierData 
*target)
@@ -84,6 +92,8 @@ static void deformStroke(GpencilModifierData *md,
 
   const bool is_randomized = !(is_zero_v3(mmd->rnd_offset) && 
is_zero_v3(mmd->rnd_rot) &&
is_zero_v3(mmd->rnd_scale));
+  const bool is_general = !(is_zero_v3(mmd->loc) && is_zero_v3(mmd->rot) &&
+is_zero_v3(mmd->scale));
 
   int seed = mmd->seed;
   /* Make sure different modifiers get different seeds. */
@@ -92,8 +102,9 @@ static void deformStroke(GpencilModifierData *md,
 
   float rand[3][3];
   float rand_offset = BLI_hash_int_01(seed);
+  bGPdata *gpd = ob->data;
 
-  if (is_randomized) {
+  if (is_randomized && mmd->mode == GP_OFFSET_RANDOM) {
 /* Get stroke index for random offset. */
 int rnd_index = BLI_findindex(>strokes, gps);
 for (int j = 0; j < 3; j++) {
@@ -117,9 +128,39 @@ static void deformStroke(GpencilModifierData *md,
   }
 }
   }
+  else {
+if (is_randomized) {
+  const int step = max_ii(mmd->stroke_step, 1);
+  const int start_offset = mmd->stroke_start_offset;
+  int offset_index;
+  int offset_size;
+  float offset_factor;
+  switch (mmd->mode) {
+case GP_OFFSET_STROKE:
+  offset_size = max_ii(BLI_listbase_count(>strokes), 1);
+  offset_index = max_ii(BLI_findindex(>strokes, gps), 0);
+  break;
+case GP_OFFSET_MATERIAL:
+  offset_size = max_ii(gpd->totcol, 1);
+  offset_index = max_ii(gps->mat_nr, 0);
+  break;
+case GP_OFFSET_LAYER:
+  offset_size = max_ii(BLI_listbase_count(>layers), 1);
+  offset_index = max_ii(BLI_findindex(>layers, gpl), 0);
+  break;
+  }
 
-  bGPdata *gpd = ob->data;
-
+  offset_factor = ((offset_size - (offset_index / step + start_offset % 
offset_size) %
+  offset_size * step % off

[Bf-blender-cvs] [c4251110a97] blender-v3.4-release: Fix T102992: GPencil Array doesn't respect restriction in Offset

2022-12-14 Thread frogstomp
Commit: c4251110a973b5458ef7bf13ca88927ab1391ff9
Author: frogstomp
Date:   Fri Dec 9 16:27:52 2022 +0100
Branches: blender-v3.4-release
https://developer.blender.org/rBc4251110a973b5458ef7bf13ca88927ab1391ff9

Fix T102992: GPencil Array doesn't respect restriction in Offset

The problem was the bounding box was calculated using
all strokes, but if a filter is added, the bounding box must
include only selected strokes.

Fix by @frogstomp

===

M   source/blender/gpencil_modifiers/intern/MOD_gpencilarray.c

===

diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilarray.c 
b/source/blender/gpencil_modifiers/intern/MOD_gpencilarray.c
index e51fe8832f0..37e28268829 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencilarray.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilarray.c
@@ -113,7 +113,45 @@ static void 
BKE_gpencil_instance_modifier_instance_tfm(Object *ob,
 zero_v3(r_mat[3]);
   }
 }
+static bool gpencil_data_selected_minmax(ArrayGpencilModifierData *mmd,
+ Object *ob,
+ float r_min[3],
+ float r_max[3])
+{
+  bGPdata *gpd = (bGPdata *)ob->data;
+  bool changed = false;
+
+  INIT_MINMAX(r_min, r_max);
+
+  if (gpd == NULL) {
+return changed;
+  }
+
+  LISTBASE_FOREACH (bGPDlayer *, gpl, >layers) {
+bGPDframe *gpf = gpl->actframe;
+
+if (gpf != NULL) {
+  LISTBASE_FOREACH (bGPDstroke *, gps, >strokes) {
+if (is_stroke_affected_by_modifier(ob,
+   mmd->layername,
+   mmd->material,
+   mmd->pass_index,
+   mmd->layer_pass,
+   1,
+   gpl,
+   gps,
+   mmd->flag & GP_ARRAY_INVERT_LAYER,
+   mmd->flag & GP_ARRAY_INVERT_PASS,
+   mmd->flag & 
GP_ARRAY_INVERT_LAYERPASS,
+   mmd->flag & 
GP_ARRAY_INVERT_MATERIAL)) {
+  changed |= BKE_gpencil_stroke_minmax(gps, false, r_min, r_max);
+}
+  }
+}
+  }
 
+  return changed;
+}
 /* array modifier - generate geometry callback (for viewport/rendering) */
 static void generate_geometry(GpencilModifierData *md,
   Depsgraph *depsgraph,
@@ -131,7 +169,7 @@ static void generate_geometry(GpencilModifierData *md,
   if (mmd->flag & GP_ARRAY_USE_RELATIVE) {
 float min[3];
 float max[3];
-if (BKE_gpencil_data_minmax(gpd, min, max)) {
+if (gpencil_data_selected_minmax(mmd, ob, min, max)) {
   sub_v3_v3v3(size, max, min);
   /* Need a minimum size (for flat drawings). */
   CLAMP3_MIN(size, 0.01f);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [fe30856d83c] master: Fix T102992: GPencil Array doesn't respect restriction in Offset

2022-12-10 Thread frogstomp
Commit: fe30856d83c7794ed42141b0baa9df15463b66fa
Author: frogstomp
Date:   Fri Dec 9 16:27:52 2022 +0100
Branches: master
https://developer.blender.org/rBfe30856d83c7794ed42141b0baa9df15463b66fa

Fix T102992: GPencil Array doesn't respect restriction in Offset

The problem was the bounding box was calculated using
all strokes, but if a filter is added, the bounding box must
include only selected strokes.

Fix by @frogstomp

===

M   source/blender/gpencil_modifiers/intern/MOD_gpencilarray.c

===

diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilarray.c 
b/source/blender/gpencil_modifiers/intern/MOD_gpencilarray.c
index bde9241e4ad..e85011639c2 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencilarray.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilarray.c
@@ -113,7 +113,45 @@ static void 
BKE_gpencil_instance_modifier_instance_tfm(Object *ob,
 zero_v3(r_mat[3]);
   }
 }
+static bool gpencil_data_selected_minmax(ArrayGpencilModifierData *mmd,
+ Object *ob,
+ float r_min[3],
+ float r_max[3])
+{
+  bGPdata *gpd = (bGPdata *)ob->data;
+  bool changed = false;
+
+  INIT_MINMAX(r_min, r_max);
+
+  if (gpd == NULL) {
+return changed;
+  }
+
+  LISTBASE_FOREACH (bGPDlayer *, gpl, >layers) {
+bGPDframe *gpf = gpl->actframe;
+
+if (gpf != NULL) {
+  LISTBASE_FOREACH (bGPDstroke *, gps, >strokes) {
+if (is_stroke_affected_by_modifier(ob,
+   mmd->layername,
+   mmd->material,
+   mmd->pass_index,
+   mmd->layer_pass,
+   1,
+   gpl,
+   gps,
+   mmd->flag & GP_ARRAY_INVERT_LAYER,
+   mmd->flag & GP_ARRAY_INVERT_PASS,
+   mmd->flag & 
GP_ARRAY_INVERT_LAYERPASS,
+   mmd->flag & 
GP_ARRAY_INVERT_MATERIAL)) {
+  changed |= BKE_gpencil_stroke_minmax(gps, false, r_min, r_max);
+}
+  }
+}
+  }
 
+  return changed;
+}
 /* array modifier - generate geometry callback (for viewport/rendering) */
 static void generate_geometry(GpencilModifierData *md,
   Depsgraph *depsgraph,
@@ -131,7 +169,7 @@ static void generate_geometry(GpencilModifierData *md,
   if (mmd->flag & GP_ARRAY_USE_RELATIVE) {
 float min[3];
 float max[3];
-if (BKE_gpencil_data_minmax(gpd, min, max)) {
+if (gpencil_data_selected_minmax(mmd, ob, min, max)) {
   sub_v3_v3v3(size, max, min);
   /* Need a minimum size (for flat drawings). */
   CLAMP3_MIN(size, 0.01f);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs