0 Replies
      Latest reply on Dec 24, 2019 1:51 AM by Vaelian
      Vaelian Level 1 Level 1 (0 points)

        G

        I reported what I thought was a bug in GKOctree to Apple and they closed my report stating that it was investigated and found to be working as documented, which leads me to believe that there is something wrong with my code.  The problem is that I'm inserting some points in the tree and when I query for the exact location of those points it returns lots of points that were not originally inserted at those locations.

         

        Here is the test code that I wrote and ran on iOS 12.4 and 13.3 with similar results:

         

        @import GameplayKit;

        @import SceneKit;

         

        int main(int argc, char * argv[]) {

            GKBox box;

            box.boxMin = simd_make_float3(-30.0, -30.0, -30.0);

            box.boxMax = simd_make_float3(30.0, 30.0, 30.0);

            GKOctree<NSValue *> *tree = [GKOctree octreeWithBoundingBox:box minimumCellSize:1.0];

            for (float x = -1.0; x <= 1.0; x += 1.0) {

                for (float y = -1.0; y <= 1.0; y += 1.0) {

                    for (float z = -1.0; z <= 1.0; z += 1.0) {

                        simd_float3 point = simd_make_float3(x, y, z);

                        NSValue *value = [NSValue valueWithSCNVector3:SCNVector3FromFloat3(point)];

                        [tree addElement:value withPoint:point];

                    }

                }

            }

            for (float x = -1.0; x <= 1.0; x += 1.0) {

                for (float y = -1.0; y <= 1.0; y += 1.0) {

                    for (float z = -1.0; z <= 1.0; z += 1.0) {

                        printf("Querying for point: %.0f, %.0f, %.0f...\n", x, y, z);

                        simd_float3 point = simd_make_float3(x, y, z);

                        NSArray<NSValue *> *values = [tree elementsAtPoint:point];

                        for (NSValue *value in values) {

                            SCNVector3 vector = value.SCNVector3Value;

                            printf("Found: %.0f, %.0f, %.0f\n", vector.x, vector.y, vector.z);

                        }

                    }

                }

            }

            return 0;

        }

         

        The idea is that for each queried point there should be only one result, but when I run this code it returns lots of results for each query and I can't figure out why.  Can anyone help?