Beispiel #1
0
        public void GenerateBlocks()
        {
            for (int x = 0; x < _chunkSize; ++x)
            {
                for (int y = 0; y < _chunkSize; ++y)
                {
                    for (int z = 0; z < _chunkSize; ++z)
                    {
                        Atlas.ID block = GenerateBlock(_column, _pos.x * _chunkSize + x, _pos.y * _chunkSize + y, _pos.z * _chunkSize + z);

                        // Skip air
                        if (block == Atlas.ID.Air)
                        {
                            continue;
                        }
                        _blocks[x, y, z] = block;

                        ++_density;
                    }
                }
            }

            if (_density == 0)
            {
                _blocks = null;
            }

            _generated = true;
        }
    public void GenerateBlocks()
    {
        for (int x = 0; x < World.GetChunkSize(); ++x)
        {
            for (int y = 0; y < World.GetChunkSize(); ++y)
            {
                for (int z = 0; z < World.GetChunkSize(); ++z)
                {
                    Atlas.ID block = World.GenerateBlock(_column, _pos.x * World.GetChunkSize() + x, _pos.y * World.GetChunkSize() + y, _pos.z * World.GetChunkSize() + z);

                    // Skip air
                    if (block == Atlas.ID.Air)
                    {
                        continue;
                    }
                    _blocks[x, y, z] = block;

                    ++_density;
                }
            }
        }

        if (_density == 0)
        {
            _blocks = null;
        }

        _generated = true;
        _chunk.UpdateState();
    }
Beispiel #3
0
    private void CubeWest(int x, int y, int z, Atlas.ID block)
    {
        _newVerts.Add(new Vector3(x, y - 1, z + 1));
        _newVerts.Add(new Vector3(x, y, z + 1));
        _newVerts.Add(new Vector3(x, y, z));
        _newVerts.Add(new Vector3(x, y - 1, z));

        Atlas.Dir dir   = Atlas.Dir.West;
        Color     color = Color.white;

        /*if (false && block == Atlas.ID.Grass && Block(x - 1, y - 1, z) == Atlas.ID.Grass)
         * {
         *      dir = Atlas.Dir.Up;
         *      color = Atlas.Colors["Normal_1"] * 2f; // Multiplier that most Unity shaders seem to use to brighten
         * }*/

        _newColors.Add(color);
        _newColors.Add(color);
        _newColors.Add(color);
        _newColors.Add(color);

        Vector2 texturePos = Atlas.GetTexture(block, dir);

        Cube(texturePos);
    }
Beispiel #4
0
    private void CubeSouth(int x, int y, int z, Atlas.ID block)
    {
        _newVerts.Add(new Vector3(x, y - 1, z));
        _newVerts.Add(new Vector3(x, y, z));
        _newVerts.Add(new Vector3(x + 1, y, z));
        _newVerts.Add(new Vector3(x + 1, y - 1, z));

        Atlas.Dir dir   = Atlas.Dir.South;
        Color     color = Color.white;

        if (block == Atlas.ID.Grass && Block(x, y - 1, z - 1) == Atlas.ID.Grass)
        {
            dir   = Atlas.Dir.Up;
            color = Atlas.Colors["Normal_1"] * 2f;             // Multiplier that most Unity shaders seem to use to brighten
        }

        _newColors.Add(color);
        _newColors.Add(color);
        _newColors.Add(color);
        _newColors.Add(color);

        Vector2 texturePos = Atlas.GetTexture(block, dir);

        Cube(texturePos);
    }
Beispiel #5
0
    /// <summary>
    /// Tell DataChunk to generate its blocks.
    /// </summary>
    public void GenerateBlocks()
    {
        for (int x = 0; x < World.chunkSize; ++x)
        {
            for (int y = 0; y < World.chunkSize; ++y)
            {
                for (int z = 0; z < World.chunkSize; ++z)
                {
                    Atlas.ID block = World.GenerateBlock(new BlockPos(x, y, z, _pos));

                    // Skip air
                    if (block == Atlas.ID.Air)
                    {
                        continue;
                    }
                    _blocks[x, y, z] = block;

                    ++_density;
                }
            }
        }

        if (_density == 0)
        {
            _blocks = null;
        }

        _generated = true;
        _chunk.UpdateState();
    }
Beispiel #6
0
    /// <summary>
    /// Tell chunk to generate its mesh.
    /// </summary>
    public void GenerateMesh()
    {
        // Iterate through x, y, z
        for (int x = 0; x < _chunkSize; x++)
        {
            for (int y = 0; y < _chunkSize; y++)
            {
                for (int z = 0; z < _chunkSize; z++)
                {
                    BlockPos pos = new BlockPos(x, y, z, _chunkPos);

                    Atlas.ID block = Block(pos);

                    // Generate the mesh and texturize
                    if (block != Atlas.ID.Air)
                    {
                        if (Block(pos + BlockPos.up) == Atlas.ID.Air)
                        {
                            CubeUp(x, y, z, block);
                        }

                        if (Block(pos + BlockPos.down) == Atlas.ID.Air)
                        {
                            CubeDown(x, y, z, block);
                        }

                        if (Block(pos + BlockPos.east) == Atlas.ID.Air)
                        {
                            CubeEast(x, y, z, block);
                        }

                        if (Block(pos + BlockPos.west) == Atlas.ID.Air)
                        {
                            CubeWest(x, y, z, block);
                        }

                        if (Block(pos + BlockPos.north) == Atlas.ID.Air)
                        {
                            CubeNorth(x, y, z, block);
                        }

                        if (Block(pos + BlockPos.south) == Atlas.ID.Air)
                        {
                            CubeSouth(x, y, z, block);
                        }
                    }
                }
            }
        }

        _clearMesh  = true;
        _updateMesh = true;
    }
