Commit: 442d3f2697d179fbbf97923dcfcfbc781b111e40
Author: Joshua Leung
Date:   Fri Nov 3 16:52:02 2017 +1300
Branches: greasepencil-object
https://developer.blender.org/rB442d3f2697d179fbbf97923dcfcfbc781b111e40

GP Array Modifier: Bring back draw-engine hack for array modifier drawing

This time, it only runs when "Make Objects" is enabled on a modifier,
giving users a workaround for the z-ordering problems.

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

M       release/scripts/startup/bl_ui/properties_data_modifier.py
M       source/blender/blenkernel/BKE_gpencil.h
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/makesrna/intern/rna_modifier.c
M       source/blender/modifiers/intern/MOD_gpencilarray.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py 
b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 910b83fde70..222c1542270 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1710,9 +1710,9 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
     def GP_ARRAY(self, layout, ob, md):
         gpd = ob.data
 
-        split = layout.split()
-        col = split.column()
+        col = layout.column()
         col.prop(md, "count")
+        col.prop(md, "use_make_objects")
 
         split = layout.split()
         col = split.column()
@@ -1725,8 +1725,7 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         row = col.row(align=True)
         row.prop(md, "lock_axis", expand=True)
 
-        row = layout.row()
-        split = row.split()
+        split = layout.split()
         col = split.column()
         col.label("Rotation:")
         col.prop(md, "rotation", text="")
@@ -1753,8 +1752,6 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         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.data
         layout.prop(md, "count")
diff --git a/source/blender/blenkernel/BKE_gpencil.h 
b/source/blender/blenkernel/BKE_gpencil.h
index da4b5cfad60..dd48baec407 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -201,6 +201,8 @@ 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_array_modifier_instance_tfm(struct GpencilArrayModifierData 
*mmd, const int elem_idx[3], float r_mat[4][4]);
+
 void BKE_gpencil_simplify_modifier(int id, struct GpencilSimplifyModifierData 
*mmd, struct Object *ob, struct bGPDlayer *gpl, struct bGPDstroke *gps);
 
 /* (wrapper api) simplify stroke using Ramer-Douglas-Peucker algorithm */
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 8557ccad3cd..2fded6402fd 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -1196,4 +1196,83 @@ struct GPUTexture *DRW_gpencil_create_blank_texture(int 
width, int height)
        return tex;
 }
 
+/* Helper for gpencil_array_modifiers()
+ * See also MOD_gpencilarray.c -> bakeModifierGP()
+ */
+static void gp_array_modifier_make_instances(GPENCIL_StorageList *stl, Object 
*ob, GpencilArrayModifierData *mmd)
+{
+       /* reset random */
+       mmd->rnd[0] = 1;
+       
+       /* Generate instances */
+       for (int x = 0; x < mmd->count[0]; x++) {
+               for (int y = 0; y < mmd->count[1]; y++) {
+                       for (int z = 0; z < mmd->count[2]; z++) {
+                               Object *newob;
+                               
+                               const int elem_idx[3] = {x, y, z};
+                               float mat[4][4];
+                               int sh;
+                               
+                               /* original strokes are at index = 0,0,0 */
+                               if ((x == 0) && (y == 0) && (z == 0)) {
+                                       continue;
+                               }
+                               
+                               /* compute transform for instance */
+                               BKE_gpencil_array_modifier_instance_tfm(mmd, 
elem_idx, 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);
+                               
+                               /* add temp object to cache */
+                               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);
+                       }
+               }
+       }
+}
+
+/* create instances using array modifiers */
+void gpencil_array_modifiers(GPENCIL_StorageList *stl, Object *ob)
+{
+       if ((ob) && (ob->data)) {
+               bGPdata *gpd = ob->data;
+               if (GPENCIL_ANY_EDIT_MODE(gpd)) {
+                       return;
+               }
+       }
+
+       for (ModifierData *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) {
+                               GpencilArrayModifierData *mmd = 
(GpencilArrayModifierData *)md;
+                               
+                               /* Only add instances if the "Make Objects" 
flag is set
+                                * FIXME: This is a workaround for z-ordering 
weirdness when all instances are in the same object
+                                */
+                               if (mmd->flag & GP_ARRAY_MAKE_OBJECTS) {
+                                       gp_array_modifier_make_instances(stl, 
ob, mmd);
+                               }
+                       }
+               }
+       }
+}
 
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c 
b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 1e114b74ab7..848a6982444 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -408,8 +408,16 @@ static void GPENCIL_cache_populate(void *vedata, Object 
*ob)
                        }
                        /* allocate memory for saving gp objects */
                        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);
