Merge branch 'master' into blender2.8
authorPhilipp Oeser <info@graphics-engineer.com>
Wed, 9 May 2018 13:08:13 +0000 (15:08 +0200)
committerPhilipp Oeser <info@graphics-engineer.com>
Wed, 9 May 2018 13:08:13 +0000 (15:08 +0200)
1  2 
source/blender/blenkernel/intern/lattice.c

index 30c839bf76648c4837f95638de40f5903c6abcf4,edca0257d2010a4fee46b8aa1b7f411ea2241e86..b9b894db9a5a26750335689d713aab864938a185
@@@ -53,6 -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)
  {
@@@ -307,8 -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);
@@@ -597,7 -601,7 +597,7 @@@ static bool where_on_path_deform(Objec
  /* 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;
        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 */
  }
  
  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;
  
                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;
                                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]);
                                }
                                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]);
                                }
                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]);
                        }
                }
        
                        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]);
                        }
                }
  /* 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;
  
        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);
  
  }
  
 -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;
+       MDeformVert *dvert = NULL;
+       int defgrp_index = -1;
        int a;
-       bool use_vgroups;
  
        if (laOb->type != OB_LATTICE)
                return;
  
        lattice_deform_data = init_latt_deform(laOb, target);
  
-       /* check whether to use vertex groups (only possible if target is a Mesh)
-        * we want either a Mesh with no derived data, or derived data with
-        * deformverts
+       /* Check whether to use vertex groups (only possible if target is a Mesh or Lattice).
+        * We want either a Mesh/Lattice with no derived data, or derived data with deformverts.
         */
-       if (target && target->type == OB_MESH) {
-               /* if there's derived data without deformverts, don't use vgroups */
-               if (mesh) {
-                       use_vgroups = (mesh->dvert != NULL);
-               }
-               else {
-                       Mesh *me = target->data;
-                       use_vgroups = (me->dvert != NULL);
+       if (vgroup && vgroup[0] && target && ELEM(target->type, OB_MESH, OB_LATTICE)) {
+               defgrp_index = defgroup_name_index(target, vgroup);
+               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;
+                       }
+                       else {
+                               dvert = ((Mesh *)target->data)->dvert;
+                       }
                }
        }
-       else {
-               use_vgroups = false;
-       }
-       
-       if (vgroup && vgroup[0] && use_vgroups) {
-               Mesh *me = target->data;
-               const int defgrp_index = defgroup_name_index(target, vgroup);
-               float weight;
-               if (defgrp_index >= 0 && (me->dvert || mesh)) {
-                       MDeformVert *dvert = mesh ? mesh->dvert : me->dvert;
-                       
-                       for (a = 0; a < numVerts; a++, dvert++) {
-                               weight = defvert_find_weight(dvert, defgrp_index);
-                               if (weight > 0.0f)
-                                       calc_latt_deform(lattice_deform_data, vertexCos[a], weight * fac);
+       if (dvert) {
+               MDeformVert *dvert_iter;
+               for (a = 0, dvert_iter = dvert; a < numVerts; a++, dvert_iter++) {
+                       const float weight = defvert_find_weight(dvert_iter, defgrp_index);
+                       if (weight > 0.0f) {
+                               calc_latt_deform(lattice_deform_data, vertexCos[a], weight * fac);
                        }
                }
        }
@@@ -1024,14 -1025,13 +1019,14 @@@ void BKE_lattice_vertexcos_apply(struc
        }
  }
  
 -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);
                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,24 -1226,8 +1221,24 @@@ void BKE_lattice_translate(Lattice *lt
  
  /* **** 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);
 +      }
 +}