Camera tracking integration
authorSergey Sharybin <sergey.vfx@gmail.com>
Wed, 13 Jul 2011 10:30:42 +0000 (10:30 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Wed, 13 Jul 2011 10:30:42 +0000 (10:30 +0000)
===========================

Previous solution to make bundles work for parented camera
wasn't very nice. It could totally confuse depsgraph and it's
quite slow.

Now i've implemented function where_is_object_mat which makes
almost the same as where_is_object_time, but it:
- Does not applies constraints.
- Assumes matrices for all dependencies are valie already
  (handles by depsgraph).
- Doesn't make any changes to object itself or it's
  dependencies.

source/blender/blenkernel/BKE_object.h
source/blender/blenkernel/intern/constraint.c
source/blender/blenkernel/intern/object.c
source/blender/blenkernel/intern/tracking.c
source/blender/makesdna/DNA_constraint_types.h

index a6b5c04b5c3038a3e2051cb11d0adc8ae3fb6172..25ca743327df1acbfe77d50a858c7e4928d552bd 100644 (file)
@@ -112,6 +112,7 @@ void set_no_parent_ipo(int val);
 void where_is_object_time(struct Scene *scene, struct Object *ob, float ctime);
 void where_is_object(struct Scene *scene, struct Object *ob);
 void where_is_object_simul(struct Scene *scene, struct Object *ob);
+void where_is_object_mat(struct Scene *scene, struct Object *ob, float obmat[4][4]);
 
 struct BoundBox *unit_boundbox(void);
 void boundbox_set_from_min_max(struct BoundBox *bb, float min[3], float max[3]);
index 93f48c77a12e4c1ed95584cac8d0a6089a00119b..621241ecdb2ec326eea877b889a0b6d34673279f 100644 (file)
@@ -4039,9 +4039,6 @@ static void camerasolver_evaluate (bConstraint *con, bConstraintOb *cob, ListBas
        MovieClip *clip= data->clip;
        MovieReconstructedCamera *camera;
 
-       if(data->flag&CAMERASOLVER_TMPDISABLE)
-               return;
-
        if(data->flag&CAMERASOLVER_DEFAULTCLIP)
                clip= scene->clip;
 
index dff62b05bd35fc0a6763f17448dea71772456f19..664794d3ae6ec569666f9e660a9a0a8d78711dc5 100644 (file)
@@ -2142,6 +2142,39 @@ void where_is_object_time(Scene *scene, Object *ob, float ctime)
        else                                                    ob->transflag &= ~OB_NEG_SCALE;
 }
 
+/* get object transformation matrix without recalculating dependencies and
+   constraints -- assume dependencies are already solved by depsgraph.
+   no changes to object and it's parent would be done.
+   used for bundles orientation in 3d space relative to parented blender camera */
+void where_is_object_mat(Scene *scene, Object *ob, float obmat[4][4])
+{
+       float *fp1, *fp2, slowmat[4][4] = MAT4_UNITY;
+       float fac1, fac2;
+       int a;
+
+       if(ob->parent) {
+               Object *par= ob->parent;
+
+               solve_parenting(scene, ob, par, obmat, slowmat, 1);
+
+               if(ob->partype & PARSLOW) {
+                       // include framerate
+                       fac1= ( 1.0f / (1.0f + (float)fabs(give_timeoffset(ob))) );
+                       if(fac1 >= 1.0f) return;
+                       fac2= 1.0f-fac1;
+
+                       fp1= obmat[0];
+                       fp2= slowmat[0];
+                       for(a=0; a<16; a++, fp1++, fp2++) {
+                               fp1[0]= fac1*fp1[0] + fac2*fp2[0];
+                       }
+               }
+       }
+       else {
+               object_to_mat4(ob, obmat);
+       }
+}
+
 static void solve_parenting (Scene *scene, Object *ob, Object *par, float obmat[][4], float slowmat[][4], int simul)
 {
        float totmat[4][4];
index 2284921dc9b174230d49a574d929bff41eefd91d..11e847fd198aadec4a431bdd970b4cda72e88cdb 100644 (file)
@@ -35,7 +35,6 @@
 
 #include "MEM_guardedalloc.h"
 
-#include "DNA_constraint_types.h"
 #include "DNA_movieclip_types.h"
 #include "DNA_object_types.h"  /* SELECT */
 #include "DNA_scene_types.h"
@@ -45,7 +44,6 @@
 #include "BLI_listbase.h"
 #include "BLI_ghash.h"
 
-#include "BKE_constraint.h"
 #include "BKE_global.h"
 #include "BKE_tracking.h"
 #include "BKE_movieclip.h"
@@ -873,40 +871,15 @@ MovieReconstructedCamera *BKE_tracking_get_reconstructed_camera(MovieTracking *t
        return NULL;
 }
 
-static void temporary_disable_camerasolver(Object *ob, Scene *scene, int disable)
-{
-       bConstraint *con;
-
-       for(con= ob->constraints.first; con; con=con->next) {
-               bConstraintTypeInfo *cti= constraint_get_typeinfo(con);
-
-               if(cti->type==CONSTRAINT_TYPE_CAMERASOLVER) {
-                       bCameraSolverConstraint *data= (bCameraSolverConstraint *)con->data;
-
-                       if(disable) data->flag|= CAMERASOLVER_TMPDISABLE;
-                       else data->flag&= ~CAMERASOLVER_TMPDISABLE;
-               }
-       }
-
-       if(ob->constraints.first)
-               where_is_object_time(scene, ob, CFRA+SUBFRA);
-}
-
 void BKE_get_tracking_mat(Scene *scene, float mat[4][4])
 {
-       float tmat[4][4];
-
-       unit_m4(mat);
-       unit_m4(tmat);
-
        if(!scene->camera)
                scene->camera= scene_find_camera(scene);
 
-       if(scene->camera) {
-               temporary_disable_camerasolver(scene->camera, scene, 1);
-               copy_m4_m4(mat, scene->camera->obmat);
-               temporary_disable_camerasolver(scene->camera, scene, 0);
-       }
+       if(scene->camera)
+               where_is_object_mat(scene, scene->camera, mat);
+       else
+               unit_m4(mat);
 }
 
 void BKE_tracking_projection_matrix(MovieTracking *tracking, int framenr, int winx, int winy, float mat[4][4])
index a175a9940237d550c6523f1e0983d38f62537047..ce48981d2953dbf892944a901a064c7d96451274 100644 (file)
@@ -762,8 +762,7 @@ typedef enum eFollowTrack_Flags {
 
 /* CameraSolver Constraint -> flag */
 typedef enum eCameraSolver_Flags {
-       CAMERASOLVER_DEFAULTCLIP        = (1<<0),
-       CAMERASOLVER_TMPDISABLE         = (1<<1)
+       CAMERASOLVER_DEFAULTCLIP        = (1<<0)
 } eCameraSolver_Flags;
 
 /* Rigid-Body Constraint */