From c56e93a617118bd0d58771ad47ce5a579b2647a2 Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Thu, 29 Aug 2024 15:58:37 +0200 Subject: [PATCH] Added some comments. --- math/spvo.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) 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