Пример #1
0
        private void addBlankMeshToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (treeView1.SelectedNode is NUD)
            {
                NUD nud = (NUD)treeView1.SelectedNode;

                NUD.Mesh m = new NUD.Mesh();

                int  i         = 0;
                bool foundName = false;
                while (!foundName)
                {
                    m.Text    = $"Blank Mesh {i++}";
                    foundName = true;
                    foreach (NUD.Mesh mesh in nud.Nodes)
                    {
                        if (mesh.Text.Equals(m.Text))
                        {
                            foundName = false;
                        }
                    }
                }

                nud.Nodes.Add(m);

                refresh();
            }
        }
Пример #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.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.UpdateRenderMesh();

            return(n);
        }
Пример #3
0
        private void belowToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (treeView1.SelectedNode is NUD.Mesh)
            {
                NUD.Mesh m = ((NUD.Mesh)treeView1.SelectedNode);

                NUD nud = (NUD)(m.Parent);

                int index = nud.Nodes.IndexOf(m);

                if (index + 1 < nud.Nodes.Count)
                {
                    nud.Nodes.Remove(m);

                    NUD.Mesh merge = (NUD.Mesh)nud.Nodes[index];

                    List <TreeNode> polygons = new List <TreeNode>();
                    foreach (NUD.Polygon p in m.Nodes)
                    {
                        polygons.Add(p);
                    }

                    foreach (NUD.Polygon p in polygons)
                    {
                        m.Nodes.Remove(p);
                        merge.Nodes.Add(p);
                    }

                    refresh();
                }
            }
        }
Пример #4
0
        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);
                }
            }
        }
Пример #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            using (var ofd = new OpenFileDialog())
            {
                ofd.Filter = "Namco Model (.nud)|*.nud";
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    string filename     = ofd.FileName;
                    NUD    nud          = new NUD(filename);
                    NUD    unorderedNud = (NUD)treeView1.SelectedNode.Tag;
                    //Gonna reorder some NUDs, NUD-in to it
                    int meshCount = nud.mesh.Count;
                    if (unorderedNud.mesh.Count > meshCount)
                    {
                        meshCount = unorderedNud.mesh.Count;
                    }
                    NUD.Mesh[] meshes = new NUD.Mesh[meshCount];

                    //Fill in matching meshes
                    foreach (NUD.Mesh m in nud.mesh)
                    {
                        foreach (NUD.Mesh m2 in unorderedNud.mesh)
                        {
                            if (m2.Name == m.Name)
                            {
                                meshes[nud.mesh.IndexOf((m))] = m2;
                                break;
                            }
                        }
                    }
                    //Fill in mismatched meshes
                    foreach (NUD.Mesh m in unorderedNud.mesh)
                    {
                        if (!meshes.Contains(m))
                        {
                            for (int i = 0; i < meshes.Length; i++)
                            {
                                if (meshes[i] == null)
                                {
                                    meshes[i] = m;
                                    break;
                                }
                            }
                        }
                    }
                    //Dummies for the dummies that don't make enough meshes
                    for (int i = 0; i < meshes.Length; i++)
                    {
                        if (meshes[i] == null)
                        {
                            meshes[i]      = new NUD.Mesh();
                            meshes[i].Name = "dummy";
                            break;
                        }
                    }

                    refresh();
                }
            }
        }
Пример #6
0
        private void singleBindToBoneToolStripMenuItem_Click(object sender, EventArgs e)
        {
            /*if(mc.vbn.bones == null)
             * {
             *  MessageBox.Show("No Skeleton Found");
             *  return;
             * }*/
            NUD.Mesh mesh = (NUD.Mesh)treeView1.SelectedNode;
            char[]   d    = "None".ToCharArray();
            LVDEditor.StringWrapper str = new LVDEditor.StringWrapper()
            {
                data = d
            };
            foreach (TreeNode node in treeView1.Nodes)
            {
                if (node is ModelContainer)
                {
                    ModelContainer mc = (ModelContainer)node;
                    if (treeView1.SelectedNode.Parent == mc.NUD)
                    {
                        if (mc.VBN.bones.Count > mesh.singlebind && mesh.singlebind != -1)
                        {
                            str = new LVDEditor.StringWrapper()
                            {
                                data = mc.VBN.bones[mesh.singlebind].Text.ToCharArray()
                            }
                        }
                    }
                    ;
                }
            }

            BoneRiggingSelector brs = new BoneRiggingSelector(str)
            {
                ModelContainers = GetModelContainers()
            };

            brs.ShowDialog();
            if (!brs.Cancelled)
            {
                mesh.boneflag   = 8;
                mesh.singlebind = brs.boneIndex;
                foreach (NUD.Polygon poly in mesh.Nodes)
                {
                    poly.polflag  = 0;
                    poly.vertSize = poly.vertSize & 0x0F;
                    foreach (NUD.Vertex vi in poly.vertices)
                    {
                        vi.node.Clear();
                        vi.node.Add(mesh.singlebind);
                        vi.weight.Clear();
                        vi.weight.Add(1);
                    }
                }
                ((NUD)treeView1.SelectedNode.Parent).PreRender();
            }
        }
