Exemplo n.º 1
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);
    }
Exemplo n.º 2
0
Arquivo: Chunk.cs Projeto: bmjoy/osuve
    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);
    }
Exemplo n.º 3
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);
    }
Exemplo n.º 4
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;
    }