Exemplo n.º 1
0
    public OctTree <TriangleBound> ConstructSceneOctree(List <TriangleInfo> sceneTriangles, Bounds bound)
    {
        int          count    = 0;
        AABBBoundBox maxBound = new AABBBoundBox(bound);

        _octree = new OctTree <TriangleBound>(maxBound);
        List <TriangleInfo> triangleList = new List <TriangleInfo>(triangleCountInOneGroup);

        foreach (TriangleInfo tri in sceneTriangles)
        {
            triangleList.Add(tri);
            if (triangleList.Count == triangleCountInOneGroup)
            {
                TriangleBound triangleBound = GroupBoundBox(triangleList);

                //boundList.Add(triangleBound);
                if (maxBound.Contains(triangleBound.GetBoundBox()) || maxBound.Overlap(triangleBound.boundBox))
                {
                    _octree.Insert(triangleBound);
                    count++;
                }
                triangleList.Clear();
            }
        }
        if (triangleList.Count != 0)
        {
            _octree.Insert(GroupBoundBox(triangleList));
            count++;
        }

        Debug.Log(count);
        _octree.UpdateTree();
        return(_octree);
    }
Exemplo n.º 2
0
 public void Voxelize()
 {
     octree = new OctTree <VoxelBound>(new AABBBoundBox(voxelBoundBox.bounds));
     InitVoxelArray();
     foreach (VoxelBound tBound in _voxelArray)
     {
         octree.Insert(tBound);
     }
     octree.UpdateTree();
     InitTriangleInfoDic();
     IntersectTest();
 }
Exemplo n.º 3
0
    public void CreateOctree()
    {
        octree = new OctTree <BoxObject>(new AABBBoundBox(-5000f * Vector3.one, 5000f * Vector3.one));
        for (int i = 0; i < collisionObjects.Count; i++)
        {
            octree.Insert(collisionObjects[i]);
        }
        octree.UpdateTree();
        int d = octree.GetMaxTreeDepth();

        Debug.Log(d + " " + Mathf.Pow(8, d) / (d - 1));
    }
Exemplo n.º 4
0
    public void UpdateTree()
    {
        if (isBuilt)
        {
            if (objects.Count == 0)
            {
                if (!hasChildren)
                {
                    if (curLifeSpan == -1)
                    {
                        curLifeSpan = maxLifeSpan;
                    }
                    else if (curLifeSpan > 0)
                    {
                        curLifeSpan--;
                    }
                }
            }
            else
            {
                if (curLifeSpan != -1)
                {
                    if (maxLifeSpan <= 64)
                    {
                        maxLifeSpan *= 2;
                    }
                    curLifeSpan = -1;
                }
            }

            List <HRigidBody> movedObjects = new List <HRigidBody> ();
            for (int i = 0; i < objects.Count; i++)
            {
                if (!objects [i].isStatic || objects [i].didMove)
                {
                    movedObjects.Add(objects [i]);
                }
            }

            for (int flags = activeChildren, index = 0; flags > 0; flags >>= 1, index++)
            {
                if ((flags & 1) == 1)
                {
                    children [index].UpdateTree();
                }
            }

            for (int i = 0; i < movedObjects.Count; i++)
            {
                OctTree current = this;
                while (!current.region.Contains(movedObjects [i].transform, movedObjects [i].radius))
                {
                    if (current.parent != null)
                    {
                        current = current.parent;
                    }
                    else
                    {
                        break;
                    }
                }
                objects.Remove(movedObjects [i]);
                current.Insert(movedObjects [i]);

                /*
                 * string result = "";
                 * foreach (HRigidBody h in tmpObjects) {
                 *      result += h.name + " ";
                 * }
                 * Debug.Log ("!" + name + " " + result);
                 */
            }
            //prune out any dead branches in the tree
            if (children != null)
            {
                for (int flags = activeChildren, index = 0; flags > 0; flags >>= 1, index++)
                {
                    if ((flags & 1) == 1 && children [index].curLifeSpan == 0)
                    {
                        children [index] = null;
                        activeChildren  ^= (byte)(1 << index);                              //remove the node from the active nodes flag list
                    }
                }
            }
        }
    }