Ejemplo n.º 1
0
 private void vertexListBox_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (vertexListBox.SelectedIndex >= 0)
     {
         SelectedVertex = ((Nud.Vertex)vertexListBox.SelectedItem);
     }
 }
Ejemplo n.º 2
0
        public void LoadVertexInfo(Nud.Vertex v)
        {
            boneWeightList.Items.Clear();
            if (v == null)
            {
                return;
            }
            if (!(vp.draw[0] is ModelContainer))
            {
                return;
            }
            ModelContainer con = (ModelContainer)vp.draw[0];

            if (con.VBN == null)
            {
                return;
            }
            VBN = con.VBN;
            if (v.boneIds.Count > 0)
            {
                boneWeightList.Items.Add(con.VBN.bones[v.boneIds[0] > -1 ? v.boneIds[0] : 0].Text + " _ " + v.boneWeights[0]);
            }
            if (v.boneIds.Count > 1)
            {
                boneWeightList.Items.Add(con.VBN.bones[v.boneIds[1] > -1 ? v.boneIds[1] : 0].Text + " _ " + v.boneWeights[1]);
            }
            if (v.boneIds.Count > 2)
            {
                boneWeightList.Items.Add(con.VBN.bones[v.boneIds[2] > -1 ? v.boneIds[2] : 0].Text + " _ " + v.boneWeights[2]);
            }
            if (v.boneIds.Count > 3)
            {
                boneWeightList.Items.Add(con.VBN.bones[v.boneIds[3] > -1 ? v.boneIds[3] : 0].Text + " _ " + v.boneWeights[3]);
            }
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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);
        }