Commit: b7ad3ea653d4b118d31d5c256997b6fcb2aed720
Author: Joshua Leung
Date:   Fri Nov 3 03:45:30 2017 +1300
Branches: greasepencil-object
https://developer.blender.org/rBb7ad3ea653d4b118d31d5c256997b6fcb2aed720

GP Modifiers - Merge Array and Duplication modifiers

Array and Duplication modifiers basically implemented the same functionality,
except that:
1) Array was slightly more powerful (i.e. it could make a 3D grid instead of
   just putting everything in a single line), and
2) Array created new objects when "Applying", while Duplication added to the
   current datablock

This commit basically merges the functionality of both into the Array modifier.
I ended up recoding this modifier to hopefully work a lot faster.
* The resulting modifier more closely resembles the behaviour of the normal
  Blender Array modifier.
* Performance should be better now with over 25 objects (previous array modifier
  implementation lagged badly with more than 25-30 instances). The previous 
approach
  of manually creating objects didn't work too well.

TODO:
* The functionality to disable the instance creation when the simplify options
  are enabled is currently lost. Still need to figure out how to restore it
* The stubs/shell for the old Duplication modifier are still around. To be 
removed!

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

M       release/scripts/startup/bl_ui/properties_data_modifier.py
M       source/blender/blenkernel/BKE_gpencil.h
M       source/blender/blenkernel/intern/gpencil_modifier.c
M       source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
M       source/blender/draw/engines/gpencil/gpencil_engine.c
M       source/blender/draw/engines/gpencil/gpencil_engine.h
M       source/blender/makesdna/DNA_modifier_types.h
M       source/blender/makesrna/intern/rna_modifier.c
M       source/blender/modifiers/intern/MOD_gpencilarray.c
M       source/blender/modifiers/intern/MOD_gpencildupli.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py 
b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 7491d8170a7..d5cc261040c 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1741,6 +1741,18 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         row.prop(md, "random_scale", text="", icon="TIME", toggle=True)
         row.prop(md, "scale_factor", text="")
 
+        split = layout.split()
+        col = split.column()
+        col.label("Layer:")
+        row = col.row(align=True)
+        row.prop_search(md, "layer", gpd, "layers", text="", 
icon="GREASEPENCIL")
+        row.prop(md, "inverse_layers", text="", icon="ARROW_LEFTRIGHT")
+        row = col.row(align=True)
+        row.prop(md, "pass_index", text="Pass")
+        row.prop(md, "inverse_pass", text="", icon="ARROW_LEFTRIGHT")
+
+        row.row(md, "use_make_objects")
+
     def GP_DUPLI(self, layout, ob, md):
         gpd = ob.grease_pencil
         layout.prop(md, "count")
