This function generates tangent vectors using the MikkTSpace code by Morten S. Mikkelsen.

getTangents(obj)

Details

glTF files include normal textures, which require the tangent space to be specified: the normals at each vertex are supplemented with a tangent vector and a bitangent vector that is their cross product. The standard recommends that if the glTF file doesn't specify tangents, they should be generated using the MikkTSpace code.

Note that a comment in mikktspace.h indicates that indexing needs to be recalculated after computing the tangents, so this function works on unindexed inputs, and reapplies indexing at the end.

Arguments

obj

A triangles or quads object as returned by rgl::scene3d().

Value

A modified copy of the original object, adding a 4 column tangents entry. The order and number of indices may have changed.

References

The MikkTSpace code was obtained from https://github.com/mmikk/MikkTSpace. The interface code is based on code from https://www.turais.de/using-mikktspace-in-your-project/ by Johannes Kuehnel.

Author

Morten S. Mikkelsen, Johannes Kuehnel and Duncan Murdoch.