private void writeChapterThumbnails() { string filePath = modPath + "\\materials\\vgui\\chapters"; for (int i = 0; i < chapters.Count; i++) { if (chapters[i].thumbnailFile == null) { chapters[i].thumbnailFile = VTF.FromBitmap(chapters[i].thumbnail, launcher); } if (chapters[i].thumbnailFile != null) { Directory.CreateDirectory(filePath); File.WriteAllBytes(filePath + "\\chapter" + (i + 1) + ".vtf", chapters[i].thumbnailFile); KeyValue root = new KeyValue("UnlitGeneric"); root.addChild(new KeyValue("$basetexture", "VGUI/chapters/chapter" + (i + 1))); root.addChild(new KeyValue("$vertexalpha", "1")); SourceSDK.KeyValue .writeChunkFile(filePath + "\\chapter" + (i + 1) + ".vmt", root, false, new UTF8Encoding(false)); } } }
private void CreateToolTexture() { Bitmap basetexture = textures["basetexture"].bitmap; Bitmap basetexture2 = textures["basetexture2"].bitmap; if (basetexture == null) { textures["tooltexture"].bitmap = null; textures["tooltexture"].bytes = null; textures["tooltexture"].relativePath = string.Empty; } if (basetexture != null && basetexture2 == null) { textures["tooltexture"].bitmap = basetexture; textures["tooltexture"].bytes = textures["basetexture"].bytes; textures["tooltexture"].relativePath = string.Empty; } else if (basetexture != null && basetexture2 != null) { Bitmap tooltexture = null; // Resize images int width = basetexture.Width; int height = basetexture.Height; // Merge images tooltexture = new Bitmap(width, height); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { Color baseColor = basetexture.GetPixel(i, j); Color baseColor2 = basetexture2.GetPixel(i, j); float baseMultiply = Math.Min(Math.Max(2.5f - (float)(i + j) / (width + height) * 4, 0), 1); float baseMultiply2 = 1 - baseMultiply; Color toolColor = Color.FromArgb((int)(baseColor.R * baseMultiply + baseColor2.R * baseMultiply2), (int)(baseColor.G * baseMultiply + baseColor2.G * baseMultiply2), (int)(baseColor.B * baseMultiply + baseColor2.B * baseMultiply2)); tooltexture.SetPixel(i, j, toolColor); } } textures["tooltexture"].bitmap = tooltexture; textures["tooltexture"].bytes = VTF.FromBitmap(tooltexture, launcher); textures["tooltexture"].relativePath = string.Empty; } pictureToolTexture.Image = textures["tooltexture"].bitmap; // TODO CALLBACK //updatePreview(); }
private void writeChapterThumbnail(int i) { // Crop image Bitmap src = chapters[i].thumbnail; Bitmap target = new Bitmap(256, 128); using (Graphics gfx = Graphics.FromImage(target)) { gfx.Clear(Color.Black); gfx.DrawImage(src, new Rectangle(0, 0, src.Width, src.Height), new Rectangle(0, 0, src.Width, src.Height), GraphicsUnit.Pixel); } chapters[i].thumbnailFile = VTF.FromBitmap(target, launcher); }
private void writeBackgroundImages() { string filePath = modPath + "\\materials\\console"; for (int i = 0; i < chapters.Count; i++) { if (chapters[i].backgroundImageFile == null) { chapters[i].backgroundImageFile = VTF.FromBitmap(chapters[i].backgroundImage, launcher); } if (chapters[i].backgroundImageWideFile == null) { chapters[i].backgroundImageWideFile = VTF.FromBitmap(chapters[i].backgroundImageWide, launcher); } if (chapters[i].backgroundImageFile != null && chapters[i].backgroundImageWideFile != null) { Directory.CreateDirectory(filePath); File.WriteAllBytes(filePath + "\\" + chapters[i].background + ".vtf", chapters[i].backgroundImageFile); File.WriteAllBytes(filePath + "\\" + chapters[i].background + "_widescreen.vtf", chapters[i].backgroundImageWideFile); KeyValue root = new KeyValue("UnlitGeneric"); root.addChild(new KeyValue("$basetexture", "console/" + chapters[i].background)); root.addChild(new KeyValue("$vertexcolor", "1")); root.addChild(new KeyValue("$vertexalpha", "1")); root.addChild(new KeyValue("$ignorez", "1")); root.addChild(new KeyValue("$no_fullbright", "1")); root.addChild(new KeyValue("$nolod", "1")); SourceSDK.KeyValue .writeChunkFile(filePath + "\\" + chapters[i].background + ".vmt", root, false, new UTF8Encoding(false)); root.getChildByKey("$basetexture").setValue("console/" + chapters[i].background + "_widescreen"); SourceSDK.KeyValue .writeChunkFile(filePath + "\\" + chapters[i].background + "_widescreen.vmt", root, false, new UTF8Encoding(false)); } } }
private void writeBackgroundImageWide(int i) { // Crop image Bitmap src = chapters[i].backgroundImageWide; Bitmap target = new Bitmap(1024, 1024); using (Graphics gfx = Graphics.FromImage(target)) { gfx.Clear(Color.Black); gfx.DrawImage(src, new Rectangle(0, 0, target.Width, target.Height), new Rectangle(0, 0, src.Width, src.Height), GraphicsUnit.Pixel); } chapters[i].backgroundImageWideFile = VTF.FromBitmap(target, launcher); }
private void LoadTexture(PictureEdit pictureEdit) { string tag = pictureEdit.Tag.ToString(); int width = textureWidth; int height = textureHeight; if (openBitmapFileDialog.ShowDialog() == DialogResult.OK) { string type = new FileInfo(openBitmapFileDialog.FileName).Extension; string modPath = launcher.GetCurrentMod().installPath; Uri path1 = new Uri(modPath + "\\"); Uri path2 = new Uri(openBitmapFileDialog.FileName); Uri diff = path1.MakeRelativeUri(path2); if (type == ".vtf") { textures[tag].relativePath = diff.OriginalString; textures[tag].bytes = File.ReadAllBytes(openBitmapFileDialog.FileName); textures[tag].bitmap = VTF.ToBitmap(textures[tag].bytes, launcher); } else { textures[tag].relativePath = string.Empty; textures[tag].bitmap = new Bitmap(Bitmap.FromFile(openBitmapFileDialog.FileName), width, height); textures[tag].bytes = VTF.FromBitmap(textures[tag].bitmap, launcher); } if (textures[tag].bitmap != null) { pictureEdit.Image = textures[tag].bitmap; } } CreateToolTexture(); }
public void SaveMaterial(string path, string shader) { SourceSDK.KeyValue vmt = new SourceSDK.KeyValue(shader); string relativePath = path; string fullPath = (launcher.GetCurrentMod().installPath + "\\materials\\" + relativePath).Replace("/", "\\"); Directory.CreateDirectory(fullPath.Substring(0, fullPath.LastIndexOf("\\"))); bool hasNormalMap = false; bool hasSpecularMap = false; foreach (KeyValuePair <string, Texture> texture in textures) { if (texture.Value.bitmap != null) { switch (texture.Key) { case "tooltexture": if (texture.Value.bytes == textures["basetexture"].bytes) { vmt.addChild(new KeyValue("$" + texture.Key, relativePath + "_basetexture")); } else { vmt.addChild(new KeyValue("$" + texture.Key, relativePath + "_" + texture.Key)); File.WriteAllBytes(fullPath + "_" + texture.Key + ".vtf", texture.Value.bytes); } break; case "envmapmask": hasSpecularMap = true; break; case "bumpmap": hasNormalMap = true; break; default: vmt.addChild(new KeyValue("$" + texture.Key, relativePath + "_" + texture.Key)); File.WriteAllBytes(fullPath + "_" + texture.Key + ".vtf", texture.Value.bytes); break; } } } if (hasNormalMap && hasSpecularMap) { Bitmap normalBitmap = textures["bumpmap"].bitmap; Bitmap specularBitmap = new Bitmap(textures["envmapmask"].bitmap, normalBitmap.Width, normalBitmap.Height); for (int i = 0; i < normalBitmap.Width; i++) { for (int j = 0; j < normalBitmap.Height; j++) { Color normalColor = normalBitmap.GetPixel(i, j); Color specularColor = specularBitmap.GetPixel(i, j); normalBitmap.SetPixel(i, j, Color.FromArgb(specularColor.R, normalColor.R, normalColor.G, normalColor.B)); } } textures["bumpmap"].bytes = VTF.FromBitmap(textures["bumpmap"].bitmap, launcher); vmt.addChild(new KeyValue("$bumpmap", relativePath + "_bumpmap")); vmt.addChild(new KeyValue("$normalmapalphaenvmapmask", "1")); vmt.addChild(new KeyValue("$envmap", "env_cubemap")); File.WriteAllBytes(fullPath + "_bumpmap.vtf", textures["bumpmap"].bytes); } else if (hasNormalMap) { vmt.addChild(new KeyValue("$bumpmap", relativePath + "_bumpmap")); File.WriteAllBytes(fullPath + "_bumpmap.vtf", textures["bumpmap"].bytes); } else if (hasSpecularMap) { vmt.addChild(new KeyValue("$envmap", "env_cubemap")); vmt.addChild(new KeyValue("$envmapmask", relativePath + "_envmapmask")); File.WriteAllBytes(fullPath + "_envmapmask.vtf", textures["envmapmask"].bytes); } if (detail != null) { vmt.addChild(new KeyValue("$detail", detail[0])); vmt.addChild(new KeyValue("$detailscale", detail[0])); vmt.addChild(new KeyValue("$detailblendfactor", detail[0])); vmt.addChild(new KeyValue("$detailblendmode", detail[0])); } vmt.addChild(new KeyValue("$surfaceprop", comboSurfaceProp.EditValue.ToString())); vmt.addChild(new KeyValue("$surfaceprop2", comboSurfaceProp2.EditValue.ToString())); SourceSDK.KeyValue.writeChunkFile(fullPath + ".vmt", vmt, false, new UTF8Encoding(false)); }
public void LoadMaterial(string fullPath) { SourceSDK.KeyValue vmt = null; if (File.Exists(fullPath)) { vmt = SourceSDK.KeyValue.readChunkfile(fullPath); } string relativePath = GetRelativePath(launcher, fullPath); this.relativePath = relativePath.Substring("\\materials\\".Length); VPKManager vpkManager = null; if (vmt != null) { vpkManager = new VPKManager(launcher); } foreach (KeyValuePair <string, PictureEdit> kv in pictureEdits) { if (vmt != null) { string value = vmt.getValue("$" + kv.Key); if (value != null) { string texturePath = vpkManager.getExtractedPath("materials/" + value + ".vtf"); if (texturePath != "" && File.Exists(texturePath)) { textures[kv.Key].relativePath = value; textures[kv.Key].bytes = File.ReadAllBytes(texturePath); textures[kv.Key].bitmap = VTF.ToBitmap(textures[kv.Key].bytes, launcher); kv.Value.Image = textures[kv.Key].bitmap; } else { ClearTexture(kv.Value); } } } else { ClearTexture(kv.Value); } } if (vmt != null && vmt.getValue("$normalmapalphaenvmapmask") == "1" && textures["bumpmap"].bitmap != null) { textures["envmapmask"].bitmap = new Bitmap(textures["bumpmap"].bitmap.Width, textures["bumpmap"].bitmap.Height); for (int i = 0; i < textures["bumpmap"].bitmap.Width; i++) { for (int j = 0; j < textures["bumpmap"].bitmap.Height; j++) { int alpha = textures["bumpmap"].bitmap.GetPixel(i, j).A; textures["envmapmask"].bitmap.SetPixel(i, j, Color.FromArgb(alpha, alpha, alpha)); } } textures["envmapmask"].bytes = VTF.FromBitmap(textures["envmapmask"].bitmap, launcher); textures["envmapmask"].relativePath = ""; pictureEnvMapMask.Image = textures["envmapmask"].bitmap; } }