diff options
author | Hans Goudey <h.goudey@me.com> | 2022-09-09 16:29:07 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-09-09 16:29:47 +0300 |
commit | 291c313f80b4cccc8fcce3035584caeaa654844f (patch) | |
tree | cdc3469c825babf773c3c2cc9de678d193bec9db /source/blender/makesrna | |
parent | 21f2bacad977d3fd83d9e4730f2a14dc9932f043 (diff) |
Mesh: Move bevel weight out of MVert and MEdge
As described in T95966, the goal is to move to a "struct of arrays"
approach rather than gathering an arbitrary set of data in hard-coded
structs. This has performance benefits, but also code complexity
benefits (this patch removes plenty of code, though the boilerplate
for the new operators outweighs that here).
To mirror the internal change, the options for storing mesh bevel
weights are converted into operators that add or remove the layer,
like for some other layers.
The most complex change is to the solidify modifier, where bevel
weights had special handling. Other than that, most changes are
removing clearing of the weights, boilerplate for the add/remove
operators, and removing the manual transfer of bevel weights
in bmesh - mesh conversion.
Eventually bevel weights can become a fully generic attribute,
but for now this patch aims to avoid most functional changes.
Bevel weights are still written and read from the mesh in the old way,
so neither forward nor backward compatibility are affected. As described
in T95965, writing in the old format will be done until 4.0.
Differential Revision: https://developer.blender.org/D14077
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r-- | source/blender/makesrna/intern/rna_mesh.c | 57 |
1 files changed, 40 insertions, 17 deletions
diff --git a/source/blender/makesrna/intern/rna_mesh.c b/source/blender/makesrna/intern/rna_mesh.c index c36e53a49cd..28ceb0d1d9d 100644 --- a/source/blender/makesrna/intern/rna_mesh.c +++ b/source/blender/makesrna/intern/rna_mesh.c @@ -108,13 +108,11 @@ static CustomData *rna_mesh_vdata(const PointerRNA *ptr) Mesh *me = rna_mesh(ptr); return rna_mesh_vdata_helper(me); } -# if 0 static CustomData *rna_mesh_edata(PointerRNA *ptr) { Mesh *me = rna_mesh(ptr); return rna_mesh_edata_helper(me); } -# endif static CustomData *rna_mesh_pdata(const PointerRNA *ptr) { Mesh *me = rna_mesh(ptr); @@ -231,6 +229,16 @@ static bool rna_Mesh_has_custom_normals_get(PointerRNA *ptr) return BKE_mesh_has_custom_loop_normals(me); } +static bool rna_Mesh_has_edge_bevel_weight_get(PointerRNA *ptr) +{ + return CustomData_has_layer(rna_mesh_edata(ptr), CD_BWEIGHT); +} + +static bool rna_Mesh_has_vertex_bevel_weight_get(PointerRNA *ptr) +{ + return CustomData_has_layer(rna_mesh_vdata(ptr), CD_BWEIGHT); +} + /** \} */ /* -------------------------------------------------------------------- */ @@ -430,26 +438,36 @@ static void rna_MeshVertex_hide_set(PointerRNA *ptr, bool value) static float rna_MeshVertex_bevel_weight_get(PointerRNA *ptr) { - MVert *mvert = (MVert *)ptr->data; - return mvert->bweight / 255.0f; + const Mesh *mesh = rna_mesh(ptr); + const int index = rna_MeshVertex_index_get(ptr); + const float *values = (const float *)CustomData_get_layer(&mesh->vdata, CD_BWEIGHT); + return values == NULL ? 0.0f : values[index]; } static void rna_MeshVertex_bevel_weight_set(PointerRNA *ptr, float value) { - MVert *mvert = (MVert *)ptr->data; - mvert->bweight = round_fl_to_uchar_clamp(value * 255.0f); + Mesh *mesh = rna_mesh(ptr); + const int index = rna_MeshVertex_index_get(ptr); + float *values = (float *)CustomData_add_layer( + &mesh->vdata, CD_BWEIGHT, CD_SET_DEFAULT, NULL, mesh->totvert); + values[index] = clamp_f(value, 0.0f, 1.0f); } static float rna_MEdge_bevel_weight_get(PointerRNA *ptr) { - MEdge *medge = (MEdge *)ptr->data; - return medge->bweight / 255.0f; + const Mesh *mesh = rna_mesh(ptr); + const int index = rna_MeshEdge_index_get(ptr); + const float *values = (const float *)CustomData_get_layer(&mesh->edata, CD_BWEIGHT); + return values == NULL ? 0.0f : values[index]; } static void rna_MEdge_bevel_weight_set(PointerRNA *ptr, float value) { - MEdge *medge = (MEdge *)ptr->data; - medge->bweight = round_fl_to_uchar_clamp(value * 255.0f); + Mesh *mesh = rna_mesh(ptr); + const int index = rna_MeshEdge_index_get(ptr); + float *values = (float *)CustomData_add_layer( + &mesh->edata, CD_BWEIGHT, CD_SET_DEFAULT, NULL, mesh->totedge); + values[index] = clamp_f(value, 0.0f, 1.0f); } static float rna_MEdge_crease_get(PointerRNA *ptr) @@ -3854,6 +3872,18 @@ static void rna_def_mesh(BlenderRNA *brna) RNA_def_property_boolean_funcs(prop, "rna_Mesh_has_custom_normals_get", NULL); RNA_define_verify_sdna(true); + prop = RNA_def_property(srna, "has_bevel_weight_edge", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text( + prop, "Has Edge Bevel Weight", "True if the mesh has an edge bevel weight layer"); + RNA_def_property_boolean_funcs(prop, "rna_Mesh_has_edge_bevel_weight_get", NULL); + + prop = RNA_def_property(srna, "has_bevel_weight_vertex", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text( + prop, "Has Vertex Bevel Weight", "True if the mesh has an vertex bevel weight layer"); + RNA_def_property_boolean_funcs(prop, "rna_Mesh_has_vertex_bevel_weight_get", NULL); + prop = RNA_def_property(srna, "texco_mesh", PROP_POINTER, PROP_NONE); RNA_def_property_pointer_sdna(prop, NULL, "texcomesh"); RNA_def_property_flag(prop, PROP_EDITABLE); @@ -3907,13 +3937,6 @@ static void rna_def_mesh(BlenderRNA *brna) RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_Mesh_update_vertmask"); /* customdata flags */ - prop = RNA_def_property(srna, "use_customdata_vertex_bevel", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "cd_flag", ME_CDFLAG_VERT_BWEIGHT); - RNA_def_property_ui_text(prop, "Store Vertex Bevel Weight", ""); - - prop = RNA_def_property(srna, "use_customdata_edge_bevel", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "cd_flag", ME_CDFLAG_EDGE_BWEIGHT); - RNA_def_property_ui_text(prop, "Store Edge Bevel Weight", ""); prop = RNA_def_property(srna, "use_customdata_vertex_crease", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "cd_flag", ME_CDFLAG_VERT_CREASE); |