Blender  V2.93
MOD_meshcache_util.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include "BLI_utildefines.h"
22 
23 #include "BLI_math.h"
24 
25 #include "DNA_modifier_types.h"
26 
27 #include "MOD_meshcache_util.h"
28 
29 void MOD_meshcache_calc_range(const float frame,
30  const char interp,
31  const int frame_tot,
32  int r_index_range[2],
33  float *r_factor)
34 {
36  r_index_range[0] = r_index_range[1] = max_ii(0, min_ii(frame_tot - 1, round_fl_to_int(frame)));
37  *r_factor = 1.0f; /* dummy */
38  }
39  else {
40  const float tframe = floorf(frame);
41  const float range = frame - tframe;
42  r_index_range[0] = (int)tframe;
43  if (range <= FRAME_SNAP_EPS) {
44  /* we're close enough not to need blending */
45  r_index_range[1] = r_index_range[0];
46  *r_factor = 1.0f; /* dummy */
47  }
48  else {
49  /* blend between 2 frames */
50  r_index_range[1] = r_index_range[0] + 1;
51  *r_factor = range;
52  }
53 
54  /* clamp */
55  if ((r_index_range[0] >= frame_tot) || (r_index_range[1] >= frame_tot)) {
56  r_index_range[0] = r_index_range[1] = frame_tot - 1;
57  *r_factor = 1.0f; /* dummy */
58  }
59  else if ((r_index_range[0] < 0) || (r_index_range[1] < 0)) {
60  r_index_range[0] = r_index_range[1] = 0;
61  *r_factor = 1.0f; /* dummy */
62  }
63  }
64 }
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
#define floorf(x)
ccl_device_inline float2 interp(const float2 &a, const float2 &b, float t)