diff options
author | Ton Roosendaal <ton@blender.org> | 2009-01-05 22:32:04 +0300 |
---|---|---|
committer | Ton Roosendaal <ton@blender.org> | 2009-01-05 22:32:04 +0300 |
commit | 833cc9c0c8e78d94f669cf238be0cc6582ce1219 (patch) | |
tree | 2ab4a4507a27c9f2eac8f0bc12fa761502bdbfa4 /source | |
parent | 3aae2de7734e13c8e98e7dc85483d1ba8c461f50 (diff) |
2.5
- Armature editmode back
- Armature pose and editmode selecting with mouse back
- Posemode only works with 3d window header now.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/armature/editarmature.c | 90 | ||||
-rw-r--r-- | source/blender/editors/armature/poseobject.c | 75 | ||||
-rw-r--r-- | source/blender/editors/include/ED_armature.h | 7 | ||||
-rw-r--r-- | source/blender/editors/object/object_edit.c | 21 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/drawarmature.c | 2 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_header.c | 21 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_select.c | 5 | ||||
-rw-r--r-- | source/blender/editors/util/ed_util.c | 13 |
8 files changed, 134 insertions, 100 deletions
diff --git a/source/blender/editors/armature/editarmature.c b/source/blender/editors/armature/editarmature.c index 964f0031be9..42d3629e3dd 100644 --- a/source/blender/editors/armature/editarmature.c +++ b/source/blender/editors/armature/editarmature.c @@ -74,6 +74,9 @@ #include "BIF_gl.h" +#include "WM_api.h" +#include "WM_types.h" + #include "ED_armature.h" #include "ED_mesh.h" #include "ED_object.h" @@ -109,6 +112,25 @@ static void select_actionchannel_by_name() {} /* **************** tools on Editmode Armature **************** */ +/* Sync selection to parent for connected children */ +static void armature_sync_selection(ListBase *edbo) +{ + EditBone *ebo; + + for (ebo=edbo->first; ebo; ebo= ebo->next) { + if ((ebo->flag & BONE_CONNECTED) && ebo->parent){ + if (ebo->parent->flag & BONE_TIPSEL) + ebo->flag |= BONE_ROOTSEL; + else + ebo->flag &= ~BONE_ROOTSEL; + } + if ((ebo->flag & BONE_TIPSEL) && (ebo->flag & BONE_ROOTSEL)) + ebo->flag |= BONE_SELECTED; + else + ebo->flag &= ~BONE_SELECTED; + } +} + /* converts Bones to EditBone list, used for tools as well */ void make_boneList(ListBase *edbo, ListBase *bones, EditBone *parent) { @@ -1437,9 +1459,8 @@ void selectconnected_armature(Scene *scene, View3D *v3d, Object *obedit) /* does bones and points */ /* note that BONE ROOT only gets drawn for root bones (or without IK) */ -static EditBone * get_nearest_editbonepoint (Scene *scene, Object *obedit, ListBase *edbo, int findunsel, int *selmask) +static EditBone *get_nearest_editbonepoint (ViewContext *vc, short mval[2], ListBase *edbo, int findunsel, int *selmask) { - ViewContext vc; EditBone *ebone; rcti rect; unsigned int buffer[MAXPICKBUF]; @@ -1447,20 +1468,21 @@ static EditBone * get_nearest_editbonepoint (Scene *scene, Object *obedit, ListB int i, mindep= 4; short hits; - memset(&vc, 0, sizeof(ViewContext)); - vc.scene= scene; - vc.obedit= scene->obedit; - glInitNames(); -// getmouseco_areawin(mval); - // fill in rect! +- 5 + rect.xmin= mval[0]-5; + rect.xmax= mval[0]+5; + rect.ymin= mval[1]-5; + rect.ymax= mval[1]+5; - hits= view3d_opengl_select(&vc, buffer, MAXPICKBUF, &rect); - if(hits==0) - // rect +- 12 - hits= view3d_opengl_select(&vc, buffer, MAXPICKBUF, &rect); - + hits= view3d_opengl_select(vc, buffer, MAXPICKBUF, &rect); + if(hits==0) { + rect.xmin= mval[0]-12; + rect.xmax= mval[0]+12; + rect.ymin= mval[1]-12; + rect.ymax= mval[1]+12; + hits= view3d_opengl_select(vc, buffer, MAXPICKBUF, &rect); + } /* See if there are any selected bones in this group */ if (hits>0) { @@ -1697,29 +1719,35 @@ void deselectall_armature(Object *obedit, int toggle, int doundo) } -/* context: editmode armature */ -void mouse_armature(Scene *scene, Object *obedit) +/* context: editmode armature in view3d */ +void mouse_armature(bContext *C, short mval[2], int extend) { + Object *obedit= CTX_data_edit_object(C); bArmature *arm= obedit->data; + ViewContext vc; EditBone *nearBone = NULL, *ebone; int selmask; - int shift= 0; // XXX - nearBone= get_nearest_editbonepoint(scene, obedit, arm->edbo, 1, &selmask); + memset(&vc, 0, sizeof(ViewContext)); + vc.ar= CTX_wm_region(C); + vc.scene= CTX_data_scene(C); + vc.v3d= (View3D *)CTX_wm_space_data(C); + vc.obact= CTX_data_active_object(C); + vc.obedit= obedit; + + nearBone= get_nearest_editbonepoint(&vc, mval, arm->edbo, 1, &selmask); if (nearBone) { - - if (!(shift)) { + + if (!extend) deselectall_armature(obedit, 0, 0); - } /* by definition the non-root connected bones have no root point drawn, - so a root selection needs to be delivered to the parent tip, - countall() (bad location) flushes these flags */ + so a root selection needs to be delivered to the parent tip */ if(selmask & BONE_SELECTED) { if(nearBone->parent && (nearBone->flag & BONE_CONNECTED)) { /* click in a chain */ - if(shift) { + if(extend) { /* hold shift inverts this bone's selection */ if(nearBone->flag & BONE_SELECTED) { /* deselect this bone */ @@ -1741,7 +1769,7 @@ void mouse_armature(Scene *scene, Object *obedit) } } else { - if(shift) { + if(extend) { /* hold shift inverts this bone's selection */ if(nearBone->flag & BONE_SELECTED) nearBone->flag &= ~(BONE_TIPSEL|BONE_ROOTSEL); @@ -1752,13 +1780,13 @@ void mouse_armature(Scene *scene, Object *obedit) } } else { - if ((shift) && (nearBone->flag & selmask)) + if (extend && (nearBone->flag & selmask)) nearBone->flag &= ~selmask; else nearBone->flag |= selmask; } - - countall(); // flushes selection! + + armature_sync_selection(arm->edbo); if(nearBone) { /* then now check for active status */ @@ -1766,9 +1794,8 @@ void mouse_armature(Scene *scene, Object *obedit) if(nearBone->flag & BONE_SELECTED) nearBone->flag |= BONE_ACTIVE; } + WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, vc.obedit); } - -// rightmouse_transform(); } void ED_armature_edit_free(struct Object *ob) @@ -3541,11 +3568,10 @@ static int bone_looper(Object *ob, Bone *bone, void *data, /* called from editview.c, for mode-less pose selection */ /* assumes scene obact and basact... XXX */ -int do_pose_selectbuffer(Scene *scene, Base *base, unsigned int *buffer, short hits) +int ED_do_pose_selectbuffer(Scene *scene, Base *base, unsigned int *buffer, short hits, short extend) { Object *ob= base->object; Bone *nearBone; - int shift= 0; // XXX if (!ob || !ob->pose) return 0; @@ -3555,7 +3581,7 @@ int do_pose_selectbuffer(Scene *scene, Base *base, unsigned int *buffer, short h bArmature *arm= ob->data; /* since we do unified select, we don't shift+select a bone if the armature object was not active yet */ - if (!(shift) || (base != scene->basact)) { + if (!(extend) || (base != scene->basact)) { ED_pose_deselectall(ob, 0, 0); nearBone->flag |= (BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL|BONE_ACTIVE); select_actionchannel_by_name(ob->action, nearBone->name, 1); diff --git a/source/blender/editors/armature/poseobject.c b/source/blender/editors/armature/poseobject.c index 825be74c06e..06b1dc2361d 100644 --- a/source/blender/editors/armature/poseobject.c +++ b/source/blender/editors/armature/poseobject.c @@ -89,41 +89,6 @@ static void autokeyframe_pose_cb_func() {} /* ************* XXX *************** */ -void enter_posemode(Scene *scene) -{ - Object *obedit= scene->obedit; // XXX context - Base *base; - Object *ob; - - if(scene->id.lib) return; - base= BASACT; - if(base==NULL) return; - - ob= base->object; - - if (ob->id.lib){ - error ("Can't pose libdata"); - return; - } - - switch (ob->type){ - case OB_ARMATURE: - - ob->flag |= OB_POSEMODE; - base->flag= ob->flag; - - break; - default: - return; - } - - if (obedit) { - ED_armature_from_edit(scene, obedit); - ED_armature_edit_free(obedit); - } - G.f &= ~(G_VERTEXPAINT | G_TEXTUREPAINT | G_WEIGHTPAINT | G_SCULPTMODE); -} - void set_pose_keys (Object *ob) { bArmature *arm= ob->data; @@ -142,19 +107,37 @@ void set_pose_keys (Object *ob) } } - -void exit_posemode(Scene *scene) +void ED_armature_enter_posemode(Base *base) { - Object *ob= OBACT; - Base *base= BASACT; - - if(ob==NULL) return; + Object *ob= base->object; - ob->flag &= ~OB_POSEMODE; - base->flag= ob->flag; + if (ob->id.lib){ + error ("Can't pose libdata"); + return; + } - countall(); + switch (ob->type){ + case OB_ARMATURE: + + ob->flag |= OB_POSEMODE; + base->flag= ob->flag; + + break; + default: + return; + } + // XXX + G.f &= ~(G_VERTEXPAINT | G_TEXTUREPAINT | G_WEIGHTPAINT | G_SCULPTMODE); +} +void ED_armature_exit_posemode(Base *base) +{ + if(base) { + Object *ob= base->object; + + ob->flag &= ~OB_POSEMODE; + base->flag= ob->flag; + } } /* if a selected or active bone is protected, throw error (oonly if warn==1) and return 1 */ @@ -184,7 +167,7 @@ static short pose_has_protected_selected(Object *ob, short only_selected, short } /* only for real IK, not for auto-IK */ -int pose_channel_in_IK_chain(Object *ob, bPoseChannel *pchan) +int ED_pose_channel_in_IK_chain(Object *ob, bPoseChannel *pchan) { bConstraint *con; Bone *bone; @@ -200,7 +183,7 @@ int pose_channel_in_IK_chain(Object *ob, bPoseChannel *pchan) } for(bone= pchan->bone->childbase.first; bone; bone= bone->next) { pchan= get_pose_channel(ob->pose, bone->name); - if(pchan && pose_channel_in_IK_chain(ob, pchan)) + if(pchan && ED_pose_channel_in_IK_chain(ob, pchan)) return 1; } return 0; diff --git a/source/blender/editors/include/ED_armature.h b/source/blender/editors/include/ED_armature.h index c77cacc6697..457e0741399 100644 --- a/source/blender/editors/include/ED_armature.h +++ b/source/blender/editors/include/ED_armature.h @@ -27,6 +27,7 @@ #ifndef ED_ARMATURE_H #define ED_ARMATURE_H +struct bContext; struct Scene; struct Object; struct Base; @@ -87,8 +88,14 @@ void ED_armature_from_edit(struct Scene *scene, struct Object *obedit); void ED_armature_to_edit(struct Object *ob); void ED_armature_edit_free(struct Object *ob); void ED_armature_edit_remake(struct Object *obedit); +int ED_do_pose_selectbuffer(struct Scene *scene, struct Base *base, unsigned int *buffer, + short hits, short extend); +void mouse_armature(struct bContext *C, short mval[2], int extend); + /* poseobject.c */ +void ED_armature_exit_posemode(struct Base *base); +void ED_armature_enter_posemode(struct Base *base); int ED_pose_channel_in_IK_chain(struct Object *ob, struct bPoseChannel *pchan); void ED_pose_deselectall(struct Object *ob, int test, int doundo); diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index d7bafc257ff..c92b3754e2a 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -112,6 +112,7 @@ #include "BKE_modifier.h" #include "ED_anim_api.h" +#include "ED_armature.h" #include "ED_mesh.h" #include "ED_object.h" #include "ED_screen.h" @@ -2255,9 +2256,10 @@ void ED_object_exit_editmode(bContext *C, int flag) if(G.f & G_WEIGHTPAINT) mesh_octree_table(obedit, NULL, NULL, 'e'); } - else if (obedit->type==OB_ARMATURE){ -// load_editArmature(); -// if (freedata) free_editArmature(); + else if (obedit->type==OB_ARMATURE) { + ED_armature_from_edit(scene, obedit); + if(freedata) + ED_armature_edit_free(obedit); } else if(ELEM(obedit->type, OB_CURVE, OB_SURF)) { // extern ListBase editNurb; @@ -2304,11 +2306,16 @@ void ED_object_enter_editmode(bContext *C, int flag) Scene *scene= CTX_data_scene(C); Base *base= CTX_data_active_base(C); Object *ob= base->object; - View3D *v3d= (View3D *)CTX_wm_space_data(C); + ScrArea *sa= CTX_wm_area(C); + View3D *v3d= NULL; int ok= 0; if(scene->id.lib) return; if(base==NULL) return; + + if(sa->spacetype==SPACE_VIEW3D) + v3d= sa->spacedata.first; + if((v3d==NULL || (base->lay & v3d->lay))==0) return; if(ob->data==NULL) return; @@ -2331,7 +2338,7 @@ void ED_object_enter_editmode(bContext *C, int flag) WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_EDITMODE_MESH, ob); } - if (ob->type==OB_ARMATURE){ + else if (ob->type==OB_ARMATURE){ bArmature *arm= base->object->data; if (!arm) return; /* @@ -2346,9 +2353,9 @@ void ED_object_enter_editmode(bContext *C, int flag) error_libdata(); return; } -// ok=1; + ok=1; scene->obedit= ob; -// XXX make_editArmature(); + ED_armature_to_edit(ob); /* to ensure all goes in restposition and without striding */ DAG_object_flush_update(scene, ob, OB_RECALC); diff --git a/source/blender/editors/space_view3d/drawarmature.c b/source/blender/editors/space_view3d/drawarmature.c index 5cd7461e7ad..6f341c6a6fe 100644 --- a/source/blender/editors/space_view3d/drawarmature.c +++ b/source/blender/editors/space_view3d/drawarmature.c @@ -1414,7 +1414,7 @@ static void draw_pose_dofs(Object *ob) if (bone->flag & BONE_SELECTED) { if (bone->layer & arm->layer) { if (pchan->ikflag & (BONE_IK_XLIMIT|BONE_IK_ZLIMIT)) { - if (pose_channel_in_IK_chain(ob, pchan)) { + if (ED_pose_channel_in_IK_chain(ob, pchan)) { float corner[4][3], posetrans[3], mat[4][4]; float phi=0.0f, theta=0.0f, scale; int a, i; diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c index c2aea73b2f3..ff07df36764 100644 --- a/source/blender/editors/space_view3d/view3d_header.c +++ b/source/blender/editors/space_view3d/view3d_header.c @@ -62,10 +62,11 @@ #include "BKE_screen.h" #include "BKE_utildefines.h" /* for VECCOPY */ -#include "ED_screen.h" +#include "ED_armature.h" #include "ED_object.h" #include "ED_mesh.h" #include "ED_util.h" +#include "ED_screen.h" #include "ED_types.h" #include "WM_api.h" @@ -5306,7 +5307,8 @@ static void do_view3d_buttons(bContext *C, void *arg, int event) Scene *scene= CTX_data_scene(C); ScrArea *sa= CTX_wm_area(C); View3D *v3d= sa->spacedata.first; - Object *ob= OBACT; + Base *basact= scene->basact; + Object *ob= basact->object; Object *obedit = CTX_data_edit_object(C); EditMesh *em= NULL; int bit, ctrl=0, shift=0; // XXX shift arg? @@ -5367,8 +5369,9 @@ static void do_view3d_buttons(bContext *C, void *arg, int event) v3d->flag &= ~V3D_MODE; // XXX exit_paint_modes(); -// XXX if(ob) exit_posemode(); /* exit posemode for active object */ - if(obedit) ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR); /* exit editmode and undo */ + ED_armature_exit_posemode(basact); + if(obedit) + ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR); /* exit editmode and undo */ } else if (v3d->modeselect == V3D_EDITMODE_SEL) { if(!obedit) { @@ -5409,7 +5412,8 @@ static void do_view3d_buttons(bContext *C, void *arg, int event) if (!(G.f & G_WEIGHTPAINT) && (ob && ob->type == OB_MESH) ) { v3d->flag &= ~V3D_MODE; // XXX exit_paint_modes(); - if(obedit) ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR); /* exit editmode and undo */ + if(obedit) + ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR); /* exit editmode and undo */ // XXX set_wpaint(); } @@ -5418,9 +5422,10 @@ static void do_view3d_buttons(bContext *C, void *arg, int event) if (ob) { v3d->flag &= ~V3D_MODE; - if(obedit) ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR); /* exit editmode and undo */ - -// XXX enter_posemode(); + if(obedit) + ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR); /* exit editmode and undo */ + + ED_armature_enter_posemode(basact); } } else if(v3d->modeselect == V3D_PARTICLEEDITMODE_SEL){ diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index 88e716a0ea6..e1cc1f65c15 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -1060,7 +1060,7 @@ static void mouse_select(bContext *C, short *mval, short extend, short obcenter) } if(has_bones && basact) { - if(0) {// XXX do_pose_selectbuffer(basact, buffer, hits) ) { /* then bone is found */ + if(ED_do_pose_selectbuffer(scene, basact, buffer, hits, extend) ) { /* then bone is found */ /* we make the armature selected: not-selected active object in posemode won't work well for tools */ @@ -1539,6 +1539,9 @@ static int view3d_select_invoke(bContext *C, wmOperator *op, wmEvent *event) if(obedit) { if(obedit->type==OB_MESH) mouse_mesh(C, mval, extend); + else if(obedit->type==OB_ARMATURE) + mouse_armature(C, mval, extend); + } else mouse_select(C, mval, extend, 0); diff --git a/source/blender/editors/util/ed_util.c b/source/blender/editors/util/ed_util.c index 6de980beff4..ed311e0ff0c 100644 --- a/source/blender/editors/util/ed_util.c +++ b/source/blender/editors/util/ed_util.c @@ -43,6 +43,7 @@ #include "BKE_context.h" #include "BKE_global.h" +#include "ED_armature.h" #include "ED_mesh.h" #include "ED_util.h" @@ -52,12 +53,12 @@ void ED_editors_exit(bContext *C) { + Object *ob= CTX_data_edit_object(C); + /* frees all editmode undos */ undo_editmode_clear(); - if(CTX_data_edit_object(C)) { - Object *ob= CTX_data_edit_object(C); - + if(ob) { if(ob->type==OB_MESH) { Mesh *me= ob->data; if(me->edit_mesh) { @@ -66,7 +67,10 @@ void ED_editors_exit(bContext *C) me->edit_mesh= NULL; } } - if(ob->type==OB_FONT) { + else if(ob->type==OB_ARMATURE) { + ED_armature_edit_free(ob); + } + else if(ob->type==OB_FONT) { // free_editText(); } // else if(ob->type==OB_MBALL) @@ -74,7 +78,6 @@ void ED_editors_exit(bContext *C) } // free_editLatt(); - // free_editArmature(); // free_posebuf(); } |