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); }
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; } }
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; } }
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; } }