[Bf-blender-cvs] [e202e27b144] refactor-mesh-bevel-weight-generic: Merge branch 'master' into refactor-mesh-bevel-weight-generic

Hans Goudey noreply at git.blender.org
Wed Aug 31 18:45:40 CEST 2022


Commit: e202e27b144265f5de7c1044638057d792b6ffaf
Author: Hans Goudey
Date:   Wed Aug 31 11:45:08 2022 -0500
Branches: refactor-mesh-bevel-weight-generic
https://developer.blender.org/rBe202e27b144265f5de7c1044638057d792b6ffaf

Merge branch 'master' into refactor-mesh-bevel-weight-generic

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



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

diff --cc source/blender/blenkernel/intern/mball_tessellate.c
index 1ca4f120bc2,bfa11b74782..36e900a14d8
--- a/source/blender/blenkernel/intern/mball_tessellate.c
+++ b/source/blender/blenkernel/intern/mball_tessellate.c
@@@ -1444,9 -1444,10 +1444,9 @@@ Mesh *BKE_mball_polygonize(Depsgraph *d
    Mesh *mesh = (Mesh *)BKE_id_new_nomain(ID_ME, ((ID *)ob->data)->name + 2);
  
    mesh->totvert = (int)process.curvertex;
-   MVert *mvert = CustomData_add_layer(&mesh->vdata, CD_MVERT, CD_DEFAULT, NULL, mesh->totvert);
+   MVert *mvert = CustomData_add_layer(&mesh->vdata, CD_MVERT, CD_CONSTRUCT, NULL, mesh->totvert);
    for (int i = 0; i < mesh->totvert; i++) {
      copy_v3_v3(mvert[i].co, process.co[i]);
 -    mvert->bweight = 0;
      mvert->flag = 0;
    }
    MEM_freeN(process.co);
diff --cc source/blender/blenkernel/intern/mesh.cc
index cd076b370f1,b44a956eec4..af061a9daae
--- a/source/blender/blenkernel/intern/mesh.cc
+++ b/source/blender/blenkernel/intern/mesh.cc
@@@ -249,7 -254,7 +254,8 @@@ static void mesh_blend_write(BlendWrite
      Set<std::string> names_to_skip;
      if (!BLO_write_is_undo(writer)) {
        BKE_mesh_legacy_convert_hide_layers_to_flags(mesh);
 +      BKE_mesh_legacy_bevel_weight_from_layers(mesh);
+       BKE_mesh_legacy_convert_material_indices_to_mpoly(mesh);
        /* When converting to the old mesh format, don't save redundant attributes. */
        names_to_skip.add_multiple_new({".hide_vert", ".hide_edge", ".hide_poly"});
      }
@@@ -338,7 -343,7 +344,6 @@@ static void mesh_blend_read_data(BlendD
  
    if (!BLO_read_data_is_undo(reader)) {
      BKE_mesh_legacy_convert_flags_to_hide_layers(mesh);
-     BKE_mesh_legacy_bevel_weight_to_layers(mesh);
 -    BKE_mesh_legacy_convert_mpoly_to_material_indices(mesh);
    }
  
    /* We don't expect to load normals from files, since they are derived data. */
diff --cc source/blender/blenkernel/intern/mesh_legacy_convert.cc
index 19594282b3f,2fc984997b8..e0f33fb038e
--- a/source/blender/blenkernel/intern/mesh_legacy_convert.cc
+++ b/source/blender/blenkernel/intern/mesh_legacy_convert.cc
@@@ -877,67 -878,6 +878,67 @@@ void BKE_mesh_add_mface_layers(CustomDa
  
  /** \} */
  
 +/* -------------------------------------------------------------------- */
 +/** \name Bevel Weight Conversion
 + * \{ */
 +
 +void BKE_mesh_legacy_bevel_weight_from_layers(Mesh *mesh)
 +{
 +  using namespace blender;
 +  MutableSpan<MVert> vertices(mesh->mvert, mesh->totvert);
 +  if (const float *weights = static_cast<const float *>(
 +          CustomData_get_layer(&mesh->vdata, CD_BWEIGHT))) {
 +    mesh->cd_flag |= ME_CDFLAG_VERT_BWEIGHT;
 +    for (const int i : vertices.index_range()) {
 +      vertices[i].bweight = std::clamp(weights[i], 0.0f, 1.0f) * 255.0f;
 +    }
 +  }
 +  else {
 +    mesh->cd_flag &= ~ME_CDFLAG_VERT_BWEIGHT;
 +    for (const int i : vertices.index_range()) {
 +      vertices[i].bweight = 0;
 +    }
 +  }
 +  MutableSpan<MEdge> edges(mesh->medge, mesh->totedge);
 +  if (const float *weights = static_cast<const float *>(
 +          CustomData_get_layer(&mesh->edata, CD_BWEIGHT))) {
 +    mesh->cd_flag |= ME_CDFLAG_EDGE_BWEIGHT;
 +    for (const int i : edges.index_range()) {
 +      edges[i].bweight = std::clamp(weights[i], 0.0f, 1.0f) * 255.0f;
 +    }
 +  }
 +  else {
 +    mesh->cd_flag &= ~ME_CDFLAG_EDGE_BWEIGHT;
 +    for (const int i : edges.index_range()) {
 +      edges[i].bweight = 0;
 +    }
 +  }
 +}
 +
 +void BKE_mesh_legacy_bevel_weight_to_layers(Mesh *mesh)
 +{
 +  using namespace blender;
 +  const Span<MVert> vertices(mesh->mvert, mesh->totvert);
 +  if (mesh->cd_flag & ME_CDFLAG_VERT_BWEIGHT) {
 +    float *weights = static_cast<float *>(
-         CustomData_add_layer(&mesh->vdata, CD_BWEIGHT, CD_DEFAULT, nullptr, vertices.size()));
++        CustomData_add_layer(&mesh->vdata, CD_BWEIGHT, CD_CONSTRUCT, nullptr, vertices.size()));
 +    for (const int i : vertices.index_range()) {
 +      weights[i] = vertices[i].bweight / 255.0f;
 +    }
 +  }
 +
 +  const Span<MEdge> edges(mesh->medge, mesh->totedge);
 +  if (mesh->cd_flag & ME_CDFLAG_EDGE_BWEIGHT) {
 +    float *weights = static_cast<float *>(
-         CustomData_add_layer(&mesh->edata, CD_BWEIGHT, CD_DEFAULT, nullptr, edges.size()));
++        CustomData_add_layer(&mesh->edata, CD_BWEIGHT, CD_CONSTRUCT, nullptr, edges.size()));
 +    for (const int i : edges.index_range()) {
 +      weights[i] = edges[i].bweight / 255.0f;
 +    }
 +  }
 +}
 +
 +/** \} */
 +
  /* -------------------------------------------------------------------- */
  /** \name Hide Attribute and Legacy Flag Conversion
   * \{ */
diff --cc source/blender/editors/mesh/mesh_data.cc
index 97671ee5513,e394f8a7251..b6944eccbab
--- a/source/blender/editors/mesh/mesh_data.cc
+++ b/source/blender/editors/mesh/mesh_data.cc
@@@ -628,28 -629,6 +629,28 @@@ static int mesh_customdata_clear_exec__
    return OPERATOR_CANCELLED;
  }
  
 +static int mesh_customdata_add_exec__internal(bContext *C, char htype, int type)
 +{
 +  Mesh *mesh = ED_mesh_context(C);
 +
 +  int tot;
 +  CustomData *data = mesh_customdata_get_type(mesh, htype, &tot);
 +
 +  BLI_assert(CustomData_layertype_is_singleton(type) == true);
 +
 +  if (mesh->edit_mesh) {
 +    BM_data_layer_add(mesh->edit_mesh->bm, data, type);
 +  }
 +  else {
-     CustomData_add_layer(data, type, CD_CALLOC, NULL, tot);
++    CustomData_add_layer(data, type, CD_SET_DEFAULT, NULL, tot);
 +  }
 +
 +  DEG_id_tag_update(&mesh->id, 0);
 +  WM_event_add_notifier(C, NC_GEOM | ND_DATA, mesh);
 +
 +  return CustomData_has_layer(data, type) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
 +}
 +
  /* Clear Mask */
  static bool mesh_customdata_mask_clear_poll(bContext *C)
  {
diff --cc source/blender/makesrna/intern/rna_mesh.c
index eaf9e9aa185,6979b65cfc9..24210601b92
--- a/source/blender/makesrna/intern/rna_mesh.c
+++ b/source/blender/makesrna/intern/rna_mesh.c
@@@ -438,34 -430,26 +438,36 @@@ static void rna_MeshVertex_hide_set(Poi
  
  static float rna_MeshVertex_bevel_weight_get(PointerRNA *ptr)
  {
 -  MVert *mvert = (MVert *)ptr->data;
 -  return mvert->bweight / 255.0f;
 +  const Mesh *mesh = rna_mesh(ptr);
 +  const int index = rna_MeshVertex_index_get(ptr);
-   const float *values = CustomData_get_layer(&mesh->vdata, CD_BWEIGHT);
++  const float *values = (const float *)CustomData_get_layer(&mesh->vdata, CD_BWEIGHT);
 +  return values == NULL ? 0.0f : values[index];
  }
  
  static void rna_MeshVertex_bevel_weight_set(PointerRNA *ptr, float value)
  {
 -  MVert *mvert = (MVert *)ptr->data;
 -  mvert->bweight = round_fl_to_uchar_clamp(value * 255.0f);
 +  Mesh *mesh = rna_mesh(ptr);
 +  const int index = rna_MeshVertex_index_get(ptr);
-   float *values = CustomData_add_layer(&mesh->vdata, CD_BWEIGHT, CD_CALLOC, NULL, mesh->totvert);
++  float *values = (float *)CustomData_add_layer(
++      &mesh->vdata, CD_BWEIGHT, CD_SET_DEFAULT, NULL, mesh->totvert);
 +  values[index] = clamp_f(value, 0.0f, 1.0f);
  }
  
  static float rna_MEdge_bevel_weight_get(PointerRNA *ptr)
  {
 -  MEdge *medge = (MEdge *)ptr->data;
 -  return medge->bweight / 255.0f;
 +  const Mesh *mesh = rna_mesh(ptr);
 +  const int index = rna_MeshEdge_index_get(ptr);
-   const float *values = CustomData_get_layer(&mesh->edata, CD_BWEIGHT);
++  const float *values = (const float *)CustomData_get_layer(&mesh->edata, CD_BWEIGHT);
 +  return values == NULL ? 0.0f : values[index];
  }
  
  static void rna_MEdge_bevel_weight_set(PointerRNA *ptr, float value)
  {
 -  MEdge *medge = (MEdge *)ptr->data;
 -  medge->bweight = round_fl_to_uchar_clamp(value * 255.0f);
 +  Mesh *mesh = rna_mesh(ptr);
 +  const int index = rna_MeshEdge_index_get(ptr);
-   float *values = CustomData_add_layer(&mesh->edata, CD_BWEIGHT, CD_CALLOC, NULL, mesh->totedge);
++  float *values = (float *)CustomData_add_layer(
++      &mesh->edata, CD_BWEIGHT, CD_SET_DEFAULT, NULL, mesh->totedge);
 +  values[index] = clamp_f(value, 0.0f, 1.0f);
  }
  
  static float rna_MEdge_crease_get(PointerRNA *ptr)
diff --cc source/blender/modifiers/intern/MOD_solidify_extrude.c
index 2247a6331fe,aa8c49ee0b8..f679769779b
--- a/source/blender/modifiers/intern/MOD_solidify_extrude.c
+++ b/source/blender/modifiers/intern/MOD_solidify_extrude.c
@@@ -400,12 -405,6 +400,12 @@@ Mesh *MOD_solidify_extrude_modifyMesh(M
      CustomData_copy_data(&mesh->pdata, &result->pdata, 0, 0, (int)polys_num);
    }
  
 +  float *result_edge_bweight = NULL;
 +  if (do_bevel_convex) {
 +    result_edge_bweight = CustomData_add_layer(
-         &result->edata, CD_BWEIGHT, CD_CALLOC, NULL, result->totedge);
++        &result->edata, CD_BWEIGHT, CD_SET_DEFAULT, NULL, result->totedge);
 +  }
 +
    /* initializes: (i_end, do_shell_align, mv). */
  #define INIT_VERT_ARRAY_OFFSETS(test) \
    if (((ofs_new >= ofs_orig) == do_flip) == test) { \
diff --cc source/blender/modifiers/intern/MOD_solidify_nonmanifold.c
index 211c96ae8eb,29adbd70198..aa871e60bd8
--- a/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c
+++ b/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c
@@@ -1973,10 -1969,9 +1973,10 @@@ Mesh *MOD_solidify_nonmanifold_modifyMe
    int *origindex_edge = CustomData_get_layer(&result->edata, CD_ORIGINDEX);
    int *origindex_poly = CustomData_get_layer(&result->pdata, CD_ORIGINDEX);
  
 -  if (bevel_convex != 0.0f || (result->cd_flag & ME_CDFLAG_VERT_BWEIGHT) != 0) {
 -    /* make sure bweight is enabled */
 -    result->cd_flag |= ME_CDFLAG_EDGE_BWEIGHT;
 +  float *result_edge_bweight = CustomData_get_layer(&result->edata, CD_BWEIGHT);
 +  if (bevel_convex != 0.0f || orig_vert_bweight != NULL) {
 +    result_edge_bweight = CustomData_add_layer(
-         &result->edata, CD_BWEIGHT, CD_CALLOC, NULL, result->totedge);
++        &result->edata, CD_BWEIGHT, CD_SET_DEFAULT, NULL, result->totedge);
    }
  
    /* Checks that result has dvert data. */



More information about the Bf-blender-cvs mailing list