Example #1
0
    protected bool[] GetVisibility(int i, int j, int k)
    {
        bool[] visibility = new bool[6];

        BlockType type = _blocks[i, j, k].type;

        // Up, Down, Front, Back, Left, Right
        Vector3Int[] neighbors =
        {
            new Vector3Int(i,     j + 1, k),
            new Vector3Int(i,     j - 1, k),
            new Vector3Int(i + 1, j,     k),
            new Vector3Int(i - 1, j,     k),
            new Vector3Int(i,     j,     k + 1),
            new Vector3Int(i,     j,     k - 1)
        };

        for (int ni = 0; ni < neighbors.Length; ni++)
        {
            Vector3Int npos = neighbors[ni];
            BlockType  ntype;
            if (LocalPositionIsInRange(npos))
            {
                Block block = _blocks[npos.x, npos.y, npos.z];
                ntype = block == null ? null : block.type;
            }
            else
            {
                Vector3Int worldPos      = LocalToWorldPosition(npos);
                WorldChunk chunkNeighbor = chunkManager.GetNearestChunk(worldPos);
                if (chunkNeighbor != null)
                {
                    ntype = chunkNeighbor.ReadBlockType(worldPos);
                }
                else
                {
                    ntype = GetBlockType(worldPos, _seed);
                }
            }
            visibility[ni] = (ntype == null || ntype.isTransparent) && (type != ntype);
        }

        return(visibility);
    }