Blender V5.3
MOD_meshcache_util.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_math_base_c.hh"
10
11#include "DNA_modifier_types.h"
12
13#include "MOD_meshcache_util.hh"
14
15namespace blender {
16
17void MOD_meshcache_calc_range(const float frame,
18 const char interp,
19 const int frame_tot,
20 int r_index_range[2],
21 float *r_factor)
22{
24 r_index_range[0] = r_index_range[1] = max_ii(0, min_ii(frame_tot - 1, round_fl_to_int(frame)));
25 *r_factor = 1.0f; /* dummy */
26 }
27 else {
28 const float tframe = floorf(frame);
29 const float range = frame - tframe;
30 r_index_range[0] = int(tframe);
31 if (range <= FRAME_SNAP_EPS) {
32 /* we're close enough not to need blending */
33 r_index_range[1] = r_index_range[0];
34 *r_factor = 1.0f; /* dummy */
35 }
36 else {
37 /* blend between 2 frames */
38 r_index_range[1] = r_index_range[0] + 1;
39 *r_factor = range;
40 }
41
42 /* clamp */
43 if ((r_index_range[0] >= frame_tot) || (r_index_range[1] >= frame_tot)) {
44 r_index_range[0] = r_index_range[1] = frame_tot - 1;
45 *r_factor = 1.0f; /* dummy */
46 }
47 else if ((r_index_range[0] < 0) || (r_index_range[1] < 0)) {
48 r_index_range[0] = r_index_range[1] = 0;
49 *r_factor = 1.0f; /* dummy */
50 }
51 }
52}
53
54} // namespace blender
#define FRAME_SNAP_EPS
ccl_device_inline float interp(const float a, const float b, const float t)
Definition math_base.h:549
BMesh Iterators.
MINLINE int round_fl_to_int(float a)
void MOD_meshcache_calc_range(const float frame, const char interp, const int frame_tot, int r_index_range[2], float *r_factor)
MINLINE int max_ii(int a, int b)
MINLINE int min_ii(int a, int b)
#define floorf