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; nut.Destroy(); } if (nut == null) { nut = new NUT(); } nut.Nodes.Clear(); nut.glTexByHashId.Clear(); nut.Nodes.Add(tex); nut.glTexByHashId.Add(tex.HASHID, NUT.CreateGlTexture(tex)); } else { MessageBox.Show("Dimensions must be " + width + "x" + height); } return(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)).toNUT_Texture(); nut.Nodes.Add(tex); tex.HASHID = 0x40000000 + randomNumber; nut.glTexByHashId.Add(tex.HASHID, NUT.CreateGlTexture(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.UpdateVertexData(); return(nud); }
private void importToolStripMenuItem_Click(object sender, EventArgs e) { if (NUT == 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 NUT.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.toNUT_Texture(); } else if (extension == ".png") { tex = fromPNG(ofd.FileName, 1); } else { return; } Edited = true; if (isTex) { tex.HASHID = texId; } else { tex.HASHID = 0x40FFFF00 | (NUT.Nodes.Count); } if (NUT.glTexByHashId.ContainsKey(tex.HASHID)) { NUT.glTexByHashId.Remove(tex.HASHID); } NUT.Nodes.Add(tex); NUT.glTexByHashId.Add(tex.HASHID, NUT.CreateGlTexture(tex)); FillForm(); } } }
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 = stock_90; } if (((MenuItem)sender).GetContextMenu().SourceControl == chr_00_renderer) { n = chr_00; } if (((MenuItem)sender).GetContextMenu().SourceControl == chr_11_renderer) { n = chr_11; } if (((MenuItem)sender).GetContextMenu().SourceControl == chr_13_renderer) { n = chr_13; } 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.Destroy(); 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.type = PixelInternalFormat.CompressedRgbaS3tcDxt5Ext; tex.HASHID = id; n.Nodes.Add(tex); n.glTexByHashId.Add(tex.HASHID, NUT.CreateGlTexture(tex)); ((MenuItem)sender).GetContextMenu().SourceControl.Invalidate(); if (((MenuItem)sender).GetContextMenu().SourceControl == stock_90_renderer) { if (stock_90_loc != null) { stock_90.Save(stock_90_loc); } } if (((MenuItem)sender).GetContextMenu().SourceControl == chr_00_renderer) { if (chr_00_loc != null) { chr_00.Save(chr_00_loc); } } if (((MenuItem)sender).GetContextMenu().SourceControl == chr_11_renderer) { if (chr_11_loc != null) { chr_11.Save(chr_13_loc); } } if (((MenuItem)sender).GetContextMenu().SourceControl == chr_13_renderer) { if (chr_13_loc != null) { chr_13.Save(chr_13_loc); } } }