parseSplatOctreeIndex function
The tree's nodes out of the header and table, every page still to load.
Implementation
SplatOctree parseSplatOctreeIndex(Uint8List bytes) {
final nodeCount = _readHeader(bytes);
final needed = kSplatOctreeHeaderBytes + nodeCount * kSplatOctreeNodeBytes;
if (bytes.length < needed || nodeCount == 0) {
throw SplatOctreeException(
'$nodeCount nodes need a $needed-byte index; got ${bytes.length}',
);
}
final data = ByteData.sublistView(bytes);
final nodes = <SplatOctreeNode>[
for (var k = 0; k < nodeCount; k++)
_node(data, kSplatOctreeHeaderBytes + k * kSplatOctreeNodeBytes),
];
for (final (k, node) in nodes.indexed) {
if (node.childCount > 8 ||
(node.childCount > 0 &&
(node.firstChild <= k ||
node.firstChild + node.childCount > nodeCount))) {
throw SplatOctreeException('node $k names children outside the tree');
}
}
return SplatOctree(nodes);
}