public void BuildPlantVertices(Vector3i blockPosition, Vector3i chunkRelativePosition, BlockType blockType, float sunLight, Color localLight)
        {
            BlockTexture texture = BlockInformation.GetTexture(blockType);

            Vector2[] UVList;

            UVList = TextureHelper.UVMappings[(int)texture * 6 + (int)BlockFaceDirection.XIncreasing];
            AddVertex(blockPosition, chunkRelativePosition, new Vector3(0.5f, 1, 1), new Vector3(1, 0, 0), UVList[0], sunLight, localLight);
            AddVertex(blockPosition, chunkRelativePosition, new Vector3(0.5f, 1, 0), new Vector3(1, 0, 0), UVList[1], sunLight, localLight);
            AddVertex(blockPosition, chunkRelativePosition, new Vector3(0.5f, 0, 1), new Vector3(1, 0, 0), UVList[2], sunLight, localLight);
            AddVertex(blockPosition, chunkRelativePosition, new Vector3(0.5f, 0, 0), new Vector3(1, 0, 0), UVList[5], sunLight, localLight);
            AddIndex(0, 1, 2, 2, 1, 3);

            UVList = TextureHelper.UVMappings[(int)texture * 6 + (int)BlockFaceDirection.XDecreasing];
            AddVertex(blockPosition, chunkRelativePosition, new Vector3(0.5f, 1, 0), new Vector3(-1, 0, 0), UVList[0], sunLight, localLight);
            AddVertex(blockPosition, chunkRelativePosition, new Vector3(0.5f, 1, 1), new Vector3(-1, 0, 0), UVList[1], sunLight, localLight);
            AddVertex(blockPosition, chunkRelativePosition, new Vector3(0.5f, 0, 0), new Vector3(-1, 0, 0), UVList[5], sunLight, localLight);
            AddVertex(blockPosition, chunkRelativePosition, new Vector3(0.5f, 0, 1), new Vector3(-1, 0, 0), UVList[2], sunLight, localLight);
            AddIndex(0, 1, 3, 0, 3, 2);

            UVList = TextureHelper.UVMappings[(int)texture * 6 + (int)BlockFaceDirection.ZIncreasing];
            AddVertex(blockPosition, chunkRelativePosition, new Vector3(0, 1, 0.5f), new Vector3(0, 0, 1), UVList[0], sunLight, localLight);
            AddVertex(blockPosition, chunkRelativePosition, new Vector3(1, 1, 0.5f), new Vector3(0, 0, 1), UVList[1], sunLight, localLight);
            AddVertex(blockPosition, chunkRelativePosition, new Vector3(0, 0, 0.5f), new Vector3(0, 0, 1), UVList[5], sunLight, localLight);
            AddVertex(blockPosition, chunkRelativePosition, new Vector3(1, 0, 0.5f), new Vector3(0, 0, 1), UVList[2], sunLight, localLight);
            AddIndex(0, 1, 3, 0, 3, 2);

            UVList = TextureHelper.UVMappings[(int)texture * 6 + (int)BlockFaceDirection.ZDecreasing];
            AddVertex(blockPosition, chunkRelativePosition, new Vector3(1, 1, 0.5f), new Vector3(0, 0, -1), UVList[0], sunLight, localLight);
            AddVertex(blockPosition, chunkRelativePosition, new Vector3(0, 1, 0.5f), new Vector3(0, 0, -1), UVList[1], sunLight, localLight);
            AddVertex(blockPosition, chunkRelativePosition, new Vector3(1, 0, 0.5f), new Vector3(0, 0, -1), UVList[2], sunLight, localLight);
            AddVertex(blockPosition, chunkRelativePosition, new Vector3(0, 0, 0.5f), new Vector3(0, 0, -1), UVList[5], sunLight, localLight);
            AddIndex(0, 1, 2, 2, 1, 3);
        }
Esempio n. 2
0
 public BasicBlock(BlockType t, Vector2s i, BlockTexture texture, bool solid = true)
 {
     type         = t;
     icon         = i;
     blockTexture = texture;
     isSolid      = solid;
 }
        public TextureMask AddData(string texture, BlockTexture side)
        {
            if (side.HasFlag(BlockTexture.Xneg))
            {
                Textures[Block.GetSideInt(BlockSide.Xneg)] = texture;
            }
            if (side.HasFlag(BlockTexture.Xpos))
            {
                Textures[Block.GetSideInt(BlockSide.Xpos)] = texture;
            }

            if (side.HasFlag(BlockTexture.Yneg))
            {
                Textures[Block.GetSideInt(BlockSide.Yneg)] = texture;
            }
            if (side.HasFlag(BlockTexture.Ypos))
            {
                Textures[Block.GetSideInt(BlockSide.Ypos)] = texture;
            }

            if (side.HasFlag(BlockTexture.Zneg))
            {
                Textures[Block.GetSideInt(BlockSide.Zneg)] = texture;
            }
            if (side.HasFlag(BlockTexture.Zpos))
            {
                Textures[Block.GetSideInt(BlockSide.Zpos)] = texture;
            }

            return this;
        }
Esempio n. 4
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);


            debugTex = new Texture2D(GraphicsDevice, 1, 1);
            Color[] white = { new Color(1f, 1f, 1f) };
            debugTex.SetData(white);

            BgTile.addTexture(Content.Load <Texture2D>("dirtText"));
            BgTile.addTexture(Content.Load <Texture2D>("grassText"));
            BgTile.addTexture(Content.Load <Texture2D>("floorText"));
            BgTile.addTexture(Content.Load <Texture2D>("waterText"));
            BgTile.addTexture(Content.Load <Texture2D>("rockText"));

            BlockTexture.addTexture(Content.Load <Texture2D>("woodBlockText"));
            BlockTexture.addTexture(Content.Load <Texture2D>("treeBlockText"));



            Lizard.initLizard(Content.Load <Texture2D>("liz"), Content.Load <Texture2D>("dest"));



            this.player = new Player(new Camera(GraphicsDevice.Viewport),
                                     Content.Load <Texture2D>("cursor"),
                                     Content.Load <Texture2D>("indicator"),
                                     new Vector2(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height));
            Lizard.player = player;

            this.world = new World(player);

            player.Init(this.world);
        }
Esempio n. 5
0
        private void HideQuad(ushort x, ushort y, ushort z, BlockFaceDirection faceDir, BlockType blockType)
        {
            BlockTexture blockTexture = blockTextureMap[(byte)blockType, (byte)faceDir];
            uint         blockFace    = EncodeBlockFace(x, y, z, faceDir);
            uint         region       = GetRegion(x, y, z);

            if (faceMap[(byte)blockTexture, region].ContainsKey(blockFace))
            {
                faceMap[(byte)blockTexture, region].Remove(blockFace);
            }
            vertexListDirty[(byte)blockTexture, region] = true;
        }
Esempio n. 6
0
        public void Render(GraphicsDevice graphicsDevice, GameTime gameTime)
        {
            RegenerateDirtyVertexLists();

            graphicsDevice.BlendState        = BlendState.Opaque;
            graphicsDevice.DepthStencilState = DepthStencilState.Default;

            for (BlockTexture blockTexture = BlockTexture.None + 1; blockTexture < BlockTexture.MAXIMUM; blockTexture++)
            {
                for (uint r = 0; r < NUMREGIONS; r++)
                {
                    // Figure out if we should be rendering translucently.
                    bool renderTranslucent = false;
                    if (blockTexture == BlockTexture.TransRed || blockTexture == BlockTexture.TransBlue)
                    {
                        renderTranslucent = true;
                    }

                    // If this is empty, don't render it.
                    DynamicVertexBuffer regionBuffer = vertexBuffers[(byte)blockTexture, r];
                    if (regionBuffer == null)
                    {
                        continue;
                    }

                    // If this isn't in our view frustum, don't render it.
                    BoundingSphere  regionBounds    = new BoundingSphere(GetRegionCenter(r), REGIONSIZE);
                    BoundingFrustum boundingFrustum = new BoundingFrustum(gameInstance.propertyBag.playerCamera.ViewMatrix * gameInstance.propertyBag.playerCamera.ProjectionMatrix);
                    if (boundingFrustum.Contains(regionBounds) == ContainmentType.Disjoint)
                    {
                        continue;
                    }

                    // Make sure our vertex buffer is clean.
                    if (vertexListDirty[(byte)blockTexture, r])
                    {
                        continue;
                    }

                    // Actually render.
                    RenderVertexList(graphicsDevice, regionBuffer, blockTextures[(byte)blockTexture].Texture, blockTextures[(byte)blockTexture].LODColor, renderTranslucent, blockTexture == BlockTexture.Lava, (float)gameTime.TotalGameTime.TotalSeconds);
                }
            }

            // Apply posteffects.
            if (bloomPosteffect != null)
            {
                bloomPosteffect.Draw(graphicsDevice);
            }
        }
