[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13018] trunk/blender/source/blender: == PoseLib - Bugfixes ==
Joshua Leung
aligorith at gmail.com
Thu Dec 27 12:20:37 CET 2007
Revision: 13018
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13018
Author: aligorith
Date: 2007-12-27 12:20:37 +0100 (Thu, 27 Dec 2007)
Log Message:
-----------
== PoseLib - Bugfixes ==
* Fixed crash using Interactive Preview, on an armature without a PoseLib
* Cancelling Interactive Preview now correctly restores the original Pose
* Interactive Preview now sets the correct active pose after it is run
* Interactive Preview now also updates the buttons window after it is run
* Clicking on the "New PoseLib" button now creates a new PoseLib action, even when one existed before
* Poses can be applied using the Pose browsing menu (i.e. when a menu item from that list is clicked, that pose is assigned)
Modified Paths:
--------------
trunk/blender/source/blender/include/BIF_poselib.h
trunk/blender/source/blender/include/butspace.h
trunk/blender/source/blender/src/buttons_editing.c
trunk/blender/source/blender/src/header_view3d.c
trunk/blender/source/blender/src/poselib.c
trunk/blender/source/blender/src/space.c
Modified: trunk/blender/source/blender/include/BIF_poselib.h
===================================================================
--- trunk/blender/source/blender/include/BIF_poselib.h 2007-12-27 10:17:33 UTC (rev 13017)
+++ trunk/blender/source/blender/include/BIF_poselib.h 2007-12-27 11:20:37 UTC (rev 13018)
@@ -43,12 +43,14 @@
int poselib_get_free_index(struct bPoseLib *pl);
struct bPoseLib *poselib_init_new(struct Object *ob);
+struct bPoseLib *poselib_validate(struct Object *ob);
+
void poselib_validate_act(struct bAction *act);
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);
+void poselib_preview_poses(struct Object *ob, short apply_active);
#endif
Modified: trunk/blender/source/blender/include/butspace.h
===================================================================
--- trunk/blender/source/blender/include/butspace.h 2007-12-27 10:17:33 UTC (rev 13017)
+++ trunk/blender/source/blender/include/butspace.h 2007-12-27 11:20:37 UTC (rev 13018)
@@ -512,11 +512,13 @@
#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_POSELIB_VALIDATE 2314
+#define B_POSELIB_VALIDATE 2311
+#define B_POSELIB_ADDPOSE 2312
+#define B_POSELIB_REPLACEP 2313
+#define B_POSELIB_REMOVEP 2314
+#define B_POSELIB_APPLYP 2315
+
/* *********************** */
#define B_CAMBUTS 2500
Modified: trunk/blender/source/blender/src/buttons_editing.c
===================================================================
--- trunk/blender/source/blender/src/buttons_editing.c 2007-12-27 10:17:33 UTC (rev 13017)
+++ trunk/blender/source/blender/src/buttons_editing.c 2007-12-27 11:20:37 UTC (rev 13018)
@@ -3765,6 +3765,11 @@
}
allqueue(REDRAWBUTSEDIT, 0);
break;
+ case B_POSELIB_APPLYP:
+ if (ob && ob->pose)
+ poselib_preview_poses(ob, 1);
+ allqueue(REDRAWBUTSEDIT, 0);
+ break;
}
}
@@ -5007,7 +5012,7 @@
uiBlockBeginAlign(block);
/* currently 'active' pose */
- uiDefButI(block, MENU, REDRAWBUTSEDIT, menustr, xco, 85,18,20, &pl->active_nr, 1, plr_count, 0, 0, "Browses Poses in PoseLib");
+ uiDefButI(block, MENU, B_POSELIB_APPLYP, menustr, xco, 85,18,20, &pl->active_nr, 1, plr_count, 0, 0, "Browses Poses in PoseLib. Applies chosen pose.");
MEM_freeN(menustr);
if (pl->active_nr) {
Modified: trunk/blender/source/blender/src/header_view3d.c
===================================================================
--- trunk/blender/source/blender/src/header_view3d.c 2007-12-27 10:17:33 UTC (rev 13017)
+++ trunk/blender/source/blender/src/header_view3d.c 2007-12-27 11:20:37 UTC (rev 13018)
@@ -4055,7 +4055,7 @@
switch(event) {
case 1:
- poselib_preview_poses(ob);
+ poselib_preview_poses(ob, 0);
break;
case 2:
poselib_add_current_pose(ob, 0);
Modified: trunk/blender/source/blender/src/poselib.c
===================================================================
--- trunk/blender/source/blender/src/poselib.c 2007-12-27 10:17:33 UTC (rev 13017)
+++ trunk/blender/source/blender/src/poselib.c 2007-12-27 11:20:37 UTC (rev 13018)
@@ -210,7 +210,7 @@
/* ************************************************************* */
-/* Initialise a new poselib */
+/* Initialise a new poselib (whether it is needed or not) */
bPoseLib *poselib_init_new (Object *ob)
{
bPose *pose= (ob) ? ob->pose : NULL;
@@ -220,9 +220,10 @@
if (ELEM(NULL, ob, pose))
return NULL;
- /* init pose's poselib action */
- if (pose->poselib == NULL)
- pose->poselib= add_empty_action("PoseLib");
+ /* init pose's poselib action (unlink old one if there) */
+ if (pose->poselib)
+ pose->poselib->id.us--;
+ pose->poselib= add_empty_action("PoseLib");
act= pose->poselib;
/* init actions's poselib data */
@@ -233,7 +234,23 @@
return pl;
}
+/* Initialise a new poselib (checks if that needs to happen) */
+bPoseLib *poselib_validate (Object *ob)
+{
+ bPose *pose= (ob) ? ob->pose : NULL;
+ bAction *act= (pose) ? pose->poselib : NULL;
+ bPoseLib *pl= (act) ? act->poselib : NULL;
+
+ if (ELEM(NULL, ob, pose))
+ return NULL;
+
+ if (ELEM(NULL, act, pl))
+ return poselib_init_new(ob);
+ else
+ return pl;
+}
+
/* 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.
*/
@@ -384,7 +401,7 @@
return;
/* get/initialise poselib */
- pl= poselib_init_new(ob);
+ pl= poselib_validate(ob);
act= pose->poselib;
/* validate name and get frame */
@@ -469,7 +486,9 @@
if (plr == NULL) return;
}
else {
- // TODO: we should really check if pose occurs in this poselib
+ /* only continue if pose belongs to poselib */
+ if (BLI_findindex(&pl->poses, plr) == -1)
+ return;
}
/* remove relevant keyframes */
@@ -554,11 +573,13 @@
typedef struct tPoseLib_Backup {
struct tPoseLib_Backup *next, *prev;
+ bPoseChannel *pchan;
+
float oldloc[3];
float oldsize[3];
float oldquat[4];
- float *loc, *size, *quat;
+ int oldflag;
} tPoseLib_Backup;
/* Makes a copy of the current pose for restoration purposes - doesn't do constraints currently */
@@ -583,9 +604,7 @@
VECCOPY(plb->oldsize, pchan->size);
QUATCOPY(plb->oldquat, pchan->quat);
- plb->loc= pchan->loc;
- plb->size= pchan->size;
- plb->quat= pchan->quat;
+ plb->pchan= pchan;
BLI_addtail(backups, plb);
}
@@ -598,9 +617,11 @@
tPoseLib_Backup *plb;
for (plb= backups->first; plb; plb= plb->next) {
- VECCOPY(plb->loc, plb->oldloc);
- VECCOPY(plb->size, plb->oldsize);
- VECCOPY(plb->quat, plb->oldquat);
+ VECCOPY(plb->pchan->loc, plb->oldloc);
+ VECCOPY(plb->pchan->size, plb->oldsize);
+ VECCOPY(plb->pchan->quat, plb->oldquat);
+
+ plb->pchan->flag = plb->oldflag;
}
}
@@ -718,7 +739,8 @@
enum {
PL_PREVIEW_RUNNING = 0,
PL_PREVIEW_CONFIRM,
- PL_PREVIEW_CANCEL
+ PL_PREVIEW_CANCEL,
+ PL_PREVIEW_RUNONCE
};
/* defines for poselib_preview_poses --> redraw values */
@@ -728,8 +750,10 @@
PL_PREVIEW_REDRAWHEADER,
};
-/* This tool allows users to preview the pose from the pose-lib using the mouse-scrollwheel/pageupdown */
-void poselib_preview_poses (Object *ob)
+/* This tool allows users to preview the pose from the pose-lib using the mouse-scrollwheel/pageupdown
+ * It is also used to apply the active poselib pose only
+ */
+void poselib_preview_poses (Object *ob, short apply_active)
{
ListBase backups = {NULL, NULL};
@@ -737,9 +761,11 @@
bArmature *arm= (ob) ? (ob->data) : NULL;
bAction *act= (pose) ? (pose->poselib) : NULL;
bPoseLib *pl= (act) ? (act->poselib) : NULL;
- bPoseLibRef *plr= (pl->active_nr) ? BLI_findlink(&pl->poses, pl->active_nr-1) : pl->poses.first;
+ bPoseLibRef *plr= (pl == NULL) ? NULL : (pl->active_nr) ? BLI_findlink(&pl->poses, pl->active_nr-1) : pl->poses.first;
+ Base *base;
- short ret_val=PL_PREVIEW_RUNNING, val=0, redraw=1, firsttime=1;
+ short ret_val= (apply_active) ? PL_PREVIEW_RUNONCE : PL_PREVIEW_RUNNING;
+ short val=0, redraw=1, firsttime=1;
unsigned short event;
char headerstr[200];
@@ -767,7 +793,7 @@
/* start preview loop */
- while (ret_val == PL_PREVIEW_RUNNING) {
+ while (ELEM(ret_val, PL_PREVIEW_RUNNING, PL_PREVIEW_RUNONCE)) {
/* preview a pose */
if (redraw) {
/* only recalc pose (and its dependencies) if pose has changed */
@@ -785,8 +811,6 @@
* - note: code copied from transform_generics.c -> recalcData()
*/
if ((arm->flag & ARM_DELAYDEFORM)==0) {
- Base *base;
-
DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); /* sets recalc flags */
/* bah, softbody exception... recalcdata doesnt reset */
@@ -801,17 +825,26 @@
where_is_pose(ob);
}
- /* do header print */
- sprintf(headerstr, "PoseLib Previewing Pose: \"%s\" | Use ScrollWheel or PageUp/Down to change", plr->name);
- headerprint(headerstr);
+ /* do header print - if interactively previewing */
+ if (ret_val == PL_PREVIEW_RUNNING) {
+ sprintf(headerstr, "PoseLib Previewing Pose: \"%s\" | Use ScrollWheel or PageUp/Down to change", plr->name);
+ headerprint(headerstr);
+ }
/* force drawing of view + clear redraw flag */
force_draw(0);
redraw= PL_PREVIEW_NOREDRAW;
}
+ /* stop now if only running once */
+ if (ret_val == PL_PREVIEW_RUNONCE) {
+ ret_val = PL_PREVIEW_CONFIRM;
+ break;
+ }
+
/* essential for idling subloop */
- if (qtest() == 0) PIL_sleep_ms(2);
+ if (qtest() == 0)
+ PIL_sleep_ms(2);
/* emptying queue and reading events */
while ( qtest() ) {
@@ -832,7 +865,7 @@
case SPACEKEY:
ret_val= PL_PREVIEW_CONFIRM;
break;
-
+
/* change to previous pose - go back to end of list if no previous (cyclic) */
case PAGEUPKEY:
case WHEELUPMOUSE:
@@ -867,39 +900,63 @@
}
}
+ /* this signal does one recalc on pose, then unlocks, so ESC or edit will work */
+ pose->flag |= POSE_DO_UNLOCK;
+
/* clear pose if cancelled */
if (ret_val == PL_PREVIEW_CANCEL) {
poselib_backup_restore(&backups);
- where_is_pose(ob);
- }
- BLI_freelistN(&backups);
-
- /* auto-keying if not cancelled */
- if (ret_val == PL_PREVIEW_CONFIRM)
- poselib_keytag_pose(ob);
-
- /* this signal does one recalc on pose, then unlocks, so ESC or edit will work */
- pose->flag |= POSE_DO_UNLOCK;
-
- /* Update event for pose and deformation children */
- DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
-
- /* updates */
- if (G.flags & G_RECORDKEYS) {
- remake_action_ipos(ob->action);
- allqueue(REDRAWIPO, 0);
+ /* old optimize trick... this enforces to bypass the depgraph
+ * - note: code copied from transform_generics.c -> recalcData()
+ */
+ if ((arm->flag & ARM_DELAYDEFORM)==0) {
+ DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); /* sets recalc flags */
+
+ /* bah, softbody exception... recalcdata doesnt reset */
+ for (base= FIRSTBASE; base; base= base->next) {
+ if (base->object->recalc & OB_RECALC_DATA)
+ if (modifiers_isSoftbodyEnabled(base->object)) {
+ base->object->softflag |= OB_SB_REDO;
+ }
+ }
+ }
+ else
+ where_is_pose(ob);
+
allqueue(REDRAWVIEW3D, 0);
- allqueue(REDRAWACTION, 0);
- allqueue(REDRAWNLA, 0);
}
- else {
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list