Merging r58362 through r58463 from trunk into soc-2013-depsgraph_mt
[blender.git] / source / blender / blenkernel / intern / constraint.c
index c78038c0f6673a7acfd92628a1fb562eea0b4510..8926ef0b599ff42d46bf3fc64be1c08f143f5038 100644 (file)
@@ -69,6 +69,7 @@
 #include "BKE_bvhutils.h"
 #include "BKE_camera.h"
 #include "BKE_constraint.h"
+#include "BKE_curve.h"
 #include "BKE_displist.h"
 #include "BKE_deform.h"
 #include "BKE_DerivedMesh.h"    /* for geometry targets */
@@ -132,8 +133,8 @@ bConstraintOb *BKE_constraints_make_evalob(Scene *scene, Object *ob, void *subda
                                unit_m4(cob->matrix);
                        
                        copy_m4_m4(cob->startmat, cob->matrix);
+                       break;
                }
-               break;
                case CONSTRAINT_OBTYPE_BONE:
                {
                        /* only set if we have valid bone, otherwise default */
@@ -158,9 +159,8 @@ bConstraintOb *BKE_constraints_make_evalob(Scene *scene, Object *ob, void *subda
                                unit_m4(cob->matrix);
                                
                        copy_m4_m4(cob->startmat, cob->matrix);
+                       break;
                }
-               break;
-                       
                default: /* other types not yet handled */
                        unit_m4(cob->matrix);
                        unit_m4(cob->startmat);
@@ -195,8 +195,8 @@ void BKE_constraints_clear_evalob(bConstraintOb *cob)
                                /* copy inverse of delta back to owner */
                                invert_m4_m4(cob->ob->constinv, delta);
                        }
+                       break;
                }
-               break;
                case CONSTRAINT_OBTYPE_BONE:
                {
                        /* cob->ob or cob->pchan might not exist */
@@ -207,8 +207,8 @@ void BKE_constraints_clear_evalob(bConstraintOb *cob)
                                /* copy inverse of delta back to owner */
                                invert_m4_m4(cob->pchan->constinv, delta);
                        }
+                       break;
                }
-               break;
        }
        
        /* free tempolary struct */
@@ -246,8 +246,8 @@ void BKE_constraint_mat_convertspace(Object *ob, bPoseChannel *pchan, float mat[
                                        /* call self with slightly different values */
                                        BKE_constraint_mat_convertspace(ob, pchan, mat, CONSTRAINT_SPACE_POSE, to);
                                }
+                               break;
                        }
-                       break;
                        case CONSTRAINT_SPACE_POSE: /* ---------- FROM POSESPACE ---------- */
                        {
                                /* pose to world */
@@ -267,8 +267,8 @@ void BKE_constraint_mat_convertspace(Object *ob, bPoseChannel *pchan, float mat[
                                                mul_m4_m4m4(mat, imat, mat);
                                        }
                                }
+                               break;
                        }
