Skip to content
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

Loss of precision due to 32 bit floating point numbers #267

Open
trygveaa opened this issue Sep 9, 2021 · 0 comments
Open

Loss of precision due to 32 bit floating point numbers #267

trygveaa opened this issue Sep 9, 2021 · 0 comments

Comments

@trygveaa
Copy link

trygveaa commented Sep 9, 2021

I have an OBJ file which is placed at a specific position on the earth, which means that the coordinates in the file are large numbers. As far as I can see, obj2gltf uses 32 bit floating point numbers both when parsing the OBJ file and when writing to the glTF file. This means that the coordinates loose precision and the geometry end up becoming distorted.

As far as I've understood the reason for using 32 bit floating point numbers is that WebGL doesn't support 64 bit floating point numbers?

The way I've solved this for now is to subtract a number from all the coordinates in the file before I convert it with obj2gltf, and then set a translation on the glTF with those coordinates afterwards. This works, but I was wondering if you had any other solution, and if this is something you could fix, or a limitation that you can't fix because of WebGL?

Here is the OBJ file:
high-coordinates.obj.txt

Here it is directly converted to glTF:
high-coordinates-distorted.gltf.txt

And here it is converted by subtracting coordinates and applying a translation:
high-coordinates-proper.gltf.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant