public static Texture2D GenerateWallTexture(WallTextureData textureData, Dictionary <string, SpriteData> patches, PaletteData paletteData) { Texture2D spriteTexture = new Texture2D(textureData.Width, textureData.Height, TextureFormat.ARGB32, true); // Make it all alpha=0 to start with spriteTexture.SetPixels(new Color[textureData.Width * textureData.Height]); foreach (var patch in textureData.Patches) { var sprite = GenerateSprite(patches[patch.PatchName], paletteData); var w = sprite.width; var h = sprite.height; var sl = 0; var st = 0; if (patch.XOffset < 0) { patch.XOffset = 0; sl -= patch.XOffset; w += patch.XOffset; } if (patch.XOffset + w > textureData.Width) { w = w - ((patch.XOffset + w) - textureData.Width); } if (patch.YOffset < 0) { patch.YOffset = 0; st -= patch.YOffset; h += patch.YOffset; } if (patch.YOffset + h > textureData.Height) { h = h - ((patch.YOffset + h) - textureData.Height); } var dl = patch.XOffset; var dt = ((textureData.Height) - patch.YOffset) - h; var data = sprite.GetPixels(sl, st, w, h); // We need to do this per-pixel so we can do alpha cutout for (var x = 0; x < w; x++) { for (var y = 0; y < h; y++) { if (data[x + (y * w)].a > 0) { spriteTexture.SetPixel(dl + x, dt + y, data[x + (y * w)]); } } } } spriteTexture.Apply(); return(spriteTexture); }
// Get a dictionary of wall patches based on the patch names listed in the wall texture data public static Dictionary <string, SpriteData> GetWallPatches(FileStream wadStream, WADInfo wadInfo, WallTextureData textureData) { var sprites = new Dictionary <string, SpriteData>(); foreach (var patch in textureData.Patches) { if (!sprites.ContainsKey(patch.PatchName)) { sprites.Add(patch.PatchName, GetPictureSprite(wadStream, wadInfo.EntryDictionary[patch.PatchName])); } } return(sprites); }