Пример #7
0
        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);
                }
            }
        }
Пример #8
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);
        }
Пример #9
0
        // 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"))
                {
                    NutTexture tex = new DDS(new FileData(b)).ToNutTexture();
                    nut.Nodes.Add(tex);
                    tex.HashId = 0x40000000 + randomNumber;
                    nut.glTexByHashId.Add(tex.HashId, NUT.CreateTexture2D(tex));
                }
            }

            NUD nud = new NUD();

            NUD.Mesh head = new NUD.Mesh();
            nud.Nodes.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.UpdateRenderMeshes();

            return(nud);
        }
Пример #10
0
        private void addBlankMeshToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (treeView1.SelectedNode.Tag is NUD)
            {
                NUD nud = (NUD)treeView1.SelectedNode.Tag;

                NUD.Mesh m = new NUD.Mesh();

                m.Text = "Blank Mesh";

                nud.mesh.Add(m);

                refresh();
            }
        }
Пример #11
0
        private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (treeView1.SelectedNode is NUD.Mesh)
            {
                NUD.Mesh mesh = (NUD.Mesh)treeView1.SelectedNode;
                char[]   d    = "None".ToCharArray();
                LVDEditor.StringWrapper str = new LVDEditor.StringWrapper()
                {
                    data = d
                };
                foreach (ModelContainer mc in Runtime.ModelContainers)
                {
                    if (treeView1.SelectedNode.Parent.Tag == mc.nud)
                    {
                        if (mc.vbn.bones.Count > mesh.singlebind && mesh.singlebind != -1)
                        {
                            str = new LVDEditor.StringWrapper()
                            {
                                data = mc.vbn.bones[mesh.singlebind].boneName
                            }
                        }
                    }
                }
                ;

                BoneRiggingSelector brs = new BoneRiggingSelector(str);
                brs.ShowDialog();
                if (!brs.Cancelled)
                {
                    mesh.singlebind = brs.boneIndex;
                    foreach (NUD.Polygon poly in mesh.polygons)
                    {
                        foreach (NUD.Vertex vi in poly.vertices)
                        {
                            vi.node.Clear();
                            vi.node.Add(mesh.singlebind);
                            vi.weight.Clear();
                            vi.weight.Add(1);
                        }
                    }
                    ((NUD)treeView1.SelectedNode.Parent.Tag).PreRender();
                }
            }
            else if (treeView1.SelectedNode is NUD.Polygon)
            {
                polySelected((NUD.Polygon)treeView1.SelectedNode, $"{treeView1.SelectedNode.Parent.Text} {treeView1.SelectedNode.Text}");
            }
        }
Пример #12
0
        private void singleBindToBoneToolStripMenuItem_Click(object sender, EventArgs e)
        {
            NUD.Mesh mesh = (NUD.Mesh)treeView1.SelectedNode;
            char[]   d    = "None".ToCharArray();
            LVDEditor.StringWrapper str = new LVDEditor.StringWrapper()
            {
                data = d
            };
            foreach (ModelContainer mc in Runtime.ModelContainers)
            {
                if (treeView1.SelectedNode.Parent.Tag == mc.nud)
                {
                    if (mc.vbn.bones.Count > mesh.singlebind && mesh.singlebind != -1)
                    {
                        str = new LVDEditor.StringWrapper()
                        {
                            data = mc.vbn.bones[mesh.singlebind].boneName
                        }
                    }
                }
            }
            ;

            BoneRiggingSelector brs = new BoneRiggingSelector(str);

            brs.ShowDialog();
            if (!brs.Cancelled)
            {
                mesh.boneflag   = 8;
                mesh.singlebind = brs.boneIndex;
                foreach (NUD.Polygon poly in mesh.polygons)
                {
                    poly.polflag  = 0;
                    poly.vertSize = poly.vertSize & 0x0F;
                    foreach (NUD.Vertex vi in poly.vertices)
                    {
                        vi.node.Clear();
                        vi.node.Add(mesh.singlebind);
                        vi.weight.Clear();
                        vi.weight.Add(1);
                    }
                }
                ((NUD)treeView1.SelectedNode.Parent.Tag).PreRender();
            }
        }
Пример #13
0
 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();
         }
     }
 }
Пример #14
0
 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
 }
Пример #15
0
        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();
            }
        }
Пример #16
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);
        }
Пример #17
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);
        }
Пример #18
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;
        }
Пример #19
0
        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();
                }
            }
        }
Пример #20
0
        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();
                }
            }
        }