private void extractToolStripMenuItem_Click(object sender, EventArgs e) { // Get the name of the bitmap for the dialog. string fileName = System.IO.Path.GetFileName(this.Bitmap.FileName); fileName = fileName.Substring(0, fileName.LastIndexOf('.')); // Display an open file dialog to save a dds file. SaveFileDialog sfd = new SaveFileDialog(); sfd.FileName = fileName; sfd.Filter = "DDS Image (*.dds)|*.dds"; if (sfd.ShowDialog() == DialogResult.OK) { // Build a dds image from the rtexture file. DDSImage ddsImage = DDSImage.FromGameTexture(this.Bitmap); // Write the dds image to file. if (ddsImage.WriteToFile(sfd.FileName) == false) { // Failed to save the bitmap. MessageBox.Show("Failed to write bitmap to file!"); } else { // TODO: Come up with a more elegant way to tell the user. MessageBox.Show("Success"); } } }
public static bool ExportModel(rModel model, string outputFolder) { // Setup xml writer formatting settings. XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = " "; settings.NewLineChars = "\r\n"; settings.Encoding = Encoding.UTF8; // Create a new xml writer for the output collada file. string modelName = Path.GetFileName(model.FileName).Replace(".rModel", ""); using (XmlWriter writer = XmlWriter.Create(string.Format("{0}\\{1}.dae", outputFolder, modelName), settings)) { // Write the xml header. writer.WriteStartDocument(); // Write the collada element start. writer.WriteStartElement("COLLADA", "http://www.collada.org/2004/COLLADASchema"); writer.WriteAttributeString("version", "1.4.1"); // Write the asset element. writer.WriteStartElement("asset"); writer.WriteStartElement("contributor"); writer.WriteElementString("authoring_tool", "Dead Rising Arc Tool"); writer.WriteFullEndElement(); writer.WriteElementString("created", DateTime.Now.ToString()); writer.WriteElementString("modified", DateTime.Now.ToString()); writer.WriteFullEndElement(); // Write the images library element. writer.WriteStartElement("library_images"); { // Loop and write and image element for every texture the model has. for (int i = 0; i < model.textureFileNames.Length; i++) { // Get name of the texture. string textureName = Path.GetFileName(model.textureFileNames[i]); // Find the arc file the resource is in. string textureFileName = GameResource.GetFullResourceName(model.textureFileNames[i], ResourceType.rTexture); ArchiveCollection.Instance.GetArchiveFileEntryFromFileName(textureFileName, out Archive.Archive arcFile, out ArchiveFileEntry fileEntry); if (arcFile == null || fileEntry == null) { // Failed to find a resource with the specified name. return(false); } // Parse the game resource and cast it to rtexture. rTexture texture = arcFile.GetFileAsResource <rTexture>(textureFileName); // Save the texture to a dds image that can be loaded with the model. DDSImage ddsImage = DDSImage.FromGameTexture(texture); if (ddsImage.WriteToFile(string.Format("{0}\\{1}.dds", outputFolder, textureName)) == false) { // Failed to extract texture to file. return(false); } // Write the image element. writer.WriteStartElement("image"); writer.WriteAttributeString("name", textureName); writer.WriteElementString("init_from", "./" + textureName + ".dds"); writer.WriteFullEndElement(); } } writer.WriteFullEndElement(); // Write the materials library element. //writer.WriteStartElement("library_materials"); //{ // // Loop through all of the materials and write each one. // for (int i = 0; i < model.materials.Length; i++) // { // // Write the material element. // writer.WriteStartElement("material"); // writer.WriteAttributeString("id", "Material " + i.ToString()); // } //} //writer.WriteFullEndElement(); // TODO: Joints // Write the geometries library element. writer.WriteStartElement("library_geometries"); { // Loop through all the primitives and write each one. for (int i = 0; i < model.primitives.Length; i++) { // Write the primitive to file. WritePrimitiveBlock(model, writer, i); } } writer.WriteFullEndElement(); // Write the collada and document end. writer.WriteEndElement(); writer.WriteEndDocument(); // Flush to file. writer.Close(); return(true); } }