[Bf-blender-cvs] [b2d5a0b7222] greasepencil-object: WIP: New Duplication modifier
Antonio Vazquez
noreply at git.blender.org
Sun Jul 23 17:54:37 CEST 2017
Commit: b2d5a0b72226b8fb10da85879e3cf099404d8ee7
Author: Antonio Vazquez
Date: Sat Jul 22 11:48:39 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rBb2d5a0b72226b8fb10da85879e3cf099404d8ee7
WIP: New Duplication modifier
This modifer works similar to use dupliobjects for the current GP object.
Still pending apply button.
===================================================================
M release/scripts/startup/bl_ui/properties_data_modifier.py
M source/blender/blenkernel/BKE_gpencil.h
M source/blender/blenkernel/intern/gpencil.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/RNA_access.h
M source/blender/makesrna/intern/rna_modifier.c
M source/blender/modifiers/CMakeLists.txt
M source/blender/modifiers/MOD_modifiertypes.h
A source/blender/modifiers/intern/MOD_gpencildupli.c
M source/blender/modifiers/intern/MOD_util.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 071269967f0..7bdd8b4b20f 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1649,6 +1649,33 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
row.prop(md, "random_scale", text="", icon="TIME", toggle=True)
row.prop(md, "scale_factor", text="")
+ def GP_DUPLI(self, layout, ob, md):
+ split = layout.split()
+ col = split.column()
+ col.prop(md, "count")
+
+ col = split.column()
+ col.label("Offset:")
+ col.prop(md, "offset", text="")
+
+ row = layout.row()
+ split = row.split()
+ col = split.column()
+ col.label("Rotation:")
+ col.prop(md, "rotation", text="")
+ col.separator()
+ row = col.row(align=True)
+ row.prop(md, "random_rot", text="", icon="TIME", toggle=True)
+ row.prop(md, "rot_factor", text="")
+
+ col = split.column()
+ col.label("Scale:")
+ col.prop(md, "scale", text="")
+ col.separator()
+ row = col.row(align=True)
+ row.prop(md, "random_scale", text="", icon="TIME", toggle=True)
+ row.prop(md, "scale_factor", text="")
+
classes = (
DATA_PT_modifiers,
)
diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index c4d134472ef..a14e7a91e2a 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -48,6 +48,7 @@ struct GpencilSubdivModifierData;
struct GpencilThickModifierData;
struct GpencilTintModifierData;
struct GpencilArrayModifierData;
+struct GpencilDupliModifierData;
/* ------------ Grease-Pencil API ------------------ */
@@ -150,5 +151,6 @@ void ED_gpencil_subdiv_modifier(int id, struct GpencilSubdivModifierData *mmd, s
void ED_gpencil_thick_modifier(int id, struct GpencilThickModifierData *mmd, struct bGPDlayer *gpl, struct bGPDstroke *gps);
void ED_gpencil_tint_modifier(int id, struct GpencilTintModifierData *mmd, struct bGPDlayer *gpl, struct bGPDstroke *gps);
void ED_gpencil_array_modifier(int id, struct GpencilArrayModifierData *mmd, struct bGPDlayer *gpl, struct bGPDframe *gpf);
+void ED_gpencil_dupli_modifier(int id, struct GpencilDupliModifierData *mmd, struct Object *ob, int elem_idx[3], float r_mat[4][4]);
#endif /* __BKE_GPENCIL_H__ */
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 33d76ce47a3..a5b12176cab 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -1997,6 +1997,50 @@ void ED_gpencil_array_modifier(int id, GpencilArrayModifierData *mmd, bGPDlayer
MEM_SAFE_FREE(stroke_cache);
}
+/* duplication modifier */
+void ED_gpencil_dupli_modifier(int UNUSED(id), GpencilDupliModifierData *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];
+
+ //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) {
+ 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;
+ }
+ /* calculate matrix */
+ loc_eul_size_to_mat4(r_mat, offset, rot, scale);
+
+}
+
/* reset modifiers */
void ED_gpencil_reset_modifiers(Object *ob)
{
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 9a81891015f..1afd7dab754 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -35,6 +35,7 @@
#include "DNA_gpencil_types.h"
#include "DNA_view3d_types.h"
+#include "DNA_modifier_types.h"
/* If builtin shaders are needed */
#include "GPU_shader.h"
@@ -831,3 +832,41 @@ struct GPUTexture *DRW_gpencil_create_blank_texture(int width, int height)
return tex;
}
+
+/* create instances using duplication modifiers */
+void gpencil_dupli_modifiers(GPENCIL_StorageList *stl, Object *ob)
+{
+ ModifierData *md;
+ GpencilDupliModifierData *mmd;
+ Object *newob = NULL;
+ int x, y, z;
+ int xyz[3];
+ float mat[4][4];
+
+ for (md = ob->modifiers.first; md; md = md->next) {
+ if (md->type == eModifierType_GpencilDupli) {
+ mmd = (GpencilDupliModifierData *)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;
+ }
+
+ ED_gpencil_dupli_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);
+ 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);
+ }
+ }
+ }
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index b696fe06e1e..e4ff5a5706a 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -224,7 +224,8 @@ 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, &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 duplicated instances using dupli modifiers */
+ gpencil_dupli_modifiers(stl, ob);
/* draw current painting strokes */
DRW_gpencil_populate_buffer_strokes(vedata, ts, ob->gpd);
}
@@ -346,6 +347,14 @@ static void GPENCIL_draw_scene(void *vedata)
DRW_draw_pass(psl->edit_pass);
}
/* free memory */
+ /* clear temp objects */
+ for (int i = 0; i < stl->g_data->gp_cache_used; ++i) {
+ Object *ob = stl->g_data->gp_object_cache[i].ob;
+ if (ob->mode == -1) {
+ MEM_SAFE_FREE(ob);
+ }
+ }
+
MEM_SAFE_FREE(stl->g_data->gp_object_cache);
/* detach temp textures */
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index cbe4fd0d19a..8488ff2fdd8 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -30,6 +30,7 @@
struct tGPspoint;
struct ModifierData;
+struct GPENCIL_StorageList;
/* TODO: these could be system parameter in userprefs screen */
#define GPENCIL_CACHE_BLOCK_SIZE 8
@@ -182,4 +183,6 @@ 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_dupli_modifiers(struct GPENCIL_StorageList *stl, struct Object *ob);
+
#endif /* __GPENCIL_ENGINE_H__ */
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 908b2127cf3..b3fba67d79a 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -92,6 +92,7 @@ typedef enum ModifierType {
eModifierType_GpencilThick = 56,
eModifierType_GpencilTint = 57,
eModifierType_GpencilArray = 58,
+ eModifierType_GpencilDupli = 59,
NUM_MODIFIER_TYPES
} ModifierType;
@@ -1706,6 +1707,24 @@ typedef enum eGpencilArray_Flag {
GP_ARRAY_INVERSE_PASS = (1 << 3),
} eGpencilArray_Flag;
+typedef struct GpencilDupliModifierData {
+ ModifierData modifier;
+ int count[3]; /* number of elements in array */
+ int flag; /* several flags */
+ float offset[3]; /* Location increments */
+ 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 */
+ char pad[4];
+} GpencilDupliModifierData;
+
+typedef enum eGpencilDupli_Flag {
+ GP_DUPLI_RANDOM_SIZE = (1 << 0),
+ GP_DUPLI_RANDOM_ROT = (1 << 1),
+} eGpencilDupli_Flag;
+
#define MOD_MESHSEQ_READ_ALL \
(MOD_MESHSEQ_READ_VERT | MOD_MESHSEQ_READ_POLY | MOD_MESHSEQ_READ_UV | MOD_MESHSEQ_READ_COLOR)
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index 6cb75c39529..1983f1528f2 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -617,6 +617,7 @@ extern StructRNA RNA_GpencilSubdivModifier;
extern StructRNA RNA_GpencilThickModifier;
extern StructRNA RNA_GpencilTintModifier;
extern StructRNA RNA_GpencilArrayModifier;
+extern StructRNA RNA_GpencilDupliModifier;
extern StructRNA RNA_TexMapping;
extern StructRNA RNA_Text;
extern StructRNA RNA_TextBox;
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/sour
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list