Esempio n. 7
0
 private void RegenerateDirtyVertexLists()
 {
     for (BlockTexture blockTexture = BlockTexture.None + 1; blockTexture < BlockTexture.MAXIMUM; blockTexture++)
     {
         for (int r = 0; r < NUMREGIONS; r++)
         {
             if (vertexListDirty[(byte)blockTexture, r])
             {
                 vertexListDirty[(byte)blockTexture, r] = false;
                 Dictionary <uint, bool> faceList = faceMap[(byte)blockTexture, r];
                 vertexBuffers[(byte)blockTexture, r] = CreateVertexBufferFromFaceList(faceList, (byte)blockTexture, r);
             }
         }
     }
 }
Esempio n. 8
0
        public static void Load(GameWindow window)
        {
            Window = window;

            ResizeFrameBuffers();
            Window.Resize += (sender, args) => ResizeFrameBuffers();

            WorldGeometryShader = ResourceReader.ReadShader(PluginDir + "Shaders/WorldGeometry");
            CompositionShader   = ResourceReader.ReadShader(PluginDir + "Shaders/Composition");
            PointLightShader    = ResourceReader.ReadShader(PluginDir + "Shaders/PointLight");
            BlockOutlineShader  = ResourceReader.ReadShader(PluginDir + "Shaders/BlockOutline");
            SpriteShader        = ResourceReader.ReadShader(PluginDir + "Shaders/Sprite");

            ScreenRectVao = new SpriteVertexArrayObject();
            ScreenRectVao.Add(new Vector2(-1, +1), Vector2.Zero, Vector3.Zero);
            ScreenRectVao.Add(new Vector2(+1, +1), Vector2.Zero, Vector3.Zero);
            ScreenRectVao.Add(new Vector2(-1, -1), Vector2.Zero, Vector3.Zero);
            ScreenRectVao.Add(new Vector2(+1, -1), Vector2.Zero, Vector3.Zero);
            ScreenRectVao.AddFace(new uint[] { 0, 2, 1, 1, 2, 3 });
            ScreenRectVao.Upload();

            Samplers.Load();

            MissingModel   = ResourceReader.ReadBlockModel("System/Models/MissingModel.json");
            MissingTexture = ResourceReader.ReadBlockTexture("System/Textures/Blocks/MissingTexture.png");

            //TODO: Remove

            var lines = File.ReadAllLines("Keybindings.txt");

            foreach (var line in lines)
            {
                var splits = line.Split('=');

                if (splits.Length != 2)
                {
                    continue;
                }

                if (Enum.TryParse(splits[0], true, out Key key))
                {
                    Keybindings.Add(key, splits[1]);
                }
            }
        }
Esempio n. 9
0
    Color32 GetWallAverageColor(BasicBlock block)
    {
        Color32      color;
        BlockTexture tex  = block.blockTexture;
        Vector2      side = World.s2v(tex.side);
        Texture2D    t    = (Texture2D)(world.transparentMaterial.mainTexture);

        Color32[] texColors = t.GetPixels32();

        int width  = (int)(t.width / world.basic.tileCols);
        int height = (int)(t.height / world.basic.tileRows);


        float textureSizeCols = 1f / world.basic.tileCols;
        float textureSizeRows = 1f / world.basic.tileRows;
        float c1 = side.y / world.basic.tileCols;
        float r1 = side.x / world.basic.tileRows;

        r1 = 1f - r1 - textureSizeRows;
        float c2 = c1 + textureSizeCols;
        float r2 = r1 + textureSizeRows;


        Texture2D texture = new Texture2D(width, height);

        for (int b = 0; b < height; b++)
        {
            for (int a = 0; a < width; a++)
            {
                texture.SetPixel(a, b, texColors[((int)(c1 * t.height) + a) + ((int)(r1 * t.height) + b) * t.width]);
            }
        }
        //GameObject obj =  Instantiate(debugPlanePrefab, parent);
        //texture.filterMode = FilterMode.Point;
        //obj.GetComponent<Renderer>().material.mainTexture = texture;

        return(AverageColorFromTexture(texture));
    }
Esempio n. 10
0
    public void setType(BlockType type)
    {
        uvs.Clear();
        blockType = type;
        BlockTexture tex   = Block.blockTypes[(int)type].texture;
        int          texId = tex.PosX;

        uvs.Add(new Vector3(0, 1, texId));
        uvs.Add(new Vector3(1, 1, texId));
        uvs.Add(new Vector3(1, 0, texId));
        uvs.Add(new Vector3(0, 0, texId));
        texId = tex.PosY;
        uvs.Add(new Vector3(0, 1, texId));
        uvs.Add(new Vector3(1, 1, texId));
        uvs.Add(new Vector3(1, 0, texId));
        uvs.Add(new Vector3(0, 0, texId));
        texId = tex.PosZ;
        uvs.Add(new Vector3(0, 1, texId));
        uvs.Add(new Vector3(1, 1, texId));
        uvs.Add(new Vector3(1, 0, texId));
        uvs.Add(new Vector3(0, 0, texId));
        texId = tex.NegX;
        uvs.Add(new Vector3(0, 1, texId));
        uvs.Add(new Vector3(1, 1, texId));
        uvs.Add(new Vector3(1, 0, texId));
        uvs.Add(new Vector3(0, 0, texId));
        texId = tex.NegY;
        uvs.Add(new Vector3(0, 1, texId));
        uvs.Add(new Vector3(1, 1, texId));
        uvs.Add(new Vector3(1, 0, texId));
        uvs.Add(new Vector3(0, 0, texId));
        texId = tex.NegZ;
        uvs.Add(new Vector3(0, 1, texId));
        uvs.Add(new Vector3(1, 1, texId));
        uvs.Add(new Vector3(1, 0, texId));
        uvs.Add(new Vector3(0, 0, texId));
        mf.mesh.SetUVs(0, uvs);
    }
Esempio n. 11
0
        private void BuildFace(Vector3i bottomBackLeft, BlockFaceField faceDir, BlockType type)
        {
            if (type == BlockType.Air)
            {
                return;
            }

            BlockTexture faceTexture = GetTexture(faceDir, type);

            Vector2[]  uvMap     = UVMap[faceTexture][faceDir];
            Vector3i[] offsetMap = faceVertexOffsetMap[faceDir];

            Vector3i currentFace;

            for (int k = 0; k < 6; k++)
            {
                if (regionMesh.Length < index + k + 1)
                {
                    break;
                }

                currentFace = (bottomBackLeft + offsetMap[k]);

                if (regionMesh[index + k] == null)
                {
                    regionMesh[index + k] = new VertexPositionTexture(currentFace.ToVector3, uvMap[k]);
                }
                else
                {
                    regionMesh[index + k].Position          = currentFace.ToVector3;
                    regionMesh[index + k].TextureCoordinate = uvMap[k];
                }
            }

            index += 6;
        }
