toGlb method
The model as one .glb.
Implementation
Uint8List toGlb() {
final bin = _buffer();
final out = Map<String, dynamic>.of(json)
..['buffers'] = [
{'byteLength': bin.length},
];
var jsonBytes = utf8.encode(jsonEncode(out));
final pad = (4 - jsonBytes.length % 4) % 4;
jsonBytes = Uint8List.fromList([...jsonBytes, ...List.filled(pad, 0x20)]);
final total = 12 + 8 + jsonBytes.length + 8 + bin.length;
final b = BytesBuilder()
..add(_u32s([0x46546c67, 2, total]))
..add(_u32s([jsonBytes.length, 0x4e4f534a]))
..add(jsonBytes)
..add(_u32s([bin.length, 0x004e4942]))
..add(bin);
return b.toBytes();
}