[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47365] trunk/blender/source/blender: Part-Bugfix, Part-Feature Completion: 'Armature' Option for Mask Modifier

Joshua Leung aligorith at gmail.com
Sun Jun 3 09:50:23 CEST 2012


Revision: 47365
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47365
Author:   aligorith
Date:     2012-06-03 07:49:54 +0000 (Sun, 03 Jun 2012)
Log Message:
-----------
Part-Bugfix, Part-Feature Completion: 'Armature' Option for Mask Modifier
finally works

This commit finally hooks up the Mask Modifier's "Armature" option with the
relevant depsgraph updates on bone selection. Hence, this feature finally works
as it was originally intended - that is, bone selections can be used to control
which parts of the mesh that the mask modifier is applied to are displayed,
giving riggers more freedom to experiment with rigs that don't necessarily
feature overbearing/cluttering widgets.

Regarding the implementation ("has_viz_deps" flag):
This feature is just the "tip of the iceberg" of a number of related set of
rigging/visual animation tools I've had in mind for a while now (dating back to
the introduction of this modifier). Key considerations
- Not all rigs will use this, so we don't want an extra (depsgraph-flush +
search) recalc cost for those that don't use this.
- There are some planned features which will also use this

Modified Paths:
--------------
    trunk/blender/source/blender/editors/armature/editarmature.c
    trunk/blender/source/blender/editors/armature/poseobject.c
    trunk/blender/source/blender/editors/space_view3d/view3d_select.c
    trunk/blender/source/blender/makesdna/DNA_armature_types.h
    trunk/blender/source/blender/makesrna/intern/rna_armature.c
    trunk/blender/source/blender/modifiers/intern/MOD_mask.c

Modified: trunk/blender/source/blender/editors/armature/editarmature.c
===================================================================
--- trunk/blender/source/blender/editors/armature/editarmature.c	2012-06-03 01:52:09 UTC (rev 47364)
+++ trunk/blender/source/blender/editors/armature/editarmature.c	2012-06-03 07:49:54 UTC (rev 47365)
@@ -1418,7 +1418,8 @@
 /* previously known as "selectconnected_posearmature" */
 static int pose_select_connected_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
-	Object *ob = CTX_data_edit_object(C);
+	Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C));
+	bArmature *arm = (bArmature *)ob->data;
 	Bone *bone, *curBone, *next = NULL;
 	int extend = RNA_boolean_get(op->ptr, "extend");
 
@@ -1457,14 +1458,20 @@
 	for (curBone = bone->childbase.first; curBone; curBone = next)
 		selectconnected_posebonechildren(ob, curBone, extend);
 	
+	/* updates */
 	WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, ob);
+	
+	if (arm->flag & ARM_HAS_VIZ_DEPS) {
+		/* mask modifier ('armature' mode), etc. */
+		DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+	}
 
 	return OPERATOR_FINISHED;
 }
 
 static int pose_select_linked_poll(bContext *C)
 {
-	return (ED_operator_view3d_active(C) && ED_operator_posemode(C) );
+	return (ED_operator_view3d_active(C) && ED_operator_posemode(C));
 }
 
 void POSE_OT_select_linked(wmOperatorType *ot)
@@ -4556,14 +4563,21 @@
 			}	
 		}
 		
