2.5
******* -ported clear loc,rot,scale operators to pose mode operators - for some reason when animated and you clear anything, the whole aramture clears. somthing to do with the depsgraph stuff that was directly ported from clear armature()
This commit is contained in:
@@ -40,6 +40,8 @@ struct EditMesh;
|
||||
struct ListBase;
|
||||
struct Main;
|
||||
struct Object;
|
||||
struct Bone;
|
||||
struct bArmature;
|
||||
struct PointerRNA;
|
||||
struct ReportList;
|
||||
struct Scene;
|
||||
|
||||
@@ -37,7 +37,9 @@ EditBone *armature_bone_get_mirrored(ListBase *edbo, EditBone *ebo);
|
||||
|
||||
void POSE_OT_hide(struct wmOperatorType *ot);
|
||||
void POSE_OT_reveil(struct wmOperatorType *ot);
|
||||
|
||||
void POSE_OT_rot_clear(struct wmOperatorType *ot);
|
||||
void POSE_OT_loc_clear(struct wmOperatorType *ot);
|
||||
void POSE_OT_scale_clear(struct wmOperatorType *ot);
|
||||
|
||||
#endif /* ED_ARMATURE_INTERN_H */
|
||||
|
||||
|
||||
@@ -109,6 +109,9 @@ void ED_operatortypes_armature(void)
|
||||
{
|
||||
WM_operatortype_append(POSE_OT_hide);
|
||||
WM_operatortype_append(POSE_OT_reveil);
|
||||
WM_operatortype_append(POSE_OT_rot_clear);
|
||||
WM_operatortype_append(POSE_OT_loc_clear);
|
||||
WM_operatortype_append(POSE_OT_scale_clear);
|
||||
|
||||
WM_operatortype_append(ARMATURE_OT_test); // XXX temp test for context iterators... to be removed
|
||||
}
|
||||
@@ -133,6 +136,9 @@ void ED_keymap_armature(wmWindowManager *wm)
|
||||
kmi= WM_keymap_add_item(keymap, "POSE_OT_hide", HKEY, KM_PRESS, KM_SHIFT, 0);
|
||||
RNA_boolean_set(kmi->ptr, "invert", 1);
|
||||
WM_keymap_add_item(keymap, "POSE_OT_reveil", HKEY, KM_PRESS, KM_ALT, 0);
|
||||
|
||||
/*clear pose*/
|
||||
WM_keymap_add_item(keymap, "POSE_OT_rot_clear", RKEY, KM_PRESS, KM_ALT, 0);
|
||||
WM_keymap_add_item(keymap, "POSE_OT_loc_clear", GKEY, KM_PRESS, KM_ALT, 0);
|
||||
WM_keymap_add_item(keymap, "POSE_OT_scale_clear", SKEY, KM_PRESS, KM_ALT, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -3483,74 +3483,6 @@ void align_selected_bones(Scene *scene)
|
||||
|
||||
/* ***************** Pose tools ********************* */
|
||||
|
||||
void clear_armature(Scene *scene, Object *ob, char mode)
|
||||
{
|
||||
bPoseChannel *pchan;
|
||||
bArmature *arm= ob->data;
|
||||
|
||||
/* only clear those channels that are not locked */
|
||||
for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
|
||||
if (pchan->bone && (pchan->bone->flag & BONE_SELECTED)) {
|
||||
if (arm->layer & pchan->bone->layer) {
|
||||
switch (mode) {
|
||||
case 'r':
|
||||
if (pchan->protectflag & (OB_LOCK_ROTX|OB_LOCK_ROTY|OB_LOCK_ROTZ)) {
|
||||
float eul[3], oldeul[3], quat1[4];
|
||||
|
||||
QUATCOPY(quat1, pchan->quat);
|
||||
QuatToEul(pchan->quat, oldeul);
|
||||
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];
|
||||
|
||||
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 {
|
||||
pchan->quat[1]=pchan->quat[2]=pchan->quat[3]=0.0F;
|
||||
pchan->quat[0]=1.0F;
|
||||
}
|
||||
break;
|
||||
case 'g':
|
||||
if ((pchan->protectflag & OB_LOCK_LOCX)==0)
|
||||
pchan->loc[0]= 0.0f;
|
||||
if ((pchan->protectflag & OB_LOCK_LOCY)==0)
|
||||
pchan->loc[1]= 0.0f;
|
||||
if ((pchan->protectflag & OB_LOCK_LOCZ)==0)
|
||||
pchan->loc[2]= 0.0f;
|
||||
break;
|
||||
case 's':
|
||||
if ((pchan->protectflag & OB_LOCK_SCALEX)==0)
|
||||
pchan->size[0]= 1.0f;
|
||||
if ((pchan->protectflag & OB_LOCK_SCALEY)==0)
|
||||
pchan->size[1]= 1.0f;
|
||||
if ((pchan->protectflag & OB_LOCK_SCALEZ)==0)
|
||||
pchan->size[2]= 1.0f;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
/* the current values from IPO's may not be zero, so tag as unkeyed */
|
||||
pchan->bone->flag |= BONE_UNKEYED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
|
||||
/* no update for this object, this will execute the action again */
|
||||
/* is weak... like for ipo editing which uses ctime now... */
|
||||
where_is_pose (scene, ob);
|
||||
ob->recalc= 0;
|
||||
}
|
||||
|
||||
/* helper for function below */
|
||||
static int clear_active_flag(Object *ob, Bone *bone, void *data)
|
||||
{
|
||||
@@ -4079,7 +4011,169 @@ void create_vgroups_from_armature(Scene *scene, Object *ob, Object *par)
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* ************* Clear Pose *****************************/
|
||||
static int pose_clear_scale_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
Object *ob= CTX_data_active_object(C);
|
||||
bArmature *arm= ob->data;
|
||||
|
||||
/* only clear those channels that are not locked */
|
||||
CTX_DATA_BEGIN(C, bPoseChannel*, pchan, selected_pchans){
|
||||
if (arm->layer & pchan->bone->layer) {
|
||||
if ((pchan->protectflag & OB_LOCK_SCALEX)==0)
|
||||
pchan->size[0]= 1.0f;
|
||||
if ((pchan->protectflag & OB_LOCK_SCALEY)==0)
|
||||
pchan->size[1]= 1.0f;
|
||||
if ((pchan->protectflag & OB_LOCK_SCALEZ)==0)
|
||||
pchan->size[2]= 1.0f;
|
||||
/* the current values from IPO's may not be zero, so tag as unkeyed */
|
||||
pchan->bone->flag |= BONE_UNKEYED;
|
||||
}
|
||||
}
|
||||
CTX_DATA_END;
|
||||
|
||||
DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
|
||||
/* no update for this object, this will execute the action again */
|
||||
/* is weak... like for ipo editing which uses ctime now... */
|
||||
where_is_pose (scene, ob);
|
||||
ob->recalc= 0;
|
||||
|
||||
/* note, notifier might evolve */
|
||||
WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, ob);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
void POSE_OT_scale_clear(wmOperatorType *ot)
|
||||
{
|
||||
/* identifiers */
|
||||
ot->name= "Clear Pose Scale";
|
||||
ot->idname= "POSE_OT_scale_clear";
|
||||
|
||||
/* api callbacks */
|
||||
ot->invoke = WM_operator_confirm;
|
||||
ot->exec = pose_clear_scale_exec;
|
||||
ot->poll = ED_operator_posemode;
|
||||
|
||||
/* flags */
|
||||
ot->flag= OPTYPE_UNDO;
|
||||
}
|
||||
|
||||
static int pose_clear_loc_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
Object *ob= CTX_data_active_object(C);
|
||||
bArmature *arm= ob->data;
|
||||
|
||||
/* only clear those channels that are not locked */
|
||||
CTX_DATA_BEGIN(C, bPoseChannel*, pchan, selected_pchans){
|
||||
if (arm->layer & pchan->bone->layer) {
|
||||
if ((pchan->protectflag & OB_LOCK_LOCX)==0)
|
||||
pchan->loc[0]= 0.0f;
|
||||
if ((pchan->protectflag & OB_LOCK_LOCY)==0)
|
||||
pchan->loc[1]= 0.0f;
|
||||
if ((pchan->protectflag & OB_LOCK_LOCZ)==0)
|
||||
pchan->loc[2]= 0.0f;
|
||||
/* the current values from IPO's may not be zero, so tag as unkeyed */
|
||||
pchan->bone->flag |= BONE_UNKEYED;
|
||||
}
|
||||
}
|
||||
CTX_DATA_END;
|
||||
|
||||
DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
|
||||
/* no update for this object, this will execute the action again */
|
||||
/* is weak... like for ipo editing which uses ctime now... */
|
||||
where_is_pose (scene, ob);
|
||||
ob->recalc= 0;
|
||||
|
||||
/* note, notifier might evolve */
|
||||
WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, ob);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
void POSE_OT_loc_clear(wmOperatorType *ot)
|
||||
{
|
||||
/* identifiers */
|
||||
ot->name= "Clear Pose Location";
|
||||
ot->idname= "POSE_OT_loc_clear";
|
||||
|
||||
/* api callbacks */
|
||||
ot->invoke = WM_operator_confirm;
|
||||
ot->exec = pose_clear_loc_exec;
|
||||
ot->poll = ED_operator_posemode;
|
||||
|
||||
/* flags */
|
||||
ot->flag= OPTYPE_UNDO;
|
||||
}
|
||||
|
||||
static int pose_clear_rot_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
Object *ob= CTX_data_active_object(C);
|
||||
bArmature *arm= ob->data;
|
||||
|
||||
/* only clear those channels that are not locked */
|
||||
CTX_DATA_BEGIN(C, bPoseChannel*, pchan, selected_pchans){
|
||||
if (arm->layer & pchan->bone->layer) {
|
||||
if (pchan->protectflag & (OB_LOCK_ROTX|OB_LOCK_ROTY|OB_LOCK_ROTZ)) {
|
||||
float eul[3], oldeul[3], quat1[4];
|
||||
|
||||
QUATCOPY(quat1, pchan->quat);
|
||||
QuatToEul(pchan->quat, oldeul);
|
||||
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];
|
||||
|
||||
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 {
|
||||
pchan->quat[1]=pchan->quat[2]=pchan->quat[3]=0.0F;
|
||||
pchan->quat[0]=1.0F;
|
||||
}
|
||||
/* the current values from IPO's may not be zero, so tag as unkeyed */
|
||||
pchan->bone->flag |= BONE_UNKEYED;
|
||||
}
|
||||
}
|
||||
CTX_DATA_END;
|
||||
|
||||
DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
|
||||
/* no update for this object, this will execute the action again */
|
||||
/* is weak... like for ipo editing which uses ctime now... */
|
||||
where_is_pose (scene, ob);
|
||||
ob->recalc= 0;
|
||||
|
||||
/* note, notifier might evolve */
|
||||
WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, ob);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
void POSE_OT_rot_clear(wmOperatorType *ot)
|
||||
{
|
||||
/* identifiers */
|
||||
ot->name= "Clear Pose Rotation";
|
||||
ot->idname= "POSE_OT_rot_clear";
|
||||
|
||||
/* api callbacks */
|
||||
ot->invoke = WM_operator_confirm;
|
||||
ot->exec = pose_clear_rot_exec;
|
||||
ot->poll = ED_operator_posemode;
|
||||
|
||||
/* flags */
|
||||
ot->flag= OPTYPE_UNDO;
|
||||
|
||||
}
|
||||
/* ************* hide/unhide pose bones ******************* */
|
||||
|
||||
static int hide_selected_pose_bone(Object *ob, Bone *bone, void *ptr)
|
||||
|
||||
@@ -1669,17 +1669,7 @@ static int object_clear_location_exec(bContext *C, wmOperator *op)
|
||||
int armature_clear= 0;
|
||||
|
||||
CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
|
||||
if ((ob->flag & OB_POSEMODE)) {
|
||||
/* only clear pose transforms if:
|
||||
* - with a mesh in weightpaint mode, it's related armature needs to be cleared
|
||||
* - with clearing transform of object being edited at the time
|
||||
*/
|
||||
if ((G.f & G_WEIGHTPAINT) || (ob==OBACT)) {
|
||||
clear_armature(scene, ob, 'g');
|
||||
armature_clear= 1; /* silly system to prevent another dag update, so no action applied */
|
||||
}
|
||||
}
|
||||
else if((G.f & G_WEIGHTPAINT)==0) {
|
||||
if((G.f & G_WEIGHTPAINT)==0) {
|
||||
if ((ob->protectflag & OB_LOCK_LOCX)==0)
|
||||
ob->loc[0]= ob->dloc[0]= 0.0f;
|
||||
if ((ob->protectflag & OB_LOCK_LOCY)==0)
|
||||
@@ -1722,17 +1712,7 @@ static int object_clear_rotation_exec(bContext *C, wmOperator *op)
|
||||
int armature_clear= 0;
|
||||
|
||||
CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
|
||||
if ((ob->flag & OB_POSEMODE)) {
|
||||
/* only clear pose transforms if:
|
||||
* - with a mesh in weightpaint mode, it's related armature needs to be cleared
|
||||
* - with clearing transform of object being edited at the time
|
||||
*/
|
||||
if ((G.f & G_WEIGHTPAINT) || (ob==OBACT)) {
|
||||
clear_armature(scene, ob, 'r');
|
||||
armature_clear= 1; /* silly system to prevent another dag update, so no action applied */
|
||||
}
|
||||
}
|
||||
else if((G.f & G_WEIGHTPAINT)==0) {
|
||||
if((G.f & G_WEIGHTPAINT)==0) {
|
||||
/* eulers can only get cleared if they are not protected */
|
||||
if ((ob->protectflag & OB_LOCK_ROTX)==0)
|
||||
ob->rot[0]= ob->drot[0]= 0.0f;
|
||||
@@ -1776,17 +1756,7 @@ static int object_clear_scale_exec(bContext *C, wmOperator *op)
|
||||
int armature_clear= 0;
|
||||
|
||||
CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
|
||||
if ((ob->flag & OB_POSEMODE)) {
|
||||
/* only clear pose transforms if:
|
||||
* - with a mesh in weightpaint mode, it's related armature needs to be cleared
|
||||
* - with clearing transform of object being edited at the time
|
||||
*/
|
||||
if ((G.f & G_WEIGHTPAINT) || (ob==OBACT)) {
|
||||
clear_armature(scene, ob, 's');
|
||||
armature_clear= 1; /* silly system to prevent another dag update, so no action applied */
|
||||
}
|
||||
}
|
||||
else if((G.f & G_WEIGHTPAINT)==0) {
|
||||
if((G.f & G_WEIGHTPAINT)==0) {
|
||||
if ((ob->protectflag & OB_LOCK_SCALEX)==0) {
|
||||
ob->dsize[0]= 0.0f;
|
||||
ob->size[0]= 1.0f;
|
||||
|
||||
Reference in New Issue
Block a user