diff --git a/source/blender/blenkernel/BKE_gpencil.h 
b/source/blender/blenkernel/BKE_gpencil.h
index d2de9597a2f..da4b5cfad60 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -202,8 +202,6 @@ void BKE_gpencil_geometry_modifiers(struct Object *ob, 
struct bGPDlayer *gpl, st
 void BKE_gpencil_stroke_normal(const struct bGPDstroke *gps, float 
r_normal[3]);
 
 void BKE_gpencil_simplify_modifier(int id, struct GpencilSimplifyModifierData 
*mmd, struct Object *ob, struct bGPDlayer *gpl, struct bGPDstroke *gps);
-void BKE_gpencil_array_modifier(int id, struct GpencilArrayModifierData *mmd, 
struct Object *ob, int elem_idx[3], float r_mat[4][4]);
-void BKE_gpencil_dupli_modifier(int id, struct GpencilDupliModifierData *mmd, 
struct Object *ob, struct bGPDlayer *gpl, struct bGPDframe *gpf);
 
 /* (wrapper api) simplify stroke using Ramer-Douglas-Peucker algorithm */
 void BKE_gpencil_simplify_stroke(struct bGPDlayer *gpl, struct bGPDstroke 
*gps, float factor);
diff --git a/source/blender/blenkernel/intern/gpencil_modifier.c 
b/source/blender/blenkernel/intern/gpencil_modifier.c
index 4dce7ab4b36..61170d88a6f 100644
--- a/source/blender/blenkernel/intern/gpencil_modifier.c
+++ b/source/blender/blenkernel/intern/gpencil_modifier.c
@@ -56,11 +56,6 @@
 // XXX: temp transitional code
 #include "../../modifiers/intern/MOD_gpencil_util.h"
 
-/* used to save temp strokes */
-typedef struct tGPencilStrokeCache {
-       struct bGPDstroke *gps;
-       int idx;
-} tGPencilStrokeCache;
 
 /* temp data for simplify modifier */
 typedef struct tbGPDspoint {
@@ -98,154 +93,7 @@ void BKE_gpencil_stroke_normal(const bGPDstroke *gps, float 
r_normal[3])
        normalize_v3(r_normal);
 }
 
-/* helper function to sort strokes using qsort */
-static int gpencil_stroke_cache_compare(const void *a1, const void *a2)
-{
-       const tGPencilStrokeCache *ps1 = a1, *ps2 = a2;
-
-       if (ps1->idx < ps2->idx) return -1;
-       else if (ps1->idx > ps2->idx) return 1;
-
-       return 0;
-}
 
-/* dupli modifier */
-void BKE_gpencil_dupli_modifier(
-        int id, GpencilDupliModifierData *mmd, Object *UNUSED(ob), bGPDlayer 
*gpl, bGPDframe *gpf)
-{
-       bGPDspoint *pt;
-       bGPDstroke *gps_dst;
-       struct tGPencilStrokeCache *stroke_cache, *p = NULL;
-       float offset[3], rot[3], scale[3];
-       float mat[4][4];
-       float factor;
-       int ri;
-
-       /* create cache for sorting */
-       int totstrokes = BLI_listbase_count(&gpf->strokes);
-       int cachesize =  totstrokes * mmd->count;
-       p = MEM_callocN(sizeof(struct tGPencilStrokeCache) * cachesize, 
"tGPencilStrokeCache");
-       if (p) {
-               stroke_cache = p;
-       }
-       else {
-               return;
-       }
-
-       int stroke = 0;
-       int idx = 0;
-       for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
-               stroke++;
-               if (!is_stroke_affected_by_modifier(
-                       mmd->layername, mmd->pass_index, 1, gpl, gps,
-                       mmd->flag & GP_DUPLI_INVERSE_LAYER, mmd->flag & 
GP_DUPLI_INVERSE_PASS))
-               {
-                       continue;
-               }
-
-               for (int e = 0; e < mmd->count; e++) {
-                       /* duplicate stroke */
-                       gps_dst = MEM_dupallocN(gps);
-                       if (id > -1) {
-                               gps_dst->palcolor = 
MEM_dupallocN(gps->palcolor);
-                       }
-                       gps_dst->points = MEM_dupallocN(gps->points);
-                       BKE_gpencil_stroke_weights_duplicate(gps, gps_dst);
-
-                       gps_dst->triangles = MEM_dupallocN(gps->triangles);
-
-                       /* add to array for sorting later */
-                       stroke_cache[idx].gps = gps_dst;
-                       stroke_cache[idx].idx = (e * 100000) + stroke;
-
-                       mul_v3_v3fl(offset, mmd->offset, e + 1);
-                       ri = mmd->rnd[0];
-                       /* rotation */
-                       if (mmd->flag & GP_DUPLI_RANDOM_ROT) {
-                               factor = mmd->rnd_rot * mmd->rnd[ri];
-                               mul_v3_v3fl(rot, mmd->rot, factor);
-                               add_v3_v3(rot, mmd->rot);
-                       }
-                       else {
-                               copy_v3_v3(rot, mmd->rot);
-                       }
-                       /* scale */
-                       if (mmd->flag & GP_DUPLI_RANDOM_SIZE) {
-                               factor = mmd->rnd_size * mmd->rnd[ri];
-                               mul_v3_v3fl(scale, mmd->scale, factor);
-                               add_v3_v3(scale, mmd->scale);
-                       }
-                       else {
-                               copy_v3_v3(scale, mmd->scale);
-                       }
-                       /* move random index */
-                       mmd->rnd[0]++;
-                       if (mmd->rnd[0] > 19) {
-                               mmd->rnd[0] = 1;
-                       }
-
-                       loc_eul_size_to_mat4(mat, offset, rot, scale);
-
-                       /* move points */
-                       for (int i = 0; i < gps->totpoints; i++) {
-                               pt = &gps_dst->points[i];
-                               mul_m4_v3(mat, &pt->x);
-                       }
-                       idx++;
-               }
-       }
-       /* sort by idx */
-       qsort(stroke_cache, idx, sizeof(tGPencilStrokeCache), 
gpencil_stroke_cache_compare);
-       
-       /* add to listbase */
-       for (int i = 0; i < idx; i++) {
-               BLI_addtail(&gpf->strokes, stroke_cache[i].gps);
-       }
-
-       /* free memory */
-       MEM_SAFE_FREE(stroke_cache);
-}
-
-/* array modifier */
-void BKE_gpencil_array_modifier(
-        int UNUSED(id), GpencilArrayModifierData *mmd, Object *UNUSED(ob), int 
elem_idx[3], float r_mat[4][4])
-{
-       float offset[3], rot[3], scale[3];
-       float factor;
-       int ri;
-
-       offset[0] = mmd->offset[0] * elem_idx[0];
-       offset[1] = mmd->offset[1] * elem_idx[1];
-       offset[2] = mmd->offset[2] * elem_idx[2];
-
-       ri = mmd->rnd[0];
-       /* rotation */
-       if (mmd->flag & GP_ARRAY_RANDOM_ROT) {
-               factor = mmd->rnd_rot * mmd->rnd[ri];
-               mul_v3_v3fl(rot, mmd->rot, factor);
-               add_v3_v3(rot, mmd->rot);
-       }
-       else {
-               copy_v3_v3(rot, mmd->rot);
-       }
-       /* scale */
-       if (mmd->flag & GP_ARRAY_RANDOM_SIZE) {
-               factor = mmd->rnd_size * mmd->rnd[ri];
-               mul_v3_v3fl(scale, mmd->scale, factor);
-               add_v3_v3(scale, mmd->scale);
-       }
-       else {
-               copy_v3_v3(scale, mmd->scale);
-       }
-       /* move random index */
-       mmd->rnd[0]++;
-       if (mmd->rnd[0] > 19) {
-               mmd->rnd[0] = 1;
-       }
-       /* calculate matrix */
-       loc_eul_size_to_mat4(r_mat, offset, rot, scale);
-
-}
 
 /* init lattice deform data */
 void BKE_gpencil_lattice_init(Object *ob)
