[Bf-blender-cvs] [a42f307915e] master: Shader Nodes: Use layers from evaluated mesh

2023-01-26 Thread Martijn Versteegh
Commit: a42f307915e49500ca7c2e18e2092dcef85f7f6e
Author: Martijn Versteegh
Date:   Mon Jan 23 19:59:46 2023 +0100
Branches: master
https://developer.blender.org/rBa42f307915e49500ca7c2e18e2092dcef85f7f6e

Shader Nodes: Use layers from evaluated mesh

The list was populated from the base (unevaluated) object, but now that
Geometry nodes can generate various layers this is impractical..

Differential Revision: https://developer.blender.org/D17093

===

M   source/blender/nodes/shader/nodes/node_shader_normal_map.cc
M   source/blender/nodes/shader/nodes/node_shader_tangent.cc
M   source/blender/nodes/shader/nodes/node_shader_uvmap.cc
M   source/blender/nodes/shader/nodes/node_shader_vertex_color.cc

===

diff --git a/source/blender/nodes/shader/nodes/node_shader_normal_map.cc 
b/source/blender/nodes/shader/nodes/node_shader_normal_map.cc
index 0bc1318a1f6..a29faff2093 100644
--- a/source/blender/nodes/shader/nodes/node_shader_normal_map.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_normal_map.cc
@@ -6,6 +6,8 @@
 #include "BKE_context.h"
 #include "BKE_node_runtime.hh"
 
+#include "DEG_depsgraph_query.h"
+
 #include "UI_interface.h"
 #include "UI_resources.h"
 
