[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [56635] trunk/blender: Added a button to apply scale on scene solution

Sergey Sharybin sergey.vfx at gmail.com
Thu May 9 18:38:55 CEST 2013


Revision: 56635
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=56635
Author:   nazgul
Date:     2013-05-09 16:38:55 +0000 (Thu, 09 May 2013)
Log Message:
-----------
Added a button to apply scale on scene solution

This is an alternative to using camera to scale the
scene and it's expected to be better solution because
scaling camera leads to issues with z-buffer.

Found the whole scaling thing a bit confusing,
especially for object tracking, but cleaning this up
is a bit different topic.

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_ui/space_clip.py
    trunk/blender/source/blender/editors/space_clip/clip_intern.h
    trunk/blender/source/blender/editors/space_clip/space_clip.c
    trunk/blender/source/blender/editors/space_clip/tracking_ops.c

Modified: trunk/blender/release/scripts/startup/bl_ui/space_clip.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/space_clip.py	2013-05-09 16:38:50 UTC (rev 56634)
+++ trunk/blender/release/scripts/startup/bl_ui/space_clip.py	2013-05-09 16:38:55 UTC (rev 56635)
@@ -399,7 +399,9 @@
         layout.separator()
 
         col = layout.column()
-        col.operator("clip.set_scale")
+        row = col.row(align=True);
+        row.operator("clip.set_scale")
+        row.operator("clip.apply_solution_scale", text="Apply Scale")
         col.prop(settings, "distance")
 
 

Modified: trunk/blender/source/blender/editors/space_clip/clip_intern.h
===================================================================
--- trunk/blender/source/blender/editors/space_clip/clip_intern.h	2013-05-09 16:38:50 UTC (rev 56634)
+++ trunk/blender/source/blender/editors/space_clip/clip_intern.h	2013-05-09 16:38:55 UTC (rev 56635)
@@ -165,6 +165,7 @@
 void CLIP_OT_set_axis(struct wmOperatorType *ot);
 void CLIP_OT_set_scale(struct wmOperatorType *ot);
 void CLIP_OT_set_solution_scale(struct wmOperatorType *ot);
+void CLIP_OT_apply_solution_scale(struct wmOperatorType *ot);
 
 void CLIP_OT_set_center_principal(struct wmOperatorType *ot);
 

Modified: trunk/blender/source/blender/editors/space_clip/space_clip.c
===================================================================
--- trunk/blender/source/blender/editors/space_clip/space_clip.c	2013-05-09 16:38:50 UTC (rev 56634)
+++ trunk/blender/source/blender/editors/space_clip/space_clip.c	2013-05-09 16:38:55 UTC (rev 56635)
@@ -488,6 +488,7 @@
 	WM_operatortype_append(CLIP_OT_set_axis);
 	WM_operatortype_append(CLIP_OT_set_scale);
 	WM_operatortype_append(CLIP_OT_set_solution_scale);
+	WM_operatortype_append(CLIP_OT_apply_solution_scale);
 
 	/* detect */
 	WM_operatortype_append(CLIP_OT_detect_features);

Modified: trunk/blender/source/blender/editors/space_clip/tracking_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_clip/tracking_ops.c	2013-05-09 16:38:50 UTC (rev 56634)
+++ trunk/blender/source/blender/editors/space_clip/tracking_ops.c	2013-05-09 16:38:55 UTC (rev 56635)
@@ -2253,7 +2253,7 @@
 
 /********************** set scale operator *********************/
 
-static int do_set_scale(bContext *C, wmOperator *op, int scale_solution)
+static int do_set_scale(bContext *C, wmOperator *op, bool scale_solution, bool apply_scale)
 {
 	SpaceClip *sc = CTX_wm_space_clip(C);
 	MovieClip *clip = ED_space_clip_get_clip(sc);
@@ -2274,7 +2274,7 @@
 		return OPERATOR_CANCELLED;
 	}
 
-	if (!scale_solution) {
+	if (!scale_solution && !apply_scale) {
 		object = get_orientation_object(C);
 		if (!object) {
 			BKE_report(op->reports, RPT_ERROR, "No object to apply orientation on");
@@ -2300,32 +2300,52 @@
 	if (len_v3(vec[0]) > 1e-5f) {
 		scale = dist / len_v3(vec[0]);
 
-		if (tracking_object->flag & TRACKING_OBJECT_CAMERA) {
-			mul_v3_fl(object->size, scale);
-			mul_v3_fl(object->loc, scale);
-		}
-		else if (!scale_solution) {
-			Object *solver_camera = object_solver_camera(scene, object);
+		if (apply_scale) {
+			/* Apply scale on reconstructed scene itself */
+			MovieTrackingReconstruction *reconstruction = BKE_tracking_get_active_reconstruction(tracking);
+			MovieReconstructedCamera *reconstructed_cameras;
+			int i;
 
-			object->size[0] = object->size[1] = object->size[2] = 1.0f / scale;
+			for (track = tracksbase->first; track; track = track->next) {
+				mul_v3_fl(track->bundle_pos, scale);
+			}
 
-			if (solver_camera) {
-				object->size[0] /= solver_camera->size[0];
-				object->size[1] /= solver_camera->size[1];
-				object->size[2] /= solver_camera->size[2];
+			reconstructed_cameras = reconstruction->cameras;
+			for (i = 0; i < reconstruction->camnr; i++) {
+				mul_v3_fl(reconstructed_cameras[i].mat[3], scale);
 			}
+
+			WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip);
+			WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
 		}
 		else {
-			tracking_object->scale = scale;
-		}
+			if (tracking_object->flag & TRACKING_OBJECT_CAMERA) {
+				mul_v3_fl(object->size, scale);
+				mul_v3_fl(object->loc, scale);
+			}
+			else if (!scale_solution) {
+				Object *solver_camera = object_solver_camera(scene, object);
 
-		DAG_id_tag_update(&clip->id, 0);
+				object->size[0] = object->size[1] = object->size[2] = 1.0f / scale;
 
-		if (object)
-			DAG_id_tag_update(&object->id, OB_RECALC_OB);
+				if (solver_camera) {
+					object->size[0] /= solver_camera->size[0];
+					object->size[1] /= solver_camera->size[1];
+					object->size[2] /= solver_camera->size[2];
+				}
+			}
+			else {
+				tracking_object->scale = scale;
+			}
 
-		WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip);
-		WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
+			DAG_id_tag_update(&clip->id, 0);
+
+			if (object)
+				DAG_id_tag_update(&object->id, OB_RECALC_OB);
+
+			WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip);
+			WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
+		}
 	}
 
 	return OPERATOR_FINISHED;
@@ -2333,7 +2353,7 @@
 
 static int set_scale_exec(bContext *C, wmOperator *op)
 {
-	return do_set_scale(C, op, 0);
+	return do_set_scale(C, op, false, false);
 }
 
 static int set_scale_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
@@ -2389,7 +2409,7 @@
 
 static int set_solution_scale_exec(bContext *C, wmOperator *op)
 {
-	return do_set_scale(C, op, 1);
+	return do_set_scale(C, op, true, false);
 }
 
 static int set_solution_scale_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
@@ -2423,6 +2443,62 @@
 	              "Distance", "Distance between selected tracks", -100.0f, 100.0f);
 }
 
