示例#1
0
        public IEnumerator Test2Addition()
        {
            List <GameObject> objects = SetupScene(0);
            BVH <GameObject>  bvh     = CreateBVH(objects);

            float t    = 0;
            int   last = 0;

            while (t < TIME_PER_TEST)
            {
                t += Time.deltaTime;
                if (t * 5 > last)
                {
                    last++;
                    GameObject obj = CreateGameObject();
                    objects.Add(obj);
                    bvh.Add(obj);
                }

                bvh.RenderDebug();

                yield return(null);
            }

            DestroyScene(objects);
        }
示例#2
0
        public IEnumerator Test5AdditionAndUpdate()
        {
            List <GameObject> objects = SetupScene(0);
            BVH <GameObject>  bvh     = CreateBVH(objects);

            float t    = 0;
            int   last = 0;

            while (t < TIME_PER_TEST)
            {
                t += Time.deltaTime;
                if (t * 5 > last)
                {
                    last++;
                    GameObject obj = CreateGameObject();
                    objects.Add(obj);
                    bvh.Add(obj);
                }

                foreach (GameObject obj in objects)
                {
                    obj.transform.Translate(obj.transform.forward * Time.deltaTime * 5);
                    bvh.MarkForUpdate(obj);
                }

                bvh.Optimize();
                bvh.RenderDebug();

                yield return(null);
            }

            DestroyScene(objects);
        }
示例#3
0
        public IEnumerator Test8AddDestroyAndUpdate()
        {
            List <GameObject> objects = SetupScene();
            BVH <GameObject>  bvh     = CreateBVH(objects);

            float t    = 0;
            int   last = 0;

            while (t < TIME_PER_TEST)
            {
                t += Time.deltaTime;
                if (t * 5 > last)
                {
                    last++;

                    if (Random.Range(0, 2) == 1)
                    {
                        GameObject obj = CreateGameObject();
                        objects.Add(obj);
                        bvh.Add(obj);
                    }
                    else if (objects.Count > 0)
                    {
                        GameObject obj = objects[objects.Count - 1];
                        bvh.Remove(obj);
                        objects.RemoveAt(objects.Count - 1);
                        Object.Destroy(obj);
                    }
                }

                foreach (GameObject obj in objects)
                {
                    obj.transform.Translate(obj.transform.forward * Time.deltaTime * 5);
                    bvh.MarkForUpdate(obj);
                }

                bvh.Optimize();
                bvh.RenderDebug();

                yield return(null);
            }

            DestroyScene(objects);
        }
示例#4
0
        public IEnumerator Test9RadialRetrival()
        {
            List <GameObject> objects = SetupScene(0);
            BVH <GameObject>  bvh     = CreateBVH(objects);

            GameObject insideObj1 = GameObject.CreatePrimitive(PrimitiveType.Cube);

            insideObj1.name = "In Radius 3";
            insideObj1.transform.localScale = Vector3.one * 0.01f;
            insideObj1.transform.position   = new Vector3(0, 5, 0);

            GameObject insideObj2 = GameObject.CreatePrimitive(PrimitiveType.Cube);

            insideObj2.name = "In Radius 1";
            insideObj2.transform.localScale = Vector3.one * 5;
            insideObj2.transform.position   = new Vector3(0, -4.5f, 0);

            GameObject insideObj3 = GameObject.CreatePrimitive(PrimitiveType.Cube);

            insideObj3.name = "In Radius 2";
            insideObj3.transform.localScale = Vector3.one * 5;
            insideObj3.transform.position   = new Vector3(-5, 0, 0);

            GameObject outsideObj1 = GameObject.CreatePrimitive(PrimitiveType.Cube);

            outsideObj1.name = "Outside Radius 1";
            outsideObj1.transform.localScale = Vector3.one * 5;
            outsideObj1.transform.position   = new Vector3(0, -40, 0);

            GameObject outsideObj2 = GameObject.CreatePrimitive(PrimitiveType.Cube);

            outsideObj2.name = "Outside Radius 2";
            outsideObj2.transform.localScale = Vector3.one * 5;
            outsideObj2.transform.position   = new Vector3(-5.1f, 0, 0);


            objects.Add(insideObj1);
            bvh.Add(insideObj1);

            objects.Add(insideObj2);
            bvh.Add(insideObj2);

            objects.Add(insideObj3);
            bvh.Add(insideObj3);

            objects.Add(outsideObj1);
            bvh.Add(outsideObj1);

            objects.Add(outsideObj2);
            bvh.Add(outsideObj2);

            float t = 0;

            while (t < TIME_PER_TEST)
            {
                t += Time.deltaTime;

                bvh.RenderDebug();

                Vector3 center = new Vector3(0, 5, 0);
                float   radius = 10f;
                List <BVHNode <GameObject> > hit = bvh.Traverse(BVHHelper.RadialNodeTraversalTest(center, radius));

                Debug.DrawLine(center, center + new Vector3(radius, 0, 0), Color.red);
                Debug.DrawLine(center, center + new Vector3(0, radius, 0), Color.green);
                Debug.DrawLine(center, center + new Vector3(0, 0, radius), Color.blue);

                Debug.Log("Traversed " + hit.Count + " nodes");

                int objectCount = 0;
                foreach (var g in hit)
                {
                    if (g.GObjects != null)
                    {
                        foreach (GameObject obj in g.GObjects)
                        {
                            Debug.Log("Found Object: " + obj.name);
                            Assert.AreNotSame(obj.name, "Outside Radius");
                            objectCount++;
                        }
                    }
                }

                Debug.Log("Found " + objectCount + " leaf nodes");

                yield return(null);
            }

            DestroyScene(objects);
        }