예제 #1
0
파일: Block.cs 프로젝트: Cyberbanan/voxeliq
 /// <summary>
 /// Return the appropriate texture to render a given face of a block.
 /// </summary>
 /// <param name="blockType"></param>
 /// <param name="faceDir"></param>
 /// <returns></returns>
 public static BlockTexture GetTexture(BlockType blockType, BlockFaceDirection faceDir)
 {
     switch (blockType)
     {
         case BlockType.Brick:
             return BlockTexture.Brick;
         case BlockType.Dirt:
             return BlockTexture.Dirt;
         case BlockType.Gold:
             return BlockTexture.Gold;
         case BlockType.Grass:
             switch (faceDir)
             {
                 case BlockFaceDirection.XIncreasing:
                 case BlockFaceDirection.XDecreasing:
                 case BlockFaceDirection.ZIncreasing:
                 case BlockFaceDirection.ZDecreasing:
                     return BlockTexture.GrassSide;
                 case BlockFaceDirection.YIncreasing:
                     return BlockTexture.GrassTop;
                 case BlockFaceDirection.YDecreasing:
                     return BlockTexture.Dirt;
                 default:
                     return BlockTexture.Rock;
             }
         case BlockType.Iron:
             return BlockTexture.Iron;
         case BlockType.Lava:
             return BlockTexture.Lava;
         case BlockType.Leaves:
             return BlockTexture.Leaves;
         case BlockType.Gravel:
             return BlockTexture.Gravel;
         case BlockType.Rock:
             return BlockTexture.Rock;
         case BlockType.Sand:
             return BlockTexture.Sand;
         case BlockType.Snow:
             return BlockTexture.Snow;
         case BlockType.Tree:
             switch (faceDir)
             {
                 case BlockFaceDirection.XIncreasing:
                 case BlockFaceDirection.XDecreasing:
                 case BlockFaceDirection.ZIncreasing:
                 case BlockFaceDirection.ZDecreasing:
                     return BlockTexture.TreeSide;
                 case BlockFaceDirection.YIncreasing:
                 case BlockFaceDirection.YDecreasing:
                     return BlockTexture.TreeTop;
                 default:
                     return BlockTexture.Rock;
             }
         case BlockType.Water:
             return BlockTexture.Water;
         default:
             return BlockTexture.Rock;
     }
 }
예제 #2
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;
            }
        }