Esempio n. 12
0
        public void BuildFaceVertices(Vector3i blockPosition, Vector3i chunkRelativePosition, BlockFaceDirection faceDir, BlockType blockType, float aoTL, float aoTR, float aoBL, float aoBR)
        {
            BlockTexture texture = BlockInformation.GetTexture(blockType, faceDir);

            int faceIndex = 0;

            switch (faceDir)
            {
            case BlockFaceDirection.XIncreasing:
                faceIndex = 0;
                break;

            case BlockFaceDirection.XDecreasing:
                faceIndex = 1;
                break;

            case BlockFaceDirection.YIncreasing:
                faceIndex = 2;
                break;

            case BlockFaceDirection.YDecreasing:
                faceIndex = 3;
                break;

            case BlockFaceDirection.ZIncreasing:
                faceIndex = 4;
                break;

            case BlockFaceDirection.ZDecreasing:
                faceIndex = 5;
                break;
            }

            int crackStage = 0;


            Vector2[] UVList      = TextureHelper.UVMappings[(int)texture * 6 + faceIndex];
            Vector2[] CrackUVList = TextureHelper.CrackMappings[crackStage * 6 + faceIndex];

            float light = 2;//TODO light hardcoded to 2

            Vector2 aoTilePosition = new Vector2(0, 0);

            switch (faceDir)
            {
            case BlockFaceDirection.XIncreasing:
            {
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(1, 1, 1), new Vector3(1, 0, 0), light, UVList[0], CrackUVList[0], aoTR);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(1, 1, 0), new Vector3(1, 0, 0), light, UVList[1], CrackUVList[1], aoTL);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(1, 0, 1), new Vector3(1, 0, 0), light, UVList[2], CrackUVList[2], aoBR);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(1, 0, 1), new Vector3(1, 0, 0), light, UVList[3], CrackUVList[3], aoBR);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(1, 1, 0), new Vector3(1, 0, 0), light, UVList[4], CrackUVList[4], aoTL);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(1, 0, 0), new Vector3(1, 0, 0), light, UVList[5], CrackUVList[5], aoBL);
            }
            break;

            case BlockFaceDirection.XDecreasing:
            {
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(0, 1, 0), new Vector3(-1, 0, 0), light, UVList[0], CrackUVList[0], aoTR);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(0, 1, 1), new Vector3(-1, 0, 0), light, UVList[1], CrackUVList[1], aoTL);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(0, 0, 1), new Vector3(-1, 0, 0), light, UVList[2], CrackUVList[2], aoBL);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(0, 1, 0), new Vector3(-1, 0, 0), light, UVList[3], CrackUVList[3], aoTR);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(0, 0, 1), new Vector3(-1, 0, 0), light, UVList[4], CrackUVList[4], aoBL);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(0, 0, 0), new Vector3(-1, 0, 0), light, UVList[5], CrackUVList[5], aoBR);
            }
            break;

            case BlockFaceDirection.YIncreasing:
            {
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(0, 1, 0), new Vector3(0, 1, 0), light, UVList[0], CrackUVList[0], aoBL);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(1, 1, 0), new Vector3(0, 1, 0), light, UVList[1], CrackUVList[1], aoBR);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(1, 1, 1), new Vector3(0, 1, 0), light, UVList[2], CrackUVList[2], aoTR);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(0, 1, 0), new Vector3(0, 1, 0), light, UVList[3], CrackUVList[3], aoBL);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(1, 1, 1), new Vector3(0, 1, 0), light, UVList[4], CrackUVList[4], aoTR);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(0, 1, 1), new Vector3(0, 1, 0), light, UVList[5], CrackUVList[5], aoTL);
            }
            break;

            case BlockFaceDirection.YDecreasing:
            {
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(1, 0, 1), new Vector3(0, -1, 0), light, UVList[0], CrackUVList[0], aoTR);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(1, 0, 0), new Vector3(0, -1, 0), light, UVList[1], CrackUVList[1], aoBR);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(0, 0, 1), new Vector3(0, -1, 0), light, UVList[2], CrackUVList[2], aoBL);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(0, 0, 1), new Vector3(0, -1, 0), light, UVList[3], CrackUVList[3], aoBL);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(1, 0, 0), new Vector3(0, -1, 0), light, UVList[4], CrackUVList[4], aoBR);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(0, 0, 0), new Vector3(0, -1, 0), light, UVList[5], CrackUVList[5], aoTR);
            }
            break;

            case BlockFaceDirection.ZIncreasing:
            {
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(0, 1, 1), new Vector3(0, 0, 1), light, UVList[0], CrackUVList[0], aoTR);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(1, 1, 1), new Vector3(0, 0, 1), light, UVList[1], CrackUVList[1], aoTL);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(1, 0, 1), new Vector3(0, 0, 1), light, UVList[2], CrackUVList[2], aoBL);

                AddVertex(blockPosition, chunkRelativePosition, new Vector3(0, 1, 1), new Vector3(0, 0, 1), light, UVList[3], CrackUVList[3], aoTR);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(1, 0, 1), new Vector3(0, 0, 1), light, UVList[4], CrackUVList[4], aoBL);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(0, 0, 1), new Vector3(0, 0, 1), light, UVList[5], CrackUVList[5], aoBR);
            }
            break;

            case BlockFaceDirection.ZDecreasing:
            {
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(1, 1, 0), new Vector3(0, 0, -1), light, UVList[0], CrackUVList[0], aoTR);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(0, 1, 0), new Vector3(0, 0, -1), light, UVList[1], CrackUVList[1], aoTL);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(1, 0, 0), new Vector3(0, 0, -1), light, UVList[2], CrackUVList[2], aoBR);

                AddVertex(blockPosition, chunkRelativePosition, new Vector3(1, 0, 0), new Vector3(0, 0, -1), light, UVList[3], CrackUVList[3], aoBR);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(0, 1, 0), new Vector3(0, 0, -1), light, UVList[4], CrackUVList[4], aoTL);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(0, 0, 0), new Vector3(0, 0, -1), light, UVList[5], CrackUVList[5], aoBL);
            }
            break;
            }
        }
Esempio n. 13
0
    void Awake()
    {
        Mesh           mesh  = new Mesh();
        List <Vector3> verts = new List <Vector3>();
        List <int>     tris  = new List <int>();
        List <Vector2> uvs   = new List <Vector2>();

        for (int y = 0; y > -Height; y--)
        {
            for (int x = 0; x < Width; x++)
            {
                for (int z = 0; z < Width; z++)
                {
                    int3 block = GetBlock(x, y, z);
                    if (block.x != 0) // check if air type
                    {
                        float3 blockPos = new float3(x, y, z);
                        int    numFaces = 0;

                        verts.Add(blockPos + new float3(0, 1, 0));
                        verts.Add(blockPos + new float3(0, 1, 1));
                        verts.Add(blockPos + new float3(1, 1, 1));
                        verts.Add(blockPos + new float3(1, 1, 0));
                        numFaces++;

                        uvs.AddRange(BlockTexture.Get((BlockType)block.x, 1).topPos.GetUVs());

                        //bottom

                        verts.Add(blockPos + new float3(0, 0, 0));
                        verts.Add(blockPos + new float3(1, 0, 0));
                        verts.Add(blockPos + new float3(1, 0, 1));
                        verts.Add(blockPos + new float3(0, 0, 1));
                        numFaces++;

                        uvs.AddRange(BlockTexture.Get((BlockType)block.x, 1).bottomPos.GetUVs());

                        //front

                        verts.Add(blockPos + new float3(0, 0, 0));
                        verts.Add(blockPos + new float3(0, 1, 0));
                        verts.Add(blockPos + new float3(1, 1, 0));
                        verts.Add(blockPos + new float3(1, 0, 0));
                        numFaces++;

                        uvs.AddRange(BlockTexture.Get((BlockType)block.x, 1).sidePos.GetUVs());

                        //right

                        verts.Add(blockPos + new float3(1, 0, 0));
                        verts.Add(blockPos + new float3(1, 1, 0));
                        verts.Add(blockPos + new float3(1, 1, 1));
                        verts.Add(blockPos + new float3(1, 0, 1));
                        numFaces++;

                        uvs.AddRange(BlockTexture.Get((BlockType)block.x, 1).sidePos.GetUVs());

                        //back

                        verts.Add(blockPos + new float3(1, 0, 1));
                        verts.Add(blockPos + new float3(1, 1, 1));
                        verts.Add(blockPos + new float3(0, 1, 1));
                        verts.Add(blockPos + new float3(0, 0, 1));
                        numFaces++;

                        uvs.AddRange(BlockTexture.Get((BlockType)block.x, 1).sidePos.GetUVs());

                        //left

                        verts.Add(blockPos + new float3(0, 0, 1));
                        verts.Add(blockPos + new float3(0, 1, 1));
                        verts.Add(blockPos + new float3(0, 1, 0));
                        verts.Add(blockPos + new float3(0, 0, 0));
                        numFaces++;

                        uvs.AddRange(BlockTexture.Get((BlockType)block.x, 1).sidePos.GetUVs());

                        int tl = verts.Count - 4 * numFaces;
                        for (int idx = 0; idx < numFaces; idx++)
                        {
                            NativeArray <int> range = new NativeArray <int>(6, Allocator.Temp);
                            range[0] = tl + idx * 4;
                            range[1] = tl + idx * 4 + 1;
                            range[2] = tl + idx * 4 + 2;
                            range[3] = tl + idx * 4;
                            range[4] = tl + idx * 4 + 2;
                            range[5] = tl + idx * 4 + 3;
                            tris.AddRange(range);
                            range.Dispose();
                        }
                    }
                }
            }
        }

        mesh.vertices  = verts.ToArray();
        mesh.triangles = tris.ToArray();
        mesh.uv        = uvs.ToArray();

        mesh.RecalculateNormals();

        GetComponent <MeshFilter>().mesh         = mesh;
        GetComponent <MeshCollider>().sharedMesh = mesh;
    }
