Esempio n. 1
0
    public override void Split()
    {
        if (!hasChildren)
        {
            children = new SurforgeOctreeNode[8];
            for (int i = 0; i < 8; i++)
            {
                SurforgeOctreeNode child = (SurforgeOctreeNode)ScriptableObject.CreateInstance(typeof(SurforgeOctreeNode));
                children[i] = child;
                child.level = 1;

                // Compute new bounding box for this child
                children[i].center   = center + boundsOffsetTable[i] * halfSize * 0.5f;
                children[i].halfSize = (int)(halfSize * 0.5f);
            }
            hasChildren = true;
        }
    }
Esempio n. 2
0
    public void SearchForNeighbors(List <SurforgeOctreeNode> nodes, SurforgeOctree octree)
    {
        List <Vector3> neighbourPositions = new List <Vector3>();

        Vector3 nX = new Vector3(center.x + halfSize, center.y, center.z);

        neighbourPositions.Add(nX);
        Vector3 nZ = new Vector3(center.x, center.y, center.z + halfSize);

        neighbourPositions.Add(nZ);
        Vector3 nXm = new Vector3(center.x - halfSize, center.y, center.z);

        neighbourPositions.Add(nXm);
        Vector3 nZm = new Vector3(center.x, center.y, center.z - halfSize);

        neighbourPositions.Add(nZm);
        Vector3 nXZ = new Vector3(center.x + halfSize, center.y, center.z + halfSize);

        neighbourPositions.Add(nXZ);
        Vector3 nXZm = new Vector3(center.x + halfSize, center.y, center.z - halfSize);

        neighbourPositions.Add(nXZm);
        Vector3 nXmZ = new Vector3(center.x - halfSize, center.y, center.z + halfSize);

        neighbourPositions.Add(nXmZ);
        Vector3 nXmZm = new Vector3(center.x - halfSize, center.y, center.z - halfSize);

        neighbourPositions.Add(nXmZm);

        Vector3 nXY = new Vector3(center.x + halfSize, center.y + halfSize, center.z);

        neighbourPositions.Add(nXY);
        Vector3 nZY = new Vector3(center.x, center.y + halfSize, center.z + halfSize);

        neighbourPositions.Add(nZY);
        Vector3 nXmY = new Vector3(center.x - halfSize, center.y + halfSize, center.z);

        neighbourPositions.Add(nXmY);
        Vector3 nZmY = new Vector3(center.x, center.y + halfSize, center.z - halfSize);

        neighbourPositions.Add(nZmY);
        Vector3 nXZY = new Vector3(center.x + halfSize, center.y + halfSize, center.z + halfSize);

        neighbourPositions.Add(nXZY);
        Vector3 nXZmY = new Vector3(center.x + halfSize, center.y + halfSize, center.z - halfSize);

        neighbourPositions.Add(nXZmY);
        Vector3 nXmZY = new Vector3(center.x - halfSize, center.y + halfSize, center.z + halfSize);

        neighbourPositions.Add(nXmZY);
        Vector3 nXmZmY = new Vector3(center.x - halfSize, center.y + halfSize, center.z - halfSize);

        neighbourPositions.Add(nXmZmY);
        Vector3 nY = new Vector3(center.x, center.y + halfSize, center.z);

        neighbourPositions.Add(nY);

        Vector3 nXYm = new Vector3(center.x + halfSize, center.y - halfSize, center.z);

        neighbourPositions.Add(nXYm);
        Vector3 nZYm = new Vector3(center.x, center.y - halfSize, center.z + halfSize);

        neighbourPositions.Add(nZYm);
        Vector3 nXmYm = new Vector3(center.x - halfSize, center.y - halfSize, center.z);

        neighbourPositions.Add(nXmYm);
        Vector3 nZmYm = new Vector3(center.x, center.y - halfSize, center.z - halfSize);

        neighbourPositions.Add(nZmYm);
        Vector3 nXZYm = new Vector3(center.x + halfSize, center.y - halfSize, center.z + halfSize);

        neighbourPositions.Add(nXZYm);
        Vector3 nXZmYm = new Vector3(center.x + halfSize, center.y - halfSize, center.z - halfSize);

        neighbourPositions.Add(nXZmYm);
        Vector3 nXmZYm = new Vector3(center.x - halfSize, center.y - halfSize, center.z + halfSize);

        neighbourPositions.Add(nXmZYm);
        Vector3 nXmZmYm = new Vector3(center.x - halfSize, center.y - halfSize, center.z - halfSize);

        neighbourPositions.Add(nXmZmYm);
        Vector3 nYm = new Vector3(center.x, center.y - halfSize, center.z);

        neighbourPositions.Add(nYm);

        foreach (Vector3 neighbourPos in neighbourPositions)
        {
            SurforgeOctreeNode n = octree.GetNodeByPointFromRoot(neighbourPos, level);
            if (n != null)
            {
                nodes.Add(n);
            }
        }
    }