diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2016-02-28 17:29:56 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2016-02-28 17:29:56 +0300 |
commit | 877f44162853664791f0ff4fa93f856384d0eed7 (patch) | |
tree | ed924b94bebd5cec0ad5455b7e90d481b63ad80a /source/blender/makesrna/intern/rna_mesh_api.c | |
parent | ea76ec2866d11156b689287f4190dfe4e79314b2 (diff) |
BKE_mesh: add polygon flipping tools.
Those new functions invert the winding of polygons, effectively inverting their normals.
A helper was also added to allow swapping two items in customdata layers.
Being able to invert normals outside of BMesh area is very important in several places,
like IO scripts or customnormals modifiers...
Reviewers: campbellbarton
Differential Revision: https://developer.blender.org/D1814
Diffstat (limited to 'source/blender/makesrna/intern/rna_mesh_api.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_mesh_api.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/source/blender/makesrna/intern/rna_mesh_api.c b/source/blender/makesrna/intern/rna_mesh_api.c index 1459157112e..a3bc21b0170 100644 --- a/source/blender/makesrna/intern/rna_mesh_api.c +++ b/source/blender/makesrna/intern/rna_mesh_api.c @@ -200,6 +200,15 @@ static void rna_Mesh_transform(Mesh *mesh, float *mat, int shape_keys) DAG_id_tag_update(&mesh->id, 0); } +static void rna_Mesh_flip_normals(Mesh *mesh) +{ + BKE_mesh_polygons_flip(mesh->mpoly, mesh->mloop, &mesh->ldata, mesh->totpoly); + BKE_mesh_tessface_clear(mesh); + BKE_mesh_calc_normals(mesh); + + DAG_id_tag_update(&mesh->id, 0); +} + #else void RNA_api_mesh(StructRNA *srna) @@ -209,11 +218,16 @@ void RNA_api_mesh(StructRNA *srna) const int normals_array_dim[] = {1, 3}; func = RNA_def_function(srna, "transform", "rna_Mesh_transform"); - RNA_def_function_ui_description(func, "Transform mesh vertices by a matrix"); + RNA_def_function_ui_description(func, "Transform mesh vertices by a matrix " + "(Warning: inverts normals if matrix is negative)"); parm = RNA_def_float_matrix(func, "matrix", 4, 4, NULL, 0.0f, 0.0f, "", "Matrix", 0.0f, 0.0f); RNA_def_property_flag(parm, PROP_REQUIRED); RNA_def_boolean(func, "shape_keys", 0, "", "Transform Shape Keys"); + func = RNA_def_function(srna, "flip_normals", "rna_Mesh_flip_normals"); + RNA_def_function_ui_description(func, "Invert winding of all polygons " + "(clears tessellation, does not handle custom normals)"); + func = RNA_def_function(srna, "calc_normals", "BKE_mesh_calc_normals"); RNA_def_function_ui_description(func, "Calculate vertex normals"); |