Revision: 38024
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38024
Author:   nazgul
Date:     2011-07-01 17:12:08 +0000 (Fri, 01 Jul 2011)
Log Message:
-----------
Camera tracking integration
===========================

- Removed unneeded checking of marker==NULL
- Tracks could be named now.
- Implemented "Follow Track" constraint to "parent"
  objects to tracks from movie clip.
- Added operator to create such constraint for active object
  using clip and track from current context.

Modified Paths:
--------------
    
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_tracking.h
    branches/soc-2011-tomato/source/blender/blenkernel/intern/constraint.c
    branches/soc-2011-tomato/source/blender/blenkernel/intern/depsgraph.c
    branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c
    branches/soc-2011-tomato/source/blender/editors/object/object_constraint.c
    branches/soc-2011-tomato/source/blender/editors/space_clip/clip_draw.c
    branches/soc-2011-tomato/source/blender/editors/space_clip/tracking_ops.c
    branches/soc-2011-tomato/source/blender/editors/transform/transform.c
    
branches/soc-2011-tomato/source/blender/editors/transform/transform_generics.c
    branches/soc-2011-tomato/source/blender/makesdna/DNA_constraint_types.h
    branches/soc-2011-tomato/source/blender/makesdna/DNA_tracking_types.h
    branches/soc-2011-tomato/source/blender/makesrna/intern/rna_constraint.c
    branches/soc-2011-tomato/source/blender/makesrna/intern/rna_tracking.c

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-07-01 16:39:13 UTC (rev 38023)
+++ 
branches/soc-2011-tomato/release/scripts/startup/bl_ui/properties_object_constraint.py
      2011-07-01 17:12:08 UTC (rev 38024)
@@ -751,6 +751,10 @@
         col = layout.column()
         col.prop(con, "rotation_range", text="Pivot When")
 
+    def FOLLOW_TRACK(self, context, layout, con):
+        layout.prop(con, "clip")
+        layout.prop(con, "track")
+
     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-07-01 16:39:13 UTC (rev 38023)
+++ branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py        
2011-07-01 17:12:08 UTC (rev 38024)
@@ -20,6 +20,42 @@
 import bpy
 
 
+class CLIP_OT_apply_follow_track(bpy.types.Operator):
+    bl_idname = "clip.apply_follow_track"
+    bl_label = "Apply Follow Track"
+    bl_options = {'UNDO', 'REGISTER'}
+
+    @classmethod
+    def poll(cls, context):
+        if context.space_data.type != 'CLIP_EDITOR':
+            return False
+
+        sc = context.space_data
+        clip = sc.clip
+
+        return clip and clip.tracking.active_track and context.active_object
+
+    def execute(self, context):
+        ob = context.active_object
+        sc = context.space_data
+        clip = sc.clip
+        track = clip.tracking.active_track
+        constraint = None
+
+        for con in ob.constraints:
+            if con.type == 'FOLLOW_TRACK':
+                constraint = con
+                break
+
+        if constraint is None:
+            constraint = ob.constraints.new(type='FOLLOW_TRACK')
+
+        constraint.clip = sc.clip
+        constraint.track = track.name
+
+        return {'FINISHED'}
+
+
 class CLIP_HT_header(bpy.types.Header):
     bl_space_type = 'CLIP_EDITOR'
 
@@ -96,16 +132,17 @@
         sc = context.space_data
         clip = sc.clip
 
-        return clip and clip.tracking.act_track
+        return clip and clip.tracking.active_track
 
     def draw(self, context):
         layout = self.layout
         sc = context.space_data
         clip = context.space_data.clip
+        act_track = clip.tracking.active_track
 
-        layout.template_track(clip.tracking, "act_track", sc.clip_user, clip)
+        layout.prop(act_track, "name")
 
-        act_track = clip.tracking.act_track
+        layout.template_track(clip.tracking, "active_track", sc.clip_user, 
clip)
 
         if act_track:
             row = layout.row()
@@ -190,6 +227,7 @@
         layout = self.layout
         sc = context.space_data
 
+        layout.operator("clip.apply_follow_track")
         layout.operator("clip.track_to_fcurves")
 
 