-		/* in weightpaint we select the associated vertex group too */
-		if (ob_act && ob_act->mode & OB_MODE_WEIGHT_PAINT) {
-			if (nearBone == arm->act_bone) {
-				ED_vgroup_select_by_name(OBACT, nearBone->name);
-				DAG_id_tag_update(&OBACT->id, OB_RECALC_DATA);
+		if (ob_act) {
+			/* in weightpaint we select the associated vertex group too */
+			if (ob_act->mode & OB_MODE_WEIGHT_PAINT) {
+				if (nearBone == arm->act_bone) {
+					ED_vgroup_select_by_name(ob_act, nearBone->name);
+					DAG_id_tag_update(&ob_act->id, OB_RECALC_DATA);
+				}
 			}
+			/* if there are some dependencies for visualising armature state 
+			 * (e.g. Mask Modifier in 'Armature' mode), force update 
+			 */
+			else if (arm->flag & ARM_HAS_VIZ_DEPS) {
+				DAG_id_tag_update(&ob_act->id, OB_RECALC_DATA);
+			}
 		}
-		
 	}
 	
 	return nearBone != NULL;
@@ -5265,6 +5279,8 @@
 	int action = RNA_enum_get(op->ptr, "action");
 	
 	Scene *scene = CTX_data_scene(C);
+	Object *ob = ED_object_context(C);
+	bArmature *arm = ob->data;
 	int multipaint = scene->toolsettings->multipaint;
 
 	if (action == SEL_TOGGLE) {
@@ -5297,8 +5313,8 @@
 
 	WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, NULL);
 	
-	if (multipaint) {
-		Object *ob = ED_object_context(C);
+	/* weightpaint or mask modifiers need depsgraph updates */
+	if (multipaint || (arm->flag & ARM_HAS_VIZ_DEPS)) {
 		DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
 	}
 
@@ -5325,12 +5341,12 @@
 static int pose_select_parent_exec(bContext *C, wmOperator *UNUSED(op))
 {
 	Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C));
+	bArmature *arm = (bArmature *)ob->data;
 	bPoseChannel *pchan, *parent;
 
-	/*	Determine if there is an active bone */
+	/* Determine if there is an active bone */
 	pchan = CTX_data_active_pose_bone(C);
 	if (pchan) {
-		bArmature *arm = ob->data;
 		parent = pchan->parent;
 		if ((parent) && !(parent->bone->flag & (BONE_HIDDEN_P | BONE_UNSELECTABLE))) {
 			parent->bone->flag |= BONE_SELECTED;
@@ -5343,9 +5359,15 @@
 	else {
 		return OPERATOR_CANCELLED;
 	}
-
+	
+	/* updates */
 	WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, ob);
 	
+	if (arm->flag & ARM_HAS_VIZ_DEPS) {
+		/* mask modifier ('armature' mode), etc. */
+		DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+	}
+	
 	return OPERATOR_FINISHED;
 }
 

Modified: trunk/blender/source/blender/editors/armature/poseobject.c
===================================================================
--- trunk/blender/source/blender/editors/armature/poseobject.c	2012-06-03 01:52:09 UTC (rev 47364)
+++ trunk/blender/source/blender/editors/armature/poseobject.c	2012-06-03 07:49:54 UTC (rev 47365)
@@ -391,6 +391,7 @@
 static int pose_select_constraint_target_exec(bContext *C, wmOperator *UNUSED(op))
 {
 	Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C));
+	bArmature *arm = (bArmature *)ob->data;
 	bConstraint *con;
 	int found = 0;
 	
@@ -422,12 +423,18 @@
 		}
 	}
 	CTX_DATA_END;
-
+	
 	if (!found)
 		return OPERATOR_CANCELLED;
-
+	
+	/* updates */
 	WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, ob);
-
+	
+	if (arm->flag & ARM_HAS_VIZ_DEPS) {
+		/* mask modifier ('armature' mode), etc. */
+		DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+	}
+	
 	return OPERATOR_FINISHED;
 }
 
@@ -477,7 +484,6 @@
 					}
 				} 
 				else { /* direction == BONE_SELECT_CHILD */
-
 					/* the child member is only assigned to connected bones, see [#30340] */
 #if 0
 					if (pchan->child == NULL) continue;
@@ -518,9 +524,15 @@
 
 	if (found == 0)
 		return OPERATOR_CANCELLED;
-
+	
+	/* updates */
 	WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, ob);
-
+	
+	if (arm->flag & ARM_HAS_VIZ_DEPS) {
+		/* mask modifier ('armature' mode), etc. */
+		DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+	}
+	
 	return OPERATOR_FINISHED;
 }
 
@@ -547,7 +559,6 @@
 	/* props */
 	ot->prop = RNA_def_enum(ot->srna, "direction", direction_items, BONE_SELECT_PARENT, "Direction", "");
 	RNA_def_boolean(ot->srna, "extend", 0, "Add to Selection", "");
-	
 }
 
 /* ******************* select grouped operator ************* */
@@ -711,6 +722,7 @@
 static int pose_select_grouped_exec(bContext *C, wmOperator *op)
 {
 	Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C));
+	bArmature *arm = (bArmature *)ob->data;
 	short extend = RNA_boolean_get(op->ptr, "extend");
 	short changed = 0;
 	
@@ -736,6 +748,11 @@
 	/* notifiers for updates */
 	WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob);
 	
+	if (arm->flag & ARM_HAS_VIZ_DEPS) {
+		/* mask modifier ('armature' mode), etc. */
+		DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+	}
+	
 	/* report done status */
 	if (changed)
 		return OPERATOR_FINISHED;

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_select.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_select.c	2012-06-03 01:52:09 UTC (rev 47364)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_select.c	2012-06-03 07:49:54 UTC (rev 47365)
@@ -64,6 +64,7 @@
 #include "BKE_context.h"
 #include "BKE_paint.h"
 #include "BKE_armature.h"
