[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13004] trunk/blender/source/blender: == PoseLib - Pose-Library Tool for Blender ==

Joshua Leung aligorith at gmail.com
Wed Dec 26 12:17:27 CET 2007


Revision: 13004
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13004
Author:   aligorith
Date:     2007-12-26 12:17:26 +0100 (Wed, 26 Dec 2007)

Log Message:
-----------
== PoseLib - Pose-Library Tool for Blender ==
"A slightly late Christmas present for the Animators out there :-)"

This tool allows animators to store frequently used poses in an action, and be able to label those poses to help them retrieve them later. In a way, it acts as a glorified clipboard for poses.

One of the cool features with this is the ability to select which stored pose to use interactively in the 3d-view. Once a few poses have been stored in the PoseLib, simply use the "Ctrl L" hotkey to start previewing. Use the Mousewheel or the Page Up/Down keys to change poses, and confirm/cancel the preview in the same way as you do for transforms.

Usage Notes:
* Each Armature may get its own PoseLib. PoseLibs are simply actions with extra data, so they can get relinked.
* Manually editing actions used as PoseLibs is not a good idea, as some data may not be able to be found. Tools to automagically find poses in an action could be investigated...
* PoseLib will only apply/retrieve poses to/from selected bones
* A basic UI for this can be found in the "Links and Materials" panel. Most of the PoseLib tools are presented there.

Useful Hotkeys (also found in Pose->PoseLib menu):
* Ctrl L  - interactively preview poses
* Shift L - add a new pose or replace an existing pose in the PoseLib with the current pose
* Ctrl Shift L - rename an existing pose in the PoseLib 
* Alt L - remove a pose from the poselib.c

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/action.c
    trunk/blender/source/blender/blenkernel/intern/object.c
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/blenloader/intern/writefile.c
    trunk/blender/source/blender/include/butspace.h
    trunk/blender/source/blender/makesdna/DNA_action_types.h
    trunk/blender/source/blender/src/buttons_editing.c
    trunk/blender/source/blender/src/header_view3d.c
    trunk/blender/source/blender/src/space.c

Added Paths:
-----------
    trunk/blender/source/blender/include/BIF_poselib.h
    trunk/blender/source/blender/src/poselib.c

Modified: trunk/blender/source/blender/blenkernel/intern/action.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/action.c	2007-12-26 10:59:08 UTC (rev 13003)
+++ trunk/blender/source/blender/blenkernel/intern/action.c	2007-12-26 11:17:26 UTC (rev 13004)
@@ -163,6 +163,15 @@
 	}
 }
 
+static void free_act_poselib (bAction *act)
+{
+	if (act->poselib) {
+		bPoseLib *pl= act->poselib;
+		
+		BLI_freelistN(&pl->poses);
+		MEM_freeN(pl);
+	}
+}
 
 void free_action (bAction *act)
 {
@@ -177,6 +186,9 @@
 	
 	if (act->chanbase.first)
 		BLI_freelistN(&act->chanbase);
+		
+	/* Free PoseLib */
+	free_act_poselib(act);
 }
 
 bAction *copy_action (bAction *src)

Modified: trunk/blender/source/blender/blenkernel/intern/object.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/object.c	2007-12-26 10:59:08 UTC (rev 13003)
+++ trunk/blender/source/blender/blenkernel/intern/object.c	2007-12-26 11:17:26 UTC (rev 13004)
@@ -230,6 +230,7 @@
 		BLI_freelistN(&ob->defbase);
 	if(ob->pose) {
 		free_pose_channels(ob->pose);
+		if (ob->pose->poselib) ob->pose->poselib->id.us--;
 		MEM_freeN(ob->pose);
 	}
 	free_effects(&ob->effect);

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2007-12-26 10:59:08 UTC (rev 13003)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2007-12-26 11:17:26 UTC (rev 13004)
@@ -1785,6 +1785,9 @@
 		}
 	}
 	
+	// ob->id.lib??? 
+	pose->poselib = newlibadr_us(fd, ob->id.lib, pose->poselib);
+	
 	if(rebuild) {
 		ob->recalc= OB_RECALC;
 		pose->flag |= POSE_RECALC;
@@ -1814,12 +1817,12 @@
 	while(act) {
 		if(act->id.flag & LIB_NEEDLINK) {
 			act->id.flag -= LIB_NEEDLINK;
-
+			
 			for (chan=act->chanbase.first; chan; chan=chan->next) {
 				chan->ipo= newlibadr_us(fd, act->id.lib, chan->ipo);
 				lib_link_constraint_channels(fd, &act->id, &chan->constraintChannels);
 			}
-
+			
 		}
 		act= act->id.next;
 	}
@@ -1847,7 +1850,10 @@
 
 	for (achan = act->chanbase.first; achan; achan=achan->next)
 		link_list(fd, &achan->constraintChannels);
-
+		
+	act->poselib= newdataadr(fd, act->poselib);
+	if (act->poselib)
+		link_list(fd, &act->poselib->poses);
 }
 
 static void direct_link_armature(FileData *fd, bArmature *arm)
