Camera tracking integration
authorSergey Sharybin <sergey.vfx@gmail.com>
Fri, 17 Jun 2011 14:47:41 +0000 (14:47 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Fri, 17 Jun 2011 14:47:41 +0000 (14:47 +0000)
===========================

Test tool: convert track to location fcurves for object in 3d world.
1 pixel on footage is equal to 1 Blender unit.

Added for testing only, could be removed any time -- real
parenting to markers/bundles are only under design now.

release/scripts/startup/bl_ui/space_clip.py
source/blender/editors/space_clip/clip_intern.h
source/blender/editors/space_clip/space_clip.c
source/blender/editors/space_clip/tracking_ops.c

index 93a163a4fd8feff4c4e6d2da5e376da32bd8f536..8bb65034fa24701fd640a47e79f73f962f4c9131 100644 (file)
@@ -159,6 +159,19 @@ class CLIP_PT_display(bpy.types.Panel):
         row.prop(sc, "path_length")
 
 
+class CLIP_PT_test(bpy.types.Panel):
+    bl_space_type = 'CLIP_EDITOR'
+    bl_region_type = 'TOOLS'
+    bl_label = "Test"
+    bl_options = {'DEFAULT_CLOSED'}
+
+    def draw(self, context):
+        layout = self.layout
+        sc = context.space_data
+
+        layout.operator("clip.track_to_fcurves")
+
+
 class CLIP_PT_debug(bpy.types.Panel):
     bl_space_type = 'CLIP_EDITOR'
     bl_region_type = 'UI'
index 327314fafec042b22b8de981be8a00a21a435dba..f9aa89d7398220189b207076d81349e54433d79f 100644 (file)
@@ -71,6 +71,8 @@ void CLIP_OT_track_markers(struct wmOperatorType *ot);
 void CLIP_OT_reset_tracking_settings(struct wmOperatorType *ot);
 void CLIP_OT_clear_track_path(struct wmOperatorType *ot);
 
+void CLIP_OT_track_to_fcurves(struct wmOperatorType *ot);
+
 /* clip_draw.c */
 void draw_clip_main(struct SpaceClip *sc, struct ARegion *ar, struct Scene *scene);
 void draw_clip_track_widget(const struct bContext *C, void *trackp, void *userp, void *clipp, rcti *rect);
index f520a6e8e57bbf4bdf02fd054eef3c27d48f0055..4f29b506d4cf8e6e3d9f68c1b14df0d6f9b8dd16 100644 (file)
@@ -210,6 +210,8 @@ static void clip_operatortypes(void)
 
        WM_operatortype_append(CLIP_OT_reset_tracking_settings);
        WM_operatortype_append(CLIP_OT_clear_track_path);
+
+       WM_operatortype_append(CLIP_OT_track_to_fcurves);
 }
 
 static void clip_keymap(struct wmKeyConfig *keyconf)
index db5b8e62b83f476662c34898dc167cc7c386f5c9..d1cf11da84523f9846e99235b4ff56cd8c2e6c32 100644 (file)
@@ -32,6 +32,7 @@
 #include "DNA_movieclip_types.h"
 #include "DNA_object_types.h"  /* SELECT */
 #include "DNA_scene_types.h"
+#include "DNA_anim_types.h"
 
 #include "BLI_utildefines.h"
 #include "BLI_math.h"
 #include "BLI_rect.h"
 #include "BLI_blenlib.h"
 
+#include "BKE_main.h"
 #include "BKE_context.h"
 #include "BKE_movieclip.h"
 #include "BKE_tracking.h"
 #include "BKE_global.h"
+#include "BKE_animsys.h"
+#include "BKE_depsgraph.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
 
 #include "ED_screen.h"
 #include "ED_clip.h"
+#include "ED_keyframing.h"
 
 #include "IMB_imbuf_types.h"
 
@@ -889,4 +894,88 @@ void CLIP_OT_clear_track_path(wmOperatorType *ot)
 
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-}
\ No newline at end of file
+}
+
+/********************** track to fcurves opertaotr *********************/
+
+static int track_to_fcurves_poll(bContext *C)
+{
+       Object *ob= CTX_data_active_object(C);
+       SpaceClip *sc= CTX_wm_space_clip(C);
+
+       if(ob && sc) {
+               MovieClip *clip= ED_space_clip(sc);
+               int type;
+               void *sel;
+
+               if(clip) {
+                       BKE_movieclip_last_selection(clip, &type, &sel);
+                       if(type==MCLIP_SEL_TRACK)
+                               return 1;
+               }
+       }
+
+       return 0;
+}
+
+static int track_to_fcurves_exec(bContext *C, wmOperator *op)
+{
+       SpaceClip *sc= CTX_wm_space_clip(C);
+       MovieClip *clip= ED_space_clip(sc);
+       Object *ob= CTX_data_active_object(C);
+       Scene *scene= CTX_data_scene(C);
+       KeyingSet *ks;
+       int kflag, fra= SFRA, type;
+       MovieTrackingTrack *track;
+       bAction *act= verify_adt_action(&ob->id, 1);
+       MovieClipUser user= {0};
+       int width, height;
+       float scale= RNA_float_get(op->ptr, "scale");
+
+       BKE_movieclip_last_selection(clip, &type, (void**)&track);
+
+       ks= ANIM_builtin_keyingset_get_named(NULL, "Location");
+       kflag= ks->flag;
+       kflag |= ANIM_get_keyframing_flags(scene, 1);
+
+       (void)op;
+
+       BKE_movieclip_acquire_size(clip, &user, &width, &height);
+
+       while(fra<EFRA) {
+               MovieTrackingMarker *marker= BKE_tracking_get_marker(track, fra);
+
+               if(marker) {
+                       FCurve *fcu;
+
+                       fcu= verify_fcurve(act, ks->name, "location", 0, 1);
+                       insert_vert_fcurve(fcu, fra, marker->pos[0]*width*scale, kflag);
+
+                       fcu= verify_fcurve(act, ks->name, "location", 1, 1);
+                       insert_vert_fcurve(fcu, fra, marker->pos[1]*height*scale, kflag);
+               }
+
+               fra++;
+       }
+
+       WM_main_add_notifier(NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
+
+       return OPERATOR_FINISHED;
+}
+
+void CLIP_OT_track_to_fcurves(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Convert Track To FCurves";
+       ot->description= "Convert active track to f-curves for active object in the scene";
+       ot->idname= "CLIP_OT_track_to_fcurves";
+
+       /* api callbacks */
+       ot->exec= track_to_fcurves_exec;
+       ot->poll= track_to_fcurves_poll;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       RNA_def_float(ot->srna, "scale", 1.f, -FLT_MAX, FLT_MAX, "Scale", "Scale factor for generated coordinates", -100.f, 100.f);
+}