16#ifdef __LITTLE_ENDIAN__
37 const char **r_err_str)
39 if (!fread(mdd_head,
sizeof(*mdd_head), 1, fp)) {
40 *r_err_str =
RPT_(
"Missing header");
44#ifdef __LITTLE_ENDIAN__
49 *r_err_str =
RPT_(
"Vertex count mismatch");
54 *r_err_str =
RPT_(
"Invalid frame total");
71 const char **r_err_str)
91 const char **r_err_str)
95 float f_time, f_time_prev =
FLT_MAX;
102 size_t frames_num_read = 0;
103 size_t frames_num_expect = mdd_head.
frame_tot;
106 frames_num_read += fread(&f_time,
sizeof(
float), 1, fp);
107#ifdef __LITTLE_ENDIAN__
110 if (f_time >= time) {
111 frames_num_expect =
i + 1;
114 f_time_prev = f_time;
117 if (frames_num_read != frames_num_expect) {
118 *r_err_str = errno ? strerror(errno) :
RPT_(
"Timestamp read failed");
126 const float range = f_time - f_time_prev;
132 frame = float(
i - 1) + ((time - f_time_prev) / range);
141 float (*vertexCos)[3],
145 const char **r_err_str)
154 *r_err_str =
RPT_(
"Header seek failed");
159 *r_err_str =
RPT_(
"Failed to seek frame");
163 size_t verts_read_num = 0;
165 if (factor >= 1.0f) {
167 float *vco = *vertexCos;
170 verts_read_num += fread(vco,
sizeof(
float[3]), 1, fp);
172# ifdef __LITTLE_ENDIAN__
180 if (!fread(vertexCos,
sizeof(
float[3]), mdd_head.
verts_tot, f)) {
181 *r_err_str = errno ? strerror(errno) :
RPT_(
"Failed to read frame");
184# ifdef __LITTLE_ENDIAN__
190 const float ifactor = 1.0f - factor;
191 float *vco = *vertexCos;
195 verts_read_num += fread(tvec,
sizeof(
float[3]), 1, fp);
197#ifdef __LITTLE_ENDIAN__
203 vco[0] = (vco[0] * ifactor) + (tvec[0] * factor);
204 vco[1] = (vco[1] * ifactor) + (tvec[1] * factor);
205 vco[2] = (vco[2] * ifactor) + (tvec[2] * factor);
209 if (verts_read_num != mdd_head.
verts_tot) {
210 *r_err_str = errno ? strerror(errno) :
RPT_(
"Vertex coordinate read failed");
218 float (*vertexCos)[3],
222 const char **r_err_str)
238 if (index_range[0] == index_range[1]) {
262 float (*vertexCos)[3],
267 const char time_mode,
268 const char **r_err_str)
276 *r_err_str = errno ? strerror(errno) :
RPT_(
"Unknown error opening file");
303 frame = std::clamp(time, 0.0f, 1.0f) * float(mdd_head.
frame_tot);
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)