コード例 #1
0
        void GetBlockData(int x, int y, int z, BlockID B, BlockFace F)
        {
            B.GetFaceVerts(x, y, z, F, Mesh, MeshT);
            B.GetFaceUVs(F, Atlas, UVs, UVsT);

            if (B.IsTransparent())
            {
                for (int i = 0; i < 4; i++)
                {
                    ClrsT.Add(new Vector3(1, 1, 1));
                }
            }
            else
            {
                Sides++;
            }

            Vector3 Normal;

            if (F == BlockFace.Forward)
            {
                Normal = new Vector3(1, 0, 0);
            }
            else if (F == BlockFace.Backward)
            {
                Normal = new Vector3(-1, 0, 0);
            }
            else if (F == BlockFace.Left)
            {
                Normal = new Vector3(0, 1, 0);
            }
            else if (F == BlockFace.Right)
            {
                Normal = new Vector3(0, -1, 0);
            }
            else if (F == BlockFace.Top)
            {
                Normal = new Vector3(0, 0, 1);
            }
            else
            {
                Normal = new Vector3(0, 0, -1);
            }

            List <Vector4> Lst = B.IsTransparent() == false ? BlockData : BlockDataT;

            Lst.Add(new Vector4(Normal, (int)B));
            Lst.Add(new Vector4(Normal, (int)B));
            Lst.Add(new Vector4(Normal, (int)B));
            Lst.Add(new Vector4(Normal, (int)B));
        }
コード例 #2
0
        // Thrown together fast, this REALLY REALLY needs a rewrite, not even i write this shitcode
        void Rebuild()
        {
            Mesh.Clear();
            UVs.Clear();
            Clrs.Clear();
            MeshT.Clear();
            UVsT.Clear();
            ClrsT.Clear();
            BlockData.Clear();
            BlockDataT.Clear();

            for (int x = 0; x < Size; x++)
            {
                for (int y = 0; y < Size; y++)
                {
                    for (int z = 0; z < Size; z++)
                    {
                        BlockID CurBlock = GetBlock(x, y, z);
                        if (CurBlock.IsTransparent())
                        {
                            BlockID B;
                            Sides = 0;

                            if ((B = GetBlock(x, y, z - 1)) != CurBlock)
                            {
                                if (B != BlockID.Air)
                                {
                                    GetBlockData(x, y, z - 1, B, BlockFace.Top);
                                }
                            }
                            if ((B = GetBlock(x, y, z + 1)) != CurBlock)
                            {
                                if (B != BlockID.Air)
                                {
                                    GetBlockData(x, y, z + 1, B, BlockFace.Bottom);
                                }
                            }
                            if ((B = GetBlock(x - 1, y, z)) != CurBlock)
                            {
                                if (B != BlockID.Air)
                                {
                                    GetBlockData(x - 1, y, z, B, BlockFace.Forward);
                                }
                            }
                            if ((B = GetBlock(x + 1, y, z)) != CurBlock)
                            {
                                if (B != BlockID.Air)
                                {
                                    GetBlockData(x + 1, y, z, B, BlockFace.Backward);
                                }
                            }
                            if ((B = GetBlock(x, y - 1, z)) != CurBlock)
                            {
                                if (B != BlockID.Air)
                                {
                                    GetBlockData(x, y - 1, z, B, BlockFace.Left);
                                }
                            }
                            if ((B = GetBlock(x, y + 1, z)) != CurBlock)
                            {
                                if (B != BlockID.Air)
                                {
                                    GetBlockData(x, y + 1, z, B, BlockFace.Right);
                                }
                            }

                            float S = 1f - Sides * 0.095f;
                            for (int i = 0; i < Sides * 4; i++)
                            {
                                Clrs.Add(new Vector3(S, S, S));
                            }
                        }
                    }
                }
            }

            VDDirty = true;
            Dirty   = false;
        }
