writeInstance static method
Writes m and its normal matrix (the inverse transpose of its upper
3×3) into out at o: one instance's kBatchInstanceFloats floats.
Implementation
static void writeInstance(Float32List out, int o, Matrix4 m) {
final s = m.storage;
for (var k = 0; k < 16; k++) {
out[o + k] = s[k];
}
final a = s[0], b = s[1], c = s[2];
final d = s[4], e = s[5], f = s[6];
final g = s[8], h = s[9], k = s[10];
final c00 = e * k - f * h, c01 = -(d * k - f * g), c02 = d * h - e * g;
final c10 = -(b * k - c * h), c11 = a * k - c * g, c12 = -(a * h - b * g);
final c20 = b * f - c * e, c21 = -(a * f - c * d), c22 = a * e - b * d;
final det = a * c00 + b * c01 + c * c02;
final inv = det.abs() < 1e-20 ? 0.0 : 1.0 / det;
out[o + 16] = c00 * inv;
out[o + 17] = c01 * inv;
out[o + 18] = c02 * inv;
out[o + 19] = 0;
out[o + 20] = c10 * inv;
out[o + 21] = c11 * inv;
out[o + 22] = c12 * inv;
out[o + 23] = 0;
out[o + 24] = c20 * inv;
out[o + 25] = c21 * inv;
out[o + 26] = c22 * inv;
out[o + 27] = 0;
}