[Bf-blender-cvs] [6f740256b8c] refactor-mesh-uv-map-generic: Fix reading and writing, other fixes and cleanups

Hans Goudey noreply at git.blender.org
Fri Aug 26 17:53:44 CEST 2022


Commit: 6f740256b8cf2af41ccb93a0b70bbe60c35eb9d2
Author: Hans Goudey
Date:   Fri Aug 26 10:53:36 2022 -0500
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB6f740256b8cf2af41ccb93a0b70bbe60c35eb9d2

Fix reading and writing, other fixes and cleanups

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

M	source/blender/blenkernel/BKE_mesh_legacy_convert.h
M	source/blender/blenkernel/intern/attribute.cc
M	source/blender/blenkernel/intern/customdata.cc
M	source/blender/blenkernel/intern/mesh_legacy_convert.cc
M	source/blender/editors/sculpt_paint/sculpt_uv.c
M	source/blender/editors/uvedit/uvedit_ops.c
M	source/blender/editors/uvedit/uvedit_path.c
M	source/blender/editors/uvedit/uvedit_rip.c
M	source/blender/editors/uvedit/uvedit_select.c
M	source/blender/editors/uvedit/uvedit_smart_stitch.c
M	source/blender/editors/uvedit/uvedit_unwrap_ops.c
M	source/blender/gpu/intern/gpu_buffers.c
M	source/blender/io/usd/intern/usd_writer_mesh.cc
M	source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc

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

diff --git a/source/blender/blenkernel/BKE_mesh_legacy_convert.h b/source/blender/blenkernel/BKE_mesh_legacy_convert.h
index 2d4664bf278..841d7f113aa 100644
--- a/source/blender/blenkernel/BKE_mesh_legacy_convert.h
+++ b/source/blender/blenkernel/BKE_mesh_legacy_convert.h
@@ -29,7 +29,7 @@ struct MFace;
 
 #ifdef __cplusplus
 
-void BKE_mesh_legacy_convert_uvs_to_struct(const Mesh *mesh,
+void BKE_mesh_legacy_convert_uvs_to_struct(Mesh *mesh,
                                            blender::ResourceScope &temp_mloopuv_for_convert,
                                            blender::Vector<CustomDataLayer, 16> &layers_to_write);
 void BKE_mesh_legacy_convert_uvs_to_generic(Mesh *mesh);
diff --git a/source/blender/blenkernel/intern/attribute.cc b/source/blender/blenkernel/intern/attribute.cc
index ebd335fc68a..94f34617822 100644
--- a/source/blender/blenkernel/intern/attribute.cc
+++ b/source/blender/blenkernel/intern/attribute.cc
@@ -166,25 +166,22 @@ 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) {
-    /* Scan for and rename uv sublayers layers. */
-    std::string old_vertsel_layer_name = uv_sublayer_name_vert_selection(layer->name);
-    std::string old_edgesel_layer_name = uv_sublayer_name_edge_selection(layer->name);
-    std::string old_pinned_layer_name = uv_sublayer_name_pin(layer->name);
-
-    std::string new_vertsel_layer_name = uv_sublayer_name_vert_selection(result_name);
-    std::string new_edgesel_layer_name = uv_sublayer_name_edge_selection(result_name);
-    std::string new_pinned_layer_name = uv_sublayer_name_pin(result_name);
-
-    BKE_id_attribute_rename(
-        id, old_vertsel_layer_name.c_str(), new_vertsel_layer_name.c_str(), reports);
-    BKE_id_attribute_rename(
-        id, old_edgesel_layer_name.c_str(), new_edgesel_layer_name.c_str(), reports);
-    BKE_id_attribute_rename(
-        id, old_pinned_layer_name.c_str(), new_pinned_layer_name.c_str(), reports);
+    /* Rename UV sub-attributes. */
+    BKE_id_attribute_rename(id,
+                            uv_sublayer_name_vert_selection(layer->name).c_str(),
+                            uv_sublayer_name_vert_selection(result_name).c_str(),
+                            reports);
+    BKE_id_attribute_rename(id,
+                            uv_sublayer_name_edge_selection(layer->name).c_str(),
+                            uv_sublayer_name_edge_selection(result_name).c_str(),
+                            reports);
+    BKE_id_attribute_rename(id,
+                            uv_sublayer_name_pin(layer->name).c_str(),
+                            uv_sublayer_name_pin(result_name).c_str(),
+                            reports);
   }
 
   BLI_strncpy_utf8(layer->name, result_name, sizeof(layer->name));
