From deebf4f8f0d79169a0e6c2a391670419b6492bfe Mon Sep 17 00:00:00 2001 From: Joseph Eagar Date: Wed, 16 Sep 2009 17:43:09 +0000 Subject: merge with 2.5/trunk at r23271 --- source/blender/editors/armature/editarmature.c | 152 ++++++++++++--------- .../editors/armature/editarmature_generate.c | 1 + .../editors/armature/editarmature_retarget.c | 6 +- source/blender/editors/armature/meshlaplacian.c | 24 ++-- source/blender/editors/armature/poselib.c | 83 ++++------- source/blender/editors/armature/poseobject.c | 130 +++++++++++------- 6 files changed, 210 insertions(+), 186 deletions(-) (limited to 'source/blender/editors/armature') diff --git a/source/blender/editors/armature/editarmature.c b/source/blender/editors/armature/editarmature.c index 632f037679f..7d196d23c98 100644 --- a/source/blender/editors/armature/editarmature.c +++ b/source/blender/editors/armature/editarmature.c @@ -239,7 +239,7 @@ static void fix_bonelist_roll (ListBase *bonelist, ListBase *editbonelist) } /* put EditMode back in Object */ -void ED_armature_from_edit(Scene *scene, Object *obedit) +void ED_armature_from_edit(Object *obedit) { bArmature *arm= obedit->data; EditBone *eBone, *neBone; @@ -340,24 +340,22 @@ void ED_armature_from_edit(Scene *scene, Object *obedit) armature_rebuild_pose(obt, arm); } - DAG_object_flush_update(scene, obedit, OB_RECALC_DATA); + DAG_id_flush_update(&obedit->id, OB_RECALC_DATA); } - - -void apply_rot_armature (Scene *scene, Object *ob, float mat[3][3]) +void ED_armature_apply_transform(Object *ob, float mat[4][4]) { EditBone *ebone; bArmature *arm= ob->data; - float scale = Mat3ToScalef(mat); /* store the scale of the matrix here to use on envelopes */ + float scale = Mat4ToScalef(mat); /* store the scale of the matrix here to use on envelopes */ /* Put the armature into editmode */ ED_armature_to_edit(ob); /* Do the rotations */ for (ebone = arm->edbo->first; ebone; ebone=ebone->next){ - Mat3MulVecfl(mat, ebone->head); - Mat3MulVecfl(mat, ebone->tail); + Mat4MulVecfl(mat, ebone->head); + Mat4MulVecfl(mat, ebone->tail); ebone->rad_head *= scale; ebone->rad_tail *= scale; @@ -365,7 +363,7 @@ void apply_rot_armature (Scene *scene, Object *ob, float mat[3][3]) } /* Turn the list into an armature */ - ED_armature_from_edit(scene, ob); + ED_armature_from_edit(ob); ED_armature_edit_free(ob); } @@ -411,7 +409,7 @@ void docenter_armature (Scene *scene, View3D *v3d, Object *ob, int centermode) } /* Turn the list into an armature */ - ED_armature_from_edit(scene, ob); + ED_armature_from_edit(ob); /* Adjust object location for new centerpoint */ if(centermode && obedit==NULL) { @@ -557,7 +555,7 @@ static int apply_armature_pose2bones_exec (bContext *C, wmOperator *op) } /* convert editbones back to bones */ - ED_armature_from_edit(scene, ob); + ED_armature_from_edit(ob); /* flush positions of posebones */ where_is_pose(scene, ob); @@ -791,7 +789,7 @@ int join_armature_exec(bContext *C, wmOperator *op) DAG_scene_sort(scene); // because we removed object(s) - ED_armature_from_edit(scene, ob); + ED_armature_from_edit(ob); ED_armature_edit_free(ob); WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, scene); @@ -994,7 +992,7 @@ static void separate_armature_bones (Scene *scene, Object *ob, short sel) } /* exit editmode (recalculates pchans too) */ - ED_armature_from_edit(scene, ob); + ED_armature_from_edit(ob); ED_armature_edit_free(ob); } @@ -1037,7 +1035,7 @@ static int separate_armature_exec (bContext *C, wmOperator *op) oldob->mode &= ~OB_MODE_POSE; //oldbase->flag &= ~OB_POSEMODE; - ED_armature_from_edit(scene, obedit); + ED_armature_from_edit(obedit); ED_armature_edit_free(obedit); /* 2) duplicate base */ @@ -1054,8 +1052,8 @@ static int separate_armature_exec (bContext *C, wmOperator *op) /* 4) fix links before depsgraph flushes */ // err... or after? separated_armature_fix_links(oldob, newob); - DAG_object_flush_update(scene, oldob, OB_RECALC_DATA); /* this is the original one */ - DAG_object_flush_update(scene, newob, OB_RECALC_DATA); /* this is the separated one */ + DAG_id_flush_update(&oldob->id, OB_RECALC_DATA); /* this is the original one */ + DAG_id_flush_update(&newob->id, OB_RECALC_DATA); /* this is the separated one */ /* 5) restore original conditions */ @@ -1890,7 +1888,7 @@ void mouse_armature(bContext *C, short mval[2], int extend) if(nearBone->flag & BONE_SELECTED) nearBone->flag |= BONE_ACTIVE; } - WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, vc.obedit); + WM_event_add_notifier(C, NC_OBJECT|ND_BONE_SELECT, vc.obedit); } } @@ -4334,8 +4332,8 @@ int ED_do_pose_selectbuffer(Scene *scene, Base *base, unsigned int *buffer, shor /* in weightpaint we select the associated vertex group too */ if (ob->mode & OB_MODE_WEIGHT_PAINT) { if (nearBone->flag & BONE_ACTIVE) { - vertexgroup_select_by_name(OBACT, nearBone->name); - DAG_object_flush_update(scene, OBACT, OB_RECALC_DATA); + ED_vgroup_select_by_name(OBACT, nearBone->name); + DAG_id_flush_update(&OBACT->id, OB_RECALC_DATA); } } @@ -4445,7 +4443,7 @@ static int bone_skinnable(Object *ob, Bone *bone, void *datap) return 0; } -static int add_defgroup_unique_bone(Object *ob, Bone *bone, void *data) +static int ED_vgroup_add_unique_bone(Object *ob, Bone *bone, void *data) { /* This group creates a vertex group to ob that has the * same name as bone (provided the bone is skinnable). @@ -4453,7 +4451,7 @@ static int add_defgroup_unique_bone(Object *ob, Bone *bone, void *data) */ if (!(bone->flag & BONE_NO_DEFORM)) { if (!get_named_vertexgroup(ob,bone->name)) { - add_defgroup_name(ob, bone->name); + ED_vgroup_add_name(ob, bone->name); return 1; } } @@ -4497,7 +4495,7 @@ static int dgroup_skinnable(Object *ob, Bone *bone, void *datap) segments = 1; if (!(defgroup = get_named_vertexgroup(ob, bone->name))) - defgroup = add_defgroup_name(ob, bone->name); + defgroup = ED_vgroup_add_name(ob, bone->name); if (data->list != NULL) { hgroup = (bDeformGroup ***) &data->list; @@ -4548,17 +4546,17 @@ static void envelope_bone_weighting(Object *ob, Mesh *mesh, float (*verts)[3], i /* add the vert to the deform group if weight!=0.0 */ if (distance!=0.0) - add_vert_to_defgroup (ob, dgroup, i, distance, WEIGHT_REPLACE); + ED_vgroup_vert_add (ob, dgroup, i, distance, WEIGHT_REPLACE); else - remove_vert_defgroup (ob, dgroup, i); + ED_vgroup_vert_remove (ob, dgroup, i); /* do same for mirror */ if (dgroupflip && dgroupflip[j] && iflip >= 0) { if (distance!=0.0) - add_vert_to_defgroup (ob, dgroupflip[j], iflip, distance, + ED_vgroup_vert_add (ob, dgroupflip[j], iflip, distance, WEIGHT_REPLACE); else - remove_vert_defgroup (ob, dgroupflip[j], iflip); + ED_vgroup_vert_remove (ob, dgroupflip[j], iflip); } } } @@ -4748,10 +4746,10 @@ void create_vgroups_from_armature(Scene *scene, Object *ob, Object *par, int mod /* Traverse the bone list, trying to create empty vertex * groups cooresponding to the bone. */ - bone_looper(ob, arm->bonebase.first, NULL, add_defgroup_unique_bone); + bone_looper(ob, arm->bonebase.first, NULL, ED_vgroup_add_unique_bone); if (ob->type == OB_MESH) - create_dverts(ob->data); + ED_vgroup_data_create(ob->data); } else if(mode == ARM_GROUPS_ENVELOPE || mode == ARM_GROUPS_AUTO) { /* Traverse the bone list, trying to create vertex groups @@ -4765,7 +4763,6 @@ void create_vgroups_from_armature(Scene *scene, Object *ob, Object *par, int mod static int pose_clear_scale_exec(bContext *C, wmOperator *op) { - Scene *scene = CTX_data_scene(C); Object *ob= CTX_data_active_object(C); /* only clear those channels that are not locked */ @@ -4782,7 +4779,7 @@ static int pose_clear_scale_exec(bContext *C, wmOperator *op) } CTX_DATA_END; - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); /* note, notifier might evolve */ WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, ob); @@ -4807,7 +4804,6 @@ void POSE_OT_scale_clear(wmOperatorType *ot) static int pose_clear_loc_exec(bContext *C, wmOperator *op) { - Scene *scene = CTX_data_scene(C); Object *ob= CTX_data_active_object(C); /* only clear those channels that are not locked */ @@ -4824,7 +4820,7 @@ static int pose_clear_loc_exec(bContext *C, wmOperator *op) } CTX_DATA_END; - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); /* note, notifier might evolve */ WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, ob); @@ -4849,39 +4845,60 @@ void POSE_OT_loc_clear(wmOperatorType *ot) static int pose_clear_rot_exec(bContext *C, wmOperator *op) { - Scene *scene = CTX_data_scene(C); Object *ob= CTX_data_active_object(C); /* only clear those channels that are not locked */ CTX_DATA_BEGIN(C, bPoseChannel*, pchan, selected_pchans) { - if (pchan->protectflag & (OB_LOCK_ROTX|OB_LOCK_ROTY|OB_LOCK_ROTZ)) { - float eul[3], oldeul[3], quat1[4]; - - if (pchan->rotmode == PCHAN_ROT_QUAT) { - QUATCOPY(quat1, pchan->quat); - QuatToEul(pchan->quat, oldeul); + if (pchan->protectflag & (OB_LOCK_ROTX|OB_LOCK_ROTY|OB_LOCK_ROTZ|OB_LOCK_ROTW)) { + /* check if convert to eulers for locking... */ + if (pchan->protectflag & OB_LOCK_ROT4D) { + /* perform clamping on a component by component basis */ + if ((pchan->protectflag & OB_LOCK_ROTW) == 0) + pchan->quat[0]= (pchan->rotmode == PCHAN_ROT_AXISANGLE) ? 0.0f : 1.0f; + if ((pchan->protectflag & OB_LOCK_ROTX) == 0) + pchan->quat[1]= 0.0f; + if ((pchan->protectflag & OB_LOCK_ROTY) == 0) + pchan->quat[2]= 0.0f; + if ((pchan->protectflag & OB_LOCK_ROTZ) == 0) + pchan->quat[3]= 0.0f; } else { - VECCOPY(oldeul, pchan->eul); - } - eul[0]= eul[1]= eul[2]= 0.0f; - - if (pchan->protectflag & OB_LOCK_ROTX) - eul[0]= oldeul[0]; - if (pchan->protectflag & OB_LOCK_ROTY) - eul[1]= oldeul[1]; - if (pchan->protectflag & OB_LOCK_ROTZ) - eul[2]= oldeul[2]; - - if (pchan->rotmode == PCHAN_ROT_QUAT) { - EulToQuat(eul, pchan->quat); - /* quaternions flip w sign to accumulate rotations correctly */ - if ((quat1[0]<0.0f && pchan->quat[0]>0.0f) || (quat1[0]>0.0f && pchan->quat[0]<0.0f)) { - QuatMulf(pchan->quat, -1.0f); + /* perform clamping using euler form (3-components) */ + float eul[3], oldeul[3], quat1[4]; + + if (pchan->rotmode == PCHAN_ROT_QUAT) { + QUATCOPY(quat1, pchan->quat); + QuatToEul(pchan->quat, oldeul); + } + else if (pchan->rotmode == PCHAN_ROT_AXISANGLE) { + AxisAngleToEulO(&pchan->quat[1], pchan->quat[0], oldeul, EULER_ORDER_DEFAULT); + } + else { + VECCOPY(oldeul, pchan->eul); + } + + eul[0]= eul[1]= eul[2]= 0.0f; + + if (pchan->protectflag & OB_LOCK_ROTX) + eul[0]= oldeul[0]; + if (pchan->protectflag & OB_LOCK_ROTY) + eul[1]= oldeul[1]; + if (pchan->protectflag & OB_LOCK_ROTZ) + eul[2]= oldeul[2]; + + if (pchan->rotmode == PCHAN_ROT_QUAT) { + EulToQuat(eul, pchan->quat); + /* quaternions flip w sign to accumulate rotations correctly */ + if ((quat1[0]<0.0f && pchan->quat[0]>0.0f) || (quat1[0]>0.0f && pchan->quat[0]<0.0f)) { + QuatMulf(pchan->quat, -1.0f); + } + } + else if (pchan->rotmode == PCHAN_ROT_AXISANGLE) { + AxisAngleToEulO(&pchan->quat[1], pchan->quat[0], oldeul, EULER_ORDER_DEFAULT); + } + else { + VECCOPY(pchan->eul, eul); } - } - else { - VECCOPY(pchan->eul, eul); } } else { @@ -4889,6 +4906,11 @@ static int pose_clear_rot_exec(bContext *C, wmOperator *op) pchan->quat[1]=pchan->quat[2]=pchan->quat[3]= 0.0f; pchan->quat[0]= 1.0f; } + else if (pchan->rotmode == PCHAN_ROT_AXISANGLE) { + /* by default, make rotation of 0 radians around y-axis (roll) */ + pchan->quat[0]=pchan->quat[1]=pchan->quat[3]= 0.0f; + pchan->quat[2]= 1.0f; + } else { pchan->eul[0]= pchan->eul[1]= pchan->eul[2]= 0.0f; } @@ -4899,7 +4921,7 @@ static int pose_clear_rot_exec(bContext *C, wmOperator *op) } CTX_DATA_END; - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); /* note, notifier might evolve */ WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, ob); @@ -5337,7 +5359,6 @@ void ED_armature_bone_rename(bArmature *arm, char *oldnamep, char *newnamep) static int armature_flip_names_exec (bContext *C, wmOperator *op) { - Scene *scene= CTX_data_scene(C); Object *ob= CTX_data_edit_object(C); bArmature *arm; char newname[32]; @@ -5357,7 +5378,7 @@ static int armature_flip_names_exec (bContext *C, wmOperator *op) CTX_DATA_END; /* since we renamed stuff... */ - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); /* note, notifier might evolve */ WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob); @@ -5383,11 +5404,10 @@ void ARMATURE_OT_flip_names (wmOperatorType *ot) static int armature_autoside_names_exec (bContext *C, wmOperator *op) { - Scene *scene= CTX_data_scene(C); Object *ob= CTX_data_edit_object(C); bArmature *arm; char newname[32]; - short axis= RNA_enum_get(op->ptr, "axis"); + short axis= RNA_enum_get(op->ptr, "type"); /* paranoia checks */ if (ELEM(NULL, ob, ob->pose)) @@ -5404,7 +5424,7 @@ static int armature_autoside_names_exec (bContext *C, wmOperator *op) CTX_DATA_END; /* since we renamed stuff... */ - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); /* note, notifier might evolve */ WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob); @@ -5434,7 +5454,7 @@ void ARMATURE_OT_autoside_names (wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; /* settings */ - RNA_def_enum(ot->srna, "axis", axis_items, 0, "Axis", "Axis tag names with."); + RNA_def_enum(ot->srna, "type", axis_items, 0, "Axis", "Axis tag names with."); } @@ -5664,7 +5684,7 @@ void generateSkeletonFromReebGraph(Scene *scene, ReebGraph *rg) if (obedit != NULL) { - ED_armature_from_edit(scene, obedit); + ED_armature_from_edit(obedit); ED_armature_edit_free(obedit); } diff --git a/source/blender/editors/armature/editarmature_generate.c b/source/blender/editors/armature/editarmature_generate.c index 6c0eab16af0..d327ed34839 100644 --- a/source/blender/editors/armature/editarmature_generate.c +++ b/source/blender/editors/armature/editarmature_generate.c @@ -30,6 +30,7 @@ #include #include +#include #include "MEM_guardedalloc.h" diff --git a/source/blender/editors/armature/editarmature_retarget.c b/source/blender/editors/armature/editarmature_retarget.c index 1d87ca8a6df..4d65059c4c6 100644 --- a/source/blender/editors/armature/editarmature_retarget.c +++ b/source/blender/editors/armature/editarmature_retarget.c @@ -2716,7 +2716,6 @@ static void finishRetarget(RigGraph *rigg) static void adjustGraphs(bContext *C, RigGraph *rigg) { - Scene *scene = CTX_data_scene(C); bArmature *arm= rigg->ob->data; RigArc *arc; @@ -2732,14 +2731,13 @@ static void adjustGraphs(bContext *C, RigGraph *rigg) /* Turn the list into an armature */ arm->edbo = rigg->editbones; - ED_armature_from_edit(scene, rigg->ob); + ED_armature_from_edit(rigg->ob); ED_undo_push(C, "Retarget Skeleton"); } static void retargetGraphs(bContext *C, RigGraph *rigg) { - Scene *scene = CTX_data_scene(C); bArmature *arm= rigg->ob->data; ReebGraph *reebg = rigg->link_mesh; RigNode *inode; @@ -2762,7 +2760,7 @@ static void retargetGraphs(bContext *C, RigGraph *rigg) /* Turn the list into an armature */ arm->edbo = rigg->editbones; - ED_armature_from_edit(scene, rigg->ob); + ED_armature_from_edit(rigg->ob); } char *RIG_nameBone(RigGraph *rg, int arc_index, int bone_index) diff --git a/source/blender/editors/armature/meshlaplacian.c b/source/blender/editors/armature/meshlaplacian.c index b44782fca73..76f56f67670 100644 --- a/source/blender/editors/armature/meshlaplacian.c +++ b/source/blender/editors/armature/meshlaplacian.c @@ -672,9 +672,9 @@ void heat_bone_weighting(Object *ob, Mesh *me, float (*verts)[3], int numbones, /* clear weights */ if(bbone && firstsegment) { for(a=0; atotvert; a++) { - remove_vert_defgroup(ob, dgrouplist[j], a); + ED_vgroup_vert_remove(ob, dgrouplist[j], a); if(vertsflipped && dgroupflip[j] && vertsflipped[a] >= 0) - remove_vert_defgroup(ob, dgroupflip[j], vertsflipped[a]); + ED_vgroup_vert_remove(ob, dgroupflip[j], vertsflipped[a]); } } @@ -694,32 +694,32 @@ void heat_bone_weighting(Object *ob, Mesh *me, float (*verts)[3], int numbones, if(bbone) { if(solution > 0.0f) - add_vert_to_defgroup(ob, dgrouplist[j], a, solution, + ED_vgroup_vert_add(ob, dgrouplist[j], a, solution, WEIGHT_ADD); } else { weight= heat_limit_weight(solution); if(weight > 0.0f) - add_vert_to_defgroup(ob, dgrouplist[j], a, weight, + ED_vgroup_vert_add(ob, dgrouplist[j], a, weight, WEIGHT_REPLACE); else - remove_vert_defgroup(ob, dgrouplist[j], a); + ED_vgroup_vert_remove(ob, dgrouplist[j], a); } /* do same for mirror */ if(vertsflipped && dgroupflip[j] && vertsflipped[a] >= 0) { if(bbone) { if(solution > 0.0f) - add_vert_to_defgroup(ob, dgroupflip[j], vertsflipped[a], + ED_vgroup_vert_add(ob, dgroupflip[j], vertsflipped[a], solution, WEIGHT_ADD); } else { weight= heat_limit_weight(solution); if(weight > 0.0f) - add_vert_to_defgroup(ob, dgroupflip[j], vertsflipped[a], + ED_vgroup_vert_add(ob, dgroupflip[j], vertsflipped[a], weight, WEIGHT_REPLACE); else - remove_vert_defgroup(ob, dgroupflip[j], vertsflipped[a]); + ED_vgroup_vert_remove(ob, dgroupflip[j], vertsflipped[a]); } } } @@ -734,16 +734,16 @@ void heat_bone_weighting(Object *ob, Mesh *me, float (*verts)[3], int numbones, /* remove too small vertex weights */ if(bbone && lastsegment) { for(a=0; atotvert; a++) { - weight= get_vert_defgroup(ob, dgrouplist[j], a); + weight= ED_vgroup_vert_weight(ob, dgrouplist[j], a); weight= heat_limit_weight(weight); if(weight <= 0.0f) - remove_vert_defgroup(ob, dgrouplist[j], a); + ED_vgroup_vert_remove(ob, dgrouplist[j], a); if(vertsflipped && dgroupflip[j] && vertsflipped[a] >= 0) { - weight= get_vert_defgroup(ob, dgroupflip[j], vertsflipped[a]); + weight= ED_vgroup_vert_weight(ob, dgroupflip[j], vertsflipped[a]); weight= heat_limit_weight(weight); if(weight <= 0.0f) - remove_vert_defgroup(ob, dgroupflip[j], vertsflipped[a]); + ED_vgroup_vert_remove(ob, dgroupflip[j], vertsflipped[a]); } } } diff --git a/source/blender/editors/armature/poselib.c b/source/blender/editors/armature/poselib.c index 021bec05a3b..c332a297e57 100644 --- a/source/blender/editors/armature/poselib.c +++ b/source/blender/editors/armature/poselib.c @@ -278,29 +278,7 @@ void poselib_validate_act (bAction *act) /* ************************************************************* */ /* Pointers to the builtin KeyingSets that we want to use */ -static KeyingSet *poselib_ks_locrotscale = NULL; /* quaternion rotations */ -static KeyingSet *poselib_ks_locrotscale2 = NULL; /* euler rotations */ // XXX FIXME... -static short poselib_ks_need_init= 1; /* have the above been obtained yet? */ - -/* Make sure the builtin KeyingSets are initialised properly - * (only gets called on first run of poselib_add_current_pose). - */ -static void poselib_get_builtin_keyingsets (void) -{ - /* only if we haven't got these yet */ - // FIXME: this assumes that we will always get the builtin sets... - if (poselib_ks_need_init) { - /* LocRotScale (quaternions) */ - poselib_ks_locrotscale= ANIM_builtin_keyingset_get_named(NULL, "LocRotScale"); - - /* LocRotScale (euler) */ - //ks_locrotscale2= ANIM_builtin_keyingset_get_named(ks_locrotscale, "LocRotScale"); - poselib_ks_locrotscale2= poselib_ks_locrotscale; // FIXME: for now, just use the same one... - - /* clear flag requesting init */ - poselib_ks_need_init= 0; - } -} +static KeyingSet *poselib_ks_locrotscale = NULL; /* the only keyingset we'll need */ /* ----- */ @@ -395,9 +373,6 @@ static int poselib_add_exec (bContext *C, wmOperator *op) /* validate name */ BLI_uniquename(&act->markers, marker, "Pose", '.', offsetof(TimeMarker, name), 64); - /* make sure we've got KeyingSets to use */ - poselib_get_builtin_keyingsets(); - /* init common-key-source for use by KeyingSets */ memset(&cks, 0, sizeof(bCommonKeySrc)); cks.id= &ob->id; @@ -410,11 +385,10 @@ static int poselib_add_exec (bContext *C, wmOperator *op) /* init cks for this PoseChannel, then use the relative KeyingSets to keyframe it */ cks.pchan= pchan; - /* KeyingSet to use depends on rotation mode */ - if (pchan->rotmode) - modify_keyframes(C, &dsources, act, poselib_ks_locrotscale2, MODIFYKEY_MODE_INSERT, (float)frame); - else - modify_keyframes(C, &dsources, act, poselib_ks_locrotscale, MODIFYKEY_MODE_INSERT, (float)frame); + /* KeyingSet to use depends on rotation mode (but that's handled by the templates code) */ + if (poselib_ks_locrotscale == NULL) + poselib_ks_locrotscale= ANIM_builtin_keyingset_get_named(NULL, "LocRotScale"); + modify_keyframes(C, &dsources, act, poselib_ks_locrotscale, MODIFYKEY_MODE_INSERT, (float)frame); } } } @@ -764,13 +738,20 @@ static void poselib_apply_pose (tPoseLib_PreviewData *pld) } /* Auto-keys/tags bones affected by the pose used from the poselib */ -static void poselib_keytag_pose (Scene *scene, tPoseLib_PreviewData *pld) +static void poselib_keytag_pose (bContext *C, Scene *scene, tPoseLib_PreviewData *pld) { bPose *pose= pld->pose; bPoseChannel *pchan; bAction *act= pld->act; bActionGroup *agrp; + bCommonKeySrc cks; + ListBase dsources = {&cks, &cks}; + + /* init common-key-source for use by KeyingSets */ + memset(&cks, 0, sizeof(bCommonKeySrc)); + cks.id= &pld->ob->id; + /* start tagging/keying */ for (agrp= act->groups.first; agrp; agrp= agrp->next) { /* only for selected action channels */ @@ -778,28 +759,17 @@ static void poselib_keytag_pose (Scene *scene, tPoseLib_PreviewData *pld) pchan= get_pose_channel(pose, agrp->name); if (pchan) { -#if 0 // XXX old animation system // TODO: use a standard autokeying function in future (to allow autokeying-editkeys to work) - if (IS_AUTOKEY_MODE(NORMAL)) { - ID *id= &pld->ob->id; + if (IS_AUTOKEY_MODE(scene, NORMAL)) { + /* Set keys on pose + * - KeyingSet to use depends on rotation mode + * (but that's handled by the templates code) + */ + // TODO: for getting the KeyingSet used, we should really check which channels were affected + if (poselib_ks_locrotscale == NULL) + poselib_ks_locrotscale= ANIM_builtin_keyingset_get_named(NULL, "LocRotScale"); - /* Set keys on pose */ - if (pchan->flag & POSE_ROT) { - insertkey(id, ID_PO, pchan->name, NULL, AC_QUAT_X, 0); - insertkey(id, ID_PO, pchan->name, NULL, AC_QUAT_Y, 0); - insertkey(id, ID_PO, pchan->name, NULL, AC_QUAT_Z, 0); - insertkey(id, ID_PO, pchan->name, NULL, AC_QUAT_W, 0); - } - if (pchan->flag & POSE_SIZE) { - insertkey(id, ID_PO, pchan->name, NULL, AC_SIZE_X, 0); - insertkey(id, ID_PO, pchan->name, NULL, AC_SIZE_Y, 0); - insertkey(id, ID_PO, pchan->name, NULL, AC_SIZE_Z, 0); - } - if (pchan->flag & POSE_LOC) { - insertkey(id, ID_PO, pchan->name, NULL, AC_LOC_X, 0); - insertkey(id, ID_PO, pchan->name, NULL, AC_LOC_Y, 0); - insertkey(id, ID_PO, pchan->name, NULL, AC_LOC_Z, 0); - } + modify_keyframes(C, &dsources, NULL, poselib_ks_locrotscale, MODIFYKEY_MODE_INSERT, (float)CFRA); /* clear any unkeyed tags */ if (pchan->bone) @@ -810,7 +780,6 @@ static void poselib_keytag_pose (Scene *scene, tPoseLib_PreviewData *pld) if (pchan->bone) pchan->bone->flag |= BONE_UNKEYED; } -#endif // XXX old animation system } } @@ -843,7 +812,7 @@ static void poselib_preview_apply (bContext *C, wmOperator *op) */ // FIXME: shouldn't this use the builtin stuff? if ((pld->arm->flag & ARM_DELAYDEFORM)==0) - DAG_object_flush_update(pld->scene, pld->ob, OB_RECALC_DATA); /* sets recalc flags */ + DAG_id_flush_update(&pld->ob->id, OB_RECALC_DATA); /* sets recalc flags */ else where_is_pose(pld->scene, pld->ob); } @@ -1346,21 +1315,21 @@ static void poselib_preview_cleanup (bContext *C, wmOperator *op) * - note: code copied from transform_generics.c -> recalcData() */ if ((arm->flag & ARM_DELAYDEFORM)==0) - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); /* sets recalc flags */ + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); /* sets recalc flags */ else where_is_pose(scene, ob); } else if (pld->state == PL_PREVIEW_CONFIRM) { /* tag poses as appropriate */ - poselib_keytag_pose(scene, pld); + poselib_keytag_pose(C, scene, pld); /* change active pose setting */ act->active_marker= BLI_findindex(&act->markers, marker) + 1; action_set_activemarker(act, marker, 0); /* Update event for pose and deformation children */ - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); /* updates */ if (IS_AUTOKEY_MODE(scene, NORMAL)) { diff --git a/source/blender/editors/armature/poseobject.c b/source/blender/editors/armature/poseobject.c index 5b378878f91..bab7111dbd7 100644 --- a/source/blender/editors/armature/poseobject.c +++ b/source/blender/editors/armature/poseobject.c @@ -125,9 +125,8 @@ void ED_armature_enter_posemode(bContext *C, Base *base) switch (ob->type){ case OB_ARMATURE: - + ob->restore_mode = ob->mode; ob->mode |= OB_MODE_POSE; - base->flag= ob->flag; WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_POSE, NULL); @@ -136,7 +135,7 @@ void ED_armature_enter_posemode(bContext *C, Base *base) return; } - ED_object_toggle_modes(C, ob->mode); + //ED_object_toggle_modes(C, ob->mode); } void ED_armature_exit_posemode(bContext *C, Base *base) @@ -144,8 +143,8 @@ void ED_armature_exit_posemode(bContext *C, Base *base) if(base) { Object *ob= base->object; + ob->restore_mode = ob->mode; ob->mode &= ~OB_MODE_POSE; - base->flag= ob->flag; WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_OBJECT, NULL); } @@ -760,6 +759,7 @@ void pose_copy_menu(Scene *scene) break; case 2: /* Local Rotation */ QUATCOPY(pchan->quat, pchanact->quat); + VECCOPY(pchan->eul, pchanact->eul); break; case 3: /* Local Size */ VECCOPY(pchan->size, pchanact->size); @@ -808,11 +808,21 @@ void pose_copy_menu(Scene *scene) break; case 10: /* Visual Rotation */ { - float delta_mat[4][4], quat[4]; + float delta_mat[4][4]; armature_mat_pose_to_bone(pchan, pchanact->pose_mat, delta_mat); - Mat4ToQuat(delta_mat, quat); - QUATCOPY(pchan->quat, quat); + + if (pchan->rotmode == PCHAN_ROT_AXISANGLE) { + float tmp_quat[4]; + + /* need to convert to quat first (in temp var)... */ + Mat4ToQuat(delta_mat, tmp_quat); + QuatToAxisAngle(tmp_quat, &pchan->quat[1], &pchan->quat[0]); + } + else if (pchan->rotmode == PCHAN_ROT_QUAT) + Mat4ToQuat(delta_mat, pchan->quat); + else + Mat4ToEulO(delta_mat, pchan->eul, pchan->rotmode); } break; case 11: /* Visual Size */ @@ -889,7 +899,7 @@ void pose_copy_menu(Scene *scene) ob->pose->flag |= POSE_RECALC; } - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); // and all its relations + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); // and all its relations BIF_undo_push("Copy Pose Attributes"); @@ -951,6 +961,11 @@ void POSE_OT_copy (wmOperatorType *ot) /* ---- */ +/* Pointers to the builtin KeyingSets that we want to use */ +static KeyingSet *posePaste_ks_locrotscale = NULL; /* the only keyingset we'll need */ + +/* ---- */ + static int pose_paste_exec (bContext *C, wmOperator *op) { Scene *scene= CTX_data_scene(C); @@ -959,6 +974,13 @@ static int pose_paste_exec (bContext *C, wmOperator *op) char name[32]; int flip= RNA_boolean_get(op->ptr, "flipped"); + bCommonKeySrc cks; + ListBase dsources = {&cks, &cks}; + + /* init common-key-source for use by KeyingSets */ + memset(&cks, 0, sizeof(bCommonKeySrc)); + cks.id= &ob->id; + /* sanity checks */ if ELEM(NULL, ob, ob->pose) return OPERATOR_CANCELLED; @@ -990,20 +1012,33 @@ static int pose_paste_exec (bContext *C, wmOperator *op) /* check if rotation modes are compatible (i.e. do they need any conversions) */ if (pchan->rotmode == chan->rotmode) { /* copy the type of rotation in use */ - if (pchan->rotmode) { + if (pchan->rotmode > 0) { VECCOPY(pchan->eul, chan->eul); } else { QUATCOPY(pchan->quat, chan->quat); } } - else if (pchan->rotmode) { - /* quat to euler */ - QuatToEul(chan->quat, pchan->eul); + else if (pchan->rotmode > 0) { + /* quat/axis-angle to euler */ + if (chan->rotmode == PCHAN_ROT_AXISANGLE) + AxisAngleToEulO(&chan->quat[1], chan->quat[0], pchan->eul, pchan->rotmode); + else + QuatToEulO(chan->quat, pchan->eul, pchan->rotmode); + } + else if (pchan->rotmode == PCHAN_ROT_AXISANGLE) { + /* quat/euler to axis angle */ + if (chan->rotmode > 0) + EulOToAxisAngle(chan->eul, chan->rotmode, &pchan->quat[1], &pchan->quat[0]); + else + QuatToAxisAngle(chan->quat, &pchan->quat[1], &pchan->quat[0]); } else { - /* euler to quat */ - EulToQuat(chan->eul, pchan->quat); + /* euler/axis-angle to quat */ + if (chan->rotmode > 0) + EulOToQuat(chan->eul, chan->rotmode, pchan->quat); + else + AxisAngleToQuat(pchan->quat, &chan->quat[1], chan->quat[0]); } /* paste flipped pose? */ @@ -1011,10 +1046,25 @@ static int pose_paste_exec (bContext *C, wmOperator *op) pchan->loc[0]*= -1; /* has to be done as eulers... */ - if (pchan->rotmode) { + if (pchan->rotmode > 0) { pchan->eul[1] *= -1; pchan->eul[2] *= -1; } + else if (pchan->rotmode == PCHAN_ROT_AXISANGLE) { + float eul[3]; + + AxisAngleToEulO(&pchan->quat[1], pchan->quat[0], eul, EULER_ORDER_DEFAULT); + eul[1]*= -1; + eul[2]*= -1; + EulOToAxisAngle(eul, EULER_ORDER_DEFAULT, &pchan->quat[1], &pchan->quat[0]); + + // experimental method (uncomment to test): +#if 0 + /* experimental method: just flip the orientation of the axis on x/y axes */ + pchan->quat[1] *= -1; + pchan->quat[2] *= -1; +#endif + } else { float eul[3]; @@ -1025,28 +1075,16 @@ static int pose_paste_exec (bContext *C, wmOperator *op) } } -#if 0 // XXX old animation system - if (autokeyframe_cfra_can_key(ob)) { - ID *id= &ob->id; + if (autokeyframe_cfra_can_key(scene, &ob->id)) { + /* Set keys on pose + * - KeyingSet to use depends on rotation mode + * (but that's handled by the templates code) + */ + // TODO: for getting the KeyingSet used, we should really check which channels were affected + if (posePaste_ks_locrotscale == NULL) + posePaste_ks_locrotscale= ANIM_builtin_keyingset_get_named(NULL, "LocRotScale"); - /* Set keys on pose */ - // TODO: make these use keyingsets.... - if (chan->flag & POSE_ROT) { - insertkey(id, ID_PO, pchan->name, NULL, AC_QUAT_X, 0); - insertkey(id, ID_PO, pchan->name, NULL, AC_QUAT_Y, 0); - insertkey(id, ID_PO, pchan->name, NULL, AC_QUAT_Z, 0); - insertkey(id, ID_PO, pchan->name, NULL, AC_QUAT_W, 0); - } - if (chan->flag & POSE_SIZE) { - insertkey(id, ID_PO, pchan->name, NULL, AC_SIZE_X, 0); - insertkey(id, ID_PO, pchan->name, NULL, AC_SIZE_Y, 0); - insertkey(id, ID_PO, pchan->name, NULL, AC_SIZE_Z, 0); - } - if (chan->flag & POSE_LOC) { - insertkey(id, ID_PO, pchan->name, NULL, AC_LOC_X, 0); - insertkey(id, ID_PO, pchan->name, NULL, AC_LOC_Y, 0); - insertkey(id, ID_PO, pchan->name, NULL, AC_LOC_Z, 0); - } + modify_keyframes(C, &dsources, NULL, posePaste_ks_locrotscale, MODIFYKEY_MODE_INSERT, (float)CFRA); /* clear any unkeyed tags */ if (chan->bone) @@ -1057,13 +1095,12 @@ static int pose_paste_exec (bContext *C, wmOperator *op) if (chan->bone) chan->bone->flag |= BONE_UNKEYED; } -#endif // XXX old animation system } } } /* Update event for pose and deformation children */ - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); if (IS_AUTOKEY_ON(scene)) { // XXX remake_action_ipos(ob->action); @@ -1120,7 +1157,7 @@ void pose_adds_vgroups(Scene *scene, Object *meshobj, int heatweights) // and all its relations - DAG_object_flush_update(scene, meshobj, OB_RECALC_DATA); + DAG_id_flush_update(&meshobj->id, OB_RECALC_DATA); } /* ********************************************** */ @@ -1536,7 +1573,6 @@ void pose_select_grouped_menu (Scene *scene) static int pose_flip_names_exec (bContext *C, wmOperator *op) { - Scene *scene= CTX_data_scene(C); Object *ob= CTX_data_active_object(C); bArmature *arm; char newname[32]; @@ -1556,7 +1592,7 @@ static int pose_flip_names_exec (bContext *C, wmOperator *op) CTX_DATA_END; /* since we renamed stuff... */ - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); /* note, notifier might evolve */ WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob); @@ -1583,7 +1619,6 @@ void POSE_OT_flip_names (wmOperatorType *ot) static int pose_autoside_names_exec (bContext *C, wmOperator *op) { - Scene *scene= CTX_data_scene(C); Object *ob= CTX_data_active_object(C); bArmature *arm; char newname[32]; @@ -1604,7 +1639,7 @@ static int pose_autoside_names_exec (bContext *C, wmOperator *op) CTX_DATA_END; /* since we renamed stuff... */ - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); /* note, notifier might evolve */ WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob); @@ -1672,8 +1707,8 @@ void pose_activate_flipped_bone(Scene *scene) /* in weightpaint we select the associated vertex group too */ if(ob->mode & OB_MODE_WEIGHT_PAINT) { - vertexgroup_select_by_name(OBACT, name); - DAG_object_flush_update(scene, OBACT, OB_RECALC_DATA); + ED_vgroup_select_by_name(OBACT, name); + DAG_id_flush_update(&OBACT->id, OB_RECALC_DATA); } // XXX notifiers need to be sent to other editors to update @@ -1946,6 +1981,7 @@ void ARMATURE_OT_bone_layers (wmOperatorType *ot) RNA_def_boolean_array(ot->srna, "layers", 16, NULL, "Layers", "Armature layers that bone belongs to."); } +/* ********************************************** */ #if 0 // XXX old sys @@ -2112,7 +2148,7 @@ void pose_relax(Scene *scene) pchan->bone->flag &= ~ BONE_TRANSFORM; /* do depsgraph flush */ - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); BIF_undo_push("Relax Pose"); } @@ -2207,7 +2243,7 @@ void pose_clear_user_transforms(Scene *scene, Object *ob) rest_pose(ob->pose); } - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); BIF_undo_push("Clear User Transform"); } -- cgit v1.2.3