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(&self->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(&bm->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