[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [36690] trunk/blender: option to have the view controls apply to the camera view ( and camera object).

Campbell Barton ideasman42 at gmail.com
Sat May 14 19:50:34 CEST 2011


Revision: 36690
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36690
Author:   campbellbarton
Date:     2011-05-14 17:50:33 +0000 (Sat, 14 May 2011)
Log Message:
-----------
option to have the view controls apply to the camera view (and camera object).
- follow rotate/pan/zoom/dolly operators.
- auto-depth preference works.
- smooth view navigation supported.
- view selected, all & numpad operator work too.

TODO
- deal with camera transform locked axis
- find a way to move/zoom the frame while the camera is locked (if it turns out to be a problem).

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_ui/space_view3d.py
    trunk/blender/source/blender/editors/include/ED_view3d.h
    trunk/blender/source/blender/editors/space_view3d/view3d_edit.c
    trunk/blender/source/blender/editors/space_view3d/view3d_view.c
    trunk/blender/source/blender/makesdna/DNA_view3d_types.h
    trunk/blender/source/blender/makesrna/intern/rna_space.c

Modified: trunk/blender/release/scripts/startup/bl_ui/space_view3d.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/space_view3d.py	2011-05-14 15:44:56 UTC (rev 36689)
+++ trunk/blender/release/scripts/startup/bl_ui/space_view3d.py	2011-05-14 17:50:33 UTC (rev 36690)
@@ -2024,6 +2024,9 @@
         elif not view.lock_object:
             col.prop(view, "lock_cursor", text="Lock to Cursor")
 
+        col = layout.column()
+        col.prop(view, "lock_camera")
+
         col = layout.column(align=True)
         col.label(text="Clip:")
         col.prop(view, "clip_start", text="Start")

Modified: trunk/blender/source/blender/editors/include/ED_view3d.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_view3d.h	2011-05-14 15:44:56 UTC (rev 36689)
+++ trunk/blender/source/blender/editors/include/ED_view3d.h	2011-05-14 17:50:33 UTC (rev 36690)
@@ -193,6 +193,9 @@
 void ED_view3d_from_object(struct Object *ob, float ofs[3], float quat[4], float *dist, float *lens);
 void ED_view3d_to_object(struct Object *ob, const float ofs[3], const float quat[4], const float dist);
 
+void ED_view3d_camera_lock_init(struct View3D *v3d, struct RegionView3D *rv3d);
+void ED_view3d_camera_lock_sync(struct View3D *v3d, struct RegionView3D *rv3d);
+
 int view3d_is_ortho(struct View3D *v3d, struct RegionView3D *rv3d);
 
 

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_edit.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_edit.c	2011-05-14 15:44:56 UTC (rev 36689)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_edit.c	2011-05-14 17:50:33 UTC (rev 36690)
@@ -56,6 +56,7 @@
 #include "BKE_paint.h"
 #include "BKE_report.h"
 #include "BKE_scene.h"
+#include "BKE_depsgraph.h" /* for ED_view3d_camera_lock_sync */
 
 
 #include "BIF_gl.h"
@@ -80,6 +81,22 @@
 
 /* ********************** view3d_edit: view manipulations ********************* */
 
+void ED_view3d_camera_lock_init(View3D *v3d, RegionView3D *rv3d)
+{
+	if(v3d->camera && (v3d->flag2 & V3D_LOCK_CAMERA) && (rv3d->persp==RV3D_CAMOB)) {
+		ED_view3d_from_object(v3d->camera, rv3d->ofs, rv3d->viewquat, &rv3d->dist, NULL);
+	}
+}
+
+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);
+	}
+}
+
+
 /* ********************* box view support ***************** */
 
 static void view3d_boxview_clip(ScrArea *sa)
