Oct-encodes a 3D vector (x, y, z) into a 2-byte representation.
This function normalizes a 3D vector to the 2D oct encoding range and encodes it using the specified math functions (xfunc and yfunc), which typically are 'floor' or 'ceil'.
xfunc
yfunc
A 3D vector, typically representing a normal (x, y, z).
The math function to apply to the x component ('floor', 'ceil', etc.).
The math function to apply to the y component ('floor', 'ceil', etc.).
The oct-encoded 2D vector as a 2-element Int8Array.
If xfunc or yfunc are not valid function names.
const vec3 = new Float32Array([0.5, -0.5, 0.5]);const encoded = octEncodeVec3(vec3, 'floor', 'ceil');console.log(encoded); // Int8Array with encoded vector values Copy
const vec3 = new Float32Array([0.5, -0.5, 0.5]);const encoded = octEncodeVec3(vec3, 'floor', 'ceil');console.log(encoded); // Int8Array with encoded vector values
Oct-encodes a 3D vector (x, y, z) into a 2-byte representation.
This function normalizes a 3D vector to the 2D oct encoding range and encodes it using the specified math functions (
xfuncandyfunc), which typically are 'floor' or 'ceil'.