+                       
                        /* add for drawing later */
                        gpencil_object_cache_add(stl->g_data->gp_object_cache, 
ob, &stl->g_data->gp_cache_used);
+                       
+                       /* generate instances as separate cache objects for 
array modifiers 
+                        * with the "Make as Objects" option enabled
+                        */
+                       if (!GP_SIMPLIFY_MODIF(ts, playing)) {
+                               gpencil_array_modifiers(stl, ob);
+                       }
                }
                /* draw current painting strokes */
                DRW_gpencil_populate_buffer_strokes(&e_data, vedata, ts, ob);
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h 
b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 676daaca70b..8d259fcf7ac 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -310,6 +310,8 @@ bool gpencil_can_draw_stroke(const struct bGPDstroke *gps, 
const bool onion);
 struct tGPencilObjectCache *gpencil_object_cache_allocate(struct 
tGPencilObjectCache *cache, int *gp_cache_size, int *gp_cache_used);
 void gpencil_object_cache_add(struct tGPencilObjectCache *cache, struct Object 
*ob, int *gp_cache_used);
 
+void gpencil_array_modifiers(struct GPENCIL_StorageList *stl, struct Object 
*ob);
+
 void DRW_gpencil_vfx_modifiers(int ob_idx, struct GPENCIL_e_data *e_data, 
struct GPENCIL_Data *vedata, struct Object *ob, struct tGPencilObjectCache 
*cache);
 
 #endif /* __GPENCIL_ENGINE_H__ */
diff --git a/source/blender/makesrna/intern/rna_modifier.c 
b/source/blender/makesrna/intern/rna_modifier.c
index a4e910c9d82..1ea688643c3 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -5261,6 +5261,17 @@ static void rna_def_modifier_gpencilarray(BlenderRNA 
*brna)
        RNA_def_struct_sdna(srna, "GpencilArrayModifierData");
        RNA_def_struct_ui_icon(srna, ICON_MOD_ARRAY);
 
+       prop = RNA_def_property(srna, "layer", PROP_STRING, PROP_NONE);
+       RNA_def_property_string_sdna(prop, NULL, "layername");
+       RNA_def_property_ui_text(prop, "Layer", "Layer name");
+       RNA_def_property_update(prop, 0, "rna_Modifier_gpencil_update");
+
+       prop = RNA_def_property(srna, "pass_index", PROP_INT, PROP_NONE);
+       RNA_def_property_int_sdna(prop, NULL, "pass_index");
+       RNA_def_property_range(prop, 0, 100);
+       RNA_def_property_ui_text(prop, "Pass", "Pass index");
+       RNA_def_property_update(prop, 0, "rna_Modifier_gpencil_update");
+
        prop = RNA_def_property(srna, "count", PROP_INT, PROP_XYZ);
        RNA_def_property_range(prop, 1, INT_MAX);
        RNA_def_property_ui_range(prop, 1, 1000, 1, -1);
@@ -5333,9 +5344,9 @@ static void rna_def_modifier_gpencilarray(BlenderRNA 
*brna)
        
        prop = RNA_def_property(srna, "use_make_objects", PROP_BOOLEAN, 
PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "flag", 
GP_ARRAY_MAKE_OBJECTS);
-       RNA_def_property_ui_text(prop, "Make As Objects", 
+       RNA_def_property_ui_text(prop, "Make Objects", 
                "When applying this modifier, instances get created as separate 
objects");
-       RNA_def_property_update(prop, 0, "rna_Modifier_update");
+       RNA_def_property_update(prop, 0, "rna_Modifier_gpencil_update");
 }
 
 static void rna_def_modifier_gpencildupli(BlenderRNA *brna)
diff --git a/source/blender/modifiers/intern/MOD_gpencilarray.c 
b/source/blender/modifiers/intern/MOD_gpencilarray.c
index c6344889831..131aaf24f21 100644
--- a/source/blender/modifiers/intern/MOD_gpencilarray.c
+++ b/source/blender/modifiers/intern/MOD_gpencilarray.c
@@ -73,6 +73,7 @@ static void initData(ModifierData *md)
        gpmd->rnd_rot = 0.5f;
        gpmd->rnd_size = 0.5f;
        gpmd->lock_axis |= GP_LOCKAXIS_X;
+       gpmd->flag |= GP_ARRAY_MAKE_OBJECTS;
        
        /* fill random values */
        gp_mod_fill_random_array(gpmd->rnd, 20);
@@ -87,7 +88,7 @@ static void copyData(ModifierData *md, ModifierData *target)
 /* -------------------------------- */
 
 /* helper function for per-instance positioning */
-static void gpencil_array_modifier_calc_matrix(GpencilArrayModifierData *mmd, 
const int elem_idx[3], float r_mat[4][4])
+void BKE_gpencil_array_modifier_instance_tfm(GpencilArrayModifierData *mmd, 
const int elem_idx[3], float r_mat[4][4])
 {
        float offset[3], rot[3], scale[3];
        int ri = mmd->rnd[0];
@@ -131,9 +132,9 @@ static void 
gpencil_array_modifier_calc_matrix(GpencilArrayModifierData *mmd, co
 
 /* array modifier - generate geometry callback (for viewport/rendering) */
 /* TODO: How to skip this for the simplify options?   -->  
!GP_SIMPLIFY_MODIF(ts, playing) */
-static void generateStrokes(ModifierData *md, const EvaluationContext 
*eval_ctx,
-                               Object *ob, bGPDlayer *gpl, bGPDframe *gpf,
-                               int modifier_index)
+static void generate_geometry(ModifierData *md, const EvaluationContext 
*eval_ctx,
+         

@@ 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