Commit: a855a763c253fd61fce49002307b2c6f14aa50ed
Author: Campbell Barton
Date:   Fri Jul 13 08:37:20 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBa855a763c253fd61fce49002307b2c6f14aa50ed

Merge branch 'master' into blender2.8

===================================================================



===================================================================

diff --cc source/blender/blenkernel/intern/mesh.c
index 5c9736c2620,6d481472074..df20d5a2b5d
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@@ -372,48 -372,6 +374,49 @@@ void BKE_mesh_ensure_skin_customdata(Me
        }
  }
  
 +bool BKE_mesh_ensure_facemap_customdata(struct Mesh *me)
 +{
 +      BMesh *bm = me->edit_btmesh ? me->edit_btmesh->bm : NULL;
 +      bool changed = false;
 +      if (bm) {
 +              if (!CustomData_has_layer(&bm->pdata, CD_FACEMAP)) {
 +                      BM_data_layer_add(bm, &bm->pdata, CD_FACEMAP);
 +                      changed = true;
 +              }
 +      }
 +      else {
 +              if (!CustomData_has_layer(&me->pdata, CD_FACEMAP)) {
-                       CustomData_add_layer(&me->pdata,
-                                                 CD_FACEMAP,
-                                                 CD_DEFAULT,
-                                                 NULL,
-                                                 me->totpoly);
++                      CustomData_add_layer(
++                              &me->pdata,
++                              CD_FACEMAP,
++                              CD_DEFAULT,
++                              NULL,
++                              me->totpoly);
 +                      changed = true;
 +              }
 +      }
 +      return changed;
 +}
 +
 +bool BKE_mesh_clear_facemap_customdata(struct Mesh *me)
 +{
 +      BMesh *bm = me->edit_btmesh ? me->edit_btmesh->bm : NULL;
 +      bool changed = false;
 +      if (bm) {
 +              if (CustomData_has_layer(&bm->pdata, CD_FACEMAP)) {
 +                      BM_data_layer_free(bm, &bm->pdata, CD_FACEMAP);
 +                      changed = true;
 +              }
 +      }
 +      else {
 +              if (CustomData_has_layer(&me->pdata, CD_FACEMAP)) {
 +                      CustomData_free_layers(&me->pdata, CD_FACEMAP, 
me->totpoly);
 +                      changed = true;
 +              }
 +      }
 +      return changed;
 +}
 +
  /* this ensures grouped customdata (e.g. mtexpoly and mloopuv and mtface, or
   * mloopcol and mcol) have the same relative active/render/clone/mask indices.
   *
@@@ -1843,12 -1652,14 +1848,13 @@@ void BKE_mesh_split_faces(Mesh *mesh, b
  #endif
  }
  
 -
  /* **** Depsgraph evaluation **** */
  