예제 #3
0
        /// <summary>
        /// Calculates uv-mampings for given texture and direction.
        /// </summary>
        /// <param name="textureIndex">The asked texture's texture-index.</param>
        /// <param name="direction">The asked direction.</param>
        /// <returns>Returns list of uv-mappings for given textureIndex and face-direction.</returns>
        private static HalfVector2[] GetBlockTextureMapping(int textureIndex, BlockFaceDirection direction)
        {
            int y = textureIndex/BlockTextureAtlasSize; // y-position for the texture.
            int x = textureIndex%BlockTextureAtlasSize; // x-position for the texture.

            float yOffset = y*UnitBlockTextureOffset; // the unit y-offset.
            float xOffset = x*UnitBlockTextureOffset; // the unit x-offset;

            var mapping = new HalfVector2[6]; // contains texture mapping for the two triangles contained.
            switch (direction)
            {
                case BlockFaceDirection.XIncreasing:
                    mapping[0] = new HalfVector2(xOffset, yOffset); // 0,0 // first triangle.
                    mapping[1] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset); // 1,0
                    mapping[2] = new HalfVector2(xOffset, yOffset + UnitBlockTextureOffset); // 0,1
                    mapping[3] = new HalfVector2(xOffset, yOffset + UnitBlockTextureOffset); // 0,1 // second triangle.
                    mapping[4] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset); // 1,0
                    mapping[5] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset + UnitBlockTextureOffset); // 1,1
                    break;

                case BlockFaceDirection.XDecreasing:
                    mapping[0] = new HalfVector2(xOffset, yOffset); // 0,0
                    mapping[1] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset); // 1,0
                    mapping[2] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset + UnitBlockTextureOffset); // 1,1
                    mapping[3] = new HalfVector2(xOffset, yOffset); // 0,0
                    mapping[4] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset + UnitBlockTextureOffset); // 1,1
                    mapping[5] = new HalfVector2(xOffset, yOffset + UnitBlockTextureOffset); // 0,1
                    break;

                case BlockFaceDirection.YIncreasing:
                    mapping[0] = new HalfVector2(xOffset, yOffset + UnitBlockTextureOffset); // 0,1
                    mapping[1] = new HalfVector2(xOffset, yOffset); // 0,0
                    mapping[2] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset); // 1,0
                    mapping[3] = new HalfVector2(xOffset, yOffset + UnitBlockTextureOffset); // 0,1
                    mapping[4] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset); // 1,0
                    mapping[5] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset + UnitBlockTextureOffset); // 1,1
                    break;

                case BlockFaceDirection.YDecreasing:
                    mapping[0] = new HalfVector2(xOffset, yOffset); // 0,0
                    mapping[1] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset); // 1,0
                    mapping[2] = new HalfVector2(xOffset, yOffset + UnitBlockTextureOffset); // 0,1
                    mapping[3] = new HalfVector2(xOffset, yOffset + UnitBlockTextureOffset); // 0,1
                    mapping[4] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset); // 1,0
                    mapping[5] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset + UnitBlockTextureOffset); // 1,1
                    break;

                case BlockFaceDirection.ZIncreasing:
                    mapping[0] = new HalfVector2(xOffset, yOffset); // 0,0
                    mapping[1] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset); // 1,0
                    mapping[2] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset + UnitBlockTextureOffset); // 1,1
                    mapping[3] = new HalfVector2(xOffset, yOffset); // 0,0
                    mapping[4] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset + UnitBlockTextureOffset); // 1,1
                    mapping[5] = new HalfVector2(xOffset, yOffset + UnitBlockTextureOffset); // 0,1
                    break;

                case BlockFaceDirection.ZDecreasing:
                    mapping[0] = new HalfVector2(xOffset, yOffset); // 0,0
                    mapping[1] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset); // 1,0
                    mapping[2] = new HalfVector2(xOffset, yOffset + UnitBlockTextureOffset); // 0,1
                    mapping[3] = new HalfVector2(xOffset, yOffset + UnitBlockTextureOffset); // 0,1
                    mapping[4] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset); // 1,0
                    mapping[5] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset + UnitBlockTextureOffset); // 1,1
                    break;
            }
            return mapping;
        }
예제 #4
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;
 }
예제 #5
0
 private void DecodeBlockFace(uint faceCode, ref ushort x, ref ushort y, ref ushort z, ref BlockFaceDirection faceDir)
 {
     x = (ushort)(faceCode % MAPSIZE);
     faceCode = (faceCode - x) / MAPSIZE;
     y = (ushort)(faceCode % MAPSIZE);
     faceCode = (faceCode - y) / MAPSIZE;
     z = (ushort)(faceCode % MAPSIZE);
     faceCode = (faceCode - z) / MAPSIZE;
     faceDir = (BlockFaceDirection)faceCode;
 }
예제 #6
0
 private uint EncodeBlockFace(ushort x, ushort y, ushort z, BlockFaceDirection faceDir)
 {
     //TODO: OPTIMIZE BY HARD CODING VALUES IN
     return (uint)(x + y * MAPSIZE + z * MAPSIZE * MAPSIZE + (byte)faceDir * MAPSIZE * MAPSIZE * MAPSIZE);
 }
예제 #7
0
 private void _RemoveBlock(ushort x, ushort y, ushort z, BlockFaceDirection dir, int x2, int y2, int z2, BlockFaceDirection dir2)
 {
     BlockType type = blockList[x, y, z];
     BlockType type2 = blockList[x2, y2, z2];
     if (type2 != BlockType.None && type != BlockType.TransRed && type != BlockType.TransBlue && type2 != BlockType.TransRed && type2 != BlockType.TransBlue)
         ShowQuad((ushort)x2, (ushort)y2, (ushort)z2, dir2, type2);
     else
         HideQuad(x, y, z, dir, type);
 }
