Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2014-07-17 19:12:12 +0400
committerBastien Montagne <montagne29@wanadoo.fr>2014-07-17 19:16:07 +0400
commit1097a3f70d92f888f62a02bb7fb53a25b1059c7b (patch)
tree52f8f25e9e6039002702fba7473b74943a0d42fb /source/blender/blenkernel/intern/mesh_validate.c
parentf46223f29e64f6a460b5e7a405d3d38abf765d79 (diff)
Add helper to validate (and fix) material indices of meshes' polygons, curves' splines and texts' letters.
Useful especially for importer addons. Reviewers: campbellbarton Reviewed By: campbellbarton Differential Revision: https://developer.blender.org/D650
Diffstat (limited to 'source/blender/blenkernel/intern/mesh_validate.c')
-rw-r--r--source/blender/blenkernel/intern/mesh_validate.c32
1 files changed, 29 insertions, 3 deletions
diff --git a/source/blender/blenkernel/intern/mesh_validate.c b/source/blender/blenkernel/intern/mesh_validate.c
index 858fe83b43f..e14bb9377da 100644
--- a/source/blender/blenkernel/intern/mesh_validate.c
+++ b/source/blender/blenkernel/intern/mesh_validate.c
@@ -909,8 +909,6 @@ static bool mesh_validate_customdata(CustomData *data, CustomDataMask mask,
return is_valid;
}
-#undef PRINT
-
/**
* \returns is_valid.
*/
@@ -1052,8 +1050,36 @@ void BKE_mesh_cd_validate(Mesh *me)
}
}
}
-/** \} */
+/**
+ * Check all material indices of polygons are valid, invalid ones are set to 0.
+ * \returns is_valid.
+ */
+int BKE_mesh_validate_material_indices(Mesh *me)
+{
+ MPoly *mp;
+ const int max_idx = max_ii(0, me->totcol - 1);
+ const int totpoly = me->totpoly;
+ int i;
+ bool is_valid = true;
+
+ for (mp = me->mpoly, i = 0; i < totpoly; i++, mp++) {
+ if (mp->mat_nr > max_idx) {
+ mp->mat_nr = 0;
+ is_valid = false;
+ }
+ }
+
+ if (!is_valid) {
+ DAG_id_tag_update(&me->id, OB_RECALC_DATA);
+ return true;
+ }
+ else {
+ return false;
+ }
+}
+
+/** \} */
/* -------------------------------------------------------------------- */