AvatarPreview.frmAvatar.lindenLabMeshToolStripMenuItem_Click C# (CSharp) Method

lindenLabMeshToolStripMenuItem_Click() private method

private lindenLabMeshToolStripMenuItem_Click ( object sender, EventArgs e ) : void
sender object
e EventArgs
return void
        private void lindenLabMeshToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "avatar_lad.xml|avatar_lad.xml";

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                _meshes.Clear();

                try
                {
                    // Parse through avatar_lad.xml to find all of the mesh references
                    XmlDocument lad = new XmlDocument();
                    lad.Load(dialog.FileName);

                    XmlNodeList meshes = lad.GetElementsByTagName("mesh");

                    foreach (XmlNode meshNode in meshes)
                    {
                        string type = meshNode.Attributes.GetNamedItem("type").Value;
                        int lod = Int32.Parse(meshNode.Attributes.GetNamedItem("lod").Value);
                        string fileName = meshNode.Attributes.GetNamedItem("file_name").Value;
                        string minPixelWidth = meshNode.Attributes.GetNamedItem("min_pixel_width").Value;

                        // Mash up the filename with the current path
                        fileName = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(dialog.FileName), fileName);

                        GLMesh mesh = (_meshes.ContainsKey(type) ? _meshes[type] : new GLMesh(type));

                        if (lod == 0)
                        {
                            mesh.LoadMesh(fileName);
                        }
                        else
                        {
                            mesh.LoadLODMesh(lod, fileName);
                        }

                        _meshes[type] = mesh;
                        glControl_Resize(null, null);
                        glControl.Invalidate();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Failed to load avatar mesh: " + ex.Message);
                }
            }
        }