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

Fox.glb has incorrectly scaled normals #8099

Open
NotAFile opened this issue Mar 15, 2023 · 9 comments
Open

Fox.glb has incorrectly scaled normals #8099

NotAFile opened this issue Mar 15, 2023 · 9 comments
Labels
A-Assets Load files from disk to use for things like images, models, and sounds A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior C-Examples An addition or correction to our examples D-Trivial Nice and easy! A great choice to get started with Bevy

Comments

@NotAFile
Copy link

Bevy version

35e107c

What went wrong

The Fox.glb model has incorrect scaling of the vertex normals.

e.g. for the first vertex, the normals are:

0.176476 -0.507666 -0.242626

correctly scaled would be:

0.299268 -0.860901 -0.411446

This has led to issues such as #6528. That has been fixed, but it would be good to fix this at the source anyway.

@NotAFile NotAFile added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Mar 15, 2023
@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen C-Examples An addition or correction to our examples A-Assets Load files from disk to use for things like images, models, and sounds D-Trivial Nice and easy! A great choice to get started with Bevy and removed S-Needs-Triage This issue needs to be labelled labels Mar 15, 2023
@alecgarza96
Copy link

New to Bevy, would love to help out. Still learning the codebase

Does this change involve edits to the 3D model itself? I looked under examples/animated_fox.rs and didn't find any code performing scaling.

I've been searching under crates/bevy_render as well for where this error could be originating

@james7132
Copy link
Member

Does this change involve edits to the 3D model itself? I looked under examples/animated_fox.rs and didn't find any code performing scaling.

Looks like it. There's no normalization code we do on any meshes by default. IMO we should any or all of the following:

  • Update the 3D model itself to include normalized normals
  • Add a validation step when loading meshes to ensure normals are normalized.
  • Add a asset preprocessing step to do this when that pipeline is ready (contingent on the asset rework @cart's working on)

@alecgarza96
Copy link

Does this change involve edits to the 3D model itself? I looked under examples/animated_fox.rs and didn't find any code performing scaling.

Looks like it. There's no normalization code we do on any meshes by default. IMO we should any or all of the following:

  • Update the 3D model itself to include normalized normals
  • Add a validation step when loading meshes to ensure normals are normalized.
  • Add a asset preprocessing step to do this when that pipeline is ready (contingent on the asset rework @cart's working on)

Looking into adding the validation step for when meshes are normalized

I found the compute_flat_normals method which utilizes the face_normal

would it be possible to reuse this functionality for the validation check, or do we want to calculate the standard normals instead of flat?

Also, at what point should the validation check occur? My initial thoughts are in either ::new() or inert_attribute()

@JohnTheCoolingFan
Copy link
Contributor

While you are figuring out validation, I've been trying to fix the model itself. I've loaded it into blender, recalculated normals (removed duplicate vertices, recalculated, disconnected faces back, export). Visually nothing changed (judging by blender's normal visualization), I tried it on commit specified in #6528 and it's still black. I've uploaded my updated model to a fork: https://github.com/JohnTheCoolingFan/bevy/blob/dfdda55edb9e1ac6f6d497259faed32dd300068b/assets/models/animated/Fox.glb

@NotAFile
Copy link
Author

For reference, the way I personally did the normalization was via MeshLab, which has a "normalize normals" option. I unfortunately could not get to output a drop in replacement .glb file though.

@mockersf
Copy link
Member

mockersf commented Apr 13, 2023

I would prefer to not change the model at all. It should come straight from https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/Fox without any modification. If it's wrong and need updating, could you submit your fix on the gltf sample repo?

@nicopap
Copy link
Contributor

nicopap commented Apr 13, 2023

I believe one of the aim of glTF is avoiding the kind of pitfall where everything needs to be sanitized and recomputed, it's "GPU ready". The glTF standard unambiguously says the normal attributes are normalized so if the model doesn't have normalized normals, it's probably in infraction of the standard.

@mockersf
Copy link
Member

If the wrong normals are confirmed on the upstream fox, fixing them would be very nice. If not, we can update ours with the original 👍

@NotAFile
Copy link
Author

There's been a commit about "fixing validation errors" upstream that's newer than the in-tree copy, perhaps pulling that in would actually already be enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Assets Load files from disk to use for things like images, models, and sounds A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior C-Examples An addition or correction to our examples D-Trivial Nice and easy! A great choice to get started with Bevy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants