From b222863336a86e772bcf5d7e1007a72f6667d53b Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 23 May 2011 02:53:30 +0000 Subject: fix [#27459] Flymode moves parent for durian we had camera rigs which needed to have the parent transformed rather then the camera, for this reason I made fly mode fly the parent rather then the camera its self. Make this a preference and use this for view camera/view locking too. --- release/scripts/startup/bl_ui/space_userpref.py | 1 + source/blender/editors/space_view3d/view3d_edit.c | 36 +++++++++++++++++++++-- source/blender/editors/space_view3d/view3d_fly.c | 2 +- source/blender/makesdna/DNA_userdef_types.h | 2 +- source/blender/makesrna/intern/rna_userdef.c | 4 +++ 5 files changed, 40 insertions(+), 5 deletions(-) diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py index cad5369f440..d4ebae04c34 100644 --- a/release/scripts/startup/bl_ui/space_userpref.py +++ b/release/scripts/startup/bl_ui/space_userpref.py @@ -199,6 +199,7 @@ class USERPREF_PT_interface(bpy.types.Panel): col.prop(view, "use_zoom_to_mouse") col.prop(view, "use_rotate_around_active") col.prop(view, "use_global_pivot") + col.prop(view, "use_camera_lock_parent") col.separator() diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index f039a3a7571..9b451095c64 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -92,9 +92,39 @@ void ED_view3d_camera_lock_init(View3D *v3d, RegionView3D *rv3d) void ED_view3d_camera_lock_sync(View3D *v3d, RegionView3D *rv3d) { if(v3d->camera && (v3d->flag2 & V3D_LOCK_CAMERA) && (rv3d->persp==RV3D_CAMOB)) { - ED_view3d_to_object(v3d->camera, rv3d->ofs, rv3d->viewquat, rv3d->dist); - DAG_id_tag_update(&v3d->camera->id, OB_RECALC_OB); - WM_main_add_notifier(NC_OBJECT|ND_TRANSFORM, v3d->camera); + Object *root_parent; + + if((U.uiflag & USER_CAM_LOCK_NO_PARENT)==0 && (root_parent= v3d->camera->parent)) { + Object *ob_update; + float view_mat[4][4]; + float diff_mat[4][4]; + float parent_mat[4][4]; + + while(root_parent->parent) { + root_parent= root_parent->parent; + } + + ED_view3d_to_m4(view_mat, rv3d->ofs, rv3d->viewquat, rv3d->dist); + + invert_m4_m4(v3d->camera->imat, v3d->camera->obmat); + mul_m4_m4m4(diff_mat, v3d->camera->imat, view_mat); + + mul_m4_m4m4(parent_mat, root_parent->obmat, diff_mat); + object_apply_mat4(root_parent, parent_mat, TRUE, FALSE); + + ob_update= v3d->camera; + while(ob_update) { + DAG_id_tag_update(&ob_update->id, OB_RECALC_OB); + WM_main_add_notifier(NC_OBJECT|ND_TRANSFORM, ob_update); + ob_update= ob_update->parent; + } + } + else { + ED_view3d_to_object(v3d->camera, rv3d->ofs, rv3d->viewquat, rv3d->dist); + root_parent= v3d->camera; + DAG_id_tag_update(&v3d->camera->id, OB_RECALC_OB); + WM_main_add_notifier(NC_OBJECT|ND_TRANSFORM, v3d->camera); + } } } diff --git a/source/blender/editors/space_view3d/view3d_fly.c b/source/blender/editors/space_view3d/view3d_fly.c index e140ec39bf3..fdee5c6f6d9 100644 --- a/source/blender/editors/space_view3d/view3d_fly.c +++ b/source/blender/editors/space_view3d/view3d_fly.c @@ -307,7 +307,7 @@ static int initFlyInfo (bContext *C, FlyInfo *fly, wmOperator *op, wmEvent *even fly->dist_backup= fly->rv3d->dist; if (fly->rv3d->persp==RV3D_CAMOB) { Object *ob_back; - if((fly->root_parent=fly->v3d->camera->parent)) { + if((U.uiflag & USER_CAM_LOCK_NO_PARENT)==0 && (fly->root_parent=fly->v3d->camera->parent)) { while(fly->root_parent->parent) fly->root_parent= fly->root_parent->parent; ob_back= fly->root_parent; diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h index 1be67a4501b..1057eeae40f 100644 --- a/source/blender/makesdna/DNA_userdef_types.h +++ b/source/blender/makesdna/DNA_userdef_types.h @@ -469,7 +469,7 @@ extern UserDef U; /* from blenkernel blender.c */ #define USER_HIDE_DOT (1 << 16) #define USER_SHOW_ROTVIEWICON (1 << 17) #define USER_SHOW_VIEWPORTNAME (1 << 18) -// old flag for #define USER_KEYINSERTNEED (1 << 19) +#define USER_CAM_LOCK_NO_PARENT (1 << 19) #define USER_ZOOM_TO_MOUSEPOS (1 << 20) #define USER_SHOW_FPS (1 << 21) #define USER_MMB_PASTE (1 << 22) diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index a914d875490..cee6b7e2b1e 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -2040,6 +2040,10 @@ static void rna_def_userdef_view(BlenderRNA *brna) RNA_def_property_boolean_sdna(prop, NULL, "uiflag", USER_ORBIT_ZBUF); RNA_def_property_ui_text(prop, "Auto Depth", "Use the depth under the mouse to improve view pan/rotate/zoom functionality"); + prop= RNA_def_property(srna, "use_camera_lock_parent", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_negative_sdna(prop, NULL, "uiflag", USER_CAM_LOCK_NO_PARENT); + RNA_def_property_ui_text(prop, "Camera Parent Lock", "When the camera is locked to the view and in fly mode, transform the parent rather then the camera"); + /* view zoom */ prop= RNA_def_property(srna, "use_zoom_to_mouse", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "uiflag", USER_ZOOM_TO_MOUSEPOS); -- cgit v1.2.3