-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fastgltf is mangling GLB files #88
Comments
Thank you for the report. My first idea is that the conversion from floats to strings in the exporting code is causing this, since I just use |
ok so #include <charconv>
#include <string>
#include <fmt/format.h>
std::string with_to_chars(float in, auto... format_args) {
const size_t buf_size = 30;
char buf[buf_size]{};
std::to_chars_result result = std::to_chars(buf, buf + buf_size, in, format_args...);
return std::string(buf, result.ptr - buf);
}
int main() {
static constexpr float input = 0.01996302604675293;
fmt::print("{}\n", std::to_string(input));
fmt::print("{}\n", with_to_chars(input, std::chars_format::fixed));
fmt::print("{}\n", with_to_chars(input, std::chars_format::fixed, 22));
fmt::print("{}\n", input);
fmt::print("{:.17f}\n", input);
fmt::print("{:.22f}\n", input);
}
While I'd love to use I'll look into fixing it this evening and seeing how many digits I need to actually print to guarantee round-trip precision. |
I would suggest looking at the Grisu2 algorithm, which was used to fix a similar problem here: godotengine/godot#98750 |
I've now changed the source to use simdjson's embedded grisu2 implementation and have added a test that now succeeds and shows that the round-trip precision is correct. Thanks for the report. |
Most of the glb files in the GLTF-Sample-Models repo end up getting mangled when rewritten by fastgltf.
Consider a simple example:
The outputted file ends up throwing errors when put through the gltf validator:
This is consistent across most glb files present in the sample repo. Modifying extensions for the parser doesn't change this, neither does forcing 64-bit only, etc.
Tested on MacOS M4 Max, 15.1
The text was updated successfully, but these errors were encountered: