[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12829] trunk/blender/source/blender: == Armature - Ghosting Feature (Cessen request) ==

Joshua Leung aligorith at gmail.com
Sun Dec 9 12:53:07 CET 2007


Revision: 12829
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12829
Author:   aligorith
Date:     2007-12-09 12:53:07 +0100 (Sun, 09 Dec 2007)

Log Message:
-----------
== Armature - Ghosting Feature (Cessen request) ==

Added a new option for Armature Ghosting: Only draw ghosts for selected bones. This is activated by toggling the "Sel" button beside the GStep: field. 

Note: this does not give any speed increases, as the whole pose must be recalculated for each ghost. In fact, it might even cause minor performance decreases, due to the need to tag and un-tag bones before/after drawing the set of ghosts.

Modified Paths:
--------------
    trunk/blender/source/blender/makesdna/DNA_armature_types.h
    trunk/blender/source/blender/src/buttons_editing.c
    trunk/blender/source/blender/src/drawarmature.c

Modified: trunk/blender/source/blender/makesdna/DNA_armature_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_armature_types.h	2007-12-09 08:46:23 UTC (rev 12828)
+++ trunk/blender/source/blender/makesdna/DNA_armature_types.h	2007-12-09 11:53:07 UTC (rev 12829)
@@ -89,18 +89,19 @@
 /* armature->flag */
 /* dont use bit 7, was saved in files to disable stuff */
 typedef enum eArmature_Flag {
-	ARM_RESTPOS		= (1<<0),
-	ARM_DRAWXRAY	= (1<<1),	/* XRAY is here only for backwards converting */
-	ARM_DRAWAXES	= (1<<2),
-	ARM_DRAWNAMES	= (1<<3), 
-	ARM_POSEMODE	= (1<<4), 
-	ARM_EDITMODE	= (1<<5), 
-	ARM_DELAYDEFORM = (1<<6), 
-	ARM_DONT_USE    = (1<<7),
-	ARM_MIRROR_EDIT	= (1<<8),
-	ARM_AUTO_IK		= (1<<9),
-	ARM_NO_CUSTOM	= (1<<10), 	/* made option negative, for backwards compat */
-	ARM_COL_CUSTOM	= (1<<11)
+	ARM_RESTPOS			= (1<<0),
+	ARM_DRAWXRAY		= (1<<1),	/* XRAY is here only for backwards converting */
+	ARM_DRAWAXES		= (1<<2),
+	ARM_DRAWNAMES		= (1<<3), 
+	ARM_POSEMODE		= (1<<4), 
+	ARM_EDITMODE		= (1<<5), 
+	ARM_DELAYDEFORM 	= (1<<6), 
+	ARM_DONT_USE    	= (1<<7),
+	ARM_MIRROR_EDIT		= (1<<8),
+	ARM_AUTO_IK			= (1<<9),
+	ARM_NO_CUSTOM		= (1<<10), 	/* made option negative, for backwards compat */
+	ARM_COL_CUSTOM		= (1<<11),	/* draw custom colours - not yet used... */
+	ARM_GHOST_ONLYSEL 	= (1<<12)	/* when ghosting, only show selected bones (this should belong to ghostflag instead) */
 } eArmature_Flag;
 
 /* armature->drawtype */
@@ -144,7 +145,7 @@
 	BONE_TRANSFORM  			= (1<<3),	/* Used instead of BONE_SELECTED during transform */
 	BONE_CONNECTED 				= (1<<4),
 	/* 32 used to be quatrot, was always set in files, do not reuse unless you clear it always */	
-	BONE_HIDDEN_P				= (1<<6), 	/* hidden Bones when drawing Posechannels */	
+	BONE_HIDDEN_P				= (1<<6), 	/* hidden Bones when drawing PoseChannels */	
 	BONE_DONE					= (1<<7),	/* For detecting cyclic dependancies */
 	BONE_ACTIVE					= (1<<8), 	/* active is on mouse clicks only */
 	BONE_HINGE					= (1<<9),	/* No parent rotation or scale */
@@ -153,7 +154,8 @@
 	BONE_NO_DEFORM				= (1<<12),
 	BONE_UNKEYED				= (1<<13), 	/* set to prevent destruction of its unkeyframed pose (after transform) */		
 	BONE_HINGE_CHILD_TRANSFORM 	= (1<<14), 	/* set to prevent hinge child bones from influencing the transform center */
-	BONE_NO_SCALE				= (1<<15) 	/* No parent scale */
+	BONE_NO_SCALE				= (1<<15), 	/* No parent scale */
+	BONE_HIDDEN_PG				= (1<<16)	/* hidden bone when drawing PoseChannels (for ghost drawing) */
 } eBone_Flag;
 
 #endif

