private void importAllTexturesToolStripMenuItem_Click(object sender, EventArgs e) { if (textureTreeView.Nodes.Count == 0) { return; } try { string directory = filePath.Replace(".", "_") + "_textures"; if (Directory.Exists(directory) == true) { DdsFile dds; foreach (string fileName in Directory.GetFiles(directory, "*.dds")) { for (int i = 0; i < textureTreeView.Nodes.Count; i++) { if (Path.GetFileNameWithoutExtension(fileName) == textureTreeView.Nodes[i].Text) { dds = new DdsFile(File.Open(fileName, FileMode.Open)); dds.Write(((PssgNode)textureTreeView.Nodes[i].Tag)); break; } } } if (textureTreeView.SelectedNode != null) { createPreview(((PssgNode)textureTreeView.SelectedNode.Tag)); } MessageBox.Show("Textures imported successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Could not find textures folder!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch { MessageBox.Show("There was an error, could not import all textures!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void importTextureToolStripMenuItem_Click(object sender, EventArgs e) { if (textureTreeView.Nodes.Count == 0 || textureTreeView.SelectedNode.Index == -1) { return; } PssgNode node = ((PssgNode)textureTreeView.SelectedNode.Tag); OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "Dds files|*.dds|All files|*.*"; dialog.Title = "Select a dds file"; dialog.FileName = node.Attributes["id"].ToString() + ".dds"; if (dialog.ShowDialog() == DialogResult.OK) { try { DdsFile dds = new DdsFile(File.Open(dialog.FileName, FileMode.Open)); dds.Write(node); } catch (Exception ex) { MessageBox.Show("Could not import texture!" + Environment.NewLine + Environment.NewLine + ex.Message, "Import Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } createPreview(node); } }
private void exportAllTexturesToolStripMenuItem_Click(object sender, EventArgs e) { if (textureTreeView.Nodes.Count == 0) { return; } try { Directory.CreateDirectory(filePath.Replace(".", "_") + "_textures"); DdsFile dds; for (int i = 0; i < textureTreeView.Nodes.Count; i++) { dds = new DdsFile(((PssgNode)textureTreeView.Nodes[i].Tag), false); dds.Write(File.Open(filePath.Replace(".", "_") + "_textures" + "\\" + textureTreeView.Nodes[i].Text + ".dds", FileMode.Create), -1); } MessageBox.Show("Textures exported successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch { MessageBox.Show("There was an error, could not export all textures!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void cubeMapImportToolStripButton_Click(object sender, EventArgs e) { if (cubeMapTreeView.Nodes.Count == 0 || cubeMapTreeView.SelectedNode.Index == -1) { return; } PssgNode node = ((PssgNode)cubeMapTreeView.SelectedNode.Tag); OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "DDS files|*.dds|All files|*.*"; dialog.Title = "Select a cubemap dds file"; dialog.FileName = node.Attributes["id"].ToString() + ".dds"; dialog.Multiselect = true; if (dialog.ShowDialog() == DialogResult.OK) { try { DdsFile dds = new DdsFile(File.Open(dialog.FileName, FileMode.Open)); dds.Write(node); } catch (Exception ex) { MessageBox.Show("Could not import cubemap!" + Environment.NewLine + Environment.NewLine + ex.Message, "Import Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } cubeMapPictureBox.Tag = 0; CubeMapCreatePreview(node, 0); } }
private void cubeMapExportToolStripButton_Click(object sender, EventArgs e) { if (cubeMapTreeView.Nodes.Count == 0 || cubeMapTreeView.SelectedNode.Index == -1) { return; } PssgNode node = ((PssgNode)cubeMapTreeView.SelectedNode.Tag); SaveFileDialog dialog = new SaveFileDialog(); dialog.Filter = "DDS files|*.dds|All files|*.*"; dialog.Title = "Select the dds save location and file name"; dialog.FileName = node.Attributes["id"].ToString() + ".dds"; if (dialog.ShowDialog() == DialogResult.OK) { try { DdsFile dds = new DdsFile(node, false); dds.Write(File.Open(dialog.FileName, FileMode.Create), -1); } catch (Exception ex) { MessageBox.Show("Could not export cubemap!" + Environment.NewLine + Environment.NewLine + ex.Message, "Export Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void CubeMapCreatePreview(PssgNode node, int targetCount) { // Make Preview try { cubeMapImageLabel.Text = ""; int height = 0; int width = 0; cubeMapPictureBox.Dock = DockStyle.Fill; height = cubeMapPictureBox.Height; width = cubeMapPictureBox.Width; FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_DDS; System.Drawing.Bitmap image = null; if (targetCount > 5) { targetCount = 0; cubeMapPictureBox.Tag = 0; } else { cubeMapPictureBox.Tag = targetCount; } DdsFile dds = new DdsFile(node, false); dds.Write(File.Open(Application.StartupPath + "\\temp.dds", FileMode.Create), targetCount); image = FreeImage.LoadBitmap(Application.StartupPath + "\\temp.dds", FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format); if (cubeMapPictureBox.Image != null) { cubeMapPictureBox.Image.Dispose(); cubeMapPictureBox.Image = null; } /*foreach (CNode sub in node.subNodes) { if (targetCount == 0 && sub.attributes["typename"].ToString() == "Raw") { CubeMapWriteDDS(Application.StartupPath + "\\temp" + "Raw" + ".dds", node, targetCount); image = FreeImage.LoadBitmap(Application.StartupPath + "\\temp" + "Raw" + ".dds", FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format); } else if (targetCount == 1 && sub.attributes["typename"].ToString() == "RawNegativeX") { CubeMapWriteDDS(Application.StartupPath + "\\temp" + "RawNegativeX" + ".dds", node, targetCount); image = FreeImage.LoadBitmap(Application.StartupPath + "\\temp" + "RawNegativeX" + ".dds", FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format); } else if (targetCount == 2 && sub.attributes["typename"].ToString() == "RawPositiveY") { CubeMapWriteDDS(Application.StartupPath + "\\temp" + "RawPositiveY" + ".dds", node, targetCount); image = FreeImage.LoadBitmap(Application.StartupPath + "\\temp" + "RawPositiveY" + ".dds", FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format); } else if (targetCount == 3 && sub.attributes["typename"].ToString() == "RawNegativeY") { CubeMapWriteDDS(Application.StartupPath + "\\temp" + "RawNegativeY" + ".dds", node, targetCount); image = FreeImage.LoadBitmap(Application.StartupPath + "\\temp" + "RawNegativeY" + ".dds", FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format); } else if (targetCount == 4 && sub.attributes["typename"].ToString() == "RawPositiveZ") { CubeMapWriteDDS(Application.StartupPath + "\\temp" + "RawPositiveZ" + ".dds", node, targetCount); image = FreeImage.LoadBitmap(Application.StartupPath + "\\temp" + "RawPositiveZ" + ".dds", FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format); } else if (targetCount == 5 && sub.attributes["typename"].ToString() == "RawNegativeZ") { CubeMapWriteDDS(Application.StartupPath + "\\temp" + "RawNegativeZ" + ".dds", node, targetCount); image = FreeImage.LoadBitmap(Application.StartupPath + "\\temp" + "RawNegativeZ" + ".dds", FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format); } }*/ if (image.Height <= height && image.Width <= width) { cubeMapPictureBox.Dock = DockStyle.None; cubeMapPictureBox.Width = image.Width; cubeMapPictureBox.Height = image.Height; } cubeMapPictureBox.Image = image; } catch { if (cubeMapPictureBox.Image != null) { cubeMapPictureBox.Image.Dispose(); cubeMapPictureBox.Image = null; } cubeMapImageLabel.Text = "Could not create preview!"; //MessageBox.Show("Could not create preview!", "No Preview", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
private void createPreview(PssgNode node) { // Make Preview try { textureImageLabel.Text = ""; int height = 0; int width = 0; texturePictureBox.Dock = DockStyle.Fill; height = texturePictureBox.Height; width = texturePictureBox.Width; DdsFile dds = new DdsFile(node, false); dds.Write(File.Open(Application.StartupPath + "\\temp.dds", FileMode.Create, FileAccess.ReadWrite, FileShare.Read), -1); // Dispose of Old Images if (texturePictureBox.Image != null) { texturePictureBox.Image.Dispose(); texturePictureBox.Image = null; } // Setup New Image FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_DDS; System.Drawing.Bitmap image = FreeImage.LoadBitmap(Application.StartupPath + "\\temp.dds", FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format); if (image.Height <= height && image.Width <= width) { texturePictureBox.Dock = DockStyle.None; texturePictureBox.Width = image.Width; texturePictureBox.Height = image.Height; } texturePictureBox.Image = image; } catch (Exception ex) { if (texturePictureBox.Image != null) { texturePictureBox.Image.Dispose(); texturePictureBox.Image = null; } textureImageLabel.Text = "Could not create preview! Export/Import may still work in certain circumstances." + Environment.NewLine + Environment.NewLine + ex.Message; //MessageBox.Show("Could not create preview! Export/Import may still work in certain circumstances." + Environment.NewLine + Environment.NewLine // + ex.Message, "No Preview", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }