64 if (ob->
runtime->curve_cache ==
nullptr) {
89 ob->
runtime->curve_cache->anim_path_accum_length = len_data;
92 float prev_len = 0.0f;
93 for (
int i = 0;
i < bl->
nr - 1;
i++) {
94 prev_len +=
len_v3v3(bp_arr[
i].vec, bp_arr[
i + 1].vec);
95 len_data[
i] = prev_len;
100 len_data[seg_size - 1] = prev_len +
len_v3v3(bp_arr[0].vec, bp_arr[bl->
nr - 1].
vec);
122 *r_p0 = &bp_arr[bl->
nr - 1];
140 if (idx == bl->
nr - 2) {
144 *r_p0 = &bp_arr[idx - 1];
145 *r_p1 = &bp_arr[idx];
146 *r_p2 = &bp_arr[idx + 1];
157 if (idx == bl->
nr - 1) {
160 *r_p0 = &bp_arr[idx - 1];
161 *r_p1 = &bp_arr[idx];
171 *r_p0 = &bp_arr[idx - 1];
172 *r_p1 = &bp_arr[idx];
173 *r_p2 = &bp_arr[idx + 1];
174 *r_p3 = &bp_arr[idx + 2];
179 const float goal_len,
183 float left_len, right_len;
184 int cur_idx = 0, cur_base = 0;
185 int cur_step = seg_size - 1;
191 *r_frac = goal_len / accum_len_arr[0];
197 cur_idx = cur_base + cur_step / 2;
198 left_len = accum_len_arr[cur_idx];
199 right_len = accum_len_arr[cur_idx + 1];
201 if (left_len <= goal_len && right_len > goal_len) {
202 *r_idx = cur_idx + 1;
203 *r_frac = (goal_len - left_len) / (right_len - left_len);
209 *r_frac = goal_len / accum_len_arr[0];
215 CLOG_ERROR(&
LOG,
"Couldn't find any valid point on the animation path!");
216 BLI_assert_msg(0,
"Couldn't find any valid point on the animation path!");
220 if (left_len < goal_len) {
222 cur_base = cur_idx + 1;
242 if (ob->
runtime->curve_cache ==
nullptr) {
246 if (ob->
runtime->curve_cache->anim_path_accum_length ==
nullptr) {
252 if (bl ==
nullptr || !bl->
nr) {
262 if (ctime < 0.0f || ctime > 1.0f) {
272 const float *accum_len_arr = ob->
runtime->curve_cache->anim_path_accum_length;
273 const float goal_len = ctime * accum_len_arr[seg_size - 1];
276 if (ctime <= 0.0f || ctime >= 1.0f) {
277 const float clamp_time =
clamp_f(ctime, 0.0f, 1.0f);
278 const int idx = clamp_time * (seg_size - 1);
282 frac = goal_len / accum_len_arr[0];
285 frac = (goal_len - accum_len_arr[idx - 1]) / (accum_len_arr[idx] - accum_len_arr[idx - 1]);
338 r_vec[0] =
w[0] * p0->
vec[0] +
w[1] * p1->
vec[0] +
w[2] * p2->
vec[0] +
w[3] * p3->
vec[0];
339 r_vec[1] =
w[0] * p0->
vec[1] +
w[1] * p1->
vec[1] +
w[2] * p2->
vec[1] +
w[3] * p3->
vec[1];
340 r_vec[2] =
w[0] * p0->
vec[2] +
w[1] * p1->
vec[2] +
w[2] * p2->
vec[2] +
w[3] * p3->
vec[2];
352 float totfac, q1[4], q2[4];
354 totfac =
w[0] +
w[3];
355 if (totfac > FLT_EPSILON) {
362 totfac =
w[1] +
w[2];
363 if (totfac > FLT_EPSILON) {
370 totfac =
w[0] +
w[1] +
w[2] +
w[3];
371 if (totfac > FLT_EPSILON) {
ListBase * BKE_curve_editNurbs_get(Curve *cu)
void key_curve_position_weights(float t, float data[4], KeyInterpolationType type)
void key_curve_tangent_weights(float t, float data[4], KeyInterpolationType type)
#define BLI_assert_msg(a, msg)
MINLINE float clamp_f(float value, float min, float max)
void interp_qt_qtqt(float q[4], const float a[4], const float b[4], float t)
void copy_qt_qt(float q[4], const float a[4])
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void clamp_v4(float vec[4], float min, float max)
MINLINE void negate_v3(float r[3])
void interp_v3_v3v3v3v3(float p[3], const float v1[3], const float v2[3], const float v3[3], const float v4[3], const float w[4])
#define CLOG_ERROR(clg_ref,...)
#define CLOG_WARN(clg_ref,...)
Object is a sort of wrapper for general info.
Read Guarded memory(de)allocation.
int BKE_anim_path_get_array_size(const CurveCache *curve_cache)
bool BKE_where_on_path(const Object *ob, float ctime, float r_vec[4], float r_dir[3], float r_quat[4], float *r_radius, float *r_weight)
static bool binary_search_anim_path(const float *accum_len_arr, const int seg_size, const float goal_len, int *r_idx, float *r_frac)
static void get_curve_points_from_idx(const int idx, const BevList *bl, const bool is_cyclic, BevPoint const **r_p0, BevPoint const **r_p1, BevPoint const **r_p2, BevPoint const **r_p3)
float BKE_anim_path_get_length(const CurveCache *curve_cache)
void BKE_anim_path_calc_data(Object *ob)
static int get_bevlist_seg_array_size(const BevList *bl)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
CCL_NAMESPACE_BEGIN ccl_device_inline float frac(const float x, ccl_private int *ix)
static bool is_cyclic(const Nurb *nu)
void * MEM_malloc_arrayN(size_t len, size_t size, const char *str)
const float * anim_path_accum_length
ObjectRuntimeHandle * runtime