@@ -360,7 +377,7 @@
 		view3d_operator_needs_opengl(C); /* needed for zbuf drawing */
 
 		if((vod->use_dyn_ofs=view_autodist(CTX_data_scene(C), vod->ar, vod->v3d, event->mval, vod->dyn_ofs))) {
-			if (rv3d->persp==RV3D_PERSP) {
+			if (rv3d->persp==RV3D_PERSP || (rv3d->persp==RV3D_CAMOB && (vod->v3d->flag2 & V3D_LOCK_CAMERA))) {
 				float my_origin[3]; /* original G.vd->ofs */
 				float my_pivot[3]; /* view */
 				float dvec[3];
@@ -710,6 +727,8 @@
 	/* avoid precision loss over time */
 	normalize_qt(rv3d->viewquat);
 
+	ED_view3d_camera_lock_sync(vod->v3d, rv3d);
+
 	ED_region_tag_redraw(vod->ar);
 }
 
@@ -777,6 +796,8 @@
 		return OPERATOR_PASS_THROUGH;
 	}
 
+	ED_view3d_camera_lock_init(vod->v3d, vod->rv3d);
+
 	/* switch from camera view when: */
 	if(rv3d->persp != RV3D_PERSP) {
 
@@ -790,7 +811,7 @@
 				ED_view3d_from_object(vod->v3d->camera, rv3d->ofs, rv3d->viewquat, &rv3d->dist, NULL);
 			}
 
-			if(rv3d->persp==RV3D_CAMOB) {
+			if(!(vod->v3d->flag2 & V3D_LOCK_CAMERA)) {
 				rv3d->persp= rv3d->lpersp;
 			}
 		}
@@ -891,7 +912,7 @@
 
 static void viewmove_apply(ViewOpsData *vod, int x, int y)
 {
-	if(vod->rv3d->persp==RV3D_CAMOB) {
+	if((vod->rv3d->persp==RV3D_CAMOB) && !(vod->v3d->flag2 & V3D_LOCK_CAMERA)) {
 		float zoomfac= ((float)M_SQRT2 + (float)vod->rv3d->camzoom / 50.0f);
 		zoomfac= (zoomfac * zoomfac) * 0.5f;
 
@@ -914,6 +935,8 @@
 	vod->oldx= x;
 	vod->oldy= y;
 
+	ED_view3d_camera_lock_sync(vod->v3d, vod->rv3d);
+
 	ED_region_tag_redraw(vod->ar);
 }
 
@@ -963,11 +986,16 @@
 
 static int viewmove_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
+	ViewOpsData *vod;
+
 	/* makes op->customdata */
 	viewops_data_create(C, op, event);
 
+	vod= op->customdata;
+
+	ED_view3d_camera_lock_init(vod->v3d, vod->rv3d);
+
 	if (event->type == MOUSEPAN) {
-		ViewOpsData *vod= op->customdata;
 		viewmove_apply(vod, event->prevx, event->prevy);
 		request_depth_update(vod->rv3d);
 		
@@ -1156,6 +1184,8 @@
 	if(vod->rv3d->viewlock & RV3D_BOXVIEW)
 		view3d_boxview_sync(vod->sa, vod->ar);
 
+	ED_view3d_camera_lock_sync(vod->v3d, vod->rv3d);
+
 	ED_region_tag_redraw(vod->ar);
 }
 
@@ -1234,7 +1264,7 @@
 
 	if(delta < 0) {
 		/* this min and max is also in viewmove() */
-		if(rv3d->persp==RV3D_CAMOB) {
+		if((rv3d->persp==RV3D_CAMOB) && !(v3d->flag2 & V3D_LOCK_CAMERA)) {
 			rv3d->camzoom-= 10;
 			if(rv3d->camzoom < RV3D_CAMZOOM_MIN) rv3d->camzoom= RV3D_CAMZOOM_MIN;
 		}
@@ -1243,7 +1273,7 @@
 		}
 	}
 	else {
-		if(rv3d->persp==RV3D_CAMOB) {
+		if((rv3d->persp==RV3D_CAMOB) && !(v3d->flag2 & V3D_LOCK_CAMERA)) {
 			rv3d->camzoom+= 10;
 			if(rv3d->camzoom > RV3D_CAMZOOM_MAX) rv3d->camzoom= RV3D_CAMZOOM_MAX;
 		}
@@ -1256,6 +1286,9 @@
 		view3d_boxview_sync(sa, ar);
 
 	request_depth_update(rv3d);
+
+	ED_view3d_camera_lock_sync(v3d, rv3d);
+
 	ED_region_tag_redraw(ar);
 
 	viewops_data_free(C, op);
@@ -1272,6 +1305,8 @@
 	viewops_data_create(C, op, event);
 	vod= op->customdata;
 
+	ED_view3d_camera_lock_init(vod->v3d, vod->rv3d);
+
 	/* if one or the other zoom position aren't set, set from event */
 	if (!RNA_property_is_set(op->ptr, "mx") || !RNA_property_is_set(op->ptr, "my"))
 	{
@@ -1373,6 +1408,8 @@
 	if(vod->rv3d->viewlock & RV3D_BOXVIEW)
 		view3d_boxview_sync(vod->sa, vod->ar);
 
+	ED_view3d_camera_lock_sync(vod->v3d, vod->rv3d);
+
 	ED_region_tag_redraw(vod->ar);
 }
 
@@ -1478,6 +1515,8 @@
 
 	vod= op->customdata;
 
+	ED_view3d_camera_lock_init(vod->v3d, vod->rv3d);
+
 	/* if one or the other zoom position aren't set, set from event */
 	if (!RNA_property_is_set(op->ptr, "mx") || !RNA_property_is_set(op->ptr, "my"))
 	{
@@ -1528,10 +1567,17 @@
 {
 	RegionView3D *rv3d= CTX_wm_region_view3d(C);
 
-	if (rv3d && rv3d->persp == RV3D_PERSP) {
-		return 1;
+	if(rv3d) {
+		if (rv3d->persp == RV3D_PERSP) {
+			return 1;
+		}
+		else {
+			View3D *v3d= CTX_wm_view3d(C);
+			if ((rv3d->persp == RV3D_CAMOB) && (v3d->flag2 & V3D_LOCK_CAMERA)) {
+				return 1;
+			}
+		}
 	}
-
 	return 0;
 }
 
@@ -1566,6 +1612,7 @@
 	Scene *scene= CTX_data_scene(C);
 	Base *base;
 	float *curs;
+	const short skip_camera= ((rv3d->persp==RV3D_CAMOB) && (v3d->flag2 & V3D_LOCK_CAMERA));
 
 	int center= RNA_boolean_get(op->ptr, "center");
 
@@ -1586,6 +1633,11 @@
 	for(base= scene->base.first; base; base= base->next) {
 		if(BASE_VISIBLE(v3d, base)) {
 			onedone= 1;
+
+			if(skip_camera && base->object == v3d->camera) {
+				continue;
+			}
+
 			minmax_object(base->object, min, max);
 		}
 	}
@@ -1621,7 +1673,7 @@
 			new_dist*= size;
 		}
 
-		if (rv3d->persp==RV3D_CAMOB) {
+		if ((rv3d->persp==RV3D_CAMOB) && !(v3d->flag2 & V3D_LOCK_CAMERA)) {
 			rv3d->persp= RV3D_PERSP;
 			smooth_view(C, v3d, ar, v3d->camera, NULL, new_ofs, NULL, &new_dist, NULL);
 		}
@@ -1665,6 +1717,7 @@
 	Object *obedit= CTX_data_edit_object(C);
 	float size, min[3], max[3], afm[3];
 	int ok=0, ok_dist=1;
+	const short skip_camera= ((rv3d->persp==RV3D_CAMOB) && (v3d->flag2 & V3D_LOCK_CAMERA));
 
 	/* SMOOTHVIEW */
 	float new_ofs[3];
@@ -1718,17 +1771,20 @@
 		ok= PE_minmax(scene, min, max);
 	}
 	else {
-		Base *base= FIRSTBASE;
-		while(base) {
+		Base *base;
+		for(base= FIRSTBASE; base; base = base->next) {
 			if(TESTBASE(v3d, base))  {
 
+				if(skip_camera && base->object == v3d->camera) {
+					continue;
+				}
+
 				/* account for duplis */
 				if (minmax_object_duplis(scene, base->object, min, max)==0)
 					minmax_object(base->object, min, max); /* use if duplis not found */
 
 				ok= 1;
 			}
-			base= base->next;
 		}
 	}
 
@@ -1764,7 +1820,7 @@
 		new_dist*= size;
 	}
 
-	if (rv3d->persp==RV3D_CAMOB) {
+	if (rv3d->persp==RV3D_CAMOB && !(v3d->flag2 & V3D_LOCK_CAMERA)) {
 		rv3d->persp= RV3D_PERSP;
 		smooth_view(C, v3d, ar, v3d->camera, NULL, new_ofs, NULL, &new_dist, NULL);
 	}
@@ -2355,6 +2411,7 @@
 
 static int vieworbit_exec(bContext *C, wmOperator *op)
 {
+	View3D *v3d= CTX_wm_view3d(C);
 	ARegion *ar= ED_view3d_context_region_unlock(C);
 	RegionView3D *rv3d= ar->regiondata; /* no NULL check is needed, poll checks */
 	float phi, q1[4], new_quat[4];
@@ -2363,8 +2420,7 @@
 	orbitdir = RNA_enum_get(op->ptr, "type");
 
 	if(rv3d->viewlock==0) {
-
-		if(rv3d->persp != RV3D_CAMOB) {
+		if((rv3d->persp != RV3D_CAMOB) || (v3d->flag2 & V3D_LOCK_CAMERA)) {
 			if(orbitdir == V3D_VIEW_STEPLEFT || orbitdir == V3D_VIEW_STEPRIGHT) {
 				float si;
 				/* z-axis */

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_view.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_view.c	2011-05-14 15:44:56 UTC (rev 36689)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_view.c	2011-05-14 17:50:33 UTC (rev 36690)
@@ -161,7 +161,19 @@
 	sms.new_dist= rv3d->dist;
 	sms.new_lens= v3d->lens;
 	sms.to_camera= 0;
-	
+
+	/* note on camera locking, this is a little confusing but works ok.
+	 * we may be changing the view 'as if' there is no active camera, but infact
+	 * there is an active camera which is locked to the view.
+	 *
+	 * In the case where smooth view is moving _to_ a camera we dont want that
+	 * camera to be moved or changed, so only when the camera is not being set should
+	 * we allow camera option locking to initialize the view settings from the camera.
+	 */
+	if(camera == NULL && oldcamera == NULL) {
+		ED_view3d_camera_lock_init(v3d, rv3d);
+	}
+
 	/* store the options we want to end with */
 	if(ofs) copy_v3_v3(sms.new_ofs, ofs);
 	if(quat) copy_qt_qt(sms.new_quat, quat);
@@ -325,6 +337,8 @@
 		
 		rv3d->dist = sms->new_dist * step + sms->orig_dist*step_inv;
 		v3d->lens = sms->new_lens * step + sms->orig_lens*step_inv;
+
+		ED_view3d_camera_lock_sync(v3d, rv3d);
 	}
 	
 	if(rv3d->viewlock & RV3D_BOXVIEW)

Modified: trunk/blender/source/blender/makesdna/DNA_view3d_types.h

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list