Esempio n. 14
0
        public BlockEngine(InfiniminerGame gameInstance)
        {
            this.gameInstance = gameInstance;

            // Initialize the block list.
            downloadList = new BlockType[MAPSIZE, MAPSIZE, MAPSIZE];
            blockList    = new BlockType[MAPSIZE, MAPSIZE, MAPSIZE];
            for (ushort i = 0; i < MAPSIZE; i++)
            {
                for (ushort j = 0; j < MAPSIZE; j++)
                {
                    for (ushort k = 0; k < MAPSIZE; k++)
                    {
                        downloadList[i, j, k] = BlockType.None;
                        blockList[i, j, k]    = BlockType.None;
                    }
                }
            }

            // Initialize the face lists.
            faceMap = new Dictionary <uint, bool> [(byte)BlockTexture.MAXIMUM, NUMREGIONS];
            for (BlockTexture blockTexture = BlockTexture.None; blockTexture < BlockTexture.MAXIMUM; blockTexture++)
            {
                for (int r = 0; r < NUMREGIONS; r++)
                {
                    faceMap[(byte)blockTexture, r] = new Dictionary <uint, bool>();
                }
            }

            // Initialize the texture map.
            blockTextureMap = new BlockTexture[(byte)BlockType.MAXIMUM, 6];
            for (BlockType blockType = BlockType.None; blockType < BlockType.MAXIMUM; blockType++)
            {
                for (BlockFaceDirection faceDir = BlockFaceDirection.XIncreasing; faceDir < BlockFaceDirection.MAXIMUM; faceDir++)
                {
                    blockTextureMap[(byte)blockType, (byte)faceDir] = BlockInformation.GetTexture(blockType, faceDir);
                }
            }

            // Load the textures we'll use.
            blockTextures = new IMTexture[(byte)BlockTexture.MAXIMUM];
            blockTextures[(byte)BlockTexture.None]          = new IMTexture(null);
            blockTextures[(byte)BlockTexture.Dirt]          = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_dirt"));
            blockTextures[(byte)BlockTexture.Rock]          = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_rock"));
            blockTextures[(byte)BlockTexture.Ore]           = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_ore"));
            blockTextures[(byte)BlockTexture.Gold]          = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_silver"));
            blockTextures[(byte)BlockTexture.Diamond]       = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_diamond"));
            blockTextures[(byte)BlockTexture.HomeRed]       = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_home_red"));
            blockTextures[(byte)BlockTexture.HomeBlue]      = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_home_blue"));
            blockTextures[(byte)BlockTexture.SolidRed]      = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_red"));
            blockTextures[(byte)BlockTexture.SolidBlue]     = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_blue"));
            blockTextures[(byte)BlockTexture.Ladder]        = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_ladder"));
            blockTextures[(byte)BlockTexture.LadderTop]     = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_ladder_top"));
            blockTextures[(byte)BlockTexture.Spikes]        = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_spikes"));
            blockTextures[(byte)BlockTexture.Jump]          = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_jump"));
            blockTextures[(byte)BlockTexture.JumpTop]       = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_jump_top"));
            blockTextures[(byte)BlockTexture.Explosive]     = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_explosive"));
            blockTextures[(byte)BlockTexture.Metal]         = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_metal"));
            blockTextures[(byte)BlockTexture.DirtSign]      = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_dirt_sign"));
            blockTextures[(byte)BlockTexture.BankTopRed]    = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_bank_top_red"));
            blockTextures[(byte)BlockTexture.BankLeftRed]   = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_bank_left_red"));
            blockTextures[(byte)BlockTexture.BankFrontRed]  = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_bank_front_red"));
            blockTextures[(byte)BlockTexture.BankRightRed]  = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_bank_right_red"));
            blockTextures[(byte)BlockTexture.BankBackRed]   = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_bank_back_red"));
            blockTextures[(byte)BlockTexture.BankTopBlue]   = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_bank_top_blue"));
            blockTextures[(byte)BlockTexture.BankLeftBlue]  = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_bank_left_blue"));
            blockTextures[(byte)BlockTexture.BankFrontBlue] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_bank_front_blue"));
            blockTextures[(byte)BlockTexture.BankRightBlue] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_bank_right_blue"));
            blockTextures[(byte)BlockTexture.BankBackBlue]  = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_bank_back_blue"));
            blockTextures[(byte)BlockTexture.TeleSideA]     = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_teleporter_a"));
            blockTextures[(byte)BlockTexture.TeleSideB]     = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_teleporter_b"));
            blockTextures[(byte)BlockTexture.TeleTop]       = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_teleporter_top"));
            blockTextures[(byte)BlockTexture.TeleBottom]    = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_teleporter_bottom"));
            blockTextures[(byte)BlockTexture.Lava]          = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_lava"));
            blockTextures[(byte)BlockTexture.Road]          = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_road"));
            blockTextures[(byte)BlockTexture.RoadTop]       = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_road_top"));
            blockTextures[(byte)BlockTexture.RoadBottom]    = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_road_bottom"));
            blockTextures[(byte)BlockTexture.BeaconRed]     = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_beacon_top_red"));
            blockTextures[(byte)BlockTexture.BeaconBlue]    = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_beacon_top_blue"));
            blockTextures[(byte)BlockTexture.TransRed]      = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_trans_red"));
            blockTextures[(byte)BlockTexture.TransBlue]     = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_trans_blue"));

            // Load our effects.
            basicEffect = gameInstance.Content.Load <Effect>("effect_basic");

            // Build vertex lists.
            vertexBuffers   = new DynamicVertexBuffer[(byte)BlockTexture.MAXIMUM, NUMREGIONS];
            vertexListDirty = new bool[(byte)BlockTexture.MAXIMUM, NUMREGIONS];
            for (int i = 0; i < (byte)BlockTexture.MAXIMUM; i++)
            {
                for (int j = 0; j < NUMREGIONS; j++)
                {
                    vertexListDirty[i, j] = true;
                }
            }

            // Initialize any graphics stuff.
            vertexDeclaration = new VertexDeclaration(VertexPositionTexture.VertexDeclaration.GetVertexElements());


            // Initialize the bloom engine.
            if (gameInstance.RenderPretty)
            {
                bloomPosteffect = new BloomComponent();
                bloomPosteffect.Load(gameInstance.GraphicsDevice, gameInstance.Content);
            }
            else
            {
                bloomPosteffect = null;
            }
        }
Esempio n. 15
0
        private static void BuildFaceVertices(Chunk chunk, Vector3Int position, BlockType blockType, BlockFaceDirection faceDir,
                                              float sunLightTL, float sunLightTR, float sunLightBL, float sunLightBR,
                                              Color localLightTL, Color localLightTR, Color localLightBL, Color localLightBR)
        {
            if (chunk.Disposed)
            {
                return;
            }

            BlockTexture texture = Block.GetTexture(blockType, faceDir);

            int faceIndex = 0; // techcraft actually uses (int)faceDir here. Further investigate it. /raist.

            HalfVector2[] textureUVMappings = TextureHelper.BlockTextureMappings[(int)texture * 6 + faceIndex];

            //int crackStage = 0;
            //HalfVector2[] crackUVMappings = TextureHelper.BlockTextureMappings[crackStage * 6 + faceIndex];

            switch (faceDir)
            {
            case BlockFaceDirection.XIncreasing:
            {
                //TR,TL,BR,BR,TL,BL
                AddVertex(chunk, position, new Vector3(1, 1, 1), textureUVMappings[0], sunLightTR, localLightTR);
                AddVertex(chunk, position, new Vector3(1, 1, 0), textureUVMappings[1], sunLightTL, localLightTL);
                AddVertex(chunk, position, new Vector3(1, 0, 1), textureUVMappings[2], sunLightBR, localLightBR);
                AddVertex(chunk, position, new Vector3(1, 0, 0), textureUVMappings[5], sunLightBL, localLightBL);
                AddIndex(chunk, 0, 1, 2, 2, 1, 3);
            }
            break;

            case BlockFaceDirection.XDecreasing:
            {
                //TR,TL,BL,TR,BL,BR
                AddVertex(chunk, position, new Vector3(0, 1, 0), textureUVMappings[0], sunLightTR, localLightTR);
                AddVertex(chunk, position, new Vector3(0, 1, 1), textureUVMappings[1], sunLightTL, localLightTL);
                AddVertex(chunk, position, new Vector3(0, 0, 0), textureUVMappings[5], sunLightBR, localLightBR);
                AddVertex(chunk, position, new Vector3(0, 0, 1), textureUVMappings[2], sunLightBL, localLightBL);
                AddIndex(chunk, 0, 1, 3, 0, 3, 2);
            }
            break;

            case BlockFaceDirection.YIncreasing:
            {
                //BL,BR,TR,BL,TR,TL
                AddVertex(chunk, position, new Vector3(1, 1, 1), textureUVMappings[0], sunLightTR, localLightTR);
                AddVertex(chunk, position, new Vector3(0, 1, 1), textureUVMappings[2], sunLightTL, localLightTL);
                AddVertex(chunk, position, new Vector3(1, 1, 0), textureUVMappings[4], sunLightBR, localLightBR);
                AddVertex(chunk, position, new Vector3(0, 1, 0), textureUVMappings[5], sunLightBL, localLightBL);
                AddIndex(chunk, 3, 2, 0, 3, 0, 1);
            }
            break;

            case BlockFaceDirection.YDecreasing:
            {
                //TR,BR,TL,TL,BR,BL
                AddVertex(chunk, position, new Vector3(1, 0, 1), textureUVMappings[0], sunLightTR, localLightTR);
                AddVertex(chunk, position, new Vector3(0, 0, 1), textureUVMappings[2], sunLightTL, localLightTL);
                AddVertex(chunk, position, new Vector3(1, 0, 0), textureUVMappings[4], sunLightBR, localLightBR);
                AddVertex(chunk, position, new Vector3(0, 0, 0), textureUVMappings[5], sunLightBL, localLightBL);
                AddIndex(chunk, 0, 2, 1, 1, 2, 3);
            }
            break;

            case BlockFaceDirection.ZIncreasing:
            {
                //TR,TL,BL,TR,BL,BR
                AddVertex(chunk, position, new Vector3(0, 1, 1), textureUVMappings[0], sunLightTR, localLightTR);
                AddVertex(chunk, position, new Vector3(1, 1, 1), textureUVMappings[1], sunLightTL, localLightTL);
                AddVertex(chunk, position, new Vector3(0, 0, 1), textureUVMappings[5], sunLightBR, localLightBR);
                AddVertex(chunk, position, new Vector3(1, 0, 1), textureUVMappings[2], sunLightBL, localLightBL);
                AddIndex(chunk, 0, 1, 3, 0, 3, 2);
            }
            break;

            case BlockFaceDirection.ZDecreasing:
            {
                //TR,TL,BR,BR,TL,BL
                AddVertex(chunk, position, new Vector3(1, 1, 0), textureUVMappings[0], sunLightTR, localLightTR);
                AddVertex(chunk, position, new Vector3(0, 1, 0), textureUVMappings[1], sunLightTL, localLightTL);
                AddVertex(chunk, position, new Vector3(1, 0, 0), textureUVMappings[2], sunLightBR, localLightBR);
                AddVertex(chunk, position, new Vector3(0, 0, 0), textureUVMappings[5], sunLightBL, localLightBL);
                AddIndex(chunk, 0, 1, 2, 2, 1, 3);
            }
            break;
            }
        }
