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; } } int uvCount = poly.UVSize >> 4; int colorType = poly.UVSize & 0x0F; uvCountUpDown.Value = uvCount; vertexColorCB.Checked = colorType != 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.vertexIndices.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.UpdateRenderMeshes(); return(n); }
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 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.vertexIndices.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 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); }
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(); if (OpenTkSharedResources.SetupStatus == OpenTkSharedResources.SharedResourceStatus.Initialized) { // Only happens once. UpdateMaterialThumbnails(); } }
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); }
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]).vertexIndices.Add(((Nud.Polygon)mes.Nodes[0]).vertices.Count); ((Nud.Polygon)mes.Nodes[0]).vertices.Add(vert); } } } } nud.OptimizeFileSize(); nud.UpdateRenderMeshes(); return(nud); }