withGeneratedTangents method

MeshData withGeneratedTangents({
  1. VertexLayout? target,
  2. TangentMethod method = TangentMethod.mikkTSpace,
  3. bool splitSeams = true,
})

A copy with per-vertex tangents derived from the UV parametrization.

The w component is glTF's bitangent sign, which is what encodes a mirrored UV island — get it backwards and a normal-mapped surface lights from the wrong side, which is exactly what NormalTangentTest is built to show. See TangentMethod for the two ways the direction is found.

A vertex may be split. MikkTSpace can give one vertex two frames — where a mirrored UV island meets its original along a shared edge, the two sides have opposite handedness — and one vertex holds one tangent. With splitSeams such a vertex is copied, once per extra frame, onto the end of the vertex list and the triangles on the other side point at the copy, so the mesh can come back longer than it went in; the vertices it had keep their places. generateTangents says which vertex each copy was made from, for a caller holding data per vertex. Without splitSeams the vertex count is kept and such a vertex takes the frame most of its corners have; that is for callers whose rows must line up with something else, like an editor's layout plan.

Requires normals and texture coordinates. Without UVs there is no tangent frame to derive, so the neutral tangent is written instead and the caller gets geometry that at least does not produce NaN.

Implementation

MeshData withGeneratedTangents({
  VertexLayout? target,
  TangentMethod method = TangentMethod.mikkTSpace,
  bool splitSeams = true,
}) => generateTangents(
  target: target,
  method: method,
  splitSeams: splitSeams,
).mesh;