diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2016-07-12 10:15:49 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2016-07-12 10:15:49 +0300 |
commit | 99bb1accbbb8e1ba38f30b073b22deb107bf3220 (patch) | |
tree | 7852ec686524e785486c452ec959713abbbef666 /source/blender/blenkernel/intern/curve.c | |
parent | 732cd96737007b1411a161369f842209a4c26419 (diff) | |
parent | b8f217ef213f908a6b5407f162a8f980091e838d (diff) |
Merge branch 'master' into asset-experiments
Conflicts:
source/blender/blenloader/intern/readfile.c
source/blender/windowmanager/intern/wm_init_exit.c
Diffstat (limited to 'source/blender/blenkernel/intern/curve.c')
-rw-r--r-- | source/blender/blenkernel/intern/curve.c | 146 |
1 files changed, 92 insertions, 54 deletions
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index dec6ff22360..0e634e21ea3 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -58,6 +58,8 @@ #include "BKE_global.h" #include "BKE_key.h" #include "BKE_library.h" +#include "BKE_library_query.h" +#include "BKE_library_remap.h" #include "BKE_main.h" #include "BKE_object.h" #include "BKE_material.h" @@ -172,12 +174,13 @@ Curve *BKE_curve_add(Main *bmain, const char *name, int type) return cu; } -Curve *BKE_curve_copy(Curve *cu) +Curve *BKE_curve_copy(Main *bmain, Curve *cu) { Curve *cun; int a; - cun = BKE_libblock_copy(&cu->id); + cun = BKE_libblock_copy(bmain, &cu->id); + BLI_listbase_clear(&cun->nurb); BKE_nurbList_duplicate(&(cun->nurb), &(cu->nurb)); @@ -191,45 +194,29 @@ Curve *BKE_curve_copy(Curve *cu) cun->tb = MEM_dupallocN(cu->tb); cun->bb = MEM_dupallocN(cu->bb); - cun->key = BKE_key_copy(cu->key); - if (cun->key) cun->key->from = (ID *)cun; + if (cu->key) { + cun->key = BKE_key_copy(bmain, cu->key); + cun->key->from = (ID *)cun; + } cun->editnurb = NULL; cun->editfont = NULL; -#if 0 // XXX old animation system - /* single user ipo too */ - if (cun->ipo) cun->ipo = copy_ipo(cun->ipo); -#endif // XXX old animation system - id_us_plus((ID *)cun->vfont); id_us_plus((ID *)cun->vfontb); id_us_plus((ID *)cun->vfonti); id_us_plus((ID *)cun->vfontbi); - if (cu->id.lib) { - BKE_id_lib_local_paths(G.main, cu->id.lib, &cun->id); + if (ID_IS_LINKED_DATABLOCK(cu)) { + BKE_id_expand_local(&cun->id); + BKE_id_lib_local_paths(bmain, cu->id.lib, &cun->id); } return cun; } -static void extern_local_curve(Curve *cu) -{ - id_lib_extern((ID *)cu->vfont); - id_lib_extern((ID *)cu->vfontb); - id_lib_extern((ID *)cu->vfonti); - id_lib_extern((ID *)cu->vfontbi); - - if (cu->mat) { - extern_local_matarar(cu->mat, cu->totcol); - } -} - -void BKE_curve_make_local(Curve *cu) +void BKE_curve_make_local(Main *bmain, Curve *cu) { - Main *bmain = G.main; - Object *ob; bool is_local = false, is_lib = false; /* - when there are only lib users: don't do @@ -237,40 +224,26 @@ void BKE_curve_make_local(Curve *cu) * - mixed: do a copy */ - if (cu->id.lib == NULL) - return; - - if (cu->id.us == 1) { - id_clear_lib_data(bmain, &cu->id); - extern_local_curve(cu); + if (!ID_IS_LINKED_DATABLOCK(cu)) { return; } - for (ob = bmain->object.first; ob && ELEM(0, is_lib, is_local); ob = ob->id.next) { - if (ob->data == cu) { - if (ob->id.lib) is_lib = true; - else is_local = true; - } - } + BKE_library_ID_test_usages(bmain, cu, &is_local, &is_lib); - if (is_local && is_lib == false) { - id_clear_lib_data(bmain, &cu->id); - extern_local_curve(cu); - } - else if (is_local && is_lib) { - Curve *cu_new = BKE_curve_copy(cu); - cu_new->id.us = 0; + if (is_local) { + if (!is_lib) { + id_clear_lib_data(bmain, &cu->id); + if (cu->key) { + BKE_key_make_local(bmain, cu->key); + } + BKE_id_expand_local(&cu->id); + } + else { + Curve *cu_new = BKE_curve_copy(bmain, cu); - BKE_id_lib_local_paths(bmain, cu->id.lib, &cu_new->id); + cu_new->id.us = 0; - for (ob = bmain->object.first; ob; ob = ob->id.next) { - if (ob->data == cu) { - if (ob->id.lib == NULL) { - ob->data = cu_new; - id_us_plus(&cu_new->id); - id_us_min(&cu->id); - } - } + BKE_libblock_remap(bmain, cu, cu_new, ID_REMAP_SKIP_INDIRECT_USAGE); } } } @@ -1384,6 +1357,71 @@ void BKE_nurb_makeCurve(Nurb *nu, float *coord_array, float *tilt_array, float * MEM_freeN(basisu); } +/** + * Calculate the length for arrays filled in by #BKE_curve_calc_coords_axis. + */ +unsigned int BKE_curve_calc_coords_axis_len( + const unsigned int bezt_array_len, const unsigned int resolu, + const bool is_cyclic, const bool use_cyclic_duplicate_endpoint) +{ + const unsigned int segments = bezt_array_len - (is_cyclic ? 0 : 1); + const unsigned int points_len = (segments * resolu) + (is_cyclic ? (use_cyclic_duplicate_endpoint) : 1); + return points_len; +} + +/** + * Calculate an array for the entire curve (cyclic or non-cyclic). + * \note Call for each axis. + * + * \param use_cyclic_duplicate_endpoint: Duplicate values at the beginning & end of the array. + */ +void BKE_curve_calc_coords_axis( + const BezTriple *bezt_array, const unsigned int bezt_array_len, const unsigned int resolu, + const bool is_cyclic, const bool use_cyclic_duplicate_endpoint, + /* array params */ + const unsigned int axis, const unsigned int stride, + float *r_points) +{ + const unsigned int points_len = BKE_curve_calc_coords_axis_len( + bezt_array_len, resolu, is_cyclic, use_cyclic_duplicate_endpoint); + float *r_points_offset = r_points; + + const unsigned int resolu_stride = resolu * stride; + const unsigned int bezt_array_last = bezt_array_len - 1; + + for (unsigned int i = 0; i < bezt_array_last; i++) { + const BezTriple *bezt_curr = &bezt_array[i]; + const BezTriple *bezt_next = &bezt_array[i + 1]; + BKE_curve_forward_diff_bezier( + bezt_curr->vec[1][axis], bezt_curr->vec[2][axis], + bezt_next->vec[0][axis], bezt_next->vec[1][axis], + r_points_offset, (int)resolu, stride); + r_points_offset = POINTER_OFFSET(r_points_offset, resolu_stride); + } + + if (is_cyclic) { + const BezTriple *bezt_curr = &bezt_array[bezt_array_last]; + const BezTriple *bezt_next = &bezt_array[0]; + BKE_curve_forward_diff_bezier( + bezt_curr->vec[1][axis], bezt_curr->vec[2][axis], + bezt_next->vec[0][axis], bezt_next->vec[1][axis], + r_points_offset, (int)resolu, stride); + r_points_offset = POINTER_OFFSET(r_points_offset, resolu_stride); + if (use_cyclic_duplicate_endpoint) { + *r_points_offset = *r_points; + r_points_offset = POINTER_OFFSET(r_points_offset, stride); + } + } + else { + float *r_points_last = POINTER_OFFSET(r_points, bezt_array_last * resolu_stride); + *r_points_last = bezt_array[bezt_array_last].vec[1][axis]; + r_points_offset = POINTER_OFFSET(r_points_offset, stride); + } + + BLI_assert(POINTER_OFFSET(r_points, points_len * stride) == r_points_offset); + UNUSED_VARS_NDEBUG(points_len); +} + /* forward differencing method for bezier curve */ void BKE_curve_forward_diff_bezier(float q0, float q1, float q2, float q3, float *p, int it, int stride) { |