[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [18477] branches/blender2.5/blender/source /blender/editors/armature/poselib.c: 2.5
Ton Roosendaal
ton at blender.org
Tue Jan 13 13:32:01 CET 2009
Revision: 18477
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18477
Author: ton
Date: 2009-01-13 13:32:01 +0100 (Tue, 13 Jan 2009)
Log Message:
-----------
2.5
Added poselib.c back, non functional entirely still.
Added Paths:
-----------
branches/blender2.5/blender/source/blender/editors/armature/poselib.c
Copied: branches/blender2.5/blender/source/blender/editors/armature/poselib.c (from rev 18476, trunk/blender/source/blender/src/poselib.c)
===================================================================
--- branches/blender2.5/blender/source/blender/editors/armature/poselib.c (rev 0)
+++ branches/blender2.5/blender/source/blender/editors/armature/poselib.c 2009-01-13 12:32:01 UTC (rev 18477)
@@ -0,0 +1,1322 @@
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL 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.
+ *
+ * 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
+ * This is a new part of Blender
+ *
+ * Contributor(s): Joshua Leung
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stddef.h>
+#include <string.h>
+#include <math.h>
+#include <float.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_arithb.h"
+#include "BLI_blenlib.h"
+#include "BLI_dynstr.h"
+
+#include "DNA_listBase.h"
+#include "DNA_action_types.h"
+#include "DNA_armature_types.h"
+#include "DNA_curve_types.h"
+#include "DNA_ipo_types.h"
+#include "DNA_object_types.h"
+#include "DNA_object_force.h"
+#include "DNA_scene_types.h"
+#include "DNA_userdef_types.h"
+
+#include "BKE_action.h"
+#include "BKE_armature.h"
+#include "BKE_depsgraph.h"
+#include "BKE_ipo.h"
+#include "BKE_modifier.h"
+#include "BKE_object.h"
+
+#include "BKE_global.h"
+#include "BKE_utildefines.h"
+
+#include "PIL_time.h" /* sleep */
+
+#include "WM_types.h"
+
+#include "ED_anim_api.h"
+#include "ED_armature.h"
+#include "ED_keyframes_draw.h"
+#include "ED_keyframing.h"
+#include "ED_keyframes_edit.h"
+
+#include "armature_intern.h"
+
+/* ******* XXX ********** */
+
+static void BIF_undo_push() {}
+static void error() {}
+static int qtest() {return 0;}
+static int sbutton() {return 0;}
+static int pupmenu() {return 0;}
+static int pupmenu_col() {return 0;}
+static int extern_qread_ext() {return 0;}
+static void persptoetsen() {}
+static void headerprint() {}
+
+static void remake_action_ipos() {}
+static void verify_pchan2achan_grouping() {}
+static void action_set_activemarker() {}
+
+/* ******* XXX ********** */
+
+
+/* ************************************************************* */
+/* == POSE-LIBRARY TOOL FOR BLENDER ==
+ *
+ * Overview:
+ * This tool allows animators to store a set of frequently used poses to dump into
+ * the active action to help in "budget" productions to quickly block out new actions.
+ * It acts as a kind of "glorified clipboard for poses", allowing for naming of poses.
+ *
+ * Features:
+ * - PoseLibs are simply normal Actions
+ * - Each "pose" is simply a set of keyframes that occur on a particular frame
+ * -> a set of TimeMarkers that belong to each Action, help 'label' where a 'pose' can be
+ * found in the Action
+ * - The Scrollwheel or PageUp/Down buttons when used in a special mode or after pressing/holding
+ * [a modifier] key, cycles through the poses available for the active pose's poselib, allowing the
+ * animator to preview what action best suits that pose
+ */
+/* ************************************************************* */
+
+/* gets list of poses in poselib as a string usable for pupmenu() */
+char *poselib_build_poses_menu (bAction *act, char title[])
+{
+ DynStr *pupds= BLI_dynstr_new();
+ TimeMarker *marker;
+ char *str;
+ char buf[64];
+ int i;
+
+ /* add title first */
+ sprintf(buf, "%s%%t|", title);
+ BLI_dynstr_append(pupds, buf);
+
+ /* loop through markers, adding them */
+ for (marker=act->markers.first, i=1; marker; marker=marker->next, i++) {
+ BLI_dynstr_append(pupds, marker->name);
+
+ sprintf(buf, "%%x%d", i);
+ BLI_dynstr_append(pupds, buf);
+
+ if (marker->next)
+ BLI_dynstr_append(pupds, "|");
+ }
+
+ /* convert to normal MEM_malloc'd string */
+ str= BLI_dynstr_get_cstring(pupds);
+ BLI_dynstr_free(pupds);
+
+ return str;
+}
+
+/* gets the first available frame in poselib to store a pose on
+ * - frames start from 1, and a pose should occur on every frame... 0 is error!
+ */
+int poselib_get_free_index (bAction *act)
+{
+ TimeMarker *marker;
+ int low=0, high=0;
+
+ /* sanity checks */
+ if (ELEM(NULL, act, act->markers.first)) return 1;
+
+ /* loop over poses finding various values (poses are not stored in chronological order) */
+ for (marker= act->markers.first; marker; marker= marker->next) {
+ /* only increase low if value is 1 greater than low, to find "gaps" where
+ * poses were removed from the poselib
+ */
+ if (marker->frame == (low + 1))
+ low++;
+
+ /* value replaces high if it is the highest value encountered yet */
+ if (marker->frame > high)
+ high= marker->frame;
+ }
+
+ /* - if low is not equal to high, then low+1 is a gap
+ * - if low is equal to high, then high+1 is the next index (add at end)
+ */
+ if (low < high)
+ return (low + 1);
+ else
+ return (high + 1);
+}
+
+/* returns the active pose for a poselib */
+TimeMarker *poselib_get_active_pose (bAction *act)
+{
+ if ((act) && (act->active_marker))
+ return BLI_findlink(&act->markers, act->active_marker-1);
+ else
+ return NULL;
+}
+
+/* ************************************************************* */
+
+/* Initialise a new poselib (whether it is needed or not) */
+bAction *poselib_init_new (Object *ob)
+{
+ /* sanity checks - only for armatures */
+ if (ELEM(NULL, ob, ob->pose))
+ return NULL;
+
+ /* init object's poselib action (unlink old one if there) */
+ if (ob->poselib)
+ ob->poselib->id.us--;
+ ob->poselib= add_empty_action("PoseLib");
+
+ return ob->poselib;
+}
+
+/* Initialise a new poselib (checks if that needs to happen) */
+bAction *poselib_validate (Object *ob)
+{
+ if (ELEM(NULL, ob, ob->pose))
+ return NULL;
+ else if (ob->poselib == NULL)
+ return poselib_init_new(ob);
+ else
+ return ob->poselib;
+}
+
+
+/* This tool automagically generates/validates poselib data so that it corresponds to the data
+ * in the action. This is for use in making existing actions usable as poselibs.
+ */
+void poselib_validate_act (bAction *act)
+{
+ ListBase keys = {NULL, NULL};
+ ActKeyColumn *ak;
+ TimeMarker *marker, *markern;
+
+ /* validate action and poselib */
+ if (act == NULL) {
+ error("No Action to validate");
+ return;
+ }
+
+ /* determine which frames have keys */
+ action_to_keylist(act, &keys, NULL, NULL);
+
+ /* for each key, make sure there is a correspnding pose */
+ for (ak= keys.first; ak; ak= ak->next) {
+ /* check if any pose matches this */
+ for (marker= act->markers.first; marker; marker= marker->next) {
+ if (IS_EQ(marker->frame, ak->cfra)) {
+ marker->flag = -1;
+ break;
+ }
+ }
+
+ /* add new if none found */
+ if (marker == NULL) {
+ char name[64];
+
+ /* add pose to poselib */
+ marker= MEM_callocN(sizeof(TimeMarker), "ActionMarker");
+
+ strcpy(name, "Pose");
+ BLI_strncpy(marker->name, name, sizeof(marker->name));
+
+ marker->frame= (int)ak->cfra;
+ marker->flag= -1;
+
+ BLI_addtail(&act->markers, marker);
+ }
+ }
+
+ /* remove all untagged poses (unused), and remove all tags */
+ for (marker= act->markers.first; marker; marker= markern) {
+ markern= marker->next;
+
+ if (marker->flag != -1)
+ BLI_freelinkN(&act->markers, marker);
+ else
+ marker->flag = 0;
+ }
+
+ /* free temp memory */
+ BLI_freelistN(&keys);
+
+ BIF_undo_push("PoseLib Validate Action");
+}
+
+/* ************************************************************* */
+
+/* This function adds an ipo-curve of the right type where it's needed */
+static IpoCurve *poselib_verify_icu (Ipo *ipo, int adrcode)
+{
+ IpoCurve *icu;
+
+ for (icu= ipo->curve.first; icu; icu= icu->next) {
+ if (icu->adrcode==adrcode) break;
+ }
+ if (icu==NULL) {
+ icu= MEM_callocN(sizeof(IpoCurve), "ipocurve");
+
+ icu->flag |= IPO_VISIBLE|IPO_AUTO_HORIZ;
+ if (ipo->curve.first==NULL) icu->flag |= IPO_ACTIVE; /* first one added active */
+
+ icu->blocktype= ID_PO;
+ icu->adrcode= adrcode;
+
+ set_icu_vars(icu);
+
+ BLI_addtail(&ipo->curve, icu);
+ }
+
+ return icu;
+}
+
+/* This tool adds the current pose to the poselib
+ * Note: Standard insertkey cannot be used for this due to its limitations
+ */
+void poselib_add_current_pose (Scene *scene, Object *ob, int val)
+{
+ bArmature *arm= (ob) ? ob->data : NULL;
+ bPose *pose= (ob) ? ob->pose : NULL;
+ bPoseChannel *pchan;
+ TimeMarker *marker;
+ bAction *act;
+ bActionChannel *achan;
+ IpoCurve *icu;
+ int frame;
+ char name[64];
+
+ /* sanity check */
+ if (ELEM3(NULL, ob, arm, pose))
+ return;
+
+ /* mode - add new or replace existing */
+ if (val == 0) {
+ if ((ob->poselib) && (ob->poselib->markers.first)) {
+ val= pupmenu("PoseLib Add Current Pose%t|Add New%x1|Add New (Current Frame)%x3|Replace Existing%x2");
+ if (val <= 0) return;
+ }
+ else
+ val= 1;
+ }
+
+ if ((ob->poselib) && (val == 2)) {
+ char *menustr;
+
+ /* get poselib */
+ act= ob->poselib;
+
+ /* get the pose to replace */
+ menustr= poselib_build_poses_menu(act, "Replace PoseLib Pose");
+ val= pupmenu_col(menustr, 20);
+ if (menustr) MEM_freeN(menustr);
+
+ if (val <= 0) return;
+ marker= BLI_findlink(&act->markers, val-1);
+ if (marker == NULL) return;
+
+ /* get the frame from the poselib */
+ frame= marker->frame;
+ }
+ else {
+ /* get name of pose */
+ sprintf(name, "Pose");
+ if (sbutton(name, 0, sizeof(name)-1, "Name: ") == 0)
+ return;
+
+ /* get/initialise poselib */
+ act= poselib_validate(ob);
+
+ /* get frame */
+ if (val == 3)
+ frame= CFRA;
+ else /* if (val == 1) */
+ frame= poselib_get_free_index(act);
+
+ /* add pose to poselib - replaces any existing pose there */
+ for (marker= act->markers.first; marker; marker= marker->next) {
+ if (marker->frame == frame) {
+ BLI_strncpy(marker->name, name, sizeof(marker->name));
+ break;
+ }
+ }
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list