[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [40915] branches/soc-2011-tomato: Camera tracking integration

Sergey Sharybin g.ulairi at gmail.com
Mon Oct 10 19:42:04 CEST 2011


Revision: 40915
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=40915
Author:   nazgul
Date:     2011-10-10 17:42:04 +0000 (Mon, 10 Oct 2011)
Log Message:
-----------
Camera tracking integration
===========================

- Added space_view3d.background_images.add() function to add new background
  image from scripts.
- Added operator to set current clip in clip editor as background in 3d viewport.
- Do not show reconstruction if camera hasn't got camera solver constraint.
- Added button to convert tracking-related constraint to fcurves.

Modified Paths:
--------------
    branches/soc-2011-tomato/release/scripts/startup/bl_operators/clip.py
    branches/soc-2011-tomato/release/scripts/startup/bl_ui/properties_object_constraint.py
    branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py
    branches/soc-2011-tomato/source/blender/blenkernel/BKE_object.h
    branches/soc-2011-tomato/source/blender/blenkernel/intern/object.c
    branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c
    branches/soc-2011-tomato/source/blender/editors/space_view3d/drawobject.c
    branches/soc-2011-tomato/source/blender/editors/space_view3d/view3d_draw.c
    branches/soc-2011-tomato/source/blender/editors/space_view3d/view3d_select.c
    branches/soc-2011-tomato/source/blender/editors/space_view3d/view3d_snap.c
    branches/soc-2011-tomato/source/blender/makesrna/intern/rna_space.c

Modified: branches/soc-2011-tomato/release/scripts/startup/bl_operators/clip.py
===================================================================
--- branches/soc-2011-tomato/release/scripts/startup/bl_operators/clip.py	2011-10-10 15:29:39 UTC (rev 40914)
+++ branches/soc-2011-tomato/release/scripts/startup/bl_operators/clip.py	2011-10-10 17:42:04 UTC (rev 40915)
@@ -139,3 +139,137 @@
             pass
 
         return {'FINISHED'}
+
+
+class CLIP_OT_set_viewport_background(Operator):
+    bl_idname = "clip.set_viewport_background"
+    bl_label = "Set as Background"
+    bl_options = {'UNDO', 'REGISTER'}
+
+    @classmethod
+    def poll(cls, context):
+        if context.space_data.type != 'CLIP_EDITOR':
+            return False
+
+        sc = context.space_data
+
+        return sc.clip
+
+    def _set_background(self, space_v3d, clip, user):
+        bgpic = None
+
+        for x in space_v3d.background_images:
+            if x.source == 'MOVIE':
+                bgpic = x
+                break
+
+        if not bgpic:
+            bgpic = space_v3d.background_images.add()
+
+        bgpic.source = 'MOVIE'
+        bgpic.clip = clip
+        bgpic.clip_user.proxy_render_size = user.proxy_render_size
+        bgpic.clip_user.use_render_undistorted = user.use_render_undistorted
+        bgpic.use_camera_clip = False
+
+    def execute(self, context):
+        sc = context.space_data
+        clip = sc.clip
+
+        for area in context.window.screen.areas:
+            if area.type == 'VIEW_3D':
+                for space in area.spaces:
+                    if space.type == 'VIEW_3D':
+                        self._set_background(space, clip, sc.clip_user)
+
+        return {'FINISHED'}
+
+
+class CLIP_OT_constraint_to_fcurve(Operator):
+    bl_idname = "clip.constraint_to_fcurve"
+    bl_label = "Constraint to F-Curve"
+    bl_options = {'UNDO', 'REGISTER'}
+
+    def _bake_object(self, scene, ob):
+        con = None
+        clip = None
+        sfra = None
+        efra = None
+        frame_current = scene.frame_current
+        matrices = []
+
+        # Find constraint which would eb converting
+        # TODO: several camera solvers and track followers would fail,
+        #       but can't think about eal workflow where it'll be useful
+        for x in ob.constraints:
+            if x.type in ('CAMERA_SOLVER', 'FOLLOW_TRACK'):
+                con = x
+
+        if not con:
+            return
+
+        if con.type == 'FOLLOW_TRACK' and con.reference == 'BUNDLE':
+            mat = ob.matrix_world.copy()
+            ob.constraints.remove(con)
+            ob.matrix_world = mat
+
+            return
+
+        # Get clip used for parenting
+        if con.use_default_clip:
+            clip = scene.clip
+        else:
+            clip = con.clip
+
+        if not clip:
+            return
+
+        # Find start and end frames
+        for track in clip.tracking.tracks:
+            if sfra is None:
+                sfra = track.markers[0].frame
+            else:
+                sfra = min(sfra, track.markers[0].frame)
+
+            if efra is None:
+                efra = track.markers[-1].frame
+            else:
+                efra = max(efra, track.markers[-1].frame)
+
+        if sfra is None or efra is None:
+           return
+
+        # Store object matrices
+        for x in range(sfra, efra+1):
+            scene.frame_set(x)
+            matrices.append(ob.matrix_world.copy())
+
+        ob.animation_data_create()
+
+        # Apply matrices on object and insert keyframes
+        i = 0
+        for x in range(sfra, efra+1):
+            scene.frame_set(x)
+            ob.matrix_world = matrices[i]
+
+            ob.keyframe_insert("location")
+
+            if ob.rotation_mode == 'QUATERNION':
+                ob.keyframe_insert("rotation_quaternion")
+            else:
+                ob.keyframe_insert("rotation_euler")
+
+            i += 1
+
+        ob.constraints.remove(con)
+
+        scene.frame_set(frame_current)
+
+    def execute(self, context):
+        scene = context.scene
+
+        for ob in scene.objects:
+            if ob.select:
+                self._bake_object(scene, ob)
+
+        return {'FINISHED'}

Modified: branches/soc-2011-tomato/release/scripts/startup/bl_ui/properties_object_constraint.py
===================================================================
--- branches/soc-2011-tomato/release/scripts/startup/bl_ui/properties_object_constraint.py	2011-10-10 15:29:39 UTC (rev 40914)
+++ branches/soc-2011-tomato/release/scripts/startup/bl_ui/properties_object_constraint.py	2011-10-10 17:42:04 UTC (rev 40915)
@@ -764,12 +764,16 @@
         row = layout.row()
         row.prop(con, "reference", expand=True)
 
+        layout.operator("clip.constraint_to_fcurve")
+
     def CAMERA_SOLVER(self, context, layout, con):
         layout.prop(con, "use_default_clip")
 
         if not con.use_default_clip:
             layout.prop(con, "clip")
 
+        layout.operator("clip.constraint_to_fcurve")
+
     def SCRIPT(self, context, layout, con):
         layout.label("Blender 2.5 has no py-constraints")
 

Modified: branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py
===================================================================
--- branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py	2011-10-10 15:29:39 UTC (rev 40914)
+++ branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py	2011-10-10 17:42:04 UTC (rev 40915)
@@ -619,6 +619,18 @@
             layout.operator("clip.open", icon='FILESEL')
 
 
+class CLIP_PT_tools_clip(Panel):
+    bl_space_type = 'CLIP_EDITOR'
+    bl_region_type = 'TOOLS'
+    bl_label = "CLip"
+
+    def draw(self, context):
+        layout = self.layout
+        clip = context.space_data.clip
+
+        layout.operator("clip.set_viewport_background")
+
+
 class CLIP_MT_view(Menu):
     bl_label = "View"
 

Modified: branches/soc-2011-tomato/source/blender/blenkernel/BKE_object.h
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/BKE_object.h	2011-10-10 15:29:39 UTC (rev 40914)
+++ branches/soc-2011-tomato/source/blender/blenkernel/BKE_object.h	2011-10-10 17:42:04 UTC (rev 40915)
@@ -155,7 +155,7 @@
 
 void object_relink(struct Object *ob);
 
-struct MovieClip *object_get_movieclip(struct Scene *scene, struct Object *ob);
+struct MovieClip *object_get_movieclip(struct Scene *scene, struct Object *ob, int use_default);
 
 #ifdef __cplusplus
 }

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/object.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/object.c	2011-10-10 15:29:39 UTC (rev 40914)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/object.c	2011-10-10 17:42:04 UTC (rev 40915)
@@ -3361,9 +3361,9 @@
 	ID_NEW(ob->proxy_group);
 }
 