Esempio n. 16
0
        private void BuildFaceVertices(int x, int z, BlockFaceDirection faceDir)
        {
            BlockTexture texture   = Block.GetTexture(BlockType.Snow, faceDir);
            int          faceIndex = 0;

            var textureUVMappings = TextureHelper.BlockTextureMappings[(int)texture * 6 + faceIndex];


            switch (faceDir)
            {
            case BlockFaceDirection.XIncreasing:
            {
                //TR,TL,BR,BR,TL,BL
                AddVertex(x, z, new Vector3(1, 1, 1), textureUVMappings[0]);
                AddVertex(x, z, new Vector3(1, 1, 0), textureUVMappings[1]);
                AddVertex(x, z, new Vector3(1, 0, 1), textureUVMappings[2]);
                AddVertex(x, z, new Vector3(1, 0, 0), textureUVMappings[5]);
                AddIndex(0, 1, 2, 2, 1, 3);
            }
            break;

            case BlockFaceDirection.XDecreasing:
            {
                //TR,TL,BL,TR,BL,BR
                AddVertex(x, z, new Vector3(0, 1, 0), textureUVMappings[0]);
                AddVertex(x, z, new Vector3(0, 1, 1), textureUVMappings[1]);
                AddVertex(x, z, new Vector3(0, 0, 0), textureUVMappings[5]);
                AddVertex(x, z, new Vector3(0, 0, 1), textureUVMappings[2]);
                AddIndex(0, 1, 3, 0, 3, 2);
            }
            break;

            case BlockFaceDirection.YIncreasing:
            {
                //BL,BR,TR,BL,TR,TL
                AddVertex(x, z, new Vector3(1, 1, 1), textureUVMappings[0]);
                AddVertex(x, z, new Vector3(0, 1, 1), textureUVMappings[2]);
                AddVertex(x, z, new Vector3(1, 1, 0), textureUVMappings[4]);
                AddVertex(x, z, new Vector3(0, 1, 0), textureUVMappings[5]);
                AddIndex(3, 2, 0, 3, 0, 1);
            }
            break;

            case BlockFaceDirection.YDecreasing:
            {
                //TR,BR,TL,TL,BR,BL
                AddVertex(x, z, new Vector3(1, 0, 1), textureUVMappings[0]);
                AddVertex(x, z, new Vector3(0, 0, 1), textureUVMappings[2]);
                AddVertex(x, z, new Vector3(1, 0, 0), textureUVMappings[4]);
                AddVertex(x, z, new Vector3(0, 0, 0), textureUVMappings[5]);
                AddIndex(0, 2, 1, 1, 2, 3);
            }
            break;

            case BlockFaceDirection.ZIncreasing:
            {
                //TR,TL,BL,TR,BL,BR
                AddVertex(x, z, new Vector3(0, 1, 1), textureUVMappings[0]);
                AddVertex(x, z, new Vector3(1, 1, 1), textureUVMappings[1]);
                AddVertex(x, z, new Vector3(0, 0, 1), textureUVMappings[5]);
                AddVertex(x, z, new Vector3(1, 0, 1), textureUVMappings[2]);
                AddIndex(0, 1, 3, 0, 3, 2);
            }
            break;

            case BlockFaceDirection.ZDecreasing:
            {
                //TR,TL,BR,BR,TL,BL
                AddVertex(x, z, new Vector3(1, 1, 0), textureUVMappings[0]);
                AddVertex(x, z, new Vector3(0, 1, 0), textureUVMappings[1]);
                AddVertex(x, z, new Vector3(1, 0, 0), textureUVMappings[2]);
                AddVertex(x, z, new Vector3(0, 0, 0), textureUVMappings[5]);
                AddIndex(0, 1, 2, 2, 1, 3);
            }
            break;
            }
        }
Esempio n. 17
0
    public void BuildMesh()
    {
        chunkPos = Utils.ChunkPosbyPosition(transform.position);
        Mesh mesh = new Mesh();
        NativeList <Vector3> verts = new NativeList <Vector3>(Allocator.Temp);
        NativeList <int>     tris  = new NativeList <int>(Allocator.Temp);
        List <Vector2>       uvs   = new List <Vector2>();

        for (int i = 0; i < BlocksCount; i++)
        {
            if (blocks[i].x != 0) // check if air type
            {
                int3   coord    = Utils.to3DBlocks(i);
                float3 blockPos = new float3(coord.x - 1, coord.y, coord.z - 1);

                int blockGrade = Math.Min(Mathf.FloorToInt(blocks[i].y / 10), 2);

                int numFaces = 0;
                if (GetTopBlock(coord, chunkPos).x == 0)
                {
                    verts.Add(blockPos + new float3(0, 1, 0));
                    verts.Add(blockPos + new float3(0, 1, 1));
                    verts.Add(blockPos + new float3(1, 1, 1));
                    verts.Add(blockPos + new float3(1, 1, 0));
                    numFaces++;

                    uvs.AddRange(BlockTexture.Get((BlockType)blocks[i].x, blockGrade).topPos.GetUVs());
                }

                //bottom
                if (GetBottomBlock(coord, chunkPos).x == 0)
                {
                    verts.Add(blockPos + new float3(0, 0, 0));
                    verts.Add(blockPos + new float3(1, 0, 0));
                    verts.Add(blockPos + new float3(1, 0, 1));
                    verts.Add(blockPos + new float3(0, 0, 1));
                    numFaces++;

                    uvs.AddRange(BlockTexture.Get((BlockType)blocks[i].x, blockGrade).bottomPos.GetUVs());
                }

                //front
                if (GetFrontBlock(coord, chunkPos).x == 0)
                {
                    verts.Add(blockPos + new float3(0, 0, 0));
                    verts.Add(blockPos + new float3(0, 1, 0));
                    verts.Add(blockPos + new float3(1, 1, 0));
                    verts.Add(blockPos + new float3(1, 0, 0));
                    numFaces++;

                    uvs.AddRange(BlockTexture.Get((BlockType)blocks[i].x, blockGrade).sidePos.GetUVs());
                }

                //right
                if (GetRightBlock(coord, chunkPos).x == 0)
                {
                    verts.Add(blockPos + new float3(1, 0, 0));
                    verts.Add(blockPos + new float3(1, 1, 0));
                    verts.Add(blockPos + new float3(1, 1, 1));
                    verts.Add(blockPos + new float3(1, 0, 1));
                    numFaces++;

                    uvs.AddRange(BlockTexture.Get((BlockType)blocks[i].x, blockGrade).sidePos.GetUVs());
                }

                //back
                if (GetBackBlock(coord, chunkPos).x == 0)
                {
                    verts.Add(blockPos + new float3(1, 0, 1));
                    verts.Add(blockPos + new float3(1, 1, 1));
                    verts.Add(blockPos + new float3(0, 1, 1));
                    verts.Add(blockPos + new float3(0, 0, 1));
                    numFaces++;

                    uvs.AddRange(BlockTexture.Get((BlockType)blocks[i].x, blockGrade).sidePos.GetUVs());
                }

                //left
                if (GetLeftBlock(coord, chunkPos).x == 0)
                {
                    verts.Add(blockPos + new float3(0, 0, 1));
                    verts.Add(blockPos + new float3(0, 1, 1));
                    verts.Add(blockPos + new float3(0, 1, 0));
                    verts.Add(blockPos + new float3(0, 0, 0));
                    numFaces++;

                    uvs.AddRange(BlockTexture.Get((BlockType)blocks[i].x, blockGrade).sidePos.GetUVs());
                }

                int tl = verts.Length - 4 * numFaces;
                for (int idx = 0; idx < numFaces; idx++)
                {
                    NativeArray <int> range = new NativeArray <int>(6, Allocator.Temp);
                    range[0] = tl + idx * 4;
                    range[1] = tl + idx * 4 + 1;
                    range[2] = tl + idx * 4 + 2;
                    range[3] = tl + idx * 4;
                    range[4] = tl + idx * 4 + 2;
                    range[5] = tl + idx * 4 + 3;
                    tris.AddRange(range);
                    range.Dispose();
                }
            }
        }

        mesh.vertices  = verts.ToArray();
        mesh.triangles = tris.ToArray();
        mesh.uv        = uvs.ToArray();

        mesh.RecalculateNormals();

        GetComponent <MeshFilter>().mesh         = mesh;
        GetComponent <MeshCollider>().sharedMesh = mesh;
        verts.Dispose();
        tris.Dispose();
    }
