Fix #106430: Index the right UVmap in BMesh #106537

Closed
Martijn Versteegh wants to merge 5 commits from Baardaap:fix-named-uvmap_bmesh into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
5 changed files with 15 additions and 7 deletions

View File

@ -20,11 +20,11 @@
#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)
Review

int layer -> const int layer

`int layer` -> `const 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 = CustomData_get_layer_index_n(&bm->ldata, CD_PROP_FLOAT2, layer);
HooglyBoogly marked this conversation as resolved Outdated

It might be simper/clearer if BM_uv_map_get_offsets called CustomData_get_active_layer_index directly. Then BM_uv_map_get_offsets_n wouldn't have to have a special case for -1.

It might be simper/clearer if `BM_uv_map_get_offsets` called `CustomData_get_active_layer_index` directly. Then `BM_uv_map_get_offsets_n` wouldn't have to have a special case for -1.
if (layer_index == -1) {
return {-1, -1, -1, -1};
}
@ -44,6 +44,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,
HooglyBoogly marked this conversation as resolved Outdated

Missing clang format here (line is 101 characters long)

Missing clang format here (line is 101 characters long)
CustomData_get_active_layer_index(&bm->ldata, CD_PROP_FLOAT2));
}
static void uv_aspect(const BMLoop *l,
const float aspect[2],
const int cd_loop_uv_offset,

View File

@ -11,9 +11,11 @@ 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

View File

@ -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: {

View File

@ -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) :

View File

@ -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);