예제 #8
0
        public static BlockTexture GetTexture(BlockType blockType, BlockFaceDirection faceDir, BlockType blockAbove)
        {
            switch (blockType)
            {
                case BlockType.Metal:
                    return BlockTexture.Metal;
                case BlockType.Dirt:
                    return BlockTexture.Dirt;
                case BlockType.Lava:
                    return BlockTexture.Lava;
                case BlockType.Rock:
                    return BlockTexture.Rock;
                case BlockType.Ore:
                    return BlockTexture.Ore;
                case BlockType.Gold:
                    return BlockTexture.Gold;
                case BlockType.Diamond:
                    return BlockTexture.Diamond;
                case BlockType.DirtSign:
                    return BlockTexture.DirtSign;

                case BlockType.BankRed:
                    switch (faceDir)
                    {
                        case BlockFaceDirection.XIncreasing: return BlockTexture.BankFrontRed;
                        case BlockFaceDirection.XDecreasing: return BlockTexture.BankBackRed;
                        case BlockFaceDirection.ZIncreasing: return BlockTexture.BankLeftRed;
                        case BlockFaceDirection.ZDecreasing: return BlockTexture.BankRightRed;
                        default: return BlockTexture.BankTopRed;
                    }

                case BlockType.BankBlue:
                    switch (faceDir)
                    {
                        case BlockFaceDirection.XIncreasing: return BlockTexture.BankFrontBlue;
                        case BlockFaceDirection.XDecreasing: return BlockTexture.BankBackBlue;
                        case BlockFaceDirection.ZIncreasing: return BlockTexture.BankLeftBlue;
                        case BlockFaceDirection.ZDecreasing: return BlockTexture.BankRightBlue;
                        default: return BlockTexture.BankTopBlue;
                    }

                case BlockType.BeaconRed:
                case BlockType.BeaconBlue:
                    switch (faceDir)
                    {
                        case BlockFaceDirection.YDecreasing:
                            return BlockTexture.LadderTop;
                        case BlockFaceDirection.YIncreasing:
                            return blockType == BlockType.BeaconRed ? BlockTexture.BeaconRed : BlockTexture.BeaconBlue;
                        case BlockFaceDirection.XDecreasing:
                        case BlockFaceDirection.XIncreasing:
                            return BlockTexture.TeleSideA;
                        case BlockFaceDirection.ZDecreasing:
                        case BlockFaceDirection.ZIncreasing:
                            return BlockTexture.TeleSideB;
                    }
                    break;

                case BlockType.Road:
                    if (faceDir == BlockFaceDirection.YIncreasing)
                        return BlockTexture.RoadTop;
                    else if (faceDir == BlockFaceDirection.YDecreasing||blockAbove!=BlockType.None) //Looks better but won't work with current graphics setup...
                        return BlockTexture.RoadBottom;
                    return BlockTexture.Road;

                case BlockType.Shock:
                    switch (faceDir)
                    {
                        case BlockFaceDirection.YDecreasing:
                            return BlockTexture.Spikes;
                        case BlockFaceDirection.YIncreasing:
                            return BlockTexture.TeleBottom;
                        case BlockFaceDirection.XDecreasing:
                        case BlockFaceDirection.XIncreasing:
                            return BlockTexture.TeleSideA;
                        case BlockFaceDirection.ZDecreasing:
                        case BlockFaceDirection.ZIncreasing:
                            return BlockTexture.TeleSideB;
                    }
                    break;

                case BlockType.Jump:
                    switch (faceDir)
                    {
                        case BlockFaceDirection.YDecreasing:
                            return BlockTexture.TeleBottom;
                        case BlockFaceDirection.YIncreasing:
                            return BlockTexture.JumpTop;
                        case BlockFaceDirection.XDecreasing:
                        case BlockFaceDirection.XIncreasing:
                            return BlockTexture.Jump;
                        case BlockFaceDirection.ZDecreasing:
                        case BlockFaceDirection.ZIncreasing:
                            return BlockTexture.Jump;
                    }
                    break;

                case BlockType.SolidRed:
                    return BlockTexture.SolidRed;
                case BlockType.SolidBlue:
                    return BlockTexture.SolidBlue;
                case BlockType.TransRed:
                    return BlockTexture.TransRed;
                case BlockType.TransBlue:
                    return BlockTexture.TransBlue;

                case BlockType.Ladder:
                    if (faceDir == BlockFaceDirection.YDecreasing || faceDir == BlockFaceDirection.YIncreasing)
                        return BlockTexture.LadderTop;
                    else
                        return BlockTexture.Ladder;

                case BlockType.Explosive:
                    return BlockTexture.Explosive;
            }

            return BlockTexture.None;
        }
