15 #ifdef __LITTLE_ENDIAN__
36 if (!fread(mdd_head,
sizeof(*mdd_head), 1, fp)) {
37 *err_str =
"Missing header";
41 #ifdef __LITTLE_ENDIAN__
46 *err_str =
"Vertex count mismatch";
51 *err_str =
"Invalid frame total";
92 float f_time, f_time_prev = FLT_MAX;
99 size_t frames_num_read = 0;
100 size_t frames_num_expect = mdd_head.
frame_tot;
102 for (i = 0; i < mdd_head.
frame_tot; i++) {
103 frames_num_read += fread(&f_time,
sizeof(
float), 1, fp);
104 #ifdef __LITTLE_ENDIAN__
107 if (f_time >=
time) {
108 frames_num_expect = i + 1;
111 f_time_prev = f_time;
114 if (frames_num_read != frames_num_expect) {
115 *err_str = errno ? strerror(errno) :
"Timestamp read failed";
122 if (
UNLIKELY(f_time_prev == FLT_MAX)) {
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 **err_str)
154 *err_str =
"Header seek failed";
159 *err_str =
"Failed to seek frame";
163 size_t verts_read_num = 0;
165 if (factor >= 1.0f) {
167 float *vco = *vertexCos;
169 for (i = mdd_head.
verts_tot; i != 0; i--, vco += 3) {
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 *err_str = errno ? strerror(errno) :
"Failed to read frame";
184 # ifdef __LITTLE_ENDIAN__
190 const float ifactor = 1.0f - factor;
191 float *vco = *vertexCos;
193 for (i = mdd_head.
verts_tot; i != 0; i--, vco += 3) {
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 *err_str = errno ? strerror(errno) :
"Vertex coordinate read failed";
218 float (*vertexCos)[3],
222 const char **err_str)
237 if (index_range[0] == index_range[1]) {
259 float (*vertexCos)[3],
264 const char time_mode,
265 const char **err_str)
273 *err_str = errno ? strerror(errno) :
"Unknown error opening file";
typedef float(TangentPoint)[2]
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
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 **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 **err_str)
static bool meshcache_read_mdd_range_from_time(FILE *fp, const int verts_tot, const float time, const float UNUSED(fps), float *r_frame, const char **err_str)
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 **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 **err_str)
static bool meshcache_read_mdd_head(FILE *fp, const int verts_tot, MDDHead *mdd_head, const char **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 float2 interp(const float2 &a, const float2 &b, float t)