[Bf-blender-cvs] [20e94d7f92c] greasepencil-object: Before to swap array and dupli names

Antonio Vazquez noreply at git.blender.org
Sun Jul 23 17:54:40 CEST 2017


Commit: 20e94d7f92ca5ea94e9d4718a676b5543e8500fc
Author: Antonio Vazquez
Date:   Sun Jul 23 10:14:20 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rB20e94d7f92ca5ea94e9d4718a676b5543e8500fc

Before to swap array and dupli names

It's more logic to name Array the modifier called Dupli, so I'm going to swap the names

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

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
M	source/blender/editors/object/object_modifier.c
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesrna/intern/rna_modifier.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 7bdd8b4b20f..63103dcd2a3 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1654,10 +1654,17 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         col = split.column()
         col.prop(md, "count")
 
+        split = layout.split()
         col = split.column()
         col.label("Offset:")
         col.prop(md, "offset", text="")
 
+        col = split.column()
+        col.label("Shift:")
+        col.prop(md, "shift", text="")
+        row = col.row(align=True)
+        row.prop(md, "lock_axis", expand=True)
+
         row = layout.row()
         split = row.split()
         col = split.column()
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index a5b12176cab..8952a1f7bd1 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -2008,10 +2008,6 @@ void ED_gpencil_dupli_modifier(int UNUSED(id), GpencilDupliModifierData *mmd, Ob
 	offset[1] = mmd->offset[1] * elem_idx[1];
 	offset[2] = mmd->offset[2] * elem_idx[2];
 
-	//offset[0] = mmd->offset[0] + (mmd->offset[0] * elem_idx[0]);
-	//offset[1] = mmd->offset[1] + (mmd->offset[1] * elem_idx[1]);
-	//offset[2] = mmd->offset[2] + (mmd->offset[2] * elem_idx[2]);
-
 	ri = mmd->rnd[0];
 	/* rotation */
 	if (mmd->flag & GP_DUPLI_RANDOM_ROT) {
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 1afd7dab754..58604107fa1 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -839,7 +839,7 @@ void gpencil_dupli_modifiers(GPENCIL_StorageList *stl, Object *ob)
 	ModifierData *md;
 	GpencilDupliModifierData *mmd;
 	Object *newob = NULL;
-	int x, y, z;
+	int x, y, z, e;
 	int xyz[3];
 	float mat[4][4];
 
@@ -861,6 +861,18 @@ void gpencil_dupli_modifiers(GPENCIL_StorageList *stl, Object *ob)
 						newob = MEM_dupallocN(ob);
 						newob->mode = -1; /* use this mark to delete later */
 						mul_m4_m4m4(newob->obmat, mat, ob->obmat);
+						/* apply shift */
+						e = x;
+						if (mmd->lock_axis & GP_LOCKAXIS_Y) {
+							e = y;
+						}
+						if (mmd->lock_axis & GP_LOCKAXIS_Z) {
+							e = z;
+						}
+						newob->obmat[3][0] += mmd->shift[0] * e;
+						newob->obmat[3][1] += mmd->shift[1] * e;
+						newob->obmat[3][2] += mmd->shift[2] * e;
+
 						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/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c
index b8088042d77..4bc2a1431de 100644
--- a/source/blender/editors/object/object_modifier.c
+++ b/source/blender/editors/object/object_modifier.c
@@ -660,6 +660,11 @@ static int modifier_apply_obdata(ReportList *reports, const bContext *C, Scene *
 		DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
 	}
 	else if (ELEM(ob->type, OB_GPENCIL)) {
+		/* dupli modifier need to have bContext */
+		if (md->type = eModifierType_GpencilDupli) {
+			GpencilDupliModifierData *mmd = (GpencilDupliModifierData *)md;
+			mmd->C = C;
+		}
 		mti->applyModifier(md, C, ob, NULL, 0);
 		if (ob->gpd) {
 			BKE_gpencil_batch_cache_dirty(ob->gpd);
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index b3fba67d79a..8ff991cdb2d 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1712,12 +1712,15 @@ typedef struct GpencilDupliModifierData {
 	int count[3];                /* number of elements in array */
 	int flag;                    /* several flags */
 	float offset[3];             /* Location increments */
+	float shift[3];              /* shift increment */
 	float rnd_size;              /* random size factor */
 	float rnd_rot;               /* random size factor */
 	float rot[3];                /* Rotation changes */
 	float scale[3];              /* Scale changes */
 	float rnd[20];               /* (first element is the index) random values */
+	int  lock_axis;              /* lock shift to one axis */
 	char pad[4];
+	void *C;                     /* bContext used only for apply */
 } GpencilDupliModifierData;
 
 typedef enum eGpencilDupli_Flag {
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index 94925b9dd61..23448617d44 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -285,6 +285,13 @@ EnumPropertyItem rna_enum_axis_flag_xyz_items[] = {
 	{0, NULL, 0, NULL, NULL}
 };
 
+EnumPropertyItem rna_enum_gpencil_lockshift_items[] = {
+	{ GP_LOCKAXIS_X, "GP_LOCKAXIS_X", 0, "X", "Use X axis" },
+	{ GP_LOCKAXIS_Y, "GP_LOCKAXIS_Y", 0, "Y", "Use Y axis" },
+	{ GP_LOCKAXIS_Z, "GP_LOCKAXIS_Z", 0, "Z", "Use Z axis" },
+	{ 0, NULL, 0, NULL, NULL }
+};
+
 #ifdef RNA_RUNTIME
 
 #include "DNA_particle_types.h"
@@ -5085,6 +5092,19 @@ static void rna_def_modifier_gpencildupli(BlenderRNA *brna)
 	RNA_def_property_ui_range(prop, -FLT_MAX, FLT_MAX, 1, RNA_TRANSLATION_PREC_DEFAULT);
 	RNA_def_property_update(prop, 0, "rna_Modifier_update");
 
+	prop = RNA_def_property(srna, "shift", PROP_FLOAT, PROP_TRANSLATION);
+	RNA_def_property_float_sdna(prop, NULL, "shift");
+	RNA_def_property_ui_text(prop, "Shift", "Shiftness value");
+	RNA_def_property_ui_range(prop, -FLT_MAX, FLT_MAX, 1, RNA_TRANSLATION_PREC_DEFAULT);
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+	prop = RNA_def_property(srna, "lock_axis", PROP_ENUM, PROP_NONE);
+	RNA_def_property_enum_sdna(prop, NULL, "lock_axis");
+	RNA_def_property_enum_items(prop, rna_enum_gpencil_lockshift_items);
+	//RNA_def_property_flag(prop, PROP_ENUM_FLAG);
+	RNA_def_property_ui_text(prop, "Axis", "");
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
 	prop = RNA_def_property(srna, "rotation", PROP_FLOAT, PROP_EULER);
 	RNA_def_property_float_sdna(prop, NULL, "rot");
 	RNA_def_property_ui_text(prop, "Rotation", "Value for chages in rotation");
diff --git a/source/blender/modifiers/intern/MOD_gpencildupli.c b/source/blender/modifiers/intern/MOD_gpencildupli.c
index 1647af57746..f8c4223dbb3 100644
--- a/source/blender/modifiers/intern/MOD_gpencildupli.c
+++ b/source/blender/modifiers/intern/MOD_gpencildupli.c
@@ -35,26 +35,39 @@
 #include "DNA_gpencil_types.h"
 
 #include "BLI_utildefines.h"
+#include "BLI_math_vector.h"
+
 #include "BKE_DerivedMesh.h"
 #include "BKE_gpencil.h"
+#include "BKE_context.h"
+#include "BKE_object.h"
+#include "BKE_main.h"
+#include "BKE_scene.h"
+#include "BKE_layer.h"
+#include "BKE_collection.h"
+
+#include "DEG_depsgraph.h"
 
 #include "MOD_modifiertypes.h"
-#include "BKE_gpencil.h"
 
 static void initData(ModifierData *md)
 {
 	GpencilDupliModifierData *gpmd = (GpencilDupliModifierData *)md;
 	gpmd->count[0] = 1;
-	gpmd->count[1] = 0;
-	gpmd->count[2] = 0;
+	gpmd->count[1] = 1;
+	gpmd->count[2] = 1;
 	gpmd->offset[0] = 1.0f;
 	gpmd->offset[1] = 1.0f;
 	gpmd->offset[2] = 1.0f;
+	gpmd->shift[0] = 0.0f;
+	gpmd->shift[2] = 0.0f;
+	gpmd->shift[3] = 0.0f;
 	gpmd->scale[0] = 1.0f;
 	gpmd->scale[1] = 1.0f;
 	gpmd->scale[2] = 1.0f;
 	gpmd->rnd_rot = 0.5f;
 	gpmd->rnd_size = 0.5f;
+	gpmd->lock_axis |= GP_LOCKAXIS_X;
 	/* fill random values */
 	ED_gpencil_fill_random_array(gpmd->rnd, 20);
 	gpmd->rnd[0] = 1;
@@ -75,12 +88,47 @@ static DerivedMesh *applyModifier(ModifierData *md, struct EvaluationContext *UN
 	ModifierApplyFlag UNUSED(flag))
 {
 	GpencilDupliModifierData *mmd = (GpencilDupliModifierData *)md;
+	bContext *C = (bContext *)mmd->C;
+	Main *bmain = CTX_data_main(C);
+	Scene *scene = CTX_data_scene(C);
+	SceneLayer *sl = CTX_data_scene_layer(C);
+	SceneCollection *sc = CTX_data_scene_collection(C);
+	Object *newob = NULL;
+	Base *base_new = NULL;
+	int xyz[3];
+	float mat[4][4];
+
 	if ((!ob) || (!ob->gpd)) {
 		return NULL;
 	}
 
-	//ED_gpencil_dupli_modifier(-1, (GpencilDupliModifierData *)md, ob, 1, mat);
+	/* reset random */
+	mmd->rnd[0] = 1;
+	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) {
+				ARRAY_SET_ITEMS(xyz, x, y, z);
+				if ((x == 0) && (y == 0) && (z == 0)) {
+					continue;
+				}
+#if 0
+				ED_gpencil_dupli_modifier(0, mmd, ob, xyz, mat);
+				newob = BKE_object_add(bmain, scene, sl, OB_GPENCIL, ob->id.name);
+				//newob = BKE_object_add_only_object(bmain, OB_GPENCIL, ob->id.name);
+				newob->gpd = ob->gpd;
+				//BKE_collection_object_add(scene, sc, newob);
+				base_new = BKE_scene_layer_base_find(sl, newob);
+
+				//BKE_object_apply_mat4(newob, newob->obmat, false, false);
 
+				////mul_m4_m4m4(newob->obmat, mat, ob->obmat);
+				//DEG_id_tag_update(&newob->id, OB_RECALC_OB);
+				BKE_scene_object_base_flag_sync_from_base(base_new);
+#endif
+			}
+		}
+	}
+	//DEG_relations_tag_update(bmain);
 	return NULL;
 }




More information about the Bf-blender-cvs mailing list