64 if (ob->
runtime->curve_cache ==
nullptr) {
88 float *len_data = (
float *)
MEM_mallocN(
sizeof(
float) * seg_size,
"calcpathdist");
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;
188 cur_idx = cur_base + cur_step / 2;
189 left_len = accum_len_arr[cur_idx];
190 right_len = accum_len_arr[cur_idx + 1];
192 if (left_len <= goal_len && right_len > goal_len) {
193 *r_idx = cur_idx + 1;
194 *r_frac = (goal_len - left_len) / (right_len - left_len);
200 *r_frac = goal_len / accum_len_arr[0];
206 CLOG_ERROR(&
LOG,
"Couldn't find any valid point on the animation path!");
207 BLI_assert_msg(0,
"Couldn't find any valid point on the animation path!");
211 if (left_len < goal_len) {
213 cur_base = cur_idx + 1;
233 if (ob->
runtime->curve_cache ==
nullptr) {
237 if (ob->
runtime->curve_cache->anim_path_accum_length ==
nullptr) {
243 if (bl ==
nullptr || !bl->
nr) {
253 if (ctime < 0.0f || ctime > 1.0f) {
263 const float *accum_len_arr = ob->
runtime->curve_cache->anim_path_accum_length;
264 const float goal_len = ctime * accum_len_arr[seg_size - 1];
267 if (ctime <= 0.0f || ctime >= 1.0f) {
268 const float clamp_time =
clamp_f(ctime, 0.0f, 1.0f);
269 const int idx = clamp_time * (seg_size - 1);
273 frac = goal_len / accum_len_arr[0];
276 frac = (goal_len - accum_len_arr[idx - 1]) / (accum_len_arr[idx] - accum_len_arr[idx - 1]);
329 r_vec[0] =
w[0] * p0->
vec[0] +
w[1] * p1->
vec[0] +
w[2] * p2->
vec[0] +
w[3] * p3->
vec[0];
330 r_vec[1] =
w[0] * p0->
vec[1] +
w[1] * p1->
vec[1] +
w[2] * p2->
vec[1] +
w[3] * p3->
vec[1];
331 r_vec[2] =
w[0] * p0->
vec[2] +
w[1] * p1->
vec[2] +
w[2] * p2->
vec[2] +
w[3] * p3->
vec[2];
343 float totfac,
q1[4], q2[4];
345 totfac =
w[0] +
w[3];
346 if (totfac > FLT_EPSILON) {
353 totfac =
w[1] +
w[2];
354 if (totfac > FLT_EPSILON) {
361 totfac =
w[0] +
w[1] +
w[2] +
w[3];
362 if (totfac > FLT_EPSILON) {
ListBase * BKE_curve_editNurbs_get(Curve *cu)
void key_curve_tangent_weights(float t, float data[4], int type)
void key_curve_position_weights(float t, float data[4], int 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(float x, ccl_private int *ix)
static bool is_cyclic(const Nurb *nu)
void *(* MEM_mallocN)(size_t len, const char *str)
const float * anim_path_accum_length
ObjectRuntimeHandle * runtime