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

ExportBodyToStl produces non-manifold stl files due to roundoff issues on the vertex #49

Open
R7President opened this issue Dec 2, 2020 · 1 comment
Labels

Comments

@R7President
Copy link

all of these vertexes I think are supposed to be the same, but because of roundoff errors in the 11+th decimal point they end up looking like different vertex, that creates tiny holes in the mesh:
vertex 0.5 -0.5000000000000001 -0.20710678118654358
vertex 0.5 0.2071067811865434 -0.5
vertex 0.5 0.2071067811865434 -0.5
vertex 0.5 0.20710678118654346 -0.5
vertex 0.5 0.2071067811865435 -0.5
vertex 0.5 0.20710678118655118 0.5
vertex 0.5 0.20710678118655124 0.5
vertex 0.5 0.20710678118655135 0.5
vertex 0.5 0.20710678118655135 0.5
vertex 0.5 0.49999999999999983 -0.2071067811865514
vertex 0.5 0.49999999999999983 -0.2071067811865514
vertex 0.5 0.5 -0.20710678118655118
vertex 0.5 0.5 -0.20710678118655118
recommended solution in exporter.js:
function fToStr(f)
{
return (+f).toExponential(11).replace(/0+e/,'e');
}
function AddTriangleToContent (normal, vertex1, vertex2, vertex3)
{
AddLineToContent ('\tfacet normal ' + fToStr(normal.x) + ' ' + fToStr(normal.y) + ' ' + fToStr(normal.z));
AddLineToContent ('\t\touter loop');
AddLineToContent ('\t\t\tvertex ' + fToStr(vertex1.x) + ' ' + fToStr(vertex1.y) + ' ' + fToStr(vertex1.z));
AddLineToContent ('\t\t\tvertex ' + fToStr(vertex2.x) + ' ' + fToStr(vertex2.y) + ' ' + fToStr(vertex2.z));
AddLineToContent ('\t\t\tvertex ' + fToStr(vertex3.x) + ' ' + fToStr(vertex3.y) + ' ' + fToStr(vertex3.z));
AddLineToContent ('\t\tendloop');
AddLineToContent ('\tendfacet');
}

unfortunately this prints "0.5" as "5.e-1" but this is necessary to get the maximum resolution. I did find that toExponential(12) does occasionally still produce an error.
The replace portion is just to remove trailing zeros thus shortening the output.

@kovacsv kovacsv added the bug label Dec 15, 2020
@kovacsv
Copy link
Owner

kovacsv commented Dec 15, 2020

Thank you for the report. If the proposed solution fixes the issue, please open a pull request with that!

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

No branches or pull requests

2 participants