35 const char **r_err_str)
37 if (!fread(mdd_head,
sizeof(*mdd_head), 1, fp)) {
38 *r_err_str =
RPT_(
"Missing header");
47 *r_err_str =
RPT_(
"Vertex count mismatch");
52 *r_err_str =
RPT_(
"Invalid frame total");
69 const char **r_err_str)
89 const char **r_err_str)
93 float f_time, f_time_prev =
FLT_MAX;
100 size_t frames_num_read = 0;
101 size_t frames_num_expect = mdd_head.
frame_tot;
104 frames_num_read += fread(&f_time,
sizeof(
float), 1, fp);
109 if (f_time >= time) {
110 frames_num_expect =
i + 1;
113 f_time_prev = f_time;
116 if (frames_num_read != frames_num_expect) {
117 *r_err_str = errno ? strerror(errno) :
RPT_(
"Timestamp read failed");
125 const float range = f_time - f_time_prev;
131 frame =
float(
i - 1) + ((time - f_time_prev) / range);
140 float (*vertexCos)[3],
144 const char **r_err_str)
153 *r_err_str =
RPT_(
"Header seek failed");
158 *r_err_str =
RPT_(
"Failed to seek frame");
162 size_t verts_read_num = 0;
164 if (factor >= 1.0f) {
166 float *vco = *vertexCos;
169 verts_read_num += fread(vco,
sizeof(
float[3]), 1, fp);
179 if (!fread(vertexCos,
sizeof(
float[3]), mdd_head.
verts_tot, f)) {
180 *r_err_str = errno ? strerror(errno) :
RPT_(
"Failed to read frame");
189 const float ifactor = 1.0f - factor;
190 float *vco = *vertexCos;
194 verts_read_num += fread(tvec,
sizeof(
float[3]), 1, fp);
202 vco[0] = (vco[0] * ifactor) + (tvec[0] * factor);
203 vco[1] = (vco[1] * ifactor) + (tvec[1] * factor);
204 vco[2] = (vco[2] * ifactor) + (tvec[2] * factor);
208 if (verts_read_num != mdd_head.
verts_tot) {
209 *r_err_str = errno ? strerror(errno) :
RPT_(
"Vertex coordinate read failed");
217 float (*vertexCos)[3],
221 const char **r_err_str)
237 if (index_range[0] == index_range[1]) {
261 float (*vertexCos)[3],
266 const char time_mode,
267 const char **r_err_str)
275 *r_err_str = errno ? strerror(errno) :
RPT_(
"Unknown error opening file");
void BLI_endian_switch_float_array(float *val, int size) ATTR_NONNULL(1)
void BLI_endian_switch_int32_array(int *val, int size) ATTR_NONNULL(1)
BLI_INLINE void BLI_endian_switch_float(float *val) ATTR_NONNULL(1)
File and directory operations.
FILE * BLI_fopen(const char *filepath, const char *mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
int BLI_fseek(FILE *stream, int64_t offset, int whence)
Compatibility-like things for windows.
@ MOD_MESHCACHE_TIME_FRAME
@ MOD_MESHCACHE_TIME_FACTOR
@ MOD_MESHCACHE_TIME_SECONDS
static bool meshcache_read_mdd_range(FILE *fp, const int verts_tot, const float frame, const char interp, int r_index_range[2], float *r_factor, const char **r_err_str)
bool MOD_meshcache_read_mdd_times(const char *filepath, float(*vertexCos)[3], const int verts_tot, const char interp, const float time, const float fps, const char time_mode, const char **r_err_str)
bool MOD_meshcache_read_mdd_frame(FILE *fp, float(*vertexCos)[3], const int verts_tot, const char interp, const float frame, const char **r_err_str)
static bool meshcache_read_mdd_range_from_time(FILE *fp, const int verts_tot, const float time, const float, float *r_frame, const char **r_err_str)
static bool meshcache_read_mdd_head(FILE *fp, const int verts_tot, MDDHead *mdd_head, const char **r_err_str)
bool MOD_meshcache_read_mdd_index(FILE *fp, float(*vertexCos)[3], const int verts_tot, const int index, const float factor, const char **r_err_str)
void MOD_meshcache_calc_range(const float frame, const char interp, const int frame_tot, int r_index_range[2], float *r_factor)
ccl_device_inline float interp(const float a, const float b, const float t)