Beispiel #1
0
void BLI_endian_switch_float_array(float *val, const int size)
{
	if (size > 0) {
		int i = size;
		val = val + (size - 1);
		while (i--) {
			BLI_endian_switch_float(val--);
		}
	}
}
Beispiel #2
0
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)
{
	MDDHead mdd_head;
	int i;
	float f_time, f_time_prev = FLT_MAX;
	float frame;

	if (meshcache_read_mdd_head(fp, verts_tot, &mdd_head, err_str) == false) {
		return false;
	}

	for (i = 0; i < mdd_head.frame_tot; i++) {
		fread(&f_time, sizeof(float), 1, fp);
#ifdef __LITTLE_ENDIAN__
		BLI_endian_switch_float(&f_time);
#endif
		if (f_time >= time) {
			break;
		}
		f_time_prev = f_time;
	}

	if (i == mdd_head.frame_tot) {
		frame = (float)(mdd_head.frame_tot - 1);
	}
	if (UNLIKELY(f_time_prev == FLT_MAX)) {
		frame = 0.0f;
	}
	else {
		const float range  = f_time - f_time_prev;

		if (range <= FRAME_SNAP_EPS) {
			frame = (float)i;
		}
		else {
			frame = (float)(i - 1) + ((time - f_time_prev) / range);
		}
	}

	*r_frame = frame;
	return true;
}
Beispiel #3
0
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)
{
	MDDHead mdd_head;

	if (meshcache_read_mdd_head(fp, verts_tot, &mdd_head, err_str) == false) {
		return false;
	}

	if (fseek(fp, mdd_head.frame_tot * sizeof(int), SEEK_CUR) != 0) {
		*err_str = "Header seek failed";
		return false;
	}

	if (fseek(fp, index * mdd_head.verts_tot * sizeof(float) * 3, SEEK_CUR) != 0) {
		*err_str = "Failed to seek frame";
		return false;
	}

	if (factor >= 1.0f) {
#if 1
		float *vco = *vertexCos;
		unsigned int i;
		for (i = mdd_head.verts_tot; i != 0 ; i--, vco += 3) {
			fread(vco, sizeof(float) * 3, 1, fp);

#  ifdef __LITTLE_ENDIAN__
			BLI_endian_switch_float(vco + 0);
			BLI_endian_switch_float(vco + 1);
			BLI_endian_switch_float(vco + 2);
#  endif  /* __LITTLE_ENDIAN__ */
		}
#else
		/* no blending */
		if (!fread(vertexCos, sizeof(float) * 3, mdd_head.verts_tot, f)) {
			*err_str = errno ? strerror(errno) : "Failed to read frame";
			return false;
		}
#  ifdef __LITTLE_ENDIAN__
		BLI_endian_switch_float_array(vertexCos[0], mdd_head.verts_tot * 3);
#  endif
#endif
	}
	else {
		const float ifactor = 1.0f - factor;
		float *vco = *vertexCos;
		unsigned int i;
		for (i = mdd_head.verts_tot; i != 0 ; i--, vco += 3) {
			float tvec[3];
			fread(tvec, sizeof(float) * 3, 1, fp);

#ifdef __LITTLE_ENDIAN__
			BLI_endian_switch_float(tvec + 0);
			BLI_endian_switch_float(tvec + 1);
			BLI_endian_switch_float(tvec + 2);
#endif

			vco[0] = (vco[0] * ifactor) + (tvec[0] * factor);
			vco[1] = (vco[1] * ifactor) + (tvec[1] * factor);
			vco[2] = (vco[2] * ifactor) + (tvec[2] * factor);
		}
	}

	return true;
}