- void BKE_mesh_eval_geometry(Depsgraph *depsgraph,
-                             Mesh *mesh)
+ void BKE_mesh_eval_geometry(
 -        EvaluationContext *UNUSED(eval_ctx),
++        Depsgraph *depsgraph,
+         Mesh *mesh)
  {
 -      DEG_debug_print_eval(__func__, mesh->id.name, mesh);
 +      DEG_debug_print_eval(depsgraph, __func__, mesh->id.name, mesh);
        if (mesh->bb == NULL || (mesh->bb->flag & BOUNDBOX_DIRTY)) {
                BKE_mesh_texspace_calc(mesh);
        }
diff --cc source/blender/blenkernel/intern/mesh_convert.c
index 3fc5d1ca51c,c801c5dcb01..738f116310b
--- a/source/blender/blenkernel/intern/mesh_convert.c
+++ b/source/blender/blenkernel/intern/mesh_convert.c
@@@ -1074,339 -1026,3 +1076,343 @@@ Mesh *BKE_mesh_new_from_object
  
        return tmpmesh;
  }
 +
 +
 +static void add_shapekey_layers(Mesh *mesh_dest, Mesh *mesh_src)
 +{
 +      KeyBlock *kb;
 +      Key *key = mesh_src->key;
 +      int i;
 +
 +      if (!mesh_src->key)
 +              return;
 +
 +      /* ensure we can use mesh vertex count for derived mesh custom data */
 +      if (mesh_src->totvert != mesh_dest->totvert) {
 +              fprintf(stderr,
 +                      "%s: vertex size mismatch (mesh/dm) '%s' (%d != %d)\n",
 +                      __func__, mesh_src->id.name + 2, mesh_src->totvert, 
mesh_dest->totvert);
 +              return;
 +      }
 +
 +      for (i = 0, kb = key->block.first; kb; kb = kb->next, i++) {
 +              int ci;
 +              float *array;
 +
 +              if (mesh_src->totvert != kb->totelem) {
 +                      fprintf(stderr,
 +                              "%s: vertex size mismatch (Mesh '%s':%d != 
KeyBlock '%s':%d)\n",
 +                              __func__, mesh_src->id.name + 2, 
mesh_src->totvert, kb->name, kb->totelem);
 +                      array = MEM_calloc_arrayN((size_t)mesh_src->totvert, 3 
* sizeof(float), __func__);
 +              }
 +              else {
 +                      array = MEM_malloc_arrayN((size_t)mesh_src->totvert, 3 
* sizeof(float), __func__);
 +                      memcpy(array, kb->data, (size_t)mesh_src->totvert * 3 * 
sizeof(float));
 +              }
 +
 +              CustomData_add_layer_named(&mesh_dest->vdata, CD_SHAPEKEY, 
CD_ASSIGN, array, mesh_dest->totvert, kb->name);
 +              ci = CustomData_get_layer_index_n(&mesh_dest->vdata, 
CD_SHAPEKEY, i);
 +
 +              mesh_dest->vdata.layers[ci].uid = kb->uid;
 +      }
 +}
 +
 +
 +Mesh *BKE_mesh_create_derived_for_modifier(
 +        struct Depsgraph *depsgraph, Scene *scene, Object *ob,
 +        ModifierData *md, int build_shapekey_layers)
 +{
 +      Mesh *me = ob->data;
 +      const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
 +      Mesh *result;
 +      KeyBlock *kb;
 +      ModifierEvalContext mectx = {depsgraph, ob, 0};
 +
 +      if (!(md->mode & eModifierMode_Realtime)) {
 +              return NULL;
 +      }
 +
 +      if (mti->isDisabled && mti->isDisabled(scene, md, 0)) {
 +              return NULL;
 +      }
 +
 +      if (build_shapekey_layers && me->key && (kb = 
BLI_findlink(&me->key->block, ob->shapenr - 1))) {
 +              BKE_keyblock_convert_to_mesh(kb, me);
 +      }
 +
 +      if (mti->type == eModifierTypeType_OnlyDeform) {
 +              int numVerts;
 +              float (*deformedVerts)[3] = BKE_mesh_vertexCos_get(me, 
&numVerts);
 +
 +              modifier_deformVerts(md, &mectx, NULL, deformedVerts, numVerts);
-               BKE_id_copy_ex(NULL, &me->id, (ID **)&result,
-                              LIB_ID_CREATE_NO_MAIN |
-                              LIB_ID_CREATE_NO_USER_REFCOUNT |
-                              LIB_ID_CREATE_NO_DEG_TAG |
-                              LIB_ID_COPY_NO_PREVIEW,
-                              false);
++              BKE_id_copy_ex(
++                      NULL, &me->id, (ID **)&result,
++                      LIB_ID_CREATE_NO_MAIN |
++                      LIB_ID_CREATE_NO_USER_REFCOUNT |
++                      LIB_ID_CREATE_NO_DEG_TAG |
++                      LIB_ID_COPY_NO_PREVIEW,
++                      false);
 +              BKE_mesh_apply_vert_coords(result, deformedVerts);
 +
 +              if (build_shapekey_layers)
 +                      add_shapekey_layers(result, me);
 +
 +              MEM_freeN(deformedVerts);
 +      }
 +      else {
 +              Mesh *mesh_temp;
-               BKE_id_copy_ex(NULL, &me->id, (ID **)&mesh_temp,
-                              LIB_ID_CREATE_NO_MAIN |
-                              LIB_ID_CREATE_NO_USER_REFCOUNT |
-                              LIB_ID_CREATE_NO_DEG_TAG |
-                              LIB_ID_COPY_NO_PREVIEW,
-                              false);
++              BKE_id_copy_ex(
++                      NULL, &me->id, (ID **)&mesh_temp,
++                      LIB_ID_CREATE_NO_MAIN |
++                      LIB_ID_CREATE_NO_USER_REFCOUNT |
++                      LIB_ID_CREATE_NO_DEG_TAG |
++                      LIB_ID_COPY_NO_PREVIEW,
++                      false);
 +
 +              if (build_shapekey_layers)
 +                      add_shapekey_layers(mesh_temp, me);
 +
 +              result = modifier_applyModifier(md, &mectx, mesh_temp);
 +              ASSERT_IS_VALID_MESH(result);
 +
 +              if (mesh_temp != result) {
 +                      BKE_id_free(NULL, mesh_temp);
 +              }
 +      }
 +
 +      return result;
 +}
 +
 +/* This is a Mesh-based copy of the same function in DerivedMesh.c */
 +static void shapekey_layers_to_keyblocks(Mesh *mesh_src, Mesh *mesh_dst, int 
actshape_uid)
 +{
 +      KeyBlock *kb;
 +      int i, j, tot;
 +
 +      if (!mesh_dst->key)
 +              return;
 +
 +      tot = CustomData_number_of_layers(&mesh_src->vdata, CD_SHAPEKEY);
 +      for (i = 0; i < tot; i++) {
 +              CustomDataLayer *layer = 
&mesh_src->vdata.layers[CustomData_get_layer_index_n(&mesh_src->vdata, 
CD_SHAPEKEY, i)];
 +              float (*cos)[3], (*kbcos)[3];
 +
 +              for (kb = mesh_dst->key->block.first; kb; kb = kb->next) {
 +                      if (kb->uid == layer->uid)
 +                              break;
 +              }
 +
 +              if (!kb) {
 +                      kb = BKE_keyblock_add(mesh_dst->key, layer->name);
 +                      kb->uid = layer->uid;
 +              }
 +
 +              if (kb->data)
 +                      MEM_freeN(kb->data);
 +
 +              cos = CustomData_get_layer_n(&mesh_src->vdata, CD_SHAPEKEY, i);
 +              kb->totelem = mesh_src->totvert;
 +
 +              kb->data = kbcos = MEM_malloc_arrayN(kb->totelem, 3 * 
sizeof(float), __func__);
 +              if (kb->uid == actshape_uid) {
 +                      MVert *mvert = mesh_src->mvert;
 +
 +                      for (j = 0; j < mesh_src->totvert; j++, kbcos++, 
mvert++) {
 +                              copy_v3_v3(*kbcos, mvert->co);
 +                      }
 +              }
 +              else {
 +                      for (j = 0; j < kb->totelem; j++, cos++, kbcos++) {
 +                              copy_v3_v3(*kbcos, *cos);
 +                      }
 +              }
 +      }
 +
 +      for (kb = mesh_dst->key->block.first; kb; kb = kb->next) {
 +              if (kb->totelem != mesh_src->totvert) {
 +                      if (kb->data)
 +                              MEM_freeN(kb->data);
 +
 +                      kb->totelem = mesh_src->totvert;
 +                      kb->data = MEM_calloc_arrayN(kb->totelem, 3 * 
sizeof(float), __func__);
 +                      fprintf(stderr, "%s: lost a shapekey layer: '%s'! 
(bmesh internal error)\n", __func__, kb->name);
 +              }
 +      }
 +}
 +
 +
 +/* This is a Mesh-based copy of DM_to_mesh() */
 +void BKE_mesh_nomain_to_mesh(Mesh *mesh_src, Mesh *mesh_dst, Object *ob, 
CustomDataMask mask, bool take_ownership)
 +{
 +      /* mesh_src might depend on mesh_dst, so we need to do everything with 
a local copy */
 +      /* TODO(Sybren): the above claim came from DM_to_mesh(); check whether 
it is still true with Mesh */
 +      Mesh tmp = *mesh_dst;
 +      int totvert, totedge /*, totface */ /* UNUSED */, totloop, totpoly;
 +      int did_shapekeys = 0;
 +      eCDAllocType alloctype = CD_DUPLICATE;
 +
 +      if (take_ownership /* && dm->type == DM_TYPE_CDDM && dm->needsFree */) {
 +              bool has_any_referenced_layers =
 +                      CustomData_has_referenced(&mesh_src->vdata) ||
 +                      CustomData_has_referenced(&mesh_src->edata) ||
 +                      CustomData_has_referenced(&mesh_src->ldata) ||
 +                      CustomData_has_referenced(&mesh_src->fdata) ||
 +                      CustomData_has_referenced(&mesh_src->pdata);
 +              if (!has_any_referenced_layers) {
 +                      alloctype = CD_ASSIGN;
 +              }
 +      }
 +      CustomData_reset(&tmp.vdata);
 +      CustomData_reset(&tmp.edata);
 +      CustomData_reset(&tmp.fdata);
 +      CustomData_reset(&tmp.ldata);
 +      CustomData_reset(&tmp.pdata);
 +
 +      BKE_mesh_ensure_normals(mesh_src);
 +
 +      totvert = tmp.totvert = mesh_src->totvert;
 +      totedge = tmp.totedge = mesh_src->totedge;
 +      totloop = tmp.totloop = mesh_src->totloop;
 +      totpoly = tmp.totpoly = mesh_src->totpoly;
 +      tmp.totface = 0;
 +
 +      CustomData_copy(&mesh_src->vdata, &tmp.vdata, mask, alloctype, totvert);
 +      CustomData_copy(&mesh_src->edata, &tmp.edata, mask, alloctype, totedge);
 +      CustomData_copy(&mesh_src->ldata, &tmp.ldata, mask, alloctype, totloop);
 +      CustomData_copy(&mesh_src->pdata, &tmp.pdata, mask, alloctype, totpoly);
 +      tmp.cd_flag = mesh_src->cd_flag;
 +      tmp.runtime.deformed_only = mesh_src->runtime.deformed_only;
 +
 +      if (CustomData_has_layer(&mesh_src->vdata, CD_SHAPEKEY)) {
 +              KeyBlock *kb;
 +              int uid;
 +
 +              if (ob) {
 +                      kb = BLI_findlink(&mesh_dst->key->block, ob->shapenr - 
1);
 +                      if (kb) {
 +                              uid = kb->uid;
 +                      }
 +                      else {
 +                              printf("%s: error - could not find active 
shapekey %d!\n",
 +                                     __func__, ob->shapenr - 1);
 +
 +                              uid = INT_MAX;
 +                      }
 +              }
 +              else {
 +                      /* if no object, set to INT_MAX so we don't mes

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to