@@ -886,8 +883,6 @@ UVMap_Data BKE_id_attributes_create_uvmap_layers(Mesh *mesh,
   data.uv_index = attribute_to_layerindex(
       &mesh->id, uvlayer, ATTR_DOMAIN_MASK_CORNER, CD_MASK_PROP_FLOAT2);
 
-  /* TODO(@Baardaap): martijn still need to handle if one of the names is already taken. */
-
   if (needed_layer_flags & MLOOPUV_VERTSEL) {
     CustomDataLayer *layer = BKE_id_attribute_new(
         &mesh->id,
diff --git a/source/blender/blenkernel/intern/customdata.cc b/source/blender/blenkernel/intern/customdata.cc
index 00544708664..07d4734bc69 100644
--- a/source/blender/blenkernel/intern/customdata.cc
+++ b/source/blender/blenkernel/intern/customdata.cc
@@ -1000,105 +1000,9 @@ static int layerMaxNum_mloopcol()
 /** \} */
 
 /* -------------------------------------------------------------------- */
-/** \name Callbacks for (#MLoopUV, #CD_MLOOPUV)
+/** \name Callbacks for #OrigSpaceLoop
  * \{ */
 
-static void layerCopyValue_mloopuv(const void *source,
-                                   void *dest,
-                                   const int mixmode,
-                                   const float mixfactor)
-{
-  const MLoopUV *luv1 = static_cast<const MLoopUV *>(source);
-  MLoopUV *luv2 = static_cast<MLoopUV *>(dest);
-
-  /* We only support a limited subset of advanced mixing here -
-   * namely the mixfactor interpolation. */
-
-  if (mixmode == CDT_MIX_NOMIX) {
-    copy_v2_v2(luv2->uv, luv1->uv);
-  }
-  else {
-    interp_v2_v2v2(luv2->uv, luv2->uv, luv1->uv, mixfactor);
-  }
-}
-
-static bool layerEqual_mloopuv(const void *data1, const void *data2)
-{
-  const MLoopUV *luv1 = static_cast<const MLoopUV *>(data1);
-  const MLoopUV *luv2 = static_cast<const MLoopUV *>(data2);
-
-  return len_squared_v2v2(luv1->uv, luv2->uv) < 0.00001f;
-}
-
-static void layerMultiply_mloopuv(void *data, const float fac)
-{
-  MLoopUV *luv = static_cast<MLoopUV *>(data);
-
-  mul_v2_fl(luv->uv, fac);
-}
-
-static void layerInitMinMax_mloopuv(void *vmin, void *vmax)
-{
-  MLoopUV *min = static_cast<MLoopUV *>(vmin);
-  MLoopUV *max = static_cast<MLoopUV *>(vmax);
-
-  INIT_MINMAX2(min->uv, max->uv);
-}
-
-static void layerDoMinMax_mloopuv(const void *data, void *vmin, void *vmax)
-{
-  const MLoopUV *luv = static_cast<const MLoopUV *>(data);
-  MLoopUV *min = static_cast<MLoopUV *>(vmin);
-  MLoopUV *max = static_cast<MLoopUV *>(vmax);
-
-  minmax_v2v2_v2(min->uv, max->uv, luv->uv);
-}
-
-static void layerAdd_mloopuv(void *data1, const void *data2)
-{
-  MLoopUV *l1 = static_cast<MLoopUV *>(data1);
-  const MLoopUV *l2 = static_cast<const MLoopUV *>(data2);
-
-  add_v2_v2(l1->uv, l2->uv);
-}
-
-static void layerInterp_mloopuv(const void **sources,
-                                const float *weights,
-                                const float *UNUSED(sub_weights),
-                                int count,
-                                void *dest)
-{
-  float uv[2];
-
-  zero_v2(uv);
-
-  for (int i = 0; i < count; i++) {
-    const float interp_weight = weights[i];
-    const MLoopUV *src = static_cast<const MLoopUV *>(sources[i]);
-    madd_v2_v2fl(uv, src->uv, interp_weight);
-  }
-
-  /* Delay writing to the destination in case dest is in sources. */
-  copy_v2_v2(((MLoopUV *)dest)->uv, uv);
-}
-
-static bool layerValidate_mloopuv(void *data, const uint totitems, const bool do_fixes)
-{
-  MLoopUV *uv = static_cast<MLoopUV *>(data);
-  bool has_errors = false;
-
-  for (int i = 0; i < totitems; i++, uv++) {
-    if (!is_finite_v2(uv->uv)) {
-      if (do_fixes) {
-        zero_v2(uv->uv);
-      }
-      has_errors = true;
-    }
-  }
-
-  return has_errors;
-}
-
 /* origspace is almost exact copy of mloopuv's, keep in sync */
 static void layerCopyValue_mloop_origspace(const void *source,
                                            void *dest,
@@ -1787,26 +1691,7 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
      * change this back to face Texture. */
     {sizeof(int), "", 0, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr},
     /* 16: CD_MLOOPUV */
-    {sizeof(MLoopUV),
-     "MLoopUV",
-     1,
-     N_("UVMap"),
-     nullptr,
-     nullptr,
-     layerInterp_mloopuv,
-     nullptr,
-     nullptr,
-     layerValidate_mloopuv,
-     layerEqual_mloopuv,
-     layerMultiply_mloopuv,
-     layerInitMinMax_mloopuv,
-     layerAdd_mloopuv,
-     layerDoMinMax_mloopuv,
-     layerCopyValue_mloopuv,
-     nullptr,
-     nullptr,
-     nullptr,
-     layerMaxNum_tface},
+    {sizeof(MLoopUV), "MLoopUV", 1, N_("UVMap")},
     /* 17: CD_PROP_BYTE_COLOR */
     {sizeof(MLoopCol),
      "MLoopCol",
diff --git a/source/blender/blenkernel/intern/mesh_legacy_convert.cc b/source/blender/blenkernel/intern/mesh_legacy_convert.cc
index 21a246ce684..dd5f2eb60f3 100644
--- a/source/blender/blenkernel/intern/mesh_legacy_convert.cc
+++ b/source/blender/blenkernel/intern/mesh_legacy_convert.cc
@@ -974,7 +974,7 @@ void BKE_mesh_legacy_convert_flags_to_hide_layers(Mesh *mesh)
  * \{ */
 
 void BKE_mesh_legacy_convert_uvs_to_struct(
-    const Mesh *mesh,
+    Mesh *mesh,
     blender::ResourceScope &temp_mloopuv_for_convert,
     Vector<CustomDataLayer, 16> &face_corner_layers_to_write)
 {
@@ -982,59 +982,60 @@ void BKE_mesh_legacy_convert_uvs_to_struct(
   using namespace blender::bke;
   const AttributeAccessor attributes = mesh_attributes(*mesh);
 
-  Vector<CustomDataLayer> new_layer_to_write;
+  Vector<CustomDataLayer, 16> new_layer_to_write;
 
+  /* Don't write the boolean UV map sublayers which will be written in the legacy #MLoopUV type. */
+  Set<std::string> uv_sublayers_to_skip;
   for (const CustomDataLayer &layer : face_corner_layers_to_write) {
-    if (layer.type == CD_PROP_FLOAT2) {
-      const Span<float2> coords{static_cast<const float2 *>(layer.data), mesh->totloop};
-      CustomDataLayer mloopuv_layer;
-      mloopuv_layer.type = CD_MLOOPUV;
-      STRNCPY(mloopuv_layer.name, layer.name);
-      MutableSpan<MLoopUV> mloopuv = temp_mloopuv_for_convert.construct<Array<MLoopUV>>(
-          mesh->totloop);
-      mloopuv_layer.data = mloopuv.data();
-      mloopuv_layer.flag = layer.flag;
-
-      const VArray<bool> vert_selection = attributes.lookup_or_default<bool>(
-          uv_sublayer_name_vert_selection(layer.name), ATTR_DOMAIN_CORNER, false);
-      const VArray<bool> edge_selection = attributes.lookup_or_default<bool>(
-          uv_sublayer_name_edge_selection(layer.name), ATTR_DOMAIN_CORNER, false);
-      const VArray<bool> pin = attributes.lookup_or_default<bool>(
-          uv_sublayer_name_pin(layer.name), ATTR_DOMAIN_CORNER, false);
-
-      threading::parallel_for(mloopuv.index_range(), 2048, [&](IndexRange range) {
-        for (const int i : range) {
-          copy_v2_v2(mloopuv[i].uv, coords[i]);
-          SET_FLAG_FROM_TEST(mloopuv[i].flag, vert_selection[i], MLOOPUV_VERTSEL);
-          SET_FLAG_FROM_TEST(mloopuv[i].flag, edge_selection[i], MLOOPUV_EDGESEL);
-          SET_FLAG_FROM_TEST(mloopuv[i].flag, pin[i], MLOOPUV_PINNED);
-        }
-      });
-      new_layer_to_write.append(mloopuv_layer);
+    uv_sublayers_to_skip.add_multiple_new({uv_sublayer_name_vert_selection(layer.name),
+                                           uv_sublayer_name_edge_selection(layer.name),
+                                           uv_sublayer_name_pin(layer.name)});
+  }
+
+  for (c

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list