diff --git a/math/spvo.py b/math/spvo.py index 5316975..f5afa66 100644 --- a/math/spvo.py +++ b/math/spvo.py @@ -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