[Bf-blender-cvs] [9a646b6a206] blender2.8: GP: New Armature modifier and tools to handle weights

Antonioya noreply at git.blender.org
Thu Aug 30 12:24:33 CEST 2018


Commit: 9a646b6a2060dbc3b2f4031f7933842c597d0716
Author: Antonioya
Date:   Thu Aug 30 12:22:55 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB9a646b6a2060dbc3b2f4031f7933842c597d0716

GP: New Armature modifier and tools to handle weights

This commit adds a new armature modifier for grease pencil. The deformations are done reusing the mesh deform routines.

There is also a new operator in weight paint mode to help the artist to generate weights base on armatures. This operator is required because 2D animation workflow is not equal to meshes when parent an object to armatures.

In the drawing engine has been added the option to handle the Fade object parameter used in armatures to see the strokes while move the bones.

When rename bones, all related data of grease pencil is renamed too. This not only affect new armature code, but also layers parented and hook modifiers.

Thanks @aligorith for his review and help.

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

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/blenkernel/BKE_lattice.h
M	source/blender/blenkernel/intern/armature.c
M	source/blender/blenkernel/intern/gpencil_modifier.c
M	source/blender/draw/engines/gpencil/gpencil_draw_utils.c
M	source/blender/editors/armature/armature_naming.c
M	source/blender/editors/gpencil/CMakeLists.txt
A	source/blender/editors/gpencil/gpencil_armature.c
M	source/blender/editors/gpencil/gpencil_intern.h
M	source/blender/editors/gpencil/gpencil_ops.c
M	source/blender/editors/include/ED_gpencil.h
M	source/blender/editors/object/object_relations.c
M	source/blender/editors/space_outliner/outliner_draw.c
M	source/blender/gpencil_modifiers/CMakeLists.txt
M	source/blender/gpencil_modifiers/MOD_gpencil_modifiertypes.h
M	source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c
A	source/blender/gpencil_modifiers/intern/MOD_gpencilarmature.c
M	source/blender/makesdna/DNA_gpencil_modifier_types.h
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/intern/rna_gpencil_modifier.c
M	source/blender/makesrna/intern/rna_space.c
M	source/blender/modifiers/intern/MOD_armature.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index b59447c3f1a..3baa257a151 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -2034,6 +2034,29 @@ class DATA_PT_gpencil_modifiers(ModifierButtonsPanel, Panel):
         row.prop(md, "pass_index", text="Pass")
         row.prop(md, "invert_pass", text="", icon="ARROW_LEFTRIGHT")
 
