A 4x4 matrix used to transform normals from local space to world space.
A flat array of normals in local space (x, y, z components).
The length of the normals array, indicating the number of normals to process.
An array where the compressed normals will be stored.
The length of the compressedNormals array before processing begins.
The updated length of the compressedNormals array.
const worldMatrix = new Float32Array([ ... 4x4 matrix ... ]);
const normals = new Float32Array([0.5, -0.5, 0.7, -0.3, 0.8, 0.5]);
const compressedNormals = new Float32Array(normals.length);
const newLen = transformAndOctEncodeNormals(worldMatrix, normals, normals.length, compressedNormals, 0);
console.log(newLen, compressedNormals);
Transforms normals by applying a world normal matrix and then oct-encodes them to minimize rounding errors.
This function takes an array of normals, transforms them using a world normal matrix, and then oct-encodes them with optimizations to minimize rounding errors. The function tests different combinations of the
ceilandfloorfunctions for the oct-encoding process and picks the encoding that maximizes the cosine similarity.