-                       break;
                        case CONSTRAINT_SPACE_LOCAL: /* ------------ FROM LOCALSPACE --------- */
                        {
                                /* local to pose - do inverse procedure that was done for pose to local */
@@ -282,8 +282,8 @@ void BKE_constraint_mat_convertspace(Object *ob, bPoseChannel *pchan, float mat[
                                        /* call self with slightly different values */
                                        BKE_constraint_mat_convertspace(ob, pchan, mat, CONSTRAINT_SPACE_POSE, to);
                                }
+                               break;
                        }
-                       break;
                        case CONSTRAINT_SPACE_PARLOCAL: /* -------------- FROM LOCAL WITH PARENT ---------- */
                        {
                                /* local + parent to pose */
@@ -297,8 +297,8 @@ void BKE_constraint_mat_convertspace(Object *ob, bPoseChannel *pchan, float mat[
                                        /* call self with slightly different values */
                                        BKE_constraint_mat_convertspace(ob, pchan, mat, CONSTRAINT_SPACE_POSE, to);
                                }
+                               break;
                        }
-                       break;
                }
        }
        else {
@@ -449,7 +449,7 @@ static void contarget_get_lattice_mat(Object *ob, const char *substring, float m
 {
        Lattice *lt = (Lattice *)ob->data;
        
-       DispList *dl = BKE_displist_find(&ob->disp, DL_VERTS);
+       DispList *dl = ob->curve_cache ? BKE_displist_find(&ob->curve_cache->disp, DL_VERTS) : NULL;
        float *co = dl ? dl->verts : NULL;
        BPoint *bp = lt->def;
        
@@ -1164,10 +1164,10 @@ static void followpath_get_tarmat(bConstraint *con, bConstraintOb *cob, bConstra
                 */
                
                /* only happens on reload file, but violates depsgraph still... fix! */
-               if (cu->path == NULL || cu->path->data == NULL)
+               if (ct->tar->curve_cache == NULL || ct->tar->curve_cache->path == NULL || ct->tar->curve_cache->path->data == NULL)
                        BKE_displist_make_curveTypes(cob->scene, ct->tar, 0);
                
-               if (cu->path && cu->path->data) {
+               if (ct->tar->curve_cache->path && ct->tar->curve_cache->path->data) {
                        float quat[4];
                        if ((data->followflag & FOLLOWPATH_STATIC) == 0) {
                                /* animated position along curve depending on time */
@@ -1934,10 +1934,8 @@ static void pycon_get_tarmat(bConstraint *con, bConstraintOb *cob, bConstraintTa
        if (VALID_CONS_TARGET(ct)) {
                /* special exception for curves - depsgraph issues */
                if (ct->tar->type == OB_CURVE) {
-                       Curve *cu = ct->tar->data;
-                       
                        /* this check is to make sure curve objects get updated on file load correctly.*/
-                       if (cu->path == NULL || cu->path->data == NULL) /* only happens on reload file, but violates depsgraph still... fix! */
+                       if (ct->tar->curve_cache == NULL || ct->tar->curve_cache->path == NULL || ct->tar->curve_cache->path->data == NULL) /* only happens on reload file, but violates depsgraph still... fix! */
                                BKE_displist_make_curveTypes(cob->scene, ct->tar, 0);
                }
                
@@ -2235,8 +2233,8 @@ static void locktrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *t
                                        
                                                /* the z axis gets mapped onto a third orthogonal vector */
                                                cross_v3_v3v3(totmat[2], totmat[0], totmat[1]);
+                                               break;
                                        }
-                                       break;
                                        case TRACK_Z: /* LOCK X TRACK Z */
                                        {
                                                /* Projection of Vector on the plane */
@@ -2249,8 +2247,8 @@ static void locktrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *t
                                        
                                                /* the z axis gets mapped onto a third orthogonal vector */
                                                cross_v3_v3v3(totmat[1], totmat[2], totmat[0]);
+                                               break;
                                        }
-                                       break;
                                        case TRACK_nY: /* LOCK X TRACK -Y */
                                        {
                                                /* Projection of Vector on the plane */
@@ -2264,8 +2262,8 @@ static void locktrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *t
                                        
                                                /* the z axis gets mapped onto a third orthogonal vector */
                                                cross_v3_v3v3(totmat[2], totmat[0], totmat[1]);
+                                               break;
                                        }
-                                       break;
                                        case TRACK_nZ: /* LOCK X TRACK -Z */
                                        {
                                                /* Projection of Vector on the plane */
@@ -2279,16 +2277,16 @@ static void locktrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *t
                                                
                                                /* the z axis gets mapped onto a third orthogonal vector */
                                                cross_v3_v3v3(totmat[1], totmat[2], totmat[0]);
+                                               break;
                                        }
-                                       break;
                                        default:
                                        {
                                                unit_m3(totmat);
+                                               break;
                                        }
-                                       break;
                                }
+                               break;
                        }
-                       break;
                        case LOCK_Y: /* LOCK Y */
                        {
                                switch (data->trackflag) {
@@ -2304,8 +2302,8 @@ static void locktrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *t
 
                                                /* the z axis gets mapped onto a third orthogonal vector */
                                                cross_v3_v3v3(totmat[2], totmat[0], totmat[1]);
+                                               break;
                                        }
-                                       break;
                                        case TRACK_Z: /* LOCK Y TRACK Z */
                                        {
                                                /* Projection of Vector on the plane */
@@ -2318,8 +2316,8 @@ static void locktrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *t
                                        
                                                /* the z axis gets mapped onto a third orthogonal vector */
                                                cross_v3_v3v3(totmat[0], totmat[1], totmat[2]);
+                                               break;
                                        }
-                                       break;
                                        case TRACK_nX: /* LOCK Y TRACK -X */
                                        {
                                                /* Projection of Vector on the plane */
@@ -2333,8 +2331,8 @@ static void locktrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *t
                                        
                                                /* the z axis gets mapped onto a third orthogonal vector */
                                                cross_v3_v3v3(totmat[2], totmat[0], totmat[1]);
+                                               break;
                                        }
-                                       break;
                                        case TRACK_nZ: /* LOCK Y TRACK -Z */
                                        {
                                                /* Projection of Vector on the plane */
@@ -2348,16 +2346,16 @@ static void locktrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *t
                                        
                                                /* the z axis gets mapped onto a third orthogonal vector */
                                                cross_v3_v3v3(totmat[0], totmat[1], totmat[2]);
+                                               break;
                                        }
-                                       break;
                                        default:
                                        {
                                                unit_m3(totmat);
+                                               break;
                                        }
-                                       break;
                                }
+                               break;
                        }
-                       break;
                        case LOCK_Z: /* LOCK Z */
                        {
                                switch (data->trackflag) {
@@ -2373,8 +2371,8 @@ static void locktrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *t
                                        
                                                /* the x axis gets mapped onto a third orthogonal vector */
                                                cross_v3_v3v3(totmat[1], totmat[2], totmat[0]);
+                                               break;
                                        }
-                                       break;
                                        case TRACK_Y: /* LOCK Z TRACK Y */
                                        {
                                                /* Projection of Vector on the plane */
@@ -2387,8 +2385,8 @@ static void locktrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *t
                                                
                                                /* the x axis gets mapped onto a third orthogonal vector */
                                                cross_v3_v3v3(totmat[0], totmat[1], totmat[2]);
+                                               break;
                                        }
-                                       break;
                                        case TRACK_nX: /* LOCK Z TRACK -X */
                                        {
                                                /* Projection of Vector on the plane */
@@ -2402,8 +2400,8 @@ static void locktrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *t
                                        
                                                /* the x axis gets mapped onto a third orthogonal vector */
                                                cross_v3_v3v3(totmat[1], totmat[2], totmat[0]);
+                                               break;
                                        }
-                                       break;
                                        case TRACK_nY: /* LOCK Z TRACK -Y */
                                        {
                                                /* Projection of Vector on the plane */
@@ -2417,21 +2415,21 @@ static void locktrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *t
                                                
                                                /* the x axis gets mapped onto a third orthogonal vector */
                                                cross_v3_v3v3(totmat[0], totmat[1], totmat[2]);
+                                               break;
                                        }
-                                       break;
                                        default:
                                        {
                                                unit_m3(totmat);
+                                               break;
                                        }
-                                       break;
                                }
+                               break;
                        }
-                       break;
                        default:
                        {
                                unit_m3(totmat);
+                               break;
                        }
-                       break;
                }
                /* Block to keep matrix heading */
                copy_m3_m4(tmpmat, cob->matrix);
@@ -3008,14 +3006,12 @@ static void clampto_flush_tars(bConstraint *con, ListBase *list, short nocopy)
 static void clampto_get_tarmat(bConstraint *UNUSED(con), bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime))
 {
        if (VALID_CONS_TARGET(ct)) {
-               Curve *cu = ct->tar->data;
-               
                /* note: when creating constraints that follow path, the curve gets the CU_PATH set now,
                 *              currently for paths to work it needs to go through the bevlist/displist system (ton) 
                 */
                
                /* only happens on reload file, but violates depsgraph still... fix! */
-               if (cu->path == NULL || cu->path->data == NULL)
+               if (ct->tar->curve_cache == NULL || ct->tar->curve_cache->path == NULL || ct->tar->curve_cache->path->data == NULL)
                        BKE_displist_make_curveTypes(cob->scene, ct->tar, 0);
        }
        
@@ -3033,7 +3029,6 @@ static void clampto_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *tar
        
        /* only evaluate if there is a target and it is a curve */
        if (VALID_CONS_TARGET(ct) && (ct->tar->type == OB_CURVE)) {
-               Curve *cu = data->tar->data;
                float obmat[4][4], ownLoc[3];
                float curveMin[3], curveMax[3];
                float targetMatrix[4][4] = MAT4_UNITY;
@@ -3046,7 +3041,7 @@ static void clampto_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *tar
                BKE_object_minmax(ct->tar, curveMin, curveMax, TRUE);
                
                /* get targetmatrix */
-               if (cu->path && cu->path->data) {
+               if (data->tar->curve_cache &&  data->tar->curve_cache->path && data->tar->curve_cache->path->data) {
                        float vec[4], dir[3], totmat[4][4];
                        float curvetime;
                        short clamp_axis;
@@ -3649,14 +3644,12 @@ static void splineik_flush_tars(bConstraint *con, ListBase *list, short nocopy)
 static void splineik_get_tarmat(bConstraint *UNUSED(con), bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime))
 {
        if (VALID_CONS_TARGET(ct)) {
-               Curve *cu = ct->tar->data;
-               
                /* note: when creating constraints that follow path, the curve gets the CU_PATH set now,
                 *              currently for paths to work it needs to go through the bevlist/displist system (ton) 
                 */
                
                /* only happens on reload file, but violates depsgraph still... fix! */
-               if (cu->path == NULL || cu->path->data == NULL)
+               if (ct->tar->curve_cache == NULL || ct->tar->curve_cache->path == NULL || ct->tar->curve_cache->path->data == NULL)
                        BKE_displist_make_curveTypes(cob->scene, ct->tar, 0);
        }
        
@@ -4414,8 +4407,8 @@ static bConstraint *add_new_constraint(Object *ob, bPoseChannel *pchan, const ch
                                con->ownspace = CONSTRAINT_SPACE_POSE;
                                con->flag |= CONSTRAINT_SPACEONCE;
                        }
+                       break;
                }
-               break;
        }
        
        return con;
@@ -4640,8 +4633,8 @@ void BKE_get_constraint_target_matrix(Scene *scene, bConstraint *con, int index,
                                        unit_m4(cob->matrix);
                                        unit_m4(cob->startmat);
                                }
+                               break;
                        }
-                       break;
                        case CONSTRAINT_OBTYPE_BONE: /* this may occur in some cases */
                        {
                                cob->ob = NULL; /* this might not work at all :/ */
@@ -4654,8 +4647,8 @@ void BKE_get_constraint_target_matrix(Scene *scene, bConstraint *con, int index,
                                        unit_m4(cob->matrix);
                                        unit_m4(cob->startmat);
                                }
+                               break;
                        }
-                       break;
                }
                
                /* get targets - we only need the first one though (and there should only be one) */