Exemplo n.º 1
0
        public Mesh[] Generate(Chunk c, GraphicsDevice gd)
        {
            _opaqueVertices = new List<VertexPositionNormalTexture>();
            _opaqueIndices = new List<int>();
            _transparentVertices = new List<VertexPositionNormalTexture>();
            _transparentIndices = new List<int>();

            _x = 0;
            _y = 0;
            _z = 0;

            _chunk = c;

            for (; ; _x++)
            {
                if (_x > 15)
                {
                    _z++;
                    _x = 0;
                    if (_z > 15)
                    {
                        _y++;
                        _z = 0;
                        if (_y > 255)
                        {
                            break;
                        }
                    }
                }

                _id = c.BlockType[_x, _y, _z];
                _meta = c.BlockMetadata[_x, _y, _z];

                if (!Blocks.blocks[_id].NotABlock && !Blocks.blocks[_id].IsTransparent)
                {
                    if (!Blocks.blocks[_id].HasMetadata)
                    {
                        if (Blocks.blocks[_id].IsMultitex)
                        {
                            if (IsTransparent(0))
                                CreateMultiTexBlockSide(0, 0);
                            if (IsTransparent(1))
                                CreateMultiTexBlockSide(1, 1);
                            if (IsTransparent(2))
                                CreateMultiTexBlockSide(2, 2);
                            if (IsTransparent(3))
                                CreateMultiTexBlockSide(3, 3);
                            if (IsTransparent(4))
                                CreateMultiTexBlockSide(4, 4);
                            if (IsTransparent(5))
                                CreateMultiTexBlockSide(5, 5);
                        }
                        else
                        {
                            if (IsTransparent(0))
                                CreateBlockSide(0);
                            if (IsTransparent(1))
                                CreateBlockSide(1);
                            if (IsTransparent(2))
                                CreateBlockSide(2);
                            if (IsTransparent(3))
                                CreateBlockSide(3);
                            if (IsTransparent(4))
                                CreateBlockSide(4);
                            if (IsTransparent(5))
                                CreateBlockSide(5);
                        }
                    }
                    else
                    {
                        if (Blocks.blocks[_id].IsMultitex)
                        {
                            if (IsTransparent(0))
                                CreateMultiTexBlockSide(0, (byte)(0 + _meta * 6));
                            if (IsTransparent(1))
                                CreateMultiTexBlockSide(1, (byte)(1 + _meta * 6));
                            if (IsTransparent(2))
                                CreateMultiTexBlockSide(2, (byte)(2 + _meta * 6));
                            if (IsTransparent(3))
                                CreateMultiTexBlockSide(3, (byte)(3 + _meta * 6));
                            if (IsTransparent(4))
                                CreateMultiTexBlockSide(4, (byte)(4 + _meta * 6));
                            if (IsTransparent(5))
                                CreateMultiTexBlockSide(5, (byte)(5 + _meta * 6));
                        }
                        else
                        {
                            if (IsTransparent(0))
                                CreateBlockSide(0);
                            if (IsTransparent(1))
                                CreateBlockSide(1);
                            if (IsTransparent(2))
                                CreateBlockSide(2);
                            if (IsTransparent(3))
                                CreateBlockSide(3);
                            if (IsTransparent(4))
                                CreateBlockSide(4);
                            if (IsTransparent(5))
                                CreateBlockSide(5);
                        }
                    }
                }
                else if (Blocks.blocks[_id].NotABlock)
                {
                    if (Blocks.blocks[_id].IsXSprite)
                    {
                        CreateXSprite();
                    }
                    else if (_id == 9)//quick hack for water
                    {
                        if (c.BlockType[_x, _y + 1, _z] != 9)
                            CreateWater(4);
                    }
                    else if (_id == 79) //ice
                    {
                        if (!SameBlock(0))
                            TransparentQuad(0);
                        if (!SameBlock(1))
                            TransparentQuad(1);
                        if (!SameBlock(2))
                            TransparentQuad(2);
                        if (!SameBlock(3))
                            TransparentQuad(3);
                        if (!SameBlock(4))
                            TransparentQuad(4);
                        if (!SameBlock(5))
                            TransparentQuad(5);
                    }
                }
                else if (Blocks.blocks[_id].IsTransparent)
                {
                    if (_id == 18) // leaves
                    {
                        CreateBlockSide(0);
                        CreateBlockSide(1);
                        CreateBlockSide(2);
                        CreateBlockSide(3);
                        CreateBlockSide(4);
                        CreateBlockSide(5);
                    }
                    else if (_id == 20)
                    {
                        if (!SameBlock(0))
                            CreateBlockSide(0);
                        if (!SameBlock(1))
                            CreateBlockSide(1);
                        if (!SameBlock(2))
                            CreateBlockSide(2);
                        if (!SameBlock(3))
                            CreateBlockSide(3);
                        if (!SameBlock(4))
                            CreateBlockSide(4);
                        if (!SameBlock(5))
                            CreateBlockSide(5);
                    }
                }
            }

            Mesh[] meshes = new Mesh[2];

            if (_opaqueIndices.Count > 0)
                meshes[0] = new Mesh(gd, _opaqueVertices.ToArray(), _opaqueIndices.ToArray());
            if (_transparentIndices.Count > 0)
                meshes[1] = new Mesh(gd, _transparentVertices.ToArray(), _transparentIndices.ToArray());

            _opaqueVertices = null;
            _opaqueIndices = null;
            _transparentVertices = null;
            _transparentIndices = null;

            return meshes;
        }
Exemplo n.º 2
0
        public void UpdateMesh(VertexIndexGenerator gen, GraphicsDevice gd)
        {
            Mesh[] meshes = gen.Generate(this, gd);

            if (meshes != null)
            {
                if (meshes.Length > 0)
                    _opaqueMesh = meshes[0];

                if (meshes.Length > 1)
                    _waterMesh = meshes[1];
            }
        }