Blender  V3.3
MOD_meshcache_util.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include "BLI_utildefines.h"
8 
9 #include "BLI_math.h"
10 
11 #include "DNA_modifier_types.h"
12 
13 #include "MOD_meshcache_util.h"
14 
15 void MOD_meshcache_calc_range(const float frame,
16  const char interp,
17  const int frame_tot,
18  int r_index_range[2],
19  float *r_factor)
20 {
22  r_index_range[0] = r_index_range[1] = max_ii(0, min_ii(frame_tot - 1, round_fl_to_int(frame)));
23  *r_factor = 1.0f; /* dummy */
24  }
25  else {
26  const float tframe = floorf(frame);
27  const float range = frame - tframe;
28  r_index_range[0] = (int)tframe;
29  if (range <= FRAME_SNAP_EPS) {
30  /* we're close enough not to need blending */
31  r_index_range[1] = r_index_range[0];
32  *r_factor = 1.0f; /* dummy */
33  }
34  else {
35  /* blend between 2 frames */
36  r_index_range[1] = r_index_range[0] + 1;
37  *r_factor = range;
38  }
39 
40  /* clamp */
41  if ((r_index_range[0] >= frame_tot) || (r_index_range[1] >= frame_tot)) {
42  r_index_range[0] = r_index_range[1] = frame_tot - 1;
43  *r_factor = 1.0f; /* dummy */
44  }
45  else if ((r_index_range[0] < 0) || (r_index_range[1] < 0)) {
46  r_index_range[0] = r_index_range[1] = 0;
47  *r_factor = 1.0f; /* dummy */
48  }
49  }
50 }
MINLINE int round_fl_to_int(float a)
MINLINE int min_ii(int a, int b)
MINLINE int max_ii(int a, int b)
@ MOD_MESHCACHE_INTERP_NONE
void MOD_meshcache_calc_range(const float frame, const char interp, const int frame_tot, int r_index_range[2], float *r_factor)
#define FRAME_SNAP_EPS
ccl_device_inline float2 interp(const float2 &a, const float2 &b, float t)
Definition: math_float2.h:232
#define floorf(x)
Definition: metal/compat.h:224