예제 #9
0
 public static BlockTexture GetTexture(BlockType blockType, BlockFaceDirection faceDir)
 {
     return GetTexture(blockType, faceDir, BlockType.None);
 }
예제 #10
0
        public static BlockTexture GetTexture(BlockType blockType, BlockFaceDirection faceDir, BlockType blockAbove)
        {
            switch (blockType)
            {
                case BlockType.Generator:
                    return BlockTexture.Generator;
                case BlockType.Controller:
                    return BlockTexture.Controller;
                case BlockType.Pump:
                    return BlockTexture.Pump;
                case BlockType.Barrel:
                    switch (faceDir)
                    {
                        case BlockFaceDirection.XIncreasing: return BlockTexture.Barrel;
                        case BlockFaceDirection.XDecreasing: return BlockTexture.Barrel;
                        case BlockFaceDirection.ZIncreasing: return BlockTexture.Barrel;
                        case BlockFaceDirection.ZDecreasing: return BlockTexture.Barrel;
                        case BlockFaceDirection.YDecreasing: return BlockTexture.LadderTop;
                        default: return BlockTexture.BarrelTop;
                    }
                case BlockType.Hinge:
                    return BlockTexture.Hinge;
                case BlockType.Pipe:
                    return BlockTexture.Pipe;
                case BlockType.Metal:
                    return BlockTexture.Metal;
                case BlockType.Dirt:
                    return BlockTexture.Dirt;
                case BlockType.Mud:
                    return BlockTexture.Mud;
                case BlockType.Grass:
                    switch (faceDir)
                    {
                        case BlockFaceDirection.XIncreasing: return BlockTexture.GrassSide;
                        case BlockFaceDirection.XDecreasing: return BlockTexture.GrassSide;
                        case BlockFaceDirection.ZIncreasing: return BlockTexture.GrassSide;
                        case BlockFaceDirection.ZDecreasing: return BlockTexture.GrassSide;
                        case BlockFaceDirection.YDecreasing: return BlockTexture.Dirt;
                        default: return BlockTexture.Grass;
                    }
                case BlockType.Sand:
                    return BlockTexture.Sand;
                case BlockType.Lava:
                    return BlockTexture.Lava;
                case BlockType.Water:
                    return BlockTexture.Water;
                case BlockType.Rock:
                    return BlockTexture.Rock;
                case BlockType.Spring:
                    return BlockTexture.Spring;
                case BlockType.MagmaVent:
                    return BlockTexture.MagmaVent;
                case BlockType.MagmaBurst:
                    return BlockTexture.MagmaBurst;
                case BlockType.Fire:
                    return BlockTexture.Fire;
                case BlockType.Ore:
                    return BlockTexture.Ore;
                case BlockType.Gold:
                    return BlockTexture.Gold;
                case BlockType.Diamond:
                    return BlockTexture.Diamond;
                case BlockType.Lever:
                    return BlockTexture.Lever;
                case BlockType.Plate:
                    return BlockTexture.Lever;
                case BlockType.DirtSign:
                    return BlockTexture.DirtSign;
                case BlockType.Magma:
                    return BlockTexture.Magma;
                case BlockType.StealthBlockR:
                    return BlockTexture.StealthBlockR;
                case BlockType.StealthBlockB:
                    return BlockTexture.StealthBlockB;
                case BlockType.TrapB:
                    return BlockTexture.TrapB;
                case BlockType.TrapR:
                   return BlockTexture.TrapR;
                case BlockType.ConstructionR:
                case BlockType.ConstructionB:
                   return BlockTexture.Construction;
                case BlockType.GlassR:
                   return BlockTexture.GlassR;
                case BlockType.GlassB:
                   return BlockTexture.GlassB;
                case BlockType.ForceR:
                   return BlockTexture.ForceR;
                case BlockType.ForceB:
                   return BlockTexture.ForceB;
                case BlockType.ArtCaseR:
                   switch (faceDir)
                   {
                       case BlockFaceDirection.XIncreasing: return BlockTexture.ArtCaseR;
                       case BlockFaceDirection.XDecreasing: return BlockTexture.BankBackRed;
                       case BlockFaceDirection.ZIncreasing: return BlockTexture.BankLeftRed;
                       case BlockFaceDirection.ZDecreasing: return BlockTexture.BankRightRed;
                       default: return BlockTexture.BankTopRed;
                   }
                case BlockType.ArtCaseB:
                   switch (faceDir)
                   {
                       case BlockFaceDirection.XIncreasing: return BlockTexture.ArtCaseB;
                       case BlockFaceDirection.XDecreasing: return BlockTexture.BankBackBlue;
                       case BlockFaceDirection.ZIncreasing: return BlockTexture.BankLeftBlue;
                       case BlockFaceDirection.ZDecreasing: return BlockTexture.BankRightBlue;
                       default: return BlockTexture.BankTopBlue;
                   }
                case BlockType.BankRed:
                    switch (faceDir)
                    {
                        case BlockFaceDirection.XIncreasing: return BlockTexture.BankFrontRed;
                        case BlockFaceDirection.XDecreasing: return BlockTexture.BankBackRed;
                        case BlockFaceDirection.ZIncreasing: return BlockTexture.BankLeftRed;
                        case BlockFaceDirection.ZDecreasing: return BlockTexture.BankRightRed;
                        default: return BlockTexture.BankTopRed;
                    }

                case BlockType.BankBlue:
                    switch (faceDir)
                    {
                        case BlockFaceDirection.XIncreasing: return BlockTexture.BankFrontBlue;
                        case BlockFaceDirection.XDecreasing: return BlockTexture.BankBackBlue;
                        case BlockFaceDirection.ZIncreasing: return BlockTexture.BankLeftBlue;
                        case BlockFaceDirection.ZDecreasing: return BlockTexture.BankRightBlue;
                        default: return BlockTexture.BankTopBlue;
                    }

                case BlockType.BaseRed:
                    switch (faceDir)
                    {
                        case BlockFaceDirection.XIncreasing: return BlockTexture.Forge;
                        case BlockFaceDirection.XDecreasing: return BlockTexture.ForgeSide;
                        case BlockFaceDirection.ZIncreasing: return BlockTexture.ForgeSide;
                        case BlockFaceDirection.ZDecreasing: return BlockTexture.ForgeSide;
                        default: return BlockTexture.BankTopRed;
                    }

                case BlockType.BaseBlue:
                    switch (faceDir)
                    {
                        case BlockFaceDirection.XIncreasing: return BlockTexture.Forge;
                        case BlockFaceDirection.XDecreasing: return BlockTexture.BankBackBlue;
                        case BlockFaceDirection.ZIncreasing: return BlockTexture.BankLeftBlue;
                        case BlockFaceDirection.ZDecreasing: return BlockTexture.BankRightBlue;
                        default: return BlockTexture.BankTopBlue;
                    }

                case BlockType.RadarRed:
                case BlockType.RadarBlue:
                    switch (faceDir)
                    {
                        case BlockFaceDirection.YDecreasing:
                            return BlockTexture.LadderTop;
                        case BlockFaceDirection.YIncreasing:
                            return blockType == BlockType.RadarRed ? BlockTexture.BeaconRed : BlockTexture.BeaconBlue;
                        case BlockFaceDirection.XDecreasing:
                        case BlockFaceDirection.XIncreasing:
                            return BlockTexture.TeleSideA;
                        case BlockFaceDirection.ZDecreasing:
                        case BlockFaceDirection.ZIncreasing:
                            return BlockTexture.TeleSideB;
                    }
                    break;

                case BlockType.ResearchR:
                case BlockType.ResearchB:
                    switch (faceDir)
                    {
                        case BlockFaceDirection.YDecreasing:
                            return BlockTexture.LadderTop;
                        case BlockFaceDirection.YIncreasing:
                            return blockType == BlockType.ResearchR ? BlockTexture.BeaconRed : BlockTexture.BeaconBlue;
                        case BlockFaceDirection.XDecreasing:
                        case BlockFaceDirection.XIncreasing:
                            return BlockTexture.TeleSideA;
                        case BlockFaceDirection.ZDecreasing:
                        case BlockFaceDirection.ZIncreasing:
                            return BlockTexture.TeleSideB;
                    }
                    break;

                case BlockType.BeaconRed:
                case BlockType.BeaconBlue:
                    switch (faceDir)
                    {
                        case BlockFaceDirection.YDecreasing:
                            return BlockTexture.LadderTop;
                        case BlockFaceDirection.YIncreasing:
                            return blockType == BlockType.BeaconRed ? BlockTexture.BeaconRed : BlockTexture.BeaconBlue;
                        case BlockFaceDirection.XDecreasing:
                        case BlockFaceDirection.XIncreasing:
                            return BlockTexture.TeleSideA;
                        case BlockFaceDirection.ZDecreasing:
                        case BlockFaceDirection.ZIncreasing:
                            return BlockTexture.TeleSideB;
                    }
                    break;

                case BlockType.Road:
                    if (faceDir == BlockFaceDirection.YIncreasing)
                        return BlockTexture.RoadTop;
                    else if (faceDir == BlockFaceDirection.YDecreasing||blockAbove!=BlockType.None) //Looks better but won't work with current graphics setup...
                        return BlockTexture.RoadBottom;
                    return BlockTexture.Road;

                case BlockType.Shock:
                    switch (faceDir)
                    {
                        case BlockFaceDirection.YDecreasing:
                            return BlockTexture.Spikes;
                        case BlockFaceDirection.YIncreasing:
                            return BlockTexture.TeleBottom;
                        case BlockFaceDirection.XDecreasing:
                        case BlockFaceDirection.XIncreasing:
                            return BlockTexture.TeleSideA;
                        case BlockFaceDirection.ZDecreasing:
                        case BlockFaceDirection.ZIncreasing:
                            return BlockTexture.TeleSideB;
                    }
                    break;

                case BlockType.Jump:
                    switch (faceDir)
                    {
                        case BlockFaceDirection.YDecreasing:
                            return BlockTexture.TeleBottom;
                        case BlockFaceDirection.YIncreasing:
                            return BlockTexture.JumpTop;
                        case BlockFaceDirection.XDecreasing:
                        case BlockFaceDirection.XIncreasing:
                            return BlockTexture.Jump;
                        case BlockFaceDirection.ZDecreasing:
                        case BlockFaceDirection.ZIncreasing:
                            return BlockTexture.Jump;
                    }
                    break;
                case BlockType.SolidRed:
                    return BlockTexture.SolidRed;
                case BlockType.SolidBlue:
                    return BlockTexture.SolidBlue;
                case BlockType.SolidRed2:
                    return BlockTexture.SolidRed2;
                case BlockType.SolidBlue2:
                    return BlockTexture.SolidBlue2;
                case BlockType.TransRed:
                    return BlockTexture.TransRed;
                case BlockType.TransBlue:
                    return BlockTexture.TransBlue;

                case BlockType.Ladder:
                    if (faceDir == BlockFaceDirection.YDecreasing || faceDir == BlockFaceDirection.YIncreasing)
                        return BlockTexture.LadderTop;
                    else
                        return BlockTexture.Ladder;

                case BlockType.Explosive:
                    return BlockTexture.Explosive;
            }

            return BlockTexture.None;
        }
예제 #11
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;
            }
        }
예제 #12
0
 private void _RemoveBlock(ushort x, ushort y, ushort z, BlockFaceDirection dir, int x2, int y2, int z2, BlockFaceDirection dir2)
 {
     BlockType type = blockList[x, y, z];
     BlockType type2 = blockList[x2, y2, z2];
     if (type2 != BlockType.None && type2 != BlockType.GlassR && type2 != BlockType.GlassB && type2 != BlockType.ForceR && type2 != BlockType.ForceB && type != BlockType.GlassR && type != BlockType.GlassB && type != BlockType.ForceR && type != BlockType.ForceB && type2 != BlockType.TrapB && type != BlockType.TrapB && type != BlockType.TrapR && type2 != BlockType.TrapR && type != BlockType.TransRed && type != BlockType.TransBlue && type != BlockType.Water && type != BlockType.StealthBlockB && type != BlockType.StealthBlockR && type2 != BlockType.TransRed && type2 != BlockType.TransBlue && type2 != BlockType.Water && type2 != BlockType.StealthBlockB && type2 != BlockType.StealthBlockR)
         ShowQuad((ushort)x2, (ushort)y2, (ushort)z2, dir2, type2);
     else
         HideQuad(x, y, z, dir, type);
 }