18#ifdef __LITTLE_ENDIAN__
39 const char **r_err_str)
41 if (!fread(mdd_head,
sizeof(*mdd_head), 1, fp)) {
42 *r_err_str =
RPT_(
"Missing header");
46#ifdef __LITTLE_ENDIAN__
51 *r_err_str =
RPT_(
"Vertex count mismatch");
56 *r_err_str =
RPT_(
"Invalid frame total");
73 const char **r_err_str)
93 const char **r_err_str)
97 float f_time, f_time_prev =
FLT_MAX;
104 size_t frames_num_read = 0;
105 size_t frames_num_expect = mdd_head.
frame_tot;
107 for (i = 0; i < mdd_head.
frame_tot; i++) {
108 frames_num_read += fread(&f_time,
sizeof(
float), 1, fp);
109#ifdef __LITTLE_ENDIAN__
112 if (f_time >= time) {
113 frames_num_expect = i + 1;
116 f_time_prev = f_time;
119 if (frames_num_read != frames_num_expect) {
120 *r_err_str = errno ? strerror(errno) :
RPT_(
"Timestamp read failed");
128 const float range = f_time - f_time_prev;
134 frame =
float(i - 1) + ((time - f_time_prev) / range);
143 float (*vertexCos)[3],
147 const char **r_err_str)
156 *r_err_str =
RPT_(
"Header seek failed");
161 *r_err_str =
RPT_(
"Failed to seek frame");
165 size_t verts_read_num = 0;
167 if (factor >= 1.0f) {
169 float *vco = *vertexCos;
171 for (i = mdd_head.
verts_tot; i != 0; i--, vco += 3) {
172 verts_read_num += fread(vco,
sizeof(
float[3]), 1, fp);
174# ifdef __LITTLE_ENDIAN__
182 if (!fread(vertexCos,
sizeof(
float[3]), mdd_head.
verts_tot, f)) {
183 *r_err_str = errno ? strerror(errno) :
RPT_(
"Failed to read frame");
186# ifdef __LITTLE_ENDIAN__
192 const float ifactor = 1.0f - factor;
193 float *vco = *vertexCos;
195 for (i = mdd_head.
verts_tot; i != 0; i--, vco += 3) {
197 verts_read_num += fread(tvec,
sizeof(
float[3]), 1, fp);
199#ifdef __LITTLE_ENDIAN__
205 vco[0] = (vco[0] * ifactor) + (tvec[0] * factor);
206 vco[1] = (vco[1] * ifactor) + (tvec[1] * factor);
207 vco[2] = (vco[2] * ifactor) + (tvec[2] * factor);
211 if (verts_read_num != mdd_head.
verts_tot) {
212 *r_err_str = errno ? strerror(errno) :
RPT_(
"Vertex coordinate read failed");
220 float (*vertexCos)[3],
224 const char **r_err_str)
240 if (index_range[0] == index_range[1]) {
264 float (*vertexCos)[3],
269 const char time_mode,
270 const char **r_err_str)
278 *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)
draw_view in_light_buf[] float
ccl_device_inline float2 interp(const float2 a, const float2 b, float t)