Exemple #1
0
        public void LoadVertexInfo(NUD.Vertex v)
        {
            ModelContainer con = vp.draw[0];

            boneWeightList.Items.Clear();
            if (con.vbn == null)
            {
                return;
            }
            if (v.node.Count > 0)
            {
                boneWeightList.Items.Add(con.vbn.bones[v.node[0] > -1 ? v.node[0] : 0].Text + " _ " + v.weight[0]);
            }
            if (v.node.Count > 1)
            {
                boneWeightList.Items.Add(con.vbn.bones[v.node[1] > -1 ? v.node[1] : 0].Text + " _ " + v.weight[1]);
            }
            if (v.node.Count > 2)
            {
                boneWeightList.Items.Add(con.vbn.bones[v.node[2] > -1 ? v.node[2] : 0].Text + " _ " + v.weight[2]);
            }
            if (v.node.Count > 3)
            {
                boneWeightList.Items.Add(con.vbn.bones[v.node[3] > -1 ? v.node[3] : 0].Text + " _ " + v.weight[3]);
            }
        }
Exemple #2
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);
        }
Exemple #3
0
 private void vertexListBox_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (vertexListBox.SelectedIndex >= 0)
     {
         SelectedVertex = ((NUD.Vertex)vertexListBox.SelectedItem);
     }
 }
Exemple #4
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]);
            }
        }
Exemple #5
0
 private void vertexListBox_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (vertexListBox.SelectedIndex >= 0)
     {
         ModelContainer con = vp.draw[0];
         NUD.Vertex     v   = (NUD.Vertex)vertexListBox.SelectedItem;
         SelectVertex(v);
         LoadVertexInfo(v);
     }
 }
Exemple #6
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.faces.Add(indexSim.IndexOf(v));
                    }
                }
            }
            return(nud);
        }
Exemple #7
0
        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);
        }
Exemple #8
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);
        }
Exemple #9
0
        private void SelectVertex(NUD.Vertex v)
        {
            ModelContainer con = vp.draw[0];

            foreach (NUD.Mesh mesh in con.nud.mesh)
            {
                foreach (NUD.Polygon poly in mesh.Nodes)
                {
                    for (int i = 0; i < poly.vertices.Count; i++)
                    {
                        if (poly.selectedVerts[i] < 0)
                        {
                            poly.selectedVerts[i] = 1;
                        }
                        if (poly.vertices[i] == v)
                        {
                            poly.selectedVerts[i] = -1;
                            return;
                        }
                    }
                }
            }
        }
Exemple #10
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]).faces.Add(((NUD.Polygon)mes.Nodes[0]).vertices.Count);
                            ((NUD.Polygon)mes.Nodes[0]).vertices.Add(vert);
                        }
                    }
                }
            }

            nud.OptimizeFileSize();
            nud.UpdateVertexData();
            return(nud);
        }
Exemple #11
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.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;
        }