public PolygonFormatEditor(NUD.Polygon poly) : this() { this.poly = poly; int weightType = poly.vertSize & 0xF0; int normalType = poly.vertSize & 0x0F; foreach (string key in WeightTypes.Keys) { if (weightType == WeightTypes[key]) { weightTypeComboBox.SelectedIndex = weightTypeComboBox.FindStringExact(key); break; } } foreach (string key in NormalTypes.Keys) { if (normalType == NormalTypes[key]) { normalTypeComboBox.SelectedIndex = normalTypeComboBox.FindStringExact(key); break; } } vertexColorCB.Checked = poly.UVSize >> 4 != 0; }
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.AddDefaultMaterial(); 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.UpdateVertexData(); return(n); }
private void flipUVsHorizontalToolStripMenuItem_Click(object sender, EventArgs e) { if (treeView1.SelectedNode is NUD.Polygon) { NUD.Polygon p = (NUD.Polygon)treeView1.SelectedNode; foreach (NUD.Vertex v in p.vertices) { for (int i = 0; i < v.uv.Count; i++) { v.uv[i] = new OpenTK.Vector2(1 - v.uv[i].X, v.uv[i].Y); } } foreach (TreeNode con in treeView1.Nodes) { if (con is ModelContainer) { if (((ModelContainer)con).NUD != null) { ((ModelContainer)con).NUD.PreRender(); } } } } }
public void openMats(NUD.Polygon poly, string name) { (new NUDMaterialEditor(poly) { ShowHint = DockState.Float, Text = name }).Show(); }
public NUDMaterialEditor(NUD.Polygon p) { InitializeComponent(); this.poly = p; this.material = p.materials; Init(); FillForm(); comboBox1.SelectedIndex = 0; }
public static NUD.Polygon scale(NUD.Polygon poly, float sx, float sy, float sz) { foreach (NUD.Vertex v in poly.vertices) { v.pos.X = v.pos.X * sx; v.pos.Y = v.pos.Y * sy; v.pos.Z = v.pos.Z * sz; if (sx == -1) v.pos = Vector3.TransformVector(v.pos, Matrix4.CreateRotationX((float)Math.PI)); } return poly; }
private static void WriteMaterials(XmlDocument doc, NUD.Polygon p, XmlNode polynode) { foreach (NUD.Material mat in p.materials) { XmlNode matnode = doc.CreateElement("material"); polynode.AppendChild(matnode); WriteMatAttributes(doc, mat, matnode); WriteTextureAttributes(doc, mat, matnode); WriteMatParams(doc, mat, matnode); } }
public NUDMaterialEditor(NUD.Polygon p) { InitializeComponent(); currentPolygon = p; currentMaterialList = p.materials; Init(); FillForm(); matsComboBox.SelectedIndex = 0; // The dummy textures will be used later. RenderTools.Setup(); }
public NUD toNUD() { NUD nud = new NUD(); int j = 0; foreach (Mesh m in mesh) { NUD.Mesh n_mesh = new NUD.Mesh(); nud.Nodes.Add(n_mesh); n_mesh.Text = "Mesh_" + j++; foreach (List <int> i in m.faces) { NUD.Polygon poly = new NUD.Polygon(); n_mesh.Nodes.Add(poly); poly.AddDefaultMaterial(); List <Vertex> indexSim = new List <Vertex>(); foreach (int index in i) { Vertex v = vertices[index]; if (!indexSim.Contains(v)) { indexSim.Add(v); NUD.Vertex vert = new NUD.Vertex(); vert.pos = v.pos; vert.nrm = v.nrm; vert.color = v.col; List <Vector2> uvs = new List <Vector2>(); uvs.Add(new Vector2(v.tx[0].X, 1 - v.tx[0].Y)); vert.uv = uvs; if (vert.boneWeights.Count < 4) { v.weight.Add(0f); v.weight.Add(0f); } vert.boneWeights = v.weight; List <int> nodez = new List <int>(); nodez.Add(m.nodeList[0][v.node[0]]); nodez.Add(m.nodeList[0][v.node[1]]); nodez.Add(0); nodez.Add(0); vert.boneIds = nodez; poly.AddVertex(vert); } poly.faces.Add(indexSim.IndexOf(v)); } } } return(nud); }
public static NUD.Polygon setToBone(NUD.Polygon poly, Bone b, VBN vbn) { foreach (NUD.Vertex v in poly.vertices) { v.boneIds.Clear(); v.boneIds.Add(vbn.bones.IndexOf(b)); Vector3 newpos = Vector3.TransformVector(Vector3.Zero, b.transform); v.pos += newpos; } return(poly); }
public NUDMaterialEditor(NUD.Polygon p) : this() { currentPolygon = p; currentMaterialList = p.materials; Init(); FillForm(); ResizeGlControlsToMaxSquareSize(glControlTableLayout); matsComboBox.SelectedIndex = 0; texturesListView.LargeImageList = textureThumbnails; RefreshTexturesImageList(); // The dummy textures will be used later. OpenTKSharedResources.InitializeSharedResources(); // Only happens once. UpdateMaterialThumbnails(); }
private void detachToolStripMenuItem_Click(object sender, EventArgs e) { if (treeView1.SelectedNode is NUD.Polygon) { NUD.Polygon p = ((NUD.Polygon)treeView1.SelectedNode); NUD.Mesh parent = (NUD.Mesh)p.Parent; p.Parent.Nodes.Remove(p); NUD.Mesh m = new NUD.Mesh(); ((NUD)parent.Parent.Tag).mesh.Add(m); m.Text = parent.Text + "_" + p.Text; m.Nodes.Add(p); if (parent.Nodes.Count == 0) { ((NUD)parent.Parent.Tag).mesh.Remove(parent); } refresh(); } }
public NUD toNUD() { NUD nud = new NUD(); int j = 0; foreach (Mesh m in mesh) { NUD.Mesh n_mesh = new NUD.Mesh(); nud.mesh.Add(n_mesh); n_mesh.Text = "Mesh_" + j++; foreach (List <int> i in m.faces) { NUD.Polygon poly = new NUD.Polygon(); n_mesh.polygons.Add(poly); poly.setDefaultMaterial(); List <Vertex> indexSim = new List <Vertex>(); foreach (int index in i) { Vertex v = vertices[index]; if (!indexSim.Contains(v)) { indexSim.Add(v); NUD.Vertex vert = new NUD.Vertex(); vert.pos = v.pos; vert.nrm = v.nrm; vert.col = v.col; vert.tx = v.tx; vert.weight = v.weight; vert.node = v.node; poly.AddVertex(vert); } poly.faces.Add(indexSim.IndexOf(v)); } } } return(nud); }
public static NUD.Polygon readPoly(string input) { NUD.Polygon poly = new NUD.Polygon(); poly.AddDefaultMaterial(); string[] lines = input.Replace(" ", " ").Split('\n'); int vi = 0; NUD.Vertex v; for (int i = 0; i < lines.Length; i++) { string[] args = lines[i].Split(' '); switch (args[0]) { case "v": v = new NUD.Vertex(); v.pos.X = float.Parse(args[1]); v.pos.Y = float.Parse(args[2]); v.pos.Z = float.Parse(args[3]); v.boneIds.Add(-1); v.boneWeights.Add(1); poly.vertices.Add(v); break; case "vt": v = poly.vertices[vi++]; v.uv.Add(new Vector2(float.Parse(args[1]), float.Parse(args[2]))); break; case "f": poly.vertexIndices.Add(int.Parse(args[1].Split('/')[0]) - 1); poly.vertexIndices.Add(int.Parse(args[2].Split('/')[0]) - 1); poly.vertexIndices.Add(int.Parse(args[3].Split('/')[0]) - 1); break; } } return(poly); }
private void generateTanBitanToolStripMenuItem1_Click(object sender, EventArgs e) { if (treeView1.SelectedNode is NUD.Polygon) { NUD.Polygon p = ((NUD.Polygon)treeView1.SelectedNode); // Don't generate tangents/bitangents if the vertex size doesn't support them. int vertType = p.vertSize & 0xF; if (vertType == 3 || vertType == 7) { p.CalculateTangentBitangent(); } else { string meshName = p.Parent.Text; MessageBox.Show("Tangents/bitangents cannot be saved for the current vertex type. \n" + "Make sure to select Normals, Tan, Bi-Tan (Half-Float) or \n" + "Normals, Tan, Bi-Tan (Float) in the DAE import settings.", meshName + ": Incorrect Vertex Type"); } } }
private void flipUVsHorizontalToolStripMenuItem_Click(object sender, EventArgs e) { if (treeView1.SelectedNode is NUD.Polygon) { NUD.Polygon p = (NUD.Polygon)treeView1.SelectedNode; foreach (NUD.Vertex v in p.vertices) { for (int i = 0; i < v.tx.Count; i++) { v.tx[i] = new OpenTK.Vector2(1 - v.tx[i].X, v.tx[i].Y); } } foreach (ModelContainer con in Runtime.ModelContainers) { if (con.nud != null) { con.nud.PreRender(); } } } }
private void checkSelect() { if (CurrentMode == Mode.Selection) { Vector2 m = GetMouseOnViewport(); if (!m.Equals(new Vector2(sx1, sy1))) { // select group of vertices float minx = Math.Min(sx1, m.X); float miny = Math.Min(sy1, m.Y); float width = Math.Abs(sx1 - m.X); float height = Math.Abs(sy1 - m.Y); foreach (TreeNode node in draw) { if (!(node is ModelContainer)) { continue; } ModelContainer con = (ModelContainer)node; foreach (NUD.Mesh mesh in con.NUD.Nodes) { foreach (NUD.Polygon poly in mesh.Nodes) { //if (!poly.IsSelected && !mesh.IsSelected) continue; int i = 0; foreach (NUD.Vertex v in poly.vertices) { if (!OpenTK.Input.Keyboard.GetState().IsKeyDown(OpenTK.Input.Key.ControlLeft)) { poly.selectedVerts[i] = 0; } Vector3 n = getScreenPoint(v.pos); if (n.X >= minx && n.Y >= miny && n.X <= minx + width && n.Y <= miny + height) { poly.selectedVerts[i] = 1; } i++; } } } } } else { // single vertex // Selects the closest vertex Ray r = RenderTools.createRay(Camera.getMVPMatrix(), GetMouseOnViewport()); Vector3 close = Vector3.Zero; foreach (TreeNode node in draw) { if (!(node is ModelContainer)) { continue; } ModelContainer con = (ModelContainer)node; NUD.Polygon Close = null; int index = 0; double mindis = 999; foreach (NUD.Mesh mesh in con.NUD.Nodes) { foreach (NUD.Polygon poly in mesh.Nodes) { //if (!poly.IsSelected && !mesh.IsSelected) continue; int i = 0; foreach (NUD.Vertex v in poly.vertices) { //if (!poly.IsSelected) continue; if (!OpenTK.Input.Keyboard.GetState().IsKeyDown(OpenTK.Input.Key.ControlLeft)) { poly.selectedVerts[i] = 0; } if (r.TrySphereHit(v.pos, 0.2f, out close)) { double dis = r.Distance(close); if (dis < mindis) { mindis = dis; Close = poly; index = i; } } i++; } } } if (Close != null) { Close.selectedVerts[index] = 1; } } } VertexTool.vertexListBox.BeginUpdate(); VertexTool.vertexListBox.Items.Clear(); foreach (TreeNode node in draw) { if (!(node is ModelContainer)) { continue; } ModelContainer con = (ModelContainer)node; foreach (NUD.Mesh mesh in con.NUD.Nodes) { foreach (NUD.Polygon poly in mesh.Nodes) { int i = 0; foreach (NUD.Vertex v in poly.vertices) { if (poly.selectedVerts[i++] == 1) { VertexTool.vertexListBox.Items.Add(v); } } } } } VertexTool.vertexListBox.EndUpdate(); CurrentMode = Mode.Normal; } }
private void polySelected(NUD.Polygon poly, string name) { MainForm.Instance.openMats(poly, name); }
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.boneIds.Add(int.Parse(args[w++])); vert.boneWeights.Add(float.Parse(args[w++])); } NUD.Mesh mes = null; foreach (NUD.Mesh m in nud.Nodes) { if (m.Text.Equals(meshName)) { mes = m; } } if (mes == null) { mes = new NUD.Mesh(); mes.Text = meshName; nud.Nodes.Add(mes); } if (mes.Nodes.Count == 0) { NUD.Polygon poly = new NUD.Polygon(); poly.AddDefaultMaterial(); mes.Nodes.Add(poly); } { ((NUD.Polygon)mes.Nodes[0]).faces.Add(((NUD.Polygon)mes.Nodes[0]).vertices.Count); ((NUD.Polygon)mes.Nodes[0]).vertices.Add(vert); } } } } nud.OptimizeFileSize(); nud.UpdateVertexData(); return(nud); }
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(); } } }
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; }