+    def GP_ARMATURE(self, layout, ob, md):
+        split = layout.split()
+
+        col = split.column()
+        col.label(text="Object:")
+        col.prop(md, "object", text="")
+        col.prop(md, "use_deform_preserve_volume")
+
+        col = split.column()
+        col.label(text="Bind To:")
+        col.prop(md, "use_vertex_groups", text="Vertex Groups")
+        col.prop(md, "use_bone_envelopes", text="Bone Envelopes")
+
+        layout.separator()
+
+        split = layout.split()
+
+        row = split.row(align=True)
+        row.prop_search(md, "vertex_group", ob, "vertex_groups", text="")
+        sub = row.row(align=True)
+        sub.active = bool(md.vertex_group)
+        sub.prop(md, "invert_vertex_group", text="", icon='ARROW_LEFTRIGHT')
+
 
 classes = (
     DATA_PT_modifiers,
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 8d2cdd4b11b..60f312c9d6b 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -3535,6 +3535,15 @@ class VIEW3D_MT_edit_armature_delete(Menu):
 
 
 # ********** Grease Pencil Stroke menus **********
+class VIEW3D_MT_gpencil_autoweights(Menu):
+    bl_label = "Generate Weights"
+
+    def draw(self, context):
+        layout = self.layout
+        layout.operator("gpencil.generate_weights", text="With Empty Groups").mode = 'NAME'
+        layout.operator("gpencil.generate_weights", text="With Automatic Weights").mode = 'AUTO'
+
+
 class VIEW3D_MT_gpencil_simplify(Menu):
     bl_label = "Simplify"
 
@@ -3704,6 +3713,9 @@ class VIEW3D_MT_weight_gpencil(Menu):
         layout.operator("gpencil.vertex_group_invert", text="Invert")
         layout.operator("gpencil.vertex_group_smooth", text="Smooth")
 
+        layout.separator()
+        layout.menu("VIEW3D_MT_gpencil_autoweights")
+
 
 class VIEW3D_MT_gpencil_animation(Menu):
     bl_label = "Animation"
@@ -5001,7 +5013,6 @@ class VIEW3D_MT_gpencil_sculpt_specials(Menu):
 
     def draw(self, context):
         layout = self.layout
-        is_3d_view = context.space_data.type == 'VIEW_3D'
 
         layout.operator_context = 'INVOKE_REGION_WIN'
         layout.menu("VIEW3D_MT_assign_material")
@@ -5016,6 +5027,9 @@ class VIEW3D_MT_gpencil_sculpt_specials(Menu):
         layout.operator("gpencil.stroke_simplify_fixed", text="Simplify")
         layout.operator("gpencil.stroke_simplify", text="Simplify Adaptative")
 
+        if context.mode == 'GPENCIL_WEIGHT':
+            layout.separator()
+            layout.menu("VIEW3D_MT_gpencil_autoweights")
 
 classes = (
     VIEW3D_HT_header,
@@ -5161,6 +5175,7 @@ classes = (
     VIEW3D_PT_object_type_visibility,
     VIEW3D_PT_grease_pencil,
     VIEW3D_PT_gpencil_multi_frame,
+    VIEW3D_MT_gpencil_autoweights,
     VIEW3D_MT_gpencil_edit_specials,
     VIEW3D_MT_gpencil_sculpt_specials,
     VIEW3D_PT_quad_view,
diff --git a/source/blender/blenkernel/BKE_lattice.h b/source/blender/blenkernel/BKE_lattice.h
index e98839e3dbc..2ca6a35eec5 100644
--- a/source/blender/blenkernel/BKE_lattice.h
+++ b/source/blender/blenkernel/BKE_lattice.h
@@ -44,6 +44,7 @@ struct Scene;
 struct BPoint;
 struct MDeformVert;
 struct Depsgraph;
+struct bGPDstroke;
 
 void BKE_lattice_resize(struct Lattice *lt, int u, int v, int w, struct Object *ltOb);
 void BKE_lattice_init(struct Lattice *lt);
@@ -73,7 +74,8 @@ void lattice_deform_verts(struct Object *laOb, struct Object *target,
 void armature_deform_verts(struct Object *armOb, struct Object *target,
                            const struct Mesh *mesh, float (*vertexCos)[3],
                            float (*defMats)[3][3], int numVerts, int deformflag,
-                           float (*prevCos)[3], const char *defgrp_name);
+                           float (*prevCos)[3], const char *defgrp_name,
+						   struct bGPDstroke *gps);
 
 float (*BKE_lattice_vertexcos_get(struct Object *ob, int *r_numVerts))[3];
 void    BKE_lattice_vertexcos_apply(struct Object *ob, float (*vertexCos)[3]);
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c
index 7383d80cfa8..a3f7dbe70be 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -46,6 +46,7 @@
 #include "DNA_anim_types.h"
 #include "DNA_armature_types.h"
 #include "DNA_constraint_types.h"
+#include "DNA_gpencil_types.h"
 #include "DNA_mesh_types.h"
 #include "DNA_lattice_types.h"
 #include "DNA_listBase.h"
@@ -970,7 +971,7 @@ static void armature_bbone_defmats_cb(void *userdata, Link *iter, int index)
 
 void armature_deform_verts(Object *armOb, Object *target, const Mesh * mesh, float (*vertexCos)[3],
                            float (*defMats)[3][3], int numVerts, int deformflag,
-                           float (*prevCos)[3], const char *defgrp_name)
+                           float (*prevCos)[3], const char *defgrp_name, bGPDstroke *gps)
 {
 	bPoseChanDeform *pdef_info_array;
 	bPoseChanDeform *pdef_info = NULL;
@@ -1024,7 +1025,7 @@ void armature_deform_verts(Object *armOb, Object *target, const Mesh * mesh, flo
 	/* get the def_nr for the overall armature vertex group if present */
 	armature_def_nr = defgroup_name_index(target, defgrp_name);
 
-	if (ELEM(target->type, OB_MESH, OB_LATTICE)) {
+	if (ELEM(target->type, OB_MESH, OB_LATTICE, OB_GPENCIL)) {
 		defbase_tot = BLI_listbase_count(&target->defbase);
 
 		if (target->type == OB_MESH) {
@@ -1033,17 +1034,22 @@ void armature_deform_verts(Object *armOb, Object *target, const Mesh * mesh, flo
 			if (dverts)
 				target_totvert = me->totvert;
 		}
-		else {
+		else if (target->type == OB_LATTICE) {
 			Lattice *lt = target->data;
 			dverts = lt->dvert;
 			if (dverts)
 				target_totvert = lt->pntsu * lt->pntsv * lt->pntsw;
 		}
+		else if (target->type == OB_GPENCIL) {
+			dverts = gps->dvert;
+			if (dverts)
+				target_totvert = gps->totpoints;
+		}
 	}
 
 	/* get a vertex-deform-index to posechannel array */
 	if (deformflag & ARM_DEF_VGROUP) {
-		if (ELEM(target->type, OB_MESH, OB_LATTICE)) {
+		if (ELEM(target->type, OB_MESH, OB_LATTICE, OB_GPENCIL)) {
 			/* if we have a Mesh, only use dverts if it has them */
 			if (mesh) {
 				use_dverts = (mesh->dvert != NULL);
diff --git a/source/blender/blenkernel/intern/gpencil_modifier.c b/source/blender/blenkernel/intern/gpencil_modifier.c
index 1cfbaed37fe..af82d8fa200 100644
--- a/source/blender/blenkernel/intern/gpencil_modifier.c
+++ b/source/blender/blenkernel/intern/gpencil_modifier.c
@@ -423,9 +423,10 @@ void BKE_gpencil_stroke_modifiers(Depsgraph *depsgraph, Object *ob, bGPDlayer *g
 				/* some modifiers could require a recalc of fill triangulation data */
 				if (gpd->flag & GP_DATA_STROKE_FORCE_RECALC) {
 					if (ELEM(md->type,
-						eGpencilModifierType_Hook,
-						eGpencilModifierType_Lattice,
-						eGpencilModifierType_Offset))
+							eGpencilModifierType_Armature,
+							eGpencilModifierType_Hook,
+							eGpencilModifierType_Lattice,
+							eGpencilModifierType_Offset))
 					{
 
 						gps->flag |= GP_STROKE_RECALC_CACHES;
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
index 858a20dbbc3..7063d86e507 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
@@ -553,14 +553,14 @@ static DRWShadingGroup *DRW_gpencil_shgroup_point_create(
 static void gpencil_add_fill_shgroup(
         GpencilBatchCache *cache, DRWShadingGroup *fillgrp,
         Object *ob, bGPDlayer *gpl, bGPDframe *gpf, bGPDstroke *gps,
-        const float tintcolor[4], const bool onion, const bool custonion)
+		float opacity, const float tintcolor[4], const bool onion, const bool custonion)
 {
 	MaterialGPencilStyle *gp_style = BKE_material_gpencil_settings_get(ob, gps->mat_nr + 1);
 	if (gps->totpoints >= 3) {
 		float tfill[4];
 		/* set color using material, tint color and opacity */
 		interp_v3_v3v3(tfill, gps->runtime.tmp_fill_rgba, tintcolor, tintcolor[3]);
-		tfill[3] = gps->runtime.tmp_fill_rgba[3] * gpl->opacity;
+		tfill[3] = gps->runtime.tmp_fill_rgba[3] * opacity;
 		if ((tfill[3] > GPENCIL_ALPHA_OPACITY_THRESH) || (gp_style->fill_style > 0)) {
 			const float *color;
 			if (!onion) {
@@ -866,7 +866,7 @@ static void gpencil_draw_strokes(
 			if ((fillgrp) && (!stl->storage->simplify_fill)) {
 				gpencil_add_fill_shgroup(
 				        cache, fillgrp, ob, gpl, derived_gpf, gps,
-				        tintcolor, false, custonion);
+						opacity, tintcolor, false, custonion);
 			}
 			/* stroke */
 			if (strokegrp) {
@@ -1219,6 +1219,7 @@ void DRW_gpencil_populate_datablock(
 	const bool main_onion = v3d != NULL ? (v3d->gp_flag & V3D_GP_SHOW_ONION_SKIN) : true;
 	const bool do_onion = (bool)((gpd->flag & GP_DATA_STROKE_WEIGHTMODE) == 0) && main_onion;
 	const bool overlay = v3d != NULL ? (bool)((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) : true;
+	float opacity;
 
 	/* check if playing animation */
 	bool playing = stl->storage->is_playing;
@@ -1242,6 +1243,16 @@ void DRW_gpencil_populate_datablock(
 		if (gpf == NULL)
 			continue;
 
+		/* if pose mode, maybe the overlay to fade geometry is enabled */
+		if ((draw_ctx->obact) && (draw_ctx->object_mode == OB_MODE_POSE) &&
+			(v3d->overlay.flag & V3D_OVERLAY_BONE_SELECT))
+		{
+			opacity = gpl->opacity * v3d->overlay.bone_select_alpha;
+		}
+		else {
+			opacity = gpl->opacity;
+		}
+
 		/* create GHash if need */
 		if (gpl->runtime.derived_data == NULL) {
 			gpl->runtime.derived_data = (GHash *)BLI_ghash_str_new(gpl->info);
@@ -1308,7 +1319,7 @@ void DRW_gpencil_populate_datablock(
 
 		gpencil_draw_

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list