Modified: branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h   
2011-07-01 16:39:13 UTC (rev 38023)
+++ branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h   
2011-07-01 17:12:08 UTC (rev 38024)
@@ -64,6 +64,9 @@
 void BKE_tracking_sync_user(struct MovieClipUser *user, struct 
MovieTrackingContext *context);
 int BKE_tracking_next(struct MovieTrackingContext *context);
 
+void BKE_track_unique_name(struct MovieTracking *tracking, struct 
MovieTrackingTrack *track);
+struct MovieTrackingTrack *BKE_find_track_by_name(struct MovieTracking 
*tracking, const char *name);
+
 #define TRACK_SELECTED(track) ((track)->flag&SELECT || 
(track)->pat_flag&SELECT || (track)->search_flag&SELECT)
 #define TRACK_AREA_SELECTED(track, area) 
((area)==TRACK_AREA_POINT?(track)->flag&SELECT : 
((area)==TRACK_AREA_PAT?(track)->pat_flag&SELECT:(track)->search_flag&SELECT))
 

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/constraint.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/constraint.c      
2011-07-01 16:39:13 UTC (rev 38023)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/constraint.c      
2011-07-01 17:12:08 UTC (rev 38024)
@@ -57,6 +57,8 @@
 #include "DNA_lattice_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_text_types.h"
+#include "DNA_tracking_types.h"
+#include "DNA_movieclip_types.h"
 
 
 #include "BKE_action.h"
@@ -75,6 +77,8 @@
 #include "BKE_idprop.h"
 #include "BKE_shrinkwrap.h"
 #include "BKE_mesh.h"
+#include "BKE_tracking.h"
+#include "BKE_movieclip.h"
 
 #ifdef WITH_PYTHON
 #include "BPY_extern.h"
@@ -3929,6 +3933,62 @@
        pivotcon_evaluate /* evaluate */
 };
 