@@ -526,11 +374,6 @@ bool BKE_gpencil_has_geometry_modifiers(Object *ob)
                if (mti->generateStrokes) {
                        return true;
                }
-                       
-               // XXX: Remove
-               if (md->type == eModifierType_GpencilDupli) {
-                       return true;
-               }
        }
        return false;
 }
@@ -596,14 +439,6 @@ void BKE_gpencil_geometry_modifiers(Object *ob, bGPDlayer 
*gpl, bGPDframe *gpf)
                                EvaluationContext eval_ctx = {0}; /* XXX */
                                mti->generateStrokes(md, &eval_ctx, ob, gpl, 
gpf, id);
                        }
-
-                       // XXX: The following lines need to all be converted to 
modifier callbacks...
-                       switch (md->type) {
-                               // Array
-                               case eModifierType_GpencilDupli:
-                                       BKE_gpencil_dupli_modifier(id, 
(GpencilDupliModifierData *)md, ob, gpl, gpf);
-                                       break;
-                       }
                }
                id++;
        }
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c 
b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
index 4df3eb49b5d..8557ccad3cd 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -1196,63 +1196,4 @@ struct GPUTexture *DRW_gpencil_create_blank_texture(int 
width, int height)
        return tex;
 }
 
-/* create instances using array modifiers */
-void gpencil_array_modifiers(GPENCIL_StorageList *stl, Object *ob)
-{
-       ModifierData *md;
-       GpencilArrayModifierData *mmd;
-       Object *newob = NULL;
-       bGPdata *gpd = NULL;
-       int x, y, z;
-       int xyz[3];
-       int sh;
-       float mat[4][4];
-
-       if ((ob) && (ob->data)) {
-               gpd = ob->data;
-               if (GPENCIL_ANY_EDIT_MODE(gpd)) {
-                       return;
-               }
-       }
-
-       for (md = ob->modifiers.first; md; md = md->next) {
-               if (((md->mode & eModifierMode_Realtime) && ((G.f & 
G_RENDER_OGL) == 0)) ||
-                   ((md->mode & eModifierMode_Render) && (G.f & G_RENDER_OGL)))
-               {
-                       if (md->type == eModifierType_GpencilArray) {
-                               mmd = (GpencilArrayModifierData *)md;
-                               /* reset random */
-                               mmd->rnd[0] = 1;
-                               for (x = 0; x < mmd->count[0]; x++) {
-                                       for (y = 0; y < mmd->count[1]; y++) {
-                                               for (z = 0; z < mmd->count[2]; 
z++) {
-                                                       ARRAY_SET_ITEMS(xyz, x, 
y, z);
-                                                       if ((x == 0) && (y == 
0) && (z == 0)) {
-                                                               continue;
-                                                       }
-                                                       
BKE_gpencil_array_modifier(0, mmd, ob, xyz, mat);
-                                                       /* add object to cache 
*/
-                                                       newob = 
MEM_dupallocN(ob);
-                                                       newob->mode = -1; /* 
use this mark to delete later */
-                                                       
mul_m4_m4m4(newob->obmat, mat, ob->obmat);
-                                                       /* apply scale */
-                                                       
ARRAY_SET_ITEMS(newob->size, mat[0][0], mat[1][1], mat[2][2]);
-                                                       /* apply shift */
-                                                       sh = x;
-                                                       if (mmd->lock_axis == 
GP_LOCKAXIS_Y) {
-                                                               sh = y;
-                                                       }
-                                                       if (mmd->lock_axis == 
GP_LOCKAXIS_Z) {
-                                                               sh = z;
-                                                       }
-                                                       
madd_v3_v3fl(newob->obmat[3], mmd->shift, sh);
-                                                       
stl->g_data->gp_object_cache = 
gpencil_object_cache_allocate(stl->g_data->gp_object_cache, 
&stl->g_data->gp_cache_size, &stl->g_data->gp_cache_used);
-                                                       
gpencil_object_cache_add(stl->g_data->gp_object_cache, newob, 
&stl->g_data->gp_cache_used);
-                                               }
-                                       }
-                               }
-                       }
-               }
-       }
 
-}
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c 
b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 56d5c6da7ff..1e114b74ab7 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -410,10 +410,6 @@ static void GPENCIL_cache_populate(void *vedata, Object 
*ob)
                        stl->g_data->gp_object_cache = 
gpencil_object_cache_allocate(stl->g_data->gp_object_cache, 
&stl->g_data->gp_cache_size, &

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to