コード例 #3
0
        public static void GetFaceVerts(this BlockID B, int lx, int ly, int lz, BlockFace F, List <Vector3> Opaque,
                                        List <Vector3> Trans)
        {
            float x = lx * Block.Size;
            float y = ly * Block.Size;
            float z = lz * Block.Size;

            List <Vector3> L = B.IsTransparent() ? Trans : Opaque;

            switch (F)
            {
            case BlockFace.Forward:
                L.AddRange(new Vector3[] {
                    new Vector3(x + Block.Size, y, z),
                    new Vector3(x + Block.Size, y + Block.Size, z),
                    new Vector3(x + Block.Size, y + Block.Size, z + Block.Size),
                    new Vector3(x + Block.Size, y, z + Block.Size)
                });
                return;

            case BlockFace.Backward:
                L.AddRange(new Vector3[] {
                    new Vector3(x, y, z + Block.Size),
                    new Vector3(x, y + Block.Size, z + Block.Size),
                    new Vector3(x, y + Block.Size, z),
                    new Vector3(x, y, z)
                });
                return;

            case BlockFace.Left:
                L.AddRange(new Vector3[] {
                    new Vector3(x, y + Block.Size, z + Block.Size),
                    new Vector3(x + Block.Size, y + Block.Size, z + Block.Size),
                    new Vector3(x + Block.Size, y + Block.Size, z),
                    new Vector3(x, y + Block.Size, z)
                });
                return;

            case BlockFace.Right:
                L.AddRange(new Vector3[] {
                    new Vector3(x, y, z),
                    new Vector3(x + Block.Size, y, z),
                    new Vector3(x + Block.Size, y, z + Block.Size),
                    new Vector3(x, y, z + Block.Size)
                });
                return;

            case BlockFace.Top:
                L.AddRange(new Vector3[] {
                    new Vector3(x, y, z + Block.Size),
                    new Vector3(x + Block.Size, y, z + Block.Size),
                    new Vector3(x + Block.Size, y + Block.Size, z + Block.Size),
                    new Vector3(x, y + Block.Size, z + Block.Size)
                });
                return;

            case BlockFace.Bottom:
                L.AddRange(new Vector3[] {
                    new Vector3(x, y + Block.Size, z),
                    new Vector3(x + Block.Size, y + Block.Size, z),
                    new Vector3(x + Block.Size, y, z),
                    new Vector3(x, y, z)
                });
                return;
            }

            throw new Exception("Unreachable code reached");
        }
コード例 #4
0
        public static void GetFaceUVs(this BlockID B, BlockFace F, Texture Tx, List <Vector2> Opaque, List <Vector2> Trans)
        {
            float TexSize = 1f / 6f * Tx.W;
            float w       = 1f / ((float)Tx.W / TexSize);
            float h       = 1f / ((float)Tx.H / TexSize);

            float x = 0;
            float y = h * B.GetTexID();

            Vector2[]      R;
            List <Vector2> L = B.IsTransparent() ? Trans : Opaque;

            switch (F)
            {
            case BlockFace.Forward:
                R = new Vector2[] {
                    new Vector2(x + w * 2, y + h),
                    new Vector2(x + w * 3, y + h),
                    new Vector2(x + w * 3, y),
                    new Vector2(x + w * 2, y),
                };
                break;

            case BlockFace.Backward:
                R = new Vector2[] {
                    new Vector2(x + w * 5, y),
                    new Vector2(x + w * 4, y),
                    new Vector2(x + w * 4, y + h),
                    new Vector2(x + w * 5, y + h),
                };
                break;

            case BlockFace.Left:
                R = new Vector2[] {
                    new Vector2(x + w * 6, y),
                    new Vector2(x + w * 5, y),
                    new Vector2(x + w * 5, y + h),
                    new Vector2(x + w * 6, y + h),
                };
                break;

            case BlockFace.Right:
                R = new Vector2[] {
                    new Vector2(x + w * 3, y + h),
                    new Vector2(x + w * 4, y + h),
                    new Vector2(x + w * 4, y),
                    new Vector2(x + w * 3, y),
                };
                break;

            case BlockFace.Top:
                R = new Vector2[] {
                    new Vector2(x, y),
                    new Vector2(x, y + h),
                    new Vector2(x + w, y + h),
                    new Vector2(x + w, y),
                };
                break;

            case BlockFace.Bottom:
                R = new Vector2[] {
                    new Vector2(x + w, y),
                    new Vector2(x + w, y + h),
                    new Vector2(x + w * 2, y + h),
                    new Vector2(x + w * 2, y),
                };
                break;

            default:
                throw new Exception("Unknown block face");
            }
            L.AddRange(R);
        }