+/* ----------- Follow Track ------------- */
+
+static void followtrack_new_data (void *cdata)
+{
+       bFollowTrackConstraint *data= (bFollowTrackConstraint *)cdata;
+
+       data->clip= NULL;
+}
+
+static void followtrack_id_looper (bConstraint *con, ConstraintIDFunc func, 
void *userdata)
+{
+       bFollowTrackConstraint *data= con->data;
+
+       func(con, (ID**)&data->clip, userdata);
+}
+
+static void followtrack_evaluate (bConstraint *con, bConstraintOb *cob, 
ListBase *UNUSED(targets))
+{
+       bFollowTrackConstraint *data= con->data;
+       MovieClipUser user;
+       MovieTrackingTrack *track;
+       MovieTrackingMarker *marker;
+       float tx, ty;
+       int width, height;
+
+       if(!data->clip || !data->track[0])
+               return;
+
+       user.framenr= cob->scene->r.cfra;
+       BKE_movieclip_acquire_size(data->clip, &user, &width, &height);
+
+       track= BKE_find_track_by_name(&data->clip->tracking, data->track);
+       marker= BKE_tracking_get_marker(track, user.framenr);
+
+       tx= marker->pos[0]*width;
+       ty= marker->pos[1]*height;
+
+       translate_m4(cob->matrix, tx, ty, 0);
+}
+
+static bConstraintTypeInfo CTI_FOLLOWTRACK = {
+       CONSTRAINT_TYPE_FOLLOWTRACK, /* type */
+       sizeof(bFollowTrackConstraint), /* size */
+       "Follow Track", /* name */
+       "bFollowTrackConstraint", /* struct name */
+       NULL, /* free data */
+       NULL, /* relink data */
+       followtrack_id_looper, /* id looper */
+       NULL, /* copy data */
+       followtrack_new_data, /* new data */
+       NULL, /* get constraint targets */
+       NULL, /* flush constraint targets */
+       NULL, /* get target matrix */
+       followtrack_evaluate /* evaluate */
+};
+
 /* ************************* Constraints Type-Info *************************** 
*/
 /* All of the constraints api functions use bConstraintTypeInfo structs to 
carry out
  * and operations that involve constraint specific code.
@@ -3966,6 +4026,7 @@
        constraintsTypeInfo[23]= &CTI_TRANSLIKE;                /* Copy 
Transforms Constraint */
        constraintsTypeInfo[24]= &CTI_SAMEVOL;                  /* Maintain 
Volume Constraint */
        constraintsTypeInfo[25]= &CTI_PIVOT;                    /* Pivot 
Constraint */
+       constraintsTypeInfo[26]= &CTI_FOLLOWTRACK;              /* Follow Track 
Constraint */
 }
 
 /* This function should be used for getting the appropriate type-info when only

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/depsgraph.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/depsgraph.c       
2011-07-01 16:39:13 UTC (rev 38023)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/depsgraph.c       
2011-07-01 17:12:08 UTC (rev 38024)
@@ -51,6 +51,7 @@
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
 #include "DNA_windowmanager_types.h"
+#include "DNA_movieclip_types.h"
 
 #include "BKE_animsys.h"
 #include "BKE_action.h"
@@ -639,7 +640,15 @@
                ListBase targets = {NULL, NULL};
                bConstraintTarget *ct;
                
-               if (cti && cti->get_constraint_targets) {
+               if(!cti)
+                       continue;
+
+               /* special case for FollowTrack -- it doesn't use targets to 
define relations */
+               if(cti->type==CONSTRAINT_TYPE_FOLLOWTRACK) {
+                       dag_add_relation(dag,scenenode,node,DAG_RL_SCENE, 
"Scene Relation");
+                       addtoroot = 0;
+               }
+               else if (cti->get_constraint_targets) {
                        cti->get_constraint_targets(con, &targets);
                        
                        for (ct= targets.first; ct; ct= ct->next) {
@@ -2073,18 +2082,25 @@
                        ListBase targets = {NULL, NULL};
                        bConstraintTarget *ct;
                        
-                       if (cti && cti->get_constraint_targets) {
-                               cti->get_constraint_targets(con, &targets);
-                               
-                               for (ct= targets.first; ct; ct= ct->next) {
-                                       if (ct->tar) {
-                                               ob->recalc |= OB_RECALC_OB;
-                                               break;
+                       if (cti) {
+                               /* special case for FollowTrack -- it doesn't 
use targets to define relations */
+                               if(cti->type==CONSTRAINT_TYPE_FOLLOWTRACK) {
+                                       ob->recalc |= OB_RECALC_OB;
+                               }
+                               else if (cti->get_constraint_targets) {
+                                       cti->get_constraint_targets(con, 
&targets);
+                                       
+                                       for (ct= targets.first; ct; ct= 
ct->next) {
+                                               if (ct->tar) {
+                                                       ob->recalc |= 
OB_RECALC_OB;
+                                                       break;
+                                               }
                                        }
+                                       
+                                       if (cti->flush_constraint_targets)
+                                               
cti->flush_constraint_targets(con, &targets, 1);
                                }
                                
-                               if (cti->flush_constraint_targets)
-                                       cti->flush_constraint_targets(con, 
&targets, 1);
                        }
                }
        }
@@ -2442,6 +2458,19 @@
                                                BKE_ptcache_object_reset(sce, 
obt, PTCACHE_RESET_DEPSGRAPH);
                }
 
+               if(idtype == ID_MC) {
+                       for(obt=bmain->object.first; obt; obt= obt->id.next){
+                               bConstraint *con;
+                               for (con = obt->constraints.first; con; 
con=con->next) {
+                                       bConstraintTypeInfo *cti= 
constraint_get_typeinfo(con);
+                                       if(cti->type == 
CONSTRAINT_TYPE_FOLLOWTRACK) {
+                                               obt->recalc |= OB_RECALC_OB;
+                                               break;
+                                       }
+                               }
+                       }
+               }
+
                /* update editors */
                dag_editors_update(bmain, id);
        }

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c        
2011-07-01 16:39:13 UTC (rev 38023)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c        
2011-07-01 17:12:08 UTC (rev 38024)
@@ -30,6 +30,8 @@
  *  \ingroup bke
  */
 
+#include <stddef.h>
+
 #include "MEM_guardedalloc.h"
 
 #include "DNA_movieclip_types.h"
@@ -663,3 +665,22 @@
 
        return ok;
 }
+
+void BKE_track_unique_name(MovieTracking *tracking, MovieTrackingTrack *track)
+{
+       BLI_uniquename(&tracking->tracks, track, "Track", '.', 
offsetof(MovieTrackingTrack, name), sizeof(track->name));
+}
+

@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to