feat: updated engine

This commit is contained in:
Sara Gerretsen 2026-07-10 17:04:34 +02:00
parent cbe99774ff
commit f4cf6b3999
6607 changed files with 910135 additions and 430025 deletions

View file

@ -2,6 +2,8 @@
#include "meshoptimizer.h"
#include <assert.h>
#include <float.h>
#include <math.h>
union FloatBits
{
@ -74,3 +76,52 @@ float meshopt_dequantizeHalf(unsigned short h)
u.ui = s | r;
return u.f;
}
int meshopt_computePositionExponent(const float* minv, const float* maxv, int min_exp, int max_bits)
{
assert(min_exp >= -126);
assert(max_bits >= 2 && max_bits <= 24);
int exp = min_exp;
// compute max absolute component to ensure that individual endpoints fit on a 24-bit signed grid
float maxc = 0.f;
for (int k = 0; k < 3; ++k)
{
maxc = maxc < fabsf(minv[k]) ? fabsf(minv[k]) : maxc;
maxc = maxc < fabsf(maxv[k]) ? fabsf(maxv[k]) : maxc;
}
int maxc_exp = 0;
float maxc_fr = frexpf(maxc, &maxc_exp);
// maxc is representable as 2^(maxc_exp-24) * 24-bit *unsigned* integer
// we have to use a 24-bit *signed* grid, so we have to chop off the last bit
// however, rounding in the corner case (mantissa is 1.111...) may increase the exponent by 1 so we need to offset it
int maxc_off = 23 - (maxc_fr >= 1.f - FLT_EPSILON / 2);
exp = exp < maxc_exp - maxc_off ? maxc_exp - maxc_off : exp;
// compute effective range with conservative rounding, to allow for some ambiguity in the caller's rounding direction
float scale = ldexpf(1.f, -exp);
float range = 0.f;
for (int k = 0; k < 3; ++k)
{
float a = floorf(minv[k] * scale);
float v = ceilf(maxv[k] * scale);
range = range < v - a ? v - a : range;
}
// range must be representable as max_bits unsigned integer
int range_exp = 0;
float range_fr = frexpf(range, &range_exp);
exp += (range_exp > max_bits) ? range_exp - max_bits : 0;
// correct range if we are at the rounding boundary that would push us to overflow max_bits
exp += range_exp > max_bits && range_fr >= 1.f - 1.f / float((1 << max_bits) - 1);
return exp;
}