Learn R Programming

rgl2gltf (version 1.0.7)

getTangents: Use the MikkTSpace code to generate tangent vectors.

Description

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

Usage

getTangents(obj)

Value

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

Arguments

obj

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

Author

Morten S. Mikkelsen, Johannes Kuehnel and Duncan Murdoch.

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.

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.