+#include "BKE_depsgraph.h"
 #include "BKE_tessmesh.h"
 #include "BKE_movieclip.h"
 #include "BKE_object.h"
@@ -333,7 +334,7 @@
 	int sco1[2], sco2[2];
 	bArmature *arm = ob->data;
 	
-	if (ob->type != OB_ARMATURE || ob->pose == NULL) return;
+	if ((ob->type != OB_ARMATURE) || (ob->pose == NULL)) return;
 
 	for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
 		if (PBONE_VISIBLE(arm, pchan->bone) && (pchan->bone->flag & BONE_UNSELECTABLE) == 0) {
@@ -348,6 +349,11 @@
 			}
 		}
 	}
+	
+	if (arm->flag & ARM_HAS_VIZ_DEPS) {
+		/* mask modifier ('armature' mode), etc. */
+		DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+	}
 }
 
 static void object_deselect_all_visible(Scene *scene, View3D *v3d)
@@ -1899,12 +1905,19 @@
 			}
 			
 			if (bone_selected) {
-				WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, base->object);
+				Object *ob = base->object;
+				bArmature *arm = ob->data;
+				
+				WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, ob);
+				
+				if (arm->flag & ARM_HAS_VIZ_DEPS) {
+					/* mask modifier ('armature' mode), etc. */
+					DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+				}
 			}
 		}
-
+		
 		WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, vc->scene);
-
 	}
 	MEM_freeN(vbuffer);
 

Modified: trunk/blender/source/blender/makesdna/DNA_armature_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_armature_types.h	2012-06-03 01:52:09 UTC (rev 47364)
+++ trunk/blender/source/blender/makesdna/DNA_armature_types.h	2012-06-03 07:49:54 UTC (rev 47365)
@@ -128,7 +128,8 @@
 	ARM_NO_CUSTOM		= (1<<10), 	/* made option negative, for backwards compat */
 	ARM_COL_CUSTOM		= (1<<11),	/* draw custom colors  */
 	ARM_GHOST_ONLYSEL 	= (1<<12),	/* when ghosting, only show selected bones (this should belong to ghostflag instead) */ // XXX depreceated
-	ARM_DS_EXPAND 		= (1<<13)
+	ARM_DS_EXPAND 		= (1<<13),	/* dopesheet channel is expanded */
+	ARM_HAS_VIZ_DEPS	= (1<<14),	/* other objects are used for visualising various states (hack for efficient updates) */
 } eArmature_Flag;
 
 /* armature->drawtype */

Modified: trunk/blender/source/blender/makesrna/intern/rna_armature.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_armature.c	2012-06-03 01:52:09 UTC (rev 47364)
+++ trunk/blender/source/blender/makesrna/intern/rna_armature.c	2012-06-03 07:49:54 UTC (rev 47365)
@@ -131,9 +131,10 @@
 
 	/* proxy lib exception, store it here so we can restore layers on file
 	 * load, since it would otherwise get lost due to being linked data */
-	for (ob = bmain->object.first; ob; ob = ob->id.next)
+	for (ob = bmain->object.first; ob; ob = ob->id.next) {
 		if (ob->data == arm && ob->pose)
 			ob->pose->proxy_layer = arm->layer;
+	}
 
 	WM_main_add_notifier(NC_GEOM | ND_DATA, arm);
 }
@@ -141,7 +142,35 @@
 static void rna_Armature_redraw_data(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
 {
 	ID *id = ptr->id.data;
+	
+	WM_main_add_notifier(NC_GEOM | ND_DATA, id);
+}
 
+static void rna_Bone_select_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
+{
+	ID *id = ptr->id.data;
+	
+	/* special updates for cases where rigs try to hook into armature drawing stuff 
+	 * e.g. Mask Modifier - 'Armature' option
+	 */
+	if (id) {
+		if (GS(id->name) == ID_AR) {
+			bArmature *arm = (bArmature *)id;
+			
+			if (arm->flag & ARM_HAS_VIZ_DEPS) {
+				DAG_id_tag_update(id, OB_RECALC_DATA);
+			}
+		}
+		else if (GS(id->name) == ID_OB) {
+			Object *ob = (Object *)id;
+			bArmature *arm = (bArmature *)ob->data;
+			
+			if (arm->flag & ARM_HAS_VIZ_DEPS) {
+				DAG_id_tag_update(id, OB_RECALC_DATA);
+			}
+		}
+	}
+	
 	WM_main_add_notifier(NC_GEOM | ND_DATA, id);
 }
 
@@ -608,8 +637,8 @@
 	prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "flag", BONE_SELECTED);

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list