diff options
author | Joshua Leung <aligorith@gmail.com> | 2006-12-28 02:30:59 +0300 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2006-12-28 02:30:59 +0300 |
commit | 819b5d51f61691a28e1fc3a0f7ffd264fa5d0de2 (patch) | |
tree | 716dedaed3e95fc08090d2a80a6184a4a821d059 | |
parent | 434e6d22eb5118daf0b459fcef672f830f0169fa (diff) |
== Armature Centering Tools ==
After all these years, it is now possible to (re)center armatures like you
can do with meshes and curves.
At the moment, you can only access this functionality from the menus
(Spacebar->Transform) as the armature button panels are pretty
crowded.
-rw-r--r-- | source/blender/include/BIF_editarmature.h | 1 | ||||
-rw-r--r-- | source/blender/src/editarmature.c | 61 | ||||
-rw-r--r-- | source/blender/src/editobject.c | 16 |
3 files changed, 78 insertions, 0 deletions
diff --git a/source/blender/include/BIF_editarmature.h b/source/blender/include/BIF_editarmature.h index 62cb7c2e749..9cdde5ffcb3 100644 --- a/source/blender/include/BIF_editarmature.h +++ b/source/blender/include/BIF_editarmature.h @@ -75,6 +75,7 @@ void adduplicate_armature(void); void addvert_armature(void); void add_primitiveArmature(int type); void apply_rot_armature (struct Object *ob, float mat[3][3]); +void docentre_armature (struct Object *ob, int centremode); void clear_armature(struct Object *ob, char mode); diff --git a/source/blender/src/editarmature.c b/source/blender/src/editarmature.c index 2a0a64b7f1f..cc3d19295fa 100644 --- a/source/blender/src/editarmature.c +++ b/source/blender/src/editarmature.c @@ -365,6 +365,67 @@ void apply_rot_armature (Object *ob, float mat[3][3]) } } +/* 0 == do centre, 1 == centre new, 2 == centre cursor */ +void docentre_armature (Object *ob, int centremode) +{ + ListBase list; + EditBone *ebone; + bArmature *arm; + float cent[3] = {0.0f, 0.0f, 0.0f}; + float min[3], max[3]; + float omat[3][3]; + + arm = get_armature(ob); + if (!arm) return; + + /* Put the armature into editmode */ + list.first= list.last = NULL; + make_boneList(&list, &arm->bonebase, NULL); + + /* Find the centrepoint */ + if (centremode == 2) { + VECCOPY(cent, give_cursor()); + Mat4Invert(ob->imat, ob->obmat); + Mat4MulVecfl(ob->imat, cent); + } + else { + INIT_MINMAX(min, max); + + for (ebone= list.first; ebone; ebone=ebone->next) { + DO_MINMAX(ebone->head, min, max); + DO_MINMAX(ebone->tail, min, max); + } + + cent[0]= (min[0]+max[0])/2.0f; + cent[1]= (min[1]+max[1])/2.0f; + cent[2]= (min[2]+max[2])/2.0f; + } + + /* Do the adjustments */ + for (ebone= list.first; ebone; ebone=ebone->next){ + VecSubf(ebone->head, ebone->head, cent); + VecSubf(ebone->tail, ebone->tail, cent); + } + + /* Turn the list into an armature */ + editbones_to_armature(&list, ob); + + /* Free the editbones */ + if (list.first){ + BLI_freelistN(&list); + } + + /* Adjust object location for new centrepoint */ + if(centremode && G.obedit==0) { + Mat3CpyMat4(omat, ob->obmat); + + Mat3MulVecfl(omat, cent); + ob->loc[0]+= cent[0]; + ob->loc[1]+= cent[1]; + ob->loc[2]+= cent[2]; + } +} + int join_armature(void) { Object *ob; diff --git a/source/blender/src/editobject.c b/source/blender/src/editobject.c index e9076bfee5e..27288f404de 100644 --- a/source/blender/src/editobject.c +++ b/source/blender/src/editobject.c @@ -1998,6 +1998,22 @@ void docentre(int centremode) allqueue(REDRAWBUTSEDIT, 0); } + else if(base->object->type==OB_ARMATURE) { + bArmature *arm = base->object->data; + + if(arm->id.us>1) { + error("Can't apply to a multi user armature"); + return; + } + + /* Function to recenter armatures in editarmature.c + * Bone + object locations are handled there. + */ + docentre_armature(base->object, centremode); + + if(G.obedit) + break; + } base->object->recalc= OB_RECALC_OB|OB_RECALC_DATA; } } |