-MovieClip *object_get_movieclip(Scene *scene, Object *ob)
+MovieClip *object_get_movieclip(Scene *scene, Object *ob, int use_default)
 {
-	MovieClip *clip= scene->clip;
+	MovieClip *clip= use_default ? scene->clip : NULL;
 	bConstraint *con= ob->constraints.first, *scon= NULL;
 
 	while(con){
@@ -3379,6 +3379,8 @@
 		bCameraSolverConstraint *solver= scon->data;
 		if((solver->flag&CAMERASOLVER_DEFAULTCLIP)==0)
 			clip= solver->clip;
+		else
+			clip= scene->clip;
 	}
 
 	return clip;

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c	2011-10-10 15:29:39 UTC (rev 40914)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c	2011-10-10 17:42:04 UTC (rev 40915)
@@ -1413,7 +1413,7 @@
 void BKE_get_tracking_mat(Scene *scene, Object *ob, float mat[4][4])
 {
 	if(!ob) {
-		if(!scene->camera) ob= scene->camera;
+		if(scene->camera) ob= scene->camera;
 		else ob= scene_find_camera(scene);
 	}
 

Modified: branches/soc-2011-tomato/source/blender/editors/space_view3d/drawobject.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/space_view3d/drawobject.c	2011-10-10 15:29:39 UTC (rev 40914)
+++ branches/soc-2011-tomato/source/blender/editors/space_view3d/drawobject.c	2011-10-10 17:42:04 UTC (rev 40915)
@@ -1598,7 +1598,7 @@
 	int i;
 	float drawsize;
 	const short is_view= (rv3d->persp==RV3D_CAMOB && ob==v3d->camera);
-	MovieClip *clip= object_get_movieclip(scene, base->object);
+	MovieClip *clip= object_get_movieclip(scene, base->object, 0);
 
 	/* draw data for movie clip set as active for scene */
 	if(clip)

Modified: branches/soc-2011-tomato/source/blender/editors/space_view3d/view3d_draw.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/space_view3d/view3d_draw.c	2011-10-10 15:29:39 UTC (rev 40914)
+++ branches/soc-2011-tomato/source/blender/editors/space_view3d/view3d_draw.c	2011-10-10 17:42:04 UTC (rev 40915)
@@ -1494,7 +1494,7 @@
 						scene->camera= scene_find_camera(scene);
 
 					if(scene->camera)
-						clip= object_get_movieclip(scene, scene->camera);
+						clip= object_get_movieclip(scene, scene->camera, 1);
 				} else clip= bgpic->clip;
 
 				if(clip==NULL)

Modified: branches/soc-2011-tomato/source/blender/editors/space_view3d/view3d_select.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/space_view3d/view3d_select.c	2011-10-10 15:29:39 UTC (rev 40914)
+++ branches/soc-2011-tomato/source/blender/editors/space_view3d/view3d_select.c	2011-10-10 17:42:04 UTC (rev 40915)
@@ -1406,7 +1406,7 @@
 							/* index of bundle is 1<<16-based. if there's no "bone" index
 							   in hight word, this buffer value belongs to camera,. not to bundle */
 							if(buffer[4*i+3] & 0xFFFF0000) {
-								MovieClip *clip= object_get_movieclip(scene, basact->object);
+								MovieClip *clip= object_get_movieclip(scene, basact->object, 0);
 								int selected;
 								track= BKE_tracking_indexed_bundle(&clip->tracking, hitresult >> 16);
 

Modified: branches/soc-2011-tomato/source/blender/editors/space_view3d/view3d_snap.c
===================================================================

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list