cesium icon indicating copy to clipboard operation
cesium copied to clipboard

Generate normals automatically for glTF 2.0 models

Open lilleyse opened this issue 7 years ago • 6 comments

From the glTF spec

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

This would replace the stopgap solution in https://github.com/AnalyticalGraphicsInc/cesium/pull/6501.

lilleyse avatar Apr 27 '18 13:04 lilleyse

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

emackey avatar Aug 30 '18 21:08 emackey

Related issue: https://github.com/CesiumGS/cesium/issues/10465

lilleyse avatar Jun 17 '22 12:06 lilleyse

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.

ptrgags avatar Jul 07 '22 17:07 ptrgags

This came up on the forum: https://community.cesium.com/t/lightning-or-normals-problem-with-3d-tiles/19985

j9liu avatar Aug 16 '22 15:08 j9liu

Came up again here: https://community.cesium.com/t/how-to-create-detail-texture/24165/4

lilleyse avatar May 19 '23 21:05 lilleyse

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.

javagl avatar Mar 03 '24 14:03 javagl