Esempio n. 18
0
        public void BuildFaceVertices(ref List <VertexPositionTextureShade> vertexList, Vector3i blockPosition, BlockFaceDirection faceDir, BlockType blockType)
        {
            BlockTexture texture = BlockInformation.GetTexture(blockType, faceDir);

            //Debug.WriteLine(string.Format("BuildBlockVertices ({0},{1},{2}) : {3} ->{4} :", x, y, z, faceDir, texture));

            int faceIndex = 0;

            switch (faceDir)
            {
            case BlockFaceDirection.XIncreasing:
                faceIndex = 0;
                break;

            case BlockFaceDirection.XDecreasing:
                faceIndex = 1;
                break;

            case BlockFaceDirection.YIncreasing:
                faceIndex = 2;
                break;

            case BlockFaceDirection.YDecreasing:
                faceIndex = 3;
                break;

            case BlockFaceDirection.ZIncreasing:
                faceIndex = 4;
                break;

            case BlockFaceDirection.ZDecreasing:
                faceIndex = 5;
                break;
            }

            Vector2[] UVList = TextureHelper.UVMappings[(int)texture * 6 + faceIndex];

            float light = 2;//TODO light hardcoded to 2

            switch (faceDir)
            {
            case BlockFaceDirection.XIncreasing:
            {
                vertexList.Add(ToVertexPositionTextureShade(blockPosition, Vector3.One, Vector3.UnitX, light, UVList[0]));
                vertexList.Add(ToVertexPositionTextureShade(blockPosition, vector110, Vector3.UnitX, light, UVList[1]));
                vertexList.Add(ToVertexPositionTextureShade(blockPosition, vector101, Vector3.UnitX, light, UVList[2]));
                vertexList.Add(ToVertexPositionTextureShade(blockPosition, vector101, Vector3.UnitX, light, UVList[3]));
                vertexList.Add(ToVertexPositionTextureShade(blockPosition, vector110, Vector3.UnitX, light, UVList[4]));
                vertexList.Add(ToVertexPositionTextureShade(blockPosition, Vector3.UnitX, Vector3.UnitX, light, UVList[5]));
            }
            break;

            case BlockFaceDirection.XDecreasing:
            {
                vertexList.Add(ToVertexPositionTextureShade(blockPosition, Vector3.UnitY, Vector3.Left, light, UVList[0]));
                vertexList.Add(ToVertexPositionTextureShade(blockPosition, vector011, Vector3.Left, light, UVList[1]));
                vertexList.Add(ToVertexPositionTextureShade(blockPosition, Vector3.UnitZ, Vector3.Left, light, UVList[2]));
                vertexList.Add(ToVertexPositionTextureShade(blockPosition, Vector3.UnitY, Vector3.Left, light, UVList[3]));
                vertexList.Add(ToVertexPositionTextureShade(blockPosition, Vector3.UnitZ, Vector3.Left, light, UVList[4]));
                vertexList.Add(ToVertexPositionTextureShade(blockPosition, Vector3.Zero, Vector3.Left, light, UVList[5]));
            }
            break;

            case BlockFaceDirection.YIncreasing:
            {
                vertexList.Add(ToVertexPositionTextureShade(blockPosition, Vector3.UnitY, Vector3.UnitY, light, UVList[0]));
                vertexList.Add(ToVertexPositionTextureShade(blockPosition, vector110, Vector3.UnitY, light, UVList[1]));
                vertexList.Add(ToVertexPositionTextureShade(blockPosition, Vector3.One, Vector3.UnitY, light, UVList[2]));
                vertexList.Add(ToVertexPositionTextureShade(blockPosition, Vector3.UnitY, Vector3.UnitY, light, UVList[3]));
                vertexList.Add(ToVertexPositionTextureShade(blockPosition, Vector3.One, Vector3.UnitY, light, UVList[4]));
                vertexList.Add(ToVertexPositionTextureShade(blockPosition, vector011, Vector3.UnitY, light, UVList[5]));
            }
            break;

            case BlockFaceDirection.YDecreasing:
            {
                vertexList.Add(ToVertexPositionTextureShade(blockPosition, vector101, Vector3.Down, light, UVList[0]));
                vertexList.Add(ToVertexPositionTextureShade(blockPosition, Vector3.UnitX, Vector3.Down, light, UVList[1]));
                vertexList.Add(ToVertexPositionTextureShade(blockPosition, Vector3.UnitZ, Vector3.Down, light, UVList[2]));
                vertexList.Add(ToVertexPositionTextureShade(blockPosition, Vector3.UnitZ, Vector3.Down, light, UVList[3]));
                vertexList.Add(ToVertexPositionTextureShade(blockPosition, Vector3.UnitX, Vector3.Down, light, UVList[4]));
                vertexList.Add(ToVertexPositionTextureShade(blockPosition, Vector3.Zero, Vector3.Down, light, UVList[5]));
            }
            break;

            case BlockFaceDirection.ZIncreasing:
            {
                vertexList.Add(ToVertexPositionTextureShade(blockPosition, vector011, Vector3.UnitZ, light, UVList[0]));
                vertexList.Add(ToVertexPositionTextureShade(blockPosition, Vector3.One, Vector3.UnitZ, light, UVList[1]));
                vertexList.Add(ToVertexPositionTextureShade(blockPosition, vector101, Vector3.UnitZ, light, UVList[2]));
                vertexList.Add(ToVertexPositionTextureShade(blockPosition, vector011, Vector3.UnitZ, light, UVList[3]));
                vertexList.Add(ToVertexPositionTextureShade(blockPosition, vector101, Vector3.UnitZ, light, UVList[4]));
                vertexList.Add(ToVertexPositionTextureShade(blockPosition, Vector3.UnitZ, Vector3.UnitZ, light, UVList[5]));
            }
            break;

            case BlockFaceDirection.ZDecreasing:
            {
                vertexList.Add(ToVertexPositionTextureShade(blockPosition, vector110, Vector3.Forward, light, UVList[0]));
                vertexList.Add(ToVertexPositionTextureShade(blockPosition, Vector3.UnitY, Vector3.Forward, light, UVList[1]));
                vertexList.Add(ToVertexPositionTextureShade(blockPosition, Vector3.UnitX, Vector3.Forward, light, UVList[2]));
                vertexList.Add(ToVertexPositionTextureShade(blockPosition, Vector3.UnitX, Vector3.Forward, light, UVList[3]));
                vertexList.Add(ToVertexPositionTextureShade(blockPosition, Vector3.UnitY, Vector3.Forward, light, UVList[4]));
                vertexList.Add(ToVertexPositionTextureShade(blockPosition, Vector3.Zero, Vector3.Forward, light, UVList[5]));
            }
            break;
            }
        }
Esempio n. 19
0
    public void BuildMesh(int2 dir)
    {
        Mesh mesh = new Mesh();
        NativeList <Vector3> verts = new NativeList <Vector3>(Allocator.Temp);
        NativeList <int>     tris  = new NativeList <int>(Allocator.Temp);
        List <Vector2>       uvs   = new List <Vector2>();

        float3 blockPos = new float3(0, 0, 0);

        int numFaces = 0;

        //front
        if (dir.y < 0)
        {
            verts.Add(blockPos + new float3(0, 0, 0));
            verts.Add(blockPos + new float3(0, 1, 0));
            verts.Add(blockPos + new float3(1, 1, 0));
            verts.Add(blockPos + new float3(1, 0, 0));
            numFaces++;

            uvs.AddRange(BlockTexture.Get(BlockType.BedRock, 0).sidePos.GetUVs());
        }

        //right
        if (dir.x > 0)
        {
            verts.Add(blockPos + new float3(1, 0, 0));
            verts.Add(blockPos + new float3(1, 1, 0));
            verts.Add(blockPos + new float3(1, 1, 1));
            verts.Add(blockPos + new float3(1, 0, 1));
            numFaces++;

            uvs.AddRange(BlockTexture.Get(BlockType.BedRock, 0).sidePos.GetUVs());
        }

        //back
        if (dir.y > 0)
        {
            verts.Add(blockPos + new float3(1, 0, 1));
            verts.Add(blockPos + new float3(1, 1, 1));
            verts.Add(blockPos + new float3(0, 1, 1));
            verts.Add(blockPos + new float3(0, 0, 1));
            numFaces++;

            uvs.AddRange(BlockTexture.Get(BlockType.BedRock, 0).sidePos.GetUVs());
        }

        //left
        if (dir.x < 0)
        {
            verts.Add(blockPos + new float3(0, 0, 1));
            verts.Add(blockPos + new float3(0, 1, 1));
            verts.Add(blockPos + new float3(0, 1, 0));
            verts.Add(blockPos + new float3(0, 0, 0));
            numFaces++;

            uvs.AddRange(BlockTexture.Get(BlockType.BedRock, 0).sidePos.GetUVs());
        }

        int tl = verts.Length - 4 * numFaces;

        for (int idx = 0; idx < numFaces; idx++)
        {
            NativeArray <int> range = new NativeArray <int>(6, Allocator.Temp);
            range[0] = tl + idx * 4;
            range[1] = tl + idx * 4 + 1;
            range[2] = tl + idx * 4 + 2;
            range[3] = tl + idx * 4;
            range[4] = tl + idx * 4 + 2;
            range[5] = tl + idx * 4 + 3;
            tris.AddRange(range);
            range.Dispose();
        }

        mesh.vertices  = verts.ToArray();
        mesh.triangles = tris.ToArray();
        mesh.uv        = uvs.ToArray();

        mesh.RecalculateNormals();

        GetComponent <MeshFilter>().mesh         = mesh;
        GetComponent <MeshCollider>().sharedMesh = mesh;
        verts.Dispose();
        tris.Dispose();
    }
