[Bf-blender-cvs] [5359430b240] refactor-mesh-uv-map-generic: Merge branch 'master' into refactor-mesh-uv-map-generic

Martijn Versteegh noreply at git.blender.org
Thu Dec 22 15:14:35 CET 2022


Commit: 5359430b240609e7a15a907653ff2b2dd4ed0445
Author: Martijn Versteegh
Date:   Thu Dec 22 13:10:04 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB5359430b240609e7a15a907653ff2b2dd4ed0445

Merge branch 'master' into refactor-mesh-uv-map-generic

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



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

diff --cc source/blender/blenkernel/BKE_mesh_tangent.h
index 28c54ccbc02,b018ab978b2..4a152e2b3a7
--- a/source/blender/blenkernel/BKE_mesh_tangent.h
+++ b/source/blender/blenkernel/BKE_mesh_tangent.h
@@@ -21,8 -21,8 +21,8 @@@ void BKE_mesh_calc_loop_tangent_single_
                                            int numVerts,
                                            const struct MLoop *mloops,
                                            float (*r_looptangent)[4],
-                                           const float (*loopnors)[3],
+                                           const float (*loop_normals)[3],
 -                                          const struct MLoopUV *loopuv,
 +                                          const float (*loopuv)[2],
                                            int numLoops,
                                            const struct MPoly *mpolys,
                                            int numPolys,
diff --cc source/blender/blenkernel/intern/attribute.cc
index 966a3b82385,58990c5c024..b6cce7b8fde
--- a/source/blender/blenkernel/intern/attribute.cc
+++ b/source/blender/blenkernel/intern/attribute.cc
@@@ -168,23 -168,12 +168,29 @@@ bool BKE_id_attribute_rename(ID *id
    char result_name[MAX_CUSTOMDATA_LAYER_NAME];
    BKE_id_attribute_calc_unique_name(id, new_name, result_name);
  
 +  if (layer->type == CD_PROP_FLOAT2) {
 +    /* Rename UV sub-attributes. */
 +    char buffer_src[MAX_CUSTOMDATA_LAYER_NAME];
 +    char buffer_dst[MAX_CUSTOMDATA_LAYER_NAME];
 +    BKE_id_attribute_rename(id,
 +                            BKE_get_uv_map_vert_selection_name(layer->name, buffer_src),
 +                            BKE_get_uv_map_vert_selection_name(result_name, buffer_dst),
 +                            reports);
 +    BKE_id_attribute_rename(id,
 +                            BKE_get_uv_map_edge_selection_name(layer->name, buffer_src),
 +                            BKE_get_uv_map_edge_selection_name(result_name, buffer_dst),
 +                            reports);
 +    BKE_id_attribute_rename(id,
 +                            BKE_get_uv_map_pin_name(layer->name, buffer_src),
 +                            BKE_get_uv_map_pin_name(result_name, buffer_dst),
 +                            reports);
 +  }
+   if (StringRef(old_name) == BKE_id_attributes_active_color_name(id)) {
+     BKE_id_attributes_active_color_set(id, result_name);
+   }
+   if (StringRef(old_name) == BKE_id_attributes_default_color_name(id)) {
+     BKE_id_attributes_default_color_set(id, result_name);
+   }
  
    BLI_strncpy_utf8(layer->name, result_name, sizeof(layer->name));
  
diff --cc source/blender/blenkernel/intern/mesh_convert.cc
index fdd2ecc5d5a,8354de20e20..f0dfda49bc3
--- a/source/blender/blenkernel/intern/mesh_convert.cc
+++ b/source/blender/blenkernel/intern/mesh_convert.cc
@@@ -198,8 -200,8 +200,8 @@@ static Mesh *mesh_nurbs_displist_to_mes
    MutableAttributeAccessor attributes = mesh->attributes_for_write();
    SpanAttributeWriter<int> material_indices = attributes.lookup_or_add_for_write_only_span<int>(
        "material_index", ATTR_DOMAIN_FACE);
 -  MLoopUV *mloopuv = static_cast<MLoopUV *>(CustomData_add_layer_named(
 -      &mesh->ldata, CD_MLOOPUV, CD_SET_DEFAULT, nullptr, mesh->totloop, DATA_("UVMap")));
 +  blender::float2 *mloopuv = static_cast<blender::float2 *>(CustomData_add_layer_named(
-       &mesh->ldata, CD_PROP_FLOAT2, CD_SET_DEFAULT, nullptr, mesh->totloop, "UVMap"));
++      &mesh->ldata, CD_PROP_FLOAT2, CD_SET_DEFAULT, nullptr, mesh->totloop, DATA_("UVMap")));
  
    /* verts and faces */
    vertcount = 0;
