diff options
Diffstat (limited to 'source/blender/blenkernel/intern/curve.c')
-rw-r--r-- | source/blender/blenkernel/intern/curve.c | 81 |
1 files changed, 78 insertions, 3 deletions
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index d8fd405b6e5..e67cf8573f3 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -52,6 +52,7 @@ #include "BKE_idtype.h" #include "BKE_key.h" #include "BKE_lib_id.h" +#include "BKE_lib_query.h" #include "BKE_main.h" #include "BKE_material.h" #include "BKE_object.h" @@ -117,6 +118,22 @@ static void curve_free_data(ID *id) MEM_SAFE_FREE(curve->tb); } +static void curve_foreach_id(ID *id, LibraryForeachIDData *data) +{ + Curve *curve = (Curve *)id; + BKE_LIB_FOREACHID_PROCESS(data, curve->bevobj, IDWALK_CB_NOP); + BKE_LIB_FOREACHID_PROCESS(data, curve->taperobj, IDWALK_CB_NOP); + BKE_LIB_FOREACHID_PROCESS(data, curve->textoncurve, IDWALK_CB_NOP); + BKE_LIB_FOREACHID_PROCESS(data, curve->key, IDWALK_CB_USER); + for (int i = 0; i < curve->totcol; i++) { + BKE_LIB_FOREACHID_PROCESS(data, curve->mat[i], IDWALK_CB_USER); + } + BKE_LIB_FOREACHID_PROCESS(data, curve->vfont, IDWALK_CB_USER); + BKE_LIB_FOREACHID_PROCESS(data, curve->vfontb, IDWALK_CB_USER); + BKE_LIB_FOREACHID_PROCESS(data, curve->vfonti, IDWALK_CB_USER); + BKE_LIB_FOREACHID_PROCESS(data, curve->vfontbi, IDWALK_CB_USER); +} + IDTypeInfo IDType_ID_CU = { .id_code = ID_CU, .id_filter = FILTER_ID_CU, @@ -131,6 +148,7 @@ IDTypeInfo IDType_ID_CU = { .copy_data = curve_copy_data, .free_data = curve_free_data, .make_local = NULL, + .foreach_id = curve_foreach_id, }; static int cu_isectLL(const float v1[3], @@ -4467,7 +4485,7 @@ void BKE_nurbList_handles_recalculate(ListBase *editnurb, const bool calc_length } } -void BKE_nurbList_flag_set(ListBase *editnurb, short flag) +void BKE_nurbList_flag_set(ListBase *editnurb, short flag, bool set) { Nurb *nu; BezTriple *bezt; @@ -4479,7 +4497,16 @@ void BKE_nurbList_flag_set(ListBase *editnurb, short flag) a = nu->pntsu; bezt = nu->bezt; while (a--) { - bezt->f1 = bezt->f2 = bezt->f3 = flag; + if (set) { + bezt->f1 |= flag; + bezt->f2 |= flag; + bezt->f3 |= flag; + } + else { + bezt->f1 &= ~flag; + bezt->f2 &= ~flag; + bezt->f3 &= ~flag; + } bezt++; } } @@ -4487,13 +4514,47 @@ void BKE_nurbList_flag_set(ListBase *editnurb, short flag) a = nu->pntsu * nu->pntsv; bp = nu->bp; while (a--) { - bp->f1 = flag; + SET_FLAG_FROM_TEST(bp->f1, set, flag); bp++; } } } } +/** + * Set \a flag for every point that already has \a from_flag set. + */ +bool BKE_nurbList_flag_set_from_flag(ListBase *editnurb, short from_flag, short flag) +{ + bool changed = false; + + for (Nurb *nu = editnurb->first; nu; nu = nu->next) { + if (nu->type == CU_BEZIER) { + for (int i = 0; i < nu->pntsu; i++) { + BezTriple *bezt = &nu->bezt[i]; + int old_f1 = bezt->f1, old_f2 = bezt->f2, old_f3 = bezt->f3; + + SET_FLAG_FROM_TEST(bezt->f1, bezt->f1 & from_flag, flag); + SET_FLAG_FROM_TEST(bezt->f2, bezt->f2 & from_flag, flag); + SET_FLAG_FROM_TEST(bezt->f3, bezt->f3 & from_flag, flag); + + changed |= (old_f1 != bezt->f1) || (old_f2 != bezt->f2) || (old_f3 != bezt->f3); + } + } + else { + for (int i = 0; i < nu->pntsu * nu->pntsv; i++) { + BPoint *bp = &nu->bp[i]; + int old_f1 = bp->f1; + + SET_FLAG_FROM_TEST(bp->f1, bp->f1 & from_flag, flag); + changed |= (old_f1 != bp->f1); + } + } + } + + return changed; +} + void BKE_nurb_direction_switch(Nurb *nu) { BezTriple *bezt1, *bezt2; @@ -5511,6 +5572,20 @@ void BKE_curve_material_remap(Curve *cu, const unsigned int *remap, unsigned int #undef MAT_NR_REMAP } +void BKE_curve_smooth_flag_set(Curve *cu, const bool use_smooth) +{ + if (use_smooth) { + for (Nurb *nu = cu->nurb.first; nu; nu = nu->next) { + nu->flag |= CU_SMOOTH; + } + } + else { + for (Nurb *nu = cu->nurb.first; nu; nu = nu->next) { + nu->flag &= ~CU_SMOOTH; + } + } +} + void BKE_curve_rect_from_textbox(const struct Curve *cu, const struct TextBox *tb, struct rctf *r_rect) |