Esempio n. 20
0
 public void Init()
 {
     _dirtAround = GameManager.BlockTextureManager.Get("dirtAround");
     _dirtTop    = GameManager.BlockTextureManager.Get("dirtTop");
 }
        public void BuildFaceVertices(Vector3i blockPosition, Vector3i chunkRelativePosition, BlockFaceDirection faceDir, BlockType blockType, float sunLightTL, float sunLightTR, float sunLightBL, float sunLightBR, Color localLightTL, Color localLightTR, Color localLightBL, Color localLightBR)
        {
            BlockTexture texture = BlockInformation.GetTexture(blockType, faceDir);

            int faceIndex = (int)faceDir;

            Vector2[] UVList = TextureHelper.UVMappings[(int)texture * 6 + faceIndex];

            switch (faceDir)
            {
            case BlockFaceDirection.XIncreasing:
            {
                //TR,TL,BR,BR,TL,BL
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(1, 1, 1), new Vector3(1, 0, 0), UVList[0], sunLightTR, localLightTR);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(1, 1, 0), new Vector3(1, 0, 0), UVList[1], sunLightTL, localLightTL);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(1, 0, 1), new Vector3(1, 0, 0), UVList[2], sunLightBR, localLightBR);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(1, 0, 0), new Vector3(1, 0, 0), UVList[5], sunLightBL, localLightBL);
                AddIndex(0, 1, 2, 2, 1, 3);
            }
            break;

            case BlockFaceDirection.XDecreasing:
            {
                //TR,TL,BL,TR,BL,BR
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(0, 1, 0), new Vector3(-1, 0, 0), UVList[0], sunLightTR, localLightTR);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(0, 1, 1), new Vector3(-1, 0, 0), UVList[1], sunLightTL, localLightTL);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(0, 0, 0), new Vector3(-1, 0, 0), UVList[5], sunLightBR, localLightBR);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(0, 0, 1), new Vector3(-1, 0, 0), UVList[2], sunLightBL, localLightBL);
                AddIndex(0, 1, 3, 0, 3, 2);
            }
            break;

            case BlockFaceDirection.YIncreasing:
            {
                //BL,BR,TR,BL,TR,TL
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(1, 1, 1), new Vector3(0, 1, 0), UVList[4], sunLightTR, localLightTR);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(0, 1, 1), new Vector3(0, 1, 0), UVList[5], sunLightTL, localLightTL);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(1, 1, 0), new Vector3(0, 1, 0), UVList[1], sunLightBR, localLightBR);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(0, 1, 0), new Vector3(0, 1, 0), UVList[3], sunLightBL, localLightBL);
                AddIndex(3, 2, 0, 3, 0, 1);
            }
            break;

            case BlockFaceDirection.YDecreasing:
            {
                //TR,BR,TL,TL,BR,BL
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(1, 0, 1), new Vector3(0, -1, 0), UVList[0], sunLightTR, localLightTR);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(0, 0, 1), new Vector3(0, -1, 0), UVList[2], sunLightTL, localLightTL);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(1, 0, 0), new Vector3(0, -1, 0), UVList[4], sunLightBR, localLightBR);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(0, 0, 0), new Vector3(0, -1, 0), UVList[5], sunLightBL, localLightBL);
                AddIndex(0, 2, 1, 1, 2, 3);
            }
            break;

            case BlockFaceDirection.ZIncreasing:
            {
                //TR,TL,BL,TR,BL,BR
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(0, 1, 1), new Vector3(0, 0, 1), UVList[0], sunLightTR, localLightTR);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(1, 1, 1), new Vector3(0, 0, 1), UVList[1], sunLightTL, localLightTL);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(0, 0, 1), new Vector3(0, 0, 1), UVList[5], sunLightBR, localLightBR);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(1, 0, 1), new Vector3(0, 0, 1), UVList[2], sunLightBL, localLightBL);
                AddIndex(0, 1, 3, 0, 3, 2);
            }
            break;

            case BlockFaceDirection.ZDecreasing:
            {
                //TR,TL,BR,BR,TL,BL
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(1, 1, 0), new Vector3(0, 0, -1), UVList[0], sunLightTR, localLightTR);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(0, 1, 0), new Vector3(0, 0, -1), UVList[1], sunLightTL, localLightTL);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(1, 0, 0), new Vector3(0, 0, -1), UVList[2], sunLightBR, localLightBR);
                AddVertex(blockPosition, chunkRelativePosition, new Vector3(0, 0, 0), new Vector3(0, 0, -1), UVList[5], sunLightBL, localLightBL);
                AddIndex(0, 1, 2, 2, 1, 3);
            }
            break;
            }
        }
Esempio n. 22
0
        private void RenderVertexList(GraphicsDevice graphicsDevice, DynamicVertexBuffer vertexBuffer, Texture2D blockTexture, Color lodColor, bool renderTranslucent, BlockTexture blocktex, float elapsedTime)
        {
            if (vertexBuffer == null)
                return;

            if (blocktex == BlockTexture.Lava || blocktex == BlockTexture.ForceR || blocktex == BlockTexture.ForceB)
            {
                basicEffect.CurrentTechnique = basicEffect.Techniques["LavaBlock"];
                basicEffect.Parameters["xTime"].SetValue(elapsedTime % 5);
            }
            else
            {
                basicEffect.CurrentTechnique = basicEffect.Techniques["Block"];
            }
            basicEffect.Parameters["xWorld"].SetValue(Matrix.Identity);
            basicEffect.Parameters["xView"].SetValue(gameInstance.propertyBag.playerCamera.ViewMatrix);
            basicEffect.Parameters["xProjection"].SetValue(gameInstance.propertyBag.playerCamera.ProjectionMatrix);
            basicEffect.Parameters["xTexture"].SetValue(blockTexture);
            basicEffect.Parameters["xLODColor"].SetValue(new Vector3(0.0f,0.0f,0.0f));//lodColor.ToVector3());
            basicEffect.Parameters["xLight"].SetValue(1.0f);

            basicEffect.Begin();

            foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
            {
                pass.Begin();

                if (renderTranslucent)
                {
                    // TODO: Make translucent blocks look like we actually want them to look!
                    // We probably also want to pull this out to be rendered AFTER EVERYTHING ELSE IN THE GAME.
                    graphicsDevice.RenderState.DepthBufferWriteEnable = false;
                    graphicsDevice.RenderState.AlphaBlendEnable = true;
                    graphicsDevice.RenderState.SourceBlend = Blend.SourceAlpha;
                    graphicsDevice.RenderState.DestinationBlend = Blend.InverseSourceAlpha;
                    graphicsDevice.SamplerStates[0].MagFilter = TextureFilter.Linear;
                }
                else if (blocktex == BlockTexture.GlassR || blocktex == BlockTexture.GlassB || blocktex == BlockTexture.ForceR || blocktex == BlockTexture.ForceB)
                {
                    graphicsDevice.RenderState.AlphaTestEnable = true;
                    graphicsDevice.RenderState.AlphaFunction = CompareFunction.Greater;
                    graphicsDevice.RenderState.ReferenceAlpha = 128;
                    graphicsDevice.SamplerStates[0].MagFilter = TextureFilter.Point;
                }
                else
                {
                    graphicsDevice.SamplerStates[0].MagFilter = TextureFilter.Linear;
                    graphicsDevice.SamplerStates[0].MipFilter = TextureFilter.Anisotropic;//probably leaking over into other textures
                    graphicsDevice.SamplerStates[0].MaxAnisotropy = 4;//probably leaking over into other textures
                }
                graphicsDevice.RenderState.CullMode = CullMode.CullCounterClockwiseFace;
                graphicsDevice.VertexDeclaration = vertexDeclaration;
                graphicsDevice.Vertices[0].SetSource(vertexBuffer, 0, VertexPositionTextureShade.SizeInBytes);
                graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, vertexBuffer.SizeInBytes / VertexPositionTextureShade.SizeInBytes / 3);
                graphicsDevice.RenderState.CullMode = CullMode.None;

                if (renderTranslucent)
                {
                    graphicsDevice.RenderState.DepthBufferWriteEnable = true;
                    graphicsDevice.RenderState.AlphaBlendEnable = false;
                }
                else if (blocktex == BlockTexture.GlassR || blocktex == BlockTexture.GlassB || blocktex == BlockTexture.ForceR || blocktex == BlockTexture.ForceB)
                {
                    graphicsDevice.RenderState.AlphaTestEnable = false;
                }
                pass.End();
            }
            basicEffect.End();
        }
