public void DeleteNode() { DialogResult dialogResult = MessageBox.Show("Are you sure? (This cannot be undone)", "Delete Polygon/Mesh", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { if (treeView1.SelectedNode is NUD.Polygon) { NUD.Mesh parent = ((NUD.Mesh)treeView1.SelectedNode.Parent); parent.Nodes.Remove((NUD.Polygon)treeView1.SelectedNode); NUD parentn = ((NUD)parent.Parent); parentn.PreRender(); } else if (treeView1.SelectedNode is NUD.Mesh) { NUD parent = ((NUD)treeView1.SelectedNode.Parent); //parent.Nodes.Remove((NUD.Mesh)treeView1.SelectedNode); treeView1.SelectedNode.Parent.Nodes.Remove(treeView1.SelectedNode); parent.PreRender(); } else if (treeView1.SelectedNode is NUD) { NUD model = (NUD)treeView1.SelectedNode; treeView1.Nodes.Remove(treeView1.SelectedNode); } } }
public NUD toNUD() { NUD n = new NUD(); n.hasBones = false; foreach (OBJObject o in objects) { NUD.Mesh m = new NUD.Mesh(); m.Text = o.name; m.singlebind = -1; m.boneflag = 0x08; foreach (OBJGroup g in o.groups) { if (g.v.Count == 0) { continue; } NUD.Polygon p = new NUD.Polygon(); m.Nodes.Add(p); m.Nodes.Add(p); p.setDefaultMaterial(); p.vertSize = 0x06; p.UVSize = 0x10; p.polflag = 0x00; Dictionary <int, int> collected = new Dictionary <int, int>(); for (int i = 0; i < g.v.Count; i++) { p.faces.Add(p.vertices.Count); NUD.Vertex v = new NUD.Vertex(); p.vertices.Add(v); if (g.v.Count > i) { v.pos = this.v[g.v[i]] + Vector3.Zero; } if (g.vn.Count > i) { v.nrm = vn[g.vn[i]] + Vector3.Zero; } if (g.vt.Count > i) { v.uv.Add(vt[g.vt[i]] + Vector2.Zero); } } } if (m.Nodes.Count > 0) { n.Nodes.Add(m); } } n.OptimizeFileSize(); n.PreRender(); return(n); }
private void merge(TreeNode n) { NUD org = (NUD)treeView1.SelectedNode.Tag; NUD nud = (NUD)n.Tag; nud.mesh.AddRange(org.mesh); org.mesh.Clear(); org.Destroy(); nud.PreRender(); treeView1.Nodes.Remove(treeView1.SelectedNode); treeView1.SelectedNode = n; // remove from model containers too ModelContainer torem = null; foreach (ModelContainer con in Runtime.ModelContainers) { if (con.nud == org) { torem = con; break; } } Runtime.ModelContainers.Remove(torem); refresh(); }
public void Apply(NUD nud) { Matrix4 rot = Matrix4.CreateRotationX(0.5f * (float)Math.PI); foreach (NUD.Mesh mesh in nud.mesh) { if (BoneTypes[(string)comboBox2.SelectedItem] == BoneTypes["No Bones"]) { mesh.boneflag = 0; } foreach (NUD.Polygon poly in mesh.polygons) { poly.vertSize = ((poly.vertSize == 0x6 ? 0 : BoneTypes[(string)comboBox2.SelectedItem])) | (VertTypes[(string)comboBox1.SelectedItem]); if (checkBox1.Checked || checkBox4.Checked || vertcolorCB.Checked) { foreach (NUD.Vertex v in poly.vertices) { if (checkBox1.Checked) { for (int i = 0; i < v.tx.Count; i++) { v.tx[i] = new Vector2(v.tx[i].X, 1 - v.tx[i].Y); } } if (vertcolorCB.Checked) { v.col = new Vector4(0x7F, 0x7F, 0x7F, 0x7F); } if (checkBox4.Checked) { v.pos = Vector3.Transform(v.pos, rot); v.nrm = Vector3.Transform(v.nrm, rot); } } } } } if (VertTypes[(string)comboBox1.SelectedItem] == 3 || VertTypes[(string)comboBox1.SelectedItem] == 7) { nud.computeTangentBitangent(); } if (checkBox2.Checked) { foreach (NUD.Mesh mesh in nud.mesh) { if (mesh.Text.Length > 5) { mesh.Text = mesh.Text.Substring(5, mesh.Text.Length - 5); } } } nud.PreRender(); }
public void deleteMesh() //Deletes selected mesh { if (Properties.Settings.Default.DltMesh == true) //checks if clear workspace is checked { if (treeView1.SelectedNode is NUD.Mesh) { DialogResult result = MessageBox.Show("You are about to delete a mesh, would you like to continue", "Safe Mode", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { TreeNode selectednode = treeView1.SelectedNode; TreeNode parent = selectednode.Parent; NUD.Mesh m = (NUD.Mesh)selectednode; NUD nud = (NUD)parent.Tag; nud.mesh.Remove(m); treeView1.SelectedNode = selectednode; nud.PreRender(); refresh(); } } else { MessageBox.Show("This can't be deleted"); } } }
public static void ArrangeBones(VBN vbn, NUD nud) { Dictionary <int, int> boneReorder = new Dictionary <int, int>(); int i = 0; for (i = 0; i < boneOrder.Count; i++) { int j = 0; for (j = 0; j < vbn.bones.Count; j++) { if (vbn.bones[j].Text.Equals(boneOrder[i])) { break; } } boneReorder.Add(j, i); } // get rest of the bones for (int j = 0; j < vbn.bones.Count; j++) { if (!boneReorder.Keys.Contains(j)) { boneReorder.Add(j, i++); } } // reorder vbn Bone[] nList = new Bone[vbn.bones.Count]; foreach (int k in boneReorder.Keys) { nList[boneReorder[k]] = vbn.bones[k]; //if (new string(vbn.bones[k].boneName).Equals("RotN")) vbn.bones[k].parentIndex = 0; if (vbn.bones[k].parentIndex != -1 && vbn.bones[k].parentIndex != 0x0FFFFFFF) { vbn.bones[k].parentIndex = boneReorder[vbn.bones[k].parentIndex]; } } vbn.bones.Clear(); vbn.bones.AddRange(nList); vbn.reset(); // now fix the nud foreach (NUD.Mesh mesh in nud.mesh) { foreach (NUD.Polygon poly in mesh.Nodes) { foreach (NUD.Vertex v in poly.vertices) { for (int k = 0; k < v.node.Count; k++) { v.node[k] = boneReorder[v.node[k]]; } } } } nud.PreRender(); }
public void DeleteNode() { DialogResult dialogResult = MessageBox.Show("Are you sure? (This cannot be undone)", "Delete Polygon/Mesh", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { if (treeView1.SelectedNode is NUD.Polygon) { NUD.Mesh parent = ((NUD.Mesh)treeView1.SelectedNode.Parent); parent.polygons.Remove((NUD.Polygon)treeView1.SelectedNode); parent.Nodes.Remove((NUD.Polygon)treeView1.SelectedNode); NUD parentn = ((NUD)parent.Parent.Tag); parentn.PreRender(); } else if (treeView1.SelectedNode is NUD.Mesh) { NUD parent = ((NUD)treeView1.SelectedNode.Parent.Tag); parent.mesh.Remove((NUD.Mesh)treeView1.SelectedNode); treeView1.SelectedNode.Parent.Nodes.Remove(treeView1.SelectedNode); parent.PreRender(); } else if (treeView1.SelectedNode.Tag is NUD) { NUD model = (NUD)treeView1.SelectedNode.Tag; ModelContainer m = null; foreach (ModelContainer modelContainer in Runtime.ModelContainers) { if (modelContainer.nud == model) { m = modelContainer; } } if (m != null) { Runtime.ModelContainers.Remove(m); } if (Runtime.TargetVBN == m.vbn) { Runtime.TargetVBN = null; } if (Runtime.TargetMTA == m.mta) { Runtime.TargetMTA = null; } if (Runtime.TargetNUD == m.nud) { Runtime.TargetNUD = null; } treeView1.Nodes.Remove(treeView1.SelectedNode); } } }
// 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")) { NUT.NUD_Texture tex = new DDS(new FileData(b)).toNUT_Texture(); nut.textures.Add(tex); tex.id = 0x40000000 + randomNumber; nut.draw.Add(tex.id, NUT.loadImage(tex)); } } NUD nud = new NUD(); NUD.Mesh head = new NUD.Mesh(); nud.mesh.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.PreRender(); return(nud); }
private void treeView1_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == '=') { if (treeView1.SelectedNode.Tag is NUD.Mesh) { TreeNode node = treeView1.SelectedNode; TreeNode parent = node.Parent; NUD.Mesh m = (NUD.Mesh)node.Tag; NUD n = (NUD)parent.Tag; int pos = n.mesh.IndexOf(m) + 1; if (pos >= n.mesh.Count) { pos = n.mesh.Count - 1; } n.mesh.Remove(m); n.mesh.Insert(pos, m); parent.Nodes.Remove(node); parent.Nodes.Insert(pos, node); treeView1.SelectedNode = node; n.PreRender(); } } if (e.KeyChar == '-') { if (treeView1.SelectedNode.Tag is NUD.Mesh) { TreeNode node = treeView1.SelectedNode; TreeNode parent = node.Parent; NUD.Mesh m = (NUD.Mesh)node.Tag; NUD n = (NUD)parent.Tag; int pos = n.mesh.IndexOf(m) - 1; if (pos < 0) { pos = 0; } n.mesh.Remove(m); n.mesh.Insert(pos, m); parent.Nodes.Remove(node); parent.Nodes.Insert(pos, node); treeView1.SelectedNode = node; n.PreRender(); } } }
public void Apply(NUD nud) { Matrix4 rot = Matrix4.CreateRotationX(0.5f * (float)Math.PI); foreach (NUD.Mesh mesh in nud.mesh) { foreach (NUD.Polygon poly in mesh.polygons) { poly.vertSize = (BoneTypes[(string)comboBox2.SelectedItem]) | (VertTypes[(string)comboBox1.SelectedItem]); if (checkBox1.Checked || checkBox4.Checked) { foreach (NUD.Vertex v in poly.vertices) { if (checkBox1.Checked) { for (int i = 0; i < v.tx.Count; i++) { v.tx[i] = new Vector2(v.tx[i].X, 1 - v.tx[i].Y); } } if (checkBox4.Checked) { v.pos = Vector3.Transform(v.pos, rot); v.nrm = Vector3.Transform(v.nrm, rot); } } } } } if (checkBox2.Checked) { foreach (NUD.Mesh mesh in nud.mesh) { if (mesh.Text.Length > 5) { mesh.Text = mesh.Text.Substring(5, mesh.Text.Length - 5); } } } nud.PreRender(); }
private void numericUpDown1_ValueChanged(object sender, EventArgs e) { if (treeView1.SelectedNode is NUD.Mesh && !changingValue) { int pos = (int)numericUpDown1.Value; TreeNode node = treeView1.SelectedNode; TreeNode parent = node.Parent; NUD.Mesh m = (NUD.Mesh)node; NUD n = (NUD)parent.Tag; n.mesh.Remove(m); n.mesh.Insert(pos, m); parent.Nodes.Remove(node); parent.Nodes.Insert(pos, node); treeView1.SelectedNode = node; n.PreRender(); } changingValue = false;//Set the value back so the user can change values }
private void treeView1_KeyDown(object sender, KeyEventArgs e) { e.Handled = false; if (e.KeyCode == Keys.Delete) { e.Handled = true; if (treeView1.SelectedNode is NUD.Mesh) { NUD parent = ((NUD)treeView1.SelectedNode.Parent.Tag); parent.mesh.Remove((NUD.Mesh)treeView1.SelectedNode); parent.PreRender(); } else if (treeView1.SelectedNode.Tag is NUD) { NUD model = (NUD)treeView1.SelectedNode.Tag; ModelContainer m = null; foreach (ModelContainer modelContainer in Runtime.ModelContainers) { if (modelContainer.nud == model) { m = modelContainer; } } if (m != null) { Runtime.ModelContainers.Remove(m); } if (Runtime.TargetVBN == m.vbn) { Runtime.TargetVBN = null; } if (Runtime.TargetMTA == m.mta) { Runtime.TargetMTA = null; } if (Runtime.TargetNUD == m.nud) { Runtime.TargetNUD = null; } } refresh(); } }
public static void effectiveScale(NUD nud, VBN vbn, Matrix4 sca) { foreach (Bone b in vbn.bones) { Vector3 pos = Vector3.Transform(new Vector3(b.position[0], b.position[1], b.position[2]), sca); b.position[0] = pos.X; b.position[1] = pos.Y; b.position[2] = pos.Z; } vbn.reset(); foreach (NUD.Mesh mesh in nud.mesh) { foreach (NUD.Polygon poly in mesh.Nodes) { foreach (NUD.Vertex v in poly.vertices) { v.pos = Vector3.Transform(v.pos, sca); } } } nud.PreRender(); }
public void Apply(NUD nud) { Matrix4 rot = Matrix4.CreateRotationX(0.5f * (float)Math.PI); float sc = 1f; bool hasScale = float.TryParse(scaleTB.Text, out sc); bool checkedUVRange = false; bool fixUV = false; bool warning = false; foreach (NUD.Mesh mesh in nud.meshes) { if (BoneTypes[(string)comboBox2.SelectedItem] == BoneTypes["No Bones"]) { mesh.boneflag = 0; } foreach (NUD.Polygon poly in mesh.Nodes) { if (BoneTypes[(string)comboBox2.SelectedItem] == BoneTypes["No Bones"]) { poly.polflag = 0; } if (smoothCB.Checked) { poly.SmoothNormals(); } // we only want to calculate new tangents/bitangents for imports // vanilla models have special tangents/bitangents for mirrored normal maps NUD.computeTangentBitangent(poly); poly.vertSize = ((poly.vertSize == 0x6 ? 0 : BoneTypes[(string)comboBox2.SelectedItem])) | (VertTypes[(string)comboBox1.SelectedItem]); if (!warning && poly.vertSize == 0x27) { MessageBox.Show("Using \"" + (string)comboBox2.SelectedItem + "\" and \"" + (string)comboBox1.SelectedItem + "\" can make shadows not appear in-game", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error); warning = true; } if (stagematCB.Checked) { // change to stage material NUD.Mat_Texture tex = poly.materials[0].textures[0]; poly.materials[0].textures.Clear(); poly.materials.Clear(); NUD.Material m = new NUD.Material(); poly.materials.Add(m); m.flags = 0xA2011001; m.RefAlpha = 128; m.cullMode = 1029; m.textures.Clear(); m.textures.Add(tex); m.entries.Add("NU_colorSamplerUV", new float[] { 1, 1, 0, 0 }); m.entries.Add("NU_diffuseColor", new float[] { 1, 1, 1, 0.5f }); m.entries.Add("NU_materialHash", new float[] { BitConverter.ToSingle(new byte[] { 0x12, 0xEE, 0x2A, 0x1B }, 0), 0, 0, 0 }); } //if (checkBox1.Checked || checkBox4.Checked || vertcolorCB.Checked || sc != 1f) foreach (NUD.Vertex v in poly.vertices) { if (!checkedUVRange && v.uv.Count > 0 && (Math.Abs(v.uv[0].X) > 4 || Math.Abs(v.uv[0].Y) > 4)) { checkedUVRange = true; DialogResult dialogResult = MessageBox.Show("Some UVs are detected to be out of accurate range.\nFix them now?", "Potential UV Problem", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { fixUV = true; } } if (fixUV) { for (int h = 0; h < v.uv.Count; h++) { v.uv[h] = new Vector2(v.uv[h].X - (int)v.uv[h].X, v.uv[h].Y - (int)v.uv[h].Y); } } if (flipUVCB.Checked) { for (int i = 0; i < v.uv.Count; i++) { v.uv[i] = new Vector2(v.uv[i].X, 1 - v.uv[i].Y); } } if (vertColorDivCB.Checked) //v.col = v.col / 2; { for (int i = 0; i < 3; i++) { v.col[i] = v.col[i] / 2; } } if (vertcolorCB.Checked) { v.col = new Vector4(0x7F, 0x7F, 0x7F, 0x7F); } if (checkBox4.Checked) { v.pos = Vector3.Transform(v.pos, rot); v.nrm = Vector3.Transform(v.nrm, rot); } if (sc != 1f) { v.pos = Vector3.Multiply(v.pos, sc); } } } } //if (VertTypes[(string)comboBox1.SelectedItem] == 3 || VertTypes[(string)comboBox1.SelectedItem] == 7) if (checkBox2.Checked) { foreach (NUD.Mesh mesh in nud.meshes) { if (mesh.Text.Length > 5) { mesh.Text = mesh.Text.Substring(5, mesh.Text.Length - 5); } } } nud.PreRender(); }
public static void MakePichu(string path = "C:\\Pichu\\") { if (!path.EndsWith("\\")) { path += "\\"; } DAT dat = new DAT(); dat.Read(new FileData(path + "PlPcNr.dat")); dat.PreRender(); dat.ExportTextures(path, 0x401B1000); BoneNameFix(dat.bones); // model-------------------------------------------------------- ModelContainer converted = dat.wrapToNUD(); NUD nud = converted.nud; float sca = 0.6f; removeLowPolyNr(nud); nud.PreRender(); Runtime.ModelContainers.Add(converted); //------------------------------------------------- Runtime.TargetVBN = converted.vbn; MainForm.HashMatch(); Dictionary <string, SkelAnimation> anims = DAT_Animation.LoadAJ(path + "PlPcAJ.dat", converted.vbn); //ArrangeBones(converted.vbn, converted.nud); // note bone 40 - 51 is disabled for pika foreach (string an in anims.Keys) { effectiveScale(anims[an], Matrix4.CreateTranslation(0, 0, 0) * Matrix4.CreateScale(sca, sca, sca)); } effectiveScale(converted.nud, converted.vbn, Matrix4.CreateTranslation(0, 0, 0) * Matrix4.CreateScale(sca, sca, sca)); Directory.CreateDirectory(path + "build\\model\\body\\c00\\"); nud.Save(path + "build\\model\\body\\c00\\model.nud"); converted.vbn.Endian = Endianness.Little; converted.vbn.Save(path + "build\\model\\body\\c00\\model.vbn"); PAC org = new PAC(); PAC npac = new PAC(); org.Read(path + "main.pac"); foreach (string key in org.Files.Keys) { byte[] d = org.Files[key]; foreach (string an in anims.Keys) { string name = an.Replace("PlyPichu5K_Share_ACTION_", "").Replace("_figatree", ""); if (key.Contains(name)) { Console.WriteLine("Matched " + name + " with " + key); if (!anims[an].getNodes(true).Contains(0) && !key.Contains("Cliff")) { KeyNode node = anims[an].getNode(0, 0); node.t_type = 1; } d = OMOOld.createOMO(anims[an], converted.vbn); break; } } npac.Files.Add(key, d); } Directory.CreateDirectory(path + "build\\motion\\"); npac.Save(path + "build\\motion\\main.pac"); /*FileOutput omo = new FileOutput(); * converted.vbn.reset(); * converted.vbn.totalBoneCount = (uint)converted.vbn.bones.Count; * omo.writeBytes(OMO.createOMO(anims["PlyPichu5K_Share_ACTION_Wait1_figatree"], converted.vbn)); * omo.save(path + "PlyPichu5K_Share_ACTION_Wait1_figatree.omo");*/ }
///<summary> ///Open a file based on the filename ///</summary> /// <param name="filename"> Filename of file to open</param> public void openFile(string filename) { if (!filename.EndsWith(".mta") && !filename.EndsWith(".dat") && !filename.EndsWith(".smd")) { openAnimation(filename); } if (filename.EndsWith(".vbn")) { Runtime.TargetVBN = new VBN(filename); if (Directory.Exists("Skapon\\")) { NUD nud = Skapon.Create(Runtime.TargetVBN); ModelContainer con = new ModelContainer(); con.vbn = Runtime.TargetVBN; con.nud = nud; nud.PreRender(); Runtime.ModelContainers.Add(con); } } if (filename.EndsWith(".sb")) { SB sb = new SB(); sb.Read(filename); SwagEditor swagEditor = new SwagEditor(sb) { ShowHint = DockState.DockRight }; AddDockedControl(swagEditor); SwagEditors.Add(swagEditor); } if (filename.EndsWith(".dat")) { if (filename.EndsWith("AJ.dat")) { MessageBox.Show("This is animation; load with Animation -> Import"); return; } DAT dat = new DAT(); dat.Read(new FileData(filename)); ModelContainer c = new ModelContainer(); Runtime.ModelContainers.Add(c); c.dat_melee = dat; dat.PreRender(); HashMatch(); Runtime.TargetVBN = dat.bones; DAT_TreeView p = new DAT_TreeView() { ShowHint = DockState.DockLeft }; p.setDAT(dat); AddDockedControl(p); //Runtime.TargetVBN = dat.bones; meshList.refresh(); } if (filename.EndsWith(".nut")) { Runtime.TextureContainers.Add(new NUT(filename)); NUTEditor ev = new NUTEditor(); ev.Show(); } if (filename.EndsWith(".lvd")) { Runtime.TargetLVD = new LVD(filename); LVD test = Runtime.TargetLVD; lvdList.fillList(); } if (filename.EndsWith(".mta")) { Runtime.TargetMTA = new MTA(); Runtime.TargetMTA.Read(filename); viewports[0].loadMTA(Runtime.TargetMTA); MTAEditor temp = new MTAEditor(Runtime.TargetMTA) { ShowHint = DockState.DockLeft }; temp.Text = Path.GetFileName(filename); AddDockedControl(temp); mtaEditors.Add(temp); } if (filename.EndsWith(".mtable")) { //project.openACMD(filename); Runtime.Moveset = new MovesetManager(filename); } if (filename.EndsWith("path.bin")) { Runtime.TargetPath = new PathBin(filename); } else if (filename.EndsWith(".bin")) { //Note to whoever is readin this: //Eventually we need to look at the magic here (and also make all .bins look at magic) //Runtime.TargetCMR0 = new CMR0(); //Runtime.TargetCMR0.read(new FileData(filename)); PARAMEditor p = new PARAMEditor(filename) { ShowHint = DockState.Document }; p.Text = Path.GetFileName(filename); AddDockedControl(p); paramEditors.Add(p); } if (filename.EndsWith(".mdl0")) { MDL0Bones mdl0 = new MDL0Bones(); Runtime.TargetVBN = mdl0.GetVBN(new FileData(filename)); } if (filename.EndsWith(".smd")) { Runtime.TargetVBN = new VBN(); SMD.read(filename, new SkelAnimation(), Runtime.TargetVBN); } if (filename.ToLower().EndsWith(".dae")) { DAEImportSettings m = new DAEImportSettings(); m.ShowDialog(); if (m.exitStatus == DAEImportSettings.Opened) { if (Runtime.ModelContainers.Count < 1) { Runtime.ModelContainers.Add(new ModelContainer()); } Collada.DAEtoNUD(filename, Runtime.ModelContainers[0]); // apply settings m.Apply(Runtime.ModelContainers[0].nud); Runtime.ModelContainers[0].nud.MergePoly(); meshList.refresh(); } } if (filename.EndsWith(".mbn")) { MBN m = new MBN(); m.Read(filename); ModelContainer con = new ModelContainer(); BCH b = new BCH(); con.bch = b; b.mbn = m; b.Read("C:\\s\\Smash\\extract\\data\\fighter\\lucas\\Ness3DS - h00\\normal.bch"); Runtime.ModelContainers.Add(con); } /*if (filename.EndsWith(".bch")) * { * ModelContainer con = new ModelContainer(); * BCH b = new BCH(); * b.Read(filename); * con.bch = b; * Runtime.ModelContainers.Add(con); * }*/ if (filename.EndsWith(".nud")) { openNud(filename); } if (filename.EndsWith(".moi")) { MOI moi = new MOI(filename); AddDockedControl(new MOIEditor(moi) { ShowHint = DockState.DockRight }); } if (filename.EndsWith(".wrkspc")) { Workspace = new WorkspaceManager(project); Workspace.OpenWorkspace(filename); } if (Runtime.TargetVBN != null) { ModelContainer m = new ModelContainer(); m.vbn = Runtime.TargetVBN; Runtime.ModelContainers.Add(m); if (filename.EndsWith(".smd")) { m.nud = SMD.toNUD(filename); meshList.refresh(); } leftPanel.treeRefresh(); } else { foreach (ModelContainer m in Runtime.ModelContainers) { if (m.vbn != null) { Runtime.TargetVBN = Runtime.ModelContainers[0].vbn; break; } } } // Don't want to mess up the project tree if we // just set it up already if (!filename.EndsWith(".wrkspc")) { project.fillTree(); } }
public static NUD toNUD(string fname) { StreamReader reader = File.OpenText(fname); string line; string current = ""; NUD nud = new NUD(); while ((line = reader.ReadLine()) != null) { line = Regex.Replace(line, @"\s+", " "); string[] args = line.Replace(";", "").TrimStart().Split(' '); if (args[0].Equals("triangles") || args[0].Equals("end")) { current = args[0]; continue; } if (current.Equals("triangles")) { string meshName = args[0]; if (args[0].Equals("")) continue; for (int j = 0; j < 3; j++) { line = reader.ReadLine(); line = Regex.Replace(line, @"\s+", " "); args = line.Replace(";", "").TrimStart().Split(' '); // read triangle strip int parent = int.Parse(args[0]); NUD.Vertex vert = new NUD.Vertex(); vert.pos = new Vector3(float.Parse(args[1]), float.Parse(args[2]), float.Parse(args[3])); vert.nrm = new Vector3(float.Parse(args[4]), float.Parse(args[5]), float.Parse(args[6])); vert.uv.Add(new Vector2(float.Parse(args[7]), float.Parse(args[8]))); int wCount = int.Parse(args[9]); int w = 10; for (int i = 0; i < wCount; i++) { vert.node.Add(int.Parse(args[w++])); vert.weight.Add(float.Parse(args[w++])); } NUD.Mesh mes = null; foreach (NUD.Mesh m in nud.meshes) { if (m.Text.Equals(meshName)) { mes = m; } } if (mes == null) { mes = new NUD.Mesh(); mes.Text = meshName; nud.meshes.Add(mes); } if (mes.Nodes.Count == 0) { NUD.Polygon poly = new NUD.Polygon(); poly.setDefaultMaterial(); mes.Nodes.Add(poly); } bool found = false; foreach (NUD.Vertex nv in ((NUD.Polygon)mes.Nodes[0]).vertices) { if (nv.pos.Equals(vert.pos)) { ((NUD.Polygon)mes.Nodes[0]).faces.Add(((NUD.Polygon)mes.Nodes[0]).vertices.IndexOf(nv)); found = true; break; } } if (!found) { ((NUD.Polygon)mes.Nodes[0]).faces.Add(((NUD.Polygon)mes.Nodes[0]).vertices.Count); ((NUD.Polygon)mes.Nodes[0]).vertices.Add(vert); } } } } nud.PreRender(); return nud; }
public void Apply(NUD nud) { nud.GenerateBoundingBoxes(); Matrix4 rot = Matrix4.CreateRotationX(0.5f * (float)Math.PI); float sc = 1f; bool hasScale = float.TryParse(scaleTB.Text, out sc); bool checkedMeshName = false; bool fixMeshName = false; bool warning = false; foreach (NUD.Mesh mesh in nud.Nodes) { if (BoneTypes[(string)comboBox2.SelectedItem] == BoneTypes["No Bones"]) { mesh.boneflag = 0; } if (!checkedMeshName) { checkedMeshName = true; if (mesh.Text.Length > 5) { string sub = mesh.Text.Substring(0, 5); int a = 0; if (sub.StartsWith("_") && sub.EndsWith("_") && int.TryParse(sub.Substring(1, 3), out a)) { fixMeshName = DialogResult.Yes == MessageBox.Show("Detected mesh names that start with \"_###_\". Would you like to fix this?\nIt is recommended that you select \"Yes\".", "Mesh Name Fix", MessageBoxButtons.YesNo); } } } if (fixMeshName) { if (mesh.Text.Length > 5) { mesh.Text = mesh.Text.Substring(5, mesh.Text.Length - 5); } } foreach (NUD.Polygon poly in mesh.Nodes) { if (BoneTypes[(string)comboBox2.SelectedItem] == BoneTypes["No Bones"]) { poly.polflag = 0; } //Smooth normals if (smoothCB.Checked) { poly.SmoothNormals(); } // we only want to calculate new tangents/bitangents for imports // vanilla models have special tangents/bitangents for mirrored normal maps NUD.computeTangentBitangent(poly); poly.vertSize = ((poly.vertSize == 0x6 ? 0 : BoneTypes[(string)comboBox2.SelectedItem])) | (VertTypes[(string)comboBox1.SelectedItem]); if (!warning && poly.vertSize == 0x27) { MessageBox.Show("Using \"" + (string)comboBox2.SelectedItem + "\" and \"" + (string)comboBox1.SelectedItem + "\" can make shadows not appear in-game.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error); warning = true; } //Use stage material if (stagematCB.Checked) { NUD.Mat_Texture tex = poly.materials[0].textures[0]; poly.materials[0].textures.Clear(); poly.materials.Clear(); NUD.Material m = new NUD.Material(); poly.materials.Add(m); m.Flags = 0xA2001001; m.RefAlpha = 128; m.cullMode = 1029; m.textures.Clear(); m.textures.Add(tex); m.entries.Add("NU_colorSamplerUV", new float[] { 1, 1, 0, 0 }); m.entries.Add("NU_diffuseColor", new float[] { 1, 1, 1, 0.5f }); m.entries.Add("NU_materialHash", new float[] { BitConverter.ToSingle(new byte[] { 0x12, 0xEE, 0x2A, 0x1B }, 0), 0, 0, 0 }); } foreach (NUD.Vertex v in poly.vertices) { //Scroll UVs V by -1 if (checkBox2.Checked) { for (int i = 0; i < v.uv.Count; i++) { v.uv[i] = new Vector2(v.uv[i].X, v.uv[i].Y + 1); } } //Flip UVs if (flipUVCB.Checked) { for (int i = 0; i < v.uv.Count; i++) { v.uv[i] = new Vector2(v.uv[i].X, 1 - v.uv[i].Y); } } //Halve vertex colors if (vertColorDivCB.Checked) { for (int i = 0; i < 3; i++) { v.col[i] = v.col[i] / 2; } } //Ignore vertex colors if (vertcolorCB.Checked) { v.col = new Vector4(0x7F, 0x7F, 0x7F, 0xFF); } //Rotate 90 degrees if (checkBox4.Checked) { v.pos = Vector3.TransformPosition(v.pos, rot); v.nrm = Vector3.TransformNormal(v.nrm, rot); } //Scale if (sc != 1f) { v.pos = Vector3.Multiply(v.pos, sc); } } } } //if (VertTypes[(string)comboBox1.SelectedItem] == 3 || VertTypes[(string)comboBox1.SelectedItem] == 7) nud.PreRender(); }
private void treeView1_KeyPress(object sender, KeyPressEventArgs e) { //WTF were these even /*if (e.KeyChar == 'c') * { * if (treeView1.SelectedNode is NUD.Polygon) * { * NUD.Polygon p = (NUD.Polygon)treeView1.SelectedNode; * * foreach (NUD.Vertex v in p.vertices) * { * v.col += new OpenTK.Vector4(5f); * } * * foreach (ModelContainer con in Runtime.ModelContainers) * { * if (con.NUD != null) * con.NUD.PreRender(); * } * } * } * if (e.KeyChar == 'x') * { * if (treeView1.SelectedNode is NUD.Polygon) * { * NUD.Polygon p = (NUD.Polygon)treeView1.SelectedNode; * * foreach (NUD.Vertex v in p.vertices) * { * v.col -= new OpenTK.Vector4(5f); * } * * foreach (ModelContainer con in Runtime.ModelContainers) * { * if (con.NUD != null) * con.NUD.PreRender(); * } * } * }*/ if (e.KeyChar == '=') { if (treeView1.SelectedNode is NUD.Mesh) { TreeNode node = treeView1.SelectedNode; TreeNode parent = node.Parent; NUD.Mesh m = (NUD.Mesh)node; NUD n = (NUD)parent; int pos = n.Nodes.IndexOf(m) + 1; if (pos >= n.Nodes.Count) { pos = n.Nodes.Count - 1; } n.Nodes.Remove(m); n.Nodes.Insert(pos, m); parent.Nodes.Remove(node); parent.Nodes.Insert(pos, node); treeView1.SelectedNode = node; n.PreRender(); } } if (e.KeyChar == '-') { if (treeView1.SelectedNode is NUD.Mesh) { TreeNode node = treeView1.SelectedNode; TreeNode parent = node.Parent; NUD.Mesh m = (NUD.Mesh)node; NUD n = (NUD)parent; int pos = n.Nodes.IndexOf(m) - 1; if (pos < 0) { pos = 0; } n.Nodes.Remove(m); n.Nodes.Insert(pos, m); parent.Nodes.Remove(node); parent.Nodes.Insert(pos, node); treeView1.SelectedNode = node; n.PreRender(); } } }
private void treeView1_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 'c') { if (treeView1.SelectedNode is NUD.Polygon) { NUD.Polygon p = (NUD.Polygon)treeView1.SelectedNode; foreach (NUD.Vertex v in p.vertices) { v.col += new OpenTK.Vector4(5f); } foreach (ModelContainer con in Runtime.ModelContainers) { if (con.nud != null) { con.nud.PreRender(); } } } } if (e.KeyChar == 'x') { if (treeView1.SelectedNode is NUD.Polygon) { NUD.Polygon p = (NUD.Polygon)treeView1.SelectedNode; foreach (NUD.Vertex v in p.vertices) { v.col -= new OpenTK.Vector4(5f); } foreach (ModelContainer con in Runtime.ModelContainers) { if (con.nud != null) { con.nud.PreRender(); } } } } if (e.KeyChar == '=') { if (treeView1.SelectedNode.Tag is NUD.Mesh) { TreeNode node = treeView1.SelectedNode; TreeNode parent = node.Parent; NUD.Mesh m = (NUD.Mesh)node.Tag; NUD n = (NUD)parent.Tag; int pos = n.mesh.IndexOf(m) + 1; if (pos >= n.mesh.Count) { pos = n.mesh.Count - 1; } n.mesh.Remove(m); n.mesh.Insert(pos, m); parent.Nodes.Remove(node); parent.Nodes.Insert(pos, node); treeView1.SelectedNode = node; n.PreRender(); } } if (e.KeyChar == '-') { if (treeView1.SelectedNode.Tag is NUD.Mesh) { TreeNode node = treeView1.SelectedNode; TreeNode parent = node.Parent; NUD.Mesh m = (NUD.Mesh)node.Tag; NUD n = (NUD)parent.Tag; int pos = n.mesh.IndexOf(m) - 1; if (pos < 0) { pos = 0; } n.mesh.Remove(m); n.mesh.Insert(pos, m); parent.Nodes.Remove(node); parent.Nodes.Insert(pos, node); treeView1.SelectedNode = node; n.PreRender(); } } }