diff options
Diffstat (limited to 'source/blender/editors/space_view3d/view3d_edit.c')
-rw-r--r-- | source/blender/editors/space_view3d/view3d_edit.c | 132 |
1 files changed, 113 insertions, 19 deletions
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index ea4d28ce32f..60a0d3bf12b 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -56,6 +56,8 @@ #include "BKE_report.h" #include "BKE_scene.h" #include "BKE_screen.h" +#include "BKE_action.h" +#include "BKE_armature.h" #include "BKE_depsgraph.h" /* for ED_view3d_camera_lock_sync */ @@ -68,6 +70,7 @@ #include "RNA_access.h" #include "RNA_define.h" +#include "ED_armature.h" #include "ED_particle.h" #include "ED_screen.h" #include "ED_transform.h" @@ -121,9 +124,9 @@ int ED_view3d_camera_lock_sync(View3D *v3d, RegionView3D *rv3d) mult_m4_m4m4(parent_mat, diff_mat, root_parent->obmat); - object_tfm_protected_backup(root_parent, &obtfm); - object_apply_mat4(root_parent, parent_mat, TRUE, FALSE); - object_tfm_protected_restore(root_parent, &obtfm, root_parent->protectflag); + BKE_object_tfm_protected_backup(root_parent, &obtfm); + BKE_object_apply_mat4(root_parent, parent_mat, TRUE, FALSE); + BKE_object_tfm_protected_restore(root_parent, &obtfm, root_parent->protectflag); ob_update = v3d->camera; while (ob_update) { @@ -133,9 +136,9 @@ int ED_view3d_camera_lock_sync(View3D *v3d, RegionView3D *rv3d) } } else { - object_tfm_protected_backup(v3d->camera, &obtfm); + BKE_object_tfm_protected_backup(v3d->camera, &obtfm); ED_view3d_to_object(v3d->camera, rv3d->ofs, rv3d->viewquat, rv3d->dist); - object_tfm_protected_restore(v3d->camera, &obtfm, v3d->camera->protectflag); + BKE_object_tfm_protected_restore(v3d->camera, &obtfm, v3d->camera->protectflag); DAG_id_tag_update(&v3d->camera->id, OB_RECALC_OB); WM_main_add_notifier(NC_OBJECT | ND_TRANSFORM, v3d->camera); @@ -983,12 +986,12 @@ void VIEW3D_OT_rotate(wmOperatorType *ot) /* NDOF utility functions * (should these functions live in this file?) */ -float ndof_to_axis_angle(struct wmNDOFMotionData*ndof, float axis[3]) +float ndof_to_axis_angle(struct wmNDOFMotionData *ndof, float axis[3]) { return ndof->dt * normalize_v3_v3(axis, ndof->rvec); } -void ndof_to_quat(struct wmNDOFMotionData*ndof, float q[4]) +void ndof_to_quat(struct wmNDOFMotionData *ndof, float q[4]) { float axis[3]; float angle; @@ -1007,8 +1010,8 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event return OPERATOR_CANCELLED; else { View3D *v3d = CTX_wm_view3d(C); - RegionView3D*rv3d = CTX_wm_region_view3d(C); - wmNDOFMotionData*ndof = (wmNDOFMotionData *) event->customdata; + RegionView3D *rv3d = CTX_wm_region_view3d(C); + wmNDOFMotionData *ndof = (wmNDOFMotionData *) event->customdata; ED_view3d_camera_lock_init(v3d, rv3d); @@ -1159,8 +1162,8 @@ static int ndof_pan_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event) return OPERATOR_CANCELLED; else { View3D *v3d = CTX_wm_view3d(C); - RegionView3D*rv3d = CTX_wm_region_view3d(C); - wmNDOFMotionData*ndof = (wmNDOFMotionData *) event->customdata; + RegionView3D *rv3d = CTX_wm_region_view3d(C); + wmNDOFMotionData *ndof = (wmNDOFMotionData *) event->customdata; ED_view3d_camera_lock_init(v3d, rv3d); @@ -2068,7 +2071,7 @@ static int view3d_all_exec(bContext *C, wmOperator *op) /* was view3d_home() in continue; } - minmax_object(base->object, min, max); + BKE_object_minmax(base->object, min, max); } } if (!onedone) { @@ -2214,8 +2217,8 @@ static int viewselected_exec(bContext *C, wmOperator *UNUSED(op)) } /* account for duplis */ - if (minmax_object_duplis(scene, base->object, min, max) == 0) - minmax_object(base->object, min, max); /* use if duplis not found */ + if (BKE_object_minmax_dupli(scene, base->object, min, max) == 0) + BKE_object_minmax(base->object, min, max); /* use if duplis not found */ ok = 1; } @@ -2236,7 +2239,7 @@ static int viewselected_exec(bContext *C, wmOperator *UNUSED(op)) size = v3d->near * 1.5f; } } - else /* ortho */ { + else { /* ortho */ if (size < 0.0001f) { /* bounding box was a single point so do not zoom */ ok_dist = 0; @@ -2291,6 +2294,89 @@ void VIEW3D_OT_view_selected(wmOperatorType *ot) ot->flag = 0; } +static int view_lock_clear_exec(bContext *C, wmOperator *UNUSED(op)) +{ + View3D *v3d = CTX_wm_view3d(C); + + if (v3d) { + ED_view3D_lock_clear(v3d); + + WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d); + + return OPERATOR_FINISHED; + } + else { + return OPERATOR_CANCELLED; + } +} + +void VIEW3D_OT_view_lock_clear(wmOperatorType *ot) +{ + + /* identifiers */ + ot->name = "View Lock Clear"; + ot->description = "Clear all view locking"; + ot->idname = "VIEW3D_OT_view_lock_clear"; + + /* api callbacks */ + ot->exec = view_lock_clear_exec; + ot->poll = ED_operator_region_view3d_active; + + /* flags */ + ot->flag = 0; +} + +static int view_lock_to_active_exec(bContext *C, wmOperator *UNUSED(op)) +{ + View3D *v3d = CTX_wm_view3d(C); + Object *obact = CTX_data_active_object(C); + + if (v3d) { + + ED_view3D_lock_clear(v3d); + + v3d->ob_centre = obact; /* can be NULL */ + + if (obact && obact->type == OB_ARMATURE) { + if (obact->mode & OB_MODE_POSE) { + bPoseChannel *pcham_act = BKE_pose_channel_active(obact); + if (pcham_act) { + BLI_strncpy(v3d->ob_centre_bone, pcham_act->name, sizeof(v3d->ob_centre_bone)); + } + } + else { + EditBone *ebone_act = ((bArmature *)obact->data)->act_edbone; + if (ebone_act) { + BLI_strncpy(v3d->ob_centre_bone, ebone_act->name, sizeof(v3d->ob_centre_bone)); + } + } + } + + WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d); + + return OPERATOR_FINISHED; + } + else { + return OPERATOR_CANCELLED; + } +} + +void VIEW3D_OT_view_lock_to_active(wmOperatorType *ot) +{ + + /* identifiers */ + ot->name = "View Lock to Active"; + ot->description = "Lock the view to the active object/bone"; + ot->idname = "VIEW3D_OT_view_lock_to_active"; + + /* api callbacks */ + ot->exec = view_lock_to_active_exec; + ot->poll = ED_operator_region_view3d_active; + + /* flags */ + ot->flag = 0; +} + static int viewcenter_cursor_exec(bContext *C, wmOperator *UNUSED(op)) { View3D *v3d = CTX_wm_view3d(C); @@ -2851,7 +2937,7 @@ static int viewnumpad_exec(bContext *C, wmOperator *op) v3d->camera = ob; if (v3d->camera == NULL) - v3d->camera = scene_find_camera(scene); + v3d->camera = BKE_scene_camera_find(scene); /* couldnt find any useful camera, bail out */ if (v3d->camera == NULL) @@ -3094,11 +3180,11 @@ static int background_image_add_invoke(bContext *C, wmOperator *op, wmEvent *UNU char path[FILE_MAX]; RNA_string_get(op->ptr, "filepath", path); - ima = BKE_add_image_file(path); + ima = BKE_image_load_exists(path); } else if (RNA_struct_property_is_set(op->ptr, "name")) { RNA_string_get(op->ptr, "name", name); - ima = (Image *)find_id("IM", name); + ima = (Image *)BKE_libblock_find_name(ID_IM, name); } bgpic = background_image_add(C); @@ -3671,7 +3757,7 @@ void ED_view3d_to_object(Object *ob, const float ofs[3], const float quat[4], co { float mat[4][4]; ED_view3d_to_m4(mat, ofs, quat, dist); - object_apply_mat4(ob, mat, TRUE, TRUE); + BKE_object_apply_mat4(ob, mat, TRUE, TRUE); } BGpic *ED_view3D_background_image_new(View3D *v3d) @@ -3709,3 +3795,11 @@ void ED_view3D_background_image_clear(View3D *v3d) bgpic = next_bgpic; } } + +void ED_view3D_lock_clear(View3D *v3d) +{ + v3d->ob_centre = NULL; + v3d->ob_centre_bone[0] = '\0'; + v3d->ob_centre_cursor = FALSE; + v3d->flag2 &= ~V3D_LOCK_CAMERA; +} |