Beispiel #7
0
    public void GenerateMesh()
    {
        if (_render)
        {
            // Iterate through x, y, z
            for (int x = 0; x < _chunkSize; x++)
            {
                for (int y = 0; y < _chunkSize; y++)
                {
                    for (int z = 0; z < _chunkSize; z++)
                    {
                        Atlas.ID block = Block(x, y, z);

                        // Generate the mesh and texturize
                        if (block != Atlas.ID.Air)
                        {
                            if (Block(x, y + 1, z) == Atlas.ID.Air)
                            {
                                CubeUp(x, y, z, block);
                            }

                            if (Block(x, y - 1, z) == Atlas.ID.Air)
                            {
                                CubeDown(x, y, z, block);
                            }

                            if (Block(x + 1, y, z) == Atlas.ID.Air)
                            {
                                CubeEast(x, y, z, block);
                            }

                            if (Block(x - 1, y, z) == Atlas.ID.Air)
                            {
                                CubeWest(x, y, z, block);
                            }

                            if (Block(x, y, z + 1) == Atlas.ID.Air)
                            {
                                CubeNorth(x, y, z, block);
                            }

                            if (Block(x, y, z - 1) == Atlas.ID.Air)
                            {
                                CubeSouth(x, y, z, block);
                            }
                        }
                    }
                }
            }

            _updateMesh = true;
        }
    }
Beispiel #8
0
        public void SetBlock(Atlas.ID block, int x, int y, int z)
        {
            // Do not give us air!
            if (block == Atlas.ID.Air)
            {
                return;
            }

            // Unnullify
            if (_blocks == null)
            {
                _blocks = new Atlas.ID[_chunkSize, _chunkSize, _chunkSize];
            }

            _blocks[x, y, z] = block;

            ++_density;
        }
Beispiel #9
0
    private void CubeDown(int x, int y, int z, Atlas.ID block)
    {
        _newVerts.Add(new Vector3(x, y - 1, z));
        _newVerts.Add(new Vector3(x + 1, y - 1, z));
        _newVerts.Add(new Vector3(x + 1, y - 1, z + 1));
        _newVerts.Add(new Vector3(x, y - 1, z + 1));

        Atlas.Dir dir   = Atlas.Dir.Down;
        Color     color = Color.white;

        _newColors.Add(color);
        _newColors.Add(color);
        _newColors.Add(color);
        _newColors.Add(color);

        Vector2 texturePos = Atlas.GetTexture(block, dir);

        Cube(texturePos);
    }
Beispiel #10
0
    /// <summary>
    /// Set block at given position.
    /// </summary>
    /// <param name="block">Block ID.</param>
    /// <param name="pos">Block position.</param>
    /// <remarks>To set <c>Atlas.ID.Air</c>, you need to use <see cref="DataChunk.RemoveBlock(BlockPos)"/></remarks>
    public void SetBlock(Atlas.ID block, BlockPos pos)
    {
        // Do not give us air!
        if (block == Atlas.ID.Air)
        {
            return;
        }
        // Something is amiss, it should be our chunk pos
        if (pos.chunkPos != _pos)
        {
            return;
        }

        // Unnullify
        if (_blocks == null)
        {
            _blocks = new Atlas.ID[World.chunkSize, World.chunkSize, World.chunkSize];
        }

        _blocks[pos.x, pos.y, pos.z] = block;

        ++_density;
    }
Beispiel #11
0
    // This generates only border mesh stuff
    public void GenerateMesh(Atlas.Dir dir)
    {
        // Start, end
        int xS = 0; int xE = _chunkSize;
        int yS = 0; int yE = _chunkSize;
        int zS = 0; int zE = _chunkSize;

        switch (dir)
        {
        case Atlas.Dir.Up:
            yS = _chunkSize; ++yE;
            break;

        case Atlas.Dir.Down:
            yE = 1;
            break;

        case Atlas.Dir.East:
            xS = _chunkSize; ++xE;
            break;

        case Atlas.Dir.West:
            xE = 1;
            break;

        case Atlas.Dir.North:
            zS = _chunkSize; ++zE;
            break;

        case Atlas.Dir.South:
            zE = 1;
            break;
        }

        // Iterate through x, y, z
        for (int x = xS; x < xE; x++)
        {
            for (int y = yS; y < yE; y++)
            {
                for (int z = zS; z < zE; z++)
                {
                    BlockPos pos = new BlockPos(x, y, z);

                    Atlas.ID block = Block(pos);

                    // Generate the mesh and texturize
                    if (block != Atlas.ID.Air)
                    {
                        // Out of bounds are done in a separate method
                        if (dir == Atlas.Dir.Up && Block(pos + BlockPos.up) == Atlas.ID.Air)
                        {
                            CubeUp(x, y, z, block);
                        }

                        if (dir == Atlas.Dir.Down && Block(pos + BlockPos.down) == Atlas.ID.Air)
                        {
                            CubeDown(x, y, z, block);
                        }

                        if (dir == Atlas.Dir.East && Block(pos + BlockPos.east) == Atlas.ID.Air)
                        {
                            CubeEast(x, y, z, block);
                        }

                        if (dir == Atlas.Dir.West && Block(pos + BlockPos.west) == Atlas.ID.Air)
                        {
                            CubeWest(x, y, z, block);
                        }

                        if (dir == Atlas.Dir.North && Block(pos + BlockPos.north) == Atlas.ID.Air)
                        {
                            CubeNorth(x, y, z, block);
                        }

                        if (dir == Atlas.Dir.South && Block(pos + BlockPos.south) == Atlas.ID.Air)
                        {
                            CubeSouth(x, y, z, block);
                        }
                    }
                }
            }
        }

        _updateMesh = true;
    }