@@ -2942,7 +2948,6 @@
 		pchan->iktree.first= pchan->iktree.last= NULL;
 		pchan->path= NULL;
 	}
-
 }
 
 static void direct_link_modifiers(FileData *fd, ListBase *lb)
@@ -7799,6 +7804,8 @@
 		expand_constraints(fd, mainvar, &chan->constraints);
 		expand_doit(fd, mainvar, chan->custom);
 	}
+	
+	expand_doit(fd, mainvar, pose->poselib);
 }
 
 static void expand_armature(FileData *fd, Main *mainvar, bArmature *arm)

Modified: trunk/blender/source/blender/blenloader/intern/writefile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/writefile.c	2007-12-26 10:59:08 UTC (rev 13003)
+++ trunk/blender/source/blender/blenloader/intern/writefile.c	2007-12-26 11:17:26 UTC (rev 13004)
@@ -1743,11 +1743,21 @@
 		if (act->id.us>0 || wd->current) {
 			writestruct(wd, ID_AC, "bAction", 1, act);
 			if (act->id.properties) IDP_WriteProperty(act->id.properties, wd);
-
+			
 			for (chan=act->chanbase.first; chan; chan=chan->next) {
 				writestruct(wd, DATA, "bActionChannel", 1, chan);
 				write_constraint_channels(wd, &chan->constraintChannels);
 			}
+			
+			if (act->poselib) {
+				bPoseLib *pl= act->poselib;
+				bPoseLibRef *plr;
+				
+				writestruct(wd, DATA, "bPoseLib", 1, pl);
+				
+				for (plr= pl->poses.first; plr; plr= plr->next)
+					writestruct(wd, DATA, "bPoseLibRef", 1, plr);
+			}
 		}
 	}
 }

Added: trunk/blender/source/blender/include/BIF_poselib.h
===================================================================
--- trunk/blender/source/blender/include/BIF_poselib.h	                        (rev 0)
+++ trunk/blender/source/blender/include/BIF_poselib.h	2007-12-26 11:17:26 UTC (rev 13004)
@@ -0,0 +1,52 @@
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. The Blender
+ * Foundation also sells licenses for use in proprietary software under
+ * the Blender License.  See http://www.blender.org/BL/ for information
+ * about this.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2007 Blender Foundation
+ * All rights reserved.
+ *
+ * The Original Code is: this is a new part of Blender
+ *
+ * Contributor(s): Joshua Leung
+ *
+ * ***** END GPL/BL DUAL LICENSE BLOCK *****
+ */
+ 
+#ifndef BIF_POSELIB_H
+#define BIF_POSELIB_H
+
+struct Object;
+struct bPoseLib;
+struct bPoseLibRef;
+
+char *poselib_build_poses_menu(struct bPoseLib *pl, char title[]);
+void poselib_unique_pose_name(struct bPoseLib *pl, char name[]);
+int poselib_get_free_index(struct bPoseLib *pl);
+
+struct bPoseLib *poselib_init_new(struct Object *ob);
+
+void poselib_remove_pose(struct Object *ob, struct bPoseLibRef *plr);
+void poselib_rename_pose(struct Object *ob);
+void poselib_add_current_pose(struct Object *ob, int mode);
+
+void poselib_preview_poses(struct Object *ob);
+
+#endif


Property changes on: trunk/blender/source/blender/include/BIF_poselib.h
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Modified: trunk/blender/source/blender/include/butspace.h
===================================================================
--- trunk/blender/source/blender/include/butspace.h	2007-12-26 10:59:08 UTC (rev 13003)
+++ trunk/blender/source/blender/include/butspace.h	2007-12-26 11:17:26 UTC (rev 13004)
@@ -501,6 +501,11 @@
 #define B_ARM_CALCPATHS		2303
 #define B_ARM_CLEARPATHS	2304
 
+#define B_POSELIB_NEW			2310
+#define B_POSELIB_ADDPOSE		2311
+#define B_POSELIB_REPLACEP		2312
+#define B_POSELIB_REMOVEP		2313
+
 /* *********************** */
 #define B_CAMBUTS		2500
 

