Camera tracking integration
authorSergey Sharybin <sergey.vfx@gmail.com>
Wed, 20 Jul 2011 15:02:49 +0000 (15:02 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Wed, 20 Jul 2011 15:02:49 +0000 (15:02 +0000)
===========================

Test feature: configurable marker colors in Clip Editor.

Use presets, so plenty of different color could be defined and
easily re-used.

release/scripts/presets/tracking_track_color/default.py [new file with mode: 0644]
release/scripts/presets/tracking_track_color/far_plane.py [new file with mode: 0644]
release/scripts/presets/tracking_track_color/near_plane.py [new file with mode: 0644]
release/scripts/startup/bl_operators/presets.py
release/scripts/startup/bl_ui/space_clip.py
source/blender/editors/space_clip/clip_draw.c
source/blender/makesdna/DNA_tracking_types.h
source/blender/makesrna/intern/rna_tracking.c

diff --git a/release/scripts/presets/tracking_track_color/default.py b/release/scripts/presets/tracking_track_color/default.py
new file mode 100644 (file)
index 0000000..264846c
--- /dev/null
@@ -0,0 +1,5 @@
+import bpy
+track = bpy.context.edit_movieclip.tracking.active_track
+
+track.color = (0.0, 0.0, 0.0)
+track.use_custom_color = False
diff --git a/release/scripts/presets/tracking_track_color/far_plane.py b/release/scripts/presets/tracking_track_color/far_plane.py
new file mode 100644 (file)
index 0000000..533df6a
--- /dev/null
@@ -0,0 +1,5 @@
+import bpy
+track = bpy.context.edit_movieclip.tracking.active_track
+
+track.color = (0.0, 0.0, 1.0)
+track.use_custom_color = True
diff --git a/release/scripts/presets/tracking_track_color/near_plane.py b/release/scripts/presets/tracking_track_color/near_plane.py
new file mode 100644 (file)
index 0000000..32ba28b
--- /dev/null
@@ -0,0 +1,5 @@
+import bpy
+track = bpy.context.edit_movieclip.tracking.active_track
+
+track.color = (0.0, 1.0, 0.0)
+track.use_custom_color = True
index d6607f58d32f97bf9cd6142e5006cdfedcc41b89..63d47ce71dfb589aef6a3b8b19e5dc4852171f58 100644 (file)
@@ -318,6 +318,24 @@ class AddPresetTrackingCamera(AddPresetBase, bpy.types.Operator):
     preset_subdir = "tracking_camera"
 
 
+class AddPresetTrackingTrackColor(AddPresetBase, bpy.types.Operator):
+    '''Add a Clip Track Color Preset'''
+    bl_idname = "clip.track_color_preset_add"
+    bl_label = "Add Track Color Preset"
+    preset_menu = "CLIP_MT_track_color_presets"
+
+    preset_defines = [
+        "track = bpy.context.edit_movieclip.tracking.active_track"
+    ]
+
+    preset_values = [
+        "track.color",
+        "track.use_custom_color"
+    ]
+
+    preset_subdir = "tracking_track_color"
+
+
 class AddPresetKeyconfig(AddPresetBase, bpy.types.Operator):
     '''Add a Keyconfig Preset'''
     bl_idname = "wm.keyconfig_preset_add"
index 61b3bee341b51fcdf1178fecdcf9e80b4d81d3ca..2d3693cdad58501763e61f6191c5570c151ae3eb 100644 (file)
@@ -214,6 +214,18 @@ class CLIP_PT_track(bpy.types.Panel):
         layout.prop(act_track, "name")
         layout.prop(act_track, "locked")
 
+        row = layout.row(align=True)
+        label = bpy.types.CLIP_MT_track_color_presets.bl_label
+        row.menu('CLIP_MT_track_color_presets', text=label)
+        row.operator("clip.track_color_preset_add", text="", icon="ZOOMIN")
+        op = row.operator("clip.track_color_preset_add", text="", icon="ZOOMOUT")
+        op.remove_active = True
+
+        row = layout.row()
+        row.prop(act_track, "use_custom_color")
+        if act_track.use_custom_color:
+            row.prop(act_track, "color", text="")
+
         layout.template_track(sc, "scopes")
 
         row = layout.row()
@@ -521,5 +533,12 @@ class CLIP_MT_camera_presets(bpy.types.Menu):
     draw = bpy.types.Menu.draw_preset
 
 
+class CLIP_MT_track_color_presets(bpy.types.Menu):
+    bl_label = "Color Presets"
+    preset_subdir = "tracking_track_color"
+    preset_operator = "script.execute_preset"
+    draw = bpy.types.Menu.draw_preset
+
+
 if __name__ == "__main__":  # only for live edit.
     bpy.utils.register_module(__name__)
index f43cb10b44f4b0878d8cd935cb53392012dd6134..2b4d382c901754d77e77a29c72275f4a9cae7a8b 100644 (file)
@@ -320,11 +320,28 @@ static void draw_marker_outline(SpaceClip *sc, MovieTrackingTrack *track, MovieT
        if(!tiny) glLineWidth(1.0f);
 }
 
+static void track_colors(MovieTrackingTrack *track, int act, float col[3], float scol[3])
+{
+       if(track->flag&TRACK_CUSTOMCOLOR) {
+               if(act) UI_GetThemeColor3fv(TH_ACT_MARKER, scol);
+               else copy_v3_v3(scol, track->color);
+
+               mul_v3_v3fl(col, track->color, 0.5f);
+       } else {
+               UI_GetThemeColor3fv(TH_MARKER, col);
+
+               if(act) UI_GetThemeColor3fv(TH_ACT_MARKER, scol);
+               else UI_GetThemeColor3fv(TH_SEL_MARKER, scol);
+       }
+}
+
 static void draw_marker_areas(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker, int act, int sel)
 {
-       int color= act?TH_ACT_MARKER:TH_SEL_MARKER;
        int tiny= sc->flag&SC_SHOW_TINY_MARKER;
        int show_pat= 0;
+       float col[3], scol[3];
+
+       track_colors(track, act, col, scol);
 
        /* marker position */
        if((track->flag&SELECT)==sel && (marker->flag&MARKER_DISABLED)==0) {
@@ -333,8 +350,8 @@ static void draw_marker_areas(SpaceClip *sc, MovieTrackingTrack *track, MovieTra
                        else if(track->flag&SELECT) UI_ThemeColorShade(TH_LOCK_MARKER, 64);
                        else UI_ThemeColor(TH_LOCK_MARKER);
                } else
-               if(track->flag&SELECT) UI_ThemeColor(color);
-               else UI_ThemeColor(TH_MARKER);
+               if(track->flag&SELECT) glColor3fv(scol);
+               else glColor3fv(col);
 
                if(!tiny) glPointSize(2.0f);
                glBegin(GL_POINTS);
@@ -364,8 +381,8 @@ static void draw_marker_areas(SpaceClip *sc, MovieTrackingTrack *track, MovieTra
                        else if(track->pat_flag&SELECT) UI_ThemeColorShade(TH_DIS_MARKER, 128);
                        else UI_ThemeColor(TH_DIS_MARKER);
                } else {
-                       if(track->pat_flag&SELECT) UI_ThemeColor(color);
-                       else UI_ThemeColor(TH_MARKER);
+                       if(track->pat_flag&SELECT) glColor3fv(scol);
+                       else glColor3fv(col);
                }
 
                if(sc->flag&SC_SHOW_MARKER_PATTERN) {
@@ -390,8 +407,8 @@ static void draw_marker_areas(SpaceClip *sc, MovieTrackingTrack *track, MovieTra
                        else if(track->search_flag&SELECT) UI_ThemeColorShade(TH_DIS_MARKER, 128);
                        else UI_ThemeColor(TH_DIS_MARKER);
                } else {
-                       if(track->search_flag&SELECT) UI_ThemeColor(color);
-                       else UI_ThemeColor(TH_MARKER);
+                       if(track->search_flag&SELECT) glColor3fv(scol);
+                       else glColor3fv(col);
                }
 
                if(sc->flag&SC_SHOW_MARKER_SEARCH) {
@@ -412,9 +429,9 @@ static void draw_marker_areas(SpaceClip *sc, MovieTrackingTrack *track, MovieTra
 
 static void draw_marker_slide_zones(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker, int outline, int act, int width, int height)
 {
-       int color= act?TH_ACT_MARKER:TH_SEL_MARKER;
        float x, y, dx, dy, tdx, tdy;
        int tiny= sc->flag&SC_SHOW_TINY_MARKER;
+       float col[3], scol[3];
 
        if((tiny && outline) || (marker->flag&MARKER_DISABLED))
                return;
@@ -422,12 +439,14 @@ static void draw_marker_slide_zones(SpaceClip *sc, MovieTrackingTrack *track, Mo
        if(!TRACK_SELECTED(track) || track->flag&TRACK_LOCKED)
                return;
 
+       track_colors(track, act, col, scol);
+
        if(outline) {
                glLineWidth(3.0f);
                UI_ThemeColor(TH_MARKER_OUTLINE);
        } else {
-               if(track->search_flag&SELECT) UI_ThemeColor(color);
-               else UI_ThemeColor(TH_MARKER);
+               if(track->search_flag&SELECT) glColor3fv(scol);
+               else glColor3fv(col);
        }
 
        glPushMatrix();
@@ -476,8 +495,8 @@ static void draw_marker_slide_zones(SpaceClip *sc, MovieTrackingTrack *track, Mo
                dy= 10.0f/height/sc->zoom;
 
                if(!outline) {
-                       if(track->pat_flag&SELECT) UI_ThemeColor(color);
-                       else UI_ThemeColor(TH_MARKER);
+                       if(track->pat_flag&SELECT) glColor3fv(scol);
+                       else glColor3fv(col);
                }
 
                x= track->pat_max[0];
index 5487831639ea87c7a7717a5451de2b0a65986f97..11fe9ceedcc2781446782fc89deeb823a8a4289e 100644 (file)
@@ -96,8 +96,8 @@ typedef struct MovieTrackingTrack {
        /* ** UI editing ** */
        int flag, pat_flag, search_flag;        /* flags (selection, ...) */
        short transflag;                                        /* transform flags */
-
-       char pad3[6];
+       char pad3[2];
+       float color[3];                                         /* custom color for track */
 } MovieTrackingTrack;
 
 typedef struct MovieTrackingSettings {
@@ -132,6 +132,7 @@ enum {
 #define TRACK_DISABLE_BLUE     (1<<4)
 #define TRACK_HIDDEN           (1<<5)
 #define TRACK_LOCKED           (1<<6)
+#define TRACK_CUSTOMCOLOR      (1<<7)
 
 /* MovieTrackingSettings->speed */
 #define TRACKING_SPEED_FASTEST         0
index cb4c50fbaf07226c6d979981cf18d9a9e25cb4e5..fdd622feaed5912bca571edf6e11947a49253617 100644 (file)
@@ -382,6 +382,19 @@ static void rna_def_trackingTrack(BlenderRNA *brna)
        RNA_def_property_boolean_sdna(prop, NULL, "flag", TRACK_LOCKED);
        RNA_def_property_ui_text(prop, "Locked", "Track is locked and all changes to it are disabled");
        RNA_def_property_update(prop, NC_MOVIECLIP|ND_DISPLAY, NULL);
+
+       /* custom color */
+       prop= RNA_def_property(srna, "use_custom_color", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "flag", TRACK_CUSTOMCOLOR);
+       RNA_def_property_ui_text(prop, "Custom Color", "Use custom color instead of theme-defined");
+       RNA_def_property_update(prop, NC_MOVIECLIP|ND_DISPLAY, NULL);
+
+       /* color */
+       prop= RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR);
+       RNA_def_property_array(prop, 3);
+       RNA_def_property_range(prop, 0.0f, 1.0f);
+       RNA_def_property_ui_text(prop, "Color", "Color of the track in the Clip Editor");
+       RNA_def_property_update(prop, NC_ANIMATION, NULL);      
 }
 
 static void rna_def_tracking(BlenderRNA *brna)