[Bf-blender-cvs] [f36543c] master: Fix viewport camera gets out of sync in certain cases

Sergey Sharybin noreply at git.blender.org
Mon Oct 10 15:07:00 CEST 2016


Commit: f36543c5f552eae909e9afd72bef9773138c192a
Author: Sergey Sharybin
Date:   Mon Oct 10 14:47:03 2016 +0200
Branches: master
https://developer.blender.org/rBf36543c5f552eae909e9afd72bef9773138c192a

Fix viewport camera gets out of sync in certain cases

It was possible to have two viewports opened and start using Ctrl-0
to make different objects an active camera for the viewport. This
worked fine for viewports which had decoupled camera from the scene,
but if viewport was locked to scene camera it was possible to run into
situation when two different viewports are locked to scene camera but
had different v3d->camera pointers.

===================================================================

M	source/blender/editors/space_view3d/view3d_view.c
M	source/blender/makesrna/intern/rna_space.c

===================================================================

diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c
index af86fb7..8582952 100644
--- a/source/blender/editors/space_view3d/view3d_view.c
+++ b/source/blender/editors/space_view3d/view3d_view.c
@@ -592,6 +592,54 @@ void VIEW3D_OT_camera_to_view_selected(wmOperatorType *ot)
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
 
+static void sync_viewport_camera_smoothview(bContext *C, View3D *v3d, Object *ob, const int smooth_viewtx)
+{
+	Main *bmain = CTX_data_main(C);
+	for (bScreen *screen = bmain->screen.first; screen != NULL; screen = screen->id.next) {
+		for (ScrArea *area = screen->areabase.first; area != NULL; area = area->next) {
+			for (SpaceLink *space_link = area->spacedata.first; space_link != NULL; space_link = space_link->next) {
+				if (space_link->spacetype == SPACE_VIEW3D) {
+					View3D *other_v3d = (View3D *)space_link;
+					if (other_v3d == v3d) {
+						continue;
+					}
+					if (other_v3d->camera == ob) {
+						continue;
+					}
+					if (v3d->scenelock) {
+						ListBase *lb = (space_link == area->spacedata.first)
+						                   ? &area->regionbase
+						                   : &space_link->regionbase;
+						for (ARegion *other_ar = lb->first; other_ar != NULL; other_ar = other_ar->next) {
+							if (other_ar->regiontype == RGN_TYPE_WINDOW) {
+								if (other_ar->regiondata) {
+									RegionView3D *other_rv3d = other_ar->regiondata;
+									if (other_rv3d->persp == RV3D_CAMOB) {
+										Object *other_camera_old = other_v3d->camera;
+										other_v3d->camera = ob;
+										ED_view3d_lastview_store(other_rv3d);
+										ED_view3d_smooth_view(
+										        C, other_v3d, other_ar, smooth_viewtx,
+										        &(const V3D_SmoothParams) {
+										            .camera_old = other_camera_old,
+										            .camera = other_v3d->camera,
+										            .ofs = other_rv3d->ofs,
+										            .quat = other_rv3d->viewquat,
+										            .dist = &other_rv3d->dist,
+										            .lens = &other_v3d->lens});
+									}
+									else {
+										other_v3d->camera = ob;
+									}
+								}
+							}
+						}
+					}
+				}
+			}
+		}
+	}
+}
 
 static int view3d_setobjectascamera_exec(bContext *C, wmOperator *op)
 {	
@@ -628,6 +676,7 @@ static int view3d_setobjectascamera_exec(bContext *C, wmOperator *op)
 		}
 
 		if (v3d->scenelock) {
+			sync_viewport_camera_smoothview(C, v3d, ob, smooth_viewtx);
 			WM_event_add_notifier(C, NC_SCENE, scene);
 		}
 		WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, scene);
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index 375d370..b6c3932 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -454,6 +454,15 @@ EnumPropertyItem *rna_TransformOrientation_itemf(bContext *C, PointerRNA *ptr, P
 }
 
 /* Space 3D View */
+static void rna_SpaceView3D_camera_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+{
+	View3D *v3d = (View3D *)(ptr->data);
+	if (v3d->scenelock) {
+		scene->camera = v3d->camera;
+		BKE_screen_view3d_main_sync(&bmain->screen, scene);
+	}
+}
+
 static void rna_SpaceView3D_lock_camera_and_layers_set(PointerRNA *ptr, int value)
 {
 	View3D *v3d = (View3D *)(ptr->data);
@@ -2368,7 +2377,7 @@ static void rna_def_space_view3d(BlenderRNA *brna)
 	RNA_def_property_pointer_sdna(prop, NULL, "camera");
 	RNA_def_property_ui_text(prop, "Camera",
 	                         "Active camera used in this view (when unlocked from the scene's active camera)");
-	RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+	RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_SpaceView3D_camera_update");
 
 	/* render border */
 	prop = RNA_def_property(srna, "use_render_border", PROP_BOOLEAN, PROP_NONE);




More information about the Bf-blender-cvs mailing list