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

Add tangents to the GLTF loader or generate if they don't exist. #121

Closed
StarArawn opened this issue Aug 11, 2020 · 4 comments
Closed

Add tangents to the GLTF loader or generate if they don't exist. #121

StarArawn opened this issue Aug 11, 2020 · 4 comments
Labels
A-Assets Load files from disk to use for things like images, models, and sounds C-Feature A new feature, making something new possible

Comments

@StarArawn
Copy link
Contributor

Tangents are useful for normal mapping and they are easy to load in from the model if they don't exist I would suggest using:
https://crates.io/crates/mikktspace

Mikktspace is what most 3D engines use to calculate tangents.

@karroffel karroffel added C-Feature A new feature, making something new possible A-Assets Load files from disk to use for things like images, models, and sounds labels Aug 12, 2020
@eliaspekkala
Copy link
Contributor

Yes, the library that Bevy uses to import 3D models (Gltf) supports loading in tangents so that should be fairly easy to add. Though, for calculating tangents for models that doesn't have them, there are some things to consider.

The Mikktspace crate depends on Nalgebra which would likely add a bit of time to Bevy's build times. If Mikktspace is used to calculate tangents in Bevy, maybe it would be possible to fork it and use Glam as the math library? Then Bevy's build times won't take as much of a hit, because Glam is already in use in Bevy.

An alternative way to add tangents to a model, that I know of, is to use Blender. I think Blender also uses the Mikktspace algorithm.

These are the steps:

  1. Open Blender and remove the default nodes (Cube, Camera, and Light).
  2. Press: File -> Import -> glTF 2.0 (or another format).
  3. Select your 3D model and press Import.
  4. Press: File -> Export -> glTF 2.0
  5. Expand the menu called Geometry and enable Tangents.
  6. Select folder to save to and press Export.

@StarArawn
Copy link
Contributor Author

Mikktspace seems to be the industry standard. I don't think it would be too difficult to either fork the Mikktspace crate and use glam or just pull into bevy directly. It is mostly a single file repo with 1800 loc.

I don't think we should have to rely on people using blender or some other 3D modeling program to generate tangents. The mesh asset should ideally generate them if they don't exist. Also this is a great article on normal mapping/tangents in general:
https://80.lv/articles/tutorial-types-of-normal-maps-common-problems/

@dvogel
Copy link

dvogel commented May 9, 2021

I've run into this problem. It seems Wings3D does not generate the required tangent data. I tested the code in #1795 and it allowed me to load the Wings3D-exported model without using another tool to re-export. I'd be happy it that was merged. However, I have very much enjoyed the fast build times w/ bevy and I would also be happy if bevy shipped a companion program to one-shot reprocess GLTF files to include this data. That seems like a reasonable compromise between making assets easy to use while also keeping the engine fast.

@alice-i-cecile
Copy link
Member

Closing this, as bevy_mikktspace now exists (however jank the auto-generated C might be).

hymm referenced this issue in hymm/bevy Jan 31, 2023
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 C-Feature A new feature, making something new possible
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants