Added some comments.

This commit is contained in:
The Wobbler 2024-08-29 15:58:37 +02:00
parent ec8ba98b56
commit c56e93a617

View file

@ -25,17 +25,26 @@ class SparseVoxelOctree:
self.origin = (0, 0, 0)
def _get_child_index(self, x, y, z, size):
"""
Get the index of a child.
Index: The position of the node in the node parent's children list.
"""
index = 0
if x >= size // 2:
index |= 1
x -= size // 2
if x >= size // 2: # x pos
# there are only 2 possible x coordinate values in a 2x2 cube, so we use the 1st bit in index for x
# xyz: the coordinates of the parent node
index |= 1 # set 1st bit to 1
x -= size // 2 # get parent x
if y >= size // 2:
# and the same for y and z
if y >= size // 2: # y pos
index |= 2
y -= size // 2
if z >= size // 2:
if z >= size // 2: # z pos
index |= 4
z -= size // 2