public int getVoxel(int x, int y, int z)
    {
        if (this.scale == 1)
        {
            return(this.voxelValue);
        }

        VoxTree subtree = this.subtrees[this.getSubtreeIndex(x, y, z)];

        if (subtree != null)
        {
            return(subtree.getVoxel(x, y, z));
        }

        return(this.voxelValue);
    }
Ejemplo n.º 2
0
 public void UpdateVoxels(VoxTree voxTree, bool limit = false)
 {
     voxTree.fillVoxelArray(this.voxels, this.x, this.y, this.z, limit);
 }
Ejemplo n.º 3
0
    void Awake()
    {
        numChunksCubed = numChunks * numChunks * numChunks;

        voxelsT = new VoxTree[numChunks][][];
        chunks  = new Chunk[numChunks][][];
        for (int x = 0; x < numChunks; x++)
        {
            voxelsT[x] = new VoxTree[numChunks][];
            chunks[x]  = new Chunk[numChunks][];
            for (int y = 0; y < numChunks; y++)
            {
                voxelsT[x][y] = new VoxTree[numChunks];
                chunks[x][y]  = new Chunk[numChunks];
                for (int z = 0; z < numChunks; z++)
                {
                    chunks[x][y][z] = Instantiate(chunkPrefab);
                    chunks[x][y][z].SetResolution(chunkResolution);
                    voxelsT[x][y][z] = new VoxTree(x * (chunkResolution), y * (chunkResolution), z * (chunkResolution), chunkResolution);
                    chunks[x][y][z].SetPosition(x * (chunkResolution), y * (chunkResolution), z * (chunkResolution));
                }
            }
        }

        // This should be put into a function
        for (int i = 0; i < chunkResolution * numChunks; i++)
        {
            for (int j = 0; j < chunkResolution * numChunks; j++)
            {
                for (int k = 0; k < chunkResolution * numChunks; k++)
                {
                    voxelsT[i / chunkResolution][j / chunkResolution][k / chunkResolution].setVoxel(i, j, k, WorldGen.TerrainVoxel(i, j, k));
                }
            }
        }

        for (int x = 0; x < numChunks; x++)
        {
            for (int y = 0; y < numChunks; y++)
            {
                for (int z = 0; z < numChunks; z++)
                {
                    voxelsT[x][y][z].setVoxelBox(20, 20, 20, 50, 50, 50, 1);
                }
            }
        }


        // TODO: refactor this
        for (int i = 0; i < numChunks; i++)
        {
            for (int j = 0; j < numChunks; j++)
            {
                for (int k = 0; k < numChunks; k++)
                {
                    chunks[i][j][k].UpdateVoxels(voxelsT[i][j][k]);
                    if (i > 0)
                    {
                        chunks[i - 1][j][k].UpdateVoxels(voxelsT[i][j][k], true);
                        if (j > 0)
                        {
                            chunks[i - 1][j - 1][k].UpdateVoxels(voxelsT[i][j][k], true);
                            if (k > 0)
                            {
                                chunks[i - 1][j - 1][k - 1].UpdateVoxels(voxelsT[i][j][k], true);
                            }
                        }
                    }

                    if (j > 0)
                    {
                        chunks[i][j - 1][k].UpdateVoxels(voxelsT[i][j][k], true);
                        if (k > 0)
                        {
                            chunks[i][j - 1][k - 1].UpdateVoxels(voxelsT[i][j][k], true);
                        }
                    }

                    if (k > 0)
                    {
                        chunks[i][j][k - 1].UpdateVoxels(voxelsT[i][j][k], true);
                        if (i > 0)
                        {
                            chunks[i - 1][j][k - 1].UpdateVoxels(voxelsT[i][j][k], true);
                        }
                    }
                }
            }
        }

        for (int i = 0; i < numChunks; i++)
        {
            for (int j = 0; j < numChunks; j++)
            {
                for (int k = 0; k < numChunks; k++)
                {
                    chunks[i][j][k].UpdateVoxels(voxelsT[i][j][k]);
                    chunks[i][j][k].UpdateMesh();
                }
            }
        }
    }