diff --cc source/blender/blenkernel/intern/mesh_tangent.cc
index 3e24cc9e39b,8534a68cca4..7c20ae8545e
--- a/source/blender/blenkernel/intern/mesh_tangent.cc
+++ b/source/blender/blenkernel/intern/mesh_tangent.cc
@@@ -70,22 -67,22 +70,22 @@@ struct BKEMeshToTangent 
      copy_v4_fl4(p_res, T.x, T.y, T.z, orientation ? 1.0f : -1.0f);
    }
  
-   const MPoly *mpolys;     /* faces */
-   const MLoop *mloops;     /* faces vertices */
-   const MVert *mverts;     /* vertices */
-   const float2 *luvs;      /* texture coordinates */
-   const float (*lnors)[3]; /* loops' normals */
-   float (*tangents)[4];    /* output tangents */
-   int num_polys;           /* number of polygons */
+   const MPoly *mpolys;            /* faces */
+   const MLoop *mloops;            /* faces vertices */
+   const MVert *mverts;            /* vertices */
 -  const MLoopUV *luvs;            /* texture coordinates */
++  const float (*luvs)[2];         /* texture coordinates */
+   const float (*loop_normals)[3]; /* loops' normals */
+   float (*tangents)[4];           /* output tangents */
+   int num_polys;                  /* number of polygons */
  };
  
  void BKE_mesh_calc_loop_tangent_single_ex(const MVert *mverts,
                                            const int /*numVerts*/,
                                            const MLoop *mloops,
                                            float (*r_looptangent)[4],
-                                           const float (*loopnors)[3],
-                                           const float (*loopuvs)[2],
-                                           const int UNUSED(numLoops),
+                                           const float (*loop_normals)[3],
 -                                          const MLoopUV *loopuvs,
++                                          const float (*loop_uvs)[2],
+                                           const int /*numLoops*/,
                                            const MPoly *mpolys,
                                            const int numPolys,
                                            ReportList *reports)
@@@ -95,8 -92,8 +95,8 @@@
    mesh_to_tangent.mpolys = mpolys;
    mesh_to_tangent.mloops = mloops;
    mesh_to_tangent.mverts = mverts;
-   mesh_to_tangent.luvs = reinterpret_cast<const float2 *>(loopuvs);
-   mesh_to_tangent.lnors = loopnors;
 -  mesh_to_tangent.luvs = loopuvs;
++  mesh_to_tangent.luvs = loop_uvs;
+   mesh_to_tangent.loop_normals = loop_normals;
    mesh_to_tangent.tangents = r_looptangent;
    mesh_to_tangent.num_polys = numPolys;
  
