/// <summary> /// The main function for reading and converting said .d3dtx into a .dds file /// </summary> /// <param name="sourceFile"></param> /// <param name="destinationFile"></param> public static void ConvertTexture_FromD3DTX_ToDDS(string sourceFile, string destinationFile) { //string file_dword = D3DTX_File.Read_D3DTX_File_MetaVersionOnly(sourceFile); D3DTX_Master d3dtx_file = new D3DTX_Master(); d3dtx_file.Read_D3DTX_File(sourceFile); DDS_Master dds_file = new DDS_Master(d3dtx_file); //write the dds file to disk dds_file.Write_D3DTX_AsDDS(d3dtx_file, destinationFile); //write the d3dtx data into a file (json for newer versions, .header for older versions) d3dtx_file.Write_D3DTX_JSON(destinationFile); //GenericImageFormats.ConvertDDS_To_PSD(destinationFile); }
/// <summary> /// The main function for reading and converting said .dds back into a .d3dtx file /// </summary> /// <param name="sourceFile"></param> /// <param name="destinationFile"></param> public static void ConvertTexture_FromDDS_ToD3DTX(string sourceFilePath, string resultDirectoryPath) { //deconstruct the source file path string textureFileDirectory = Path.GetDirectoryName(sourceFilePath); string textureFileNameOnly = Path.GetFileNameWithoutExtension(sourceFilePath); //create the names of the following files string textureFileNameWithD3DTX = textureFileNameOnly + D3DTX_Master.d3dtxExtension; string textureFileNameWithHEADER = textureFileNameOnly + D3DTX_Master.headerExtension; string textureFileNameWithJSON = textureFileNameOnly + D3DTX_Master.jsonExtension; //create the path of these files. If things go well, these files (depending on the version) should exist in the same directory at the original .dds file. string textureFilePath_HEADER = textureFileDirectory + "/" + textureFileNameWithHEADER; string textureFilePath_JSON = textureFileDirectory + "/" + textureFileNameWithJSON; //create the final path of the d3dtx string textureResultPath_D3DTX = resultDirectoryPath + "/" + textureFileNameWithD3DTX; //if a json file exists (for newer 5VSM and 6VSM) if (File.Exists(textureFilePath_JSON)) { //read in our DDS file DDS_Master dds = new DDS_Master(sourceFilePath, false); //dds parse test //dds.TEST_WriteDDSToDisk(sourceFilePath); //create our d3dtx object D3DTX_Master d3dtx_file = new D3DTX_Master(); //parse the .json file as a d3dtx d3dtx_file.Read_D3DTX_JSON(textureFilePath_JSON); //modify the d3dtx file using our dds data d3dtx_file.Modify_D3DTX(dds); //ISSUE HERE WITH DXT5 AND MIP MAPS WITH UPSCALED TEXTURES //write our final d3dtx file to disk d3dtx_file.Write_Final_D3DTX(textureResultPath_D3DTX); //File.Delete(textureFilePath_JSON); //File.Delete(sourceFilePath); } //if there is no .json, check for a .header (for versions older than 5VSM) else if (File.Exists(textureFilePath_HEADER)) { ConsoleFunctions.SetConsoleColor(ConsoleColor.Black, ConsoleColor.Red); Console.WriteLine("Converting d3dtx older than 5VSM not supported yet!!!!"); Console.WriteLine("{0}", textureFileNameOnly); Console.WriteLine("Skipping conversion on this file.", textureFileNameOnly); ConsoleFunctions.SetConsoleColor(ConsoleColor.Black, ConsoleColor.White); return; } //if we found neither, we're screwed! else { ConsoleFunctions.SetConsoleColor(ConsoleColor.Black, ConsoleColor.Red); Console.WriteLine("No .json or .header was found for the file were trying to convert!!!!"); Console.WriteLine("{0}", textureFileNameOnly); Console.WriteLine("Skipping conversion on this file.", textureFileNameOnly); ConsoleFunctions.SetConsoleColor(ConsoleColor.Black, ConsoleColor.White); return; } }