Modified: trunk/blender/source/blender/src/buttons_editing.c
===================================================================
--- trunk/blender/source/blender/src/buttons_editing.c	2007-12-09 08:46:23 UTC (rev 12828)
+++ trunk/blender/source/blender/src/buttons_editing.c	2007-12-09 11:53:07 UTC (rev 12829)
@@ -3990,9 +3990,10 @@
 													10, 160, 150, 20, &arm->ghosttype, 0, 0, 0, 0, "Choose range of Ghosts to draw for current Action");	
 		
 		if (arm->ghosttype != ARM_GHOST_KEYS)
-			uiDefButS(block, NUM, REDRAWVIEW3D, "GStep: ", 10,140,150,20, &arm->ghostsize, 1.0f, 20.0f, 0, 0, "How many frames between Ghost instances");
+			uiDefButS(block, NUM, REDRAWVIEW3D, "GStep: ", 10,120,150,20, &arm->ghostsize, 1.0f, 20.0f, 0, 0, "How many frames between Ghost instances");
 		else
-			uiDefBut(block, LABEL, REDRAWVIEW3D, "GStep: N/A", 10,140,150,20, NULL, 0.0f, 0.0f, 0, 0, "How many frames between Ghost instances");
+			uiDefBut(block, LABEL, REDRAWVIEW3D, "GStep: N/A", 10,140,120,20, NULL, 0.0f, 0.0f, 0, 0, "How many frames between Ghost instances");
+		uiDefButBitS(block, TOG, ARM_GHOST_ONLYSEL, REDRAWVIEW3D, "Sel", 130, 140, 30, 20, &arm->flag, 0, 0, 0, 0, "Only show Ghosts for selected bones");
 	uiBlockEndAlign(block);
 	
 	uiBlockBeginAlign(block);

Modified: trunk/blender/source/blender/src/drawarmature.c
===================================================================
--- trunk/blender/source/blender/src/drawarmature.c	2007-12-09 08:46:23 UTC (rev 12828)
+++ trunk/blender/source/blender/src/drawarmature.c	2007-12-09 11:53:07 UTC (rev 12829)
@@ -1211,7 +1211,7 @@
 	
 	for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
 		bone= pchan->bone;
