Whitespace commit for editarmature.c while I try to find the cause of some bugs here.

This commit is contained in:
Joshua Leung 2008-04-02 04:31:41 +00:00
parent 65a4f5c556
commit 64201b0f24

@ -135,14 +135,14 @@ void make_boneList(ListBase *list, ListBase *bones, EditBone *parent)
eBone= MEM_callocN(sizeof(EditBone), "make_editbone"); eBone= MEM_callocN(sizeof(EditBone), "make_editbone");
/* Copy relevant data from bone to eBone */ /* Copy relevant data from bone to eBone */
eBone->parent=parent; eBone->parent= parent;
BLI_strncpy (eBone->name, curBone->name, 32); BLI_strncpy(eBone->name, curBone->name, 32);
eBone->flag = curBone->flag; eBone->flag = curBone->flag;
/* fix selection flags */ /* fix selection flags */
if (eBone->flag & BONE_SELECTED) { if (eBone->flag & BONE_SELECTED) {
eBone->flag |= BONE_TIPSEL; eBone->flag |= BONE_TIPSEL;
if(eBone->parent && (eBone->flag & BONE_CONNECTED)) if (eBone->parent && (eBone->flag & BONE_CONNECTED))
eBone->parent->flag |= BONE_TIPSEL; eBone->parent->flag |= BONE_TIPSEL;
else else
eBone->flag |= BONE_ROOTSEL; eBone->flag |= BONE_ROOTSEL;
@ -156,7 +156,7 @@ void make_boneList(ListBase *list, ListBase *bones, EditBone *parent)
eBone->roll= 0.0; eBone->roll= 0.0;
/* roll fixing */ /* roll fixing */
VecSubf (delta, eBone->tail, eBone->head); VecSubf(delta, eBone->tail, eBone->head);
vec_roll_to_mat3(delta, 0.0, postmat); vec_roll_to_mat3(delta, 0.0, postmat);
Mat3CpyMat4(premat, curBone->arm_mat); Mat3CpyMat4(premat, curBone->arm_mat);
@ -262,16 +262,16 @@ void editbones_to_armature (ListBase *list, Object *ob)
fBone->parent= eBone->parent; fBone->parent= eBone->parent;
} }
printf("Warning: removed zero sized bone: %s\n", eBone->name); printf("Warning: removed zero sized bone: %s\n", eBone->name);
BLI_freelinkN (list, eBone); BLI_freelinkN(list, eBone);
} }
} }
/* Copy the bones from the editData into the armature */ /* Copy the bones from the editData into the armature */
for (eBone=list->first; eBone; eBone=eBone->next) { for (eBone=list->first; eBone; eBone=eBone->next) {
newBone= MEM_callocN (sizeof(Bone), "bone"); newBone= MEM_callocN(sizeof(Bone), "bone");
eBone->temp= newBone; /* Associate the real Bones with the EditBones */ eBone->temp= newBone; /* Associate the real Bones with the EditBones */
BLI_strncpy (newBone->name, eBone->name, 32); BLI_strncpy(newBone->name, eBone->name, 32);
memcpy(newBone->head, eBone->head, sizeof(float)*3); memcpy(newBone->head, eBone->head, sizeof(float)*3);
memcpy(newBone->tail, eBone->tail, sizeof(float)*3); memcpy(newBone->tail, eBone->tail, sizeof(float)*3);
newBone->flag= eBone->flag; newBone->flag= eBone->flag;
@ -297,8 +297,8 @@ void editbones_to_armature (ListBase *list, Object *ob)
for (eBone=list->first;eBone;eBone=eBone->next) { for (eBone=list->first;eBone;eBone=eBone->next) {
newBone= (Bone *)eBone->temp; newBone= (Bone *)eBone->temp;
if (eBone->parent) { if (eBone->parent) {
newBone->parent=(Bone *)eBone->parent->temp; newBone->parent= (Bone *)eBone->parent->temp;
BLI_addtail(&newBone->parent->childbase,newBone); BLI_addtail(&newBone->parent->childbase, newBone);
{ {
float M_boneRest[3][3]; float M_boneRest[3][3];
@ -307,11 +307,11 @@ void editbones_to_armature (ListBase *list, Object *ob)
float delta[3]; float delta[3];
/* Get the parent's matrix (rotation only) */ /* Get the parent's matrix (rotation only) */
VecSubf (delta, eBone->parent->tail, eBone->parent->head); VecSubf(delta, eBone->parent->tail, eBone->parent->head);
vec_roll_to_mat3(delta, eBone->parent->roll, M_parentRest); vec_roll_to_mat3(delta, eBone->parent->roll, M_parentRest);
/* Get this bone's matrix (rotation only) */ /* Get this bone's matrix (rotation only) */
VecSubf (delta, eBone->tail, eBone->head); VecSubf(delta, eBone->tail, eBone->head);
vec_roll_to_mat3(delta, eBone->roll, M_boneRest); vec_roll_to_mat3(delta, eBone->roll, M_boneRest);
/* Invert the parent matrix */ /* Invert the parent matrix */
@ -327,7 +327,7 @@ void editbones_to_armature (ListBase *list, Object *ob)
} }
/* ...otherwise add this bone to the armature's bonebase */ /* ...otherwise add this bone to the armature's bonebase */
else else
BLI_addtail(&arm->bonebase,newBone); BLI_addtail(&arm->bonebase, newBone);
} }
/* Make a pass through the new armature to fix rolling */ /* Make a pass through the new armature to fix rolling */
@ -336,7 +336,7 @@ void editbones_to_armature (ListBase *list, Object *ob)
/* so all users of this armature should get rebuilt */ /* so all users of this armature should get rebuilt */
for (obt= G.main->object.first; obt; obt= obt->id.next) { for (obt= G.main->object.first; obt; obt= obt->id.next) {
if(obt->data==arm) if (obt->data==arm)
armature_rebuild_pose(obt, arm); armature_rebuild_pose(obt, arm);
} }
@ -558,7 +558,7 @@ int join_armature(void)
/* if(G.obedit) return; */ /* Alredy checked in join_menu() */ /* if(G.obedit) return; */ /* Alredy checked in join_menu() */
ob= OBACT; ob= OBACT;
if(ob->type!=OB_ARMATURE) return 0; if (ob->type!=OB_ARMATURE) return 0;
if (object_data_is_libdata(ob)) { if (object_data_is_libdata(ob)) {
error_libdata(); error_libdata();
return 0; return 0;
@ -573,10 +573,10 @@ int join_armature(void)
for (base=FIRSTBASE; base; base=nextbase) { for (base=FIRSTBASE; base; base=nextbase) {
nextbase = base->next; nextbase = base->next;
if (TESTBASE(base)){ if (TESTBASE(base)){
if ((base->object->type==OB_ARMATURE) && (base->object!=ob)){ if ((base->object->type==OB_ARMATURE) && (base->object!=ob)) {
/* Make a list of editbones in current armature */ /* Make a list of editbones in current armature */
eblist.first=eblist.last= NULL; eblist.first=eblist.last= NULL;
make_boneList (&eblist, &((bArmature*)base->object->data)->bonebase,NULL); make_boneList(&eblist, &((bArmature *)base->object->data)->bonebase, NULL);
/* Get Pose of current armature */ /* Get Pose of current armature */
opose= base->object->pose; opose= base->object->pose;
@ -591,7 +591,7 @@ int join_armature(void)
curbone= editbone_name_exists(&eblist, pchan->name); curbone= editbone_name_exists(&eblist, pchan->name);
/* Get new name */ /* Get new name */
unique_editbone_name (&ebbase, curbone->name); unique_editbone_name(&ebbase, curbone->name);
/* Transform the bone */ /* Transform the bone */
{ {
@ -1818,13 +1818,13 @@ static void add_primitive_bone(Object *ob, short newob)
float obmat[3][3], curs[3], viewmat[3][3], totmat[3][3], imat[3][3]; float obmat[3][3], curs[3], viewmat[3][3], totmat[3][3], imat[3][3];
EditBone *bone; EditBone *bone;
VECCOPY (curs, give_cursor()); VECCOPY(curs, give_cursor());
/* Get inverse point for head and orientation for tail */ /* Get inverse point for head and orientation for tail */
Mat4Invert(G.obedit->imat, G.obedit->obmat); Mat4Invert(G.obedit->imat, G.obedit->obmat);
Mat4MulVecfl(G.obedit->imat, curs); Mat4MulVecfl(G.obedit->imat, curs);
if ( !(newob) || U.flag & USER_ADD_VIEWALIGNED) Mat3CpyMat4(obmat, G.vd->viewmat); if ( !(newob) || (U.flag & USER_ADD_VIEWALIGNED) ) Mat3CpyMat4(obmat, G.vd->viewmat);
else Mat3One(obmat); else Mat3One(obmat);
Mat3CpyMat4(viewmat, G.obedit->obmat); Mat3CpyMat4(viewmat, G.obedit->obmat);
@ -1838,7 +1838,7 @@ static void add_primitive_bone(Object *ob, short newob)
VECCOPY(bone->head, curs); VECCOPY(bone->head, curs);
if ( !(newob) || U.flag & USER_ADD_VIEWALIGNED) if ( !(newob) || (U.flag & USER_ADD_VIEWALIGNED) )
VecAddf(bone->tail, bone->head, imat[1]); // bone with unit length 1 VecAddf(bone->tail, bone->head, imat[1]); // bone with unit length 1
else else
VecAddf(bone->tail, bone->head, imat[2]); // bone with unit length 1, pointing up Z VecAddf(bone->tail, bone->head, imat[2]); // bone with unit length 1, pointing up Z
@ -1853,7 +1853,7 @@ void add_primitiveArmature(int type)
/* this function also comes from an info window */ /* this function also comes from an info window */
if ELEM(curarea->spacetype, SPACE_VIEW3D, SPACE_INFO); else return; if ELEM(curarea->spacetype, SPACE_VIEW3D, SPACE_INFO); else return;
if(G.vd==NULL) return; if (G.vd==NULL) return;
G.f &= ~(G_VERTEXPAINT+G_TEXTUREPAINT+G_WEIGHTPAINT); G.f &= ~(G_VERTEXPAINT+G_TEXTUREPAINT+G_WEIGHTPAINT);
setcursor_space(SPACE_VIEW3D, CURSOR_STD); setcursor_space(SPACE_VIEW3D, CURSOR_STD);
@ -1861,7 +1861,7 @@ void add_primitiveArmature(int type)
check_editmode(OB_ARMATURE); check_editmode(OB_ARMATURE);
/* If we're not the "obedit", make a new object and enter editmode */ /* If we're not the "obedit", make a new object and enter editmode */
if(G.obedit==NULL) { if (G.obedit==NULL) {
add_object(OB_ARMATURE); add_object(OB_ARMATURE);
base_init_from_view3d(BASACT, G.vd); base_init_from_view3d(BASACT, G.vd);
G.obedit= BASACT->object; G.obedit= BASACT->object;
@ -1878,7 +1878,7 @@ void add_primitiveArmature(int type)
countall(); // flushes selection! countall(); // flushes selection!
if ( (newob) && !(U.flag & USER_ADD_EDITMODE)) { if ((newob) && !(U.flag & USER_ADD_EDITMODE)) {
exit_editmode(2); exit_editmode(2);
} }
@ -1897,17 +1897,23 @@ void addvert_armature(void)
TEST_EDITARMATURE; TEST_EDITARMATURE;
/* find the active or selected bone */ /* find the active or selected bone */
for (ebone = G.edbo.first; ebone; ebone=ebone->next) for (ebone = G.edbo.first; ebone; ebone=ebone->next) {
if(arm->layer & ebone->layer) if (arm->layer & ebone->layer) {
if(ebone->flag & (BONE_ACTIVE|BONE_TIPSEL)) break; if (ebone->flag & (BONE_ACTIVE|BONE_TIPSEL))
break;
}
}
if(ebone==NULL) { if (ebone==NULL) {
for (ebone = G.edbo.first; ebone; ebone=ebone->next) for (ebone = G.edbo.first; ebone; ebone=ebone->next) {
if(arm->layer & ebone->layer) if (arm->layer & ebone->layer) {
if(ebone->flag & (BONE_ACTIVE|BONE_ROOTSEL)) break; if (ebone->flag & (BONE_ACTIVE|BONE_ROOTSEL))
break;
if(ebone==NULL) }
}
if (ebone == NULL)
return; return;
to_root= 1; to_root= 1;
} }
@ -1915,12 +1921,12 @@ void addvert_armature(void)
/* we re-use code for mirror editing... */ /* we re-use code for mirror editing... */
flipbone= NULL; flipbone= NULL;
if(arm->flag & ARM_MIRROR_EDIT) if (arm->flag & ARM_MIRROR_EDIT)
flipbone= armature_bone_get_mirrored(ebone); flipbone= armature_bone_get_mirrored(ebone);
for(a=0; a<2; a++) { for (a=0; a<2; a++) {
if(a==1) { if (a==1) {
if(flipbone==NULL) if (flipbone==NULL)
break; break;
else { else {
SWAP(EditBone *, flipbone, ebone); SWAP(EditBone *, flipbone, ebone);
@ -1930,7 +1936,7 @@ void addvert_armature(void)
newbone= add_editbone(ebone->name); newbone= add_editbone(ebone->name);
newbone->flag |= BONE_ACTIVE; newbone->flag |= BONE_ACTIVE;
if(to_root) { if (to_root) {
VECCOPY(newbone->head, ebone->head); VECCOPY(newbone->head, ebone->head);
newbone->rad_head= ebone->rad_tail; newbone->rad_head= ebone->rad_tail;
newbone->parent= ebone->parent; newbone->parent= ebone->parent;
@ -1946,7 +1952,7 @@ void addvert_armature(void)
VECCOPY(newbone->tail, curs); VECCOPY(newbone->tail, curs);
VecSubf(newbone->tail, newbone->tail, G.obedit->obmat[3]); VecSubf(newbone->tail, newbone->tail, G.obedit->obmat[3]);
if(a==1) if (a==1)
newbone->tail[0]= -newbone->tail[0]; newbone->tail[0]= -newbone->tail[0];
Mat3CpyMat4(mat, G.obedit->obmat); Mat3CpyMat4(mat, G.obedit->obmat);
@ -1959,13 +1965,10 @@ void addvert_armature(void)
} }
countall(); countall();
BIF_undo_push("Add Bone"); BIF_undo_push("Add Bone");
allqueue(REDRAWVIEW3D, 0); allqueue(REDRAWVIEW3D, 0);
while(get_mbut()&R_MOUSE);
} }
/* adds an EditBone between the nominated locations (should be in the right space) */ /* adds an EditBone between the nominated locations (should be in the right space) */
@ -1987,8 +1990,8 @@ static EditBone *get_named_editbone(char *name)
EditBone *eBone; EditBone *eBone;
if (name) if (name)
for (eBone=G.edbo.first; eBone; eBone=eBone->next){ for (eBone=G.edbo.first; eBone; eBone=eBone->next) {
if (!strcmp (name, eBone->name)) if (!strcmp(name, eBone->name))
return eBone; return eBone;
} }
@ -2006,7 +2009,6 @@ static void update_dup_subtarget(EditBone *dupBone)
bConstraint *curcon; bConstraint *curcon;
ListBase *conlist; ListBase *conlist;
if ( (chan = verify_pose_channel(OBACT->pose, dupBone->name)) ) { if ( (chan = verify_pose_channel(OBACT->pose, dupBone->name)) ) {
if ( (conlist = &chan->constraints) ) { if ( (conlist = &chan->constraints) ) {
for (curcon = conlist->first; curcon; curcon=curcon->next) { for (curcon = conlist->first; curcon; curcon=curcon->next) {
@ -2068,10 +2070,9 @@ void adduplicate_armature(void)
} }
/* Find the selected bones and duplicate them as needed */ /* Find the selected bones and duplicate them as needed */
for (curBone=G.edbo.first; curBone && curBone!=firstDup; curBone=curBone->next){ for (curBone=G.edbo.first; curBone && curBone!=firstDup; curBone=curBone->next) {
if (arm->layer & curBone->layer) { if (arm->layer & curBone->layer) {
if (curBone->flag & BONE_SELECTED) { if (curBone->flag & BONE_SELECTED) {
eBone=MEM_callocN(sizeof(EditBone), "addup_editbone"); eBone=MEM_callocN(sizeof(EditBone), "addup_editbone");
eBone->flag |= BONE_SELECTED; eBone->flag |= BONE_SELECTED;
@ -2081,8 +2082,8 @@ void adduplicate_armature(void)
curBone->temp = eBone; curBone->temp = eBone;
eBone->temp = curBone; eBone->temp = curBone;
unique_editbone_name (&G.edbo, eBone->name); unique_editbone_name(&G.edbo, eBone->name);
BLI_addtail (&G.edbo, eBone); BLI_addtail(&G.edbo, eBone);
if (!firstDup) if (!firstDup)
firstDup=eBone; firstDup=eBone;
@ -2125,23 +2126,21 @@ void adduplicate_armature(void)
} }
/* Run though the list and fix the pointers */ /* Run though the list and fix the pointers */
for (curBone=G.edbo.first; curBone && curBone!=firstDup; curBone=curBone->next){ for (curBone=G.edbo.first; curBone && curBone!=firstDup; curBone=curBone->next) {
if(arm->layer & curBone->layer) { if (arm->layer & curBone->layer) {
if (curBone->flag & BONE_SELECTED){ if (curBone->flag & BONE_SELECTED) {
eBone=(EditBone*) curBone->temp; eBone=(EditBone*) curBone->temp;
/* If this bone has no parent, /* If this bone has no parent,
Set the duplicate->parent to NULL Set the duplicate->parent to NULL
*/ */
if (!curBone->parent){ if (!curBone->parent)
eBone->parent = NULL; eBone->parent = NULL;
}
/* If this bone has a parent that IS selected, /* If this bone has a parent that IS selected,
Set the duplicate->parent to the curBone->parent->duplicate Set the duplicate->parent to the curBone->parent->duplicate
*/ */
else if (curBone->parent->flag & BONE_SELECTED){ else if (curBone->parent->flag & BONE_SELECTED)
eBone->parent=(EditBone*) curBone->parent->temp; eBone->parent= (EditBone *)curBone->parent->temp;
}
/* If this bone has a parent that IS not selected, /* If this bone has a parent that IS not selected,
Set the duplicate->parent to the curBone->parent Set the duplicate->parent to the curBone->parent
*/ */
@ -2159,8 +2158,8 @@ void adduplicate_armature(void)
/* Deselect the old bones and select the new ones */ /* Deselect the old bones and select the new ones */
for (curBone=G.edbo.first; curBone && curBone!=firstDup; curBone=curBone->next){ for (curBone=G.edbo.first; curBone && curBone!=firstDup; curBone=curBone->next) {
if(arm->layer & curBone->layer) if (arm->layer & curBone->layer)
curBone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL | BONE_ACTIVE); curBone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL | BONE_ACTIVE);
} }
@ -2249,12 +2248,11 @@ static void fill_add_joint (EditBone *ebo, short eb_tail, ListBase *points)
VECCOPY(vec, ebo->head); VECCOPY(vec, ebo->head);
} }
// FIXME: this algorithm sucks... it misses things it shouldn't
for (ebp= points->first; ebp; ebp= ebp->next) { for (ebp= points->first; ebp; ebp= ebp->next) {
if (VecEqual(ebp->vec, vec)) { if (VecEqual(ebp->vec, vec)) {
if (eb_tail) { if (eb_tail) {
if ((ebp->head_owner) && (ebp->head_owner->parent == ebo)) { if ((ebp->head_owner) && (ebp->head_owner->parent == ebo)) {
/* so this bone's tail owner is this bone*/ /* so this bone's tail owner is this bone */
ebp->tail_owner= ebo; ebp->tail_owner= ebo;
found= 1; found= 1;
break; break;
@ -2561,9 +2559,9 @@ void hide_selected_armature_bones(void)
bArmature *arm= G.obedit->data; bArmature *arm= G.obedit->data;
EditBone *ebone; EditBone *ebone;
for (ebone = G.edbo.first; ebone; ebone=ebone->next){ for (ebone = G.edbo.first; ebone; ebone=ebone->next) {
if(arm->layer & ebone->layer) { if (arm->layer & ebone->layer) {
if(ebone->flag & (BONE_SELECTED)) { if (ebone->flag & (BONE_SELECTED)) {
ebone->flag &= ~(BONE_TIPSEL|BONE_SELECTED|BONE_ROOTSEL|BONE_ACTIVE); ebone->flag &= ~(BONE_TIPSEL|BONE_SELECTED|BONE_ROOTSEL|BONE_ACTIVE);
ebone->flag |= BONE_HIDDEN_A; ebone->flag |= BONE_HIDDEN_A;
} }
@ -2579,10 +2577,10 @@ void hide_unselected_armature_bones(void)
{ {
EditBone *ebone; EditBone *ebone;
for (ebone = G.edbo.first; ebone; ebone=ebone->next){ for (ebone = G.edbo.first; ebone; ebone=ebone->next) {
bArmature *arm= G.obedit->data; bArmature *arm= G.obedit->data;
if(arm->layer & ebone->layer) { if (arm->layer & ebone->layer) {
if(ebone->flag & (BONE_TIPSEL|BONE_SELECTED|BONE_ROOTSEL)); if (ebone->flag & (BONE_TIPSEL|BONE_SELECTED|BONE_ROOTSEL));
else { else {
ebone->flag &= ~BONE_ACTIVE; ebone->flag &= ~BONE_ACTIVE;
ebone->flag |= BONE_HIDDEN_A; ebone->flag |= BONE_HIDDEN_A;
@ -2599,10 +2597,10 @@ void show_all_armature_bones(void)
{ {
EditBone *ebone; EditBone *ebone;
for (ebone = G.edbo.first; ebone; ebone=ebone->next){ for (ebone = G.edbo.first; ebone; ebone=ebone->next) {
bArmature *arm= G.obedit->data; bArmature *arm= G.obedit->data;
if(arm->layer & ebone->layer) { if(arm->layer & ebone->layer) {
if(ebone->flag & BONE_HIDDEN_A) { if (ebone->flag & BONE_HIDDEN_A) {
ebone->flag |= (BONE_TIPSEL|BONE_SELECTED|BONE_ROOTSEL); ebone->flag |= (BONE_TIPSEL|BONE_SELECTED|BONE_ROOTSEL);
ebone->flag &= ~BONE_HIDDEN_A; ebone->flag &= ~BONE_HIDDEN_A;
} }
@ -2771,7 +2769,7 @@ static void editbone_clear_parent(EditBone *ebone, int mode)
ebone->parent->flag &= ~(BONE_TIPSEL); ebone->parent->flag &= ~(BONE_TIPSEL);
} }
if(mode==1) ebone->parent= NULL; if (mode==1) ebone->parent= NULL;
ebone->flag &= ~BONE_CONNECTED; ebone->flag &= ~BONE_CONNECTED;
} }
@ -2783,13 +2781,12 @@ void clear_bone_parent(void)
short val; short val;
val= pupmenu("Clear Parent%t|Clear Parent%x1|Disconnect Bone%x2"); val= pupmenu("Clear Parent%t|Clear Parent%x1|Disconnect Bone%x2");
if (val<1) return;
if(val<1) return;
for (ebone = G.edbo.first; ebone; ebone=ebone->next) { for (ebone = G.edbo.first; ebone; ebone=ebone->next) {
if(arm->layer & ebone->layer) { if (arm->layer & ebone->layer) {
if(ebone->flag & BONE_SELECTED) { if (ebone->flag & BONE_SELECTED) {
if (arm->flag & ARM_MIRROR_EDIT)
if(arm->flag & ARM_MIRROR_EDIT)
flipbone = armature_bone_get_mirrored(ebone); flipbone = armature_bone_get_mirrored(ebone);
if (flipbone) if (flipbone)
@ -2798,6 +2795,7 @@ void clear_bone_parent(void)
} }
} }
} }
countall(); // checks selection countall(); // checks selection
allqueue(REDRAWVIEW3D, 0); allqueue(REDRAWVIEW3D, 0);
allqueue(REDRAWBUTSEDIT, 0); allqueue(REDRAWBUTSEDIT, 0);
@ -2812,8 +2810,8 @@ static EditBone *editbone_name_exists (ListBase *ebones, char *name)
if (ebones == NULL) ebones = &G.edbo; if (ebones == NULL) ebones = &G.edbo;
for (eBone=ebones->first; eBone; eBone=eBone->next){ for (eBone=ebones->first; eBone; eBone=eBone->next) {
if (!strcmp (name, eBone->name)) if (!strcmp(name, eBone->name))
return eBone; return eBone;
} }
return NULL; return NULL;
@ -2826,21 +2824,19 @@ void unique_editbone_name (ListBase *ebones, char *name)
int number; int number;
char *dot; char *dot;
if (editbone_name_exists(ebones, name)) { if (editbone_name_exists(ebones, name)) {
/* Strip off the suffix, if it's a number */ /* Strip off the suffix, if it's a number */
number= strlen(name); number= strlen(name);
if(number && isdigit(name[number-1])) { if (number && isdigit(name[number-1])) {
dot= strrchr(name, '.'); // last occurrance dot= strrchr(name, '.'); // last occurrance
if (dot) if (dot)
*dot=0; *dot=0;
} }
for (number = 1; number <=999; number++){ for (number = 1; number <=999; number++) {
sprintf (tempname, "%s.%03d", name, number); sprintf (tempname, "%s.%03d", name, number);
if (!editbone_name_exists(ebones, tempname)){ if (!editbone_name_exists(ebones, tempname)) {
BLI_strncpy (name, tempname, 32); BLI_strncpy(name, tempname, 32);
return; return;
} }
} }
@ -2858,11 +2854,11 @@ void extrude_armature(int forked)
TEST_EDITARMATURE; TEST_EDITARMATURE;
/* since we allow root extrude too, we have to make sure selection is OK */ /* since we allow root extrude too, we have to make sure selection is OK */
for (ebone = G.edbo.first; ebone; ebone=ebone->next){ for (ebone = G.edbo.first; ebone; ebone=ebone->next) {
if(arm->layer & ebone->layer) { if (arm->layer & ebone->layer) {
if(ebone->flag & BONE_ROOTSEL) { if (ebone->flag & BONE_ROOTSEL) {
if(ebone->parent && (ebone->flag & BONE_CONNECTED)) { if (ebone->parent && (ebone->flag & BONE_CONNECTED)) {
if(ebone->parent->flag & BONE_TIPSEL) if (ebone->parent->flag & BONE_TIPSEL)
ebone->flag &= ~BONE_ROOTSEL; ebone->flag &= ~BONE_ROOTSEL;
} }
} }
@ -2870,38 +2866,36 @@ void extrude_armature(int forked)
} }
/* Duplicate the necessary bones */ /* Duplicate the necessary bones */
for (ebone = G.edbo.first; ((ebone) && (ebone!=first)); ebone=ebone->next){ for (ebone = G.edbo.first; ((ebone) && (ebone!=first)); ebone=ebone->next) {
if(arm->layer & ebone->layer) { if (arm->layer & ebone->layer) {
/* we extrude per definition the tip */ /* we extrude per definition the tip */
do_extrude= 0; do_extrude= 0;
if (ebone->flag & (BONE_TIPSEL|BONE_SELECTED)) if (ebone->flag & (BONE_TIPSEL|BONE_SELECTED))
do_extrude= 1; do_extrude= 1;
else if(ebone->flag & BONE_ROOTSEL) { else if (ebone->flag & BONE_ROOTSEL) {
/* but, a bone with parent deselected we do the root... */ /* but, a bone with parent deselected we do the root... */
if(ebone->parent && (ebone->parent->flag & BONE_TIPSEL)); if (ebone->parent && (ebone->parent->flag & BONE_TIPSEL));
else do_extrude= 2; else do_extrude= 2;
} }
if (do_extrude) { if (do_extrude) {
/* we re-use code for mirror editing... */ /* we re-use code for mirror editing... */
flipbone= NULL; flipbone= NULL;
if(arm->flag & ARM_MIRROR_EDIT) { if(arm->flag & ARM_MIRROR_EDIT) {
flipbone= armature_bone_get_mirrored(ebone); flipbone= armature_bone_get_mirrored(ebone);
if (flipbone) { if (flipbone) {
forked= 0; // we extrude 2 different bones forked= 0; // we extrude 2 different bones
if(flipbone->flag & (BONE_TIPSEL|BONE_ROOTSEL|BONE_SELECTED)) if (flipbone->flag & (BONE_TIPSEL|BONE_ROOTSEL|BONE_SELECTED))
/* don't want this bone to be selected... */ /* don't want this bone to be selected... */
flipbone->flag &= ~(BONE_TIPSEL|BONE_SELECTED|BONE_ROOTSEL|BONE_ACTIVE); flipbone->flag &= ~(BONE_TIPSEL|BONE_SELECTED|BONE_ROOTSEL|BONE_ACTIVE);
} }
if(flipbone==NULL && forked) if ((flipbone==NULL) && (forked))
flipbone= ebone; flipbone= ebone;
} }
for(a=0; a<2; a++) { for (a=0; a<2; a++) {
if(a==1) { if (a==1) {
if(flipbone==NULL) if (flipbone==NULL)
break; break;
else { else {
SWAP(EditBone *, flipbone, ebone); SWAP(EditBone *, flipbone, ebone);
@ -2911,7 +2905,7 @@ void extrude_armature(int forked)
totbone++; totbone++;
newbone = MEM_callocN(sizeof(EditBone), "extrudebone"); newbone = MEM_callocN(sizeof(EditBone), "extrudebone");
if(do_extrude==1) { if (do_extrude==1) {
VECCOPY (newbone->head, ebone->tail); VECCOPY (newbone->head, ebone->tail);
VECCOPY (newbone->tail, newbone->head); VECCOPY (newbone->tail, newbone->head);
newbone->parent = ebone; newbone->parent = ebone;
@ -2937,11 +2931,11 @@ void extrude_armature(int forked)
newbone->segments= 1; newbone->segments= 1;
newbone->layer= ebone->layer; newbone->layer= ebone->layer;
if(newbone->parent) newbone->flag |= BONE_CONNECTED; if (newbone->parent) newbone->flag |= BONE_CONNECTED;
BLI_strncpy (newbone->name, ebone->name, 32); BLI_strncpy (newbone->name, ebone->name, 32);
if(flipbone && forked) { // only set if mirror edit if (flipbone && forked) { // only set if mirror edit
if(strlen(newbone->name)<30) { if(strlen(newbone->name)<30) {
if(a==0) strcat(newbone->name, "_L"); if(a==0) strcat(newbone->name, "_L");
else strcat(newbone->name, "_R"); else strcat(newbone->name, "_R");
@ -2955,9 +2949,8 @@ void extrude_armature(int forked)
first = newbone; first = newbone;
/* restore ebone if we were flipping */ /* restore ebone if we were flipping */
if(a==1 && flipbone) if (a==1 && flipbone)
SWAP(EditBone *, flipbone, ebone); SWAP(EditBone *, flipbone, ebone);
} }
} }
@ -2966,7 +2959,7 @@ void extrude_armature(int forked)
} }
} }
/* if only one bone, make this one active */ /* if only one bone, make this one active */
if(totbone==1 && first) first->flag |= BONE_ACTIVE; if (totbone==1 && first) first->flag |= BONE_ACTIVE;
/* Transform the endpoints */ /* Transform the endpoints */
countall(); // flushes selection! countall(); // flushes selection!
@ -2986,32 +2979,33 @@ void subdivide_armature(int numcuts)
EditBone *ebone, *newbone, *tbone, *mbone; EditBone *ebone, *newbone, *tbone, *mbone;
int a, i; int a, i;
if(numcuts < 1) return; if (numcuts < 1) return;
for (mbone = G.edbo.last; mbone; mbone= mbone->prev) { for (mbone = G.edbo.last; mbone; mbone= mbone->prev) {
if(arm->layer & mbone->layer) { if (arm->layer & mbone->layer) {
if(mbone->flag & BONE_SELECTED) { if (mbone->flag & BONE_SELECTED) {
for(i=numcuts+1; i>1; i--) { for (i=numcuts+1; i>1; i--) {
/* compute cut ratio first */ /* compute cut ratio first */
float cutratio= 1/(float)i; float cutratio= 1/(float)i;
float cutratioI= 1-cutratio; float cutratioI= 1-cutratio;
/* take care of mirrored stuff */ /* take care of mirrored stuff */
for(a=0; a<2; a++) { for (a=0; a<2; a++) {
float val1[3]; float val1[3];
float val2[3]; float val2[3];
float val3[3]; float val3[3];
/* try to find mirrored bone on a != 0 */ /* try to find mirrored bone on a != 0 */
if(a) { if (a) {
if(arm->flag & ARM_MIRROR_EDIT) if (arm->flag & ARM_MIRROR_EDIT)
ebone= armature_bone_get_mirrored(mbone); ebone= armature_bone_get_mirrored(mbone);
else ebone= NULL; else
ebone= NULL;
} }
else else
ebone= mbone; ebone= mbone;
if(ebone) { if (ebone) {
newbone= MEM_mallocN(sizeof(EditBone), "ebone subdiv"); newbone= MEM_mallocN(sizeof(EditBone), "ebone subdiv");
*newbone = *ebone; *newbone = *ebone;
BLI_addtail(&G.edbo, newbone); BLI_addtail(&G.edbo, newbone);
@ -3037,8 +3031,8 @@ void subdivide_armature(int numcuts)
unique_editbone_name (&G.edbo, newbone->name); unique_editbone_name (&G.edbo, newbone->name);
/* correct parent bones */ /* correct parent bones */
for (tbone = G.edbo.first; tbone; tbone=tbone->next){ for (tbone = G.edbo.first; tbone; tbone=tbone->next) {
if(tbone->parent==ebone) if (tbone->parent==ebone)
tbone->parent= newbone; tbone->parent= newbone;
} }
newbone->parent= ebone; newbone->parent= ebone;
@ -3049,7 +3043,7 @@ void subdivide_armature(int numcuts)
} }
} }
if(numcuts==1) BIF_undo_push("Subdivide"); if (numcuts==1) BIF_undo_push("Subdivide");
else BIF_undo_push("Subdivide multi"); else BIF_undo_push("Subdivide multi");
} }
@ -3149,7 +3143,7 @@ int do_pose_selectbuffer(Base *base, unsigned int *buffer, short hits)
bArmature *arm= ob->data; bArmature *arm= ob->data;
/* since we do unified select, we don't shift+select a bone if the armature object was not active yet */ /* since we do unified select, we don't shift+select a bone if the armature object was not active yet */
if (!(G.qual & LR_SHIFTKEY) || base!=BASACT){ if (!(G.qual & LR_SHIFTKEY) || (base != BASACT)) {
deselectall_posearmature(ob, 0, 0); deselectall_posearmature(ob, 0, 0);
nearBone->flag |= (BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL|BONE_ACTIVE); nearBone->flag |= (BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL|BONE_ACTIVE);
select_actionchannel_by_name(ob->action, nearBone->name, 1); select_actionchannel_by_name(ob->action, nearBone->name, 1);
@ -3166,7 +3160,7 @@ int do_pose_selectbuffer(Base *base, unsigned int *buffer, short hits)
select_actionchannel_by_name(ob->action, nearBone->name, 0); select_actionchannel_by_name(ob->action, nearBone->name, 0);
} }
} }
else{ else {
bone_looper(ob, arm->bonebase.first, NULL, clear_active_flag); bone_looper(ob, arm->bonebase.first, NULL, clear_active_flag);
nearBone->flag |= (BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL|BONE_ACTIVE); nearBone->flag |= (BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL|BONE_ACTIVE);
@ -3175,8 +3169,8 @@ int do_pose_selectbuffer(Base *base, unsigned int *buffer, short hits)
} }
/* in weightpaint we select the associated vertex group too */ /* in weightpaint we select the associated vertex group too */
if(G.f & G_WEIGHTPAINT) { if (G.f & G_WEIGHTPAINT) {
if(nearBone->flag & BONE_ACTIVE) { if (nearBone->flag & BONE_ACTIVE) {
vertexgroup_select_by_name(OBACT, nearBone->name); vertexgroup_select_by_name(OBACT, nearBone->name);
DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
} }
@ -3191,7 +3185,6 @@ int do_pose_selectbuffer(Base *base, unsigned int *buffer, short hits)
} }
return nearBone!=NULL; return nearBone!=NULL;
} }
/* test==0: deselect all /* test==0: deselect all
@ -3205,34 +3198,36 @@ void deselectall_posearmature (Object *ob, int test, int doundo)
int selectmode= 0; int selectmode= 0;
/* we call this from outliner too, but with OBACT set OK */ /* we call this from outliner too, but with OBACT set OK */
if(!ob || !ob->pose) return; if (ELEM(NULL, ob, ob->pose)) return;
arm= get_armature(ob); arm= get_armature(ob);
/* Determine if we're selecting or deselecting */ /* Determine if we're selecting or deselecting */
if (test==1) { if (test==1) {
for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
if(pchan->bone->layer & arm->layer && !(pchan->bone->flag & BONE_HIDDEN_P)) if ((pchan->bone->layer & arm->layer) && !(pchan->bone->flag & BONE_HIDDEN_P)) {
if(pchan->bone->flag & BONE_SELECTED) if (pchan->bone->flag & BONE_SELECTED)
break; break;
}
}
if (pchan==NULL) if (pchan == NULL)
selectmode= 1; selectmode= 1;
} }
else if(test==2) else if (test == 2)
selectmode= 2; selectmode= 2;
/* Set the flags accordingly */ /* Set the flags accordingly */
for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
if(pchan->bone->layer & arm->layer && !(pchan->bone->flag & BONE_HIDDEN_P)) { if ((pchan->bone->layer & arm->layer) && !(pchan->bone->flag & BONE_HIDDEN_P)) {
if(selectmode==0) pchan->bone->flag &= ~(BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL|BONE_ACTIVE); if (selectmode==0) pchan->bone->flag &= ~(BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL|BONE_ACTIVE);
else if(selectmode==1) pchan->bone->flag |= BONE_SELECTED; else if (selectmode==1) pchan->bone->flag |= BONE_SELECTED;
else pchan->bone->flag &= ~BONE_ACTIVE; else pchan->bone->flag &= ~BONE_ACTIVE;
} }
} }
/* action editor */ /* action editor */
deselect_actionchannels(ob->action, 0); /* deselects for sure */ deselect_actionchannels(ob->action, 0); /* deselects for sure */
if(selectmode==1) if (selectmode == 1)
deselect_actionchannels(ob->action, 1); /* swaps */ deselect_actionchannels(ob->action, 1); /* swaps */
allqueue(REDRAWBUTSEDIT, 0); allqueue(REDRAWBUTSEDIT, 0);
@ -3384,7 +3379,7 @@ static int dgroup_skinnable(Object *ob, Bone *bone, void *datap)
if (data->list != NULL) { if (data->list != NULL) {
hgroup = (bDeformGroup ***) &data->list; hgroup = (bDeformGroup ***) &data->list;
for(a=0; a<segments; a++) { for (a=0; a<segments; a++) {
**hgroup = defgroup; **hgroup = defgroup;
++*hgroup; ++*hgroup;
} }
@ -3418,7 +3413,7 @@ static void envelope_bone_weighting(Object *ob, Mesh *mesh, float (*verts)[3], i
/* for each skinnable bone */ /* for each skinnable bone */
for (j=0; j < numbones; ++j) { for (j=0; j < numbones; ++j) {
if(!selected[j]) if (!selected[j])
continue; continue;
bone = bonelist[j]; bone = bonelist[j];
@ -3514,13 +3509,13 @@ void add_verts_to_dgroups(Object *ob, Object *par, int heat, int mirror)
dgroup = dgrouplist[j]; dgroup = dgrouplist[j];
/* handle bbone */ /* handle bbone */
if(heat) { if (heat) {
if(segments == 0) { if (segments == 0) {
segments = 1; segments = 1;
bbone = NULL; bbone = NULL;
if(par->pose && (pchan=get_pose_channel(par->pose, bone->name))) { if ((par->pose) && (pchan=get_pose_channel(par->pose, bone->name))) {
if(bone->segments > 1) { if (bone->segments > 1) {
segments = bone->segments; segments = bone->segments;
bbone = b_bone_spline_setup(pchan, 1); bbone = b_bone_spline_setup(pchan, 1);
} }
@ -3531,10 +3526,10 @@ void add_verts_to_dgroups(Object *ob, Object *par, int heat, int mirror)
} }
/* compute root and tip */ /* compute root and tip */
if(bbone) { if (bbone) {
VECCOPY(root[j], bbone[segments].mat[3]); VECCOPY(root[j], bbone[segments].mat[3]);
Mat4MulVecfl(bone->arm_mat, root[j]); Mat4MulVecfl(bone->arm_mat, root[j]);
if(segments+1 < bone->segments) { if ((segments+1) < bone->segments) {
VECCOPY(tip[j], bbone[segments+1].mat[3]) VECCOPY(tip[j], bbone[segments+1].mat[3])
Mat4MulVecfl(bone->arm_mat, tip[j]); Mat4MulVecfl(bone->arm_mat, tip[j]);
} }
@ -3550,7 +3545,7 @@ void add_verts_to_dgroups(Object *ob, Object *par, int heat, int mirror)
Mat4MulVecfl(par->obmat, tip[j]); Mat4MulVecfl(par->obmat, tip[j]);
/* set selected */ /* set selected */
if(wpmode) { if (wpmode) {
if ((arm->layer & bone->layer) && (bone->flag & BONE_SELECTED)) if ((arm->layer & bone->layer) && (bone->flag & BONE_SELECTED))
selected[j] = 1; selected[j] = 1;
} }
@ -3558,16 +3553,17 @@ void add_verts_to_dgroups(Object *ob, Object *par, int heat, int mirror)
selected[j] = 1; selected[j] = 1;
/* find flipped group */ /* find flipped group */
if(mirror) { if (mirror) {
char name[32]; char name[32];
BLI_strncpy(name, dgroup->name, 32); BLI_strncpy(name, dgroup->name, 32);
// 0 = don't strip off number extensions // 0 = don't strip off number extensions
bone_flip_name(name, 0); bone_flip_name(name, 0);
for (curdg = ob->defbase.first; curdg; curdg=curdg->next) for (curdg = ob->defbase.first; curdg; curdg=curdg->next) {
if (!strcmp(curdg->name, name)) if (!strcmp(curdg->name, name))
break; break;
}
dgroupflip[j] = curdg; dgroupflip[j] = curdg;
} }
@ -3581,7 +3577,7 @@ void add_verts_to_dgroups(Object *ob, Object *par, int heat, int mirror)
/* if in weight paint mode, use final verts from derivedmesh */ /* if in weight paint mode, use final verts from derivedmesh */
DerivedMesh *dm = mesh_get_derived_final(ob, CD_MASK_BAREMESH); DerivedMesh *dm = mesh_get_derived_final(ob, CD_MASK_BAREMESH);
if(dm->foreachMappedVert) { if (dm->foreachMappedVert) {
dm->foreachMappedVert(dm, add_vgroups__mapFunc, (void*)verts); dm->foreachMappedVert(dm, add_vgroups__mapFunc, (void*)verts);
vertsfilled = 1; vertsfilled = 1;
} }
@ -3604,12 +3600,14 @@ void add_verts_to_dgroups(Object *ob, Object *par, int heat, int mirror)
} }
/* compute the weights based on gathered vertices and bones */ /* compute the weights based on gathered vertices and bones */
if (heat) if (heat) {
heat_bone_weighting(ob, mesh, verts, numbones, dgrouplist, dgroupflip, heat_bone_weighting(ob, mesh, verts, numbones, dgrouplist, dgroupflip,
root, tip, selected); root, tip, selected);
else }
else {
envelope_bone_weighting(ob, mesh, verts, numbones, bonelist, dgrouplist, envelope_bone_weighting(ob, mesh, verts, numbones, bonelist, dgrouplist,
dgroupflip, root, tip, selected, Mat4ToScalef(par->obmat)); dgroupflip, root, tip, selected, Mat4ToScalef(par->obmat));
}
/* free the memory allocated */ /* free the memory allocated */
MEM_freeN(bonelist); MEM_freeN(bonelist);
@ -3642,7 +3640,7 @@ void create_vgroups_from_armature(Object *ob, Object *par)
"Name Groups %x2|" "Name Groups %x2|"
"Create From Envelopes %x3|" "Create From Envelopes %x3|"
"Create From Bone Heat %x4|"); "Create From Bone Heat %x4|");
switch (mode){ switch (mode) {
case 2: case 2:
/* Traverse the bone list, trying to create empty vertex /* Traverse the bone list, trying to create empty vertex
* groups cooresponding to the bone. * groups cooresponding to the bone.
@ -3662,7 +3660,6 @@ void create_vgroups_from_armature(Object *ob, Object *par)
*/ */
add_verts_to_dgroups(ob, par, (mode == 4), 0); add_verts_to_dgroups(ob, par, (mode == 4), 0);
break; break;
} }
} }
@ -3670,7 +3667,7 @@ static int hide_selected_pose_bone(Object *ob, Bone *bone, void *ptr)
{ {
bArmature *arm= ob->data; bArmature *arm= ob->data;
if(arm->layer & bone->layer) { if (arm->layer & bone->layer) {
if (bone->flag & BONE_SELECTED) { if (bone->flag & BONE_SELECTED) {
bone->flag |= BONE_HIDDEN_P; bone->flag |= BONE_HIDDEN_P;
bone->flag &= ~(BONE_SELECTED|BONE_ACTIVE); bone->flag &= ~(BONE_SELECTED|BONE_ACTIVE);
@ -3700,7 +3697,8 @@ static int hide_unselected_pose_bone(Object *ob, Bone *bone, void *ptr)
{ {
bArmature *arm= ob->data; bArmature *arm= ob->data;
if(arm->layer & bone->layer) { if (arm->layer & bone->layer) {
// hrm... typo here?
if (~bone->flag & BONE_SELECTED) { if (~bone->flag & BONE_SELECTED) {
bone->flag |= BONE_HIDDEN_P; bone->flag |= BONE_HIDDEN_P;
bone->flag &= ~BONE_ACTIVE; bone->flag &= ~BONE_ACTIVE;
@ -3714,7 +3712,7 @@ void hide_unselected_pose_bones(void)
{ {
bArmature *arm; bArmature *arm;
arm=get_armature (OBACT); arm=get_armature(OBACT);
if (!arm) if (!arm)
return; return;
@ -3732,7 +3730,7 @@ static int show_pose_bone(Object *ob, Bone *bone, void *ptr)
{ {
bArmature *arm= ob->data; bArmature *arm= ob->data;
if(arm->layer & bone->layer) { if (arm->layer & bone->layer) {
if (bone->flag & BONE_HIDDEN_P) { if (bone->flag & BONE_HIDDEN_P) {
bone->flag &= ~BONE_HIDDEN_P; bone->flag &= ~BONE_HIDDEN_P;
bone->flag |= BONE_SELECTED; bone->flag |= BONE_SELECTED;
@ -3747,7 +3745,7 @@ void show_all_pose_bones(void)
{ {
bArmature *arm; bArmature *arm;
arm=get_armature (OBACT); arm=get_armature(OBACT);
if (!arm) if (!arm)
return; return;
@ -3781,9 +3779,9 @@ void unique_bone_name (bArmature *arm, char *name)
*dot=0; *dot=0;
} }
for (number = 1; number <=999; number++){ for (number = 1; number <=999; number++) {
sprintf (tempname, "%s.%03d", name, number); sprintf (tempname, "%s.%03d", name, number);
if (!get_named_bone(arm, tempname)){ if (!get_named_bone(arm, tempname)) {
BLI_strncpy (name, tempname, 32); BLI_strncpy (name, tempname, 32);
return; return;
} }
@ -3836,12 +3834,12 @@ void armature_bone_rename(bArmature *arm, char *oldnamep, char *newnamep)
BLI_strncpy(oldname, oldnamep, MAXBONENAME); BLI_strncpy(oldname, oldnamep, MAXBONENAME);
/* now check if we're in editmode, we need to find the unique name */ /* now check if we're in editmode, we need to find the unique name */
if(G.obedit && G.obedit->data==arm) { if ((G.obedit) && (G.obedit->data==arm)) {
EditBone *eBone; EditBone *eBone;
eBone= editbone_name_exists(&G.edbo, oldname); eBone= editbone_name_exists(&G.edbo, oldname);
if(eBone) { if (eBone) {
unique_editbone_name (&G.edbo, newname); unique_editbone_name(&G.edbo, newname);
BLI_strncpy(eBone->name, newname, MAXBONENAME); BLI_strncpy(eBone->name, newname, MAXBONENAME);
} }
else return; else return;
@ -3849,7 +3847,7 @@ void armature_bone_rename(bArmature *arm, char *oldnamep, char *newnamep)
else { else {
Bone *bone= get_named_bone (arm, oldname); Bone *bone= get_named_bone (arm, oldname);
if(bone) { if (bone) {
unique_bone_name (arm, newname); unique_bone_name (arm, newname);
BLI_strncpy(bone->name, newname, MAXBONENAME); BLI_strncpy(bone->name, newname, MAXBONENAME);
} }
@ -3857,9 +3855,9 @@ void armature_bone_rename(bArmature *arm, char *oldnamep, char *newnamep)
} }
/* do entire dbase */ /* do entire dbase */
for(ob= G.main->object.first; ob; ob= ob->id.next) { for (ob= G.main->object.first; ob; ob= ob->id.next) {
/* we have the object using the armature */ /* we have the object using the armature */
if(arm==ob->data) { if (arm==ob->data) {
Object *cob; Object *cob;
bAction *act; bAction *act;
bActionChannel *achan; bActionChannel *achan;
@ -3870,15 +3868,15 @@ void armature_bone_rename(bArmature *arm, char *oldnamep, char *newnamep)
if (act && !act->id.lib) { if (act && !act->id.lib) {
/* Find the appropriate channel */ /* Find the appropriate channel */
achan= get_action_channel(act, oldname); achan= get_action_channel(act, oldname);
if(achan) BLI_strncpy(achan->name, newname, MAXBONENAME); if (achan)
BLI_strncpy(achan->name, newname, MAXBONENAME);
} }
/* Rename the pose channel, if it exists */ /* Rename the pose channel, if it exists */
if (ob->pose) { if (ob->pose) {
bPoseChannel *pchan = get_pose_channel(ob->pose, oldname); bPoseChannel *pchan = get_pose_channel(ob->pose, oldname);
if (pchan) { if (pchan)
BLI_strncpy (pchan->name, newname, MAXBONENAME); BLI_strncpy (pchan->name, newname, MAXBONENAME);
}
} }
/* check all nla-strips too */ /* check all nla-strips too */
@ -3888,13 +3886,14 @@ void armature_bone_rename(bArmature *arm, char *oldnamep, char *newnamep)
if (act && !act->id.lib) { if (act && !act->id.lib) {
/* Find the appropriate channel */ /* Find the appropriate channel */
achan= get_action_channel(act, oldname); achan= get_action_channel(act, oldname);
if(achan) BLI_strncpy(achan->name, newname, MAXBONENAME); if (achan)
BLI_strncpy(achan->name, newname, MAXBONENAME);
} }
} }
/* Update any object constraints to use the new bone name */ /* Update any object constraints to use the new bone name */
for(cob= G.main->object.first; cob; cob= cob->id.next) { for (cob= G.main->object.first; cob; cob= cob->id.next) {
if(cob->constraints.first) if (cob->constraints.first)
constraint_bone_name_fix(ob, &cob->constraints, oldname, newname); constraint_bone_name_fix(ob, &cob->constraints, oldname, newname);
if (cob->pose) { if (cob->pose) {
bPoseChannel *pchan; bPoseChannel *pchan;
@ -3907,18 +3906,18 @@ void armature_bone_rename(bArmature *arm, char *oldnamep, char *newnamep)
/* See if an object is parented to this armature */ /* See if an object is parented to this armature */
if (ob->parent && (ob->parent->data == arm)) { if (ob->parent && (ob->parent->data == arm)) {
if(ob->partype==PARBONE) { if (ob->partype==PARBONE) {
/* bone name in object */ /* bone name in object */
if (!strcmp(ob->parsubstr, oldname)) if (!strcmp(ob->parsubstr, oldname))
BLI_strncpy(ob->parsubstr, newname, MAXBONENAME); BLI_strncpy(ob->parsubstr, newname, MAXBONENAME);
} }
} }
if(modifiers_usesArmature(ob, arm)) { if (modifiers_usesArmature(ob, arm)) {
bDeformGroup *dg; bDeformGroup *dg;
/* bone name in defgroup */ /* bone name in defgroup */
for (dg=ob->defbase.first; dg; dg=dg->next) { for (dg=ob->defbase.first; dg; dg=dg->next) {
if(!strcmp(dg->name, oldname)) if (!strcmp(dg->name, oldname))
BLI_strncpy(dg->name, newname, MAXBONENAME); BLI_strncpy(dg->name, newname, MAXBONENAME);
} }
} }
@ -3934,8 +3933,8 @@ void armature_flip_names(void)
char newname[32]; char newname[32];
for (ebone = G.edbo.first; ebone; ebone=ebone->next) { for (ebone = G.edbo.first; ebone; ebone=ebone->next) {
if(arm->layer & ebone->layer) { if (arm->layer & ebone->layer) {
if(ebone->flag & BONE_SELECTED) { if (ebone->flag & BONE_SELECTED) {
BLI_strncpy(newname, ebone->name, sizeof(newname)); BLI_strncpy(newname, ebone->name, sizeof(newname));
bone_flip_name(newname, 1); // 1 = do strip off number extensions bone_flip_name(newname, 1); // 1 = do strip off number extensions
armature_bone_rename(G.obedit->data, ebone->name, newname); armature_bone_rename(G.obedit->data, ebone->name, newname);
@ -3985,9 +3984,12 @@ EditBone *armature_bone_get_mirrored(EditBone *ebo)
BLI_strncpy(name, ebo->name, sizeof(name)); BLI_strncpy(name, ebo->name, sizeof(name));
bone_flip_name(name, 0); // 0 = don't strip off number extensions bone_flip_name(name, 0); // 0 = don't strip off number extensions
for (eboflip=G.edbo.first; eboflip; eboflip=eboflip->next) for (eboflip=G.edbo.first; eboflip; eboflip=eboflip->next) {
if(ebo!=eboflip) if (ebo != eboflip) {
if (!strcmp (name, eboflip->name)) break; if (!strcmp (name, eboflip->name))
break;
}
}
return eboflip; return eboflip;
} }
@ -4000,25 +4002,24 @@ void transform_armature_mirror_update(void)
for (ebo=G.edbo.first; ebo; ebo=ebo->next) { for (ebo=G.edbo.first; ebo; ebo=ebo->next) {
/* no layer check, correct mirror is more important */ /* no layer check, correct mirror is more important */
if(ebo->flag & (BONE_TIPSEL|BONE_ROOTSEL)) { if (ebo->flag & (BONE_TIPSEL|BONE_ROOTSEL)) {
eboflip= armature_bone_get_mirrored(ebo); eboflip= armature_bone_get_mirrored(ebo);
if(eboflip) { if (eboflip) {
/* we assume X-axis flipping for now */ /* we assume X-axis flipping for now */
if(ebo->flag & BONE_TIPSEL) { if (ebo->flag & BONE_TIPSEL) {
eboflip->tail[0]= -ebo->tail[0]; eboflip->tail[0]= -ebo->tail[0];
eboflip->tail[1]= ebo->tail[1]; eboflip->tail[1]= ebo->tail[1];
eboflip->tail[2]= ebo->tail[2]; eboflip->tail[2]= ebo->tail[2];
eboflip->rad_tail= ebo->rad_tail; eboflip->rad_tail= ebo->rad_tail;
} }
if(ebo->flag & BONE_ROOTSEL) { if (ebo->flag & BONE_ROOTSEL) {
eboflip->head[0]= -ebo->head[0]; eboflip->head[0]= -ebo->head[0];
eboflip->head[1]= ebo->head[1]; eboflip->head[1]= ebo->head[1];
eboflip->head[2]= ebo->head[2]; eboflip->head[2]= ebo->head[2];
eboflip->rad_head= ebo->rad_head; eboflip->rad_head= ebo->rad_head;
} }
if(ebo->flag & BONE_SELECTED) { if (ebo->flag & BONE_SELECTED) {
eboflip->dist= ebo->dist; eboflip->dist= ebo->dist;
eboflip->roll= -ebo->roll; eboflip->roll= -ebo->roll;
eboflip->xwidth= ebo->xwidth; eboflip->xwidth= ebo->xwidth;