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

Generate normals automatically for glTF 2.0 models #6506

Open
lilleyse opened this issue Apr 27, 2018 · 6 comments
Open

Generate normals automatically for glTF 2.0 models #6506

lilleyse opened this issue Apr 27, 2018 · 6 comments

Comments

@lilleyse
Copy link
Contributor

From the glTF spec

Implementation note: When normals are not specified, client implementations should calculate flat normals.

This would replace the stopgap solution in #6501.

@emackey
Copy link
Contributor

emackey commented Aug 30, 2018

Note: Make sure to not calculate normals for materials where the unlit extension is in use (#6977)

@lilleyse
Copy link
Contributor Author

Related issue: #10465

@ptrgags
Copy link
Contributor

ptrgags commented Jul 7, 2022

The implementation for this will be quite similar to what I did for outlines in #10506. This can be done by:

  • Create a class (perhaps FlatNormalGenerator) that takes typed arrays for indices/attributes and generates the flat normal attribute. Vertices will need to be duplicated in most cases since the normal is different for each adjacent face. See PrimitiveOutlineGenerator for an example of how I did the indices/attribute processing
  • In PrimitiveLoadPlan:
    • Add a needsFlatNormals flag (similar to the needsOutlines flag)
    • update postProcess() to generate flat normals (using FlatNormalGenerator) if needed.
    • I think normals should be processed first because it's more likely to duplicate vertices. The more the vertices are duplicated, the less work the outline stage needs to do to generate outline coordinates.
  • Update GltfLoader to check for primitives without normals. if so, update details in the loadPlan so the attributes load as attribute.packedTypedArray and then are post-processed.

@j9liu
Copy link
Contributor

j9liu commented Aug 16, 2022

@lilleyse
Copy link
Contributor Author

@javagl
Copy link
Contributor

javagl commented Mar 3, 2024

Came up again in https://community.cesium.com/t/3d-model-does-not-display-shades/30269/11

EDIT: And for those stumbling over this issue, in general, or via one of the linked threads: The post at https://community.cesium.com/t/3d-model-does-not-display-shades/30269/11 also contains short instructions for how to add normals to existing models, as a workaround until this issue is fixed.

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

No branches or pull requests

6 participants