@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
36 lines (32 loc) • 1.11 kB
JavaScript
/**
*
* @param {SMikkTSpaceContext} pContext
* @param {number[]} tangent
* @param {number[]} bi_tangent
* @param {number} fMagS
* @param {number} fMagT
* @param {boolean} bi_tangent_preserves_orientation
* @param {number} iFace
* @param {number} iVert
* @returns {void}
*/
export function m_setTSpace(
pContext,
tangent,
bi_tangent,
fMagS,
fMagT,
bi_tangent_preserves_orientation,
iFace,
iVert
) {
// figure out which vertex it is
const vertex_index = pContext.geometry_buffer_index[iFace * 3 + iVert];
const tangent_destination = pContext.geometry_buffer_vertex_tangent;
const tangent_address = vertex_index * 4;
// for logic explanation, see https://github.com/gltf-rs/mikktspace/blob/6275cc4f15cff8be29819fb34ae8be3b9129dae1/src/lib.rs#L33
tangent_destination[tangent_address] = tangent[0];
tangent_destination[tangent_address + 1] = tangent[1];
tangent_destination[tangent_address + 2] = tangent[2];
tangent_destination[tangent_address + 3] = bi_tangent_preserves_orientation ? 1 : -1;
}