diff options
Diffstat (limited to 'source/blender/editors/space_view3d/view3d_snap.c')
-rw-r--r-- | source/blender/editors/space_view3d/view3d_snap.c | 83 |
1 files changed, 44 insertions, 39 deletions
diff --git a/source/blender/editors/space_view3d/view3d_snap.c b/source/blender/editors/space_view3d/view3d_snap.c index 5ee87db6b68..e90998da21c 100644 --- a/source/blender/editors/space_view3d/view3d_snap.c +++ b/source/blender/editors/space_view3d/view3d_snap.c @@ -43,6 +43,7 @@ #include "BLI_math.h" #include "BLI_editVert.h" #include "BLI_linklist.h" +#include "BLI_utildefines.h" #include "BKE_armature.h" #include "BKE_context.h" @@ -82,12 +83,12 @@ static TransVert *transvmain=NULL; static int tottrans= 0; /* copied from editobject.c, now uses (almost) proper depgraph */ -static void special_transvert_update(Scene *scene, Object *obedit) +static void special_transvert_update(Object *obedit) { if(obedit) { - DAG_id_flush_update(obedit->data, OB_RECALC_DATA); + DAG_id_tag_update(obedit->data, 0); if(obedit->type==OB_MESH) { Mesh *me= obedit->data; @@ -443,7 +444,7 @@ static void make_trans_verts(Object *obedit, float *min, float *max, int mode) /* *********************** operators ******************** */ -static int snap_sel_to_grid(bContext *C, wmOperator *op) +static int snap_sel_to_grid(bContext *C, wmOperator *UNUSED(op)) { extern float originmat[3][3]; /* XXX object.c */ Main *bmain= CTX_data_main(C); @@ -481,7 +482,7 @@ static int snap_sel_to_grid(bContext *C, wmOperator *op) VECCOPY(tv->loc, vec); } - special_transvert_update(scene, obedit); + special_transvert_update(obedit); MEM_freeN(transvmain); transvmain= NULL; @@ -510,7 +511,12 @@ static int snap_sel_to_grid(bContext *C, wmOperator *op) armature_loc_pose_to_bone(pchan, vec, vecN); /* adjust location */ - VECCOPY(pchan->loc, vecN); + if ((pchan->protectflag & OB_LOCK_LOCX)==0) + pchan->loc[0]= vecN[0]; + if ((pchan->protectflag & OB_LOCK_LOCY)==0) + pchan->loc[0]= vecN[1]; + if ((pchan->protectflag & OB_LOCK_LOCZ)==0) + pchan->loc[0]= vecN[2]; } /* if the bone has a parent and is connected to the parent, * don't do anything - will break chain unless we do auto-ik. @@ -522,7 +528,7 @@ static int snap_sel_to_grid(bContext *C, wmOperator *op) /* auto-keyframing */ // XXX autokeyframe_pose_cb_func(ob, TFM_TRANSLATION, 0); - DAG_id_flush_update(&ob->id, OB_RECALC_DATA); + DAG_id_tag_update(&ob->id, OB_RECALC_DATA); } else { ob->recalc |= OB_RECALC_OB; @@ -536,16 +542,14 @@ static int snap_sel_to_grid(bContext *C, wmOperator *op) invert_m3_m3(imat, originmat); mul_m3_v3(imat, vec); - ob->loc[0]+= vec[0]; - ob->loc[1]+= vec[1]; - ob->loc[2]+= vec[2]; } - else { + if ((ob->protectflag & OB_LOCK_LOCX)==0) ob->loc[0]+= vec[0]; + if ((ob->protectflag & OB_LOCK_LOCY)==0) ob->loc[1]+= vec[1]; + if ((ob->protectflag & OB_LOCK_LOCZ)==0) ob->loc[2]+= vec[2]; - } - + /* auto-keyframing */ // XXX autokeyframe_ob_cb_func(ob, TFM_TRANSLATION); } @@ -569,7 +573,7 @@ void VIEW3D_OT_snap_selected_to_grid(wmOperatorType *ot) /* api callbacks */ ot->exec= snap_sel_to_grid; - ot->poll= ED_operator_view3d_active; + ot->poll= ED_operator_region_view3d_active; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -577,7 +581,7 @@ void VIEW3D_OT_snap_selected_to_grid(wmOperatorType *ot) /* *************************************************** */ -static int snap_sel_to_curs(bContext *C, wmOperator *op) +static int snap_sel_to_curs(bContext *C, wmOperator *UNUSED(op)) { extern float originmat[3][3]; /* XXX object.c */ Main *bmain= CTX_data_main(C); @@ -602,15 +606,12 @@ static int snap_sel_to_curs(bContext *C, wmOperator *op) tv= transvmain; for(a=0; a<tottrans; a++, tv++) { - vec[0]= curs[0]-obedit->obmat[3][0]; - vec[1]= curs[1]-obedit->obmat[3][1]; - vec[2]= curs[2]-obedit->obmat[3][2]; - + sub_v3_v3v3(vec, curs, obedit->obmat[3]); mul_m3_v3(imat, vec); - VECCOPY(tv->loc, vec); + copy_v3_v3(tv->loc, vec); } - special_transvert_update(scene, obedit); + special_transvert_update(obedit); MEM_freeN(transvmain); transvmain= NULL; @@ -636,8 +637,13 @@ static int snap_sel_to_curs(bContext *C, wmOperator *op) /* get location of cursor in bone-space */ armature_loc_pose_to_bone(pchan, cursp, curspn); - /* calculate new position */ - VECCOPY(pchan->loc, curspn); + /* copy new position */ + if ((pchan->protectflag & OB_LOCK_LOCX)==0) + pchan->loc[0]= curspn[0]; + if ((pchan->protectflag & OB_LOCK_LOCY)==0) + pchan->loc[1]= curspn[1]; + if ((pchan->protectflag & OB_LOCK_LOCZ)==0) + pchan->loc[2]= curspn[2]; } /* if the bone has a parent and is connected to the parent, * don't do anything - will break chain unless we do auto-ik. @@ -649,7 +655,7 @@ static int snap_sel_to_curs(bContext *C, wmOperator *op) /* auto-keyframing */ // XXX autokeyframe_pose_cb_func(ob, TFM_TRANSLATION, 0); - DAG_id_flush_update(&ob->id, OB_RECALC_DATA); + DAG_id_tag_update(&ob->id, OB_RECALC_DATA); } else { ob->recalc |= OB_RECALC_OB; @@ -663,15 +669,14 @@ static int snap_sel_to_curs(bContext *C, wmOperator *op) invert_m3_m3(imat, originmat); mul_m3_v3(imat, vec); - ob->loc[0]+= vec[0]; - ob->loc[1]+= vec[1]; - ob->loc[2]+= vec[2]; } - else { + if ((ob->protectflag & OB_LOCK_LOCX)==0) ob->loc[0]+= vec[0]; + if ((ob->protectflag & OB_LOCK_LOCY)==0) ob->loc[1]+= vec[1]; + if ((ob->protectflag & OB_LOCK_LOCZ)==0) ob->loc[2]+= vec[2]; - } + /* auto-keyframing */ // XXX autokeyframe_ob_cb_func(ob, TFM_TRANSLATION); } @@ -703,7 +708,7 @@ void VIEW3D_OT_snap_selected_to_cursor(wmOperatorType *ot) /* *************************************************** */ -static int snap_curs_to_grid(bContext *C, wmOperator *op) +static int snap_curs_to_grid(bContext *C, wmOperator *UNUSED(op)) { Scene *scene= CTX_data_scene(C); RegionView3D *rv3d= CTX_wm_region_data(C); @@ -732,7 +737,7 @@ void VIEW3D_OT_snap_cursor_to_grid(wmOperatorType *ot) /* api callbacks */ ot->exec= snap_curs_to_grid; - ot->poll= ED_operator_view3d_active; + ot->poll= ED_operator_region_view3d_active; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -740,7 +745,7 @@ void VIEW3D_OT_snap_cursor_to_grid(wmOperatorType *ot) /* **************************************************** */ -static int snap_curs_to_sel(bContext *C, wmOperator *op) +static int snap_curs_to_sel(bContext *C, wmOperator *UNUSED(op)) { Object *obedit= CTX_data_edit_object(C); Scene *scene= CTX_data_scene(C); @@ -786,16 +791,16 @@ static int snap_curs_to_sel(bContext *C, wmOperator *op) transvmain= NULL; } else { - Object *ob= CTX_data_active_object(C); + Object *obact= CTX_data_active_object(C); - if(ob && (ob->mode & OB_MODE_POSE)) { - bArmature *arm= ob->data; + if(obact && (obact->mode & OB_MODE_POSE)) { + bArmature *arm= obact->data; bPoseChannel *pchan; - for (pchan = ob->pose->chanbase.first; pchan; pchan=pchan->next) { + for (pchan = obact->pose->chanbase.first; pchan; pchan=pchan->next) { if(arm->layer & pchan->bone->layer) { if(pchan->bone->flag & BONE_SELECTED) { VECCOPY(vec, pchan->pose_head); - mul_m4_v3(ob->obmat, vec); + mul_m4_v3(obact->obmat, vec); add_v3_v3(centroid, vec); DO_MINMAX(vec, min, max); count++; @@ -847,7 +852,7 @@ void VIEW3D_OT_snap_cursor_to_selected(wmOperatorType *ot) /* ********************************************** */ -static int snap_curs_to_active(bContext *C, wmOperator *op) +static int snap_curs_to_active(bContext *C, wmOperator *UNUSED(op)) { Object *obedit= CTX_data_edit_object(C); Object *obact= CTX_data_active_object(C); @@ -898,7 +903,7 @@ void VIEW3D_OT_snap_cursor_to_active(wmOperatorType *ot) /* **************************************************** */ /*New Code - Snap Cursor to Center -*/ -static int snap_curs_to_center(bContext *C, wmOperator *op) +static int snap_curs_to_center(bContext *C, wmOperator *UNUSED(op)) { Scene *scene= CTX_data_scene(C); View3D *v3d= CTX_wm_view3d(C); @@ -924,7 +929,7 @@ void VIEW3D_OT_snap_cursor_to_center(wmOperatorType *ot) /* api callbacks */ ot->exec= snap_curs_to_center; - ot->poll= ED_operator_view3d_active; + ot->poll= ED_operator_view3d_active; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; |