Merge branch 'master' into blender2.8
[blender.git] / source / blender / blenkernel / intern / lattice.c
index edca0257d2010a4fee46b8aa1b7f411ea2241e86..b9b894db9a5a26750335689d713aab864938a185 100644 (file)
@@ -53,7 +53,6 @@
 #include "BKE_anim.h"
 #include "BKE_cdderivedmesh.h"
 #include "BKE_curve.h"
-#include "BKE_depsgraph.h"
 #include "BKE_displist.h"
 #include "BKE_key.h"
 #include "BKE_lattice.h"
 
 #include "BKE_deform.h"
 
-/* Workaround for cyclic dependency with curves.
- * In such case curve_cache might not be ready yet,
- */
-#define CYCLIC_DEPENDENCY_WORKAROUND
-
 int BKE_lattice_index_from_uvw(Lattice *lt,
                                const int u, const int v, const int w)
 {
@@ -313,6 +307,8 @@ void BKE_lattice_free(Lattice *lt)
 {
        BKE_animdata_free(&lt->id, false);
 
+       BKE_lattice_batch_cache_free(lt);
+
        MEM_SAFE_FREE(lt->def);
        if (lt->dvert) {
                BKE_defvert_array_free(lt->dvert, lt->pntsu * lt->pntsv * lt->pntsw);
@@ -601,7 +597,7 @@ static bool where_on_path_deform(Object *ob, float ctime, float vec[4], float di
 /* co: local coord, result local too */
 /* returns quaternion for rotation, using cd->no_rot_axis */
 /* axis is using another define!!! */
-static bool calc_curve_deform(Scene *scene, Object *par, float co[3],
+static bool calc_curve_deform(Object *par, float co[3],
                               const short axis, CurveDeform *cd, float r_quat[4])
 {
        Curve *cu = par->data;
@@ -609,12 +605,10 @@ static bool calc_curve_deform(Scene *scene, Object *par, float co[3],
        short index;
        const bool is_neg_axis = (axis > 2);
 
-       /* to be sure, mostly after file load, also cyclic dependencies */
-#ifdef CYCLIC_DEPENDENCY_WORKAROUND
        if (par->curve_cache == NULL) {
-               BKE_displist_make_curveTypes(scene, par, false);
+               /* Happens with a cyclic dependencies. */
+               return false;
        }
-#endif
 
        if (par->curve_cache->path == NULL) {
                return false;  /* happens on append, cyclic dependencies and empty curves */
@@ -705,7 +699,7 @@ static bool calc_curve_deform(Scene *scene, Object *par, float co[3],
 }
 
 void curve_deform_verts(
-        Scene *scene, Object *cuOb, Object *target, DerivedMesh *dm, float (*vertexCos)[3],
+        Object *cuOb, Object *target, Mesh *mesh, float (*vertexCos)[3],
         int numVerts, const char *vgroup, short defaxis)
 {
        Curve *cu;
@@ -741,8 +735,8 @@ void curve_deform_verts(
 
                if (defgrp_index != -1) {
                        /* if there's derived data without deformverts, don't use vgroups */
-                       if (dm) {
-                               dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT);
+                       if (mesh) {
+                               dvert = CustomData_get_layer(&mesh->vdata, CD_MDEFORMVERT);
                        }
                        else if (target->type == OB_LATTICE) {
                                dvert = ((Lattice *)target->data)->dvert;
@@ -764,7 +758,7 @@ void curve_deform_verts(
                                if (weight > 0.0f) {
                                        mul_m4_v3(cd.curvespace, vertexCos[a]);
                                        copy_v3_v3(vec, vertexCos[a]);
-                                       calc_curve_deform(scene, cuOb, vec, defaxis, &cd, NULL);
+                                       calc_curve_deform(cuOb, vec, defaxis, &cd, NULL);
                                        interp_v3_v3v3(vertexCos[a], vertexCos[a], vec, weight);
                                        mul_m4_v3(cd.objectspace, vertexCos[a]);
                                }
@@ -787,7 +781,7 @@ void curve_deform_verts(
                                if (weight > 0.0f) {
                                        /* already in 'cd.curvespace', prev for loop */
                                        copy_v3_v3(vec, vertexCos[a]);
-                                       calc_curve_deform(scene, cuOb, vec, defaxis, &cd, NULL);
+                                       calc_curve_deform(cuOb, vec, defaxis, &cd, NULL);
                                        interp_v3_v3v3(vertexCos[a], vertexCos[a], vec, weight);
                                        mul_m4_v3(cd.objectspace, vertexCos[a]);
                                }
@@ -798,7 +792,7 @@ void curve_deform_verts(
                if (cu->flag & CU_DEFORM_BOUNDS_OFF) {
                        for (a = 0; a < numVerts; a++) {
                                mul_m4_v3(cd.curvespace, vertexCos[a]);
-                               calc_curve_deform(scene, cuOb, vertexCos[a], defaxis, &cd, NULL);
+                               calc_curve_deform(cuOb, vertexCos[a], defaxis, &cd, NULL);
                                mul_m4_v3(cd.objectspace, vertexCos[a]);
                        }
                }
@@ -813,7 +807,7 @@ void curve_deform_verts(
        
                        for (a = 0; a < numVerts; a++) {
                                /* already in 'cd.curvespace', prev for loop */
-                               calc_curve_deform(scene, cuOb, vertexCos[a], defaxis, &cd, NULL);
+                               calc_curve_deform(cuOb, vertexCos[a], defaxis, &cd, NULL);
                                mul_m4_v3(cd.objectspace, vertexCos[a]);
                        }
                }
@@ -823,7 +817,7 @@ void curve_deform_verts(
 /* input vec and orco = local coord in armature space */
 /* orco is original not-animated or deformed reference point */
 /* result written in vec and mat */
-void curve_deform_vector(Scene *scene, Object *cuOb, Object *target,
+void curve_deform_vector(Object *cuOb, Object *target,
                          float orco[3], float vec[3], float mat[3][3], int no_rot_axis)
 {
        CurveDeform cd;
@@ -842,7 +836,7 @@ void curve_deform_vector(Scene *scene, Object *cuOb, Object *target,
 
        mul_m4_v3(cd.curvespace, vec);
        
-       if (calc_curve_deform(scene, cuOb, vec, target->trackflag, &cd, quat)) {
+       if (calc_curve_deform(cuOb, vec, target->trackflag, &cd, quat)) {
                float qmat[3][3];
                
                quat_to_mat3(qmat, quat);
@@ -855,7 +849,7 @@ void curve_deform_vector(Scene *scene, Object *cuOb, Object *target,
 
 }
 
-void lattice_deform_verts(Object *laOb, Object *target, DerivedMesh *dm,
+void lattice_deform_verts(Object *laOb, Object *target, Mesh *mesh,
                           float (*vertexCos)[3], int numVerts, const char *vgroup, float fac)
 {
        LatticeDeformData *lattice_deform_data;
@@ -876,8 +870,8 @@ void lattice_deform_verts(Object *laOb, Object *target, DerivedMesh *dm,
 
                if (defgrp_index != -1) {
                        /* if there's derived data without deformverts, don't use vgroups */
-                       if (dm) {
-                               dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT);
+                       if (mesh) {
+                               dvert = CustomData_get_layer(&mesh->vdata, CD_MDEFORMVERT);
                        }
                        else if (target->type == OB_LATTICE) {
                                dvert = ((Lattice *)target->data)->dvert;
@@ -1025,13 +1019,14 @@ void BKE_lattice_vertexcos_apply(struct Object *ob, float (*vertexCos)[3])
        }
 }
 
-void BKE_lattice_modifiers_calc(Scene *scene, Object *ob)
+void BKE_lattice_modifiers_calc(struct Depsgraph *depsgraph, Scene *scene, Object *ob)
 {
        Lattice *lt = ob->data;
        VirtualModifierData virtualModifierData;
        ModifierData *md = modifiers_getVirtualModifierList(ob, &virtualModifierData);
        float (*vertexCos)[3] = NULL;
        int numVerts, editmode = (lt->editlatt != NULL);
+       const ModifierEvalContext mectx = {depsgraph, ob, 0};
 
        if (ob->curve_cache) {
                BKE_displist_free(&ob->curve_cache->disp);
@@ -1052,7 +1047,7 @@ void BKE_lattice_modifiers_calc(Scene *scene, Object *ob)
                if (mti->type != eModifierTypeType_OnlyDeform) continue;
 
                if (!vertexCos) vertexCos = BKE_lattice_vertexcos_get(ob, &numVerts);
-               mti->deformVerts(md, ob, NULL, vertexCos, numVerts, 0);
+               modifier_deformVerts_DM_deprecated(md, &mectx, NULL, vertexCos, numVerts);
        }
 
        /* always displist to make this work like derivedmesh */
@@ -1226,8 +1221,24 @@ void BKE_lattice_translate(Lattice *lt, float offset[3], bool do_keys)
 
 /* **** Depsgraph evaluation **** */
 
-void BKE_lattice_eval_geometry(EvaluationContext *UNUSED(eval_ctx),
+void BKE_lattice_eval_geometry(struct Depsgraph *UNUSED(depsgraph),
                                Lattice *UNUSED(latt))
 {
 }
 
+/* Draw Engine */
+void (*BKE_lattice_batch_cache_dirty_cb)(Lattice *lt, int mode) = NULL;
+void (*BKE_lattice_batch_cache_free_cb)(Lattice *lt) = NULL;
+
+void BKE_lattice_batch_cache_dirty(Lattice *lt, int mode)
+{
+       if (lt->batch_cache) {
+               BKE_lattice_batch_cache_dirty_cb(lt, mode);
+       }
+}
+void BKE_lattice_batch_cache_free(Lattice *lt)
+{
+       if (lt->batch_cache) {
+               BKE_lattice_batch_cache_free_cb(lt);
+       }
+}