From c00e7d07933b36f636431a1bef2c3ff77d8fc680 Mon Sep 17 00:00:00 2001 From: Martijn Versteegh Date: Tue, 4 Apr 2023 11:23:03 +0200 Subject: [PATCH 1/4] Fix creating BMLoopUV object with the correct iv layer. --- source/blender/bmesh/intern/bmesh_query_uv.cc | 13 +++++++++++-- source/blender/bmesh/intern/bmesh_query_uv.h | 3 ++- .../python/bmesh/bmesh_py_types_customdata.c | 2 +- .../blender/python/bmesh/bmesh_py_types_meshdata.c | 4 ++-- .../blender/python/bmesh/bmesh_py_types_meshdata.h | 2 +- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/source/blender/bmesh/intern/bmesh_query_uv.cc b/source/blender/bmesh/intern/bmesh_query_uv.cc index d4863ebc29a..47261db582c 100644 --- a/source/blender/bmesh/intern/bmesh_query_uv.cc +++ b/source/blender/bmesh/intern/bmesh_query_uv.cc @@ -20,11 +20,14 @@ #include "bmesh.h" #include "intern/bmesh_private.h" -BMUVOffsets BM_uv_map_get_offsets(const BMesh *bm) + + +BMUVOffsets BM_uv_map_get_offsets_n(const BMesh *bm, int layer) { using namespace blender; using namespace blender::bke; - const int layer_index = CustomData_get_active_layer_index(&bm->ldata, CD_PROP_FLOAT2); + const int layer_index = layer == -1 ? CustomData_get_active_layer_index(&bm->ldata, CD_PROP_FLOAT2) : + CustomData_get_layer_index_n(&bm->ldata, CD_PROP_FLOAT2, layer); if (layer_index == -1) { return {-1, -1, -1, -1}; } @@ -44,6 +47,12 @@ BMUVOffsets BM_uv_map_get_offsets(const BMesh *bm) return offsets; } +BMUVOffsets BM_uv_map_get_offsets(const BMesh *bm) +{ + return BM_uv_map_get_offsets_n(bm, -1); +} + + static void uv_aspect(const BMLoop *l, const float aspect[2], const int cd_loop_uv_offset, diff --git a/source/blender/bmesh/intern/bmesh_query_uv.h b/source/blender/bmesh/intern/bmesh_query_uv.h index 422e858f1b7..aaee130bfac 100644 --- a/source/blender/bmesh/intern/bmesh_query_uv.h +++ b/source/blender/bmesh/intern/bmesh_query_uv.h @@ -11,9 +11,10 @@ extern "C" { #endif /** - * Retrieve the custom data offsets for layers used for user interaction with the active UV map. + * Retrieve the custom data offsets for layers used for user interaction with a UV map, returns the active uv map if layer is -1. */ BMUVOffsets BM_uv_map_get_offsets(const BMesh *bm); +BMUVOffsets BM_uv_map_get_offsets_n(const BMesh *bm, int layer); float BM_loop_uv_calc_edge_length_squared(const BMLoop *l, int cd_loop_uv_offset) ATTR_WARN_UNUSED_RESULT diff --git a/source/blender/python/bmesh/bmesh_py_types_customdata.c b/source/blender/python/bmesh/bmesh_py_types_customdata.c index 18276bed898..f2661375d57 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, (BMLoop *)py_ele->ele); + ret = BPy_BMLoopUV_CreatePyObject(py_ele->bm, (BMLoop *)py_ele->ele, py_layer->index); break; } case CD_PROP_BYTE_COLOR: { diff --git a/source/blender/python/bmesh/bmesh_py_types_meshdata.c b/source/blender/python/bmesh/bmesh_py_types_meshdata.c index c85984aa467..329d4fc2fa5 100644 --- a/source/blender/python/bmesh/bmesh_py_types_meshdata.c +++ b/source/blender/python/bmesh/bmesh_py_types_meshdata.c @@ -209,11 +209,11 @@ int BPy_BMLoopUV_AssignPyObject(struct BMesh *bm, BMLoop *loop, PyObject *value) return 0; } -PyObject *BPy_BMLoopUV_CreatePyObject(struct BMesh *bm, BMLoop *loop) +PyObject *BPy_BMLoopUV_CreatePyObject(struct BMesh *bm, BMLoop *loop, int layer) { BPy_BMLoopUV *self = PyObject_New(BPy_BMLoopUV, &BPy_BMLoopUV_Type); - const BMUVOffsets offsets = BM_uv_map_get_offsets(bm); + const BMUVOffsets offsets = BM_uv_map_get_offsets_n(bm, layer); self->uv = BM_ELEM_CD_GET_FLOAT_P(loop, offsets.uv); self->vert_select = offsets.select_vert >= 0 ? BM_ELEM_CD_GET_BOOL_P(loop, offsets.select_vert) : diff --git a/source/blender/python/bmesh/bmesh_py_types_meshdata.h b/source/blender/python/bmesh/bmesh_py_types_meshdata.h index 60f82893f1a..8f872450cb7 100644 --- a/source/blender/python/bmesh/bmesh_py_types_meshdata.h +++ b/source/blender/python/bmesh/bmesh_py_types_meshdata.h @@ -23,7 +23,7 @@ struct MVertSkin; struct BMesh; int BPy_BMLoopUV_AssignPyObject(struct BMesh *bm, BMLoop *loop, PyObject *value); -PyObject *BPy_BMLoopUV_CreatePyObject(struct BMesh *bm, BMLoop *loop); +PyObject *BPy_BMLoopUV_CreatePyObject(struct BMesh *bm, BMLoop *loop, int layer); int BPy_BMVertSkin_AssignPyObject(struct MVertSkin *mvertskin, PyObject *value); PyObject *BPy_BMVertSkin_CreatePyObject(struct MVertSkin *mvertskin); -- 2.30.2 From 85cfb3df7785b1e5132b573740e7efd02456488d Mon Sep 17 00:00:00 2001 From: Martijn Versteegh Date: Tue, 4 Apr 2023 11:24:29 +0200 Subject: [PATCH 2/4] Cleanup: make format. --- source/blender/bmesh/intern/bmesh_query_uv.cc | 10 ++++------ source/blender/bmesh/intern/bmesh_query_uv.h | 3 ++- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/source/blender/bmesh/intern/bmesh_query_uv.cc b/source/blender/bmesh/intern/bmesh_query_uv.cc index 47261db582c..93de646ca94 100644 --- a/source/blender/bmesh/intern/bmesh_query_uv.cc +++ b/source/blender/bmesh/intern/bmesh_query_uv.cc @@ -20,14 +20,13 @@ #include "bmesh.h" #include "intern/bmesh_private.h" - - BMUVOffsets BM_uv_map_get_offsets_n(const BMesh *bm, int layer) { using namespace blender; using namespace blender::bke; - const int layer_index = layer == -1 ? CustomData_get_active_layer_index(&bm->ldata, CD_PROP_FLOAT2) : - CustomData_get_layer_index_n(&bm->ldata, CD_PROP_FLOAT2, layer); + const int layer_index = layer == -1 ? + CustomData_get_active_layer_index(&bm->ldata, CD_PROP_FLOAT2) : + CustomData_get_layer_index_n(&bm->ldata, CD_PROP_FLOAT2, layer); if (layer_index == -1) { return {-1, -1, -1, -1}; } @@ -49,10 +48,9 @@ BMUVOffsets BM_uv_map_get_offsets_n(const BMesh *bm, int layer) BMUVOffsets BM_uv_map_get_offsets(const BMesh *bm) { - return BM_uv_map_get_offsets_n(bm, -1); + return BM_uv_map_get_offsets_n(bm, -1); } - static void uv_aspect(const BMLoop *l, const float aspect[2], const int cd_loop_uv_offset, diff --git a/source/blender/bmesh/intern/bmesh_query_uv.h b/source/blender/bmesh/intern/bmesh_query_uv.h index aaee130bfac..4c0cb3a0f45 100644 --- a/source/blender/bmesh/intern/bmesh_query_uv.h +++ b/source/blender/bmesh/intern/bmesh_query_uv.h @@ -11,7 +11,8 @@ extern "C" { #endif /** - * Retrieve the custom data offsets for layers used for user interaction with a UV map, returns the active uv map if layer is -1. + * Retrieve the custom data offsets for layers used for user interaction with a UV map, returns the + * active uv map if layer is -1. */ BMUVOffsets BM_uv_map_get_offsets(const BMesh *bm); BMUVOffsets BM_uv_map_get_offsets_n(const BMesh *bm, int layer); -- 2.30.2 From 49dcec1cd773ac896e885e40cb521d2f0c82a064 Mon Sep 17 00:00:00 2001 From: Martijn Versteegh Date: Tue, 4 Apr 2023 14:17:24 +0200 Subject: [PATCH 3/4] Implemented Hans' suggestion --- source/blender/bmesh/intern/bmesh_query_uv.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/source/blender/bmesh/intern/bmesh_query_uv.cc b/source/blender/bmesh/intern/bmesh_query_uv.cc index 93de646ca94..e55c2e2d3ce 100644 --- a/source/blender/bmesh/intern/bmesh_query_uv.cc +++ b/source/blender/bmesh/intern/bmesh_query_uv.cc @@ -24,9 +24,7 @@ BMUVOffsets BM_uv_map_get_offsets_n(const BMesh *bm, int layer) { using namespace blender; using namespace blender::bke; - const int layer_index = layer == -1 ? - CustomData_get_active_layer_index(&bm->ldata, CD_PROP_FLOAT2) : - CustomData_get_layer_index_n(&bm->ldata, CD_PROP_FLOAT2, layer); + const int layer_index = CustomData_get_layer_index_n(&bm->ldata, CD_PROP_FLOAT2, layer); if (layer_index == -1) { return {-1, -1, -1, -1}; } @@ -48,7 +46,7 @@ BMUVOffsets BM_uv_map_get_offsets_n(const BMesh *bm, int layer) BMUVOffsets BM_uv_map_get_offsets(const BMesh *bm) { - return BM_uv_map_get_offsets_n(bm, -1); + return BM_uv_map_get_offsets_n(bm, CustomData_get_active_layer_index(&bm->ldata, CD_PROP_FLOAT2)); } static void uv_aspect(const BMLoop *l, -- 2.30.2 From 6f17b661db61e43270e3914ed2b30392738e4c8b Mon Sep 17 00:00:00 2001 From: Martijn Versteegh Date: Tue, 4 Apr 2023 16:39:04 +0200 Subject: [PATCH 4/4] Cleanup: make format --- source/blender/bmesh/intern/bmesh_query_uv.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/blender/bmesh/intern/bmesh_query_uv.cc b/source/blender/bmesh/intern/bmesh_query_uv.cc index e55c2e2d3ce..10af8462596 100644 --- a/source/blender/bmesh/intern/bmesh_query_uv.cc +++ b/source/blender/bmesh/intern/bmesh_query_uv.cc @@ -46,7 +46,8 @@ BMUVOffsets BM_uv_map_get_offsets_n(const BMesh *bm, int layer) BMUVOffsets BM_uv_map_get_offsets(const BMesh *bm) { - return BM_uv_map_get_offsets_n(bm, CustomData_get_active_layer_index(&bm->ldata, CD_PROP_FLOAT2)); + return BM_uv_map_get_offsets_n(bm, + CustomData_get_active_layer_index(&bm->ldata, CD_PROP_FLOAT2)); } static void uv_aspect(const BMLoop *l, -- 2.30.2