Modified: trunk/blender/source/blender/makesdna/DNA_action_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_action_types.h	2007-12-26 10:59:08 UTC (rev 13003)
+++ trunk/blender/source/blender/makesdna/DNA_action_types.h	2007-12-26 11:17:26 UTC (rev 13004)
@@ -90,12 +90,35 @@
  */
 typedef struct bPose {
 	ListBase chanbase; 			/* list of pose channels */
+	struct bAction *poselib;	/* poselib-action for this pose */
+	
 	short flag, proxy_layer;	/* proxy layer: copy from armature, gets synced */
+	
 	float ctime;				/* local action time of this pose */
 	float stride_offset[3];		/* applied to object */
 	float cyclic_offset[3];		/* result of match and cycles, applied in where_is_pose() */
 } bPose;
 
+
+/* "Pose" reference for PoseLib */
+typedef struct bPoseLibRef {
+	struct bPoseLibRef *next, *prev;
+	int frame;					/* frame in the action to look for this pose */
+	char name[32];				/* name of the pose */
+	int pad;
+} bPoseLibRef;
+
+/* PoseLib data for Action 
+ *	PoseLib data is stored in actions so that poselibs can easily be assigned/removed from
+ *	a pose. Currently the only data that is stored for a poselib is a set of references to which
+ *	frame a named pose occurs in the action.
+ */
+typedef struct bPoseLib {
+	ListBase 	poses;			/* List of poses for an action (arranged in chronological order) */
+	int 	flag;				/* Settings (not used yet) */
+	int 	active_nr;			/* Index of the poselib's active pose (for UI) */
+} bPoseLib;
+
 /* Action Channels belong to Actions. They are linked with an IPO block, and can also own 
  * Constraint Channels in certain situations. 
  */
@@ -115,6 +138,7 @@
 typedef struct bAction {
 	ID				id;
 	ListBase		chanbase;	/* Action Channels in this Action */
+	bPoseLib		*poselib;	/* PoseLib data of this Action (only if the action is used as poselib) */
 } bAction;
 
 /* Action Editor Space. This is defined here instead of in DNA_space_types.h */

Modified: trunk/blender/source/blender/src/buttons_editing.c
===================================================================
--- trunk/blender/source/blender/src/buttons_editing.c	2007-12-26 10:59:08 UTC (rev 13003)
+++ trunk/blender/source/blender/src/buttons_editing.c	2007-12-26 11:17:26 UTC (rev 13004)
@@ -114,6 +114,7 @@
 #include "BIF_interface.h"
 #include "BIF_meshtools.h"
 #include "BIF_mywindow.h"
+#include "BIF_poselib.h"
 #include "BIF_poseobject.h"
 #include "BIF_renderwin.h"
 #include "BIF_resources.h"
@@ -3729,6 +3730,32 @@
 		if (ob && ob->pose)
 			pose_clear_paths(ob);
 		break;
+		
+	case B_POSELIB_NEW:
+		if (ob && ob->pose)
+			poselib_init_new(ob);
+		allqueue(REDRAWBUTSEDIT, 0);
+		break;
+	case B_POSELIB_ADDPOSE:
+		if (ob && ob->pose)
+			poselib_add_current_pose(ob, 1);
+		allqueue(REDRAWBUTSEDIT, 0);
+		break;
+	case B_POSELIB_REPLACEP:
+		if (ob && ob->pose)
+			poselib_add_current_pose(ob, 2);
+		allqueue(REDRAWBUTSEDIT, 0);
+		break;
+	case B_POSELIB_REMOVEP:
+		if (ob && ob->pose) {
+			bAction *act= ob->pose->poselib;
+			bPoseLib *pl= act->poselib;
+			bPoseLibRef *plr= BLI_findlink(&pl->poses, pl->active_nr-1);
+			
+			poselib_remove_pose(ob, plr);
+		}
+		allqueue(REDRAWBUTSEDIT, 0);
+		break;
 	}
 }
 
@@ -4937,6 +4964,59 @@
 		return;
 	}
 	
+	/* poselib for armatures */
+	if (ob->type==OB_ARMATURE) {
+		if ((ob->pose) && (ob->flag & OB_POSEMODE) && (G.obedit != ob)) {
+			bPose *pose= ob->pose;
+			bAction *act= pose->poselib;
+			
+			xco= 143;
+			
+			uiDefBut(block, LABEL,0,"PoseLib:", xco, 154, 130,20, 0, 0, 0, 0, 0, "");
+			
+			/* PoseLib Action */
+			if (act) {
+				if (act->poselib==NULL) {
+					uiBlockSetCol(block, TH_REDALERT);

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list