Camera tracking integration
[blender.git] / source / blender / blenkernel / intern / depsgraph.c
index d3c5942b685ff3fe9facf2595132f94d7d68e628..b94891ced4996e4daeba0a90b4d8b0f5530ae951 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id$
- *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
@@ -52,6 +50,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"
@@ -641,7 +640,26 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Scene *scene, O
                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(ELEM(cti->type, CONSTRAINT_TYPE_FOLLOWTRACK, CONSTRAINT_TYPE_CAMERASOLVER)) {
+                       if(cti->type==CONSTRAINT_TYPE_FOLLOWTRACK) {
+                               bFollowTrackConstraint *data= (bFollowTrackConstraint *)con->data;
+
+                               if((data->clip || data->flag&FOLLOWTRACK_ACTIVECLIP) && data->track[0]) {
+                                       if(scene->camera) {
+                                               node2 = dag_get_node(dag, scene->camera);
+                                               dag_add_relation(dag, node2, node, DAG_RL_DATA_OB|DAG_RL_OB_OB, cti->name);
+                                       }
+                               }
+                       }
+
+                       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) {
@@ -2102,18 +2120,25 @@ static void dag_object_time_update_flags(Object *ob)
                        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(ELEM(cti->type, CONSTRAINT_TYPE_FOLLOWTRACK, CONSTRAINT_TYPE_CAMERASOLVER)) {
+                                       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);
                        }
                }
        }
@@ -2471,6 +2496,36 @@ static void dag_id_flush_update(Scene *sce, ID *id)
                                                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(ELEM(cti->type, CONSTRAINT_TYPE_FOLLOWTRACK, CONSTRAINT_TYPE_CAMERASOLVER)) {
+                                               obt->recalc |= OB_RECALC_OB;
+                                               break;
+                                       }
+                               }
+                       }
+
+                       if(sce->nodetree) {
+                               bNode *node;
+
+                               for(node= sce->nodetree->nodes.first; node; node= node->next) {
+                                       if(node->id==id) {
+                                               nodeUpdate(sce->nodetree, node);
+                                       }
+                               }
+                       }
+               }
+
+               /* camera's matrix is used to orient reconstructed stuff,
+                  so it should happen tracking-related constraints recalculation
+                  when camera is changing */
+               if(sce->camera && &sce->camera->id == id && sce->clip) {
+                       dag_id_flush_update(sce, &sce->clip->id);
+               }
+
                /* update editors */
                dag_editors_update(bmain, id);
        }