diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2014-07-17 19:12:12 +0400 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2014-07-17 19:16:07 +0400 |
commit | 1097a3f70d92f888f62a02bb7fb53a25b1059c7b (patch) | |
tree | 52f8f25e9e6039002702fba7473b74943a0d42fb /source/blender/blenkernel/intern/curve.c | |
parent | f46223f29e64f6a460b5e7a405d3d38abf765d79 (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/curve.c')
-rw-r--r-- | source/blender/blenkernel/intern/curve.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index 0abe956b599..eaeffdf6fef 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -52,6 +52,7 @@ #include "BKE_animsys.h" #include "BKE_curve.h" +#include "BKE_depsgraph.h" #include "BKE_displist.h" #include "BKE_font.h" #include "BKE_global.h" @@ -4230,6 +4231,45 @@ void BKE_curve_material_index_clear(Curve *cu) } } +int BKE_curve_material_index_validate(Curve *cu) +{ + const int curvetype = BKE_curve_type_get(cu); + bool is_valid = true; + + if (curvetype == OB_FONT) { + CharInfo *info = cu->strinfo; + const int max_idx = max_ii(0, cu->totcol); /* OB_FONT use 1 as first mat index, not 0!!! */ + int i; + for (i = cu->len_wchar - 1; i >= 0; i--, info++) { + if (info->mat_nr > max_idx) { + info->mat_nr = 0; + is_valid = false; + } + } + } + else { + Nurb *nu; + const int max_idx = max_ii(0, cu->totcol - 1); + for (nu = cu->nurb.first; nu; nu = nu->next) { + if (nu->mat_nr > max_idx) { + nu->mat_nr = 0; + if (curvetype == OB_CURVE) { + nu->charidx = 0; + } + is_valid = false; + } + } + } + + if (!is_valid) { + DAG_id_tag_update(&cu->id, OB_RECALC_DATA); + return true; + } + else { + return false; + } +} + void BKE_curve_rect_from_textbox(const struct Curve *cu, const struct TextBox *tb, struct rctf *r_rect) { r_rect->xmin = cu->xof + tb->x; |