public override void Replace(string FileName) { string ext = Utils.GetExtension(FileName); if (ext == ".bfmaa") { MaterialAnim.Import(FileName); MaterialAnim.Name = Text; LoadAnim(MaterialAnim); } else if (ext == ".gif" || ext == ".png" || ext == ".apng") { BNTX bntx = PluginRuntime.bntxContainers[0]; GifToTexturePatternAnimation anim = new GifToTexturePatternAnimation(FileName, bntx, this); MaterialAnim.Name = Text; LoadAnim(MaterialAnim); } }
private void stComboBox1_SelectedIndexChanged(object sender, EventArgs e) { int index = stComboBox1.SelectedIndex; if (index < 0) { return; } if (PluginRuntime.bntxContainers.Count > 0) { activeBntx = PluginRuntime.bntxContainers[index]; LoadTexture(); } if (PluginRuntime.ftexContainers.Count > 0) { activeFtexContainer = PluginRuntime.ftexContainers[index]; LoadTexture(); } }
private void NewTextureFile(object sender, EventArgs args) { string Name = "textures"; for (int i = 0; i < resFile.ExternalFiles.Count; i++) { if (resFile.ExternalFileDict.GetKey(i) == Name) { Name = Name + i; } } if (!Nodes.ContainsKey("EXT")) { Nodes.Add(new EmbeddedFilesFolder()); } BNTX bntx = new BNTX(); bntx.Data = new byte[0]; BinaryTextureContainer bntxTreeNode = new BinaryTextureContainer(new byte[0], "textures", resFile.Name); Nodes["EXT"].Nodes.Add(bntxTreeNode); }
public override void Replace(string FileName) { var bntxFile = new BNTX(); var tex = new TextureData(); tex.Replace(FileName, MipCount, 0, Format); //If it's null, the operation is cancelled if (tex.Texture == null) { return; } var surfacesNew = tex.GetSurfaces(); var surfaces = GetSurfaces(); if (surfaces[0].mipmaps[0].Length > surfacesNew[0].mipmaps[0].Length) { throw new Exception($"Image must be the same size or smaller! {surfaces[0].mipmaps[0].Length}"); } ImageData = tex.Texture.TextureData[0][0]; Width = tex.Texture.Width; Height = tex.Texture.Height; MipCount = tex.Texture.MipCount; ArrayCount = tex.Texture.ArrayLength; Format = tex.Format; TexFormat = FormatTable.FirstOrDefault(x => x.Value == tex.Format).Key; UpdateProperties(); Console.WriteLine($"TexFormat {TexFormat.ToString("X")}"); surfacesNew.Clear(); surfaces.Clear(); UpdateEditor(); }
public override void Replace(string FileName) { var bntxFile = new BNTX(); var tex = new TextureData(); tex.Replace(FileName, MipCount, 0, Format); //If it's null, the operation is cancelled if (tex.Texture == null) { return; } var surfacesNew = tex.GetSurfaces(); var surfaces = GetSurfaces(); if (surfaces[0].mipmaps[0].Length != surfacesNew[0].mipmaps[0].Length) { throw new Exception($"Image must be the same size! {surfaces[0].mipmaps[0].Length}"); } if (Width != tex.Texture.Width || Height != tex.Texture.Height) { throw new Exception("Image size must be the same!"); } ImageData = tex.Texture.TextureData[0][0]; Width = tex.Texture.Width; Height = tex.Texture.Height; MipCount = tex.Texture.MipCount; surfacesNew.Clear(); surfaces.Clear(); UpdateEditor(); }
public Dictionary <string, STGenericTexture> GetTextures() { Dictionary <string, STGenericTexture> textures = new Dictionary <string, STGenericTexture>(); if (File.Exists(FilePath)) { string folder = Path.GetDirectoryName(FilePath); foreach (var file in Directory.GetFiles(folder)) { try { if (Utils.GetExtension(file) == ".bflim") { BFLIM bflim = (BFLIM)STFileLoader.OpenFileFormat(file); if (!textures.ContainsKey(bflim.FileName)) { textures.Add(bflim.FileName, bflim); } } if (Utils.GetExtension(file) == ".bntx") { BNTX bntx = (BNTX)STFileLoader.OpenFileFormat(file); foreach (var tex in bntx.Textures) { if (!textures.ContainsKey(tex.Key)) { textures.Add(tex.Key, tex.Value); } } string fileName = Path.GetFileName(file); if (!header.TextureManager.BinaryContainers.ContainsKey(fileName)) { header.TextureManager.BinaryContainers.Add(fileName, bntx); } } } catch (Exception ex) { STErrorDialog.Show($"Failed to load texture {file}. ", "Layout Editor", ex.ToString()); } } } foreach (var archive in PluginRuntime.SarcArchives) { foreach (var file in archive.Files) { try { if (Utils.GetExtension(file.FileName) == ".bntx") { BNTX bntx = (BNTX)file.OpenFile(); file.FileFormat = bntx; foreach (var tex in bntx.Textures) { if (!textures.ContainsKey(tex.Key)) { textures.Add(tex.Key, tex.Value); } } if (!header.TextureManager.BinaryContainers.ContainsKey($"{archive.FileName}.bntx")) { header.TextureManager.BinaryContainers.Add($"{archive.FileName}.bntx", bntx); } } if (Utils.GetExtension(file.FileName) == ".bflim") { BFLIM bflim = (BFLIM)file.OpenFile(); string name = bflim.FileName; if (archive is SARC) { if (((SARC)archive).sarcData.HashOnly) { var sarcEntry = file as SARC.SarcEntry; //Look through all textures and find a hash match name = sarcEntry.TryGetHash(header.Textures, "timg"); name = Path.GetFileName(name); } } file.FileFormat = bflim; if (!textures.ContainsKey(bflim.FileName)) { textures.Add(name, bflim); } } } catch (Exception ex) { STErrorDialog.Show($"Failed to load texture {file.FileName}. ", "Layout Editor", ex.ToString()); } } if (!header.TextureManager.ArchiveFile.ContainsKey(archive.FileName)) { header.TextureManager.ArchiveFile.Add(archive.FileName, archive); } } return(textures); }
public GifToTexturePatternAnimation(string FileName, BNTX TargetBNTX, FMAA fmaa) { string TextureName = System.IO.Path.GetFileNameWithoutExtension(FileName); Image gifImg = Image.FromFile(FileName); //Add all the images var images = GetImages(gifImg); TargetBNTX.ImportTexture(images, TextureName); //Now load the key data to the animation fmaa.MaterialAnim = new Syroot.NintenTools.NSW.Bfres.MaterialAnim(); fmaa.MaterialAnim.Name = fmaa.Text; fmaa.MaterialAnim.Path = ""; fmaa.MaterialAnim.Loop = true; fmaa.MaterialAnim.FrameCount = images.Length; fmaa.MaterialAnim.TextureNames = new List <string>(); foreach (ImageKeyFrame key in images) { fmaa.MaterialAnim.TextureNames.Add($"{TextureName}{key.Frame}"); } var material = new MaterialAnimData(); material.Name = "NewMaterial"; material.TexturePatternAnimInfos = new List <TexturePatternAnimInfo>(); material.TexturePatternCurveIndex = 0; material.BeginVisalConstantIndex = 0; TexturePatternAnimInfo info = new TexturePatternAnimInfo(); info.CurveIndex = 0; info.SubBindIndex = -1; info.BeginConstant = ushort.MaxValue; info.Name = "_a0"; material.TexturePatternAnimInfos.Add(info); fmaa.MaterialAnim.MaterialAnimDataList.Add(material); AnimCurve curve = new AnimCurve(); curve.AnimDataOffset = 0; curve.CurveType = AnimCurveType.StepInt; curve.Delta = 0; curve.EndFrame = images.Length; curve.StartFrame = 0; curve.FrameType = AnimCurveFrameType.Byte; curve.Scale = 1; curve.Offset = 0; curve.Frames = new float[(int)curve.EndFrame]; for (int i = 0; i < curve.EndFrame; i++) { curve.Frames[i] = images[i].Frame; } curve.Keys = new float[(int)curve.Frames.Length, 1]; for (int i = 0; i < (ushort)curve.Keys.Length; i++) { int index = fmaa.MaterialAnim.TextureNames.IndexOf($"{TextureName}{images[i].Frame}"); curve.Keys[i, 0] = index; } material.Curves.Add(curve); fmaa.UpdateMaterialBinds(); }
public List <STGenericTexture> AddTextures() { List <STGenericTexture> textures = new List <STGenericTexture>(); switch (Platform) { case PlatformType.WiiU: { var archive = ArchiveParent; if (archive == null) { return(null); } var matches = archive.Files.Where(p => p.FileName.Contains("bflim")).ToList(); string textureFolder = "timg"; if (matches.Count > 0) { textureFolder = System.IO.Path.GetDirectoryName(matches[0].FileName); } var bflim = BFLIM.CreateNewFromImage(); if (bflim == null) { return(textures); } textures.Add(bflim); var mem = new System.IO.MemoryStream(); bflim.Save(mem); archive.AddFile(new ArchiveFileInfo() { FileData = mem.ToArray(), FileName = System.IO.Path.Combine(textureFolder, bflim.Text).Replace('\\', '/'), }); } break; case PlatformType.Switch: { BNTX bntx = null; if (BinaryContainers.Count == 0) { //Create a new one if none exist //Method for saving these will come in the save dialog bntx = new BNTX(); bntx.IFileInfo = new IFileInfo(); bntx.FileName = "textures"; bntx.Load(new System.IO.MemoryStream(BNTX.CreateNewBNTX("textures"))); BinaryContainers.Add("textures", bntx); } else { //Use first container for now as archives only use one bntx = BinaryContainers.Values.FirstOrDefault(); } var importedTextures = bntx.ImportTexture(); //Load all the additional textues for (int i = 0; i < importedTextures.Count; i++) { textures.Add(importedTextures[i]); } } break; } return(textures); }