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

VertexPreprocessor unnecesssarily normalizing all normal and tangent vectors #243

Closed
vermadas opened this issue Jul 25, 2024 · 4 comments
Closed

Comments

@vermadas
Copy link

In the SanitizeVertexGeometry lambda there are two if statements that have typos in their conditionals that's causing all normal and tangent vectors to be normalized. First here:

if (l < 0.99f || l > 0.01f) vertex.SetNormal(Vector3.Normalize(n));

Second here:
if (l < 0.99f || l > 0.01f) t = Vector3.Normalize(t);

I'm guessing that those if statements should read if (l < 0.99f || l > 1.01f)

Normally, this shouldn't be an issue. However, several models I was building with morph animations were failing validation because they had zero MorphTargetsCount instead of the expected. When I was saving vertices to the meshbuilder, the normals on the vertices were always being normalized, despite me normalizing them upstream. And for some reason, some of them were changing very slightly with minor floating point precision differences. So when the MorphTargetBuilder was keeping track of the vertex geometry as keys in a dictionary, they were not being found when I was calling SetVertex.

<0, -0.4185573, -0.90819037> became <0, -0.41855732, -0.9081904>, for example.

@vpenades
Copy link
Owner

yeah, these values are definitely wrong

I'll look into it.

@vpenades
Copy link
Owner

vpenades commented Jul 25, 2024

I've checked the issue, the fact that the renormalization (or any other vertex sanitization step) can alter how the morph targets are processed is an unexpected and undesirable effect I did not foresee.

I've fixed the code so it only runs when the normals and tangets are indeed out of bounds and not indiscriminately.

You can try the code with the latest commit with the bounds check fix.

Alternatively, if you know you're feeding clean vertices, you can also configure the VertexPreprocessorLambdas with empty ones that do nothing. This will make the code to run slightly faster, and will ensure the library does not modify the vertices in any way.

Feel free to close the issue if you consider this as the appropiate solution, and thanks for reporting it. I bet you expended quite some time figuring out the source of the problem.

@vermadas
Copy link
Author

Yes, it was a bit frustrating to figure out. I kept making wrong assumptions about why or where it was happening. And issue #208 was a bit of a red herring since their symptoms lined up with mine.

Thank you for the quick fix though!

@vpenades
Copy link
Owner

Because the unit tests take so long, I got a late test error, it's fixed an the next commit.

Morph targets is a nightmare to deal with, and the fact that vertices can have any kind of morphable attribute does not help either.

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

2 participants