Fix: Broken mesh hide status RNA accessors

Mistake in 2480b55f21.
Also deduplicate some of the code to find the indices of mesh elements.
This commit is contained in:
Hans Goudey 2022-08-11 17:55:49 -04:00
parent d2b1e4712d
commit 344919240c
1 changed files with 94 additions and 68 deletions

View File

@ -344,15 +344,61 @@ static void rna_Mesh_update_positions_tag(Main *bmain, Scene *scene, PointerRNA
/** \name Property get/set Callbacks
* \{ */
static int rna_MeshVertex_index_get(PointerRNA *ptr)
{
const Mesh *mesh = rna_mesh(ptr);
const MVert *vert = (MVert *)ptr->data;
const int index = (int)(vert - mesh->mvert);
BLI_assert(index >= 0);
BLI_assert(index < mesh->totvert);
return index;
}
static int rna_MeshEdge_index_get(PointerRNA *ptr)
{
const Mesh *mesh = rna_mesh(ptr);
const MEdge *edge = (MEdge *)ptr->data;
const int index = (int)(edge - mesh->medge);
BLI_assert(index >= 0);
BLI_assert(index < mesh->totedge);
return index;
}
static int rna_MeshPolygon_index_get(PointerRNA *ptr)
{
const Mesh *mesh = rna_mesh(ptr);
const MPoly *mpoly = (MPoly *)ptr->data;
const int index = (int)(mpoly - mesh->mpoly);
BLI_assert(index >= 0);
BLI_assert(index < mesh->totpoly);
return index;
}
static int rna_MeshLoop_index_get(PointerRNA *ptr)
{
const Mesh *mesh = rna_mesh(ptr);
const MLoop *mloop = (MLoop *)ptr->data;
const int index = (int)(mloop - mesh->mloop);
BLI_assert(index >= 0);
BLI_assert(index < mesh->totloop);
return index;
}
static int rna_MeshLoopTriangle_index_get(PointerRNA *ptr)
{
const Mesh *mesh = rna_mesh(ptr);
const MLoopTri *ltri = (MLoopTri *)ptr->data;
const int index = (int)(ltri - mesh->runtime.looptris.array);
BLI_assert(index >= 0);
BLI_assert(index < mesh->runtime.looptris.len);
return index;
}
static void rna_MeshVertex_normal_get(PointerRNA *ptr, float *value)
{
Mesh *mesh = rna_mesh(ptr);
const float(*vert_normals)[3] = BKE_mesh_vertex_normals_ensure(mesh);
const int index = (MVert *)ptr->data - mesh->mvert;
BLI_assert(index >= 0);
BLI_assert(index < mesh->totvert);
const int index = rna_MeshVertex_index_get(ptr);
copy_v3_v3(value, vert_normals[index]);
}
@ -361,19 +407,24 @@ static bool rna_MeshVertex_hide_get(PointerRNA *ptr)
const Mesh *mesh = rna_mesh(ptr);
const bool *hide_vert = (const bool *)CustomData_get_layer_named(
&mesh->vdata, CD_PROP_BOOL, ".hide_vert");
const int index = (const MVert *)ptr->data - mesh->mvert;
BLI_assert(index >= 0);
BLI_assert(index < mesh->totvert);
return hide_vert[index];
const int index = rna_MeshVertex_index_get(ptr);
return hide_vert == NULL ? false : hide_vert[index];
}
static void rna_MeshVertex_hide_set(PointerRNA *ptr, bool value)
{
Mesh *mesh = rna_mesh(ptr);
bool *hide_vert = (bool *)CustomData_get_layer_named(&mesh->vdata, CD_PROP_BOOL, ".hide_vert");
const int index = (const MVert *)ptr->data - mesh->mvert;
BLI_assert(index >= 0);
BLI_assert(index < mesh->totvert);
bool *hide_vert = (bool *)CustomData_duplicate_referenced_layer_named(
&mesh->vdata, CD_PROP_BOOL, ".hide_vert", mesh->totvert);
if (!hide_vert) {
if (!value) {
/* Skip adding layer if it doesn't exist already anyway and we're not hiding an element.. */
return;
}
hide_vert = (bool *)CustomData_add_layer_named(
&mesh->vdata, CD_PROP_BOOL, CD_CALLOC, NULL, mesh->totvert, ".hide_vert");
}
const int index = rna_MeshVertex_index_get(ptr);
hide_vert[index] = value;
}
@ -490,19 +541,24 @@ static bool rna_MeshPolygon_hide_get(PointerRNA *ptr)
const Mesh *mesh = rna_mesh(ptr);
const bool *hide_poly = (const bool *)CustomData_get_layer_named(
&mesh->pdata, CD_PROP_BOOL, ".hide_poly");
const int index = (const MPoly *)ptr->data - mesh->mpoly;
BLI_assert(index >= 0);
BLI_assert(index < mesh->totpoly);
return hide_poly[index];
const int index = rna_MeshPolygon_index_get(ptr);
return hide_poly == NULL ? false : hide_poly[index];
}
static void rna_MeshPolygon_hide_set(PointerRNA *ptr, bool value)
{
Mesh *mesh = rna_mesh(ptr);
bool *hide_poly = (bool *)CustomData_get_layer_named(&mesh->pdata, CD_PROP_BOOL, ".hide_poly");
const int index = (const MPoly *)ptr->data - mesh->mpoly;
BLI_assert(index >= 0);
BLI_assert(index < mesh->totpoly);
bool *hide_poly = (bool *)CustomData_duplicate_referenced_layer_named(
&mesh->pdata, CD_PROP_BOOL, ".hide_poly", mesh->totpoly);
if (!hide_poly) {
if (!value) {
/* Skip adding layer if it doesn't exist already anyway and we're not hiding an element.. */
return;
}
hide_poly = (bool *)CustomData_add_layer_named(
&mesh->pdata, CD_PROP_BOOL, CD_CALLOC, NULL, mesh->totpoly, ".hide_poly");
}
const int index = rna_MeshPolygon_index_get(ptr);
hide_poly[index] = value;
}
@ -1216,76 +1272,46 @@ static void rna_MeshPoly_material_index_range(
}
# endif
static int rna_MeshVertex_index_get(PointerRNA *ptr)
{
Mesh *me = rna_mesh(ptr);
MVert *vert = (MVert *)ptr->data;
return (int)(vert - me->mvert);
}
static int rna_MeshEdge_index_get(PointerRNA *ptr)
{
Mesh *me = rna_mesh(ptr);
MEdge *edge = (MEdge *)ptr->data;
return (int)(edge - me->medge);
}
static bool rna_MeshEdge_hide_get(PointerRNA *ptr)
{
const Mesh *mesh = rna_mesh(ptr);
const bool *hide_edge = (const bool *)CustomData_get_layer_named(
&mesh->pdata, CD_PROP_BOOL, ".hide_edge");
const int index = (const MEdge *)ptr->data - mesh->medge;
BLI_assert(index >= 0);
BLI_assert(index < mesh->totedge);
return hide_edge[index];
const int index = rna_MeshEdge_index_get(ptr);
return hide_edge == NULL ? false : hide_edge[index];
}
static void rna_MeshEdge_hide_set(PointerRNA *ptr, bool value)
{
Mesh *mesh = rna_mesh(ptr);
bool *hide_edge = (bool *)CustomData_get_layer_named(&mesh->edata, CD_PROP_BOOL, ".hide_edge");
const int index = (const MEdge *)ptr->data - mesh->medge;
BLI_assert(index >= 0);
BLI_assert(index < mesh->totedge);
bool *hide_edge = (bool *)CustomData_duplicate_referenced_layer_named(
&mesh->edata, CD_PROP_BOOL, ".hide_edge", mesh->totedge);
if (!hide_edge) {
if (!value) {
/* Skip adding layer if it doesn't exist already anyway and we're not hiding an element.. */
return;
}
hide_edge = (bool *)CustomData_add_layer_named(
&mesh->edata, CD_PROP_BOOL, CD_CALLOC, NULL, mesh->totedge, ".hide_edge");
}
const int index = rna_MeshEdge_index_get(ptr);
hide_edge[index] = value;
}
static int rna_MeshLoopTriangle_index_get(PointerRNA *ptr)
{
Mesh *me = rna_mesh(ptr);
MLoopTri *ltri = (MLoopTri *)ptr->data;
return (int)(ltri - me->runtime.looptris.array);
}
static int rna_MeshLoopTriangle_material_index_get(PointerRNA *ptr)
{
Mesh *me = rna_mesh(ptr);
MLoopTri *ltri = (MLoopTri *)ptr->data;
const Mesh *me = rna_mesh(ptr);
const MLoopTri *ltri = (MLoopTri *)ptr->data;
return me->mpoly[ltri->poly].mat_nr;
}
static bool rna_MeshLoopTriangle_use_smooth_get(PointerRNA *ptr)
{
Mesh *me = rna_mesh(ptr);
MLoopTri *ltri = (MLoopTri *)ptr->data;
const Mesh *me = rna_mesh(ptr);
const MLoopTri *ltri = (MLoopTri *)ptr->data;
return me->mpoly[ltri->poly].flag & ME_SMOOTH;
}
static int rna_MeshPolygon_index_get(PointerRNA *ptr)
{
Mesh *me = rna_mesh(ptr);
MPoly *mpoly = (MPoly *)ptr->data;
return (int)(mpoly - me->mpoly);
}
static int rna_MeshLoop_index_get(PointerRNA *ptr)
{
Mesh *me = rna_mesh(ptr);
MLoop *mloop = (MLoop *)ptr->data;
return (int)(mloop - me->mloop);
}
/* path construction */
static char *rna_VertexGroupElement_path(const PointerRNA *ptr)