+/********************** apply solution scale operator *********************/
+
+static int apply_solution_scale_poll(bContext *C)
+{
+	SpaceClip *sc = CTX_wm_space_clip(C);
+
+	if (sc) {
+		MovieClip *clip = ED_space_clip_get_clip(sc);
+
+		if (clip) {
+			MovieTracking *tracking = &clip->tracking;
+			MovieTrackingObject *tracking_object = BKE_tracking_object_get_active(tracking);
+
+			return tracking_object->flag & TRACKING_OBJECT_CAMERA;
+		}
+	}
+
+	return FALSE;
+}
+
+static int apply_solution_scale_exec(bContext *C, wmOperator *op)
+{
+	return do_set_scale(C, op, false, true);
+}
+
+static int apply_solution_scale_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+{
+	SpaceClip *sc = CTX_wm_space_clip(C);
+	MovieClip *clip = ED_space_clip_get_clip(sc);
+
+	if (!RNA_struct_property_is_set(op->ptr, "distance"))
+		RNA_float_set(op->ptr, "distance", clip->tracking.settings.dist);
+
+	return apply_solution_scale_exec(C, op);
+}
+
+void CLIP_OT_apply_solution_scale(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Apply Solution Scale";
+	ot->description = "Apply scale on solution itself to make distance between selected tracks equals to desired";
+	ot->idname = "CLIP_OT_apply_solution_scale";
+
+	/* api callbacks */
+	ot->exec = apply_solution_scale_exec;
+	ot->invoke = apply_solution_scale_invoke;
+	ot->poll = apply_solution_scale_poll;
+
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+	/* properties */
+	RNA_def_float(ot->srna, "distance", 0.0f, -FLT_MAX, FLT_MAX,
+	              "Distance", "Distance between selected tracks", -100.0f, 100.0f);
+}
+
 /********************** set principal center operator *********************/
 
 static int set_center_principal_exec(bContext *C, wmOperator *UNUSED(op))




More information about the Bf-blender-cvs mailing list