public static void ShowGtxMipmapWarning(NUT nut) { if (nut.ContainsGtxTextures()) { MessageBox.Show("Mipmaps will not be exported correctly for some textures.", "GTX textures detected"); } }
private void RenderTexture(GLControl glControl1, NUT nut) { if (nut == null) { return; } glControl1.MakeCurrent(); GL.Viewport(glControl1.ClientRectangle); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.ClearColor(Color.Black); GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); GL.MatrixMode(MatrixMode.Projection); foreach (NutTexture tex in nut.Nodes) { ScreenDrawing.DrawTexturedQuad(nut.glTexByHashId[tex.HashId], tex.Width, tex.Height, screenTriangle, true, true, true, true, true); } glControl1.SwapBuffers(); }
private void ImportBack(string filename) { if (dontModify) { return; } NutTexture tex = textureFromFile[filename]; try { Dds dds = new Dds(new FileData(filename)); NutTexture ntex = dds.ToNutTexture(); tex.Height = ntex.Height; tex.Width = ntex.Width; tex.pixelInternalFormat = ntex.pixelInternalFormat; tex.surfaces = ntex.surfaces; tex.pixelFormat = ntex.pixelFormat; //GL.DeleteTexture(NUT.glTexByHashId[tex.HASHID]); currentNut.glTexByHashId.Remove(tex.HashId); currentNut.glTexByHashId.Add(tex.HashId, NUT.CreateTexture2D(tex)); FillForm(); textureListBox.SelectedItem = tex; glControl1.Invalidate(); } catch { Console.WriteLine("Could not be open for editing"); } }
public NutEditor(string filePath) : this() { NUT nut = new NUT(filePath); FilePath = filePath; Edited = false; SelectNut(nut); }
// I'm completely totally serious public static Nud Create(VBN vbn) { Dictionary <string, string> files = new Dictionary <string, string>(); ZipArchive zip = ZipFile.OpenRead("lib\\Skapon.zip"); Random random = new Random(); int randomNumber = random.Next(0, 0xFFFFFF); NUT nut = new NUT(); foreach (ZipArchiveEntry e in zip.Entries) { byte[] b; using (BinaryReader br = new BinaryReader(e.Open())) { b = br.ReadBytes((int)e.Length); } var stream = new StreamReader(new MemoryStream(b)); string s = stream.ReadToEnd(); files.Add(e.Name, s); if (e.Name.EndsWith(".dds")) { NutTexture tex = new Dds(new FileData(b)).ToNutTexture(); nut.Nodes.Add(tex); tex.HashId = 0x40000000 + randomNumber; nut.glTexByHashId.Add(tex.HashId, NUT.CreateTexture2D(tex)); } } Nud nud = new Nud(); Nud.Mesh head = new Nud.Mesh(); nud.Nodes.Add(head); head.Text = "Skapon"; head.Nodes.Add(setToBone(scale(readPoly(files["head.obj"]), 1, 1, 1), vbn.bones[vbn.boneIndex("HeadN")], vbn)); head.Nodes.Add(setToBone(scale(readPoly(files["body.obj"]), 1, 1, 1), vbn.bones[vbn.boneIndex("BustN")], vbn)); head.Nodes.Add(setToBone(scale(readPoly(files["hand.obj"]), 1, 1, 1), vbn.bones[vbn.boneIndex("RHandN")], vbn)); head.Nodes.Add(setToBone(scale(readPoly(files["hand.obj"]), -1, -1, 1), vbn.bones[vbn.boneIndex("LHandN")], vbn)); head.Nodes.Add(setToBone(scale(readPoly(files["foot.obj"]), 1, 1, 1), vbn.bones[vbn.boneIndex("RFootJ")], vbn)); head.Nodes.Add(setToBone(scale(readPoly(files["foot.obj"]), -1, -1, -1), vbn.bones[vbn.boneIndex("LFootJ")], vbn)); foreach (Nud.Polygon p in head.Nodes) { p.materials[0].textures[0].hash = 0x40000000 + randomNumber; } nud.UpdateRenderMeshes(); return(nud); }
public ModelContainer() { ImageKey = "folder"; SelectedImageKey = "folder"; nud = new Nud(); nut = new NUT(); mta = new MTA(); MOI = new MOI(); jtb = new JTB(); XMB = new XMBFile(); Checked = true; Refresh(); }
private void chr_13_renderer_DragDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); foreach (string filePath in files) { if (filePath.ToLower().EndsWith(".dds")) { Dds dds = new Dds(new FileData(filePath)); if (sender == chr_13_renderer) { chr13 = ReplaceTexture(dds.ToNutTexture(), 416, 416, chr13); if (chr13Loc != null) { chr13.Save(chr13Loc); } } if (sender == chr_00_renderer) { chr00 = ReplaceTexture(dds.ToNutTexture(), 128, 128, chr00); if (chr00Loc != null) { chr00.Save(chr00Loc); } } if (sender == chr_11_renderer) { chr11 = ReplaceTexture(dds.ToNutTexture(), 384, 384, chr13); if (chr11Loc != null) { chr11.Save(chr11Loc); } } } if (filePath.ToLower().EndsWith(".png")) { if (sender == stock_90_renderer) { stock90 = ReplaceTexture(NutEditor.FromPng(filePath, 0), 64, 64, chr13); if (stock90Loc != null) { stock90.Save(stock90Loc); } } } } ((GLControl)sender).Invalidate(); } }
private void replaceToolStripMenuItem_Click(object sender, EventArgs e) { if (currentNut == null || textureListBox.SelectedItem == null) { return; } using (var ofd = new OpenFileDialog()) { NutTexture texture = (NutTexture)(textureListBox.SelectedItem); ofd.Filter = "Supported Formats|*.dds;*.png|" + "DirectDraw Surface (.dds)|*.dds|" + "Portable Network Graphics (.png)|*.png|" + "All files(*.*)|*.*"; if (ofd.ShowDialog() == DialogResult.OK) { NutTexture newTexture = null; string extension = Path.GetExtension(ofd.FileName).ToLowerInvariant(); if (extension == ".dds") { Dds dds = new Dds(new FileData(ofd.FileName)); newTexture = dds.ToNutTexture(); } else if (extension == ".png") { newTexture = FromPng(ofd.FileName, 1); } else { return; } texture.Height = newTexture.Height; texture.Width = newTexture.Width; texture.pixelInternalFormat = newTexture.pixelInternalFormat; texture.surfaces = newTexture.surfaces; texture.pixelFormat = newTexture.pixelFormat; Edited = true; //GL.DeleteTexture(NUT.glTexByHashId[texture.HASHID]); currentNut.glTexByHashId.Remove(texture.HashId); currentNut.glTexByHashId.Add(texture.HashId, NUT.CreateTexture2D(texture)); FillForm(); } } }
public UiPreview(NUT chr00, NUT chr11, NUT chr13, NUT stock90) { InitializeComponent(); if (chr00 == null) { chr00 = new NUT(); } if (chr11 == null) { chr11 = new NUT(); } if (chr13 == null) { chr13 = new NUT(); } if (stock90 == null) { stock90 = new NUT(); } this.chr00 = chr00; this.chr11 = chr11; this.chr13 = chr13; this.stock90 = stock90; ContextMenu cm = new ContextMenu(); MenuItem snapShot = new MenuItem("Begin Snapshot"); snapShot.Click += SnapShotMode; cm.MenuItems.Add(snapShot); MenuItem snapShot2 = new MenuItem("Snapshot"); snapShot2.Click += LetsDance; cm.MenuItems.Add(snapShot2); chr_00_renderer.ContextMenu = cm; chr_11_renderer.ContextMenu = cm; chr_13_renderer.ContextMenu = cm; stock_90_renderer.AllowDrop = true; chr_00_renderer.AllowDrop = true; chr_11_renderer.AllowDrop = true; chr_13_renderer.AllowDrop = true; //stock_90_renderer.ContextMenu = cm; }
private void mipLevelTrackBar_Scroll(object sender, EventArgs e) { NutTexture tex = ((NutTexture)textureListBox.SelectedItem); if (tex.surfaces.Count == 6) { // Create a new texture for the selected surface at the first mip level. currentMipLevel = 0; SetCurrentCubeMapFaceLabel(mipLevelTrackBar.Value); textureToRender = NUT.CreateTexture2D(tex, mipLevelTrackBar.Value); } else { // Regular texture. currentMipLevel = mipLevelTrackBar.Value; } glControl1.Invalidate(); }
private void RegenerateMipMaps_Click(object sender, EventArgs e) { if (OpenTkSharedResources.SetupStatus != OpenTkSharedResources.SharedResourceStatus.Initialized) { return; } if (textureListBox.SelectedItem != null) { NutTexture tex = ((NutTexture)textureListBox.SelectedItem); NUT.RegenerateMipmapsFromTexture2D(tex); // Render the selected texture again. currentNut.RefreshGlTexturesByHashId(); if (currentNut.glTexByHashId.ContainsKey(tex.HashId)) { textureToRender = currentNut.glTexByHashId[tex.HashId]; } glControl1.Invalidate(); } }
private NUT ReplaceTexture(NutTexture tex, int width, int height, NUT nut) { if (tex.Width == width && tex.Height == height) { tex.HashId = 0x280052B7; if (nut != null && nut.Nodes.Count > 0) { tex.HashId = ((NutTexture)nut.Nodes[0]).HashId; } if (nut == null) { nut = new NUT(); } nut.Nodes.Clear(); nut.glTexByHashId.Clear(); nut.Nodes.Add(tex); nut.glTexByHashId.Add(tex.HashId, NUT.CreateTexture2D(tex)); } else { MessageBox.Show("Dimensions must be " + width + "x" + height); } return(nut); }
private void LetsDance(object sender, EventArgs e) { Control c = MainForm.Instance.GetActiveModelViewport(); if (!(c is ModelViewport)) { return; } ModelViewport view = (ModelViewport)c; view.currentMode = ModelViewport.Mode.Normal; NUT n = null; if (((MenuItem)sender).GetContextMenu().SourceControl == stock_90_renderer) { n = stock90; } if (((MenuItem)sender).GetContextMenu().SourceControl == chr_00_renderer) { n = chr00; } if (((MenuItem)sender).GetContextMenu().SourceControl == chr_11_renderer) { n = chr11; } if (((MenuItem)sender).GetContextMenu().SourceControl == chr_13_renderer) { n = chr13; } if (n == null) { return; } byte[] data = RenderTools.DXT5ScreenShot(view.glViewport, view.shootX, view.shootY, view.shootWidth, view.shootHeight); int id = n.Nodes.Count > 0 ? ((NutTexture)n.Nodes[0]).HashId : 0x280052B7; n.Nodes.Clear(); n.glTexByHashId.Clear(); NutTexture tex = new NutTexture(); tex.Width = view.shootWidth; tex.Height = view.shootHeight; tex.surfaces.Add(new TextureSurface()); tex.surfaces[0].mipmaps.Add(FlipDxt5(data, tex.Width, tex.Height)); tex.pixelInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt5Ext; tex.HashId = id; n.Nodes.Add(tex); n.glTexByHashId.Add(tex.HashId, NUT.CreateTexture2D(tex)); ((MenuItem)sender).GetContextMenu().SourceControl.Invalidate(); if (((MenuItem)sender).GetContextMenu().SourceControl == stock_90_renderer) { if (stock90Loc != null) { stock90.Save(stock90Loc); } } if (((MenuItem)sender).GetContextMenu().SourceControl == chr_00_renderer) { if (chr00Loc != null) { chr00.Save(chr00Loc); } } if (((MenuItem)sender).GetContextMenu().SourceControl == chr_11_renderer) { if (chr11Loc != null) { chr11.Save(chr13Loc); } } if (((MenuItem)sender).GetContextMenu().SourceControl == chr_13_renderer) { if (chr13Loc != null) { chr13.Save(chr13Loc); } } }
public void SelectNut(NUT n) { currentNut = n; FillForm(); }
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { tbl = new DataTable(); tbl.Columns.Add(new DataColumn("Name") { ReadOnly = true }); tbl.Columns.Add("Value"); dataGridView1.DataSource = tbl; tbl.Rows.Clear(); try { if (e.Node.Parent.Text == "Symbols") { tbl.Rows.Add("String", lumen.Strings[e.Node.Index]); } else if (e.Node.Parent.Text == "Colors") { tbl.Rows.Add("Red", lumen.Colors[e.Node.Index].X * 255); tbl.Rows.Add("Green", lumen.Colors[e.Node.Index].Y * 255); tbl.Rows.Add("Blue", lumen.Colors[e.Node.Index].Z * 255); tbl.Rows.Add("Alpha", lumen.Colors[e.Node.Index].W * 255); } else if (e.Node.Parent.Text == "Transforms") { tbl.Rows.Add("X-Scale", lumen.Transforms[e.Node.Index].Row0[0]); tbl.Rows.Add("X-Skew", lumen.Transforms[e.Node.Index].Row1[0]); tbl.Rows.Add("X-Transform", lumen.Transforms[e.Node.Index].Row3[0]); tbl.Rows.Add("Y-Scale", lumen.Transforms[e.Node.Index].Row1[1]); tbl.Rows.Add("Y-Skew", lumen.Transforms[e.Node.Index].Row0[1]); tbl.Rows.Add("Y-Transform", lumen.Transforms[e.Node.Index].Row3[1]); } else if (e.Node.Parent.Text == "Positions") { tbl.Rows.Add("X", lumen.Positions[e.Node.Index][0]); tbl.Rows.Add("Y", lumen.Positions[e.Node.Index][1]); } else if (e.Node.Parent.Text == "Bounds") { tbl.Rows.Add("Top", lumen.Bounds[e.Node.Index].TopLeft.X); tbl.Rows.Add("Left", lumen.Bounds[e.Node.Index].TopLeft.Y); tbl.Rows.Add("Bottom", lumen.Bounds[e.Node.Index].BottomRight.X); tbl.Rows.Add("Right", lumen.Bounds[e.Node.Index].BottomRight.Y); } else if (e.Node.Parent.Text == "Atlases") { tbl.Rows.Add("Texture ID", lumen.Atlases[e.Node.Index].id); tbl.Rows.Add("Name ID", lumen.Atlases[e.Node.Index].nameId); tbl.Rows.Add("Width", lumen.Atlases[e.Node.Index].width); tbl.Rows.Add("Height", lumen.Atlases[e.Node.Index].height); } else if (e.Node.Text.StartsWith("Graphic 0x")) { string filename = (Path.GetDirectoryName(lumen.Filename) + "\\img-" + (e.Node.Index.ToString("00000")) + ".nut"); nut = new NUT(filename); nut.RefreshGlTexturesByHashId(); LmuvViewer uvViewer = new LmuvViewer(lumen, nut, e.Node.Parent.Index, e.Node.Index); uvViewer.Show(); } else if (e.Node.Parent.Text == "Texts") { tbl.Rows.Add("Character ID", lumen.Texts[e.Node.Index].CharacterId); tbl.Rows.Add("unk 1", lumen.Texts[e.Node.Index].unk1); tbl.Rows.Add("Placeholder Text ID", lumen.Texts[e.Node.Index].placeholderTextId); tbl.Rows.Add("unk 2", lumen.Texts[e.Node.Index].unk2); tbl.Rows.Add("Stroke Color ID", lumen.Texts[e.Node.Index].strokeColorId); tbl.Rows.Add("unk 3", lumen.Texts[e.Node.Index].unk3); tbl.Rows.Add("unk 4", lumen.Texts[e.Node.Index].unk3); tbl.Rows.Add("unk 5", lumen.Texts[e.Node.Index].unk3); tbl.Rows.Add("Text Alignment", lumen.Texts[e.Node.Index].alignment); tbl.Rows.Add("unk 6", lumen.Texts[e.Node.Index].unk3); tbl.Rows.Add("unk 7", lumen.Texts[e.Node.Index].unk3); tbl.Rows.Add("unk 8", lumen.Texts[e.Node.Index].unk3); tbl.Rows.Add("Size", lumen.Texts[e.Node.Index].size); tbl.Rows.Add("unk 9", lumen.Texts[e.Node.Index].unk3); tbl.Rows.Add("unk 10", lumen.Texts[e.Node.Index].unk10); tbl.Rows.Add("unk 11", lumen.Texts[e.Node.Index].unk11); tbl.Rows.Add("unk 12", lumen.Texts[e.Node.Index].unk12); } else if (e.Node.Parent.Text == "Unk") { } } catch { } }
private void ImportNutFromFolder(object sender, EventArgs e) { using (FolderSelectDialog f = new FolderSelectDialog()) { if (f.ShowDialog() == DialogResult.OK) { Edited = true; if (!Directory.Exists(f.SelectedPath)) { Directory.CreateDirectory(f.SelectedPath); } NUT nut; nut = currentNut; foreach (var texPath in Directory.GetFiles(f.SelectedPath)) { string extension = Path.GetExtension(texPath).ToLowerInvariant(); if (!(extension == ".dds" || extension == ".png")) { continue; } int texId; bool isTex = int.TryParse(Path.GetFileNameWithoutExtension(texPath), NumberStyles.HexNumber, new CultureInfo("en-US"), out texId); NutTexture texture = null; if (isTex) { foreach (NutTexture tex in nut.Nodes) { if (tex.HashId == texId) { texture = tex; } } } if (texture == null) { //new texture NutTexture tex = null; if (extension == ".dds") { Dds dds = new Dds(new FileData(texPath)); tex = dds.ToNutTexture(); } else if (extension == ".png") { tex = FromPng(texPath, 1); } if (isTex) { tex.HashId = texId; } else { tex.HashId = nut.Nodes.Count; } nut.Nodes.Add(tex); currentNut.glTexByHashId.Add(tex.HashId, NUT.CreateTexture2D(tex)); FillForm(); } else { //existing texture NutTexture tex = texture; NutTexture ntex = null; if (extension == ".dds") { Dds dds = new Dds(new FileData(texPath)); ntex = dds.ToNutTexture(); } else if (extension == ".png") { ntex = FromPng(texPath, 1); } tex.Height = ntex.Height; tex.Width = ntex.Width; tex.pixelInternalFormat = ntex.pixelInternalFormat; tex.surfaces = ntex.surfaces; tex.pixelFormat = ntex.pixelFormat; //GL.DeleteTexture(NUT.glTexByHashId[tex.HASHID]); currentNut.glTexByHashId.Remove(tex.HashId); currentNut.glTexByHashId.Add(tex.HashId, NUT.CreateTexture2D(tex)); FillForm(); } } if (!Runtime.textureContainers.Contains(nut)) { Runtime.textureContainers.Add(nut); } } } FillForm(); }
private void textureListBox_SelectedIndexChanged(object sender, EventArgs e) { if (textureListBox.SelectedIndex >= 0) { NutTexture tex = ((NutTexture)textureListBox.SelectedItem); if (tex == null) { return; } // Render the selected texture. if (currentNut.glTexByHashId.ContainsKey(tex.HashId)) { textureToRender = currentNut.glTexByHashId[tex.HashId]; } SetGeneralAndDimensionsText(tex); if (tex.surfaces.Count == 6) { SetCubeMapText(tex); if (OpenTkSharedResources.SetupStatus == OpenTkSharedResources.SharedResourceStatus.Initialized) { RenderTools.dummyTextures[Filetypes.Models.Nuds.NudEnums.DummyTexture.StageMapHigh] = NUT.CreateTextureCubeMap(tex); } } else { SetMipMapText(tex); } } else { SetDefaultGeneralAndDimensionsText(); } // Render on index changed rather than every frame. glControl1.Invalidate(); }
private void importToolStripMenuItem_Click(object sender, EventArgs e) { if (currentNut == null) { return; } using (var ofd = new OpenFileDialog()) { ofd.Filter = "Supported Formats|*.dds;*.png|" + "DirectDraw Surface (.dds)|*.dds|" + "Portable Network Graphics (.png)|*.png|" + "All files(*.*)|*.*"; if (ofd.ShowDialog() == DialogResult.OK) { int texId; bool isTex = int.TryParse(Path.GetFileNameWithoutExtension(ofd.FileName), NumberStyles.HexNumber, new CultureInfo("en-US"), out texId); if (isTex) { foreach (NutTexture te in currentNut.Nodes) { if (texId == te.HashId) { isTex = false; } } } NutTexture tex = null; string extension = Path.GetExtension(ofd.FileName).ToLowerInvariant(); if (extension == ".dds") { Dds dds = new Dds(new FileData(ofd.FileName)); tex = dds.ToNutTexture(); } else if (extension == ".png") { tex = FromPng(ofd.FileName, 1); } else { return; } Edited = true; if (isTex) { tex.HashId = texId; } else { tex.HashId = 0x40FFFF00 | (currentNut.Nodes.Count); } // Replace OpenGL texture. if (currentNut.glTexByHashId.ContainsKey(tex.HashId)) { currentNut.glTexByHashId.Remove(tex.HashId); } currentNut.glTexByHashId.Add(tex.HashId, NUT.CreateTexture2D(tex)); currentNut.Nodes.Add(tex); FillForm(); } } }
public NutEditor(NUT nut) : this() { SelectNut(nut); }