Geometry · function
generateTangents
Derive a tangent frame from positions, normals and texture coordinates.
Explained in Hello world, Meshes and geometry.
function generateTangents(positions: Float32Array, normals: Float32Array, uvs: Float32Array, indices: Uint16Array | Uint32Array, out?: Float32Array): Float32Arrayimport { generateTangents } from '@driftengine/core';Parameters
| Parameter | Type | Description |
|---|---|---|
positions | Float32Array | |
normals | Float32Array | |
uvs | Float32Array | |
indices | Uint16Array | Uint32Array | |
out? | Float32Array |
In depth
Accumulated per triangle, then orthogonalised per vertex. A vertex shared by two triangles gets the sum of their tangents, which is what makes a smooth surface's frame smooth; the sum is then no longer square to the interpolated normal, and Gram-Schmidt is what puts it back. Dropping that step is a normal map that shears wherever the geometry curves.
Never returns a NaN. A triangle whose three vertices share one texture coordinate has no direction along the texture at all and the arithmetic divides by zero — which is the common case in a bought asset rather than an edge case, and a NaN in a vertex buffer takes the whole triangle off the screen. Those vertices get some unit vector perpendicular to their normal, which is arbitrary and finite, and arbitrary is the honest answer to an unanswerable question.