@@ -26,7 +28,11 @@ static void node_shader_buts_normal_map(uiLayout *layout, 
bContext *C, PointerRN
 PointerRNA obptr = CTX_data_pointer_get(C, "active_object");
 
 if (obptr.data && RNA_enum_get(, "type") == OB_MESH) {
-  PointerRNA dataptr = RNA_pointer_get(, "data");
+  PointerRNA eval_obptr;
+
+  Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
+  DEG_get_evaluated_rna_pointer(depsgraph, , _obptr);
+  PointerRNA dataptr = RNA_pointer_get(_obptr, "data");
   uiItemPointerR(layout, ptr, "uv_map", , "uv_layers", "", 
ICON_NONE);
 }
 else {
diff --git a/source/blender/nodes/shader/nodes/node_shader_tangent.cc 
b/source/blender/nodes/shader/nodes/node_shader_tangent.cc
index 9b09eb09bba..cb0c3f34e40 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tangent.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_tangent.cc
@@ -5,6 +5,8 @@
 
 #include "BKE_context.h"
 
+#include "DEG_depsgraph_query.h"
+
 #include "UI_interface.h"
 #include "UI_resources.h"
 
@@ -29,7 +31,11 @@ static void node_shader_buts_tangent(uiLayout *layout, 
bContext *C, PointerRNA *
 PointerRNA obptr = CTX_data_pointer_get(C, "active_object");
 
 if (obptr.data && RNA_enum_get(, "type") == OB_MESH) {
-  PointerRNA dataptr = RNA_pointer_get(, "data");
+  PointerRNA eval_obptr;
+
+  Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
+  DEG_get_evaluated_rna_pointer(depsgraph, , _obptr);
+  PointerRNA dataptr = RNA_pointer_get(_obptr, "data");
   uiItemPointerR(row, ptr, "uv_map", , "uv_layers", "", ICON_NONE);
 }
 else {
diff --git a/source/blender/nodes/shader/nodes/node_shader_uvmap.cc 
b/source/blender/nodes/shader/nodes/node_shader_uvmap.cc
index 483e06f1192..de8221e3e97 100644
--- a/source/blender/nodes/shader/nodes/node_shader_uvmap.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_uvmap.cc
@@ -7,6 +7,8 @@
 
 #include "DNA_customdata_types.h"
 
+#include "DEG_depsgraph_query.h"
+
 #include "UI_interface.h"
 #include "UI_resources.h"
 
@@ -25,7 +27,11 @@ static void node_shader_buts_uvmap(uiLayout *layout, 
bContext *C, PointerRNA *pt
 PointerRNA obptr = CTX_data_pointer_get(C, "active_object");
 
 if (obptr.data && RNA_enum_get(, "type") == OB_MESH) {
-  PointerRNA dataptr = RNA_pointer_get(, "data");
+  PointerRNA eval_obptr;
+
+  Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
+  DEG_get_evaluated_rna_pointer(depsgraph, , _obptr);
+  PointerRNA dataptr = RNA_pointer_get(_obptr, "data");
   uiItemPointerR(layout, ptr, "uv_map", , "uv_layers", "", 
ICON_NONE);
 }
   }
diff --git a/source/blender/nodes/shader/nodes/node_shader_vertex_color.cc 
b/source/blender/nodes/shader/nodes/node_shader_vertex_color.cc
index 8f7e30b99df..0e0f9496851 100644
--- a/source/blender/nodes/shader/nodes/node_shader_vertex_color.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_vertex_color.cc
@@ -5,6 +5,8 @@
 
 #include "BKE_context.h"
 
+#include "DEG_depsgraph_query.h"
+
 #include "UI_interface.h"
 #include "UI_resources.h"
 
@@ -20,8 +22,11 @@ static void node_shader_buts_vertex_color(uiLayout *layout, 
bContext *C, Pointer
 {
   PointerRNA obptr = CTX_dat

[Bf-blender-cvs] [a73a2d345ff] master: Fix T104044: keep order of UVMaps on load

2023-01-24 Thread Martijn Versteegh
Commit: a73a2d345fffa89375e6838405b1e82cac76a8c2
Author: Martijn Versteegh
Date:   Tue Jan 24 11:14:41 2023 +0100
Branches: master
https://developer.blender.org/rBa73a2d345fffa89375e6838405b1e82cac76a8c2

Fix T104044: keep order of UVMaps on load

Use a Vector , instead of a Set as a Set does
not keep the same order when iterating over it.

Differential Revision: https://developer.blender.org/D17103

===

M   source/blender/blenkernel/intern/mesh_legacy_convert.cc

===

diff --git a/source/blender/blenkernel/intern/mesh_legacy_convert.cc 
b/source/blender/blenkernel/intern/mesh_legacy_convert.cc
index be68bfe7c65..a60dfa3a19c 100644
--- a/source/blender/blenkernel/intern/mesh_legacy_convert.cc
+++ b/source/blender/blenkernel/intern/mesh_legacy_convert.cc
@@ -1616,9 +1616,9 @@ void BKE_mesh_legacy_convert_uvs_to_generic(Mesh *mesh)
   const std::string default_uv = StringRef(
   CustomData_get_render_layer_name(>ldata, CD_MLOOPUV));
 
-  Set uv_layers_to_convert;
+  Vector uv_layers_to_convert;
   for (const int uv_layer_i : 
IndexRange(CustomData_number_of_layers(>ldata, CD_MLOOPUV))) {
-uv_layers_to_convert.add_as(CustomData_get_layer_name(>ldata, 
CD_MLOOPUV, uv_layer_i));
+uv_layers_to_convert.append(CustomData_get_layer_name(>ldata, 
CD_MLOOPUV, uv_layer_i));
   }
 
   for (const StringRefNull name : uv_layers_to_convert) {

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [6a22230db4e] master: Fix : accidentally committed typo, roo many closing brackets.

2023-01-20 Thread Martijn Versteegh
Commit: 6a22230db4eee17d36af676f3c8828b8a9316a7e
Author: Martijn Versteegh
Date:   Sat Jan 21 00:22:17 2023 +0100
Branches: master
https://developer.blender.org/rB6a22230db4eee17d36af676f3c8828b8a9316a7e

Fix : accidentally committed typo, roo many closing brackets.

Ooops

===

M   source/blender/makesrna/intern/rna_mesh.c

===

diff --git a/source/blender/makesrna/intern/rna_mesh.c 
b/source/blender/makesrna/intern/rna_mesh.c
index 18f89636f1b..5ab36c1aa7d 100644
--- a/source/blender/makesrna/intern/rna_mesh.c
+++ b/source/blender/makesrna/intern/rna_mesh.c
@@ -2915,7 +2915,7 @@ static void rna_def_mloopuv(BlenderRNA *brna)
 
   prop = RNA_def_property(srna, "uv", PROP_COLLECTION, PROP_NONE);
   RNA_def_property_struct_type(prop, "Float2AttributeValue");
-  RNA_def_property_ui_text(prop, "UV", "UV coordinates on face corners"));
+  RNA_def_property_ui_text(prop, "UV", "UV coordinates on face corners");
   RNA_def_property_collection_funcs(prop,
 "rna_MeshUVLoopLayer_uv_begin",
 "rna_iterator_array_next",

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [a82c12ae32d] master: Add collection properties to MeshUVLoopLayer to access UV and the associated bool attributes (Python API).

2023-01-20 Thread Martijn Versteegh
Commit: a82c12ae32d94e2ec15a5ad81012ab9f93ab2b33
Author: Martijn Versteegh
Date:   Sat Jan 21 00:03:42 2023 +0100
Branches: master
https://developer.blender.org/rBa82c12ae32d94e2ec15a5ad81012ab9f93ab2b33

Add collection properties to MeshUVLoopLayer to access UV and the associated 
bool attributes (Python API).

This adds 4 collection properties to MeshUVLoopLayer to eventually replace the 
(MeshUVLoop) .data property.
The added properties are:

.uv
.vertex_selection
.edge_selection
.pin

The direct access to the separate arrays is much more efficient than the access 
via MeshUVLoop.

Differential Revision: https://developer.blender.org/D16998

===

M   source/blender/makesrna/intern/rna_mesh.c

===

diff --git a/source/blender/makesrna/intern/rna_mesh.c 
b/source/blender/makesrna/intern/rna_mesh.c
index 7c8e7431652..18f89636f1b 100644
--- a/source/blender/makesrna/intern/rna_mesh.c
+++ b/source/blender/makesrna/intern/rna_mesh.c
@@ -986,16 +986,128 @@ static char *rna_MeshUVLoopLayer_path(const PointerRNA 
*ptr)
 
 static void rna_MeshUVLoopLayer_data_begin(CollectionPropertyIterator *iter, 
PointerRNA *ptr)
 {
-  Mesh *me = rna_mesh(ptr);
+  Mesh *mesh = rna_mesh(ptr);
   CustomDataLayer *layer = (CustomDataLayer *)ptr->data;
   rna_iterator_array_begin(
-  iter, layer->data, sizeof(float[2]), (me->edit_mesh) ? 0 : me->totloop, 
0, NULL);
+  iter, layer->data, sizeof(float[2]), (mesh->edit_mesh) ? 0 : 
mesh->totloop, 0, NULL);
 }
 
 static int rna_MeshUVLoopLayer_data_length(PointerRNA *ptr)
+{
+  Mesh *mesh = rna_mesh(ptr);
+  return (mesh->edit_mesh) ? 0 : mesh->totloop;
+}
+
+static MBoolProperty *MeshUVLoopLayer_get_bool_layer(Mesh *mesh, char const 
*name)
+{
+  void *layer = CustomData_get_layer_named_for_write(
+  >ldata, CD_PROP_BOOL, name, mesh->totloop);
+  if (layer == NULL) {
+layer = CustomData_add_layer_named(
+>ldata, CD_PROP_BOOL, CD_SET_DEFAULT, NULL, mesh->totloop, name);
+  }
+
+  BLI_assert(layer);
+
+  return (MBoolProperty *)layer;
+}
+
+static void bool_layer_begin(CollectionPropertyIterator *iter,
+ PointerRNA *ptr,
+ const char *(*layername_func)(const char 
*uv_name, char *name))
+{
+  char bool_layer_name[MAX_CUSTOMDATA_LAYER_NAME];
+  Mesh *mesh = rna_mesh(ptr);
+  CustomDataLayer *layer = (CustomDataLayer *)ptr->data;
+  layername_func(layer->name, bool_layer_name);
+
+  rna_iterator_array_begin(iter,
+   MeshUVLoopLayer_get_bool_layer(mesh, 
bool_layer_name),
+   sizeof(MBoolProperty),
+   (mesh->edit_mesh) ? 0 : mesh->totloop,
+   0,
+   NULL);
+}
+
+static int bool_layer_lookup_int(PointerRNA *ptr,
+ int index,
+ PointerRNA *r_ptr,
+ const char *(*layername_func)(const char 
*uv_name, char *name))
+{
+  char bool_layer_name[MAX_CUSTOMDATA_LAYER_NAME];
+  Mesh *mesh = rna_mesh(ptr);
+  if (mesh->edit_mesh || index < 0 || index >= mesh->totloop) {
+return 0;
+  }
+  CustomDataLayer *layer = (CustomDataLayer *)ptr->data;
+  layername_func(layer->name, bool_layer_name);
+
+  r_ptr->owner_id = >id;
+  r_ptr->type = _BoolAttributeValue;
+  r_ptr->data = MeshUVLoopLayer_get_bool_layer(mesh, bool_layer_name) + index;
+  return 1;
+}
+
+/* Collection accessors for vert_select. */
+static void rna_MeshUVLoopLayer_vert_select_begin(CollectionPropertyIterator 
*iter,
+  PointerRNA *ptr)
+{
+  bool_layer_begin(iter, ptr, BKE_uv_map_vert_select_name_get);
+}
+
+static int rna_MeshUVLoopLayer_vert_select_lookup_int(PointerRNA *ptr,
+  int index,
+  PointerRNA *r_ptr)
+{
+  return bool_layer_lookup_int(ptr, index, r_ptr, 
BKE_uv_map_vert_select_name_get);
+}
+
+/* Collection accessors for edge_select. */
+static void rna_MeshUVLoopLayer_edge_select_begin(CollectionPropertyIterator 
*iter,
+  PointerRNA *ptr)
+{
+  bool_layer_begin(iter, ptr, BKE_uv_map_edge_select_name_get);
+}
+
+static int rna_MeshUVLoopLayer_edge_select_lookup_int(PointerRNA *ptr,
+  int index,
+  PointerRNA *r_ptr)
+{
+  return bool_layer_lookup_int(ptr, index, r_ptr, 
BKE_uv_map_edge_select_name_get);
+}
+
+/* Collection accessors for pin. */
+static void rna_MeshUVLoopLayer_pin_begin(CollectionPropertyIterator *iter, 
PointerRNA *ptr)
+{
+  bool_layer_begin(iter, ptr, BKE_uv_map_pin_name_get);
+}
+
+static int 

[Bf-blender-cvs] [16fc9280689] master: Fix: uninitialized UVs when painting in sculpt mode

2023-01-12 Thread Martijn Versteegh
Commit: 16fc9280689aa5b03ded010e1b6c82334e667094
Author: Martijn Versteegh
Date:   Thu Jan 12 11:37:41 2023 +0100
Branches: master
https://developer.blender.org/rB16fc9280689aa5b03ded010e1b6c82334e667094

Fix: uninitialized UVs when painting in sculpt mode

Because of a mistake in commit 6c774feba2c9 the uv vbo was not
initialized in the pbvh.

===

M   source/blender/draw/intern/draw_pbvh.cc

===

diff --git a/source/blender/draw/intern/draw_pbvh.cc 
b/source/blender/draw/intern/draw_pbvh.cc
index 42e2686df82..964d2190177 100644
--- a/source/blender/draw/intern/draw_pbvh.cc
+++ b/source/blender/draw/intern/draw_pbvh.cc
@@ -721,6 +721,16 @@ struct PBVHBatches {
   });
 }
 break;
+  case CD_PROP_FLOAT2: {
+float2 *mloopuv = static_cast(
+CustomData_get_layer_named(args->ldata, CD_PROP_FLOAT2, 
vbo.name.c_str()));
+
+foreach_faces([&](int /*buffer_i*/, int tri_i, int /*vertex_i*/, const 
MLoopTri *tri) {
+  *static_cast(GPU_vertbuf_raw_step()) = 
mloopuv[tri->tri[tri_i]];
+});
+break;
+  }
+
 }
   }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [6c774feba2c] master: Mesh: Move UV layers to generic attributes

2023-01-09 Thread Martijn Versteegh
Commit: 6c774feba2c9a1eb5834646f597a0f2c63177914
Author: Martijn Versteegh
Date:   Tue Jan 10 00:47:04 2023 -0500
Branches: master
https://developer.blender.org/rB6c774feba2c9a1eb5834646f597a0f2c63177914

Mesh: Move UV layers to generic attributes

Currently the `MLoopUV` struct stores UV coordinates and flags related
to editing UV maps in the UV editor. This patch changes the coordinates
to use the generic 2D vector type, and moves the flags into three
separate boolean attributes. This follows the design in T95965, with
the ultimate intention of simplifying code and improving performance.

Importantly, the change allows exporters and renderers to use UVs
"touched" by geometry nodes, which only creates generic attributes.
It also allows geometry nodes to create "proper" UV maps from scratch,
though only with the Store Named Attribute node for now.

The new design considers any 2D vector attribute on the corner domain
to be a UV map. In the future, they might be distinguished from regular
2D vectors with attribute metadata, which may be helpful because they
are often interpolated differently.

Most of the code changes deal with passing around UV BMesh custom data
offsets and tracking the boolean "sublayers". The boolean layers are
use the following prefixes for attribute names: vert selection: `.vs.`,
edge selection: `.es.`, pinning: `.pn.`. Currently these are short to
avoid using up the maximum length of attribute names. To accommodate
for these 4 extra characters, the name length limit is enlarged to 68
bytes, while the maximum user settable name length is still 64 bytes.

Unfortunately Python/RNA API access to the UV flag data becomes slower.
Accessing the boolean layers directly is be better for performance in
general.

Like the other mesh SoA refactors, backward and forward compatibility
aren't affected, and won't be changed until 4.0. We pay for that by
making mesh reading and writing more expensive with conversions.

Resolves T85962

Differential Revision: https://developer.blender.org/D14365

===

M   release/scripts/startup/bl_ui/properties_data_mesh.py
M   source/blender/blenkernel/BKE_attribute.h
M   source/blender/blenkernel/BKE_customdata.h
M   source/blender/blenkernel/BKE_editmesh_tangent.h
M   source/blender/blenkernel/BKE_mesh.h
M   source/blender/blenkernel/BKE_mesh_legacy_convert.h
M   source/blender/blenkernel/BKE_mesh_mapping.h
M   source/blender/blenkernel/BKE_mesh_tangent.h
M   source/blender/blenkernel/intern/DerivedMesh.cc
M   source/blender/blenkernel/intern/attribute.cc
M   source/blender/blenkernel/intern/attribute_access.cc
M   source/blender/blenkernel/intern/attribute_access_intern.hh
M   source/blender/blenkernel/intern/customdata.cc
M   source/blender/blenkernel/intern/data_transfer.cc
M   source/blender/blenkernel/intern/dynamicpaint.c
M   source/blender/blenkernel/intern/editmesh_tangent.cc
M   source/blender/blenkernel/intern/fluid.c
M   source/blender/blenkernel/intern/geometry_component_mesh.cc
M   source/blender/blenkernel/intern/layer_utils.c
M   source/blender/blenkernel/intern/mesh.cc
M   source/blender/blenkernel/intern/mesh_convert.cc
M   source/blender/blenkernel/intern/mesh_evaluate.cc
M   source/blender/blenkernel/intern/mesh_legacy_convert.cc
M   source/blender/blenkernel/intern/mesh_mapping.cc
M   source/blender/blenkernel/intern/mesh_merge_customdata.cc
M   source/blender/blenkernel/intern/mesh_mirror.cc
M   source/blender/blenkernel/intern/mesh_tangent.cc
M   source/blender/blenkernel/intern/mesh_validate.cc
M   source/blender/blenkernel/intern/object_dupli.cc
M   source/blender/blenkernel/intern/object_update.cc
M   source/blender/blenkernel/intern/paint_canvas.cc
M   source/blender/blenkernel/intern/pbvh_pixels.cc
M   source/blender/blenkernel/intern/pbvh_uv_islands.cc
M   source/blender/blenkernel/intern/pbvh_uv_islands.hh
M   source/blender/blenkernel/intern/subdiv_converter_mesh.c
M   source/blender/blenkernel/intern/subdiv_eval.c
M   source/blender/blenkernel/intern/subdiv_mesh.cc
M   source/blender/blenkernel/intern/subsurf_ccg.c
M   source/blender/blenloader/intern/versioning_280.c
M   source/blender/blenloader/intern/versioning_400.cc
M   source/blender/blenloader/intern/versioning_defaults.cc
M   source/blender/bmesh/bmesh.h
M   source/blender/bmesh/bmesh_class.h
M   source/blender/bmesh/intern/bmesh_interp.c
M   source/blender/bmesh/intern/bmesh_interp.h
M   source/blender/bmesh/intern/bmesh_mesh_convert.cc
M   source/blender/bmesh/intern/bmesh_polygon.c
M   source/blender/bmesh/intern/bmesh_query_uv.cc
M   source/blender/bmesh/intern/bmesh_query_uv.h
M   source/blender/bmesh/operators/bmo_join_triangles.c
M   source/blender/bmesh/operators/bmo_mirror.

[Bf-blender-cvs] [c9daec01f0c] refactor-mesh-uv-map-generic: Incorporated Hans' suggestions to comments.

2023-01-09 Thread Martijn Versteegh
Commit: c9daec01f0ca2712cab4d859f7e55e5693a2d23f
Author: Martijn Versteegh
Date:   Mon Jan 9 19:19:21 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rBc9daec01f0ca2712cab4d859f7e55e5693a2d23f

Incorporated Hans' suggestions to comments.

===

M   source/blender/python/bmesh/bmesh_py_types_meshdata.c

===

diff --git a/source/blender/python/bmesh/bmesh_py_types_meshdata.c 
b/source/blender/python/bmesh/bmesh_py_types_meshdata.c
index 0ae5e04a59e..0136b5703c7 100644
--- a/source/blender/python/bmesh/bmesh_py_types_meshdata.c
+++ b/source/blender/python/bmesh/bmesh_py_types_meshdata.c
@@ -5,15 +5,15 @@
  * \ingroup pybmesh
  *
  * This file defines custom-data types which can't be accessed as primitive
- * python types such as #MDeformVert. It also exposed UV map data in a way
+ * Python types such as #MDeformVert. It also exposed UV map data in a way
  * compatible with the (removed) #MLoopUV type.
  * MLoopUV used to be a struct containing both the UV information and various
- * selection flags. This has since been split up into a float2 attribute layer
- * and three bool attribute layers for the selection/pin states.
- * For backwards compatibility reasons the original #MLoopUV is emulated in the
- * python API, this comes at a performance penalty  however and the plan is
- * to provide direct access to the bool layers for faster access. Eventually
- * (probably in 4.0 ) the MLoopUV should be deprecated on the python side as 
well.
+ * selection flags. This has since been split up into a float2 attribute
+ * and three boolean attributes for the selection/pin states.
+ * For backwards compatibility, the original #MLoopUV is emulated in the
+ * python API. This comes at a performance penalty however, and the plan is
+ * to provide direct access to the boolean layers for faster access. Eventually
+ * (probably in 4.0) #MLoopUV should be removed on the Python side as well.
  */
 
 #include 
@@ -89,7 +89,7 @@ static int bpy_bmloopuv_pin_uv_set(BPy_BMLoopUV *self, 
PyObject *value, void *UN
 {
   /* TODO: if we add lazy allocation of the associated uv map bool layers to 
BMesh we need
* to add a pin layer and update self->pin in the case of self->pin being 
NULL.
-   * This isn't easy to do currently as adding CustomData layers to a bmesh 
invalidates
+   * This isn't easy to do currently as adding CustomData layers to a BMesh 
invalidates
* existing python objects. So for now lazy allocation isn't done and 
self->pin should
* never be NULL. */
   BLI_assert(self->pin);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [4bd776b90f0] refactor-mesh-uv-map-generic: Typo in comment.

2023-01-09 Thread Martijn Versteegh
Commit: 4bd776b90f0de0ad1a3b659326e0c745d2e1ae43
Author: Martijn Versteegh
Date:   Mon Jan 9 19:03:47 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB4bd776b90f0de0ad1a3b659326e0c745d2e1ae43

Typo in comment.

===

M   source/blender/python/bmesh/bmesh_py_types_meshdata.c

===

diff --git a/source/blender/python/bmesh/bmesh_py_types_meshdata.c 
b/source/blender/python/bmesh/bmesh_py_types_meshdata.c
index bffa480f353..0ae5e04a59e 100644
--- a/source/blender/python/bmesh/bmesh_py_types_meshdata.c
+++ b/source/blender/python/bmesh/bmesh_py_types_meshdata.c
@@ -5,7 +5,7 @@
  * \ingroup pybmesh
  *
  * This file defines custom-data types which can't be accessed as primitive
- * python types such as #MDeformVert, It also exposed UV map data in a way
+ * python types such as #MDeformVert. It also exposed UV map data in a way
  * compatible with the (removed) #MLoopUV type.
  * MLoopUV used to be a struct containing both the UV information and various
  * selection flags. This has since been split up into a float2 attribute layer

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [b9d924527e0] refactor-mesh-uv-map-generic: Cleanup: typo in comment

2023-01-09 Thread Martijn Versteegh
Commit: b9d924527e0f50eec7a8a0548eb3253e15a513fe
Author: Martijn Versteegh
Date:   Mon Jan 9 14:26:21 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rBb9d924527e0f50eec7a8a0548eb3253e15a513fe

Cleanup: typo in comment

===

M   source/blender/blenkernel/BKE_customdata.h

===

diff --git a/source/blender/blenkernel/BKE_customdata.h 
b/source/blender/blenkernel/BKE_customdata.h
index 003dca00997..fa18bb8208e 100644
--- a/source/blender/blenkernel/BKE_customdata.h
+++ b/source/blender/blenkernel/BKE_customdata.h
@@ -34,7 +34,7 @@ typedef uint64_t eCustomDataMask;
 /* These names are used as prefixes for UV layer names to find the associated 
bool
  * layers. They should never be longer than 2 chars, as 
MAX_CUSTOMDATA_LAYER_NAME
  * has 4 extra bytes above what can be used for the base layer name, and these
- * prefixes uare placed between 2 '.'s at the start of the layer name.
+ * prefixes are placed between 2 '.'s at the start of the layer name.
  * For example The uv vert selection layer of a layer named 'UVMap.001'
  * will be called '.vs.UVMap.001' . */
 #define UV_VERTSEL_NAME "vs"

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [4fda4d6f1d1] refactor-mesh-uv-map-generic: Fix merge mistake (BLI_math_vector_types.hh rename)

2023-01-09 Thread Martijn Versteegh
Commit: 4fda4d6f1d1ca42c9da737189f0132ab849220a7
Author: Martijn Versteegh
Date:   Mon Jan 9 13:29:32 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB4fda4d6f1d1ca42c9da737189f0132ab849220a7

Fix merge mistake (BLI_math_vector_types.hh rename)

===

M   source/blender/blenkernel/intern/mesh_legacy_convert.cc
M   source/blender/blenkernel/intern/mesh_merge_customdata.cc
M   source/blender/blenkernel/intern/subdiv_mesh.cc
M   
source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_angle.cc
M   
source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_area.cc
M   source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_uv.cc
M   
source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
M   source/blender/io/alembic/intern/abc_customdata.h
M   source/blender/io/collada/GeometryExporter.cpp
M   source/blender/io/usd/intern/usd_writer_mesh.cc

===

diff --git a/source/blender/blenkernel/intern/mesh_legacy_convert.cc 
b/source/blender/blenkernel/intern/mesh_legacy_convert.cc
index dc1a428231e..f31c9e4977e 100644
--- a/source/blender/blenkernel/intern/mesh_legacy_convert.cc
+++ b/source/blender/blenkernel/intern/mesh_legacy_convert.cc
@@ -17,7 +17,7 @@
 
 #include "BLI_edgehash.h"
 #include "BLI_math.h"
-#include "BLI_math_vec_types.hh"
+#include "BLI_math_vector_types.hh"
 #include "BLI_memarena.h"
 #include "BLI_polyfill_2d.h"
 #include "BLI_task.hh"
diff --git a/source/blender/blenkernel/intern/mesh_merge_customdata.cc 
b/source/blender/blenkernel/intern/mesh_merge_customdata.cc
index b78de0da295..9a0fc8b2b82 100644
--- a/source/blender/blenkernel/intern/mesh_merge_customdata.cc
+++ b/source/blender/blenkernel/intern/mesh_merge_customdata.cc
@@ -16,7 +16,7 @@
 #include "BKE_customdata.h"
 #include "BKE_mesh.h"
 #include "BKE_mesh_mapping.h"
-#include "BLI_math_vec_types.hh"
+#include "BLI_math_vector_types.hh"
 #include "BLI_memarena.h"
 
 #include "BLI_strict_flags.h"
diff --git a/source/blender/blenkernel/intern/subdiv_mesh.cc 
b/source/blender/blenkernel/intern/subdiv_mesh.cc
index 55c1400c8bb..8caf0febb93 100644
--- a/source/blender/blenkernel/intern/subdiv_mesh.cc
+++ b/source/blender/blenkernel/intern/subdiv_mesh.cc
@@ -15,7 +15,7 @@
 
 #include "BLI_array.hh"
 #include "BLI_bitmap.h"
-#include "BLI_math_vec_types.hh"
+#include "BLI_math_vector_types.hh"
 #include "BLI_math_vector.h"
 
 #include "BKE_customdata.h"
diff --git 
a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_angle.cc
 
b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_angle.cc
index 191cce03d81..17363ccedd5 100644
--- 
a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_angle.cc
+++ 
b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_angle.cc
@@ -9,7 +9,7 @@
 
 #include "BKE_mesh.h"
 
-#include "BLI_math_vec_types.hh"
+#include "BLI_math_vector_types.hh"
 
 #include "extract_mesh.hh"
 
diff --git 
a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_area.cc
 
b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_area.cc
index 88bad80ea7d..6e515390733 100644
--- 
a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_area.cc
+++ 
b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_area.cc
@@ -5,7 +5,7 @@
  * \ingroup draw
  */
 
-#include "BLI_math_vec_types.hh"
+#include "BLI_math_vector_types.hh"
 
 #include "MEM_guardedalloc.h"
 
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_uv.cc 
b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_uv.cc
index 025de5463e1..54dbfa4fbe1 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_uv.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_uv.cc
@@ -5,7 +5,7 @@
  * \ingroup draw
  */
 
-#include "BLI_math_vec_types.hh"
+#include "BLI_math_vector_types.hh"
 #include "BLI_string.h"
 
 #include "draw_subdivision.h"
diff --git 
a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp 
b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
index 18993d1b375..bc3c5d210b9 100644
--- 
a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
+++ 
b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
@@ -44,7 +44,7 @@
 #include "BLI_ghash.h"
 #include "BLI_listbase.h"
 #incl

[Bf-blender-cvs] [225b2577f7a] refactor-mesh-uv-map-generic: Changed some names and comments as requested in the review. No functional changes

2023-01-09 Thread Martijn Versteegh
Commit: 225b2577f7a5ea496b3b740b4d37a5a6dc891d4e
Author: Martijn Versteegh
Date:   Mon Jan 9 13:10:14 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB225b2577f7a5ea496b3b740b4d37a5a6dc891d4e

Changed some names and comments as requested in the review. No functional 
changes

===

M   source/blender/blenkernel/BKE_attribute.h
M   source/blender/blenkernel/BKE_customdata.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/bmesh/intern/bmesh_interp.c
M   source/blender/bmesh/intern/bmesh_mesh_convert.cc
M   source/blender/bmesh/intern/bmesh_query_uv.cc
M   source/blender/editors/mesh/mesh_data.cc
M   source/blender/editors/object/object_bake_api.c
M   source/blender/makesdna/DNA_customdata_types.h
M   source/blender/makesrna/intern/rna_attribute.c
M   source/blender/makesrna/intern/rna_mesh.c
M   source/blender/makesrna/intern/rna_mesh_api.c
M   source/blender/makesrna/intern/rna_modifier.c
M   source/blender/python/bmesh/bmesh_py_types_meshdata.c

===

diff --git a/source/blender/blenkernel/BKE_attribute.h 
b/source/blender/blenkernel/BKE_attribute.h
index 8fdf3850798..7c01a9205fc 100644
--- a/source/blender/blenkernel/BKE_attribute.h
+++ b/source/blender/blenkernel/BKE_attribute.h
@@ -131,8 +131,8 @@ struct CustomDataLayer *BKE_id_attributes_color_find(const 
struct ID *id, const
 
 bool BKE_id_attribute_calc_unique_name(struct ID *id, const char *name, char 
*outname);
 
-const char *BKE_uv_map_vert_selection_name_get(const char *uv_map_name, char 
*buffer);
-const char *BKE_uv_map_edge_selection_name_get(const char *uv_map_name, char 
*buffer);
+const char *BKE_uv_map_vert_select_name_get(const char *uv_map_name, char 
*buffer);
+const char *BKE_uv_map_edge_select_name_get(const char *uv_map_name, char 
*buffer);
 const char *BKE_uv_map_pin_name_get(const char *uv_map_name, char *buffer);
 
 #ifdef __cplusplus
diff --git a/source/blender/blenkernel/BKE_customdata.h 
b/source/blender/blenkernel/BKE_customdata.h
index 96d5c45e297..003dca00997 100644
--- a/source/blender/blenkernel/BKE_customdata.h
+++ b/source/blender/blenkernel/BKE_customdata.h
@@ -31,6 +31,12 @@ struct CustomData_MeshMasks;
 struct ID;
 typedef uint64_t eCustomDataMask;
 
+/* These names are used as prefixes for UV layer names to find the associated 
bool
+ * layers. They should never be longer than 2 chars, as 
MAX_CUSTOMDATA_LAYER_NAME
+ * has 4 extra bytes above what can be used for the base layer name, and these
+ * prefixes uare placed between 2 '.'s at the start of the layer name.
+ * For example The uv vert selection layer of a layer named 'UVMap.001'
+ * will be called '.vs.UVMap.001' . */
 #define UV_VERTSEL_NAME "vs"
 #define UV_EDGESEL_NAME "es"
 #define UV_PINNED_NAME "pn"
diff --git a/source/blender/blenkernel/intern/attribute.cc 
b/source/blender/blenkernel/intern/attribute.cc
index 183f33c4c81..bb04dccd713 100644
--- a/source/blender/blenkernel/intern/attribute.cc
+++ b/source/blender/blenkernel/intern/attribute.cc
@@ -187,12 +187,12 @@ bool BKE_id_attribute_rename(ID *id,
 char buffer_dst[MAX_CUSTOMDATA_LAYER_NAME];
 
 bke_id_attribute_rename_if_exists(id,
-  
BKE_uv_map_vert_selection_name_get(layer->name, buffer_src),
-  
BKE_uv_map_vert_selection_name_get(result_name, buffer_dst),
+  
BKE_uv_map_vert_select_name_get(layer->name, buffer_src),
+  
BKE_uv_map_vert_select_name_get(result_name, buffer_dst),
   reports);
 bke_id_attribute_rename_if_exists(id,
-  
BKE_uv_map_edge_selection_name_get(layer->name, buffer_src),
-  
BKE_uv_map_edge_selection_name_get(result_name, buffer_dst),
+  
BKE_uv_map_edge_select_name_get(layer->name, buffer_src),
+  
BKE_uv_map_edge_select_name_get(result_name, buffer_dst),
   reports);
 bke_id_attribute_rename_if_exists(id,
   BKE_uv_map_pin_name_get(layer->name, 
buffer_src),
@@ -243,10 +243,10 @@ static bool unique_name_cb(void *arg, const char *name)
 bool BKE_id_attribute_calc_unique_name(ID *id, const char *name, char *outname)
 {
   AttrUniqueData data{id};
-  int maxlength = MAX_CUSTOMDATA_LAYER_NAME_GUI;
+  int maxlength = MAX_CUSTOMDATA_LAYER_NAME_NO_PREFIX;
 
-  if (STREQLEN("." UV_VERTSEL_NAME ".", name, 4) || STREQLEN("." 
UV_EDGESEL_NAME ".&qu

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

2023-01-09 Thread Martijn Versteegh
Commit: 1a5d4296117445ffa6723b2f616512721057e0fc
Author: Martijn Versteegh
Date:   Mon Jan 9 13:13:23 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB1a5d4296117445ffa6723b2f616512721057e0fc

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

===



===

diff --cc source/blender/bmesh/intern/bmesh_query_uv.cc
index e93cace530e,44e49bc8491..d4863ebc29a
--- a/source/blender/bmesh/intern/bmesh_query_uv.cc
+++ b/source/blender/bmesh/intern/bmesh_query_uv.cc
@@@ -9,10 -9,9 +9,10 @@@
  #include "BLI_array.hh"
  #include "BLI_linklist.h"
  #include "BLI_math.h"
- #include "BLI_math_vec_types.hh"
+ #include "BLI_math_vector_types.hh"
  #include "BLI_utildefines_stack.h"
  
 +#include "BKE_attribute.hh"
  #include "BKE_customdata.h"
  
  #include "DNA_meshdata_types.h"

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


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

2023-01-06 Thread Martijn Versteegh
Commit: 1f2ebcc4df1f304e3519e5b89068d78c59ae5ca9
Author: Martijn Versteegh
Date:   Fri Jan 6 15:36:07 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB1f2ebcc4df1f304e3519e5b89068d78c59ae5ca9

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

===



===

diff --cc source/blender/editors/uvedit/uvedit_unwrap_ops.c
index 471eb280ed4,0f8830a4521..97e5cb7dcfa
--- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c
+++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
@@@ -2731,31 -2749,98 +2727,98 @@@ static void uv_map_mirror(BMFace *efa
BMLoop *l;
BMIter liter;
float **uvs = BLI_array_alloca(uvs, efa->len);
-   float dx;
-   int i, mi;
- 
-   const int cd_loop_uv_offset = CustomData_get_offset(>bm->ldata, 
CD_PROP_FLOAT2);
- 
-   BM_ITER_ELEM_INDEX (l, , efa, BM_LOOPS_OF_FACE, i) {
+   int j;
+   BM_ITER_ELEM_INDEX (l, , efa, BM_LOOPS_OF_FACE, j) {
 -MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
 -uvs[j] = luv->uv;
 -if (luv->uv[0] >= 1.0f) {
 -  luv->uv[0] -= 1.0f;
 +float *luv = BM_ELEM_CD_GET_FLOAT_P(l, cd_loop_uv_offset);
- uvs[i] = luv;
++uvs[j] = luv;
++if (luv[0] >= 1.0f) {
++  luv[0] -= 1.0f;
+ }
 -right_u = max_ff(right_u, luv->uv[0]);
++right_u = max_ff(right_u, luv[0]);
}
  
-   mi = 0;
-   for (i = 1; i < efa->len; i++) {
- if (uvs[i][0] > uvs[mi][0]) {
-   mi = i;
+   float left_u = 1.0e30f;
+   BM_ITER_ELEM (l, , efa, BM_LOOPS_OF_FACE) {
 -MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
 -if (right_u <= luv->uv[0] + 0.5f) {
 -  left_u = min_ff(left_u, luv->uv[0]);
++float *luv = BM_ELEM_CD_GET_FLOAT_P(l, cd_loop_uv_offset);
++if (right_u <= luv[0] + 0.5f) {
++  left_u = min_ff(left_u, luv[0]);
  }
}
  
-   for (i = 0; i < efa->len; i++) {
- if (i != mi) {
-   dx = uvs[mi][0] - uvs[i][0];
-   if (dx > 0.5f) {
- uvs[i][0] += 1.0f;
+   BM_ITER_ELEM (l, , efa, BM_LOOPS_OF_FACE) {
 -MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
 -if (luv->uv[0] + 0.5f < right_u) {
 -  if (2 * luv->uv[0] + 1.0f < left_u + right_u) {
 -luv->uv[0] += 1.0f;
++float *luv = BM_ELEM_CD_GET_FLOAT_P(l, cd_loop_uv_offset);
++if (luv[0] + 0.5f < right_u) {
++  if (2 * luv[0] + 1.0f < left_u + right_u) {
++luv[0] += 1.0f;
}
  }
}
+   if (!fan) {
+ return;
+   }
+ 
+   /* Another heuristic, this time, we attempt to "fan"
+* the UVs of faces which pass through one of the poles
+* of the unwrapping. */
+ 
+   /* Need to recompute min and max. */
+   float minmax_u[2] = {1.0e30f, -1.0e30f};
+   int pole_count = 0;
+   for (int i = 0; i < efa->len; i++) {
+ if (regular[i]) {
+   minmax_u[0] = min_ff(minmax_u[0], uvs[i][0]);
+   minmax_u[1] = max_ff(minmax_u[1], uvs[i][0]);
+ }
+ else {
+   pole_count++;
+ }
+   }
+   if (pole_count == 0 || pole_count == efa->len) {
+ return;
+   }
+   for (int i = 0; i < efa->len; i++) {
+ if (regular[i]) {
+   continue;
+ }
+ float u = 0.0f;
+ float sum = 0.0f;
+ const int i_plus = (i + 1) % efa->len;
+ const int i_minus = (i + efa->len - 1) % efa->len;
+ if (regular[i_plus]) {
+   u += uvs[i_plus][0];
+   sum += 1.0f;
+ }
+ if (regular[i_minus]) {
+   u += uvs[i_minus][0];
+   sum += 1.0f;
+ }
+ if (sum == 0) {
+   u += minmax_u[0] + minmax_u[1];
+   sum += 2.0f;
+ }
+ uvs[i][0] = u / sum;
+   }
+ }
+ 
+ static void uv_sphere_project(BMFace *efa,
+   const float center[3],
+   const float rotmat[3][3],
+   const bool fan,
+   const int cd_loop_uv_offset)
+ {
+   bool *regular = BLI_array_alloca(regular, efa->len);
+   int i;
+   BMLoop *l;
+   BMIter iter;
+   BM_ITER_ELEM_INDEX (l, , efa, BM_LOOPS_OF_FACE, i) {
 -MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
++float *luv = BM_ELEM_CD_GET_FLOAT_P(l, cd_loop_uv_offset);
+ float pv[3];
+ sub_v3_v3v3(pv, l->v->co, center);
+ mul_m3_v3(rotmat, pv);
 -regular[i] = map_to_sphere(>uv[0], >uv[1], pv[0], pv[1], pv[2]);
++regular[i] = map_to_sphere([0], [1], pv[0], pv[1], pv[2]);
+   }
+ 
+   uv_map_mirror(efa, regular, fan, cd_loop_uv_offset);
  }
  
  static int sphere_project_exec(bContext *C, wmOperator *op)
@@@ -2789,8 -2873,8 +2851,8 @@@
continue;
  }
  
 -const int cd_loop_uv_offset = CustomData_get_offset(>bm->ldata, 
CD_MLOOPUV);
 +const BMUVOffsets offsets = BM_uv_map_get_offsets(em->bm);
- float center[3], rotmat[4][4];
+ flo

[Bf-blender-cvs] [6a3a1512f44] refactor-mesh-uv-map-generic: Return -1 from failed setter function to indicate an error to python

2023-01-06 Thread Martijn Versteegh
Commit: 6a3a1512f44218bab69e61f0c43de3712223e158
Author: Martijn Versteegh
Date:   Fri Jan 6 15:55:35 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB6a3a1512f44218bab69e61f0c43de3712223e158

Return -1 from failed setter function to indicate an error to python

===

M   source/blender/python/bmesh/bmesh_py_types_meshdata.c

===

diff --git a/source/blender/python/bmesh/bmesh_py_types_meshdata.c 
b/source/blender/python/bmesh/bmesh_py_types_meshdata.c
index 01bc5be1dff..4228d4054e7 100644
--- a/source/blender/python/bmesh/bmesh_py_types_meshdata.c
+++ b/source/blender/python/bmesh/bmesh_py_types_meshdata.c
@@ -97,7 +97,8 @@ static int bpy_bmloopuv_pin_uv_set(BPy_BMLoopUV *self, 
PyObject *value, void *UN
   }
   else {
 PyErr_SetString(PyExc_RuntimeError,
- "active uv layer has no associated pin layer. This is a 
bug!");
+"active uv layer has no associated pin layer. This is a 
bug!");
+return -1;
   }
   return 0;
 }
@@ -116,7 +117,8 @@ static int bpy_bmloopuv_select_set(BPy_BMLoopUV *self, 
PyObject *value, void *UN
   }
   else {
 PyErr_SetString(PyExc_RuntimeError,
- "active uv layer has no associated vertex selection layer. 
This is a bug!");
+"active uv layer has no associated vertex selection layer. 
This is a bug!");
+return -1;
   }
   return 0;
 }
@@ -135,7 +137,8 @@ static int bpy_bmloopuv_select_edge_set(BPy_BMLoopUV *self, 
PyObject *value, voi
   }
   else {
 PyErr_SetString(PyExc_RuntimeError,
- "active uv layer has no associated edge selection layer. This 
is a bug!");
+"active uv layer has no associated edge selection layer. 
This is a bug!");
+return -1;
   }
   return 0;
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [3d92ce8e244] refactor-mesh-uv-map-generic: Use PyErr_SetString() instead of PyErr_Format()

2023-01-06 Thread Martijn Versteegh
Commit: 3d92ce8e244ad8f3f8a1ececa2f92eccb2c1fb25
Author: Martijn Versteegh
Date:   Fri Jan 6 15:36:36 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB3d92ce8e244ad8f3f8a1ececa2f92eccb2c1fb25

Use PyErr_SetString() instead of PyErr_Format()

===

M   source/blender/python/bmesh/bmesh_py_types_meshdata.c

===

diff --git a/source/blender/python/bmesh/bmesh_py_types_meshdata.c 
b/source/blender/python/bmesh/bmesh_py_types_meshdata.c
index 71d2b996c7d..01bc5be1dff 100644
--- a/source/blender/python/bmesh/bmesh_py_types_meshdata.c
+++ b/source/blender/python/bmesh/bmesh_py_types_meshdata.c
@@ -96,7 +96,7 @@ static int bpy_bmloopuv_pin_uv_set(BPy_BMLoopUV *self, 
PyObject *value, void *UN
 *self->pin = PyC_Long_AsBool(value);
   }
   else {
-PyErr_Format(PyExc_RuntimeError,
+PyErr_SetString(PyExc_RuntimeError,
  "active uv layer has no associated pin layer. This is a 
bug!");
   }
   return 0;
@@ -115,7 +115,7 @@ static int bpy_bmloopuv_select_set(BPy_BMLoopUV *self, 
PyObject *value, void *UN
 *self->vert_select = PyC_Long_AsBool(value);
   }
   else {
-PyErr_Format(PyExc_RuntimeError,
+PyErr_SetString(PyExc_RuntimeError,
  "active uv layer has no associated vertex selection layer. 
This is a bug!");
   }
   return 0;
@@ -134,7 +134,7 @@ static int bpy_bmloopuv_select_edge_set(BPy_BMLoopUV *self, 
PyObject *value, voi
 *self->edge_select = PyC_Long_AsBool(value);
   }
   else {
-PyErr_Format(PyExc_RuntimeError,
+PyErr_SetString(PyExc_RuntimeError,
  "active uv layer has no associated edge selection layer. This 
is a bug!");
   }
   return 0;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [35af41cb496] refactor-mesh-uv-map-generic: Rename some functions to be more in line with the surrounding code

2023-01-06 Thread Martijn Versteegh
Commit: 35af41cb496cdcac7b15dc253f1f64476cdbd0d7
Author: Martijn Versteegh
Date:   Fri Jan 6 15:12:15 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB35af41cb496cdcac7b15dc253f1f64476cdbd0d7

Rename some functions to be more in line with the surrounding code

===

M   source/blender/editors/include/ED_mesh.h
M   source/blender/editors/mesh/mesh_data.cc
M   source/blender/makesrna/intern/rna_mesh.c

===

diff --git a/source/blender/editors/include/ED_mesh.h 
b/source/blender/editors/include/ED_mesh.h
index ff1cdad15d5..fdd0d639883 100644
--- a/source/blender/editors/include/ED_mesh.h
+++ b/source/blender/editors/include/ED_mesh.h
@@ -552,12 +552,12 @@ void ED_mesh_geometry_clear(struct Mesh *mesh);
 
 void ED_mesh_update(struct Mesh *mesh, struct bContext *C, bool calc_edges, 
bool calc_edges_loose);
 
-bool *ED_mesh_uv_map_ensure_vert_select(struct Mesh *mesh, int uv_index);
-bool *ED_mesh_uv_map_ensure_edge_select(struct Mesh *mesh, int uv_index);
-bool *ED_mesh_uv_map_ensure_pin(struct Mesh *mesh, int uv_index);
-const bool *ED_mesh_uv_map_get_vert_select(const struct Mesh *mesh, int 
uv_index);
-const bool *ED_mesh_uv_map_get_edge_select(const struct Mesh *mesh, int 
uv_index);
-const bool *ED_mesh_uv_map_get_pin(const struct Mesh *mesh, int uv_index);
+bool *ED_mesh_uv_map_vert_select_layer_ensure(struct Mesh *mesh, int 
uv_map_index);
+bool *ED_mesh_uv_map_edge_select_layer_ensure(struct Mesh *mesh, int 
uv_map_index);
+bool *ED_mesh_uv_map_pin_layer_ensure(struct Mesh *mesh, int uv_map_index);
+const bool *ED_mesh_uv_map_vert_select_layer_get(const struct Mesh *mesh, int 
uv_map_index);
+const bool *ED_mesh_uv_map_edge_select_layer_get(const struct Mesh *mesh, int 
uv_map_index);
+const bool *ED_mesh_uv_map_pin_layer_get(const struct Mesh *mesh, int 
uv_map_index);
 
 bool ED_mesh_edge_is_loose(const struct Mesh *mesh, int index);
 
diff --git a/source/blender/editors/mesh/mesh_data.cc 
b/source/blender/editors/mesh/mesh_data.cc
index 06f90dbb9be..49d452ebe3c 100644
--- a/source/blender/editors/mesh/mesh_data.cc
+++ b/source/blender/editors/mesh/mesh_data.cc
@@ -333,7 +333,7 @@ static const bool 
*mesh_loop_boolean_custom_data_get_by_name(const Mesh , c
   return static_cast(CustomData_get_layer_named(, 
CD_PROP_BOOL, name));
 }
 
-const bool *ED_mesh_uv_map_get_vert_select(const Mesh *mesh, const int 
uv_index)
+const bool *ED_mesh_uv_map_vert_select_layer_get(const Mesh *mesh, const int 
uv_index)
 {
   using namespace blender::bke;
   char buffer[MAX_CUSTOMDATA_LAYER_NAME];
@@ -343,7 +343,7 @@ const bool *ED_mesh_uv_map_get_vert_select(const Mesh 
*mesh, const int uv_index)
 }
 /* UV map edge selections are stored on face corners (loops) and not on edges
  * because we need selections per face edge, even when the edge is split in UV 
space. */
-const bool *ED_mesh_uv_map_get_edge_select(const Mesh *mesh, const int 
uv_index)
+const bool *ED_mesh_uv_map_edge_select_layer_get(const Mesh *mesh, const int 
uv_index)
 {
   using namespace blender::bke;
   char buffer[MAX_CUSTOMDATA_LAYER_NAME];
@@ -352,7 +352,7 @@ const bool *ED_mesh_uv_map_get_edge_select(const Mesh 
*mesh, const int uv_index)
   *mesh, BKE_uv_map_edge_selection_name_get(uv_name, buffer));
 }
 
-const bool *ED_mesh_uv_map_get_pin(const Mesh *mesh, const int uv_index)
+const bool *ED_mesh_uv_map_pin_layer_get(const Mesh *mesh, const int uv_index)
 {
   using namespace blender::bke;
   char buffer[MAX_CUSTOMDATA_LAYER_NAME];
@@ -372,7 +372,7 @@ static bool *ensure_corner_boolean_attribute(Mesh , 
const blender::StringRe
   return data;
 }
 
-bool *ED_mesh_uv_map_ensure_vert_select(Mesh *mesh, const int uv_index)
+bool *ED_mesh_uv_map_vert_select_layer_ensure(Mesh *mesh, const int uv_index)
 {
   using namespace blender::bke;
   char buffer[MAX_CUSTOMDATA_LAYER_NAME];
@@ -380,7 +380,7 @@ bool *ED_mesh_uv_map_ensure_vert_select(Mesh *mesh, const 
int uv_index)
   return ensure_corner_boolean_attribute(*mesh,
  
BKE_uv_map_vert_selection_name_get(uv_name, buffer));
 }
-bool *ED_mesh_uv_map_ensure_edge_select(Mesh *mesh, const int uv_index)
+bool *ED_mesh_uv_map_edge_select_layer_ensure(Mesh *mesh, const int uv_index)
 {
   using namespace blender::bke;
   char buffer[MAX_CUSTOMDATA_LAYER_NAME];
@@ -388,7 +388,7 @@ bool *ED_mesh_uv_map_ensure_edge_select(Mesh *mesh, const 
int uv_index)
   return ensure_corner_boolean_attribute(*mesh,
  
BKE_uv_map_edge_selection_name_get(uv_name, buffer));
 }
-bool *ED_mesh_uv_map_ensure_pin(Mesh *mesh, const int uv_index)
+bool *ED_mesh_uv_map_pin_layer_ensure(Mesh *mesh, const int uv_index)
 {
   using namespace blender::bke;
   char buffer[MAX_CUSTOMDATA_LAYER_NAME];
diff --git a/source/blender/makesrna/intern/rna_mesh.c 
b/source/blender/makesrna

[Bf-blender-cvs] [ed4c093be5e] refactor-mesh-uv-map-generic: Add some clarifying comments

2023-01-06 Thread Martijn Versteegh
Commit: ed4c093be5e64133676b57b464ba5d9458af7a7a
Author: Martijn Versteegh
Date:   Fri Jan 6 15:12:40 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rBed4c093be5e64133676b57b464ba5d9458af7a7a

Add some clarifying comments

===

M   source/blender/python/bmesh/bmesh_py_types_meshdata.c

===

diff --git a/source/blender/python/bmesh/bmesh_py_types_meshdata.c 
b/source/blender/python/bmesh/bmesh_py_types_meshdata.c
index 21fa551f414..d1134dacc85 100644
--- a/source/blender/python/bmesh/bmesh_py_types_meshdata.c
+++ b/source/blender/python/bmesh/bmesh_py_types_meshdata.c
@@ -6,6 +6,13 @@
  *
  * This file defines custom-data types which can't be accessed as primitive
  * python types such as #MDeformVert and the legacy #MLoopUV type.
+ * MLoopUV used to be a struct containing both the UV information and various
+ * selection flags. This has since been split up into a float2 attribute layer
+ * and three bool attribute layers for the selection/pin states.
+ * For backwards compatibility reasons the original #MLoopUV is emulated in the
+ * python API, this comes at a performance penalty  however and the plan is
+ * to provide direct access to the bool layers for faster access. Eventually
+ * (probably in 4.0 ) the MLoopUV should be deprecated on the python side as 
well.
  */
 
 #include 
@@ -37,6 +44,12 @@
 typedef struct BPy_BMLoopUV {
   PyObject_VAR_HEAD
   float *uv;
+  /* vert_select, edge_select and pin could be NULL, signifying those layers 
don't exist.
+   * Currently those layers are always created on a BMesh because adding 
layers to an existing
+   * BMesh is slow and invalidates existing python objects having pointers 
into the original
+   * datablocks (adding a layer re-generates all blocks). But eventually the 
plan is to lazily
+   * allocate the bool layers 'on demand'. Therefore the code tries to handle 
all cases where
+   * the layers don't exist. */
   bool *vert_select;
   bool *edge_select;
   bool *pin;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [9965e83b506] refactor-mesh-uv-map-generic: Add python exceptions to soem asserts, to make sure there's a warning in release mode.

2023-01-06 Thread Martijn Versteegh
Commit: 9965e83b506dbf737c401201642a1beb0fe9af3b
Author: Martijn Versteegh
Date:   Fri Jan 6 15:13:24 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB9965e83b506dbf737c401201642a1beb0fe9af3b

Add python exceptions to soem asserts, to make sure there's a warning in 
release mode.

===

M   source/blender/python/bmesh/bmesh_py_types_meshdata.c

===

diff --git a/source/blender/python/bmesh/bmesh_py_types_meshdata.c 
b/source/blender/python/bmesh/bmesh_py_types_meshdata.c
index d1134dacc85..71d2b996c7d 100644
--- a/source/blender/python/bmesh/bmesh_py_types_meshdata.c
+++ b/source/blender/python/bmesh/bmesh_py_types_meshdata.c
@@ -83,6 +83,7 @@ static PyObject *bpy_bmloopuv_pin_uv_get(BPy_BMLoopUV *self, 
void *UNUSED(closur
   /* A non existing pin layer means nothing is currently pinned */
   return self->pin ? PyBool_FromLong(*self->pin) : false;
 }
+
 static int bpy_bmloopuv_pin_uv_set(BPy_BMLoopUV *self, PyObject *value, void 
*UNUSED(closure))
 {
   /* TODO: if we add lazy allocation of the associated uv map bool layers to 
BMesh we need
@@ -94,6 +95,10 @@ static int bpy_bmloopuv_pin_uv_set(BPy_BMLoopUV *self, 
PyObject *value, void *UN
   if (self->pin) {
 *self->pin = PyC_Long_AsBool(value);
   }
+  else {
+PyErr_Format(PyExc_RuntimeError,
+ "active uv layer has no associated pin layer. This is a 
bug!");
+  }
   return 0;
 }
 
@@ -109,6 +114,10 @@ static int bpy_bmloopuv_select_set(BPy_BMLoopUV *self, 
PyObject *value, void *UN
   if (self->vert_select) {
 *self->vert_select = PyC_Long_AsBool(value);
   }
+  else {
+PyErr_Format(PyExc_RuntimeError,
+ "active uv layer has no associated vertex selection layer. 
This is a bug!");
+  }
   return 0;
 }
 
@@ -124,6 +133,10 @@ static int bpy_bmloopuv_select_edge_set(BPy_BMLoopUV 
*self, PyObject *value, voi
   if (self->edge_select) {
 *self->edge_select = PyC_Long_AsBool(value);
   }
+  else {
+PyErr_Format(PyExc_RuntimeError,
+ "active uv layer has no associated edge selection layer. This 
is a bug!");
+  }
   return 0;
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [d04eb72625e] refactor-mesh-uv-map-generic: Limit user settable length of layer names to 64 bytes

2023-01-05 Thread Martijn Versteegh
Commit: d04eb72625e2d0fe455deaf3278e9df4bd2dc159
Author: Martijn Versteegh
Date:   Fri Jan 6 00:18:42 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rBd04eb72625e2d0fe455deaf3278e9df4bd2dc159

Limit user settable length of layer names to 64 bytes

===

M   source/blender/editors/object/object_bake_api.c
M   source/blender/makesdna/DNA_customdata_types.h
M   source/blender/makesrna/intern/rna_attribute.c
M   source/blender/makesrna/intern/rna_mesh.c
M   source/blender/makesrna/intern/rna_mesh_api.c
M   source/blender/makesrna/intern/rna_modifier.c

===

diff --git a/source/blender/editors/object/object_bake_api.c 
b/source/blender/editors/object/object_bake_api.c
index 20e9850b387..46d231726b1 100644
--- a/source/blender/editors/object/object_bake_api.c
+++ b/source/blender/editors/object/object_bake_api.c
@@ -2246,7 +2246,7 @@ void OBJECT_OT_bake(wmOperatorType *ot)
   RNA_def_string(ot->srna,
  "uv_layer",
  NULL,
- MAX_CUSTOMDATA_LAYER_NAME,
+ MAX_CUSTOMDATA_LAYER_NAME_GUI,
  "UV Layer",
  "UV layer to override active");
 }
diff --git a/source/blender/makesdna/DNA_customdata_types.h 
b/source/blender/makesdna/DNA_customdata_types.h
index e1d8976b932..7938944b822 100644
--- a/source/blender/makesdna/DNA_customdata_types.h
+++ b/source/blender/makesdna/DNA_customdata_types.h
@@ -56,6 +56,7 @@ typedef struct CustomDataLayer {
 } CustomDataLayer;
 
 #define MAX_CUSTOMDATA_LAYER_NAME 68
+#define MAX_CUSTOMDATA_LAYER_NAME_GUI 64
 
 typedef struct CustomDataExternal {
   /** FILE_MAX. */
diff --git a/source/blender/makesrna/intern/rna_attribute.c 
b/source/blender/makesrna/intern/rna_attribute.c
index 67d0e8adef5..2d7ab4fdd44 100644
--- a/source/blender/makesrna/intern/rna_attribute.c
+++ b/source/blender/makesrna/intern/rna_attribute.c
@@ -1191,7 +1191,7 @@ static void rna_def_attribute_group(BlenderRNA *brna)
   RNA_def_property_update(prop, 0, "rna_AttributeGroup_update_active_color");
 
   prop = RNA_def_property(srna, "default_color_name", PROP_STRING, PROP_NONE);
-  RNA_def_property_string_maxlength(prop, MAX_CUSTOMDATA_LAYER_NAME);
+  RNA_def_property_string_maxlength(prop, MAX_CUSTOMDATA_LAYER_NAME_GUI);
   RNA_def_property_string_funcs(prop,
 "rna_AttributeGroup_default_color_name_get",
 "rna_AttributeGroup_default_color_name_length",
@@ -1202,7 +1202,7 @@ static void rna_def_attribute_group(BlenderRNA *brna)
   "The name of the default color attribute used as a fallback for 
rendering");
 
   prop = RNA_def_property(srna, "active_color_name", PROP_STRING, PROP_NONE);
-  RNA_def_property_string_maxlength(prop, MAX_CUSTOMDATA_LAYER_NAME);
+  RNA_def_property_string_maxlength(prop, MAX_CUSTOMDATA_LAYER_NAME_GUI);
   RNA_def_property_string_funcs(prop,
 "rna_AttributeGroup_active_color_name_get",
 "rna_AttributeGroup_active_color_name_length",
diff --git a/source/blender/makesrna/intern/rna_mesh.c 
b/source/blender/makesrna/intern/rna_mesh.c
index 45c9f583060..3cf59afb251 100644
--- a/source/blender/makesrna/intern/rna_mesh.c
+++ b/source/blender/makesrna/intern/rna_mesh.c
@@ -2739,6 +2739,7 @@ static void rna_def_mloopuv(BlenderRNA *brna)
   prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
   RNA_def_struct_name_property(srna, prop);
   RNA_def_property_string_funcs(prop, NULL, NULL, 
"rna_MeshLoopLayer_name_set");
+  RNA_def_property_string_maxlength(prop, MAX_CUSTOMDATA_LAYER_NAME_GUI);
   RNA_def_property_ui_text(prop, "Name", "Name of UV map");
   RNA_def_property_update(prop, 0, "rna_Mesh_update_data_legacy_deg_tag_all");
 
@@ -2800,6 +2801,7 @@ static void rna_def_mloopcol(BlenderRNA *brna)
   prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
   RNA_def_struct_name_property(srna, prop);
   RNA_def_property_string_funcs(prop, NULL, NULL, 
"rna_MeshLoopLayer_name_set");
+  RNA_def_property_string_maxlength(prop, MAX_CUSTOMDATA_LAYER_NAME_GUI);
   RNA_def_property_ui_text(prop, "Name", "Name of Vertex color layer");
   RNA_def_property_update(prop, 0, "rna_Mesh_update_data_legacy_deg_tag_all");
 
@@ -2860,6 +2862,7 @@ static void rna_def_MPropCol(BlenderRNA *brna)
   prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
   RNA_def_struct_name_property(srna, prop);
   RNA_def_property_string_funcs(prop, NULL, NULL, 
"rna_MeshVertexLayer_name_set");
+  RNA_def_property_string_maxlength(prop, MAX_CUSTOMDATA_LAYER_NAME_GUI);
   RNA_def

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

2023-01-05 Thread Martijn Versteegh
Commit: 46bfbf4bded83cde64ee04ded0c7e336368612b2
Author: Martijn Versteegh
Date:   Fri Jan 6 00:24:39 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB46bfbf4bded83cde64ee04ded0c7e336368612b2

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

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [78151569d06] refactor-mesh-uv-map-generic: Making layernames unique should not let them grow too large.

2023-01-05 Thread Martijn Versteegh
Commit: 78151569d06cf804d471cff7eb9525a63edc8273
Author: Martijn Versteegh
Date:   Fri Jan 6 00:13:56 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB78151569d06cf804d471cff7eb9525a63edc8273

Making layernames unique should not let them grow too large.

The maximum size of the layernames internally now is
MAX_CUSTOMDATA_LAYER_SIZE , but except for layers with prefixes
like the uv map associated bool layers the size should never actually
be larger than MAX_CUSTMDATA_LAYER_NAME_GUI, which is 4 bytes
smaller to leave room for the prefixes.

===

M   source/blender/blenkernel/intern/attribute.cc
M   source/blender/blenkernel/intern/customdata.cc

===

diff --git a/source/blender/blenkernel/intern/attribute.cc 
b/source/blender/blenkernel/intern/attribute.cc
index 8b151e81354..183f33c4c81 100644
--- a/source/blender/blenkernel/intern/attribute.cc
+++ b/source/blender/blenkernel/intern/attribute.cc
@@ -243,18 +243,23 @@ static bool unique_name_cb(void *arg, const char *name)
 bool BKE_id_attribute_calc_unique_name(ID *id, const char *name, char *outname)
 {
   AttrUniqueData data{id};
+  int maxlength = MAX_CUSTOMDATA_LAYER_NAME_GUI;
+
+  if (STREQLEN("." UV_VERTSEL_NAME ".", name, 4) || STREQLEN("." 
UV_EDGESEL_NAME ".", name, 4) ||
+  STREQLEN("." UV_PINNED_NAME ".", name, 4)) {
+maxlength = MAX_CUSTOMDATA_LAYER_NAME;
+  }
 
   /* Set default name if none specified.
* NOTE: We only call IFACE_() if needed to avoid locale lookup overhead. */
   if (!name || name[0] == '\0') {
-BLI_strncpy(outname, IFACE_("Attribute"), MAX_CUSTOMDATA_LAYER_NAME);
+BLI_strncpy(outname, IFACE_("Attribute"), maxlength);
   }
   else {
-BLI_strncpy_utf8(outname, name, MAX_CUSTOMDATA_LAYER_NAME);
+BLI_strncpy_utf8(outname, name, maxlength);
   }
 
-  return BLI_uniquename_cb(
-  unique_name_cb, , nullptr, '.', outname, MAX_CUSTOMDATA_LAYER_NAME);
+  return BLI_uniquename_cb(unique_name_cb, , nullptr, '.', outname, 
maxlength);
 }
 
 CustomDataLayer *BKE_id_attribute_new(
diff --git a/source/blender/blenkernel/intern/customdata.cc 
b/source/blender/blenkernel/intern/customdata.cc
index 0a2839bde32..3c0f434d17d 100644
--- a/source/blender/blenkernel/intern/customdata.cc
+++ b/source/blender/blenkernel/intern/customdata.cc
@@ -4319,14 +4319,21 @@ void CustomData_set_layer_unique_name(CustomData *data, 
const int index)
 return;
   }
 
+  int maxlength = MAX_CUSTOMDATA_LAYER_NAME_GUI;
+
+  if (STREQLEN("." UV_VERTSEL_NAME ".", nlayer->name, 4) ||
+  STREQLEN("." UV_EDGESEL_NAME ".", nlayer->name, 4) ||
+  STREQLEN("." UV_PINNED_NAME ".", nlayer->name, 4)) {
+maxlength = MAX_CUSTOMDATA_LAYER_NAME;
+  }
+
   /* Set default name if none specified. Note we only call DATA_() when
* needed to avoid overhead of locale lookups in the depsgraph. */
   if (nlayer->name[0] == '\0') {
 STRNCPY(nlayer->name, DATA_(typeInfo->defaultname));
   }
 
-  BLI_uniquename_cb(
-  customdata_unique_check, _arg, nullptr, '.', nlayer->name, 
sizeof(nlayer->name));
+  BLI_uniquename_cb(customdata_unique_check, _arg, nullptr, '.', 
nlayer->name, maxlength);
 }
 
 void CustomData_validate_layer_name(const CustomData *data,

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [3e19309596a] refactor-mesh-uv-map-generic: Cleanup: make format

2023-01-05 Thread Martijn Versteegh
Commit: 3e19309596a21ae79fc17104103a65589422f177
Author: Martijn Versteegh
Date:   Fri Jan 6 00:23:58 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB3e19309596a21ae79fc17104103a65589422f177

Cleanup: make format

===

M   source/blender/blenkernel/BKE_mesh_tangent.h

===

diff --git a/source/blender/blenkernel/BKE_mesh_tangent.h 
b/source/blender/blenkernel/BKE_mesh_tangent.h
index 44a0ffb43cd..02e823bd009 100644
--- a/source/blender/blenkernel/BKE_mesh_tangent.h
+++ b/source/blender/blenkernel/BKE_mesh_tangent.h
@@ -79,18 +79,17 @@ void BKE_mesh_add_loop_tangent_named_layer_for_uv(struct 
CustomData *uv_data,
  * Also, we calculate tangent_mask that works as a descriptor of tangents 
state.
  * If tangent_mask has changed, then recalculate tangents.
  */
-void BKE_mesh_calc_loop_tangent_step_0(
-const struct CustomData *loopData,
-bool calc_active_tangent,
-const char (*tangent_names)[MAX_CUSTOMDATA_LAYER_NAME],
-int tangent_names_count,
-bool *rcalc_act,
-bool *rcalc_ren,
-int *ract_uv_n,
-int *rren_uv_n,
-char *ract_uv_name,
-char *rren_uv_name,
-short *rtangent_mask);
+void BKE_mesh_calc_loop_tangent_step_0(const struct CustomData *loopData,
+   bool calc_active_tangent,
+   const char 
(*tangent_names)[MAX_CUSTOMDATA_LAYER_NAME],
+   int tangent_names_count,
+   bool *rcalc_act,
+   bool *rcalc_ren,
+   int *ract_uv_n,
+   int *rren_uv_n,
+   char *ract_uv_name,
+   char *rren_uv_name,
+   short *rtangent_mask);
 
 #ifdef __cplusplus
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [b46a426a017] refactor-mesh-uv-map-generic: Fix incorrect buffer size to hold layer name in attribute lookup

2023-01-05 Thread Martijn Versteegh
Commit: b46a426a017bfc4a77af31d3f5566cbb7a54a12a
Author: Martijn Versteegh
Date:   Fri Jan 6 00:17:11 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rBb46a426a017bfc4a77af31d3f5566cbb7a54a12a

Fix incorrect buffer size to hold layer name in attribute lookup

===

M   source/blender/blenkernel/intern/attribute_access.cc

===

diff --git a/source/blender/blenkernel/intern/attribute_access.cc 
b/source/blender/blenkernel/intern/attribute_access.cc
index 986df7be722..4db8f2953ba 100644
--- a/source/blender/blenkernel/intern/attribute_access.cc
+++ b/source/blender/blenkernel/intern/attribute_access.cc
@@ -221,7 +221,7 @@ static void *add_generic_custom_data_layer(CustomData 
_data,
const AttributeIDRef _id)
 {
   if (!attribute_id.is_anonymous()) {
-char attribute_name_c[MAX_NAME];
+char attribute_name_c[MAX_CUSTOMDATA_LAYER_NAME];
 attribute_id.name().copy(attribute_name_c);
 return CustomData_add_layer_named(
 _data, data_type, alloctype, layer_data, domain_num, 
attribute_name_c);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [b0624f3cc85] refactor-mesh-uv-map-generic: Use MAX_CUSTOMDATA_LAYER_NAME instead of literal 68 in BKE_mesh_tangent.h

2023-01-05 Thread Martijn Versteegh
Commit: b0624f3cc85dfcc22f21e008c9481987b8ebfb8d
Author: Martijn Versteegh
Date:   Fri Jan 6 00:12:30 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rBb0624f3cc85dfcc22f21e008c9481987b8ebfb8d

Use MAX_CUSTOMDATA_LAYER_NAME instead of literal 68 in BKE_mesh_tangent.h

===

M   source/blender/blenkernel/BKE_mesh_tangent.h

===

diff --git a/source/blender/blenkernel/BKE_mesh_tangent.h 
b/source/blender/blenkernel/BKE_mesh_tangent.h
index 4a152e2b3a7..44a0ffb43cd 100644
--- a/source/blender/blenkernel/BKE_mesh_tangent.h
+++ b/source/blender/blenkernel/BKE_mesh_tangent.h
@@ -50,7 +50,7 @@ void BKE_mesh_calc_loop_tangent_ex(const struct MVert *mvert,
 
struct CustomData *loopdata,
bool calc_active_tangent,
-   const char (*tangent_names)[68 
/*MAX_CUSTOMDATA_LAYER_NAME */],
+   const char 
(*tangent_names)[MAX_CUSTOMDATA_LAYER_NAME],
int tangent_names_len,
const float (*vert_normals)[3],
const float (*poly_normals)[3],
@@ -82,7 +82,7 @@ void BKE_mesh_add_loop_tangent_named_layer_for_uv(struct 
CustomData *uv_data,
 void BKE_mesh_calc_loop_tangent_step_0(
 const struct CustomData *loopData,
 bool calc_active_tangent,
-const char (*tangent_names)[68 /* MAX_CUSTOMDATA_LAYER_NAME */],
+const char (*tangent_names)[MAX_CUSTOMDATA_LAYER_NAME],
 int tangent_names_count,
 bool *rcalc_act,
 bool *rcalc_ren,

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [1df6ac5ffb9] refactor-mesh-uv-map-generic: Cleanup: make format

2023-01-05 Thread Martijn Versteegh
Commit: 1df6ac5ffb955c785999879dc7b27b6a8fabdfbb
Author: Martijn Versteegh
Date:   Thu Jan 5 19:49:59 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB1df6ac5ffb955c785999879dc7b27b6a8fabdfbb

Cleanup: make format

===

M   source/blender/bmesh/intern/bmesh_mesh_convert.cc
M   source/blender/editors/mesh/mesh_data.cc
M   source/blender/makesrna/intern/rna_mesh.c
M   source/blender/python/bmesh/bmesh_py_types_meshdata.c

===

diff --git a/source/blender/bmesh/intern/bmesh_mesh_convert.cc 
b/source/blender/bmesh/intern/bmesh_mesh_convert.cc
index a851d7d5efa..231e688508f 100644
--- a/source/blender/bmesh/intern/bmesh_mesh_convert.cc
+++ b/source/blender/bmesh/intern/bmesh_mesh_convert.cc
@@ -151,23 +151,25 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const 
struct BMeshFromMeshPar
 
   blender::Vector temporary_layers_to_delete;
 
-  for (const int layer_index : 
IndexRange(CustomData_number_of_layers(_ldata, CD_PROP_FLOAT2))) {
+  for (const int layer_index :
+   IndexRange(CustomData_number_of_layers(_ldata, CD_PROP_FLOAT2))) {
 char name[MAX_CUSTOMDATA_LAYER_NAME];
-BKE_uv_map_vert_selection_name_get(CustomData_get_layer_name(_ldata, 
CD_PROP_FLOAT2, layer_index),
-   name);
+BKE_uv_map_vert_selection_name_get(
+CustomData_get_layer_name(_ldata, CD_PROP_FLOAT2, layer_index), 
name);
 if (CustomData_get_named_layer_index(_ldata, CD_PROP_BOOL, name) < 0) 
{
   CustomData_add_layer_named(
   _ldata, CD_PROP_BOOL, CD_SET_DEFAULT, nullptr, me->totloop, 
name);
   temporary_layers_to_delete.append(std::string(name));
 }
-BKE_uv_map_edge_selection_name_get(CustomData_get_layer_name(_ldata, 
CD_PROP_FLOAT2, layer_index),
-   name);
+BKE_uv_map_edge_selection_name_get(
+CustomData_get_layer_name(_ldata, CD_PROP_FLOAT2, layer_index), 
name);
 if (CustomData_get_named_layer_index(_ldata, CD_PROP_BOOL, name) < 0) 
{
   CustomData_add_layer_named(
   _ldata, CD_PROP_BOOL, CD_SET_DEFAULT, nullptr, me->totloop, 
name);
   temporary_layers_to_delete.append(std::string(name));
 }
-BKE_uv_map_pin_name_get(CustomData_get_layer_name(_ldata, 
CD_PROP_FLOAT2, layer_index), name);
+BKE_uv_map_pin_name_get(CustomData_get_layer_name(_ldata, 
CD_PROP_FLOAT2, layer_index),
+name);
 if (CustomData_get_named_layer_index(_ldata, CD_PROP_BOOL, name) < 0) 
{
   CustomData_add_layer_named(
   _ldata, CD_PROP_BOOL, CD_SET_DEFAULT, nullptr, me->totloop, 
name);
@@ -985,7 +987,8 @@ void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, 
const struct BMeshToMesh
   me->act_face = -1;
 
   /* Mark UV selection layers which are all false as 'nocopy'. */
-  for (const int layer_index : 
IndexRange(CustomData_number_of_layers(>ldata, CD_PROP_FLOAT2))) {
+  for (const int layer_index :
+   IndexRange(CustomData_number_of_layers(>ldata, CD_PROP_FLOAT2))) {
 char const *layer_name = CustomData_get_layer_name(>ldata, 
CD_PROP_FLOAT2, layer_index);
 char sub_layer_name[MAX_CUSTOMDATA_LAYER_NAME];
 int vertsel_layer_index = CustomData_get_named_layer_index(
diff --git a/source/blender/editors/mesh/mesh_data.cc 
b/source/blender/editors/mesh/mesh_data.cc
index 1adf1354130..cb685baa13d 100644
--- a/source/blender/editors/mesh/mesh_data.cc
+++ b/source/blender/editors/mesh/mesh_data.cc
@@ -328,11 +328,9 @@ int ED_mesh_uv_add(
   return layernum_dst;
 }
 
-static const bool *mesh_loop_boolean_custom_data_get_by_name(const Mesh ,
-const char *name)
+static const bool *mesh_loop_boolean_custom_data_get_by_name(const Mesh , 
const char *name)
 {
-  return static_cast(
-  CustomData_get_layer_named(, CD_PROP_BOOL, name));
+  return static_cast(CustomData_get_layer_named(, 
CD_PROP_BOOL, name));
 }
 
 const bool *ED_mesh_uv_map_get_vert_select(const Mesh *mesh, const int 
uv_index)
@@ -340,7 +338,8 @@ const bool *ED_mesh_uv_map_get_vert_select(const Mesh 
*mesh, const int uv_index)
   using namespace blender::bke;
   char buffer[MAX_CUSTOMDATA_LAYER_NAME];
   const char *uv_name = CustomData_get_layer_name(>ldata, 
CD_PROP_FLOAT2, uv_index);
-  return mesh_loop_boolean_custom_data_get_by_name(*mesh, 
BKE_uv_map_vert_selection_name_get(uv_name, buffer));
+  return mesh_loop_boolean_custom_data_get_by_name(
+  *mesh, BKE_uv_map_vert_selection_name_get(uv_name, buffer));
 }
 /* UV map edge selections are stored on face corners (loops) and not on edges
  * because we need selections per face edge, even when the edge is split in UV 
space. */
@@ -349,7 +348,8 @@ const bool *ED_mesh_uv_map_get_edge_select(const Mesh 
*mesh, const int uv_index)
   using names

[Bf-blender-cvs] [466f4b7b44f] refactor-mesh-uv-map-generic: Add clarifying comment

2023-01-05 Thread Martijn Versteegh
Commit: 466f4b7b44f5c6ddb912e8200edb84dc1988f042
Author: Martijn Versteegh
Date:   Thu Jan 5 20:15:40 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB466f4b7b44f5c6ddb912e8200edb84dc1988f042

Add clarifying comment

===

M   source/blender/makesrna/intern/rna_mesh.c

===

diff --git a/source/blender/makesrna/intern/rna_mesh.c 
b/source/blender/makesrna/intern/rna_mesh.c
index 4a9518aad98..45c9f583060 100644
--- a/source/blender/makesrna/intern/rna_mesh.c
+++ b/source/blender/makesrna/intern/rna_mesh.c
@@ -1798,7 +1798,14 @@ static char *rna_MeshUVLoop_path(const PointerRNA *ptr)
 {
   return rna_LoopCustomData_data_path(ptr, "uv_layers", CD_PROP_FLOAT2);
 }
-
+/* The rna_MeshUVLoop_*_get/set() functions get passed a pointer to
+ * the (float2) uv attribute. This is for historical reasons because
+ * the api used to wrap MLoopUV, which contained the uv and all the selection
+ * pin states in a single struct. But since that struct no longer exists and
+ * we still can use only a single pointer to access these, we need to look up
+ * the original attribute layer and the index of the uv in it to be able to
+ * find the associated bool layers. So we scan the available foat2 layers
+ * to find into which layer the pointer we got passed points. */
 static bool get_uv_index_and_layer(const PointerRNA *ptr,
int *r_uv_layer_index,
int *r_index_in_attribute)

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


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

2023-01-05 Thread Martijn Versteegh
Commit: aae00f624ceadb77e8bd43b0c1871fe6e9c20406
Author: Martijn Versteegh
Date:   Thu Jan 5 19:51:18 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rBaae00f624ceadb77e8bd43b0c1871fe6e9c20406

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

===



===

diff --cc source/blender/makesdna/DNA_customdata_types.h
index 6983af5ab79,0710ed6d30f..e1d8976b932
--- a/source/blender/makesdna/DNA_customdata_types.h
+++ b/source/blender/makesdna/DNA_customdata_types.h
@@@ -41,15 -48,13 +49,13 @@@ typedef struct CustomDataLayer 
/** Layer data. */
void *data;
/**
-* Run-time identifier for this layer. If no one has a strong reference to 
this id anymore,
-* the layer can be removed. The custom data layer only has a weak 
reference to the id, because
-* otherwise there will always be a strong reference and the attribute 
can't be removed
-* automatically.
+* Run-time identifier for this layer. Can be used to retrieve information 
about where this
+* attribute was created.
 */
-   const struct AnonymousAttributeID *anonymous_id;
+   const AnonymousAttributeIDHandle *anonymous_id;
  } CustomDataLayer;
  
 -#define MAX_CUSTOMDATA_LAYER_NAME 64
 +#define MAX_CUSTOMDATA_LAYER_NAME 68
  
  typedef struct CustomDataExternal {
/** FILE_MAX. */

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [4f597024cd4] refactor-mesh-uv-map-generic: Add clarifying comment

2023-01-05 Thread Martijn Versteegh
Commit: 4f597024cd46297ae4d711fba1128551a9fc8614
Author: Martijn Versteegh
Date:   Thu Jan 5 19:48:34 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB4f597024cd46297ae4d711fba1128551a9fc8614

Add clarifying comment

===

M   source/blender/editors/mesh/mesh_data.cc

===

diff --git a/source/blender/editors/mesh/mesh_data.cc 
b/source/blender/editors/mesh/mesh_data.cc
index 84bfad97bfc..1adf1354130 100644
--- a/source/blender/editors/mesh/mesh_data.cc
+++ b/source/blender/editors/mesh/mesh_data.cc
@@ -342,6 +342,8 @@ const bool *ED_mesh_uv_map_get_vert_select(const Mesh 
*mesh, const int uv_index)
   const char *uv_name = CustomData_get_layer_name(>ldata, 
CD_PROP_FLOAT2, uv_index);
   return mesh_loop_boolean_custom_data_get_by_name(*mesh, 
BKE_uv_map_vert_selection_name_get(uv_name, buffer));
 }
+/* UV map edge selections are stored on face corners (loops) and not on edges
+ * because we need selections per face edge, even when the edge is split in UV 
space. */
 const bool *ED_mesh_uv_map_get_edge_select(const Mesh *mesh, const int 
uv_index)
 {
   using namespace blender::bke;
@@ -349,6 +351,7 @@ const bool *ED_mesh_uv_map_get_edge_select(const Mesh 
*mesh, const int uv_index)
   const char *uv_name = CustomData_get_layer_name(>ldata, 
CD_PROP_FLOAT2, uv_index);
   return mesh_loop_boolean_custom_data_get_by_name(*mesh, 
BKE_uv_map_edge_selection_name_get(uv_name, buffer));
 }
+
 const bool *ED_mesh_uv_map_get_pin(const Mesh *mesh, const int uv_index)
 {
   using namespace blender::bke;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [25cc34aa973] refactor-mesh-uv-map-generic: Don't lookup BMLoop in BPy_BMLoopUV functions. Add some TODO comments

2023-01-05 Thread Martijn Versteegh
Commit: 25cc34aa9737ab2c590509ac604b33d5f7696d32
Author: Martijn Versteegh
Date:   Thu Jan 5 17:37:18 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB25cc34aa9737ab2c590509ac604b33d5f7696d32

Don't lookup BMLoop in BPy_BMLoopUV functions. Add some TODO comments

===

M   source/blender/python/bmesh/bmesh_py_types_customdata.c
M   source/blender/python/bmesh/bmesh_py_types_meshdata.c
M   source/blender/python/bmesh/bmesh_py_types_meshdata.h

===

diff --git a/source/blender/python/bmesh/bmesh_py_types_customdata.c 
b/source/blender/python/bmesh/bmesh_py_types_customdata.c
index fd175819731..e1708037095 100644
--- a/source/blender/python/bmesh/bmesh_py_types_customdata.c
+++ b/source/blender/python/bmesh/bmesh_py_types_customdata.c
@@ -1149,7 +1149,7 @@ PyObject *BPy_BMLayerItem_GetItem(BPy_BMElem *py_ele, 
BPy_BMLayerItem *py_layer)
 PyErr_SetString(PyExc_ValueError, "BMElem[layer]: layer is from 
another mesh");
 return NULL;
   }
-  ret = BPy_BMLoopUV_CreatePyObject(py_ele->bm, py_ele->ele->head.index);
+  ret = BPy_BMLoopUV_CreatePyObject(py_ele->bm, (BMLoop *)py_ele->ele);
   break;
 }
 case CD_PROP_BYTE_COLOR: {
@@ -1256,7 +1256,7 @@ int BPy_BMLayerItem_SetItem(BPy_BMElem *py_ele, 
BPy_BMLayerItem *py_layer, PyObj
 ret = -1;
   }
   else {
-ret = BPy_BMLoopUV_AssignPyObject(py_ele->bm, py_ele->ele->head.index, 
py_value);
+ret = BPy_BMLoopUV_AssignPyObject(py_ele->bm, (BMLoop *)py_ele->ele, 
py_value);
   }
   break;
 }
diff --git a/source/blender/python/bmesh/bmesh_py_types_meshdata.c 
b/source/blender/python/bmesh/bmesh_py_types_meshdata.c
index a12ac99ff72..5e0af19ce50 100644
--- a/source/blender/python/bmesh/bmesh_py_types_meshdata.c
+++ b/source/blender/python/bmesh/bmesh_py_types_meshdata.c
@@ -40,6 +40,7 @@ typedef struct BPy_BMLoopUV {
   bool *vert_select;
   bool *edge_select;
   bool *pin;
+  BMLoop *loop;
 } BPy_BMLoopUV;
 
 PyDoc_STRVAR(bpy_bmloopuv_uv_doc,
@@ -71,9 +72,11 @@ static PyObject *bpy_bmloopuv_pin_uv_get(BPy_BMLoopUV *self, 
void *UNUSED(closur
 }
 static int bpy_bmloopuv_pin_uv_set(BPy_BMLoopUV *self, PyObject *value, void 
*UNUSED(closure))
 {
-  /* TODO: if we add lazy allocation of the associated uv map bool layers to 
BMesh there needs to be
-   * an BM_uv_map_ensure_pin_attr() call here. But as currently BMesh will 
always have the
-   * layers and we can't easily get at the layer name here just do an assert */
+  /* TODO: if we add lazy allocation of the associated uv map bool layers to 
BMesh we need
+   * to add a pin layere and update self->pin in the case of self->pin being 
NULL.
+   * This isn't easy to do currently as adding CustomData layers to a bmesh 
invalidates
+   * existing python objects. So for now lazy allocation isn't done and 
self->pin should
+   * never be NULL. */
   BLI_assert(self->pin);
   if (self->pin) {
 *self->pin = PyC_Long_AsBool(value);
@@ -88,9 +91,7 @@ static PyObject *bpy_bmloopuv_select_get(BPy_BMLoopUV *self, 
void *UNUSED(closur
 }
 static int bpy_bmloopuv_select_set(BPy_BMLoopUV *self, PyObject *value, void 
*UNUSED(closure))
 {
-  /* TODO: if we add lazy allocation of the associated uv map bool layers to 
BMesh there needs to be
-   * an BM_uv_map_ensure_vert_select_attr() call here. But as currently BMesh 
will always have the
-   * layers and we can't easily get at the layer name here just do an assert */
+  /* TODO: see comment above on bpy_bmloopuv_pin_uv_set(), the same applies 
here. */
   BLI_assert(self->vert_select);
   if (self->vert_select) {
 *self->vert_select = PyC_Long_AsBool(value);
@@ -105,9 +106,7 @@ static PyObject *bpy_bmloopuv_select_edge_get(BPy_BMLoopUV 
*self, void *UNUSED(c
 }
 static int bpy_bmloopuv_select_edge_set(BPy_BMLoopUV *self, PyObject *value, 
void *UNUSED(closure))
 {
-  /* TODO: if we add lazy allocation of the associated uv map bool layers to 
BMesh there needs to be
-   * an BM_uv_map_ensure_edge_select_attr() call here. But as currently BMesh 
will always have the
-   * layers and we can't easily get at the layer name here just do an assert */
+  /* TODO: see comment above on bpy_bmloopuv_pin_uv_set(), the same applies 
here.  */
   BLI_assert(self->edge_select);
   if (self->edge_select) {
 *self->edge_select = PyC_Long_AsBool(value);
@@ -154,7 +153,7 @@ static void bm_init_types_bmloopuv(void)
   PyType_Ready(_BMLoopUV_Type);
 }
 
-int BPy_BMLoopUV_AssignPyObject(struct BMesh *bm, const int loop_index, 
PyObject *value)
+int BPy_BMLoopUV_AssignPyObject(struct BMesh *bm, BMLoop *loop, PyObject 
*value)
 {
   if (UNLIKELY(!BPy_BMLoopUV_Check(value))) {
 PyErr_Format(PyExc_TypeError, "expected BMLoopUV, not a %.200s", 
Py_TYPE(value)-&g

[Bf-blender-cvs] [5a85bc4f5be] refactor-mesh-uv-map-generic: Add some clarifying comments

2023-01-05 Thread Martijn Versteegh
Commit: 5a85bc4f5bee6f56de3a96c7773e8f658e5db66c
Author: Martijn Versteegh
Date:   Thu Jan 5 16:17:25 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB5a85bc4f5bee6f56de3a96c7773e8f658e5db66c

Add some clarifying comments

===

M   source/blender/python/bmesh/bmesh_py_types_meshdata.c

===

diff --git a/source/blender/python/bmesh/bmesh_py_types_meshdata.c 
b/source/blender/python/bmesh/bmesh_py_types_meshdata.c
index ecfe81c0f43..a12ac99ff72 100644
--- a/source/blender/python/bmesh/bmesh_py_types_meshdata.c
+++ b/source/blender/python/bmesh/bmesh_py_types_meshdata.c
@@ -66,10 +66,14 @@ PyDoc_STRVAR(bpy_bmloopuv_select_edge_doc, "UV edge select 
state.\n\n:type: bool
 
 static PyObject *bpy_bmloopuv_pin_uv_get(BPy_BMLoopUV *self, void 
*UNUSED(closure))
 {
+  /* A non existing pin layer means nothing is currently pinned */
   return self->pin ? PyBool_FromLong(*self->pin) : false;
 }
 static int bpy_bmloopuv_pin_uv_set(BPy_BMLoopUV *self, PyObject *value, void 
*UNUSED(closure))
 {
+  /* TODO: if we add lazy allocation of the associated uv map bool layers to 
BMesh there needs to be
+   * an BM_uv_map_ensure_pin_attr() call here. But as currently BMesh will 
always have the
+   * layers and we can't easily get at the layer name here just do an assert */
   BLI_assert(self->pin);
   if (self->pin) {
 *self->pin = PyC_Long_AsBool(value);
@@ -79,10 +83,14 @@ static int bpy_bmloopuv_pin_uv_set(BPy_BMLoopUV *self, 
PyObject *value, void *UN
 
 static PyObject *bpy_bmloopuv_select_get(BPy_BMLoopUV *self, void 
*UNUSED(closure))
 {
+  /* A non existing vert_select layer means nothing is currently selected */
   return self->vert_select ? PyBool_FromLong(*self->vert_select) : false;
 }
 static int bpy_bmloopuv_select_set(BPy_BMLoopUV *self, PyObject *value, void 
*UNUSED(closure))
 {
+  /* TODO: if we add lazy allocation of the associated uv map bool layers to 
BMesh there needs to be
+   * an BM_uv_map_ensure_vert_select_attr() call here. But as currently BMesh 
will always have the
+   * layers and we can't easily get at the layer name here just do an assert */
   BLI_assert(self->vert_select);
   if (self->vert_select) {
 *self->vert_select = PyC_Long_AsBool(value);
@@ -92,10 +100,14 @@ static int bpy_bmloopuv_select_set(BPy_BMLoopUV *self, 
PyObject *value, void *UN
 
 static PyObject *bpy_bmloopuv_select_edge_get(BPy_BMLoopUV *self, void 
*UNUSED(closure))
 {
+  /* A non existing edge_select layer means nothing is currently selected */
   return self->edge_select ? PyBool_FromLong(*self->edge_select) : false;
 }
 static int bpy_bmloopuv_select_edge_set(BPy_BMLoopUV *self, PyObject *value, 
void *UNUSED(closure))
 {
+  /* TODO: if we add lazy allocation of the associated uv map bool layers to 
BMesh there needs to be
+   * an BM_uv_map_ensure_edge_select_attr() call here. But as currently BMesh 
will always have the
+   * layers and we can't easily get at the layer name here just do an assert */
   BLI_assert(self->edge_select);
   if (self->edge_select) {
 *self->edge_select = PyC_Long_AsBool(value);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [d7cc907a49b] refactor-mesh-uv-map-generic: Fix use-after-free when passing BKE_id_attribute_remove the name owned by the layer itself

2023-01-05 Thread Martijn Versteegh
Commit: d7cc907a49b9f637d59f22bb880b3ffaa0d9cb60
Author: Martijn Versteegh
Date:   Thu Jan 5 15:39:02 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rBd7cc907a49b9f637d59f22bb880b3ffaa0d9cb60

Fix use-after-free when passing BKE_id_attribute_remove the name owned by the 
layer itself

===

M   source/blender/blenkernel/intern/attribute.cc

===

diff --git a/source/blender/blenkernel/intern/attribute.cc 
b/source/blender/blenkernel/intern/attribute.cc
index f03911fbdc0..8b151e81354 100644
--- a/source/blender/blenkernel/intern/attribute.cc
+++ b/source/blender/blenkernel/intern/attribute.cc
@@ -392,11 +392,15 @@ bool BKE_id_attribute_remove(ID *id, const char *name, 
ReportList *reports)
   BM_data_layer_free_named(em->bm, data, 
BKE_uv_map_pin_name_get(name, buffer_src));
 }
   }
+  /* Because it's possible that name is owned by the layer and will be 
freed
+   * when freeing the layer, do these checks before freeing. */
+  const bool is_active_color_attribute = name == 
StringRef(mesh->active_color_attribute);
+  const bool is_default_color_attribute = name == 
StringRef(mesh->default_color_attribute);
   if (BM_data_layer_free_named(em->bm, data, name)) {
-if (name == StringRef(mesh->active_color_attribute)) {
+if (is_active_color_attribute) {
   MEM_SAFE_FREE(mesh->active_color_attribute);
 }
-else if (name == StringRef(mesh->default_color_attribute)) {
+else if (is_default_color_attribute) {
   MEM_SAFE_FREE(mesh->default_color_attribute);
 }
 return true;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [4d5cb09d522] refactor-mesh-uv-map-generic: float (*)[2] -> float2 * in C++

2023-01-05 Thread Martijn Versteegh
Commit: 4d5cb09d522ddbf286845ae329e85daccab4bfce
Author: Martijn Versteegh
Date:   Thu Jan 5 14:49:32 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB4d5cb09d522ddbf286845ae329e85daccab4bfce

float (*)[2] -> float2 * in C++

===

M   source/blender/modifiers/intern/MOD_array.cc

===

diff --git a/source/blender/modifiers/intern/MOD_array.cc 
b/source/blender/modifiers/intern/MOD_array.cc
index 73a6ccec0e0..6018b8afd87 100644
--- a/source/blender/modifiers/intern/MOD_array.cc
+++ b/source/blender/modifiers/intern/MOD_array.cc
@@ -673,7 +673,7 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd,
   if (chunk_nloops > 0 && is_zero_v2(amd->uv_offset) == false) {
 const int totuv = CustomData_number_of_layers(>ldata, 
CD_PROP_FLOAT2);
 for (i = 0; i < totuv; i++) {
-  float(*dmloopuv)[2] = static_cast(
+  blender::float2 *dmloopuv = static_cast(
   CustomData_get_layer_n(>ldata, CD_PROP_FLOAT2, i));
   dmloopuv += chunk_nloops;
   for (c = 1; c < count; c++) {

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [0501acfb508] refactor-mesh-uv-map-generic: Add back python warning on missing UV layer

2023-01-05 Thread Martijn Versteegh
Commit: 0501acfb508b3ce3f800dce0d2c0f59200d378fa
Author: Martijn Versteegh
Date:   Thu Jan 5 14:49:10 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB0501acfb508b3ce3f800dce0d2c0f59200d378fa

Add back python warning on missing UV layer

===

M   source/blender/makesrna/intern/rna_mesh.c

===

diff --git a/source/blender/makesrna/intern/rna_mesh.c 
b/source/blender/makesrna/intern/rna_mesh.c
index 28877c24e74..712d5af7a65 100644
--- a/source/blender/makesrna/intern/rna_mesh.c
+++ b/source/blender/makesrna/intern/rna_mesh.c
@@ -2230,6 +2230,9 @@ static PointerRNA rna_Mesh_uv_layers_new(struct Mesh *me,
 
 static void rna_Mesh_uv_layers_remove(struct Mesh *me, ReportList *reports, 
CustomDataLayer *layer)
 {
+  if (!BKE_id_attribute_find(>id, layer->name, CD_PROP_FLOAT, 
ATTR_DOMAIN_CORNER)) {
+BKE_reportf(reports, RPT_ERROR, "Texture layer '%s' not found", 
layer->name);
+  }
   BKE_id_attribute_remove(>id, layer->name, reports);
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [4287247bce1] refactor-mesh-uv-map-generic: change forgotten CD_MLOOPUV to CD_PROP_FLOAT2

2023-01-05 Thread Martijn Versteegh
Commit: 4287247bce1a5335da63e80261f84b527f136d16
Author: Martijn Versteegh
Date:   Thu Jan 5 14:50:15 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB4287247bce1a5335da63e80261f84b527f136d16

change forgotten CD_MLOOPUV to CD_PROP_FLOAT2

===

M   source/blender/python/bmesh/bmesh_py_types_customdata.c

===

diff --git a/source/blender/python/bmesh/bmesh_py_types_customdata.c 
b/source/blender/python/bmesh/bmesh_py_types_customdata.c
index 894464500fe..fd175819731 100644
--- a/source/blender/python/bmesh/bmesh_py_types_customdata.c
+++ b/source/blender/python/bmesh/bmesh_py_types_customdata.c
@@ -1250,7 +1250,7 @@ int BPy_BMLayerItem_SetItem(BPy_BMElem *py_ele, 
BPy_BMLayerItem *py_layer, PyObj
   }
   break;
 }
-case CD_MLOOPUV: {
+case CD_PROP_FLOAT2: {
   if (UNLIKELY(py_ele->bm != py_layer->bm)) {
 PyErr_SetString(PyExc_ValueError, "BMElem[layer]: layer is from 
another mesh");
 ret = -1;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [b5f4659afa7] refactor-mesh-uv-map-generic: Made some function/variable names longer, others shorter

2023-01-05 Thread Martijn Versteegh
Commit: b5f4659afa7f5adc2f1a92128f99175ba3427157
Author: Martijn Versteegh
Date:   Thu Jan 5 14:48:09 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rBb5f4659afa7f5adc2f1a92128f99175ba3427157

Made some function/variable names longer, others shorter

as requested in the review

===

M   source/blender/bmesh/intern/bmesh_interp.c
M   source/blender/bmesh/intern/bmesh_interp.h
M   source/blender/bmesh/intern/bmesh_mesh_convert.cc
M   source/blender/editors/include/ED_mesh.h
M   source/blender/editors/mesh/mesh_data.cc
M   source/blender/editors/uvedit/uvedit_ops.c
M   source/blender/editors/uvedit/uvedit_rip.c
M   source/blender/editors/uvedit/uvedit_select.c
M   source/blender/editors/uvedit/uvedit_unwrap_ops.c
M   source/blender/makesrna/intern/rna_mesh.c
M   
source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_ico_sphere.cc
M   source/blender/python/bmesh/bmesh_py_types_customdata.c
M   source/blender/python/bmesh/bmesh_py_types_meshdata.c

===

diff --git a/source/blender/bmesh/intern/bmesh_interp.c 
b/source/blender/bmesh/intern/bmesh_interp.c
index 3fb6492d3fb..8a97d5f744a 100644
--- a/source/blender/bmesh/intern/bmesh_interp.c
+++ b/source/blender/bmesh/intern/bmesh_interp.c
@@ -873,11 +873,11 @@ void BM_data_layer_ensure_named(BMesh *bm, CustomData 
*data, int type, const cha
   }
 }
 
-void BM_uv_map_ensure_selection_and_pin_attributes(BMesh *bm)
+void BM_uv_map_ensure_select_and_pin_attrs(BMesh *bm)
 {
   const int nr_uv_layers = CustomData_number_of_layers(>ldata, 
CD_PROP_FLOAT2);
   for (int l = 0; l < nr_uv_layers; l++) {
-/* note: you can't re-use the returnvalue of CustomData_get_layer_name() 
because adding layers
+/* NOTE: you can't re-use the returnvalue of CustomData_get_layer_name() 
because adding layers
  * can invalidate that. */
 char name[MAX_CUSTOMDATA_LAYER_NAME];
 BM_data_layer_ensure_named(
@@ -900,21 +900,21 @@ void BM_uv_map_ensure_selection_and_pin_attributes(BMesh 
*bm)
   }
 }
 
-void BM_uv_map_ensure_vert_selection_attribute(BMesh *bm, const char 
*uv_map_name)
+void BM_uv_map_ensure_vert_select_attr(BMesh *bm, const char *uv_map_name)
 {
   char name[MAX_CUSTOMDATA_LAYER_NAME];
   BM_data_layer_ensure_named(
   bm, >ldata, CD_PROP_BOOL, 
BKE_uv_map_vert_selection_name_get(uv_map_name, name));
 }
 
-void BM_uv_map_ensure_edge_selection_attribute(BMesh *bm, const char 
*uv_map_name)
+void BM_uv_map_ensure_edge_select_attr(BMesh *bm, const char *uv_map_name)
 {
   char name[MAX_CUSTOMDATA_LAYER_NAME];
   BM_data_layer_ensure_named(
   bm, >ldata, CD_PROP_BOOL, 
BKE_uv_map_edge_selection_name_get(uv_map_name, name));
 }
 
-void BM_uv_map_ensure_pin_attribute(BMesh *bm, const char *uv_map_name)
+void BM_uv_map_ensure_pin_attr(BMesh *bm, const char *uv_map_name)
 {
   char name[MAX_CUSTOMDATA_LAYER_NAME];
   BM_data_layer_ensure_named(
diff --git a/source/blender/bmesh/intern/bmesh_interp.h 
b/source/blender/bmesh/intern/bmesh_interp.h
index d75410c4699..013ed9d237f 100644
--- a/source/blender/bmesh/intern/bmesh_interp.h
+++ b/source/blender/bmesh/intern/bmesh_interp.h
@@ -66,11 +66,11 @@ void BM_data_layer_ensure_named(BMesh *bm, CustomData 
*data, int type, const cha
 void BM_data_layer_free(BMesh *bm, CustomData *data, int type);
 
 /** Ensure the dependent boolean layers exist for all face corner 
#CD_PROP_FLOAT2 layers. */
-void BM_uv_map_ensure_selection_and_pin_attributes(BMesh *bm);
+void BM_uv_map_ensure_select_and_pin_attrs(BMesh *bm);
 
-void BM_uv_map_ensure_vert_selection_attribute(BMesh *bm, const char 
*uv_map_name);
-void BM_uv_map_ensure_edge_selection_attribute(BMesh *bm, const char 
*uv_map_name);
-void BM_uv_map_ensure_pin_attribute(BMesh *bm, const char *uv_map_name);
+void BM_uv_map_ensure_vert_select_attr(BMesh *bm, const char *uv_map_name);
+void BM_uv_map_ensure_edge_select_attr(BMesh *bm, const char *uv_map_name);
+void BM_uv_map_ensure_pin_attr(BMesh *bm, const char *uv_map_name);
 
 /**
  * Remove a named custom data layer, if it existed. Return true if the layer 
was removed.
diff --git a/source/blender/bmesh/intern/bmesh_mesh_convert.cc 
b/source/blender/bmesh/intern/bmesh_mesh_convert.cc
index b49dd1a294a..a851d7d5efa 100644
--- a/source/blender/bmesh/intern/bmesh_mesh_convert.cc
+++ b/source/blender/bmesh/intern/bmesh_mesh_convert.cc
@@ -151,23 +151,23 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const 
struct BMeshFromMeshPar
 
   blender::Vector temporary_layers_to_delete;
 
-  for (const int l : IndexRange(CustomData_number_of_layers(_ldata, 
CD_PROP_FLOAT2))) {
+  for (const int layer_index : 
IndexRange(CustomData_number_of_layers(_ldata, CD_PROP_FLOAT2))) {
 char name[MAX_CUSTOMDATA_LAYER_NAME];
-BKE_uv_map_vert_selection_name_get(CustomData_get_layer

[Bf-blender-cvs] [f5e87e9facc] refactor-mesh-uv-map-generic: Use correct layer name length for assert

2023-01-05 Thread Martijn Versteegh
Commit: f5e87e9faccabb5371c30d122fb64cfbca58d031
Author: Martijn Versteegh
Date:   Thu Jan 5 14:44:46 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rBf5e87e9faccabb5371c30d122fb64cfbca58d031

Use correct layer name length for assert

===

M   source/blender/blenkernel/intern/attribute.cc

===

diff --git a/source/blender/blenkernel/intern/attribute.cc 
b/source/blender/blenkernel/intern/attribute.cc
index 402c693b329..f03911fbdc0 100644
--- a/source/blender/blenkernel/intern/attribute.cc
+++ b/source/blender/blenkernel/intern/attribute.cc
@@ -875,7 +875,7 @@ void BKE_id_attribute_copy_domains_temp(short id_type,
 const char *BKE_uv_map_vert_selection_name_get(const char *uv_map_name, char 
*buffer)
 {
   BLI_assert(strlen(UV_VERTSEL_NAME) == 2);
-  BLI_assert(strlen(uv_map_name) < MAX_CUSTOMDATA_LAYER_NAME - 5);
+  BLI_assert(strlen(uv_map_name) < MAX_CUSTOMDATA_LAYER_NAME - 4);
   BLI_snprintf(buffer, MAX_CUSTOMDATA_LAYER_NAME, ".%s.%s", UV_VERTSEL_NAME, 
uv_map_name);
   return buffer;
 }
@@ -883,7 +883,7 @@ const char *BKE_uv_map_vert_selection_name_get(const char 
*uv_map_name, char *bu
 const char *BKE_uv_map_edge_selection_name_get(const char *uv_map_name, char 
*buffer)
 {
   BLI_assert(strlen(UV_EDGESEL_NAME) == 2);
-  BLI_assert(strlen(uv_map_name) < MAX_CUSTOMDATA_LAYER_NAME - 5);
+  BLI_assert(strlen(uv_map_name) < MAX_CUSTOMDATA_LAYER_NAME - 4);
   BLI_snprintf(buffer, MAX_CUSTOMDATA_LAYER_NAME, ".%s.%s", UV_EDGESEL_NAME, 
uv_map_name);
   return buffer;
 }
@@ -891,7 +891,7 @@ const char *BKE_uv_map_edge_selection_name_get(const char 
*uv_map_name, char *bu
 const char *BKE_uv_map_pin_name_get(const char *uv_map_name, char *buffer)
 {
   BLI_assert(strlen(UV_PINNED_NAME) == 2);
-  BLI_assert(strlen(uv_map_name) < MAX_CUSTOMDATA_LAYER_NAME - 5);
+  BLI_assert(strlen(uv_map_name) < MAX_CUSTOMDATA_LAYER_NAME - 4);
   BLI_snprintf(buffer, MAX_CUSTOMDATA_LAYER_NAME, ".%s.%s", UV_PINNED_NAME, 
uv_map_name);
   return buffer;
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [a475146648e] refactor-mesh-uv-map-generic: Cleanup: NULL -> nullptr in C++

2023-01-05 Thread Martijn Versteegh
Commit: a475146648e2bf432f54b7c7ce2d0b224aecf743
Author: Martijn Versteegh
Date:   Thu Jan 5 14:50:31 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rBa475146648e2bf432f54b7c7ce2d0b224aecf743

Cleanup: NULL -> nullptr in C++

===

M   source/blender/render/intern/bake.cc

===

diff --git a/source/blender/render/intern/bake.cc 
b/source/blender/render/intern/bake.cc
index 0f3756d6daf..c57b24b0ee0 100644
--- a/source/blender/render/intern/bake.cc
+++ b/source/blender/render/intern/bake.cc
@@ -715,7 +715,7 @@ void RE_bake_pixels_populate(Mesh *me,
  const char *uv_layer)
 {
   const float(*mloopuv)[2];
-  if ((uv_layer == NULL) || (uv_layer[0] == '\0')) {
+  if ((uv_layer == nullptr) || (uv_layer[0] == '\0')) {
 mloopuv = static_cast(CustomData_get_layer(>ldata, 
CD_PROP_FLOAT2));
   }
   else {

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [efc9952c908] refactor-mesh-uv-map-generic: Cleanup: make format

2023-01-05 Thread Martijn Versteegh
Commit: efc9952c908c0d0443fa4b1d572cb7d49f263a60
Author: Martijn Versteegh
Date:   Wed Jan 4 13:03:24 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rBefc9952c908c0d0443fa4b1d572cb7d49f263a60

Cleanup: make format

===

M   source/blender/editors/uvedit/uvedit_select.c

===

diff --git a/source/blender/editors/uvedit/uvedit_select.c 
b/source/blender/editors/uvedit/uvedit_select.c
index 8014d83da69..9b7efdf8877 100644
--- a/source/blender/editors/uvedit/uvedit_select.c
+++ b/source/blender/editors/uvedit/uvedit_select.c
@@ -4205,7 +4205,7 @@ static int uv_select_pinned_exec(bContext *C, wmOperator 
*op)
 
   BM_ITER_ELEM (l, , efa, BM_LOOPS_OF_FACE) {
 
-if (BM_ELEM_CD_GET_BOOL (l, offsets.pin)) {
+if (BM_ELEM_CD_GET_BOOL(l, offsets.pin)) {
   uvedit_uv_select_enable(scene, em->bm, l, false, offsets);
   changed = true;
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


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

2023-01-05 Thread Martijn Versteegh
Commit: c24a650ba765be3b7cfe73b3fcd9d90e16374dbf
Author: Martijn Versteegh
Date:   Wed Jan 4 13:00:44 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rBc24a650ba765be3b7cfe73b3fcd9d90e16374dbf

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

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [0ffddf997f8] refactor-mesh-uv-map-generic: Fixed a missed 64 to 68 for something that needs to store layer names

2023-01-04 Thread Martijn Versteegh
Commit: 0ffddf997f81415d7b56f91864120e9347529d42
Author: Martijn Versteegh
Date:   Wed Jan 4 12:27:43 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB0ffddf997f81415d7b56f91864120e9347529d42

Fixed a missed 64 to 68 for something that needs to store layer names

===

M   source/blender/gpu/GPU_material.h

===

diff --git a/source/blender/gpu/GPU_material.h 
b/source/blender/gpu/GPU_material.h
index ce70c60c04e..f9bae39b016 100644
--- a/source/blender/gpu/GPU_material.h
+++ b/source/blender/gpu/GPU_material.h
@@ -362,8 +362,8 @@ typedef struct GPULayerAttr {
   struct GPULayerAttr *next, *prev;
 
   /* Meaningful part of the attribute set key. */
-  char name[64]; /* MAX_CUSTOMDATA_LAYER_NAME */
-  /** Hash of name[64]. */
+  char name[68]; /* MAX_CUSTOMDATA_LAYER_NAME */
+  /** Hash of name[68]. */
   uint32_t hash_code;
 
   /* Helper fields used by code generation. */

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [df7ccbdae4f] refactor-mesh-uv-map-generic: Replace literal use of '68' with MAX_CUSTOMDATA_LAYERNAME

2023-01-04 Thread Martijn Versteegh
Commit: df7ccbdae4f168e96ed03e283dc624aaf32274aa
Author: Martijn Versteegh
Date:   Wed Jan 4 12:26:56 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rBdf7ccbdae4f168e96ed03e283dc624aaf32274aa

Replace literal use of '68' with MAX_CUSTOMDATA_LAYERNAME

===

M   source/blender/blenkernel/BKE_editmesh_tangent.h

===

diff --git a/source/blender/blenkernel/BKE_editmesh_tangent.h 
b/source/blender/blenkernel/BKE_editmesh_tangent.h
index 5a44a9b5152..c2697ec38b0 100644
--- a/source/blender/blenkernel/BKE_editmesh_tangent.h
+++ b/source/blender/blenkernel/BKE_editmesh_tangent.h
@@ -9,6 +9,7 @@
 #ifdef __cplusplus
 extern "C" {
 #endif
+#include "DNA_customdata_types.h"
 
 /**
  * \see #BKE_mesh_calc_loop_tangent, same logic but used arrays instead of 
#BMesh data.
@@ -19,7 +20,7 @@ extern "C" {
  */
 void BKE_editmesh_loop_tangent_calc(BMEditMesh *em,
 bool calc_active_tangent,
-const char (*tangent_names)[68 /* 
MAX_CUSTOMDATA_LAYER_NAME*/],
+const char 
(*tangent_names)[MAX_CUSTOMDATA_LAYER_NAME],
 int tangent_names_len,
 const float (*poly_normals)[3],
 const float (*loop_normals)[3],

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [bb657247e9b] refactor-mesh-uv-map-generic: Clarify comment

2023-01-04 Thread Martijn Versteegh
Commit: bb657247e9ba3b4d266f2114d4ca1cffef96b855
Author: Martijn Versteegh
Date:   Wed Jan 4 12:12:30 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rBbb657247e9ba3b4d266f2114d4ca1cffef96b855

Clarify comment

===

M   source/blender/blenkernel/BKE_customdata.h

===

diff --git a/source/blender/blenkernel/BKE_customdata.h 
b/source/blender/blenkernel/BKE_customdata.h
index 67d25c0cd52..cb67828eceb 100644
--- a/source/blender/blenkernel/BKE_customdata.h
+++ b/source/blender/blenkernel/BKE_customdata.h
@@ -39,6 +39,7 @@ typedef uint64_t eCustomDataMask;
 /**
  * UV map related customdata offsets into BMesh attribute blocks. See 
#BM_uv_map_get_offsets.
  * Defined in #BKE_customdata.h to avoid including bmesh.h in many unrelated 
areas.
+ * An offset of -1 means that the corresponding layer does not exist.
  */
 typedef struct BMUVOffsets {
   int uv;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [cc0c37a9be7] refactor-mesh-uv-map-generic: Add various asserts and ensure() calls for the vertex and edge selection layers

2023-01-04 Thread Martijn Versteegh
Commit: cc0c37a9be7eeb72053d3da4ac20c9e86f723e5e
Author: Martijn Versteegh
Date:   Wed Jan 4 11:23:35 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rBcc0c37a9be7eeb72053d3da4ac20c9e86f723e5e

Add various asserts and ensure() calls for the vertex and edge selection layers

While this isn't strictly needed now that we have decided to have the
layers always present in BMesh and do the lazy allocatyion only for
Mesh. But It would be nice to expand the lazy allocation to BMesh one
day, and then it is nice to have these asserts.

===

M   source/blender/editors/uvedit/uvedit_select.c

===

diff --git a/source/blender/editors/uvedit/uvedit_select.c 
b/source/blender/editors/uvedit/uvedit_select.c
index 4c1294cf384..46e544921e4 100644
--- a/source/blender/editors/uvedit/uvedit_select.c
+++ b/source/blender/editors/uvedit/uvedit_select.c
@@ -227,6 +227,8 @@ bool uvedit_face_visible_test(const Scene *scene, BMFace 
*efa)
 
 bool uvedit_face_select_test_ex(const ToolSettings *ts, BMFace *efa, const 
BMUVOffsets offsets)
 {
+  BLI_assert(offsets.select_vert >= 0);
+  BLI_assert(offsets.select_edge >= 0);
   if (ts->uv_flag & UV_SYNC_SELECTION) {
 return BM_elem_flag_test(efa, BM_ELEM_SELECT);
   }
@@ -325,7 +327,8 @@ void uvedit_face_select_set(const Scene *scene,
 void uvedit_face_select_enable(
 const Scene *scene, BMesh *bm, BMFace *efa, const bool do_history, const 
BMUVOffsets offsets)
 {
-  BLI_assert(offsets.uv >= 0);
+  BLI_assert(offsets.select_vert >= 0);
+  BLI_assert(offsets.select_edge >= 0);
   const ToolSettings *ts = scene->toolsettings;
 
   if (ts->uv_flag & UV_SYNC_SELECTION) {
@@ -350,7 +353,8 @@ void uvedit_face_select_disable(const Scene *scene,
 BMFace *efa,
 const BMUVOffsets offsets)
 {
-  BLI_assert(offsets.uv >= 0);
+  BLI_assert(offsets.select_vert >= 0);
+  BLI_assert(offsets.select_edge >= 0);
   const ToolSettings *ts = scene->toolsettings;
 
   if (ts->uv_flag & UV_SYNC_SELECTION) {
@@ -369,6 +373,8 @@ void uvedit_face_select_disable(const Scene *scene,
 
 bool uvedit_edge_select_test_ex(const ToolSettings *ts, BMLoop *l, const 
BMUVOffsets offsets)
 {
+  BLI_assert(offsets.select_vert >= 0);
+  BLI_assert(offsets.select_edge >= 0);
   if (ts->uv_flag & UV_SYNC_SELECTION) {
 if (ts->selectmode & SCE_SELECT_FACE) {
   return BM_elem_flag_test(l->f, BM_ELEM_SELECT);
@@ -472,6 +478,8 @@ void uvedit_edge_select_set_noflush(const Scene *scene,
 const int sticky_flag,
 const BMUVOffsets offsets)
 {
+  BLI_assert(offsets.uv >= 0);
+  BLI_assert(offsets.select_edge >= 0);
   BMLoop *l_iter = l;
   do {
 if (uvedit_face_visible_test(scene, l_iter->f)) {
@@ -503,6 +511,8 @@ void uvedit_edge_select_enable(
 
 {
   const ToolSettings *ts = scene->toolsettings;
+  BLI_assert(offsets.select_vert >= 0);
+  BLI_assert(offsets.select_edge >= 0);
 
   if (ts->uv_flag & UV_SYNC_SELECTION) {
 if (ts->selectmode & SCE_SELECT_FACE) {
@@ -533,6 +543,8 @@ void uvedit_edge_select_disable(const Scene *scene,
 const BMUVOffsets offsets)
 {
   const ToolSettings *ts = scene->toolsettings;
+  BLI_assert(offsets.select_vert >= 0);
+  BLI_assert(offsets.select_edge >= 0);
 
   if (ts->uv_flag & UV_SYNC_SELECTION) {
 if (ts->selectmode & SCE_SELECT_FACE) {
@@ -566,6 +578,7 @@ void uvedit_edge_select_disable(const Scene *scene,
 
 bool uvedit_uv_select_test_ex(const ToolSettings *ts, BMLoop *l, const 
BMUVOffsets offsets)
 {
+  BLI_assert(offsets.select_vert >= 0);
   if (ts->uv_flag & UV_SYNC_SELECTION) {
 if (ts->selectmode & SCE_SELECT_FACE) {
   return BM_elem_flag_test_bool(l->f, BM_ELEM_SELECT);
@@ -641,6 +654,7 @@ void uvedit_uv_select_shared_vert(const Scene *scene,
   const BMUVOffsets offsets)
 {
   BLI_assert(ELEM(sticky_flag, SI_STICKY_LOC, SI_STICKY_VERTEX));
+  BLI_assert(offsets.uv >= 0);
 
   BMEdge *e_first, *e_iter;
   e_first = e_iter = l->e;
@@ -688,6 +702,7 @@ void uvedit_uv_select_enable(
 const Scene *scene, BMesh *bm, BMLoop *l, const bool do_history, const 
BMUVOffsets offsets)
 {
   const ToolSettings *ts = scene->toolsettings;
+  BLI_assert(offsets.select_vert >= 0);
 
   if (ts->selectmode & SCE_SELECT_EDGE) {
 /* Are you looking for `uvedit_edge_select_set(...)` instead? */
@@ -713,6 +728,7 @@ void uvedit_uv_select_enable(
 void uvedit_uv_select_disable(const Scene *scene, BMesh *bm, BMLoop *l, const 
BMUVOffsets offsets)
 {
   const ToolSettings *ts = scene->toolsettings;
+  BLI_assert(offsets.select_vert >= 0);
 
 

[Bf-blender-cvs] [51188afa2ce] refactor-mesh-uv-map-generic: Remove extraneous includes

2023-01-04 Thread Martijn Versteegh
Commit: 51188afa2ce573344419b9e3fb927b852957ebeb
Author: Martijn Versteegh
Date:   Wed Jan 4 12:12:15 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB51188afa2ce573344419b9e3fb927b852957ebeb

Remove extraneous includes

===

M   source/blender/blenkernel/BKE_attribute.h

===

diff --git a/source/blender/blenkernel/BKE_attribute.h 
b/source/blender/blenkernel/BKE_attribute.h
index 2663180f1f9..8fdf3850798 100644
--- a/source/blender/blenkernel/BKE_attribute.h
+++ b/source/blender/blenkernel/BKE_attribute.h
@@ -8,9 +8,6 @@
 
 #pragma once
 
-#include 
-
-#include "BLI_string.h"
 #include "BLI_sys_types.h"
 
 #include "BKE_customdata.h"

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [308bbbe74f1] refactor-mesh-uv-map-generic: Remove CD_FAKE_BWEIGHT, which had popped back up because of a merge mistake

2023-01-04 Thread Martijn Versteegh
Commit: 308bbbe74f14c1a713374136c21e888719c6d411
Author: Martijn Versteegh
Date:   Wed Jan 4 11:10:47 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB308bbbe74f14c1a713374136c21e888719c6d411

Remove CD_FAKE_BWEIGHT, which had popped back up because of a merge mistake

===

M   source/blender/blenkernel/BKE_customdata.h

===

diff --git a/source/blender/blenkernel/BKE_customdata.h 
b/source/blender/blenkernel/BKE_customdata.h
index b725ec3b6ec..67d25c0cd52 100644
--- a/source/blender/blenkernel/BKE_customdata.h
+++ b/source/blender/blenkernel/BKE_customdata.h
@@ -623,7 +623,6 @@ enum {
   CD_FAKE_SEAM = CD_FAKE | 100, /* UV seam flag for edges. */
 
   /* Multiple types of mesh elements... */
-  CD_FAKE_BWEIGHT = CD_FAKE | CD_BWEIGHT, /* *sigh*. */
   CD_FAKE_UV =
   CD_FAKE |
   CD_PROP_FLOAT2, /* UV flag, because we handle both loop's UVs and poly's 
textures. */

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [bb6e9a7e868] refactor-mesh-uv-map-generic: Correct brackets for if statement

2023-01-04 Thread Martijn Versteegh
Commit: bb6e9a7e868fa2048377496447030f653a074e0c
Author: Martijn Versteegh
Date:   Wed Jan 4 12:09:14 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rBbb6e9a7e868fa2048377496447030f653a074e0c

Correct brackets for if statement

===

M   source/blender/editors/uvedit/uvedit_select.c

===

diff --git a/source/blender/editors/uvedit/uvedit_select.c 
b/source/blender/editors/uvedit/uvedit_select.c
index 46e544921e4..8014d83da69 100644
--- a/source/blender/editors/uvedit/uvedit_select.c
+++ b/source/blender/editors/uvedit/uvedit_select.c
@@ -4205,7 +4205,7 @@ static int uv_select_pinned_exec(bContext *C, wmOperator 
*op)
 
   BM_ITER_ELEM (l, , efa, BM_LOOPS_OF_FACE) {
 
-if BM_ELEM_CD_GET_BOOL (l, offsets.pin) {
+if (BM_ELEM_CD_GET_BOOL (l, offsets.pin)) {
   uvedit_uv_select_enable(scene, em->bm, l, false, offsets);
   changed = true;
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [4e1e61a21f8] refactor-mesh-uv-map-generic: Cleanup: make format

2023-01-03 Thread Martijn Versteegh
Commit: 4e1e61a21f8aacf02b5d5d94f78f45df23444666
Author: Martijn Versteegh
Date:   Tue Jan 3 13:17:33 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB4e1e61a21f8aacf02b5d5d94f78f45df23444666

Cleanup: make format

===

M   source/blender/blenkernel/intern/attribute.cc
M   source/blender/blenkernel/intern/customdata.cc

===

diff --git a/source/blender/blenkernel/intern/attribute.cc 
b/source/blender/blenkernel/intern/attribute.cc
index bc174adc5df..402c693b329 100644
--- a/source/blender/blenkernel/intern/attribute.cc
+++ b/source/blender/blenkernel/intern/attribute.cc
@@ -141,9 +141,9 @@ bool BKE_attribute_allow_procedural_access(const char 
*attribute_name)
 }
 
 static bool bke_id_attribute_rename_if_exists(ID *id,
- const char *old_name,
- const char *new_name,
- ReportList *reports)
+  const char *old_name,
+  const char *new_name,
+  ReportList *reports)
 {
   CustomDataLayer *layer = BKE_id_attribute_search(
   id, old_name, CD_MASK_PROP_ALL, ATTR_DOMAIN_MASK_ALL);
@@ -187,17 +187,17 @@ bool BKE_id_attribute_rename(ID *id,
 char buffer_dst[MAX_CUSTOMDATA_LAYER_NAME];
 
 bke_id_attribute_rename_if_exists(id,
-BKE_uv_map_vert_selection_name_get(layer->name, 
buffer_src),
-BKE_uv_map_vert_selection_name_get(result_name, 
buffer_dst),
-reports);
+  
BKE_uv_map_vert_selection_name_get(layer->name, buffer_src),
+  
BKE_uv_map_vert_selection_name_get(result_name, buffer_dst),
+  reports);
 bke_id_attribute_rename_if_exists(id,
-BKE_uv_map_edge_selection_name_get(layer->name, 
buffer_src),
-BKE_uv_map_edge_selection_name_get(result_name, 
buffer_dst),
-reports);
+  
BKE_uv_map_edge_selection_name_get(layer->name, buffer_src),
+  
BKE_uv_map_edge_selection_name_get(result_name, buffer_dst),
+  reports);
 bke_id_attribute_rename_if_exists(id,
-BKE_uv_map_pin_name_get(layer->name, buffer_src),
-BKE_uv_map_pin_name_get(result_name, buffer_dst),
-reports);
+  BKE_uv_map_pin_name_get(layer->name, 
buffer_src),
+  BKE_uv_map_pin_name_get(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);
@@ -293,7 +293,6 @@ CustomDataLayer *BKE_id_attribute_new(
   return (index == -1) ? nullptr : &(customdata->layers[index]);
 }
 
-
 static void bke_id_attribute_copy_if_exists(ID *id, const char *srcname, const 
char *dstname)
 {
   using namespace blender::bke;
@@ -310,10 +309,8 @@ static void bke_id_attribute_copy_if_exists(ID *id, const 
char *srcname, const c
 
   const eCustomDataType type = cpp_type_to_custom_data_type(src.varray.type());
   attributes->add(dstname, src.domain, type, AttributeInitVArray(src.varray));
-
 }
 
-
 CustomDataLayer *BKE_id_attribute_duplicate(ID *id, const char *name, 
ReportList *reports)
 {
   using namespace blender::bke;
@@ -349,17 +346,16 @@ CustomDataLayer *BKE_id_attribute_duplicate(ID *id, const 
char *name, ReportList
 char buffer_dst[MAX_CUSTOMDATA_LAYER_NAME];
 
 bke_id_attribute_copy_if_exists(id,
-BKE_uv_map_vert_selection_name_get(name, 
buffer_src),
-BKE_uv_map_vert_selection_name_get(uniquename, 
buffer_dst));
+BKE_uv_map_vert_selection_name_get(name, 
buffer_src),
+
BKE_uv_map_vert_selection_name_get(uniquename, buffer_dst));
 bke_id_attribute_copy_if_exists(id,
-BKE_uv_map_edge_selection_name_get(name, 
buffer_src),
-BKE_uv_map_edge_selection_name_get(uniquename, 
buffer_dst));
+BKE_uv_map_edge_selection_name_get(name, 
buffer_src),
+
BKE_uv_map_edge_selection_name_get(uniquename, buffer_dst));
 bke_id_attribute_copy_if_exists(id,
-BKE_uv_map_pin_name_get(name, buffer_src),
-BKE_uv_map_pin_nam

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

2023-01-03 Thread Martijn Versteegh
Commit: 8f0d4dd8d48f6b65532a30c8bec4ee2072806d23
Author: Martijn Versteegh
Date:   Tue Jan 3 13:10:59 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB8f0d4dd8d48f6b65532a30c8bec4ee2072806d23

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

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [392a95e0bcc] refactor-mesh-uv-map-generic: Handle UV map associated bool lyers on attribute removal

2023-01-03 Thread Martijn Versteegh
Commit: 392a95e0bcc9576b3e8dadc2484a1ce1e1ce42ca
Author: Martijn Versteegh
Date:   Tue Jan 3 13:09:45 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB392a95e0bcc9576b3e8dadc2484a1ce1e1ce42ca

Handle UV map associated bool lyers on attribute removal

===

M   source/blender/blenkernel/BKE_customdata.h
M   source/blender/blenkernel/intern/attribute.cc
M   source/blender/blenkernel/intern/customdata.cc

===

diff --git a/source/blender/blenkernel/BKE_customdata.h 
b/source/blender/blenkernel/BKE_customdata.h
index 01ceee78497..b725ec3b6ec 100644
--- a/source/blender/blenkernel/BKE_customdata.h
+++ b/source/blender/blenkernel/BKE_customdata.h
@@ -440,6 +440,7 @@ int CustomData_get_n_offset(const struct CustomData *data, 
int type, int n);
 int CustomData_get_layer_index(const struct CustomData *data, int type);
 int CustomData_get_layer_index_n(const struct CustomData *data, int type, int 
n);
 int CustomData_get_named_layer_index(const struct CustomData *data, int type, 
const char *name);
+int CustomData_get_named_layer_index_notype(const struct CustomData *data, 
const char *name);
 int CustomData_get_active_layer_index(const struct CustomData *data, int type);
 int CustomData_get_render_layer_index(const struct CustomData *data, int type);
 int CustomData_get_clone_layer_index(const struct CustomData *data, int type);
diff --git a/source/blender/blenkernel/intern/attribute.cc 
b/source/blender/blenkernel/intern/attribute.cc
index 0431967ebc0..490f7d48833 100644
--- a/source/blender/blenkernel/intern/attribute.cc
+++ b/source/blender/blenkernel/intern/attribute.cc
@@ -341,11 +341,23 @@ bool BKE_id_attribute_remove(ID *id, const char *name, 
ReportList *reports)
   DomainInfo info[ATTR_DOMAIN_NUM];
   get_domains(id, info);
 
+
+
   if (GS(id->name) == ID_ME) {
 Mesh *mesh = reinterpret_cast(id);
 if (BMEditMesh *em = mesh->edit_mesh) {
   for (const int domain : IndexRange(ATTR_DOMAIN_NUM)) {
 if (CustomData *data = info[domain].customdata) {
+  int layer_index = CustomData_get_named_layer_index_notype(data, 
name);
+  if (layer_index >= 0) {
+if (data->layers[layer_index].type == CD_PROP_FLOAT2) {
+  /* free associated UV map bool layers */
+  char buffer_src[MAX_CUSTOMDATA_LAYER_NAME];
+  BM_data_layer_free_named(em->bm, data, 
BKE_uv_map_vert_selection_name_get(name, buffer_src));
+  BM_data_layer_free_named(em->bm, data, 
BKE_uv_map_edge_selection_name_get(name, buffer_src));
+  BM_data_layer_free_named(em->bm, data, 
BKE_uv_map_pin_name_get(name, buffer_src));
+}
+  }
   if (BM_data_layer_free_named(em->bm, data, name)) {
 if (name == StringRef(mesh->active_color_attribute)) {
   MEM_SAFE_FREE(mesh->active_color_attribute);
@@ -362,10 +374,30 @@ bool BKE_id_attribute_remove(ID *id, const char *name, 
ReportList *reports)
   }
 
   std::optional attributes = 
get_attribute_accessor_for_write(*id);
+
   if (!attributes) {
 return false;
   }
 
+  if (GS(id->name) == ID_ME) {
+
+std::optional metadata = 
attributes->lookup_meta_data(name);
+if (metadata->data_type == CD_PROP_FLOAT2)
+{
+  /* remove UV sub-attributes. */
+  char buffer_src[MAX_CUSTOMDATA_LAYER_NAME];
+  BKE_id_attribute_remove(id,
+  BKE_uv_map_vert_selection_name_get(name, 
buffer_src),
+  reports);
+  BKE_id_attribute_remove(id,
+  BKE_uv_map_edge_selection_name_get(name, 
buffer_src),
+  reports);
+  BKE_id_attribute_remove(id,
+  BKE_uv_map_pin_name_get(name, buffer_src),
+  reports);
+}
+  }
+
   return attributes->remove(name);
 }
 
diff --git a/source/blender/blenkernel/intern/customdata.cc 
b/source/blender/blenkernel/intern/customdata.cc
index 0509592427a..04233d1aedc 100644
--- a/source/blender/blenkernel/intern/customdata.cc
+++ b/source/blender/blenkernel/intern/customdata.cc
@@ -2506,6 +2506,18 @@ int CustomData_get_named_layer_index(const CustomData 
*data, const int type, con
   return -1;
 }
 
+int CustomData_get_named_layer_index_notype(const CustomData *data, const char 
*name)
+{
+  for (int i = 0; i < data->totlayer; i++) {
+if (STREQ(data->layers[i].name, name)) {
+return i;
+}
+  }
+
+  return -1;
+}
+
+
 int CustomData_get_active_layer_index(const CustomData *data, const int type)
 {
   const int layer_index = data->typemap[type];

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [065826a3b41] refactor-mesh-uv-map-generic: Handle UV map associated bool lyers on attribute duplication

2023-01-03 Thread Martijn Versteegh
Commit: 065826a3b41da8931e313acc51865f4000e50c22
Author: Martijn Versteegh
Date:   Tue Jan 3 13:09:58 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB065826a3b41da8931e313acc51865f4000e50c22

Handle UV map associated bool lyers on attribute duplication

===

M   source/blender/blenkernel/intern/attribute.cc

===

diff --git a/source/blender/blenkernel/intern/attribute.cc 
b/source/blender/blenkernel/intern/attribute.cc
index 490f7d48833..bc174adc5df 100644
--- a/source/blender/blenkernel/intern/attribute.cc
+++ b/source/blender/blenkernel/intern/attribute.cc
@@ -293,6 +293,27 @@ CustomDataLayer *BKE_id_attribute_new(
   return (index == -1) ? nullptr : &(customdata->layers[index]);
 }
 
+
+static void bke_id_attribute_copy_if_exists(ID *id, const char *srcname, const 
char *dstname)
+{
+  using namespace blender::bke;
+
+  std::optional attributes = 
get_attribute_accessor_for_write(*id);
+  if (!attributes) {
+return;
+  }
+
+  GAttributeReader src = attributes->lookup(srcname);
+  if (!src) {
+return;
+  }
+
+  const eCustomDataType type = cpp_type_to_custom_data_type(src.varray.type());
+  attributes->add(dstname, src.domain, type, AttributeInitVArray(src.varray));
+
+}
+
+
 CustomDataLayer *BKE_id_attribute_duplicate(ID *id, const char *name, 
ReportList *reports)
 {
   using namespace blender::bke;
@@ -322,6 +343,23 @@ CustomDataLayer *BKE_id_attribute_duplicate(ID *id, const 
char *name, ReportList
   const eCustomDataType type = cpp_type_to_custom_data_type(src.varray.type());
   attributes->add(uniquename, src.domain, type, 
AttributeInitVArray(src.varray));
 
+  if (GS(id->name) == ID_ME && type == CD_PROP_FLOAT2) {
+/* Duplicate UV sub-attributes. */
+char buffer_src[MAX_CUSTOMDATA_LAYER_NAME];
+char buffer_dst[MAX_CUSTOMDATA_LAYER_NAME];
+
+bke_id_attribute_copy_if_exists(id,
+BKE_uv_map_vert_selection_name_get(name, 
buffer_src),
+BKE_uv_map_vert_selection_name_get(uniquename, 
buffer_dst));
+bke_id_attribute_copy_if_exists(id,
+BKE_uv_map_edge_selection_name_get(name, 
buffer_src),
+BKE_uv_map_edge_selection_name_get(uniquename, 
buffer_dst));
+bke_id_attribute_copy_if_exists(id,
+BKE_uv_map_pin_name_get(name, buffer_src),
+BKE_uv_map_pin_name_get(uniquename, buffer_dst));
+  }
+
+
   return BKE_id_attribute_search(id, uniquename, CD_MASK_PROP_ALL, 
ATTR_DOMAIN_MASK_ALL);
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [7fb1c67c3d2] refactor-mesh-uv-map-generic: Only copy associated UV map bool layers if they exist

2023-01-02 Thread Martijn Versteegh
Commit: 7fb1c67c3d2d2d1694d320c1f2cc3b112e2a387a
Author: Martijn Versteegh
Date:   Mon Jan 2 23:37:52 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB7fb1c67c3d2d2d1694d320c1f2cc3b112e2a387a

Only copy associated UV map bool layers if they exist

===

M   source/blender/blenkernel/intern/attribute.cc

===

diff --git a/source/blender/blenkernel/intern/attribute.cc 
b/source/blender/blenkernel/intern/attribute.cc
index 83f2277e09c..0431967ebc0 100644
--- a/source/blender/blenkernel/intern/attribute.cc
+++ b/source/blender/blenkernel/intern/attribute.cc
@@ -140,6 +140,19 @@ bool BKE_attribute_allow_procedural_access(const char 
*attribute_name)
   return blender::bke::allow_procedural_attribute_access(attribute_name);
 }
 
+static bool bke_id_attribute_rename_if_exists(ID *id,
+ const char *old_name,
+ const char *new_name,
+ ReportList *reports)
+{
+  CustomDataLayer *layer = BKE_id_attribute_search(
+  id, old_name, CD_MASK_PROP_ALL, ATTR_DOMAIN_MASK_ALL);
+  if (layer == nullptr) {
+return false;
+  }
+  return BKE_id_attribute_rename(id, old_name, new_name, reports);
+}
+
 bool BKE_id_attribute_rename(ID *id,
  const char *old_name,
  const char *new_name,
@@ -172,15 +185,16 @@ bool BKE_id_attribute_rename(ID *id,
 /* Rename UV sub-attributes. */
 char buffer_src[MAX_CUSTOMDATA_LAYER_NAME];
 char buffer_dst[MAX_CUSTOMDATA_LAYER_NAME];
-BKE_id_attribute_rename(id,
+
+bke_id_attribute_rename_if_exists(id,
 BKE_uv_map_vert_selection_name_get(layer->name, 
buffer_src),
 BKE_uv_map_vert_selection_name_get(result_name, 
buffer_dst),
 reports);
-BKE_id_attribute_rename(id,
+bke_id_attribute_rename_if_exists(id,
 BKE_uv_map_edge_selection_name_get(layer->name, 
buffer_src),
 BKE_uv_map_edge_selection_name_get(result_name, 
buffer_dst),
 reports);
-BKE_id_attribute_rename(id,
+bke_id_attribute_rename_if_exists(id,
 BKE_uv_map_pin_name_get(layer->name, buffer_src),
 BKE_uv_map_pin_name_get(result_name, buffer_dst),
 reports);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


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

2023-01-01 Thread Martijn Versteegh
Commit: 918b7cc7829c79d824572c015a48b51dd7345c99
Author: Martijn Versteegh
Date:   Sun Jan 1 23:08:00 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB918b7cc7829c79d824572c015a48b51dd7345c99

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

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


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

2022-12-31 Thread Martijn Versteegh
Commit: 0c3763f580eee4e5c4b0cde85cd6974a130f9a1a
Author: Martijn Versteegh
Date:   Sat Dec 31 13:10:06 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB0c3763f580eee4e5c4b0cde85cd6974a130f9a1a

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

===



===

diff --cc source/blender/blenkernel/intern/mesh_convert.cc
index 622d5f2ae18,0a66bacd004..7d5f8afb715
--- a/source/blender/blenkernel/intern/mesh_convert.cc
+++ b/source/blender/blenkernel/intern/mesh_convert.cc
@@@ -196,16 -198,13 +198,13 @@@ static Mesh *mesh_nurbs_displist_to_mes
MutableAttributeAccessor attributes = mesh->attributes_for_write();
SpanAttributeWriter material_indices = 
attributes.lookup_or_add_for_write_only_span(
"material_index", ATTR_DOMAIN_FACE);
 -  MLoopUV *mloopuv = static_cast(CustomData_add_layer_named(
 -  >ldata, CD_MLOOPUV, CD_SET_DEFAULT, nullptr, mesh->totloop, 
DATA_("UVMap")));
 +  blender::float2 *mloopuv = static_cast(CustomData_add_layer_named(
 +  >ldata, CD_PROP_FLOAT2, CD_SET_DEFAULT, nullptr, mesh->totloop, 
DATA_("UVMap")));
  
-   /* verts and faces */
-   vertcount = 0;
- 
+   int dst_vert = 0;
+   int dst_edge = 0;
+   int dst_poly = 0;
+   int dst_loop = 0;
LISTBASE_FOREACH (const DispList *, dl, dispbase) {
  const bool is_smooth = (dl->rt & CU_SMOOTH) != 0;
  
@@@ -282,8 -278,8 +278,8 @@@
  
  if (mloopuv) {
for (int i = 0; i < 3; i++, mloopuv++) {
- (*mloopuv)[0] = (mloop[i].v - startvert) / float(dl->nr - 1);
 -mloopuv->uv[0] = (loops[dst_loop + i].v - startvert) / 
float(dl->nr - 1);
 -mloopuv->uv[1] = 0.0f;
++(*mloopuv)[0] = (loops[dst_loop + i].v - startvert) / 
float(dl->nr - 1);
 +(*mloopuv)[1] = 0.0f;
}
  }
  
@@@ -357,17 -353,17 +353,17 @@@
  
  for (int i = 0; i < 4; i++, mloopuv++) {
/* find uv based on vertex index into grid array */
-   int v = mloop[i].v - startvert;
+   int v = loops[dst_loop + i].v - startvert;
  
 -  mloopuv->uv[0] = (v / dl->nr) / float(orco_sizev);
 -  mloopuv->uv[1] = (v % dl->nr) / float(orco_sizeu);
 +  (*mloopuv)[0] = (v / dl->nr) / float(orco_sizev);
 +  (*mloopuv)[1] = (v % dl->nr) / float(orco_sizeu);
  
/* cyclic correction */
 -  if (ELEM(i, 1, 2) && mloopuv->uv[0] == 0.0f) {
 -mloopuv->uv[0] = 1.0f;
 +  if ((ELEM(i, 1, 2)) && (*mloopuv)[0] == 0.0f) {
 +(*mloopuv)[0] = 1.0f;
}
 -  if (ELEM(i, 0, 1) && mloopuv->uv[1] == 0.0f) {
 -mloopuv->uv[1] = 1.0f;
 +  if ((ELEM(i, 0, 1)) && (*mloopuv)[1] == 0.0f) {
 +(*mloopuv)[1] = 1.0f;
}
  }
}
diff --cc source/blender/editors/sculpt_paint/paint_image_proj.cc
index 9f41d4f58c0,3d23cb46856..7bcce664267
--- a/source/blender/editors/sculpt_paint/paint_image_proj.cc
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.cc
@@@ -4103,11 -4104,11 +4103,11 @@@ static bool proj_paint_state_mesh_eval_
return true;
  }
  
- typedef struct {
+ struct ProjPaintLayerClone {
 -  const MLoopUV *mloopuv_clone_base;
 +  const float (*mloopuv_clone_base)[2];
const TexPaintSlot *slot_last_clone;
const TexPaintSlot *slot_clone;
- } ProjPaintLayerClone;
+ };
  
  static void proj_paint_layer_clone_init(ProjPaintState *ps, 
ProjPaintLayerClone *layer_clone)
  {

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [fee6059785e] refactor-mesh-uv-map-generic: Cleanup: make format

2022-12-31 Thread Martijn Versteegh
Commit: fee6059785e95179e5a88ff2777e8b0a0c8a22e0
Author: Martijn Versteegh
Date:   Sat Dec 31 13:13:07 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rBfee6059785e95179e5a88ff2777e8b0a0c8a22e0

Cleanup: make format

===

M   source/blender/blenkernel/intern/customdata.cc
M   source/blender/blenloader/intern/versioning_280.c
M   source/blender/editors/mesh/mesh_data.cc

===

diff --git a/source/blender/blenkernel/intern/customdata.cc 
b/source/blender/blenkernel/intern/customdata.cc
index fd623dd6d22..0509592427a 100644
--- a/source/blender/blenkernel/intern/customdata.cc
+++ b/source/blender/blenkernel/intern/customdata.cc
@@ -4414,9 +4414,9 @@ static bool 
CustomData_layer_ensure_data_exists(CustomDataLayer *layer, size_t c
 
   switch (layer->type) {
 /* When more instances of corrupt files are found, add them here. */
-case CD_PROP_BOOL: /* See T84935. */
-case CD_MLOOPUV:   /* See T90620. */
-case CD_PROP_FLOAT2:   /* See T90620. */
+case CD_PROP_BOOL:   /* See T84935. */
+case CD_MLOOPUV: /* See T90620. */
+case CD_PROP_FLOAT2: /* See T90620. */
   layer->data = MEM_calloc_arrayN(count, typeInfo->size, 
layerType_getName(layer->type));
   BLI_assert(layer->data);
   if (typeInfo->set_default_value) {
diff --git a/source/blender/blenloader/intern/versioning_280.c 
b/source/blender/blenloader/intern/versioning_280.c
index c12f03ce399..a41adc72a4f 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -1798,7 +1798,8 @@ void blo_do_versions_280(FileData *fd, Library 
*UNUSED(lib), Main *bmain)
 if (DNA_struct_find(fd->filesdna, "MTexPoly")) {
   for (Mesh *me = bmain->meshes.first; me; me = me->id.next) {
 /* If we have UV's, so this file will have MTexPoly layers too! */
-if (CustomData_has_layer(>ldata, CD_MLOOPUV) || 
CustomData_has_layer(>ldata, CD_PROP_FLOAT2)) {
+if (CustomData_has_layer(>ldata, CD_MLOOPUV) ||
+CustomData_has_layer(>ldata, CD_PROP_FLOAT2)) {
   CustomData_update_typemap(>pdata);
   CustomData_free_layers(>pdata, CD_MTEXPOLY, me->totpoly);
 }
diff --git a/source/blender/editors/mesh/mesh_data.cc 
b/source/blender/editors/mesh/mesh_data.cc
index d14a69d3c23..86d64355b63 100644
--- a/source/blender/editors/mesh/mesh_data.cc
+++ b/source/blender/editors/mesh/mesh_data.cc
@@ -140,7 +140,6 @@ static void delete_customdata_layer(Mesh *me, 
CustomDataLayer *layer)
   }
 }
 
-
 static void mesh_uv_reset_array(float **fuv, const int len)
 {
   if (len == 3) {

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [0e1a91d5bb0] refactor-mesh-uv-map-generic: Rewrite comment to refelct the current plan.

2022-12-31 Thread Martijn Versteegh
Commit: 0e1a91d5bb0e6fa6005514ac457a092146a41683
Author: Martijn Versteegh
Date:   Sat Dec 31 12:50:11 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB0e1a91d5bb0e6fa6005514ac457a092146a41683

Rewrite comment to refelct the current plan.

===

M   source/blender/blenkernel/intern/mesh.cc

===

diff --git a/source/blender/blenkernel/intern/mesh.cc 
b/source/blender/blenkernel/intern/mesh.cc
index 7cdf486c417..bce8bb4f8ad 100644
--- a/source/blender/blenkernel/intern/mesh.cc
+++ b/source/blender/blenkernel/intern/mesh.cc
@@ -517,9 +517,12 @@ static int customdata_compare(
   const Span loops_1 = m1->loops();
   const Span loops_2 = m2->loops();
 
-  /* TODO(@Baardaap) the uv selection / pin layers are ignored in the 
comparisons because
-   * the original flags they replace were ignored as well. For completeness it 
would be
-   * better to compare them as well, but some test files would need to be 
updated. */
+  /* The uv selection / pin layers are ignored in the comparisons because
+   * the original flags they replace were ignored as well. Because of the
+   * lazy creation of these layers it would need careful handling of the
+   * test files to compare these layers. For now it has been decided to
+   * skip them.
+   */
 
   for (int i = 0; i < c1->totlayer; i++) {
 l1 = >layers[i];

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


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

2022-12-31 Thread Martijn Versteegh
Commit: 8a36afd007c3bfb04a12073c4646436cdc5f7de9
Author: Martijn Versteegh
Date:   Thu Dec 29 10:34:09 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB8a36afd007c3bfb04a12073c4646436cdc5f7de9

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

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [14667de65bd] master: Fix uninitialized ColorSceneLinear4f occuring in certain situations.

2022-12-24 Thread Martijn Versteegh
Commit: 14667de65bd139c13e1b19cc8a0621ab7147d7c2
Author: Martijn Versteegh
Date:   Fri Dec 23 12:01:59 2022 +0100
Branches: master
https://developer.blender.org/rB14667de65bd139c13e1b19cc8a0621ab7147d7c2

Fix uninitialized ColorSceneLinear4f occuring in certain situations.

On gcc 11.3, Ubuntu 22.04 the default constructor for
ColorSceneLinear4f did not zero the r,g,b,a member variables. Replacing
the empty constructor with a default constructor circumvents this
problem (compiler bug? ) even though it *should* be more or less
equivalent.

===

M   source/blender/blenlib/BLI_color.hh

===

diff --git a/source/blender/blenlib/BLI_color.hh 
b/source/blender/blenlib/BLI_color.hh
index b1b9aeb17f1..0256cec667c 100644
--- a/source/blender/blenlib/BLI_color.hh
+++ b/source/blender/blenlib/BLI_color.hh
@@ -152,9 +152,7 @@ BLI_INLINE ColorTheme4 
BLI_color_convert_to_theme4b(const ColorTheme4
 class ColorSceneLinear4f final : public ColorRGBA {
  public:
-  constexpr ColorSceneLinear4f() : ColorRGBA()
-  {
-  }
+  constexpr ColorSceneLinear4f() = default;
 
   constexpr ColorSceneLinear4f(const float *rgba)
   : ColorRGBA(rgba)

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [262ea626dfc] refactor-mesh-uv-map-generic: In certain locations where it is unclear if we should check for CD_MLOOPUV or CD_PROP_FLOAT, just do both.

2022-12-23 Thread Martijn Versteegh
Commit: 262ea626dfc3db711454683abf5e0e7e6d971f52
Author: Martijn Versteegh
Date:   Fri Dec 23 14:56:52 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB262ea626dfc3db711454683abf5e0e7e6d971f52

In certain locations where it is unclear if we should check for CD_MLOOPUV or 
CD_PROP_FLOAT, just do both.

===

M   source/blender/blenkernel/intern/customdata.cc
M   source/blender/blenloader/intern/versioning_280.c

===

diff --git a/source/blender/blenkernel/intern/customdata.cc 
b/source/blender/blenkernel/intern/customdata.cc
index cb43a962785..fd623dd6d22 100644
--- a/source/blender/blenkernel/intern/customdata.cc
+++ b/source/blender/blenkernel/intern/customdata.cc
@@ -4416,8 +4416,7 @@ static bool 
CustomData_layer_ensure_data_exists(CustomDataLayer *layer, size_t c
 /* When more instances of corrupt files are found, add them here. */
 case CD_PROP_BOOL: /* See T84935. */
 case CD_MLOOPUV:   /* See T90620. */
-  /* TODO(@Baardaap) check if this is run before or after versioning. If 
after we need to add
-   * #CD_PROP_FLOAT2 to the list? */
+case CD_PROP_FLOAT2:   /* See T90620. */
   layer->data = MEM_calloc_arrayN(count, typeInfo->size, 
layerType_getName(layer->type));
   BLI_assert(layer->data);
   if (typeInfo->set_default_value) {
diff --git a/source/blender/blenloader/intern/versioning_280.c 
b/source/blender/blenloader/intern/versioning_280.c
index ffb87949234..c12f03ce399 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -1798,7 +1798,7 @@ void blo_do_versions_280(FileData *fd, Library 
*UNUSED(lib), Main *bmain)
 if (DNA_struct_find(fd->filesdna, "MTexPoly")) {
   for (Mesh *me = bmain->meshes.first; me; me = me->id.next) {
 /* If we have UV's, so this file will have MTexPoly layers too! */
-if (CustomData_has_layer(>ldata, CD_MLOOPUV)) {
+if (CustomData_has_layer(>ldata, CD_MLOOPUV) || 
CustomData_has_layer(>ldata, CD_PROP_FLOAT2)) {
   CustomData_update_typemap(>pdata);
   CustomData_free_layers(>pdata, CD_MTEXPOLY, me->totpoly);
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


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

2022-12-23 Thread Martijn Versteegh
Commit: e497f7ccbbfaeaf0ee48695b54e89b6acd27a915
Author: Martijn Versteegh
Date:   Fri Dec 23 14:50:17 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rBe497f7ccbbfaeaf0ee48695b54e89b6acd27a915

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

===



===

diff --cc source/blender/editors/mesh/mesh_data.cc
index 2cf13dd73d8,a2310dddc61..bd99dc92db3
--- a/source/blender/editors/mesh/mesh_data.cc
+++ b/source/blender/editors/mesh/mesh_data.cc
@@@ -120,7 -117,7 +120,7 @@@ static void delete_customdata_layer(Mes
int layer_index, tot, n;
  
char htype = BM_FACE;
--  if (ELEM(type, CD_PROP_BYTE_COLOR, CD_MLOOPUV)) {
++  if (ELEM(type, CD_PROP_BYTE_COLOR, CD_PROP_FLOAT2)) {
  htype = BM_LOOP;
}
else if (ELEM(type, CD_PROP_COLOR)) {

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


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

2022-12-22 Thread Martijn Versteegh
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 material_indices = 
attributes.lookup_or_add_for_write_only_span(
"material_index", ATTR_DOMAIN_FACE);
 -  MLoopUV *mloopuv = static_cast(CustomData_add_layer_named(
 -  >ldata, CD_MLOOPUV, CD_SET_DEFAULT, nullptr, mesh->totloop, 
DATA_("UVMap")));
 +  blender::float2 *mloopuv = static_cast(CustomData_add_layer_named(
-   >ldata, CD_PROP_FLOAT2, CD_SET_DEFAULT, nullptr, mesh->totloop, 
"UVMap"));
++  >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];

[Bf-blender-cvs] [b255bb87cbf] refactor-mesh-uv-map-generic: Make generated objects use 'UVMap' as name for their uv maps.

2022-12-13 Thread Martijn Versteegh
Commit: b255bb87cbf978d866038f15750bcbbdd2c57519
Author: Martijn Versteegh
Date:   Tue Dec 13 19:50:49 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rBb255bb87cbf978d866038f15750bcbbdd2c57519

Make generated objects use 'UVMap' as name for their uv maps.

Now the UVMaps are stored in a float2 attribute layer, the default
layername is 'Float2'. Using 'UVMap' as name for a uv map is more
descriptive.

===

M   source/blender/modifiers/intern/MOD_ocean.c
M   
source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_ico_sphere.cc

===

diff --git a/source/blender/modifiers/intern/MOD_ocean.c 
b/source/blender/modifiers/intern/MOD_ocean.c
index 6da94bd4f90..44ea944bc83 100644
--- a/source/blender/modifiers/intern/MOD_ocean.c
+++ b/source/blender/modifiers/intern/MOD_ocean.c
@@ -288,8 +288,8 @@ static Mesh *generate_ocean_geometry(OceanModifierData 
*omd, Mesh *mesh_orig, co
 
   /* add uvs */
   if (CustomData_number_of_layers(>ldata, CD_PROP_FLOAT2) < 
MAX_MTFACE) {
-gogd.mloopuvs = CustomData_add_layer(
->ldata, CD_PROP_FLOAT2, CD_SET_DEFAULT, NULL, polys_num * 4);
+gogd.mloopuvs = CustomData_add_layer_named(
+>ldata, CD_PROP_FLOAT2, CD_SET_DEFAULT, NULL, polys_num * 4, 
"UVMap");
 
 if (gogd.mloopuvs) { /* unlikely to fail */
   gogd.ix = 1.0 / gogd.rx;
diff --git 
a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_ico_sphere.cc 
b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_ico_sphere.cc
index 4d59d904405..623ff98fc0d 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_ico_sphere.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_ico_sphere.cc
@@ -35,7 +35,7 @@ static Mesh *create_ico_sphere_mesh(const int subdivisions, 
const float radius)
   bmesh_create_params.use_toolflags = true;
   const BMAllocTemplate allocsize = {0, 0, 0, 0};
   BMesh *bm = BM_mesh_create(, _create_params);
-  BM_data_layer_add_named(bm, >ldata, CD_PROP_FLOAT2, nullptr);
+  BM_data_layer_add_named(bm, >ldata, CD_PROP_FLOAT2, "UVMap");
   /* Make sure the associated bool layers exists as well.
* Normally this would be done when adding a UV layer via python
* or when copying from Mesh, but when we 'manually' create the UV layer

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


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

2022-12-13 Thread Martijn Versteegh
Commit: 2ba38549f6aaf5adce9a727ebc1bc7742e1e52fa
Author: Martijn Versteegh
Date:   Tue Dec 13 00:01:38 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB2ba38549f6aaf5adce9a727ebc1bc7742e1e52fa

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

===



===

diff --cc source/blender/blenkernel/intern/pbvh_uv_islands.cc
index 3ac4660fe15,21645e50e7e..c16ddfeaffb
--- a/source/blender/blenkernel/intern/pbvh_uv_islands.cc
+++ b/source/blender/blenkernel/intern/pbvh_uv_islands.cc
@@@ -115,8 -115,8 +115,8 @@@ static void mesh_data_init_primitives(M
  for (int j = 0; j < 3; j++) {
MeshUVVert uv_vert;
uv_vert.loop = tri.tri[j];
-   uv_vert.vertex = _data.vertices[mesh_data.mloop[uv_vert.loop].v];
+   uv_vert.vertex = _data.vertices[mesh_data.loops[uv_vert.loop].v];
 -  uv_vert.uv = mesh_data.mloopuv[uv_vert.loop].uv;
 +  uv_vert.uv = mesh_data.mloopuv[uv_vert.loop];
primitive.vertices.append(uv_vert);
  }
  mesh_data.primitives.append(primitive);
@@@ -215,16 -215,11 +215,11 @@@ static void mesh_data_init(MeshData 
mesh_data_init_primitive_uv_island_ids(mesh_data);
  }
  
- MeshData::MeshData(const MLoopTri *looptri,
-const int64_t looptri_len,
-const int64_t vert_len,
-const MLoop *mloop,
-const float2 *mloopuv)
- : looptri(looptri),
-   looptri_len(looptri_len),
-   vert_len(vert_len),
-   mloop(mloop),
-   mloopuv(mloopuv)
+ MeshData::MeshData(const Span looptris,
+const Span loops,
+const int verts_num,
 -   const Span mloopuv)
++   const Span mloopuv)
+ : looptris(looptris), verts_num(verts_num), loops(loops), mloopuv(mloopuv)
  {
mesh_data_init(*this);
  }
diff --cc source/blender/blenkernel/intern/pbvh_uv_islands.hh
index eb6f05e356c,4d81f5da00c..98dc0342883
--- a/source/blender/blenkernel/intern/pbvh_uv_islands.hh
+++ b/source/blender/blenkernel/intern/pbvh_uv_islands.hh
@@@ -92,11 -92,10 +92,10 @@@ struct MeshPrimitive 
   */
  struct MeshData {
   public:
-   const MLoopTri *looptri;
-   const int64_t looptri_len;
-   const int64_t vert_len;
-   const MLoop *mloop;
-   const float2 *mloopuv;
+   const Span looptris;
+   const int64_t verts_num;
+   const Span loops;
 -  const Span mloopuv;
++  const Span mloopuv;
  
Vector primitives;
Vector edges;
@@@ -105,11 -104,10 +104,10 @@@
int64_t uv_island_len;
  
   public:
-   explicit MeshData(const MLoopTri *looptri,
- const int64_t looptri_len,
- const int64_t vert_len,
- const MLoop *mloop,
- const float2 *mloopuv);
+   explicit MeshData(const Span looptris,
+ const Span loops,
+ const int verts_num,
 -const Span mloopuv);
++const Span mloopuv);
  };
  
  struct UVVertex {

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [d2feeef6683] refactor-mesh-uv-map-generic: Cleanup: make format

2022-12-13 Thread Martijn Versteegh
Commit: d2feeef6683dbb5d57d88f8c59110ab9ad698f53
Author: Martijn Versteegh
Date:   Mon Dec 12 23:56:12 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rBd2feeef6683dbb5d57d88f8c59110ab9ad698f53

Cleanup: make format

===

M   source/blender/bmesh/intern/bmesh_interp.c

===

diff --git a/source/blender/bmesh/intern/bmesh_interp.c 
b/source/blender/bmesh/intern/bmesh_interp.c
index 745257dd919..92fb0bf225a 100644
--- a/source/blender/bmesh/intern/bmesh_interp.c
+++ b/source/blender/bmesh/intern/bmesh_interp.c
@@ -876,15 +876,27 @@ void BM_data_layer_ensure_named(BMesh *bm, CustomData 
*data, int type, const cha
 void BM_uv_map_ensure_selection_and_pin_attributes(BMesh *bm)
 {
   const int nr_uv_layers = CustomData_number_of_layers(>ldata, 
CD_PROP_FLOAT2);
-  for (int l = 0; l < nr_uv_layers; l++ ) {
-/* note: you can't re-use the returnvalue of CustomData_get_layer_name() 
because adding layers can invalidate that. */
+  for (int l = 0; l < nr_uv_layers; l++) {
+/* note: you can't re-use the returnvalue of CustomData_get_layer_name() 
because adding layers
+ * can invalidate that. */
 char name[MAX_CUSTOMDATA_LAYER_NAME];
 BM_data_layer_ensure_named(
-bm, >ldata, CD_PROP_BOOL, 
BKE_get_uv_map_vert_selection_name(CustomData_get_layer_name(>ldata, 
CD_PROP_FLOAT2, l), name));
+bm,
+>ldata,
+CD_PROP_BOOL,
+BKE_get_uv_map_vert_selection_name(
+CustomData_get_layer_name(>ldata, CD_PROP_FLOAT2, l), name));
 BM_data_layer_ensure_named(
-bm, >ldata, CD_PROP_BOOL, 
BKE_get_uv_map_edge_selection_name(CustomData_get_layer_name(>ldata, 
CD_PROP_FLOAT2, l), name));
+bm,
+>ldata,
+CD_PROP_BOOL,
+BKE_get_uv_map_edge_selection_name(
+CustomData_get_layer_name(>ldata, CD_PROP_FLOAT2, l), name));
 BM_data_layer_ensure_named(
-bm, >ldata, CD_PROP_BOOL, 
BKE_get_uv_map_pin_name(CustomData_get_layer_name(>ldata, CD_PROP_FLOAT2, 
l), name));
+bm,
+>ldata,
+CD_PROP_BOOL,
+BKE_get_uv_map_pin_name(CustomData_get_layer_name(>ldata, 
CD_PROP_FLOAT2, l), name));
   }
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [1d5cdde29f1] refactor-mesh-uv-map-generic: Rename BM_uv_map_ensure_selection_pin_attributes.

2022-12-06 Thread Martijn Versteegh
Commit: 1d5cdde29f1a08807c19f35f8374745fe326e3d6
Author: Martijn Versteegh
Date:   Tue Dec 6 21:33:08 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB1d5cdde29f1a08807c19f35f8374745fe326e3d6

Rename BM_uv_map_ensure_selection_pin_attributes.

Rename it to BM_uv_map_ensure_selection_and_pin_attributes.

===

M   source/blender/bmesh/intern/bmesh_interp.c
M   source/blender/bmesh/intern/bmesh_interp.h
M   source/blender/editors/mesh/mesh_data.cc
M   
source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_ico_sphere.cc
M   source/blender/python/bmesh/bmesh_py_types_customdata.c

===

diff --git a/source/blender/bmesh/intern/bmesh_interp.c 
b/source/blender/bmesh/intern/bmesh_interp.c
index 6a8d7c99b8c..7c13b2e7663 100644
--- a/source/blender/bmesh/intern/bmesh_interp.c
+++ b/source/blender/bmesh/intern/bmesh_interp.c
@@ -873,7 +873,7 @@ void BM_data_layer_ensure_named(BMesh *bm, CustomData 
*data, int type, const cha
   }
 }
 
-void BM_uv_map_ensure_selection_pin_attributes(BMesh *bm, const char 
*uv_map_name)
+void BM_uv_map_ensure_selection_and_pin_attributes(BMesh *bm, const char 
*uv_map_name)
 {
   char name[MAX_CUSTOMDATA_LAYER_NAME];
   BM_data_layer_ensure_named(
diff --git a/source/blender/bmesh/intern/bmesh_interp.h 
b/source/blender/bmesh/intern/bmesh_interp.h
index f8bb45af1e7..0b7b5197074 100644
--- a/source/blender/bmesh/intern/bmesh_interp.h
+++ b/source/blender/bmesh/intern/bmesh_interp.h
@@ -65,7 +65,7 @@ void BM_data_layer_add_named(BMesh *bm, CustomData *data, int 
type, const char *
 void BM_data_layer_ensure_named(BMesh *bm, CustomData *data, int type, const 
char *name);
 void BM_data_layer_free(BMesh *bm, CustomData *data, int type);
 
-void BM_uv_map_ensure_selection_pin_attributes(BMesh *bm, const char 
*uv_map_name);
+void BM_uv_map_ensure_selection_and_pin_attributes(BMesh *bm, const char 
*uv_map_name);
 void BM_uv_map_ensure_vert_selection_attribute(BMesh *bm, const char 
*uv_map_name);
 void BM_uv_map_ensure_edge_selection_attribute(BMesh *bm, const char 
*uv_map_name);
 void BM_uv_map_ensure_pin_attribute(BMesh *bm, const char *uv_map_name);
diff --git a/source/blender/editors/mesh/mesh_data.cc 
b/source/blender/editors/mesh/mesh_data.cc
index 270d1dd2350..098bf62677a 100644
--- a/source/blender/editors/mesh/mesh_data.cc
+++ b/source/blender/editors/mesh/mesh_data.cc
@@ -246,7 +246,7 @@ int ED_mesh_uv_add(
 }
 
 BM_data_layer_add_named(em->bm, >bm->ldata, CD_PROP_FLOAT2, name);
-BM_uv_map_ensure_selection_pin_attributes(em->bm, name);
+BM_uv_map_ensure_selection_and_pin_attributes(em->bm, name);
 /* copy data from active UV */
 if (layernum_dst && do_init) {
   const int layernum_src = CustomData_get_active_layer(>bm->ldata, 
CD_PROP_FLOAT2);
diff --git 
a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_ico_sphere.cc 
b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_ico_sphere.cc
index e7b6f9b5205..2543b21e7fb 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_ico_sphere.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_ico_sphere.cc
@@ -36,8 +36,11 @@ static Mesh *create_ico_sphere_mesh(const int subdivisions, 
const float radius)
   const BMAllocTemplate allocsize = {0, 0, 0, 0};
   BMesh *bm = BM_mesh_create(, _create_params);
   BM_data_layer_add_named(bm, >ldata, CD_PROP_FLOAT2, nullptr);
-
-  BM_uv_map_ensure_selection_pin_attributes(
+  /* Make sure the associated bool layers exists as well.
+   * Normally this would be done when adding a UV layer via python
+   * or when copying from Mesh, but when we 'manually' create the UV layer
+   * we need to make sure the bool layers exist as well. */
+  BM_uv_map_ensure_selection_and_pin_attributes(
   bm, CustomData_get_layer_name(>ldata, CD_PROP_FLOAT2, 0));
 
   BMO_op_callf(bm,
diff --git a/source/blender/python/bmesh/bmesh_py_types_customdata.c 
b/source/blender/python/bmesh/bmesh_py_types_customdata.c
index 2bf288f22a3..659ec0bb104 100644
--- a/source/blender/python/bmesh/bmesh_py_types_customdata.c
+++ b/source/blender/python/bmesh/bmesh_py_types_customdata.c
@@ -468,7 +468,7 @@ static PyObject 
*bpy_bmlayercollection_verify(BPy_BMLayerCollection *self)
  * now. */
 const char *active_uv_name = 
CustomData_get_active_layer_name(>bm->ldata,
   
CD_PROP_FLOAT2);
-BM_uv_map_ensure_selection_pin_attributes(self->bm, active_uv_name);
+BM_uv_map_ensure_selection_and_pin_attributes(self->bm, active_uv_name);
   }
 
   BLI_assert(index >= 0);
@@ -517,7 +517,7 @@ static PyObject 
*bpy_bmlayercollection_new(BPy_BMLayerCollection *self, PyObject
  * now. */
 const char *active_uv_n

[Bf-blender-cvs] [95404396f82] refactor-mesh-uv-map-generic: Remove outdated comment.

2022-12-06 Thread Martijn Versteegh
Commit: 95404396f82d34f0b5e1e3fda9b640c728f5180a
Author: Martijn Versteegh
Date:   Tue Dec 6 21:34:09 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB95404396f82d34f0b5e1e3fda9b640c728f5180a

Remove outdated comment.

===

M   source/blender/python/bmesh/bmesh_py_types_meshdata.c

===

diff --git a/source/blender/python/bmesh/bmesh_py_types_meshdata.c 
b/source/blender/python/bmesh/bmesh_py_types_meshdata.c
index 5077bdce75d..c6c040b2768 100644
--- a/source/blender/python/bmesh/bmesh_py_types_meshdata.c
+++ b/source/blender/python/bmesh/bmesh_py_types_meshdata.c
@@ -74,11 +74,6 @@ static int bpy_bmloopuv_pin_uv_set(BPy_BMLoopUV *self, 
PyObject *value, void *UN
   if (self->pinned) {
 *self->pinned = PyC_Long_AsBool(value);
   }
-  /* TODO(martijn) if (!self->pinned) that means the layed does not exist , or 
at least didn't
-   * exist when the PY object was created. We *should* create it here instead 
of just bailing, but
-   * we can't because that would invalidate all existing BPy_BMLoopUV objects' 
interal pointers.
-   * the same goes for vertsel and edgesel below.
-   */
   return 0;
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


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

2022-12-06 Thread Martijn Versteegh
Commit: b2d30c95f8954082a382dfa36c7a2704de33a8ef
Author: Martijn Versteegh
Date:   Tue Dec 6 13:59:19 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rBb2d30c95f8954082a382dfa36c7a2704de33a8ef

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

===



===

diff --cc release/scripts/addons
index 63e1e6227af,0b0052bd53a..90c87dd771e
--- a/release/scripts/addons
+++ b/release/scripts/addons
@@@ -1,1 -1,1 +1,1 @@@
- Subproject commit 63e1e6227af42c1090fadc116e19b604d734a56c
 -Subproject commit 0b0052bd53ad8249ed07dfb87705c338af698bde
++Subproject commit 90c87dd771e027e0ffa157a0e294399bfd605d99
diff --cc source/blender/blenkernel/BKE_uv_islands.hh
index 000,406ecf39b71..3dc842bd510
mode 00,100644..100644
--- a/source/blender/blenkernel/BKE_uv_islands.hh
+++ b/source/blender/blenkernel/BKE_uv_islands.hh
@@@ -1,0 -1,746 +1,746 @@@
+ /* SPDX-License-Identifier: GPL-2.0-or-later */
+ 
+ #pragma once
+ 
+ #include 
+ #include 
+ 
+ #include "BLI_array.hh"
+ #include "BLI_edgehash.h"
+ #include "BLI_float3x3.hh"
+ #include "BLI_map.hh"
+ #include "BLI_math.h"
+ #include "BLI_math_vec_types.hh"
+ #include "BLI_rect.h"
+ #include "BLI_vector.hh"
+ #include "BLI_vector_list.hh"
+ 
+ #include "DNA_meshdata_types.h"
+ 
+ namespace blender::bke::uv_islands {
+ 
+ struct MeshEdge;
+ struct MeshPrimitive;
+ struct UVBorder;
+ struct UVEdge;
+ struct UVIslands;
+ struct UVIslandsMask;
+ struct UVPrimitive;
+ struct UVPrimitiveEdge;
+ struct UVVertex;
+ 
+ struct MeshVertex {
+   int64_t v;
+   Vector edges;
+ };
+ 
+ struct MeshUVVert {
+   MeshVertex *vertex;
+   float2 uv;
+   int64_t loop;
+ };
+ 
+ struct MeshEdge {
+   MeshVertex *vert1;
+   MeshVertex *vert2;
+   Vector primitives;
+ };
+ 
+ /** Represents a triangle in 3d space (MLoopTri) */
+ struct MeshPrimitive {
+   int64_t index;
+   int64_t poly;
+   Vector edges;
+   Vector vertices;
+ 
+   /**
+* UV island this primitive belongs to. This is used to speed up the 
initial uv island
+* extraction, but should not be used when extending uv islands.
+*/
+   int64_t uv_island_id;
+ 
+   MeshUVVert *get_other_uv_vertex(const MeshVertex *v1, const MeshVertex *v2)
+   {
+ BLI_assert(vertices[0].vertex == v1 || vertices[1].vertex == v1 || 
vertices[2].vertex == v1);
+ BLI_assert(vertices[0].vertex == v2 || vertices[1].vertex == v2 || 
vertices[2].vertex == v2);
+ for (MeshUVVert _vertex : vertices) {
+   if (uv_vertex.vertex != v1 && uv_vertex.vertex != v2) {
+ return _vertex;
+   }
+ }
+ return nullptr;
+   }
+ 
+   rctf uv_bounds() const;
+ 
+   bool has_shared_uv_edge(const MeshPrimitive *other) const
+   {
+ int shared_uv_verts = 0;
+ for (const MeshUVVert  : vertices) {
+   for (const MeshUVVert _vert : other->vertices) {
+ if (vert.uv == other_vert.uv) {
+   shared_uv_verts += 1;
+ }
+   }
+ }
+ return shared_uv_verts >= 2;
+   }
+ };
+ 
+ /**
+  * MeshData contains input geometry data converted in a list of primitives, 
edges and vertices for
+  * quick access for both local space and uv space.
+  */
+ struct MeshData {
+  public:
+   const MLoopTri *looptri;
+   const int64_t looptri_len;
+   const int64_t vert_len;
+   const MLoop *mloop;
 -  const MLoopUV *mloopuv;
++  const float2 *mloopuv;
+ 
+  public:
+   Vector primitives;
+   Vector edges;
+   Vector vertices;
+   /** Total number of uv islands detected. */
+   int64_t uv_island_len;
+ 
+   explicit MeshData(const MLoopTri *looptri,
+ const int64_t looptri_len,
+ const int64_t vert_len,
+ const MLoop *mloop,
 -const MLoopUV *mloopuv)
++const float2 *mloopuv)
+   : looptri(looptri),
+ looptri_len(looptri_len),
+ vert_len(vert_len),
+ mloop(mloop),
+ mloopuv(mloopuv)
+   {
+ init_vertices();
+ init_primitives();
+ init_edges();
+ init_primitive_uv_island_ids();
+   }
+ 
+   void init_vertices()
+   {
+ vertices.reserve(vert_len);
+ for (int64_t i = 0; i < vert_len; i++) {
+   MeshVertex vert;
+   vert.v = i;
+   vertices.append(vert);
+ }
+   }
+ 
+   void init_primitives()
+   {
+ primitives.reserve(looptri_len);
+ for (int64_t i = 0; i < looptri_len; i++) {
+   const MLoopTri  = looptri[i];
+   MeshPrimitive primitive;
+   primitive.index = i;
+   primitive.poly = tri.poly;
+ 
+   for (int j = 0; j < 3; j++) {
+ MeshUVVert uv_vert;
+ uv_vert.loop = tri.tri[j];
+ uv_vert.vertex = [mloop[uv_vert.loop].v];
 -uv_vert.uv = mloopuv[uv_vert.loop].uv;
++uv_v

[Bf-blender-cvs] [84b3e6c3e5e] refactor-mesh-uv-map-generic: Cleanup: make format

2022-12-06 Thread Martijn Versteegh
Commit: 84b3e6c3e5ef0d5311e6ab4aaf6f7275d0baf553
Author: Martijn Versteegh
Date:   Tue Dec 6 12:56:22 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB84b3e6c3e5ef0d5311e6ab4aaf6f7275d0baf553

Cleanup: make format

===

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/bmesh/intern/bmesh_interp.c
M   source/blender/bmesh/intern/bmesh_mesh_convert.cc
M   source/blender/editors/mesh/mesh_data.cc
M   source/blender/editors/sculpt_paint/paint_image_proj.cc

===

diff --git a/source/blender/blenkernel/intern/attribute.cc 
b/source/blender/blenkernel/intern/attribute.cc
index 9be3d627b76..3fc93f981d7 100644
--- a/source/blender/blenkernel/intern/attribute.cc
+++ b/source/blender/blenkernel/intern/attribute.cc
@@ -838,4 +838,3 @@ char const *BKE_get_uv_map_pin_name(char const 
*uv_map_name, char *buffer)
   BLI_snprintf(buffer, MAX_CUSTOMDATA_LAYER_NAME, ".%s.%s", UV_PINNED_NAME, 
uv_map_name);
   return buffer;
 }
-
diff --git a/source/blender/blenkernel/intern/customdata.cc 
b/source/blender/blenkernel/intern/customdata.cc
index 938789eb9ac..a3d3c0a26c6 100644
--- a/source/blender/blenkernel/intern/customdata.cc
+++ b/source/blender/blenkernel/intern/customdata.cc
@@ -4171,9 +4171,9 @@ void CustomData_from_bmesh_block(const CustomData *source,
   int dest_i = 0;
   for (int src_i = 0; src_i < source->totlayer; src_i++) {
 
- if (source->layers[src_i].flag & CD_FLAG_NOCOPY) {
-   continue;
- }
+if (source->layers[src_i].flag & CD_FLAG_NOCOPY) {
+  continue;
+}
 
 /* find the first dest layer with type >= the source type
  * (this should work because layers are ordered by type)
diff --git a/source/blender/blenkernel/intern/mesh_legacy_convert.cc 
b/source/blender/blenkernel/intern/mesh_legacy_convert.cc
index 691705c4d0a..7ede253519e 100644
--- a/source/blender/blenkernel/intern/mesh_legacy_convert.cc
+++ b/source/blender/blenkernel/intern/mesh_legacy_convert.cc
@@ -1477,9 +1477,10 @@ void BKE_mesh_legacy_convert_uvs_to_struct(
   char edge_name[MAX_CUSTOMDATA_LAYER_NAME];
   char pin_name[MAX_CUSTOMDATA_LAYER_NAME];
   for (const CustomDataLayer  : face_corner_layers_to_write) {
-
uv_sublayers_to_skip.add_multiple_new({BKE_get_uv_map_vert_selection_name(layer.name,
 vert_name),
-   
BKE_get_uv_map_edge_selection_name(layer.name, edge_name),
-   BKE_get_uv_map_pin_name(layer.name, 
pin_name)});
+uv_sublayers_to_skip.add_multiple_new(
+{BKE_get_uv_map_vert_selection_name(layer.name, vert_name),
+ BKE_get_uv_map_edge_selection_name(layer.name, edge_name),
+ BKE_get_uv_map_pin_name(layer.name, pin_name)});
   }
 
   for (const CustomDataLayer  : face_corner_layers_to_write) {
diff --git a/source/blender/bmesh/intern/bmesh_interp.c 
b/source/blender/bmesh/intern/bmesh_interp.c
index 29e754fc683..6a8d7c99b8c 100644
--- a/source/blender/bmesh/intern/bmesh_interp.c
+++ b/source/blender/bmesh/intern/bmesh_interp.c
@@ -880,7 +880,8 @@ void BM_uv_map_ensure_selection_pin_attributes(BMesh *bm, 
const char *uv_map_nam
   bm, >ldata, CD_PROP_BOOL, 
BKE_get_uv_map_vert_selection_name(uv_map_name, name));
   BM_data_layer_ensure_named(
   bm, >ldata, CD_PROP_BOOL, 
BKE_get_uv_map_edge_selection_name(uv_map_name, name));
-  BM_data_layer_ensure_named(bm, >ldata, CD_PROP_BOOL, 
BKE_get_uv_map_pin_name(uv_map_name, name));
+  BM_data_layer_ensure_named(
+  bm, >ldata, CD_PROP_BOOL, BKE_get_uv_map_pin_name(uv_map_name, 
name));
 }
 
 void BM_uv_map_ensure_vert_selection_attribute(BMesh *bm, const char 
*uv_map_name)
@@ -900,7 +901,8 @@ void BM_uv_map_ensure_edge_selection_attribute(BMesh *bm, 
const char *uv_map_nam
 void BM_uv_map_ensure_pin_attribute(BMesh *bm, const char *uv_map_name)
 {
   char name[MAX_CUSTOMDATA_LAYER_NAME];
-  BM_data_layer_ensure_named(bm, >ldata, CD_PROP_BOOL, 
BKE_get_uv_map_pin_name(uv_map_name, name));
+  BM_data_layer_ensure_named(
+  bm, >ldata, CD_PROP_BOOL, BKE_get_uv_map_pin_name(uv_map_name, 
name));
 }
 
 void BM_data_layer_free(BMesh *bm, CustomData *data, int type)
diff --git a/source/blender/bmesh/intern/bmesh_mesh_convert.cc 
b/source/blender/bmesh/intern/bmesh_mesh_convert.cc
index d7a2dc1c16d..22d28a67030 100644
--- a/source/blender/bmesh/intern/bmesh_mesh_convert.cc
+++ b/source/blender/bmesh/intern/bmesh_mesh_convert.cc
@@ -154,14 +154,14 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const 
struct BMeshFromMeshPar
   for (const int l : IndexRange(CustomData_number_of_layers(_ldata, 
CD_PROP_FLOAT2))) {
 char name[MAX_CUSTOMDATA_LAYER_NAME];
 BKE_get_u

[Bf-blender-cvs] [02a1342641a] refactor-mesh-uv-map-generic: Create dependent layers for all uv layers created via python API.

2022-12-06 Thread Martijn Versteegh
Commit: 02a1342641aae9f2c527759518272ec9df855feb
Author: Martijn Versteegh
Date:   Tue Dec 6 11:33:46 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB02a1342641aae9f2c527759518272ec9df855feb

Create dependent layers for all uv layers created via python API.

===

M   source/blender/python/bmesh/bmesh_py_types_customdata.c

===

diff --git a/source/blender/python/bmesh/bmesh_py_types_customdata.c 
b/source/blender/python/bmesh/bmesh_py_types_customdata.c
index 9aea303aca5..2bf288f22a3 100644
--- a/source/blender/python/bmesh/bmesh_py_types_customdata.c
+++ b/source/blender/python/bmesh/bmesh_py_types_customdata.c
@@ -511,6 +511,15 @@ static PyObject 
*bpy_bmlayercollection_new(BPy_BMLayerCollection *self, PyObject
 BM_data_layer_add(self->bm, data, self->type);
   }
 
+  if (self->type == CD_PROP_FLOAT2 && self->htype == BM_LOOP) {
+/* Because adding CustomData layers to a bmesh will invalidate any 
existing pointers
+ * in Py objects we can't lazily add the associated bool layers. So add 
them all right
+ * now. */
+const char *active_uv_name = 
CustomData_get_active_layer_name(>bm->ldata,
+  
CD_PROP_FLOAT2);
+BM_uv_map_ensure_selection_pin_attributes(self->bm, active_uv_name);
+  }
+
   index = CustomData_number_of_layers(data, self->type) - 1;
   BLI_assert(index >= 0);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [62734ea67cd] refactor-mesh-uv-map-generic: When syncing BMesh to mesh, skip all-empty bool layers by marking them as NOCOPY.

2022-12-06 Thread Martijn Versteegh
Commit: 62734ea67cd4da6f03aeab179dc4ece951e2cf82
Author: Martijn Versteegh
Date:   Tue Dec 6 11:32:26 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB62734ea67cd4da6f03aeab179dc4ece951e2cf82

When syncing BMesh to mesh, skip all-empty bool layers by marking them as 
NOCOPY.

===

M   source/blender/bmesh/intern/bmesh_mesh_convert.cc

===

diff --git a/source/blender/bmesh/intern/bmesh_mesh_convert.cc 
b/source/blender/bmesh/intern/bmesh_mesh_convert.cc
index 854445572ea..d7a2dc1c16d 100644
--- a/source/blender/bmesh/intern/bmesh_mesh_convert.cc
+++ b/source/blender/bmesh/intern/bmesh_mesh_convert.cc
@@ -984,6 +984,53 @@ void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, 
const struct BMeshToMesh
   me->totface = 0;
   me->act_face = -1;
 
+  /* Mark uv selection layers which are all false as 'nocopy'
+   */
+
+
+  for (const int l : IndexRange(CustomData_number_of_layers(>ldata, 
CD_PROP_FLOAT2))) {
+char const *layer_name = CustomData_get_layer_name(>ldata, 
CD_PROP_FLOAT2, l);
+char sub_layer_name[MAX_CUSTOMDATA_LAYER_NAME];
+int vertsel_layer_index = CustomData_get_named_layer_index(>ldata, 
CD_PROP_BOOL, BKE_get_uv_map_vert_selection_name(layer_name, sub_layer_name));
+int edgesel_layer_index = CustomData_get_named_layer_index(>ldata, 
CD_PROP_BOOL, BKE_get_uv_map_edge_selection_name(layer_name, sub_layer_name));
+int pin_layer_index = CustomData_get_named_layer_index(>ldata, 
CD_PROP_BOOL, BKE_get_uv_map_pin_name(layer_name, sub_layer_name));
+int vertsel_offset = bm->ldata.layers[vertsel_layer_index].offset;
+int edgesel_offset = bm->ldata.layers[edgesel_layer_index].offset;
+int pin_offset = bm->ldata.layers[pin_layer_index].offset;
+bool need_vertsel = false;
+bool need_edgesel = false;
+bool need_pin = false;
+
+BM_ITER_MESH (f, , bm, BM_FACES_OF_MESH) {
+  BMIter liter;
+  BMLoop *l;
+  BM_ITER_ELEM (l, , f, BM_LOOPS_OF_FACE) {
+  need_vertsel |= BM_ELEM_CD_GET_BOOL(l, vertsel_offset);
+  need_edgesel |= BM_ELEM_CD_GET_BOOL(l, edgesel_offset);
+  need_pin |= BM_ELEM_CD_GET_BOOL(l, pin_offset);
+  }
+}
+
+if (need_vertsel) {
+bm->ldata.layers[vertsel_layer_index].flag &= ~CD_FLAG_NOCOPY;
+} else {
+bm->ldata.layers[vertsel_layer_index].flag |= CD_FLAG_NOCOPY;
+}
+if (need_edgesel) {
+bm->ldata.layers[edgesel_layer_index].flag &= ~CD_FLAG_NOCOPY;
+} else {
+bm->ldata.layers[edgesel_layer_index].flag |= CD_FLAG_NOCOPY;
+}
+if (need_pin) {
+bm->ldata.layers[pin_layer_index].flag &= ~CD_FLAG_NOCOPY;
+} else {
+bm->ldata.layers[pin_layer_index].flag |= CD_FLAG_NOCOPY;
+}
+
+
+  }
+
+
   {
 CustomData_MeshMasks mask = CD_MASK_MESH;
 CustomData_MeshMasks_update(, >cd_mask_extra);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [6b8321ea99d] refactor-mesh-uv-map-generic: Do not inline get_uv_map_*_name()

2022-12-06 Thread Martijn Versteegh
Commit: 6b8321ea99dcdab294695667b2494fe9a55cfd12
Author: Martijn Versteegh
Date:   Tue Nov 29 23:05:26 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB6b8321ea99dcdab294695667b2494fe9a55cfd12

Do not inline get_uv_map_*_name()

Rename get_uv_map_*_name() to BKE_get_uv_map_*_name() and moved them
to the .cc file. Don't inline them.

===

M   source/blender/blenkernel/BKE_attribute.h
M   source/blender/blenkernel/intern/attribute.cc
M   source/blender/blenkernel/intern/mesh_legacy_convert.cc
M   source/blender/bmesh/intern/bmesh_interp.c
M   source/blender/bmesh/intern/bmesh_mesh_convert.cc
M   source/blender/bmesh/intern/bmesh_query_uv.cc
M   source/blender/editors/mesh/mesh_data.cc

===

diff --git a/source/blender/blenkernel/BKE_attribute.h 
b/source/blender/blenkernel/BKE_attribute.h
index 236cc44a77f..18a8d473f0e 100644
--- a/source/blender/blenkernel/BKE_attribute.h
+++ b/source/blender/blenkernel/BKE_attribute.h
@@ -141,41 +141,9 @@ struct CustomDataLayer *BKE_id_attributes_color_find(const 
struct ID *id, const
 
 bool BKE_id_attribute_calc_unique_name(struct ID *id, const char *name, char 
*outname);
 
-inline char const *get_uv_map_vert_selection_name(char const *uv_map_name, 
char *buffer)
-{
-  size_t len = strlen(uv_map_name);
-
-  BLI_assert(strlen(UV_VERTSEL_NAME) == 2);
-  if (len >= MAX_CUSTOMDATA_LAYER_NAME - 5) {
-/* TODO(martijn) come up with a way to generate a non-colliding 
shortening... */
-  }
-  BLI_snprintf(buffer, MAX_CUSTOMDATA_LAYER_NAME, ".%s.%s", UV_VERTSEL_NAME, 
uv_map_name);
-  return buffer;
-}
-
-inline char const *get_uv_map_edge_selection_name(char const *uv_map_name, 
char *buffer)
-{
-  size_t len = strlen(uv_map_name);
-
-  BLI_assert(strlen(UV_VERTSEL_NAME) == 2);
-  if (len >= MAX_CUSTOMDATA_LAYER_NAME - 5) {
-/* TODO(martijn) come up with a way to generate a non-colliding 
shortening... */
-  }
-  BLI_snprintf(buffer, MAX_CUSTOMDATA_LAYER_NAME, ".%s.%s", UV_EDGESEL_NAME, 
uv_map_name);
-  return buffer;
-}
-
-inline char const *get_uv_map_pin_name(char const *uv_map_name, char *buffer)
-{
-  size_t len = strlen(uv_map_name);
-
-  BLI_assert(strlen(UV_VERTSEL_NAME) == 2);
-  if (len >= MAX_CUSTOMDATA_LAYER_NAME - 5) {
-/* TODO(martijn) come up with a way to generate a non-colliding 
shortening... */
-  }
-  BLI_snprintf(buffer, MAX_CUSTOMDATA_LAYER_NAME, ".%s.%s", UV_PINNED_NAME, 
uv_map_name);
-  return buffer;
-}
+char const *BKE_get_uv_map_vert_selection_name(char const *uv_map_name, char 
*buffer);
+char const *BKE_get_uv_map_edge_selection_name(char const *uv_map_name, char 
*buffer);
+char const *BKE_get_uv_map_pin_name(char const *uv_map_name, char *buffer);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/blenkernel/intern/attribute.cc 
b/source/blender/blenkernel/intern/attribute.cc
index d9f8baeda1a..9be3d627b76 100644
--- a/source/blender/blenkernel/intern/attribute.cc
+++ b/source/blender/blenkernel/intern/attribute.cc
@@ -173,16 +173,16 @@ bool BKE_id_attribute_rename(ID *id,
 char buffer_src[MAX_CUSTOMDATA_LAYER_NAME];
 char buffer_dst[MAX_CUSTOMDATA_LAYER_NAME];
 BKE_id_attribute_rename(id,
-get_uv_map_vert_selection_name(layer->name, 
buffer_src),
-get_uv_map_vert_selection_name(result_name, 
buffer_dst),
+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,
-get_uv_map_edge_selection_name(layer->name, 
buffer_src),
-get_uv_map_edge_selection_name(result_name, 
buffer_dst),
+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,
-get_uv_map_pin_name(layer->name, buffer_src),
-get_uv_map_pin_name(result_name, buffer_dst),
+BKE_get_uv_map_pin_name(layer->name, buffer_src),
+BKE_get_uv_map_pin_name(result_name, buffer_dst),
 reports);
   }
 
@@ -814,3 +814,28 @@ void BKE_id_attribute_copy_domains_temp(short id_type,
 
   *((short *)r_id->name) = id_type;
 }
+
+char const *BKE_get_uv_map_vert_selection_name(char const *uv_map_name, char 
*buffer)
+{
+  BLI_assert(strlen(UV_VERTSEL_NAME) == 2);
+  BLI_assert(strlen(uv_map_name) < MAX_CUSTOMDATA_LAYER_NAME - 5);
+  BLI_snprintf(buffer, MAX_CUSTOMDATA_LAYER_NAME, ".%s.%s&

[Bf-blender-cvs] [655db600b60] refactor-mesh-uv-map-generic: Skip layers marked as 'NOCOPY' when converting BMesh CData to Mesh.

2022-12-06 Thread Martijn Versteegh
Commit: 655db600b60a1f7516a5467f4fc13bb91dcb1e4f
Author: Martijn Versteegh
Date:   Tue Dec 6 11:31:32 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB655db600b60a1f7516a5467f4fc13bb91dcb1e4f

Skip layers marked as 'NOCOPY' when converting BMesh CData to Mesh.

===

M   source/blender/blenkernel/intern/customdata.cc

===

diff --git a/source/blender/blenkernel/intern/customdata.cc 
b/source/blender/blenkernel/intern/customdata.cc
index c6d7dea6ad2..938789eb9ac 100644
--- a/source/blender/blenkernel/intern/customdata.cc
+++ b/source/blender/blenkernel/intern/customdata.cc
@@ -4171,6 +4171,10 @@ void CustomData_from_bmesh_block(const CustomData 
*source,
   int dest_i = 0;
   for (int src_i = 0; src_i < source->totlayer; src_i++) {
 
+ if (source->layers[src_i].flag & CD_FLAG_NOCOPY) {
+   continue;
+ }
+
 /* find the first dest layer with type >= the source type
  * (this should work because layers are ordered by type)
  */

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [fc1273ea26b] refactor-mesh-uv-map-generic: Fix comment location and simplify calling ensure() functions

2022-12-06 Thread Martijn Versteegh
Commit: fc1273ea26baac2c03851c843adba7479bd56be6
Author: Martijn Versteegh
Date:   Tue Nov 29 23:08:24 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rBfc1273ea26baac2c03851c843adba7479bd56be6

Fix comment location and simplify calling ensure() functions

===

M   source/blender/python/bmesh/bmesh_py_types_customdata.c

===

diff --git a/source/blender/python/bmesh/bmesh_py_types_customdata.c 
b/source/blender/python/bmesh/bmesh_py_types_customdata.c
index 0639d34e68c..9aea303aca5 100644
--- a/source/blender/python/bmesh/bmesh_py_types_customdata.c
+++ b/source/blender/python/bmesh/bmesh_py_types_customdata.c
@@ -461,17 +461,14 @@ static PyObject 
*bpy_bmlayercollection_verify(BPy_BMLayerCollection *self)
   if (index == -1) {
 BM_data_layer_add(self->bm, data, self->type);
 index = 0;
-/* Because adding CustomData layers to a bmesh will invalidate any 
existing pointers
- * in Py objects we can't lazily add the associated bool layers. So add 
them all right
- * now.
- */
   }
   if (self->type == CD_PROP_FLOAT2 && self->htype == BM_LOOP) {
+/* Because adding CustomData layers to a bmesh will invalidate any 
existing pointers
+ * in Py objects we can't lazily add the associated bool layers. So add 
them all right
+ * now. */
 const char *active_uv_name = 
CustomData_get_active_layer_name(>bm->ldata,
   
CD_PROP_FLOAT2);
-BM_uv_map_ensure_vert_selection_attribute(self->bm, active_uv_name);
-BM_uv_map_ensure_edge_selection_attribute(self->bm, active_uv_name);
-BM_uv_map_ensure_pin_attribute(self->bm, active_uv_name);
+BM_uv_map_ensure_selection_pin_attributes(self->bm, active_uv_name);
   }
 
   BLI_assert(index >= 0);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [a7368551d9b] refactor-mesh-uv-map-generic: Remove unnecessary include.

2022-12-06 Thread Martijn Versteegh
Commit: a7368551d9b33944d2790262f42354e566363de2
Author: Martijn Versteegh
Date:   Tue Nov 29 23:07:02 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rBa7368551d9b33944d2790262f42354e566363de2

Remove unnecessary include.

===

M   
source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_ico_sphere.cc

===

diff --git 
a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_ico_sphere.cc 
b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_ico_sphere.cc
index 89945fdf87a..e7b6f9b5205 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_ico_sphere.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_ico_sphere.cc
@@ -7,7 +7,6 @@
 #include "BKE_mesh.h"
 
 #include "bmesh.h"
-#include "intern/bmesh_interp.h"
 
 #include "node_geometry_util.hh"

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [e257e2e0759] blender-v3.3-release: Fix: Link drag search crash with incorrect socket name in switch node

2022-11-28 Thread Martijn Versteegh
Commit: e257e2e0759294c915db26db94f7af6cce2a903e
Author: Martijn Versteegh
Date:   Tue Nov 15 21:47:57 2022 +0100
Branches: blender-v3.3-release
https://developer.blender.org/rBe257e2e0759294c915db26db94f7af6cce2a903e

Fix: Link drag search crash with incorrect socket name in switch node

When dragging out a boolean noodle, releasing and choosing
'switch > Switch' from the search popup, the code would mistakenly
search for 'Start' instead of 'Switch'.

Also the function called was not exactly the right one, leading to the
node being marked as invalid.

Reviewed By: Jacques Lucke

Differential Revision: https://developer.blender.org/D16512

===

M   source/blender/nodes/geometry/nodes/node_geo_switch.cc

===

diff --git a/source/blender/nodes/geometry/nodes/node_geo_switch.cc 
b/source/blender/nodes/geometry/nodes/node_geo_switch.cc
index ddc87e3dac4..11e7f40c1c5 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_switch.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_switch.cc
@@ -123,7 +123,7 @@ static void 
node_gather_link_searches(GatherLinkSearchOpParams )
 if (params.other_socket().type == SOCK_BOOLEAN) {
   params.add_item(IFACE_("Switch"), [](LinkSearchOpParams ) {
 bNode  = params.add_node("GeometryNodeSwitch");
-params.connect_available_socket(node, "Start");
+params.update_and_connect_available_socket(node, "Switch");
   });
 }
 params.add_item(IFACE_("False"), [](LinkSearchOpParams ) {

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [4696a27c65f] refactor-mesh-uv-map-generic: Fix accidentally committed typo.

2022-11-25 Thread Martijn Versteegh
Commit: 4696a27c65f58f59cc702b1fe8ad13bc53ecd1c3
Author: Martijn Versteegh
Date:   Fri Nov 25 23:48:42 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB4696a27c65f58f59cc702b1fe8ad13bc53ecd1c3

Fix accidentally committed typo.

===

M   source/blender/editors/sculpt_paint/paint_image_proj.cc

===

diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.cc 
b/source/blender/editors/sculpt_paint/paint_image_proj.cc
index 45ffdcebc08..fb0191de298 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.cc
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.cc
@@ -4112,7 +4112,7 @@ static void proj_paint_layer_clone_init(ProjPaintState 
*ps, ProjPaintLayerClone
 MEM_mallocN(ps->totpoly_eval * sizeof(float(*)[2]), 
"proj_paint_mtfaces"));
 
 if (layer_num != -1) {
-  mloopuv_clone_base = static_cast < const 
float(*)[2](CustomData_get_layer_n(
+  mloopuv_clone_base = static_cast (CustomData_get_layer_n(
  >me_eval->ldata, 
CD_PROP_FLOAT2, layer_num));
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [5dde38214fe] refactor-mesh-uv-map-generic: Cleanup: clang-format

2022-11-24 Thread Martijn Versteegh
Commit: 5dde38214fe51fce52d2d72b92918816cdaff91a
Author: Martijn Versteegh
Date:   Thu Nov 24 21:36:11 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB5dde38214fe51fce52d2d72b92918816cdaff91a

Cleanup: clang-format

===

M   source/blender/bmesh/intern/bmesh_mesh_convert.cc
M   source/blender/draw/intern/draw_manager_data.cc
M   source/blender/editors/sculpt_paint/paint_image_proj.cc
M   source/blender/editors/uvedit/uvedit_ops.c
M   
source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_ico_sphere.cc
M   source/blender/python/bmesh/bmesh_py_types_customdata.c

===

diff --git a/source/blender/bmesh/intern/bmesh_mesh_convert.cc 
b/source/blender/bmesh/intern/bmesh_mesh_convert.cc
index 08d971f48be..58ae011e093 100644
--- a/source/blender/bmesh/intern/bmesh_mesh_convert.cc
+++ b/source/blender/bmesh/intern/bmesh_mesh_convert.cc
@@ -151,33 +151,33 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const 
struct BMeshFromMeshPar
 
   blender::Vector temporary_layers_to_delete;
 
-  for (size_t l = 0; l < CustomData_number_of_layers(_ldata, 
CD_PROP_FLOAT2); l++)
-  {
+  for (size_t l = 0; l < CustomData_number_of_layers(_ldata, 
CD_PROP_FLOAT2); l++) {
 char name[MAX_CUSTOMDATA_LAYER_NAME];
-get_uv_map_vert_selection_name(CustomData_get_layer_name(_ldata, 
CD_PROP_FLOAT2, l), name);
-if (CustomData_get_named_layer_index(_ldata, CD_PROP_BOOL, name) < 0)
-{
-CustomData_add_layer_named(_ldata, CD_PROP_BOOL, CD_SET_DEFAULT, 
nullptr, me->totloop, name);
-temporary_layers_to_delete.append(std::string(name));
+get_uv_map_vert_selection_name(CustomData_get_layer_name(_ldata, 
CD_PROP_FLOAT2, l),
+   name);
+if (CustomData_get_named_layer_index(_ldata, CD_PROP_BOOL, name) < 0) 
{
+  CustomData_add_layer_named(
+  _ldata, CD_PROP_BOOL, CD_SET_DEFAULT, nullptr, me->totloop, 
name);
+  temporary_layers_to_delete.append(std::string(name));
 }
-get_uv_map_edge_selection_name(CustomData_get_layer_name(_ldata, 
CD_PROP_FLOAT2, l), name);
-if (CustomData_get_named_layer_index(_ldata, CD_PROP_BOOL, name) < 0)
-{
-CustomData_add_layer_named(_ldata, CD_PROP_BOOL, CD_SET_DEFAULT, 
nullptr, me->totloop, name);
-temporary_layers_to_delete.append(std::string(name));
+get_uv_map_edge_selection_name(CustomData_get_layer_name(_ldata, 
CD_PROP_FLOAT2, l),
+   name);
+if (CustomData_get_named_layer_index(_ldata, CD_PROP_BOOL, name) < 0) 
{
+  CustomData_add_layer_named(
+  _ldata, CD_PROP_BOOL, CD_SET_DEFAULT, nullptr, me->totloop, 
name);
+  temporary_layers_to_delete.append(std::string(name));
 }
 get_uv_map_pin_name(CustomData_get_layer_name(_ldata, CD_PROP_FLOAT2, 
l), name);
-if (CustomData_get_named_layer_index(_ldata, CD_PROP_BOOL, name) < 0)
-{
-CustomData_add_layer_named(_ldata, CD_PROP_BOOL, CD_SET_DEFAULT, 
nullptr, me->totloop, name);
-temporary_layers_to_delete.append(std::string(name));
+if (CustomData_get_named_layer_index(_ldata, CD_PROP_BOOL, name) < 0) 
{
+  CustomData_add_layer_named(
+  _ldata, CD_PROP_BOOL, CD_SET_DEFAULT, nullptr, me->totloop, 
name);
+  temporary_layers_to_delete.append(std::string(name));
 }
   }
 
   BLI_SCOPED_DEFER([&]() {
-for (auto n : temporary_layers_to_delete)
-{
-CustomData_free_layer_named(_ldata, n.c_str(), me->totloop);
+for (auto n : temporary_layers_to_delete) {
+  CustomData_free_layer_named(_ldata, n.c_str(), me->totloop);
 }
 
 MEM_SAFE_FREE(mesh_vdata.layers);
diff --git a/source/blender/draw/intern/draw_manager_data.cc 
b/source/blender/draw/intern/draw_manager_data.cc
index b398acd9aab..dfbe8355cb3 100644
--- a/source/blender/draw/intern/draw_manager_data.cc
+++ b/source/blender/draw/intern/draw_manager_data.cc
@@ -695,7 +695,7 @@ static void drw_call_obinfos_init(DRWObjectInfos *ob_infos, 
Object *ob)
   drw_call_calc_orco(ob, ob_infos->orcotexfac);
   /* Random float value. */
   uint random = (DST.dupli_source) ?
- DST.dupli_source->random_id :
+DST.dupli_source->random_id :
  /* TODO(fclem): this is rather costly to do at runtime. 
Maybe we can
   * put it in ob->runtime and make depsgraph ensure it is 
up to date. */
  BLI_hash_int_2d(BLI_hash_string(ob->id.name + 2), 0);
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.cc 
b/source/blender/editors/sculpt_paint/paint_image_proj.cc
index 60728f26e79..45ffdcebc08 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.cc
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c

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

2022-11-24 Thread Martijn Versteegh
Commit: 2d5c8b0a9cb02db756fb252f49229a17cbc4afb8
Author: Martijn Versteegh
Date:   Thu Nov 24 21:28:31 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB2d5c8b0a9cb02db756fb252f49229a17cbc4afb8

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

===



===

diff --cc source/blender/blenkernel/intern/mesh.cc
index 35ac5634af9,02d375bd782..d26f381cbdc
--- a/source/blender/blenkernel/intern/mesh.cc
+++ b/source/blender/blenkernel/intern/mesh.cc
@@@ -276,12 -275,10 +276,14 @@@ static void mesh_blend_write(BlendWrite
  CustomData_blend_write_prepare(mesh->edata, edge_layers, names_to_skip);
  CustomData_blend_write_prepare(mesh->ldata, loop_layers, names_to_skip);
  CustomData_blend_write_prepare(mesh->pdata, poly_layers, names_to_skip);
 +
 +if (!BLO_write_is_undo(writer)) {
 +  BKE_mesh_legacy_convert_uvs_to_struct(mesh, 
temp_arrays_for_legacy_format, loop_layers);
 +}
}
  
+   mesh->runtime = nullptr;
+ 
BLO_write_id_struct(writer, Mesh, id_address, >id);
BKE_id_blend_write(writer, >id);
  
diff --cc source/blender/bmesh/intern/bmesh_interp.c
index fdae1d71f04,8ceefc94d8a..ab7978d7d70
--- a/source/blender/bmesh/intern/bmesh_interp.c
+++ b/source/blender/bmesh/intern/bmesh_interp.c
@@@ -874,58 -864,17 +866,54 @@@ void BM_data_layer_add_named(BMesh *bm
}
  }
  
 +void BM_data_layer_ensure_named(BMesh *bm, CustomData *data, int type, const 
char *name)
 +{
 +  if (CustomData_get_named_layer_index(data, type, name) == -1) {
 +BM_data_layer_add_named(bm, data, type, name);
 +  }
 +}
 +
 +void BM_uv_map_ensure_selection_pin_attributes(BMesh *bm, const char 
*uv_map_name)
 +{
 +  char name[MAX_CUSTOMDATA_LAYER_NAME];
 +  BM_data_layer_ensure_named(
 +  bm, >ldata, CD_PROP_BOOL, 
get_uv_map_vert_selection_name(uv_map_name, name));
 +  BM_data_layer_ensure_named(
 +  bm, >ldata, CD_PROP_BOOL, 
get_uv_map_edge_selection_name(uv_map_name, name));
 +  BM_data_layer_ensure_named(bm, >ldata, CD_PROP_BOOL, 
get_uv_map_pin_name(uv_map_name, name));
 +}
 +
 +void BM_uv_map_ensure_vert_selection_attribute(BMesh *bm, const char 
*uv_map_name)
 +{
 +  char name[MAX_CUSTOMDATA_LAYER_NAME];
 +  BM_data_layer_ensure_named(
 +  bm, >ldata, CD_PROP_BOOL, 
get_uv_map_vert_selection_name(uv_map_name, name));
 +}
 +
 +void BM_uv_map_ensure_edge_selection_attribute(BMesh *bm, const char 
*uv_map_name)
 +{
 +  char name[MAX_CUSTOMDATA_LAYER_NAME];
 +  BM_data_layer_ensure_named(
 +  bm, >ldata, CD_PROP_BOOL, 
get_uv_map_edge_selection_name(uv_map_name, name));
 +}
 +
 +void BM_uv_map_ensure_pin_attribute(BMesh *bm, const char *uv_map_name)
 +{
 +  char name[MAX_CUSTOMDATA_LAYER_NAME];
 +  BM_data_layer_ensure_named(bm, >ldata, CD_PROP_BOOL, 
get_uv_map_pin_name(uv_map_name, name));
 +}
 +
  void BM_data_layer_free(BMesh *bm, CustomData *data, int type)
  {
-   CustomData olddata;
-   bool has_layer;
- 
-   olddata = *data;
+   CustomData olddata = *data;
olddata.layers = (olddata.layers) ? MEM_dupallocN(olddata.layers) : NULL;
- 
-   /* the pool is now owned by olddata and must not be shared */
+   /* The pool is now owned by `olddata` and must not be shared. */
data->pool = NULL;
  
-   has_layer = CustomData_free_layer_active(data, type, 0);
+   const bool had_layer = CustomData_free_layer_active(data, type, 0);
/* Assert because its expensive to realloc - better not do if layer isn't 
present. */
-   BLI_assert(has_layer != false);
-   UNUSED_VARS_NDEBUG(has_layer);
+   BLI_assert(had_layer != false);
+   UNUSED_VARS_NDEBUG(had_layer);
  
update_data_blocks(bm, , data);
if (olddata.layers) {
diff --cc source/blender/editors/include/ED_mesh.h
index 76f7e3b2c3e,bab1f7e4c5e..b717a9d4b4e
--- a/source/blender/editors/include/ED_mesh.h
+++ b/source/blender/editors/include/ED_mesh.h
@@@ -552,13 -552,8 +552,15 @@@ void ED_mesh_geometry_clear(struct Mes
  
  void ED_mesh_update(struct Mesh *mesh, struct bContext *C, bool calc_edges, 
bool calc_edges_loose);
  
 +bool *ED_mesh_uv_map_ensure_vert_selection(struct Mesh *mesh, int uv_index);
 +bool *ED_mesh_uv_map_ensure_edge_selection(struct Mesh *mesh, int uv_index);
 +bool *ED_mesh_uv_map_ensure_pin(struct Mesh *mesh, int uv_index);
 +const bool *ED_mesh_uv_map_get_vert_selection(const struct Mesh *mesh, int 
uv_index);
 +const bool *ED_mesh_uv_map_get_edge_selection(const struct Mesh *mesh, int 
uv_index);
 +const bool *ED_mesh_uv_map_get_pin(const struct Mesh *mesh, int uv_index);
 +
+ bool ED_mesh_edge_is_loose(const struct Mesh *mesh, int index);
+ 
  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);
diff --cc source/blender/editors/sculpt_paint/paint_image_proj.cc
ind

[Bf-blender-cvs] [71ac20ef187] refactor-mesh-uv-map-generic: Create associated UV bool layers on BMesh creation.

2022-11-24 Thread Martijn Versteegh
Commit: 71ac20ef187ae80ec76a2a6c16f8a35bc4b8f227
Author: Martijn Versteegh
Date:   Thu Nov 24 13:02:46 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB71ac20ef187ae80ec76a2a6c16f8a35bc4b8f227

Create associated UV bool layers on BMesh creation.

Because on-demand allocation of the associated bool layers can lead to
problems for the BMesh python api (adding layers in a BMesh reallocates
the CustomData blocks, thus making existing pointers in python objects
invalid) always create the layers when converting to a BMesh.

===

M   source/blender/bmesh/intern/bmesh_mesh_convert.cc

===

diff --git a/source/blender/bmesh/intern/bmesh_mesh_convert.cc 
b/source/blender/bmesh/intern/bmesh_mesh_convert.cc
index d4be23a44a8..e7f5e0b8faa 100644
--- a/source/blender/bmesh/intern/bmesh_mesh_convert.cc
+++ b/source/blender/bmesh/intern/bmesh_mesh_convert.cc
@@ -148,7 +148,38 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const 
struct BMeshFromMeshPar
   
mask.pmask);
   CustomData mesh_ldata = 
CustomData_shallow_copy_remove_non_bmesh_attributes(>ldata,
   
mask.lmask);
+
+  blender::Vector temporary_layers_to_delete;
+
+  for (size_t l = 0; l < CustomData_number_of_layers(_ldata, 
CD_PROP_FLOAT2); l++)
+  {
+char name[MAX_CUSTOMDATA_LAYER_NAME];
+get_uv_map_vert_selection_name(CustomData_get_layer_name(_ldata, 
CD_PROP_FLOAT2, l), name);
+if (CustomData_get_named_layer_index(_ldata, CD_PROP_BOOL, name) < 0)
+{
+CustomData_add_layer_named(_ldata, CD_PROP_BOOL, CD_SET_DEFAULT, 
nullptr, me->totloop, name);
+temporary_layers_to_delete.append(std::string(name));
+}
+get_uv_map_edge_selection_name(CustomData_get_layer_name(_ldata, 
CD_PROP_FLOAT2, l), name);
+if (CustomData_get_named_layer_index(_ldata, CD_PROP_BOOL, name) < 0)
+{
+CustomData_add_layer_named(_ldata, CD_PROP_BOOL, CD_SET_DEFAULT, 
nullptr, me->totloop, name);
+temporary_layers_to_delete.append(std::string(name));
+}
+get_uv_map_pin_name(CustomData_get_layer_name(_ldata, CD_PROP_FLOAT2, 
l), name);
+if (CustomData_get_named_layer_index(_ldata, CD_PROP_BOOL, name) < 0)
+{
+CustomData_add_layer_named(_ldata, CD_PROP_BOOL, CD_SET_DEFAULT, 
nullptr, me->totloop, name);
+temporary_layers_to_delete.append(std::string(name));
+}
+  }
+
   BLI_SCOPED_DEFER([&]() {
+for (auto n : temporary_layers_to_delete)
+{
+CustomData_free_layer_named(_ldata, n.c_str(), me->totloop);
+}
+
 MEM_SAFE_FREE(mesh_vdata.layers);
 MEM_SAFE_FREE(mesh_edata.layers);
 MEM_SAFE_FREE(mesh_pdata.layers);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [c988561debd] refactor-mesh-uv-map-generic: Remove lazy bool attribute allocation for BMesh.

2022-11-24 Thread Martijn Versteegh
Commit: c988561debd5e30b560e0b96d71ca8217c2ba8ed
Author: Martijn Versteegh
Date:   Thu Nov 24 13:06:37 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rBc988561debd5e30b560e0b96d71ca8217c2ba8ed

Remove lazy bool attribute allocation for BMesh.

===

M   source/blender/bmesh/bmesh_class.h
M   source/blender/bmesh/intern/bmesh_interp.c
M   source/blender/bmesh/intern/bmesh_interp.h
M   source/blender/draw/intern/mesh_extractors/extract_mesh.cc
M   source/blender/editors/mesh/mesh_data.cc
M   source/blender/editors/sculpt_paint/sculpt_uv.c
M   source/blender/editors/uvedit/uvedit_ops.c
M   source/blender/editors/uvedit/uvedit_rip.c
M   source/blender/editors/uvedit/uvedit_select.c
M   source/blender/editors/uvedit/uvedit_unwrap_ops.c
M   
source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_ico_sphere.cc
M   source/blender/python/bmesh/bmesh_py_types_meshdata.c

===

diff --git a/source/blender/bmesh/bmesh_class.h 
b/source/blender/bmesh/bmesh_class.h
index ab6c17f92d7..a724a8783d4 100644
--- a/source/blender/bmesh/bmesh_class.h
+++ b/source/blender/bmesh/bmesh_class.h
@@ -533,9 +533,6 @@ typedef bool (*BMLoopPairFilterFunc)(const BMLoop *, const 
BMLoop *, void *user_
 #define BM_ELEM_CD_GET_BOOL(ele, offset) \
   (BLI_assert(offset != -1), *((bool *)((char *)(ele)->head.data + (offset
 
-#define BM_ELEM_CD_GET_OPT_BOOL(ele, offset) \
-  (offset == -1 ? false : *((bool *)((char *)(ele)->head.data + (offset
-
 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
 #  define BM_ELEM_CD_GET_BOOL_P(ele, offset) \
 (BLI_assert(offset != -1), \
@@ -549,20 +546,6 @@ typedef bool (*BMLoopPairFilterFunc)(const BMLoop *, const 
BMLoop *, void *user_
 (BLI_assert(offset != -1), (bool *)((char *)(ele)->head.data + (offset)))
 #endif
 
-#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
-#  define BM_ELEM_CD_GET_OPT_BOOL_P(ele, offset) \
-((offset != -1) ? \
- _Generic(ele, \
-  GENERIC_TYPE_ANY((bool *)POINTER_OFFSET((ele)->head.data, 
offset), \
-   _BM_GENERIC_TYPE_ELEM_NONCONST), \
-  GENERIC_TYPE_ANY((const bool 
*)POINTER_OFFSET((ele)->head.data, offset), \
-   _BM_GENERIC_TYPE_ELEM_CONST)) : \
- NULL)
-#else
-#  define BM_ELEM_CD_GET_OPT_BOOL_P(ele, offset) \
-((offset != -1) ? (bool *)((char *)(ele)->head.data + (offset)) : NULL)
-#endif
-
 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
 #  define BM_ELEM_CD_GET_VOID_P(ele, offset) \
 (BLI_assert(offset != -1), \
diff --git a/source/blender/bmesh/intern/bmesh_interp.c 
b/source/blender/bmesh/intern/bmesh_interp.c
index 86f86d79fac..fdae1d71f04 100644
--- a/source/blender/bmesh/intern/bmesh_interp.c
+++ b/source/blender/bmesh/intern/bmesh_interp.c
@@ -881,6 +881,16 @@ void BM_data_layer_ensure_named(BMesh *bm, CustomData 
*data, int type, const cha
   }
 }
 
+void BM_uv_map_ensure_selection_pin_attributes(BMesh *bm, const char 
*uv_map_name)
+{
+  char name[MAX_CUSTOMDATA_LAYER_NAME];
+  BM_data_layer_ensure_named(
+  bm, >ldata, CD_PROP_BOOL, 
get_uv_map_vert_selection_name(uv_map_name, name));
+  BM_data_layer_ensure_named(
+  bm, >ldata, CD_PROP_BOOL, 
get_uv_map_edge_selection_name(uv_map_name, name));
+  BM_data_layer_ensure_named(bm, >ldata, CD_PROP_BOOL, 
get_uv_map_pin_name(uv_map_name, name));
+}
+
 void BM_uv_map_ensure_vert_selection_attribute(BMesh *bm, const char 
*uv_map_name)
 {
   char name[MAX_CUSTOMDATA_LAYER_NAME];
diff --git a/source/blender/bmesh/intern/bmesh_interp.h 
b/source/blender/bmesh/intern/bmesh_interp.h
index cebf47910e1..f8bb45af1e7 100644
--- a/source/blender/bmesh/intern/bmesh_interp.h
+++ b/source/blender/bmesh/intern/bmesh_interp.h
@@ -65,6 +65,7 @@ void BM_data_layer_add_named(BMesh *bm, CustomData *data, int 
type, const char *
 void BM_data_layer_ensure_named(BMesh *bm, CustomData *data, int type, const 
char *name);
 void BM_data_layer_free(BMesh *bm, CustomData *data, int type);
 
+void BM_uv_map_ensure_selection_pin_attributes(BMesh *bm, const char 
*uv_map_name);
 void BM_uv_map_ensure_vert_selection_attribute(BMesh *bm, const char 
*uv_map_name);
 void BM_uv_map_ensure_edge_selection_attribute(BMesh *bm, const char 
*uv_map_name);
 void BM_uv_map_ensure_pin_attribute(BMesh *bm, const char *uv_map_name);
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh.cc 
b/source/blender/draw/intern/mesh_extractors/extract_mesh.cc
index 42336f7b416..98edb1c4e3c 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh.cc
@@ -127,7 +127,7 @@ void mesh_render_data_loop_flag(cons

[Bf-blender-cvs] [44af138b279] refactor-mesh-uv-map-generic: Change some CD_MLOOPUVs to CD_PROP_FLOAT2

2022-11-16 Thread Martijn Versteegh
Commit: 44af138b2797297d882f269cbb32593c66e90550
Author: Martijn Versteegh
Date:   Wed Nov 16 21:36:22 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB44af138b2797297d882f269cbb32593c66e90550

Change some CD_MLOOPUVs to CD_PROP_FLOAT2

During merging some CD_MLOOPUVs crept back in because I forgot
to check for the expected number of CD_MLOOPUVs in the source tree.

===

M   source/blender/blenloader/intern/versioning_defaults.cc
M   source/blender/bmesh/intern/bmesh_query_uv.cc
M   source/blender/draw/intern/draw_cache.c
M   source/blender/draw/intern/draw_manager_data.cc
M   source/blender/draw/intern/draw_pbvh.cc
M   source/blender/editors/mesh/editface.cc
M   source/blender/editors/mesh/mesh_data.cc
M   source/blender/editors/object/object_bake.c

===

diff --git a/source/blender/blenloader/intern/versioning_defaults.cc 
b/source/blender/blenloader/intern/versioning_defaults.cc
index 3d924bc9c05..940596ed976 100644
--- a/source/blender/blenloader/intern/versioning_defaults.cc
+++ b/source/blender/blenloader/intern/versioning_defaults.cc
@@ -350,7 +350,7 @@ static void blo_update_defaults_scene(Main *bmain, Scene 
*scene)
 
   /* Correct default startup UV's. */
   Mesh *me = static_cast(BLI_findstring(>meshes, "Cube", 
offsetof(ID, name) + 2));
-  if (me && (me->totloop == 24) && CustomData_has_layer(>ldata, 
CD_MLOOPUV)) {
+  if (me && (me->totloop == 24) && CustomData_has_layer(>ldata, 
CD_PROP_FLOAT2)) {
 const float uv_values[24][2] = {
 {0.625, 0.50}, {0.875, 0.50}, {0.875, 0.75}, {0.625, 0.75}, {0.375, 
0.75}, {0.625, 0.75},
 {0.625, 1.00}, {0.375, 1.00}, {0.375, 0.00}, {0.625, 0.00}, {0.625, 
0.25}, {0.375, 0.25},
diff --git a/source/blender/bmesh/intern/bmesh_query_uv.cc 
b/source/blender/bmesh/intern/bmesh_query_uv.cc
index 2bc24078bad..443980df84a 100644
--- a/source/blender/bmesh/intern/bmesh_query_uv.cc
+++ b/source/blender/bmesh/intern/bmesh_query_uv.cc
@@ -24,7 +24,7 @@ BMUVOffsets BM_uv_map_get_offsets(const BMesh *bm)
 {
   using namespace blender;
   using namespace blender::bke;
-  const int layer_index = CustomData_get_layer_index(>ldata, 
CD_PROP_FLOAT2);
+  const int layer_index = CustomData_get_active_layer_index(>ldata, 
CD_PROP_FLOAT2);
   if (layer_index == -1) {
 return {-1, -1, -1, -1};
   }
diff --git a/source/blender/draw/intern/draw_cache.c 
b/source/blender/draw/intern/draw_cache.c
index 00ac2563c43..f1f62d8aee9 100644
--- a/source/blender/draw/intern/draw_cache.c
+++ b/source/blender/draw/intern/draw_cache.c
@@ -3371,7 +3371,7 @@ void DRW_cdlayer_attr_aliases_add(GPUVertFormat *format,
 
   /* Active render layer name. */
   if (is_active_render) {
-GPU_vertformat_alias_add(format, cl->type == CD_MLOOPUV ? "a" : base_name);
+GPU_vertformat_alias_add(format, cl->type == CD_PROP_FLOAT2 ? "a" : 
base_name);
   }
 
   /* Active display layer name. */
diff --git a/source/blender/draw/intern/draw_manager_data.cc 
b/source/blender/draw/intern/draw_manager_data.cc
index beeff6f35c2..b398acd9aab 100644
--- a/source/blender/draw/intern/draw_manager_data.cc
+++ b/source/blender/draw/intern/draw_manager_data.cc
@@ -1420,11 +1420,11 @@ void DRW_shgroup_call_sculpt(DRWShadingGroup *shgroup,
   }
 
   if (use_uv) {
-int layer_i = CustomData_get_active_layer_index(>ldata, CD_MLOOPUV);
+int layer_i = CustomData_get_active_layer_index(>ldata, 
CD_PROP_FLOAT2);
 if (layer_i != -1) {
   CustomDataLayer *layer = me->ldata.layers + layer_i;
 
-  attrs[attrs_num].type = CD_MLOOPUV;
+  attrs[attrs_num].type = CD_PROP_FLOAT2;
   attrs[attrs_num].domain = ATTR_DOMAIN_CORNER;
   BLI_strncpy(attrs[attrs_num].name, layer->name, 
sizeof(attrs[attrs_num].name));
 
@@ -1481,11 +1481,11 @@ void 
DRW_shgroup_call_sculpt_with_materials(DRWShadingGroup **shgroups,
 
   for (uint i = 0; i < 32; i++) {
 if (cd_needed.uv & (1 << i)) {
-  int layer_i = CustomData_get_layer_index_n(>ldata, CD_MLOOPUV, i);
+  int layer_i = CustomData_get_layer_index_n(>ldata, CD_PROP_FLOAT2, 
i);
   CustomDataLayer *layer = layer_i != -1 ? me->ldata.layers + layer_i : 
nullptr;
 
   if (layer) {
-attrs[attrs_i].type = CD_MLOOPUV;
+attrs[attrs_i].type = CD_PROP_FLOAT2;
 attrs[attrs_i].domain = ATTR_DOMAIN_CORNER;
 BLI_strncpy(attrs[attrs_i].name, layer->name, 
sizeof(PBVHAttrReq::name));
 attrs_i++;
diff --git a/source/blender/draw/intern/draw_pbvh.cc 
b/source/blender/draw/intern/draw_pbvh.cc
index 3ae673f556a..cfae4275294 100644
--- a/source/blender/draw/intern/draw_pbvh.cc
+++ b/source/blender/draw/intern/draw_pbvh.cc
@@ -889,7 +889,7 @@ struct PBVHBatches {
 }
   

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

2022-11-16 Thread Martijn Versteegh
Commit: 44f8bfdeacfe7adc7d43040525ea3f09dd660b7d
Author: Martijn Versteegh
Date:   Wed Nov 16 12:30:18 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB44f8bfdeacfe7adc7d43040525ea3f09dd660b7d

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

===



===

diff --cc release/scripts/addons
index 68419fb3659,5a818af9508..63e1e6227af
--- a/release/scripts/addons
+++ b/release/scripts/addons
@@@ -1,1 -1,1 +1,1 @@@
- Subproject commit 68419fb3659f09e8447d351a25b1bd8e56211a5a
 -Subproject commit 5a818af95080cccf04dfa8317f0e966bff515c64
++Subproject commit 63e1e6227af42c1090fadc116e19b604d734a56c
diff --cc source/blender/bmesh/intern/bmesh_query_uv.h
index 1bd3ce6ebc7,edb756875f3..422e858f1b7
--- a/source/blender/bmesh/intern/bmesh_query_uv.h
+++ b/source/blender/bmesh/intern/bmesh_query_uv.h
@@@ -6,11 -6,10 +6,15 @@@
   * \ingroup bmesh
   */
  
+ #ifdef __cplusplus
+ extern "C" {
+ #endif
+ 
 +/**
 + * Retrieve the custom data offsets for layers used for user interaction with 
the active UV map.
 + */
 +BMUVOffsets BM_uv_map_get_offsets(const BMesh *bm);
 +
  float BM_loop_uv_calc_edge_length_squared(const BMLoop *l,
int cd_loop_uv_offset) 
ATTR_WARN_UNUSED_RESULT
  ATTR_NONNULL();

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [cd55d2b9d98] refactor-mesh-uv-map-generic: Port a new CD_MLOOPUV to CD_PROP_FLOAT2.

2022-11-16 Thread Martijn Versteegh
Commit: cd55d2b9d98d397c84a16046098faa4287bc5f12
Author: Martijn Versteegh
Date:   Wed Nov 16 12:37:01 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rBcd55d2b9d98d397c84a16046098faa4287bc5f12

Port a new CD_MLOOPUV to CD_PROP_FLOAT2.

===

M   source/blender/editors/uvedit/uvedit_clipboard.cc

===

diff --git a/source/blender/editors/uvedit/uvedit_clipboard.cc 
b/source/blender/editors/uvedit/uvedit_clipboard.cc
index 7ededf516bc..865ea749407 100644
--- a/source/blender/editors/uvedit/uvedit_clipboard.cc
+++ b/source/blender/editors/uvedit/uvedit_clipboard.cc
@@ -157,8 +157,8 @@ void UV_ClipboardBuffer::append(UvElementMap *element_map, 
const int cd_loop_uv_
   if (!element->separate) {
 continue;
   }
-  MLoopUV *luv = static_cast(BM_ELEM_CD_GET_VOID_P(element->l, 
cd_loop_uv_offset));
-  uv.append(std::make_pair(luv->uv[0], luv->uv[1]));
+  float *luv = BM_ELEM_CD_GET_FLOAT_P(element->l, cd_loop_uv_offset);
+  uv.append(std::make_pair(luv[0], luv[1]));
 }
   }
 }
@@ -183,9 +183,9 @@ void UV_ClipboardBuffer::write_uvs(UvElementMap 
*element_map,
 BLI_assert(unique_uv < label.size());
 const std::pair _uv = 
uv_clipboard->uv[label[unique_uv]];
 while (element) {
-  MLoopUV *luv = static_cast(BM_ELEM_CD_GET_VOID_P(element->l, 
cd_loop_uv_offset));
-  luv->uv[0] = source_uv.first;
-  luv->uv[1] = source_uv.second;
+  float *luv = BM_ELEM_CD_GET_FLOAT_P(element->l, cd_loop_uv_offset);
+  luv[0] = source_uv.first;
+  luv[1] = source_uv.second;
   element = element->next;
   if (!element || element->separate) {
 break;
@@ -282,7 +282,7 @@ static int uv_copy_exec(bContext *C, wmOperator * /*op*/)
 UvElementMap *element_map = BM_uv_element_map_create(
 em->bm, scene, true, false, use_seams, true);
 if (element_map) {
-  const int cd_loop_uv_offset = CustomData_get_offset(>bm->ldata, 
CD_MLOOPUV);
+  const int cd_loop_uv_offset = CustomData_get_offset(>bm->ldata, 
CD_PROP_FLOAT2);
   uv_clipboard->append(element_map, cd_loop_uv_offset);
 }
 BM_uv_element_map_free(element_map);
@@ -313,7 +313,7 @@ static int uv_paste_exec(bContext *C, wmOperator * /*op*/)
 BMEditMesh *em = BKE_editmesh_from_object(ob);
 
 const bool use_seams = false;
-const int cd_loop_uv_offset = CustomData_get_offset(>bm->ldata, 
CD_MLOOPUV);
+const int cd_loop_uv_offset = CustomData_get_offset(>bm->ldata, 
CD_PROP_FLOAT2);
 
 UvElementMap *dest_element_map = BM_uv_element_map_create(
 em->bm, scene, true, false, use_seams, true);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [65944e7e842] master: Merge branch 'blender-v3.4-release'

2022-11-15 Thread Martijn Versteegh
Commit: 65944e7e8420e09c7c7bb1aa05dc911f91edb4c1
Author: Martijn Versteegh
Date:   Tue Nov 15 22:13:08 2022 +0100
Branches: master
https://developer.blender.org/rB65944e7e8420e09c7c7bb1aa05dc911f91edb4c1

Merge branch 'blender-v3.4-release'

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [c0df88f3b51] blender-v3.4-release: Fix: Link drag search crash with incorrect socket name in switch node

2022-11-15 Thread Martijn Versteegh
Commit: c0df88f3b513447bf01242cbceb8a949401d
Author: Martijn Versteegh
Date:   Tue Nov 15 21:47:57 2022 +0100
Branches: blender-v3.4-release
https://developer.blender.org/rBc0df88f3b513447bf01242cbceb8a949401d

Fix: Link drag search crash with incorrect socket name in switch node

When dragging out a boolean noodle, releasing and choosing
'switch > Switch' from the search popup, the code would mistakenly
search for 'Start' instead of 'Switch'.

Also the function called was not exactly the right one, leading to the
node being marked as invalid.

Reviewed By: Jacques Lucke

Differential Revision: https://developer.blender.org/D16512

===

M   source/blender/nodes/geometry/nodes/node_geo_switch.cc

===

diff --git a/source/blender/nodes/geometry/nodes/node_geo_switch.cc 
b/source/blender/nodes/geometry/nodes/node_geo_switch.cc
index 36be68f1a22..6a001c00fd0 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_switch.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_switch.cc
@@ -123,7 +123,7 @@ static void 
node_gather_link_searches(GatherLinkSearchOpParams )
 if (params.other_socket().type == SOCK_BOOLEAN) {
   params.add_item(IFACE_("Switch"), [](LinkSearchOpParams ) {
 bNode  = params.add_node("GeometryNodeSwitch");
-params.connect_available_socket(node, "Start");
+params.update_and_connect_available_socket(node, "Switch");
   });
 }
 params.add_item(IFACE_("False"), [](LinkSearchOpParams ) {

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [f8ed657481d] refactor-mesh-uv-map-generic: Cleanup: fix comment typo.

2022-11-13 Thread Martijn Versteegh
Commit: f8ed657481db7866cf23a6499bb1a146df2a7e4d
Author: Martijn Versteegh
Date:   Sun Nov 13 23:38:50 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rBf8ed657481db7866cf23a6499bb1a146df2a7e4d

Cleanup: fix comment typo.

===

M   source/blender/python/bmesh/bmesh_py_types_customdata.c

===

diff --git a/source/blender/python/bmesh/bmesh_py_types_customdata.c 
b/source/blender/python/bmesh/bmesh_py_types_customdata.c
index a3fad5c9ccf..382fec4e188 100644
--- a/source/blender/python/bmesh/bmesh_py_types_customdata.c
+++ b/source/blender/python/bmesh/bmesh_py_types_customdata.c
@@ -461,7 +461,7 @@ static PyObject 
*bpy_bmlayercollection_verify(BPy_BMLayerCollection *self)
   if (index == -1) {
 BM_data_layer_add(self->bm, data, self->type);
 index = 0;
-/* Because addingCustomData layers to a bmesh will invalidate any existing 
pointers
+/* Because adding CustomData layers to a bmesh will invalidate any 
existing pointers
  * in Py objects we can't lazily add the associated bool layers. So add 
them all right
  * now.
  */

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [a9e9ad53965] refactor-mesh-uv-map-generic: Use element index instead of layer index for creation of python MLoopUV.

2022-11-13 Thread Martijn Versteegh
Commit: a9e9ad539658d598c5b0c218deda7f29ec368444
Author: Martijn Versteegh
Date:   Sun Nov 13 23:37:24 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rBa9e9ad539658d598c5b0c218deda7f29ec368444

Use element index instead of layer index for creation of python MLoopUV.

===

M   source/blender/python/bmesh/bmesh_py_types_customdata.c

===

diff --git a/source/blender/python/bmesh/bmesh_py_types_customdata.c 
b/source/blender/python/bmesh/bmesh_py_types_customdata.c
index f6e9a6864d8..a3fad5c9ccf 100644
--- a/source/blender/python/bmesh/bmesh_py_types_customdata.c
+++ b/source/blender/python/bmesh/bmesh_py_types_customdata.c
@@ -1147,7 +1147,7 @@ PyObject *BPy_BMLayerItem_GetItem(BPy_BMElem *py_ele, 
BPy_BMLayerItem *py_layer)
 PyErr_SetString(PyExc_ValueError, "BMElem[layer]: layer is from 
another mesh");
 return NULL;
   }
-  ret = BPy_BMLoopUV_CreatePyObject(py_ele->bm, py_layer->index);
+  ret = BPy_BMLoopUV_CreatePyObject(py_ele->bm, py_ele->ele->head.index);
   break;
 }
 case CD_PROP_BYTE_COLOR: {
@@ -1254,7 +1254,7 @@ int BPy_BMLayerItem_SetItem(BPy_BMElem *py_ele, 
BPy_BMLayerItem *py_layer, PyObj
 ret = -1;
   }
   else {
-ret = BPy_BMLoopUV_AssignPyObject(py_ele->bm, py_layer->index, 
py_value);
+ret = BPy_BMLoopUV_AssignPyObject(py_ele->bm, py_ele->ele->head.index, 
py_value);
   }
   break;
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [673c7065857] refactor-mesh-uv-map-generic: Always ensure bool layers for pyhton api.

2022-11-13 Thread Martijn Versteegh
Commit: 673c70658573a40899dac7a23454f9aa76d054aa
Author: Martijn Versteegh
Date:   Sun Nov 13 21:23:06 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB673c70658573a40899dac7a23454f9aa76d054aa

Always ensure bool layers for pyhton api.

When verifying a uv layer from the pytho api, always ensure
the associated bool layers. We can't lazily allocate them because
allocating CustomData layers on a BMesh reallocates layers thereby
invalidating existing python objects.

===

M   source/blender/python/bmesh/bmesh_py_types_customdata.c

===

diff --git a/source/blender/python/bmesh/bmesh_py_types_customdata.c 
b/source/blender/python/bmesh/bmesh_py_types_customdata.c
index 10ae6a33435..f6e9a6864d8 100644
--- a/source/blender/python/bmesh/bmesh_py_types_customdata.c
+++ b/source/blender/python/bmesh/bmesh_py_types_customdata.c
@@ -465,13 +465,13 @@ static PyObject 
*bpy_bmlayercollection_verify(BPy_BMLayerCollection *self)
  * in Py objects we can't lazily add the associated bool layers. So add 
them all right
  * now.
  */
-if (self->type == CD_PROP_FLOAT2 && self->htype == BM_LOOP) {
-  const char *active_uv_name = 
CustomData_get_active_layer_name(>bm->ldata,
+  }
+  if (self->type == CD_PROP_FLOAT2 && self->htype == BM_LOOP) {
+const char *active_uv_name = 
CustomData_get_active_layer_name(>bm->ldata,
 
CD_PROP_FLOAT2);
-  BM_uv_map_ensure_vert_selection_attribute(self->bm, active_uv_name);
-  BM_uv_map_ensure_edge_selection_attribute(self->bm, active_uv_name);
-  BM_uv_map_ensure_pin_attribute(self->bm, active_uv_name);
-}
+BM_uv_map_ensure_vert_selection_attribute(self->bm, active_uv_name);
+BM_uv_map_ensure_edge_selection_attribute(self->bm, active_uv_name);
+BM_uv_map_ensure_pin_attribute(self->bm, active_uv_name);
   }
 
   BLI_assert(index >= 0);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [ea4275a9bd3] refactor-mesh-uv-map-generic: Fix alignment of DisplaceModifierData.

2022-11-12 Thread Martijn Versteegh
Commit: ea4275a9bd3928f3fe25575944e7e1f33d41d556
Author: Martijn Versteegh
Date:   Sun Nov 13 00:59:39 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rBea4275a9bd3928f3fe25575944e7e1f33d41d556

Fix alignment of DisplaceModifierData.

The start of  DisplaceModifierData needs to have the exact same layout
as MappingInfoModifierData because it gets cast to that.

===

M   source/blender/makesdna/DNA_modifier_types.h

===

diff --git a/source/blender/makesdna/DNA_modifier_types.h 
b/source/blender/makesdna/DNA_modifier_types.h
index 5fca67321b1..735d0462488 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -560,6 +560,7 @@ typedef struct DisplaceModifierData {
   char map_bone[64];
   /** MAX_CUSTOMDATA_LAYER_NAME. */
   char uvlayer_name[68];
+  char _pad1[4];
   int uvlayer_tmp;
   int texmapping;
   /* end MappingInfoModifierData */
@@ -571,7 +572,7 @@ typedef struct DisplaceModifierData {
   float midlevel;
   int space;
   short flag;
-  char _pad2[2];
+  char _pad2[6];
 } DisplaceModifierData;
 
 /** #DisplaceModifierData.flag */

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [f14dd870a95] refactor-mesh-uv-map-generic: Cleanup: clang-format

2022-11-11 Thread Martijn Versteegh
Commit: f14dd870a956b6d357b47600dcffd5bf092a6a5c
Author: Martijn Versteegh
Date:   Sat Nov 12 00:08:48 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rBf14dd870a956b6d357b47600dcffd5bf092a6a5c

Cleanup: clang-format

===

M   source/blender/blenloader/intern/versioning_defaults.cc
M   source/blender/bmesh/bmesh_class.h
M   source/blender/bmesh/intern/bmesh_interp.c
M   source/blender/draw/engines/overlay/overlay_edit_uv.cc
M   source/blender/editors/transform/transform_convert_mesh_uv.c
M   source/blender/editors/uvedit/uvedit_islands.cc
M   source/blender/python/bmesh/bmesh_py_types_customdata.c
M   source/blender/python/bmesh/bmesh_py_types_meshdata.c

===

diff --git a/source/blender/blenloader/intern/versioning_defaults.cc 
b/source/blender/blenloader/intern/versioning_defaults.cc
index cfc56250bcd..3d924bc9c05 100644
--- a/source/blender/blenloader/intern/versioning_defaults.cc
+++ b/source/blender/blenloader/intern/versioning_defaults.cc
@@ -357,7 +357,8 @@ static void blo_update_defaults_scene(Main *bmain, Scene 
*scene)
 {0.125, 0.50}, {0.375, 0.50}, {0.375, 0.75}, {0.125, 0.75}, {0.375, 
0.50}, {0.625, 0.50},
 {0.625, 0.75}, {0.375, 0.75}, {0.375, 0.25}, {0.625, 0.25}, {0.625, 
0.50}, {0.375, 0.50},
 };
-float(*mloopuv)[2] = static_cast(CustomData_get_layer(>ldata, CD_PROP_FLOAT2));
+float(*mloopuv)[2] = static_cast(
+CustomData_get_layer(>ldata, CD_PROP_FLOAT2));
 memcpy(mloopuv, uv_values, sizeof(float[2]) * me->totloop);
   }
 
diff --git a/source/blender/bmesh/bmesh_class.h 
b/source/blender/bmesh/bmesh_class.h
index 5139cbec692..4b56c5a1b78 100644
--- a/source/blender/bmesh/bmesh_class.h
+++ b/source/blender/bmesh/bmesh_class.h
@@ -532,7 +532,6 @@ typedef bool (*BMLoopPairFilterFunc)(const BMLoop *, const 
BMLoop *, void *user_
 #define BM_ELEM_CD_GET_OPT_BOOL(ele, offset) \
   (offset == -1 ? false : *((bool *)((char *)(ele)->head.data + (offset
 
-
 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
 #  define BM_ELEM_CD_GET_BOOL_P(ele, offset) \
 (BLI_assert(offset != -1), \
@@ -549,17 +548,17 @@ typedef bool (*BMLoopPairFilterFunc)(const BMLoop *, 
const BMLoop *, void *user_
 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
 #  define BM_ELEM_CD_GET_OPT_BOOL_P(ele, offset) \
 ((offset != -1) ? \
- _Generic(ele, \
-  GENERIC_TYPE_ANY((bool *)POINTER_OFFSET((ele)->head.data, 
offset), \
-   _BM_GENERIC_TYPE_ELEM_NONCONST), \
-  GENERIC_TYPE_ANY((const bool *)POINTER_OFFSET((ele)->head.data, 
offset), \
-   _BM_GENERIC_TYPE_ELEM_CONST)) : NULL)
+ _Generic(ele, \
+  GENERIC_TYPE_ANY((bool *)POINTER_OFFSET((ele)->head.data, 
offset), \
+   _BM_GENERIC_TYPE_ELEM_NONCONST), \
+  GENERIC_TYPE_ANY((const bool 
*)POINTER_OFFSET((ele)->head.data, offset), \
+   _BM_GENERIC_TYPE_ELEM_CONST)) : \
+ NULL)
 #else
 #  define BM_ELEM_CD_GET_OPT_BOOL_P(ele, offset) \
 ((offset != -1) ? (bool *)((char *)(ele)->head.data + (offset)) : NULL)
 #endif
 
-
 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
 #  define BM_ELEM_CD_GET_VOID_P(ele, offset) \
 (BLI_assert(offset != -1), \
diff --git a/source/blender/bmesh/intern/bmesh_interp.c 
b/source/blender/bmesh/intern/bmesh_interp.c
index 0198cb6818f..86f86d79fac 100644
--- a/source/blender/bmesh/intern/bmesh_interp.c
+++ b/source/blender/bmesh/intern/bmesh_interp.c
@@ -898,8 +898,7 @@ void BM_uv_map_ensure_edge_selection_attribute(BMesh *bm, 
const char *uv_map_nam
 void BM_uv_map_ensure_pin_attribute(BMesh *bm, const char *uv_map_name)
 {
   char name[MAX_CUSTOMDATA_LAYER_NAME];
-  BM_data_layer_ensure_named(
-  bm, >ldata, CD_PROP_BOOL, get_uv_map_pin_name(uv_map_name, name));
+  BM_data_layer_ensure_named(bm, >ldata, CD_PROP_BOOL, 
get_uv_map_pin_name(uv_map_name, name));
 }
 
 void BM_data_layer_free(BMesh *bm, CustomData *data, int type)
diff --git a/source/blender/draw/engines/overlay/overlay_edit_uv.cc 
b/source/blender/draw/engines/overlay/overlay_edit_uv.cc
index 83aa2aac3e8..9d34e7559dc 100644
--- a/source/blender/draw/engines/overlay/overlay_edit_uv.cc
+++ b/source/blender/draw/engines/overlay/overlay_edit_uv.cc
@@ -116,10 +116,10 @@ void OVERLAY_edit_uv_init(OVERLAY_Data *vedata)
   const bool show_modified_uvs = sima->flag & SI_DRAWSHADOW;
   const bool is_tiled_image = image && (image->source == IMA_SRC_TILED);
   const bool do_edges_only = (ts->uv_flag & UV_SYNC_SELECTION) ?
-  /* NOTE: Ignore #SCE_SELECT_EDGE because a 
single s

[Bf-blender-cvs] [cbdb2207a44] refactor-mesh-uv-map-generic: Fix some more mistakes found when checking the whole diff.

2022-11-11 Thread Martijn Versteegh
Commit: cbdb2207a44aae54420d19b583b7b2a354f9ed91
Author: Martijn Versteegh
Date:   Sat Nov 12 00:02:10 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rBcbdb2207a44aae54420d19b583b7b2a354f9ed91

Fix some more mistakes found when checking the whole diff.

===

M   source/blender/editors/transform/transform_convert_mesh_uv.c
M   source/blender/editors/uvedit/uvedit_ops.c
M   source/blender/editors/uvedit/uvedit_unwrap_ops.c
M   source/blender/python/bmesh/bmesh_py_types_meshdata.c

===

diff --git a/source/blender/editors/transform/transform_convert_mesh_uv.c 
b/source/blender/editors/transform/transform_convert_mesh_uv.c
index 96bcbaa412a..a36aa05f8db 100644
--- a/source/blender/editors/transform/transform_convert_mesh_uv.c
+++ b/source/blender/editors/transform/transform_convert_mesh_uv.c
@@ -375,7 +375,7 @@ static void createTransUVs(bContext *C, TransInfo *t)
   }
 }
 
-luv = BM_ELEM_CD_GET_VOID_P(l, offsets.uv);
+luv = (float (*)[2])BM_ELEM_CD_GET_FLOAT_P(l, offsets.uv);
 UVsToTransData(t->aspect, td++, td2d++, *luv, center, prop_distance, 
selected);
   }
 }
diff --git a/source/blender/editors/uvedit/uvedit_ops.c 
b/source/blender/editors/uvedit/uvedit_ops.c
index 392a415c701..b05bc011b78 100644
--- a/source/blender/editors/uvedit/uvedit_ops.c
+++ b/source/blender/editors/uvedit/uvedit_ops.c
@@ -1481,7 +1481,7 @@ static int uv_hide_exec(bContext *C, wmOperator *op)
 
   BM_ITER_ELEM (l, , efa, BM_LOOPS_OF_FACE) {
 
-if (UV_VERT_SEL_TEST(l, !swap)) {
+if (UV_VERT_SEL_TEST(l, !swap) || UV_EDGE_SEL_TEST(l, !swap)) {
   hide = 1;
   break;
 }
diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c 
b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
index 1924c4c4e65..1e55d091e1a 100644
--- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c
+++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
@@ -340,7 +340,7 @@ static void uvedit_prepare_pinned_indices(ParamHandle 
*handle,
   BMIter liter;
   BMLoop *l;
   BM_ITER_ELEM (l, , efa, BM_LOOPS_OF_FACE) {
-bool pin = BM_ELEM_CD_GET_BOOL(l, offsets.pin);
+bool pin = BM_ELEM_CD_GET_OPT_BOOL(l, offsets.pin);
 if (options->pin_unselected && !pin) {
   pin = !uvedit_uv_select_test(scene, l, offsets);
 }
diff --git a/source/blender/python/bmesh/bmesh_py_types_meshdata.c 
b/source/blender/python/bmesh/bmesh_py_types_meshdata.c
index af66d531d82..a090ed30da3 100644
--- a/source/blender/python/bmesh/bmesh_py_types_meshdata.c
+++ b/source/blender/python/bmesh/bmesh_py_types_meshdata.c
@@ -70,6 +70,7 @@ static PyObject *bpy_bmloopuv_pin_uv_get(BPy_BMLoopUV *self, 
void *UNUSED(closur
 }
 static int bpy_bmloopuv_pin_uv_set(BPy_BMLoopUV *self, PyObject *value, void 
*UNUSED(closure))
 {
+  BLI_assert(self->pinned);
   if (self->pinned) {
 *self->pinned = PyC_Long_AsBool(value);
   }
@@ -87,6 +88,7 @@ static PyObject *bpy_bmloopuv_select_get(BPy_BMLoopUV *self, 
void *UNUSED(closur
 }
 static int bpy_bmloopuv_select_set(BPy_BMLoopUV *self, PyObject *value, void 
*UNUSED(closure))
 {
+  BLI_assert(self->vertsel);
   if (self->vertsel) {
 *self->vertsel = PyC_Long_AsBool(value);
   }
@@ -99,6 +101,7 @@ static PyObject *bpy_bmloopuv_select_edge_get(BPy_BMLoopUV 
*self, void *UNUSED(c
 }
 static int bpy_bmloopuv_select_edge_set(BPy_BMLoopUV *self, PyObject *value, 
void *UNUSED(closure))
 {
+  BLI_assert(self->edgesel);
   if (self->edgesel) {
 *self->edgesel = PyC_Long_AsBool(value);
   }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


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

2022-11-11 Thread Martijn Versteegh
Commit: b4757873bf1c2fb5e3f858a085af62359d3c1b3f
Author: Martijn Versteegh
Date:   Fri Nov 11 19:44:16 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rBb4757873bf1c2fb5e3f858a085af62359d3c1b3f

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

===



===

diff --cc source/blender/editors/geometry/geometry_attributes.cc
index 1a4c93afcdc,7f163da493b..5b0202dcbe1
--- a/source/blender/editors/geometry/geometry_attributes.cc
+++ b/source/blender/editors/geometry/geometry_attributes.cc
@@@ -290,23 -290,32 +289,15 @@@ static int geometry_attribute_convert_e
 * 4. Create a new attribute based on the previously copied data. */
switch (mode) {
  case ConvertAttributeMode::Generic: {
-   const eAttrDomain dst_domain = 
static_cast(RNA_enum_get(op->ptr, "domain"));
-   const eCustomDataType dst_type = static_cast(
-   RNA_enum_get(op->ptr, "data_type"));
- 
-   if (ELEM(dst_type, CD_PROP_STRING)) {
- BKE_report(op->reports, RPT_ERROR, "Cannot convert to the selected 
type");
+   if (!ED_geometry_attribute_convert(mesh,
+  name.c_str(),
+  
eCustomDataType(RNA_enum_get(op->ptr, "data_type")),
+  eAttrDomain(RNA_enum_get(op->ptr, 
"domain")),
+  op->reports)) {
  return OPERATOR_CANCELLED;
}
- 
-   GVArray src_varray = attributes.lookup_or_default(name, dst_domain, 
dst_type);
-   const CPPType _type = src_varray.type();
-   void *new_data = MEM_malloc_arrayN(src_varray.size(), cpp_type.size(), 
__func__);
-   src_varray.materialize_to_uninitialized(new_data);
-   attributes.remove(name);
-   attributes.add(name, dst_domain, dst_type, 
blender::bke::AttributeInitMoveArray(new_data));
break;
  }
 -case ConvertAttributeMode::UVMap: {
 -  MLoopUV *dst_uvs = static_cast(
 -  MEM_calloc_arrayN(mesh->totloop, sizeof(MLoopUV), __func__));
 -  VArray src_varray = attributes.lookup_or_default(
 -  name, ATTR_DOMAIN_CORNER, {0.0f, 0.0f});
 -  for (const int i : IndexRange(mesh->totloop)) {
 -copy_v2_v2(dst_uvs[i].uv, src_varray[i]);
 -  }
 -  attributes.remove(name);
 -  CustomData_add_layer_named(
 -  >ldata, CD_MLOOPUV, CD_ASSIGN, dst_uvs, mesh->totloop, 
name.c_str());
 -  int *active_index = BKE_id_attributes_active_index_p(>id);
 -  if (*active_index > 0) {
 -*active_index -= 1;
 -  }
 -  break;
 -}
  case ConvertAttributeMode::VertexGroup: {
Array src_weights(mesh->totvert);
VArray src_varray = attributes.lookup_or_default(

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [1bbb48a5d10] refactor-mesh-uv-map-generic: Cleanup: fix typos in comments. make diff minimal for layout.

2022-11-11 Thread Martijn Versteegh
Commit: 1bbb48a5d10cde6240cb66c69fe38e971d3129de
Author: Martijn Versteegh
Date:   Sat Nov 12 00:03:09 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB1bbb48a5d10cde6240cb66c69fe38e971d3129de

Cleanup: fix typos in comments. make diff minimal for layout.

===

M   source/blender/editors/uvedit/uvedit_ops.c
M   source/blender/editors/uvedit/uvedit_path.c
M   source/blender/io/collada/GeometryExporter.cpp
M   source/blender/io/wavefront_obj/importer/obj_import_mesh.cc
M   source/blender/python/bmesh/bmesh_py_types_customdata.c

===

diff --git a/source/blender/editors/uvedit/uvedit_ops.c 
b/source/blender/editors/uvedit/uvedit_ops.c
index b05bc011b78..7032e73bf9b 100644
--- a/source/blender/editors/uvedit/uvedit_ops.c
+++ b/source/blender/editors/uvedit/uvedit_ops.c
@@ -1848,8 +1848,8 @@ static int uv_seams_from_islands_exec(bContext *C, 
wmOperator *op)
   continue;
 }
 
-bool changed = false;
 const BMUVOffsets offsets = BM_uv_map_get_offsets(em->bm);
+bool changed = false;
 
 BMFace *f;
 BM_ITER_MESH (f, , bm, BM_FACES_OF_MESH) {
diff --git a/source/blender/editors/uvedit/uvedit_path.c 
b/source/blender/editors/uvedit/uvedit_path.c
index 248f97392ae..82d8c536fba 100644
--- a/source/blender/editors/uvedit/uvedit_path.c
+++ b/source/blender/editors/uvedit/uvedit_path.c
@@ -567,7 +567,6 @@ static int uv_shortest_path_pick_invoke(bContext *C, 
wmOperator *op, const wmEve
   Object *obedit = CTX_data_edit_object(C);
   BMEditMesh *em = BKE_editmesh_from_object(obedit);
   BMesh *bm = em->bm;
-
   const BMUVOffsets offsets = BM_uv_map_get_offsets(bm);
 
   float aspect_y;
diff --git a/source/blender/io/collada/GeometryExporter.cpp 
b/source/blender/io/collada/GeometryExporter.cpp
index 44f52dc797c..a14d941ed43 100644
--- a/source/blender/io/collada/GeometryExporter.cpp
+++ b/source/blender/io/collada/GeometryExporter.cpp
@@ -370,6 +370,7 @@ void GeometryExporter::create_mesh_primitive_list(short 
material_index,
 int layer_index = CustomData_get_layer_index_n(>ldata, CD_PROP_FLOAT2, 
i);
 if (!this->export_settings.get_active_uv_only() || layer_index == 
active_uv_index) {
 
+  // char *name = CustomData_get_layer_name(>ldata, CD_PROP_FLOAT2, i);
   COLLADASW::Input texcoord_input(
   COLLADASW::InputSemantic::TEXCOORD,
   makeUrl(makeTexcoordSourceId(geom_id, i, 
this->export_settings.get_active_uv_only())),
diff --git a/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc 
b/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc
index f27bbd296e4..5a54874aae1 100644
--- a/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc
+++ b/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc
@@ -293,7 +293,7 @@ void MeshFromGeometry::create_uv_verts(Mesh *mesh)
   uv_map.finish();
 
   /* If we have an object without UVs which resides in the same .obj file
-   * as an object which *does* have UVs we can end up adding and UV layer
+   * as an object which *does* have UVs we can end up adding a UV layer
* filled with zeroes.
* We could maybe check before creating this layer but that would need
* iterating over the whole mesh to check for UVs and as this is probably
diff --git a/source/blender/python/bmesh/bmesh_py_types_customdata.c 
b/source/blender/python/bmesh/bmesh_py_types_customdata.c
index 239e21b6ffb..1f5c2f57e01 100644
--- a/source/blender/python/bmesh/bmesh_py_types_customdata.c
+++ b/source/blender/python/bmesh/bmesh_py_types_customdata.c
@@ -462,7 +462,8 @@ static PyObject 
*bpy_bmlayercollection_verify(BPy_BMLayerCollection *self)
 BM_data_layer_add(self->bm, data, self->type);
 index = 0;
 /* Because addingCustomData layers to a bmesh will invalidate any existing 
pointers
- * in Py objects we can't lazily add the associated bool layers. So add 
htem right now.
+ * in Py objects we can't lazily add the associated bool layers. So add 
them all right 
+ * now.
  */
 if (self->type == CD_PROP_FLOAT2 && self->htype == BM_LOOP) {
   const char *active_uv_name = 
CustomData_get_active_layer_name(>bm->ldata, CD_PROP_FLOAT2);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [62effd67918] refactor-mesh-uv-map-generic: Fix merge error of release/scripts/addons

2022-11-11 Thread Martijn Versteegh
Commit: 62effd6791858221392ff7b92104a22ed44ebf7d
Author: Martijn Versteegh
Date:   Fri Nov 11 19:41:14 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB62effd6791858221392ff7b92104a22ed44ebf7d

Fix merge error of release/scripts/addons

===

M   release/scripts/addons

===

diff --git a/release/scripts/addons b/release/scripts/addons
index 85c414a2023..68419fb3659 16
--- a/release/scripts/addons
+++ b/release/scripts/addons
@@ -1 +1 @@
-Subproject commit 85c414a2023c1fdf16b6f3c9dc462fe242a625b9
+Subproject commit 68419fb3659f09e8447d351a25b1bd8e56211a5a

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [350271f4709] refactor-mesh-uv-map-generic: Fix some mistakes after reviewing half of the patch.

2022-11-11 Thread Martijn Versteegh
Commit: 350271f47094ee8e0ca65d77bafc50c513a87653
Author: Martijn Versteegh
Date:   Fri Nov 11 17:10:40 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB350271f47094ee8e0ca65d77bafc50c513a87653

Fix some mistakes after reviewing half of the patch.

Turns out I forgot to merge with master before reviewing
the diff(to master). Halfway I encountered unmerged code,
so the second half of the review will
happen after the merge. ;-)

===

M   source/blender/blenkernel/intern/object_update.cc
M   source/blender/bmesh/tools/bmesh_path_uv.c

===

diff --git a/source/blender/blenkernel/intern/object_update.cc 
b/source/blender/blenkernel/intern/object_update.cc
index bea7ec19b25..32d332cf07e 100644
--- a/source/blender/blenkernel/intern/object_update.cc
+++ b/source/blender/blenkernel/intern/object_update.cc
@@ -158,7 +158,7 @@ void BKE_object_handle_data_update(Depsgraph *depsgraph, 
Scene *scene, Object *o
 #endif
   if (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER) {
 /* Always compute UVs, vertex colors as orcos for render. */
-cddata_masks.lmask |= CD_MASK_PROP_BYTE_COLOR;
+cddata_masks.lmask |= CD_MASK_PROP_FLOAT2 | CD_MASK_PROP_BYTE_COLOR;
 cddata_masks.vmask |= CD_MASK_ORCO | CD_MASK_PROP_COLOR;
   }
   makeDerivedMesh(depsgraph, scene, ob, _masks); /* was 
CD_MASK_BAREMESH */
diff --git a/source/blender/bmesh/tools/bmesh_path_uv.c 
b/source/blender/bmesh/tools/bmesh_path_uv.c
index 58d5104cc74..26726fe4bac 100644
--- a/source/blender/bmesh/tools/bmesh_path_uv.c
+++ b/source/blender/bmesh/tools/bmesh_path_uv.c
@@ -398,7 +398,7 @@ static float facetag_cut_cost_edge_uv(BMFace *f_a,
   BM_face_uv_calc_center_median_weighted(f_b, aspect_v2, cd_loop_uv_offset, 
f_b_cent);
 
   const float *co_v1 = BM_ELEM_CD_GET_FLOAT_P(l_edge, cd_loop_uv_offset);
-  const float *co_v2 = BM_ELEM_CD_GET_VOID_P(l_edge->next, cd_loop_uv_offset);
+  const float *co_v2 = BM_ELEM_CD_GET_FLOAT_P(l_edge->next, cd_loop_uv_offset);
 
 #if 0
   mid_v2_v2v2(e_cent, co_v1, co_v2);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [ea2256f540b] refactor-mesh-uv-map-generic: Replace some forgotten CD_MLOOPUVs with CD_PROP_FLOAT2.

2022-11-10 Thread Martijn Versteegh
Commit: ea2256f540b5754c725a3e6255c800b07928031c
Author: Martijn Versteegh
Date:   Thu Nov 10 14:38:54 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rBea2256f540b5754c725a3e6255c800b07928031c

Replace some forgotten CD_MLOOPUVs with CD_PROP_FLOAT2.

mesh_legacy_convert.cc is the only file that can still contain CD_MLOOPUV
therefore I missed a few in another function in the same file.

===

M   source/blender/blenkernel/intern/mesh_legacy_convert.cc

===

diff --git a/source/blender/blenkernel/intern/mesh_legacy_convert.cc 
b/source/blender/blenkernel/intern/mesh_legacy_convert.cc
index c777bc2989f..c1419f2aaae 100644
--- a/source/blender/blenkernel/intern/mesh_legacy_convert.cc
+++ b/source/blender/blenkernel/intern/mesh_legacy_convert.cc
@@ -536,17 +536,17 @@ static void update_active_fdata_layers(CustomData *fdata, 
CustomData *ldata)
 {
   int act;
 
-  if (CustomData_has_layer(ldata, CD_MLOOPUV)) {
-act = CustomData_get_active_layer(ldata, CD_MLOOPUV);
+  if (CustomData_has_layer(ldata, CD_PROP_FLOAT2)) {
+act = CustomData_get_active_layer(ldata, CD_PROP_FLOAT2);
 CustomData_set_layer_active(fdata, CD_MTFACE, act);
 
-act = CustomData_get_render_layer(ldata, CD_MLOOPUV);
+act = CustomData_get_render_layer(ldata, CD_PROP_FLOAT2);
 CustomData_set_layer_render(fdata, CD_MTFACE, act);
 
-act = CustomData_get_clone_layer(ldata, CD_MLOOPUV);
+act = CustomData_get_clone_layer(ldata, CD_PROP_FLOAT2);
 CustomData_set_layer_clone(fdata, CD_MTFACE, act);
 
-act = CustomData_get_stencil_layer(ldata, CD_MLOOPUV);
+act = CustomData_get_stencil_layer(ldata, CD_PROP_FLOAT2);
 CustomData_set_layer_stencil(fdata, CD_MTFACE, act);
   }
 
@@ -579,7 +579,7 @@ static bool check_matching_legacy_layer_counts(CustomData 
*fdata, CustomData *ld
 ((a_num += CustomData_number_of_layers(l_a, t_a)) == \
  (b_num += CustomData_number_of_layers(l_b, t_b)))
 
-  if (!LAYER_CMP(ldata, CD_MLOOPUV, fdata, CD_MTFACE)) {
+  if (!LAYER_CMP(ldata, CD_PROP_FLOAT2, fdata, CD_MTFACE)) {
 return false;
   }
   if (!LAYER_CMP(ldata, CD_PROP_BYTE_COLOR, fdata, CD_MCOL)) {
@@ -612,7 +612,7 @@ static void add_mface_layers(CustomData *fdata, CustomData 
*ldata, int total)
   BLI_assert(!check_matching_legacy_layer_counts(fdata, ldata, false));
 
   for (int i = 0; i < ldata->totlayer; i++) {
-if (ldata->layers[i].type == CD_MLOOPUV) {
+if (ldata->layers[i].type == CD_PROP_FLOAT2) {
   CustomData_add_layer_named(
   fdata, CD_MTFACE, CD_SET_DEFAULT, nullptr, total, 
ldata->layers[i].name);
 }
@@ -650,7 +650,7 @@ static void mesh_ensure_tessellation_customdata(Mesh *me)
  * Callers could also check but safer to do here - campbell */
   }
   else {
-const int tottex_original = CustomData_number_of_layers(>ldata, 
CD_MLOOPUV);
+const int tottex_original = CustomData_number_of_layers(>ldata, 
CD_PROP_FLOAT2);
 const int totcol_original = CustomData_number_of_layers(>ldata, 
CD_PROP_BYTE_COLOR);
 
 const int tottex_tessface = CustomData_number_of_layers(>fdata, 
CD_MTFACE);
@@ -669,7 +669,7 @@ static void mesh_ensure_tessellation_customdata(Mesh *me)
  * some info to help troubleshoot what's going on. */
 printf(
 "%s: warning! Tessellation uvs or vcol data got out of sync, "
-"had to reset!\nCD_MTFACE: %d != CD_MLOOPUV: %d || CD_MCOL: %d 
!= "
+"had to reset!\nCD_MTFACE: %d != CD_PROP_FLOAT2: %d || 
CD_MCOL: %d != "
 "CD_PROP_BYTE_COLOR: "
 "%d\n",
 __func__,

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [ea81b0f9745] refactor-mesh-uv-map-generic: Fix mangled merge of versioning code.

2022-11-10 Thread Martijn Versteegh
Commit: ea81b0f9745b3a22baf1a79e678238570f7e80c7
Author: Martijn Versteegh
Date:   Thu Nov 10 20:17:12 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rBea81b0f9745b3a22baf1a79e678238570f7e80c7

Fix mangled merge of versioning code.

Versioning code was put in the mesh loading code, instead of versioning
in an earlier version of the SoA conversions. Later it was moved to the
proper place, but in the refactor-mesh-uv-as-attrib branch it remained
in the original location due to a merge error.

===

M   source/blender/blenkernel/intern/mesh.cc
M   source/blender/blenloader/intern/versioning_400.cc

===

diff --git a/source/blender/blenkernel/intern/mesh.cc 
b/source/blender/blenkernel/intern/mesh.cc
index dc9de1e61c2..53c61a1a5e7 100644
--- a/source/blender/blenkernel/intern/mesh.cc
+++ b/source/blender/blenkernel/intern/mesh.cc
@@ -365,13 +365,6 @@ static void mesh_blend_read_data(BlendDataReader *reader, 
ID *id)
 }
   }
 
-  if (!BLO_read_data_is_undo(reader)) {
-BKE_mesh_legacy_convert_flags_to_hide_layers(mesh);
-BKE_mesh_legacy_convert_uvs_to_generic(mesh);
-BKE_mesh_legacy_convert_mpoly_to_material_indices(mesh);
-BKE_mesh_legacy_bevel_weight_to_layers(mesh);
-  }
-
   /* We don't expect to load normals from files, since they are derived data. 
*/
   BKE_mesh_normals_tag_dirty(mesh);
   BKE_mesh_assert_normals_dirty_or_calculated(mesh);
diff --git a/source/blender/blenloader/intern/versioning_400.cc 
b/source/blender/blenloader/intern/versioning_400.cc
index 2616bb890a3..3302aa890d9 100644
--- a/source/blender/blenloader/intern/versioning_400.cc
+++ b/source/blender/blenloader/intern/versioning_400.cc
@@ -23,6 +23,7 @@ static void 
version_mesh_legacy_to_struct_of_array_format(Mesh )
 {
   BKE_mesh_legacy_convert_flags_to_selection_layers();
   BKE_mesh_legacy_convert_flags_to_hide_layers();
+  BKE_mesh_legacy_convert_uvs_to_generic();
   BKE_mesh_legacy_convert_mpoly_to_material_indices();
   BKE_mesh_legacy_bevel_weight_to_layers();
   BKE_mesh_legacy_face_set_to_generic();

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [9ba26598c03] refactor-mesh-uv-map-generic: Delete an erroneously created UV attribute .

2022-11-09 Thread Martijn Versteegh
Commit: 9ba26598c03a7f6302b67e0d74dbd181bb85fe07
Author: Martijn Versteegh
Date:   Thu Nov 10 00:04:49 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB9ba26598c03a7f6302b67e0d74dbd181bb85fe07

Delete an erroneously created UV attribute .

When loading a mesh without UVs from a wavefront obj file which also contains
meshes with UVs, we ended up creating an uninitialized UV layer. Detect when
that happens and delete the invaliud layer. We could also check for UVs
before creating the layer, but as this is probably a rather rare occasion
and checking involves looping over the whole mesh we just detect it after the
fact and delete.

===

M   source/blender/io/wavefront_obj/importer/obj_import_mesh.cc

===

diff --git a/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc 
b/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc
index 8f034eac62a..f27bbd296e4 100644
--- a/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc
+++ b/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc
@@ -273,6 +273,7 @@ void MeshFromGeometry::create_uv_verts(Mesh *mesh)
   "UVMap", ATTR_DOMAIN_CORNER);
 
   int tot_loop_idx = 0;
+  bool added_uv = false;
 
   for (const PolyElem _face : mesh_geometry_.face_elements_) {
 for (int idx = 0; idx < curr_face.corner_count_; ++idx) {
@@ -280,12 +281,27 @@ void MeshFromGeometry::create_uv_verts(Mesh *mesh)
   if (curr_corner.uv_vert_index >= 0 &&
   curr_corner.uv_vert_index < global_vertices_.uv_vertices.size()) {
 uv_map.span[tot_loop_idx] = 
global_vertices_.uv_vertices[curr_corner.uv_vert_index];
-tot_loop_idx++;
+added_uv = true;
   }
+  else {
+uv_map.span[tot_loop_idx] = {0.f, 0.f};
+  }
+  tot_loop_idx++;
 }
   }
 
   uv_map.finish();
+
+  /* If we have an object without UVs which resides in the same .obj file
+   * as an object which *does* have UVs we can end up adding and UV layer
+   * filled with zeroes.
+   * We could maybe check before creating this layer but that would need
+   * iterating over the whole mesh to check for UVs and as this is probably
+   * the exception rather than the rule, just delete it afterwards.
+   */
+  if (!added_uv) {
+attributes.remove("UVMap");
+  }
 }
 
 static Material *get_or_create_material(Main *bmain,

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [4706b4fe2d8] refactor-mesh-uv-map-generic: Do not guard setting of the UV-associated bools against the layer not existing.

2022-11-09 Thread Martijn Versteegh
Commit: 4706b4fe2d884f9886597332baed1278595f1d68
Author: Martijn Versteegh
Date:   Wed Nov 9 11:03:22 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB4706b4fe2d884f9886597332baed1278595f1d68

Do not guard setting of the UV-associated bools against the layer not existing.

It's better if it just crashes than if it silently fails.

===

M   source/blender/python/bmesh/bmesh_py_types_meshdata.c

===

diff --git a/source/blender/python/bmesh/bmesh_py_types_meshdata.c 
b/source/blender/python/bmesh/bmesh_py_types_meshdata.c
index b3c6d92a210..af66d531d82 100644
--- a/source/blender/python/bmesh/bmesh_py_types_meshdata.c
+++ b/source/blender/python/bmesh/bmesh_py_types_meshdata.c
@@ -158,15 +158,9 @@ int BPy_BMLoopUV_AssignPyObject(struct BMesh *bm, const 
int loop_index, PyObject
   float *luv = BM_ELEM_CD_GET_FLOAT_P(l, offsets.uv);
   copy_v2_v2(luv, src->uv);
 
-  if (offsets.select_vert >=0) {
-BM_ELEM_CD_SET_BOOL(l, offsets.select_vert, *src->vertsel);
-  }
-  if (offsets.select_edge >=0) {
-BM_ELEM_CD_SET_BOOL(l, offsets.select_edge, *src->edgesel);
-  }
-  if (offsets.pin >=0) {
-BM_ELEM_CD_SET_BOOL(l, offsets.pin, *src->pinned);
-  }
+  BM_ELEM_CD_SET_BOOL(l, offsets.select_vert, *src->vertsel);
+  BM_ELEM_CD_SET_BOOL(l, offsets.select_edge, *src->edgesel);
+  BM_ELEM_CD_SET_BOOL(l, offsets.pin, *src->pinned);
 
   return 0;
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


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

2022-11-09 Thread Martijn Versteegh
Commit: 26acb7d5f4878ba8c7bc1c95681d5890101c2e6c
Author: Martijn Versteegh
Date:   Tue Nov 8 23:18:55 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB26acb7d5f4878ba8c7bc1c95681d5890101c2e6c

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

===



===

diff --cc source/blender/editors/uvedit/uvedit_islands.cc
index 2c6a8a1a3a6,d8e10435146..c45fb8a2cbd
--- a/source/blender/editors/uvedit/uvedit_islands.cc
+++ b/source/blender/editors/uvedit/uvedit_islands.cc
@@@ -36,29 -36,48 +36,48 @@@
  
  #include "bmesh.h"
  
- /*  */
- /** \name UV Face Utilities
-  * \{ */
+ static void mul_v2_m2_add_v2v2(float r[2],
+const float mat[2][2],
+const float a[2],
+const float b[2])
+ {
+   /* Compute `r = mat * (a + b)` with high precision. */
+   const double x = static_cast(a[0]) + static_cast(b[0]);
+   const double y = static_cast(a[1]) + static_cast(b[1]);
+ 
+   r[0] = static_cast(mat[0][0] * x + mat[1][0] * y);
+   r[1] = static_cast(mat[0][1] * x + mat[1][1] * y);
+ }
  
- static void bm_face_uv_translate_and_scale_around_pivot(BMFace *f,
- const float offset[2],
- const float scale[2],
- const float pivot[2],
- const int 
cd_loop_uv_offset)
+ static void island_uv_transform(FaceIsland *island,
+ const float matrix[2][2],/* Scale and 
rotation. */
+ const float pre_translate[2] /* (pre) 
Translation. */
+ )
  {
-   BMLoop *l_iter;
-   BMLoop *l_first;
-   l_iter = l_first = BM_FACE_FIRST_LOOP(f);
-   do {
- float *luv = BM_ELEM_CD_GET_FLOAT_P(l_iter, cd_loop_uv_offset);
- for (int i = 0; i < 2; i++) {
-   luv[i] = offset[i] + (((luv[i] - pivot[i]) * scale[i]) + pivot[i]);
+   /* Use a pre-transform to compute `A * (x+b)`
+*
+* \note Ordinarily, we'd use a post_transform like `A * x + b`
+* In general, post-transforms are easier to work with when using 
homogenous co-ordinates.
+*
+* When UV mapping into the unit square, post-transforms can lose precision 
on small islands.
+* Instead we're using a pre-transform to maintain precision.
+*
+* To convert post-transform to pre-transform, use `A * x + b == A * (x + 
c), c = A^-1 * b`
+*/
+ 
 -  const int cd_loop_uv_offset = island->cd_loop_uv_offset;
++  const int cd_loop_uv_offset = island->offsets.uv;
+   const int faces_len = island->faces_len;
+   for (int i = 0; i < faces_len; i++) {
+ BMFace *f = island->faces[i];
+ BMLoop *l;
+ BMIter iter;
+ BM_ITER_ELEM (l, , f, BM_LOOPS_OF_FACE) {
 -  MLoopUV *luv = (MLoopUV *)BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
 -  mul_v2_m2_add_v2v2(luv->uv, matrix, luv->uv, pre_translate);
++  float *luv = BM_ELEM_CD_GET_FLOAT_P(l, cd_loop_uv_offset);
++  mul_v2_m2_add_v2v2(luv, matrix, luv, pre_translate);
  }
-   } while ((l_iter = l_iter->next) != l_first);
+   }
  }
  
- /** \} */
- 
  /*  */
  /** \name UV Face Array Utilities
   * \{ */
diff --cc source/blender/editors/uvedit/uvedit_select.c
index aa87aa9e5e5,777cc1d97e4..faa7b0e9b73
--- a/source/blender/editors/uvedit/uvedit_select.c
+++ b/source/blender/editors/uvedit/uvedit_select.c
@@@ -4679,9 -4703,9 +4679,9 @@@ static int uv_select_similar_vert_exec(
continue;
  }
  
 -const int cd_loop_uv_offset = CustomData_get_offset(>ldata, 
CD_MLOOPUV);
 +const BMUVOffsets offsets = BM_uv_map_get_offsets(bm);
  float ob_m3[3][3];
- copy_m3_m4(ob_m3, ob->obmat);
+ copy_m3_m4(ob_m3, ob->object_to_world);
  
  BMFace *face;
  BMIter iter;
@@@ -4715,10 -4740,9 +4715,10 @@@
  }
  
  bool changed = false;
 -const int cd_loop_uv_offset = CustomData_get_offset(>ldata, 
CD_MLOOPUV);
 +
 +const BMUVOffsets offsets = BM_uv_map_get_offsets(bm);
  float ob_m3[3][3];
- copy_m3_m4(ob_m3, ob->obmat);
+ copy_m3_m4(ob_m3, ob->object_to_world);
  
  BMFace *face;
  BMIter iter;
@@@ -4791,9 -4816,9 +4791,9 @@@ static int uv_select_similar_edge_exec(
continue;
  }
  
 -const int cd_loop_uv_offset = CustomData_get_offset(>ldata, 
CD_MLOOPUV);
 +const BMUVOffsets offsets = BM_uv_map_get_offsets(bm);
  float ob_m3[3][3];
- copy_m3_m4(ob_m3, ob->obmat);
+ copy_m3_m4(ob_m3, ob->object_to_world);
  
  BMFace *face;
  BMIter iter;
@@@ -4830,9 -4857,9 +4

[Bf-blender-cvs] [5391060724a] refactor-mesh-uv-map-generic: Try to handle creation of associated bool layers for bmesh.

2022-11-08 Thread Martijn Versteegh
Commit: 5391060724adc280a210d1e5eba2d9cf8c633a73
Author: Martijn Versteegh
Date:   Tue Nov 8 14:09:30 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB5391060724adc280a210d1e5eba2d9cf8c633a73

Try to handle creation of associated bool layers for bmesh.

===

M   source/blender/python/bmesh/bmesh_py_types_customdata.c
M   source/blender/python/bmesh/bmesh_py_types_meshdata.c

===

diff --git a/source/blender/python/bmesh/bmesh_py_types_customdata.c 
b/source/blender/python/bmesh/bmesh_py_types_customdata.c
index b1e83ac7b2c..ce6fbbc2a96 100644
--- a/source/blender/python/bmesh/bmesh_py_types_customdata.c
+++ b/source/blender/python/bmesh/bmesh_py_types_customdata.c
@@ -461,6 +461,15 @@ static PyObject 
*bpy_bmlayercollection_verify(BPy_BMLayerCollection *self)
   if (index == -1) {
 BM_data_layer_add(self->bm, data, self->type);
 index = 0;
+/* Because addingCustomData layers to a bmesh will invalidate any existing 
pointers
+ * in Py objects we can't lazily add the associated bool layers. So add 
htem right now.
+ */
+if (self->type == CD_PROP_FLOAT2 && self->htype == BM_LOOP) {
+  const char *active_uv_name = 
CustomData_get_active_layer_name(>bm->ldata, CD_PROP_FLOAT2);
+  BM_uv_map_ensure_vert_selection_attribute(self->bm, active_uv_name);
+  BM_uv_map_ensure_edge_selection_attribute(self->bm, active_uv_name);
+  BM_uv_map_ensure_pin_attribute(self->bm, active_uv_name);
+}
   }
 
   BLI_assert(index >= 0);
diff --git a/source/blender/python/bmesh/bmesh_py_types_meshdata.c 
b/source/blender/python/bmesh/bmesh_py_types_meshdata.c
index 0381a969b01..a7dff0d43a9 100644
--- a/source/blender/python/bmesh/bmesh_py_types_meshdata.c
+++ b/source/blender/python/bmesh/bmesh_py_types_meshdata.c
@@ -73,10 +73,10 @@ static int bpy_bmloopuv_pin_uv_set(BPy_BMLoopUV *self, 
PyObject *value, void *UN
   if (self->pinned) {
 *self->pinned = PyC_Long_AsBool(value);
   }
-  /* TODO(martijn) if (!self->pinmned) that means the layed does not exist , 
or at least didn't exist
-   * when the PY object was created
-   * we *should* create it here instead of just bailing...
-   * same for vertsel and edgesel
+  /* TODO(martijn) if (!self->pinned) that means the layed does not exist , or 
at least didn't exist
+   * when the PY object was created. We *should* create it here instead of 
just bailing, but we can't
+   * because that would invalidate all existing BPy_BMLoopUV objects' interal 
pointers.
+   * the same goes for vertsel and edgesel below.
*/
   return 0;
 }
@@ -152,19 +152,21 @@ int BPy_BMLoopUV_AssignPyObject(struct BMesh *bm, const 
int loop_index, PyObject
   }
 
   BPy_BMLoopUV *src = (BPy_BMLoopUV *)value;
-  const char *active_uv_name = CustomData_get_active_layer_name(>ldata, 
CD_PROP_FLOAT2);
-  BM_uv_map_ensure_vert_selection_attribute(bm, active_uv_name);
-  BM_uv_map_ensure_edge_selection_attribute(bm, active_uv_name);
-  BM_uv_map_ensure_pin_attribute(bm, active_uv_name);
   const BMUVOffsets offsets = BM_uv_map_get_offsets(bm);
 
   BMLoop *l = BM_loop_at_index_find(bm, loop_index);
   float *luv = BM_ELEM_CD_GET_FLOAT_P(l, offsets.uv);
   copy_v2_v2(luv, src->uv);
 
-  BM_ELEM_CD_SET_BOOL(l, offsets.select_vert, src->vertsel);
-  BM_ELEM_CD_SET_BOOL(l, offsets.select_edge, src->edgesel);
-  BM_ELEM_CD_SET_BOOL(l, offsets.pin, src->pinned);
+  if (offsets.select_vert >=0) {
+BM_ELEM_CD_SET_BOOL(l, offsets.select_vert, *src->vertsel);
+  }
+  if (offsets.select_edge >=0) {
+BM_ELEM_CD_SET_BOOL(l, offsets.select_edge, *src->edgesel);
+  }
+  if (offsets.pin >=0) {
+BM_ELEM_CD_SET_BOOL(l, offsets.pin, *src->pinned);
+  }
 
   return 0;
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


  1   2   >