-		if(bone && !(bone->flag & BONE_HIDDEN_P)) {
+		if(bone && !(bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))) {
 			if(bone->flag & BONE_SELECTED) {
 				if(bone->layer & arm->layer) {
 					if(pchan->ikflag & (BONE_IK_XLIMIT|BONE_IK_ZLIMIT)) {
@@ -1346,7 +1346,7 @@
 			
 			for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
 				bone= pchan->bone;
-				if(bone && !(bone->flag & (BONE_HIDDEN_P|BONE_NO_DEFORM))) {
+				if(bone && !(bone->flag & (BONE_HIDDEN_P|BONE_NO_DEFORM|BONE_HIDDEN_PG))) {
 					if(bone->flag & (BONE_SELECTED))
 						if(bone->layer & arm->layer)
 							draw_sphere_bone_dist(smat, imat, bone->flag, pchan, NULL);
@@ -1369,14 +1369,14 @@
 		
 		for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
 			bone= pchan->bone;
-			if(bone && !(bone->flag & BONE_HIDDEN_P)) {
+			if(bone && !(bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))) {
 				if(bone->layer & arm->layer) {
 					glPushMatrix();
 					glMultMatrixf(pchan->pose_mat);
 					
 					/* catch exception for bone with hidden parent */
 					flag= bone->flag;
-					if(bone->parent && (bone->parent->flag & BONE_HIDDEN_P))
+					if(bone->parent && (bone->parent->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG)))
 						flag &= ~BONE_CONNECTED;
 					
 					if(pchan->custom && !(arm->flag & ARM_NO_CUSTOM))
@@ -1418,7 +1418,7 @@
 		
 		for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
 			bone= pchan->bone;
-			if(bone && !(bone->flag & BONE_HIDDEN_P)) {
+			if(bone && !(bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))) {
 				if(bone->layer & arm->layer) {
 					if (do_dashed && bone->parent) {
 						/*	Draw a line from our root to the parent's tip */
@@ -1456,7 +1456,7 @@
 					
 					/* catch exception for bone with hidden parent */
 					flag= bone->flag;
-					if(bone->parent && (bone->parent->flag & BONE_HIDDEN_P))
+					if(bone->parent && (bone->parent->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG)))
 						flag &= ~BONE_CONNECTED;
 					
 					/* extra draw service for pose mode */
@@ -1510,7 +1510,7 @@
 			if(G.vd->zbuf) glDisable(GL_DEPTH_TEST);
 			
 			for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
-				if((pchan->bone->flag & BONE_HIDDEN_P)==0) {
+				if((pchan->bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))==0) {
 					if(pchan->bone->layer & arm->layer) {
 						if (arm->flag & (ARM_EDITMODE|ARM_POSEMODE)) {
 							bone= pchan->bone;
@@ -1727,7 +1727,13 @@
 	}
 }
 
-/* in view space */
+/* ****************************** Armature Visualisation ******************************** */
+
+/* ---------- Paths --------- */
+
+/* draw bone paths
+ *	- in view space 
+ */
 static void draw_pose_paths(Object *ob)
 {
 	bArmature *arm= ob->data;
@@ -1927,8 +1933,42 @@
 	glPopMatrix();
 }
 
+
+/* ---------- Ghosts --------- */
+
+/* helper function for ghost drawing - sets/removes flags for temporarily 
+ * hiding unselected bones while drawing ghosts
+ */
+static void ghost_poses_tag_unselected(Object *ob, short unset)
+{
+	bArmature *arm= ob->data;
+	bPose *pose= ob->pose;
+	bPoseChannel *pchan;
+	Bone *bone;
+	
+	/* don't do anything if no hiding any bones */
+	if ((arm->flag & ARM_GHOST_ONLYSEL)==0)
+		return;
+		
+	/* loop over all pchans, adding/removing tags as appropriate */
+	for (pchan= pose->chanbase.first; pchan; pchan= pchan->next) {
+		if ((pchan->bone) && (arm->layer & pchan->bone->layer)) {
+			if (unset) {
+				/* remove tags from all pchans if cleaning up */
+				pchan->bone->flag &= ~BONE_HIDDEN_PG;
+			}
+			else {
+				/* set tags on unselected pchans only */
+				if ((pchan->bone->flag & BONE_SELECTED)==0)
+					pchan->bone->flag |= BONE_HIDDEN_PG;
+			}
+		}
+	}
+}
+
 /* draw ghosts that occur within a frame range 
- * 	note: object should be in posemode */
+ * 	note: object should be in posemode 
+ */
 static void draw_ghost_poses_range(Base *base)
 {
 	Object *ob= base->object;
@@ -1958,6 +1998,7 @@
 	copy_pose(&posen, ob->pose, 1);
 	ob->pose= posen;
 	armature_rebuild_pose(ob, ob->data);	/* child pointers for IK */
+	ghost_poses_tag_unselected(ob, 0);		/* hide unselected bones if need be */
 	
 	glEnable(GL_BLEND);
 	if (G.vd->zbuf) glDisable(GL_DEPTH_TEST);
@@ -1974,6 +2015,7 @@
 	glDisable(GL_BLEND);
 	if (G.vd->zbuf) glEnable(GL_DEPTH_TEST);
 
+	ghost_poses_tag_unselected(ob, 1);		/* unhide unselected bones if need be */
 	free_pose_channels(posen);
 	MEM_freeN(posen);
 	
@@ -1986,6 +2028,9 @@
 	ob->ipoflag= ipoflago; 
 }
 
+/* draw ghosts on keyframes in action within range 
+ *	- object should be in posemode 
+ */
 static void draw_ghost_poses_keys(Base *base)
 {
 	Object *ob= base->object;
@@ -2028,6 +2073,7 @@
 	copy_pose(&posen, ob->pose, 1);
 	ob->pose= posen;
 	armature_rebuild_pose(ob, ob->data);	/* child pointers for IK */
+	ghost_poses_tag_unselected(ob, 0);		/* hide unselected bones if need be */
 	
 	glEnable(GL_BLEND);
 	if (G.vd->zbuf) glDisable(GL_DEPTH_TEST);
@@ -2046,6 +2092,7 @@
 	glDisable(GL_BLEND);
 	if (G.vd->zbuf) glEnable(GL_DEPTH_TEST);
 
+	ghost_poses_tag_unselected(ob, 1);		/* unhide unselected bones if need be */
 	free_pose_channels(posen);
 	BLI_freelistN(&keys);
 	MEM_freeN(posen);
@@ -2059,7 +2106,9 @@
 	ob->ipoflag= ipoflago; 
 }
 
-/* object is supposed to be armature in posemode */
+/* draw ghosts around current frame
+ * 	- object is supposed to be armature in posemode 
+ */
 static void draw_ghost_poses(Base *base)
 {
 	Object *ob= base->object;
@@ -2070,11 +2119,11 @@
 	int cfrao, maptime, flago, ipoflago;
 	
 	/* pre conditions, get an action with sufficient frames */
-	if(ob->action==NULL)
+	if (ob->action==NULL)
 		return;
 
 	calc_action_range(ob->action, &start, &end, 0);
-	if(start==end)
+	if (start == end)
 		return;
 
 	stepsize= (float)(arm->ghostsize);
@@ -2082,7 +2131,7 @@
 	
 	/* we only map time for armature when an active strip exists */
 	for (strip=ob->nlastrips.first; strip; strip=strip->next)
-		if(strip->flag & ACTSTRIP_ACTIVE)
+		if (strip->flag & ACTSTRIP_ACTIVE)
 			break;
 	
 	maptime= (strip!=NULL);
@@ -2090,7 +2139,7 @@
 	/* store values */
 	ob->flag &= ~OB_POSEMODE;
 	cfrao= CFRA;
-	if(maptime) actframe= get_action_frame(ob, (float)CFRA);
+	if (maptime) actframe= get_action_frame(ob, (float)CFRA);

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list