Esempio n. 23
0
        private void BuildFaceVertices(int x, int y, int z, Buffer buffer, ref VertexPositionTextureShade[] vertexArray, BlockFaceDirection faceDir, BlockTexture texture)
        {
            int faceIndex = 0;

            switch (faceDir)
            {
            case BlockFaceDirection.XIncreasing:
                faceIndex = 0;
                break;

            case BlockFaceDirection.XDecreasing:
                faceIndex = 1;
                break;

            case BlockFaceDirection.YIncreasing:
                faceIndex = 2;
                break;

            case BlockFaceDirection.YDecreasing:
                faceIndex = 3;
                break;

            case BlockFaceDirection.ZIncreasing:
                faceIndex = 4;
                break;

            case BlockFaceDirection.ZDecreasing:
                faceIndex = 5;
                break;
            }
            Vector2[] UVList = UVMappings[(int)texture * 6 + faceIndex];
            int       index  = 0;

            switch (buffer)
            {
            case Buffer.Model:
                index = _modelIndex;
                break;

            case Buffer.Solid:
                index = _solidIndex;
                break;

            case Buffer.Water:
                index = _waterIndex;
                break;
            }

            switch (faceDir)
            {
            case BlockFaceDirection.XIncreasing:
            {
                vertexArray[index]     = new VertexPositionTextureShade(new Vector3(x + 1, y + 1, z + 1), UVList[0], _world.Lighting.GetLight(x + 1, y, z) + WorldSettings.SIDESHADOWS);
                vertexArray[index + 1] = new VertexPositionTextureShade(new Vector3(x + 1, y + 1, z), UVList[1], _world.Lighting.GetLight(x + 1, y, z) + WorldSettings.SIDESHADOWS);
                vertexArray[index + 2] = new VertexPositionTextureShade(new Vector3(x + 1, y, z + 1), UVList[2], _world.Lighting.GetLight(x + 1, y, z) + WorldSettings.SIDESHADOWS);
                vertexArray[index + 3] = new VertexPositionTextureShade(new Vector3(x + 1, y, z + 1), UVList[3], _world.Lighting.GetLight(x + 1, y, z) + WorldSettings.SIDESHADOWS);
                vertexArray[index + 4] = new VertexPositionTextureShade(new Vector3(x + 1, y + 1, z), UVList[4], _world.Lighting.GetLight(x + 1, y, z) + WorldSettings.SIDESHADOWS);
                vertexArray[index + 5] = new VertexPositionTextureShade(new Vector3(x + 1, y, z), UVList[5], _world.Lighting.GetLight(x + 1, y, z) + WorldSettings.SIDESHADOWS);
            }
            break;

            case BlockFaceDirection.XDecreasing:
            {
                vertexArray[index]     = new VertexPositionTextureShade(new Vector3(x, y + 1, z), UVList[0], _world.Lighting.GetLight(x - 1, y, z) + WorldSettings.SIDESHADOWS);
                vertexArray[index + 1] = new VertexPositionTextureShade(new Vector3(x, y + 1, z + 1), UVList[1], _world.Lighting.GetLight(x - 1, y, z) + WorldSettings.SIDESHADOWS);
                vertexArray[index + 2] = new VertexPositionTextureShade(new Vector3(x, y, z + 1), UVList[2], _world.Lighting.GetLight(x - 1, y, z) + WorldSettings.SIDESHADOWS);
                vertexArray[index + 3] = new VertexPositionTextureShade(new Vector3(x, y + 1, z), UVList[3], _world.Lighting.GetLight(x - 1, y, z) + WorldSettings.SIDESHADOWS);
                vertexArray[index + 4] = new VertexPositionTextureShade(new Vector3(x, y, z + 1), UVList[4], _world.Lighting.GetLight(x - 1, y, z) + WorldSettings.SIDESHADOWS);
                vertexArray[index + 5] = new VertexPositionTextureShade(new Vector3(x, y, z), UVList[5], _world.Lighting.GetLight(x - 1, y, z) + WorldSettings.SIDESHADOWS);
            }
            break;

            case BlockFaceDirection.YIncreasing:
            {
                vertexArray[index]     = new VertexPositionTextureShade(new Vector3(x, y + 1, z), UVList[0], _world.Lighting.GetLight(x, y + 1, z));
                vertexArray[index + 1] = new VertexPositionTextureShade(new Vector3(x + 1, y + 1, z), UVList[1], _world.Lighting.GetLight(x, y + 1, z));
                vertexArray[index + 2] = new VertexPositionTextureShade(new Vector3(x + 1, y + 1, z + 1), UVList[2], _world.Lighting.GetLight(x, y + 1, z));
                vertexArray[index + 3] = new VertexPositionTextureShade(new Vector3(x, y + 1, z), UVList[3], _world.Lighting.GetLight(x, y + 1, z));
                vertexArray[index + 4] = new VertexPositionTextureShade(new Vector3(x + 1, y + 1, z + 1), UVList[4], _world.Lighting.GetLight(x, y + 1, z));
                vertexArray[index + 5] = new VertexPositionTextureShade(new Vector3(x, y + 1, z + 1), UVList[5], _world.Lighting.GetLight(x, y + 1, z));
            }
            break;

            case BlockFaceDirection.YDecreasing:
            {
                vertexArray[index]     = new VertexPositionTextureShade(new Vector3(x + 1, y, z + 1), UVList[0], _world.Lighting.GetLight(x, y - 1, z) + WorldSettings.SIDESHADOWS);
                vertexArray[index + 1] = new VertexPositionTextureShade(new Vector3(x + 1, y, z), UVList[1], _world.Lighting.GetLight(x, y - 1, z) + WorldSettings.SIDESHADOWS);
                vertexArray[index + 2] = new VertexPositionTextureShade(new Vector3(x, y, z + 1), UVList[2], _world.Lighting.GetLight(x, y - 1, z) + WorldSettings.SIDESHADOWS);
                vertexArray[index + 3] = new VertexPositionTextureShade(new Vector3(x, y, z + 1), UVList[3], _world.Lighting.GetLight(x, y - 1, z) + WorldSettings.SIDESHADOWS);
                vertexArray[index + 4] = new VertexPositionTextureShade(new Vector3(x + 1, y, z), UVList[4], _world.Lighting.GetLight(x, y - 1, z) + WorldSettings.SIDESHADOWS);
                vertexArray[index + 5] = new VertexPositionTextureShade(new Vector3(x, y, z), UVList[5], _world.Lighting.GetLight(x, y - 1, z) + WorldSettings.SIDESHADOWS);
            }
            break;

            case BlockFaceDirection.ZIncreasing:
            {
                vertexArray[index]     = new VertexPositionTextureShade(new Vector3(x, y + 1, z + 1), UVList[0], _world.Lighting.GetLight(x, y, z + 1));
                vertexArray[index + 1] = new VertexPositionTextureShade(new Vector3(x + 1, y + 1, z + 1), UVList[1], _world.Lighting.GetLight(x, y, z + 1));
                vertexArray[index + 2] = new VertexPositionTextureShade(new Vector3(x + 1, y, z + 1), UVList[2], _world.Lighting.GetLight(x, y, z + 1));
                vertexArray[index + 3] = new VertexPositionTextureShade(new Vector3(x, y + 1, z + 1), UVList[3], _world.Lighting.GetLight(x, y, z + 1));
                vertexArray[index + 4] = new VertexPositionTextureShade(new Vector3(x + 1, y, z + 1), UVList[4], _world.Lighting.GetLight(x, y, z + 1));
                vertexArray[index + 5] = new VertexPositionTextureShade(new Vector3(x, y, z + 1), UVList[5], _world.Lighting.GetLight(x, y, z + 1));
            }
            break;

            case BlockFaceDirection.ZDecreasing:
            {
                vertexArray[index]     = new VertexPositionTextureShade(new Vector3(x + 1, y + 1, z), UVList[0], _world.Lighting.GetLight(x, y, z - 1));
                vertexArray[index + 1] = new VertexPositionTextureShade(new Vector3(x, y + 1, z), UVList[1], _world.Lighting.GetLight(x, y, z - 1));
                vertexArray[index + 2] = new VertexPositionTextureShade(new Vector3(x + 1, y, z), UVList[2], _world.Lighting.GetLight(x, y, z - 1));
                vertexArray[index + 3] = new VertexPositionTextureShade(new Vector3(x + 1, y, z), UVList[3], _world.Lighting.GetLight(x, y, z - 1));
                vertexArray[index + 4] = new VertexPositionTextureShade(new Vector3(x, y + 1, z), UVList[4], _world.Lighting.GetLight(x, y, z - 1));
                vertexArray[index + 5] = new VertexPositionTextureShade(new Vector3(x, y, z), UVList[5], _world.Lighting.GetLight(x, y, z - 1));
            }
            break;
            }
            index += 6;
            switch (buffer)
            {
            case Buffer.Model:
                _modelIndex = index;
                break;

            case Buffer.Solid:
                _solidIndex = index;
                break;

            case Buffer.Water:
                _waterIndex = index;
                break;
            }
        }
Esempio n. 24
0
 void Start()
 {
     BlockTexture.Import();
 }