@@@ -148,8 -145,8 +148,8 @@@ void BKE_mesh_calc_loop_tangent_single(
                                         mesh->totvert,
                                         BKE_mesh_loops(mesh),
                                         r_looptangents,
-                                        loopnors,
+                                        loop_normals,
 -                                       loopuvs,
 +                                       reinterpret_cast<const float(*)[2]>(uv_map.data()),
                                         mesh->totloop,
                                         BKE_mesh_polys(mesh),
                                         mesh->totpoly,
diff --cc source/blender/editors/include/ED_mesh.h
index b53709932e8,59f348f6d8a..2bb816f4f84
--- a/source/blender/editors/include/ED_mesh.h
+++ b/source/blender/editors/include/ED_mesh.h
@@@ -564,7 -557,9 +564,10 @@@ bool ED_mesh_edge_is_loose(const struc
  void ED_mesh_uv_ensure(struct Mesh *me, const char *name);
  int ED_mesh_uv_add(
      struct Mesh *me, const char *name, bool active_set, bool do_init, struct ReportList *reports);
+ bool ED_mesh_uv_remove_index(struct Mesh *me, int n);
+ bool ED_mesh_uv_remove_active(struct Mesh *me);
+ bool ED_mesh_uv_remove_named(struct Mesh *me, const char *name);
 +
  void ED_mesh_uv_loop_reset(struct bContext *C, struct Mesh *me);
  /**
   * Without a #bContext, called when UV-editing.
diff --cc source/blender/editors/mesh/mesh_data.cc
index 3fd74c6bae1,a2310dddc61..2cf13dd73d8
--- a/source/blender/editors/mesh/mesh_data.cc
+++ b/source/blender/editors/mesh/mesh_data.cc
@@@ -112,7 -110,33 +113,34 @@@ static CustomData *mesh_customdata_get_
  }
  
  #define GET_CD_DATA(me, data) ((me)->edit_mesh ? &(me)->edit_mesh->bm->data : &(me)->data)
+ static void delete_customdata_layer(Mesh *me, CustomDataLayer *layer)
+ {
+   const int type = layer->type;
+   CustomData *data;
+   int layer_index, tot, n;
+ 
+   char htype = BM_FACE;
+   if (ELEM(type, CD_PROP_BYTE_COLOR, CD_MLOOPUV)) {
+     htype = BM_LOOP;
+   }
+   else if (ELEM(type, CD_PROP_COLOR)) {
+     htype = BM_VERT;
+   }
+ 
+   data = mesh_customdata_get_type(me, htype, &tot);
+   layer_index = CustomData_get_layer_index(data, type);
+   n = (layer - &data->layers[layer_index]);
+   BLI_assert(n >= 0 && (n + layer_index) < data->totlayer);
+ 
+   if (me->edit_mesh) {
+     BM_data_layer_free_n(me->edit_mesh->bm, data, type, n);
+   }
+   else {
+     CustomData_free_layer(data, type, tot, layer_index + n);
+   }
+ }
+ 
 +
  static void mesh_uv_reset_array(float **fuv, const int len)
  {
    if (len == 3) {
@@@ -384,54 -337,81 +412,81 @@@ void ED_mesh_uv_ensure(Mesh *me, const 
    }
  }
  
- int ED_mesh_color_add(Mesh *me,
-                       const char *name,
-                       const bool active_set,
-                       const bool do_init,
-                       ReportList * /*reports*/)
+ bool ED_mesh_uv_remove_index(Mesh *me, const int n)
  {
-   /* NOTE: keep in sync with #ED_mesh_uv_add. */
+   CustomData *ldata = GET_CD_DATA(me, ldata);
+   CustomDataLayer *cdlu;
+   int index;
  
-   BMEditMesh *em;
-   int layernum;
 -  index = CustomData_get_layer_index_n(ldata, CD_MLOOPUV, n);
++  index = CustomData_get_layer_index_n(ldata, CD_PROP_FLOAT2, n);
+   cdlu = (index == -1) ? nullptr : &ldata->layers[index];
  
-   if (me->edit_mesh) {
-     em = me->edit_mesh;
+   if (!cdlu) {
+     return false;
+   }
  
-     layernum = CustomData_number_of_layers(&em->bm->ldata, CD_PROP_BYTE_COLOR);
+   delete_customdata_layer(me, cdlu);
  
-     /* CD_PROP_BYTE_COLOR */
-     BM_data_layer_add_named(em->bm, &em->bm->ldata, CD_PROP_BYTE_COLOR, name);
-     /* copy data from active vertex color layer */
-     if (layernum && do_init) {
-       const int layernum_dst = CustomData_get_active_layer(&em->bm->ldata, CD_PROP_BYTE_COLOR);
-       BM_data_layer_copy(em->bm, &em->bm->ldata, CD_PROP_BYTE_COLOR, layernum_dst, layernum);
-     }
-     if (active_set || layernum == 0) {
-       CustomData_set_layer_active(&em->bm->ldata, C

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list