private void lvFiles_SelectedIndexChanged(object sender, EventArgs e) { if (lvFiles.SelectedItems.Count <= 0) { pbPreview.Width = 0; pbPreview.Visible = false; rtbPreview.Width = 0; rtbPreview.Visible = false; splitContainer.SplitterDistance = this.Width; lbSelection.Text = String.Empty; return; } if (File.Exists(currentMeshFile)) { File.Delete(currentMeshFile); } if (File.Exists(currentMeshFile + ".mtl")) { File.Delete(currentMeshFile + ".mtl"); } if (glControl != null) { if (glControl.GLrender != null) { glControl.GLrender.ClearAllObjects(); glControl.GLrender.GLControlInstance.Dispose(); } glControl.Dispose(); } ListViewItem Item = lvFiles.SelectedItems[0]; lbSelection.Text = String.Format("Sel {0}", Item.Index + 1); ImageListIndex indx = FileType.GetImageIndex(Path.GetExtension(Item.Text)); if (indx == ImageListIndex.Image) { pbPreview.Width = 399; pbPreview.Visible = true; rtbPreview.Width = 0; rtbPreview.Visible = false; pnlPreview.Visible = false; ArchiveEntry ent = m_Archive.getByName(Path.GetFileNameWithoutExtension(Item.Text)); Image img = null; using (MemoryStream ms = new MemoryStream(ent.getData())) { try { if (Path.GetExtension(Item.Text) == ".tga") { TargaImage tgaImg = new TargaImage(ms); img = tgaImg.Image; } else { img = Image.FromStream(ms); } } catch { } } if (img != null) { pbPreview.Image = img; pbPreview.Width = img.Width; pbPreview.Location = new Point(pbPreview.Location.X, (this.Height / 2) - (img.Height / 2) - 20); splitContainer.SplitterDistance = Math.Max(this.Width - img.Width - 20, 200); } } else if (indx == ImageListIndex.Text) { pbPreview.Width = 0; pbPreview.Visible = false; rtbPreview.Width = 500; rtbPreview.Visible = true; pnlPreview.Visible = false; splitContainer.SplitterDistance = this.Width - 500; rtbPreview.Text = ""; ArchiveEntry ent = m_Archive.getByName(Path.GetFileNameWithoutExtension(Item.Text)); if (ent != null) { rtbPreview.Text = Encoding.Default.GetString(ent.getData()); } } else if (indx == ImageListIndex.Mesh) { pnlPreview.Visible = true; splitContainer.SplitterDistance = this.Width - 500; glControl = new OGLControl(); glControl.Parent = pnlPreview; glControl.Dock = DockStyle.Fill; glContext = new OpenGLContext(glControl); glControl.GLrender.PrimitiveTypes = OpenTK.Graphics.OpenGL.PrimitiveType.Triangles; glControl.GLrender.Camera.ZNear = 0.01f; glControl.GLrender.Camera.ZFar = float.MaxValue; string tempFile = Path.GetTempFileName(); currentMeshFile = Path.ChangeExtension(Path.GetTempFileName(), "obj"); ArchiveEntry ent = m_Archive.getByName(Path.GetFileNameWithoutExtension(Item.Text)); ent.extractTo(tempFile, true); using (AssimpContext context = new AssimpContext()) { Scene mesh = context.ImportFile(tempFile); context.ExportFile(mesh, currentMeshFile, "obj"); } File.Delete(tempFile); Model model = new Model(currentMeshFile); glControl.GLrender.AddModel(model); glControl.GLrender.SelectedModelIndex = 0; } else { pbPreview.Width = 0; pbPreview.Visible = false; rtbPreview.Width = 0; rtbPreview.Visible = false; pnlPreview.Visible = false; } }