Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonioya <blendergit@gmail.com>2018-08-15 17:07:16 +0300
committerAntonioya <blendergit@gmail.com>2018-08-15 21:27:59 +0300
commit8e8d93eb86109988db44730a0107e9da9e870328 (patch)
tree7a4e317f52de4e07d3261817e55a5444be1379f2 /source/blender/gpencil_modifiers
parentbb84f7ff5f5268226b4d14e0f1e44a2579354b37 (diff)
GP: Redesign logic of drawing engine for object instance support
The initial design assumed that there was only one object for each unique name, but that was not the case when instances were created. Now, instances are supported and speed has been greatly improved when repetitions are used. As a result of this change, the option to create objects has been removed in the Instances modifier. This option was strange and was also against Blender's design rules, since a modifier should never create objects. The old functionality of the modifier can be achieved with instances. Also, several memory leakage problems that were not previously detected have been eliminated, and especially in the grid and in the drawing process Onion Skin is not supported in multi-user datablocks. Support this, makes incompatible with instances. We need find a solution in the long term, but now it's better keep disabled and make instances work. Anyway, the new instances makes unnecessary to use muli-user datablocks.
Diffstat (limited to 'source/blender/gpencil_modifiers')
-rw-r--r--source/blender/gpencil_modifiers/intern/MOD_gpencilinstance.c127
1 files changed, 5 insertions, 122 deletions
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilinstance.c b/source/blender/gpencil_modifiers/intern/MOD_gpencilinstance.c
index a35174d882f..10f96d3a22f 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencilinstance.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilinstance.c
@@ -77,7 +77,6 @@ static void initData(GpencilModifierData *md)
gpmd->rnd_rot = 0.5f;
gpmd->rnd_size = 0.5f;
gpmd->lock_axis |= GP_LOCKAXIS_X;
- gpmd->flag |= GP_INSTANCE_MAKE_OBJECTS;
/* fill random values */
BLI_array_frand(gpmd->rnd, 20, 1);
@@ -197,11 +196,10 @@ static void generate_geometry(
MEM_SAFE_FREE(valid_strokes);
}
-/* bakeModifier - "Bake to Data" Mode */
-static void bakeModifierGP_strokes(
- Depsgraph *depsgraph,
- GpencilModifierData *md, Object *ob)
+static void bakeModifier(Main *UNUSED(bmain), Depsgraph *depsgraph,
+ GpencilModifierData *md, Object *ob)
{
+
bGPdata *gpd = ob->data;
for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
@@ -213,127 +211,12 @@ static void bakeModifierGP_strokes(
/* -------------------------------- */
-/* helper to create a new object */
-static Object *array_instance_add_ob_copy(Main *bmain, Scene *scene, Object *from_ob)
-{
- Object *ob;
-
- ob = BKE_object_copy(bmain, from_ob);
- BKE_collection_object_add_from(bmain, scene, from_ob, ob);
-
- zero_v3(ob->loc);
- zero_v3(ob->rot);
-
- DEG_id_type_tag(bmain, ID_OB);
- DEG_relations_tag_update(bmain);
- DEG_id_tag_update(&scene->id, 0);
-
- return ob;
-}
-
-/* bakeModifier - "Make Objects" Mode */
-static void bakeModifierGP_objects(Main *bmain, Depsgraph *depsgraph, GpencilModifierData *md, Object *ob)
-{
- InstanceGpencilModifierData *mmd = (InstanceGpencilModifierData *)md;
- Scene *scene = DEG_get_evaluated_scene(depsgraph);
- /* reset random */
- mmd->rnd[0] = 1;
-
- /* generate instances as objects */
- 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;
- GpencilModifierData *fmd;
-
- const int elem_idx[3] = {x, y, z};
- float mat[4][4], finalmat[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_instance_modifier_instance_tfm(mmd, elem_idx, mat);
- mul_m4_m4m4(finalmat, ob->obmat, mat);
-
- /* moves to new origin */
- sh = x;
- if (mmd->lock_axis == GP_LOCKAXIS_Y) {
- sh = y;
- }
- if (mmd->lock_axis == GP_LOCKAXIS_Z) {
- sh = z;
- }
- madd_v3_v3fl(finalmat[3], mmd->shift, sh);
-
- /* Create a new object
- *
- * NOTE: Copies share the same original GP datablock
- * Artists can later user make_single_user on these
- * to make them unique (if necessary), without too
- * much extra memory usage.
- */
- newob = array_instance_add_ob_copy(bmain, scene, ob);
-
- /* remove array on destination object */
- fmd = (GpencilModifierData *)BLI_findstring(&newob->greasepencil_modifiers, md->name, offsetof(GpencilModifierData, name));
- if (fmd) {
- BLI_remlink(&newob->greasepencil_modifiers, fmd);
- BKE_gpencil_modifier_free(fmd);
- }
-
- /* copy transforms to destination object */
- copy_m4_m4(newob->obmat, finalmat);
-
- copy_v3_v3(newob->loc, finalmat[3]);
- mat4_to_eul(newob->rot, finalmat);
- mat4_to_size(newob->size, finalmat);
- }
- }
- }
-}
-
-/* -------------------------------- */
-
/* Generic "generateStrokes" callback */
static void generateStrokes(
GpencilModifierData *md, Depsgraph *depsgraph,
Object *ob, bGPDlayer *gpl, bGPDframe *gpf)
{
- InstanceGpencilModifierData *mmd = (InstanceGpencilModifierData *)md;
-
- /* When the "make_objects" flag is set, this modifier is handled as part of the
- * draw engine instead. The main benefit is that the instances won't suffer from
- * z-ordering problems.
- *
- * FIXME: Ultimately, the draw-engine hack here shouldn't be necessary, but until
- * we find a better fix to the z-ordering problems, it's better to have
- * working functionality
- */
- if ((mmd->flag & GP_INSTANCE_MAKE_OBJECTS) == 0) {
- generate_geometry(md, depsgraph, ob, gpl, gpf);
- }
-}
-
-/* Generic "bakeModifier" callback */
-static void bakeModifier(
- Main *bmain, Depsgraph *depsgraph,
- GpencilModifierData *md, Object *ob)
-{
- InstanceGpencilModifierData *mmd = (InstanceGpencilModifierData *)md;
-
- /* Create new objects or add all to current datablock.
- * Sometimes it's useful to have the option to do either of these...
- */
- if (mmd->flag & GP_INSTANCE_MAKE_OBJECTS) {
- bakeModifierGP_objects(bmain, depsgraph, md, ob);
- }
- else {
- bakeModifierGP_strokes(depsgraph, md, ob);
- }
+ generate_geometry(md, depsgraph, ob, gpl, gpf);
}
GpencilModifierTypeInfo modifierType_Gpencil_Instance = {
@@ -347,7 +230,7 @@ GpencilModifierTypeInfo modifierType_Gpencil_Instance = {
/* deformStroke */ NULL,
/* generateStrokes */ generateStrokes,
- /* bakeModifier */ bakeModifier,
+ /* bakeModifier */ bakeModifier,
/* initData */ initData,
/* freeData */ NULL,