private void OnConvert(object sender, EventArgs e) { // Show the user a file dialog if (!resourceDialog.Open()) { return; } // Parse the model data ReadFile(resourceDialog.FileName); }
protected void AdjustResourcePath() { if (!resourceDialog.Open()) { return; } resourcePath = Common.GetPath(resourceDialog.FileName); }
private JurassicReader ReadFile(string fileName) { JurassicReader reader = new JurassicReader(); if (!reader.Read(resourceDialog.FileName)) { MessageBox.Show(resourceDialog.FileName + "\n\nERROR: File encountered an error while parsing!", "Export failed!"); return(null); } string resourceName = resourceDialog.FileName; string extension = Common.GetExtension(resourceName); if (reader.reader is IMeshReader) { Mesh mesh = reader.mesh; if (mesh == null) { return(reader); } // Fetch missing textures string texType = "dds"; List <string> missingTextures = new List <string>(); string path = Common.GetPath(resourceName); foreach (string texture in mesh.GetTextures()) { if (texture.StartsWith("color_")) { continue; } if (!File.Exists(path + "\\" + texture + "." + texType)) { missingTextures.Add(texture); } } if (missingTextures.Count > 0) { MessageBox.Show("Missing " + missingTextures.Count + " texture" + (missingTextures.Count > 1 ? "s" : "") + "! Please specify the texture directory."); string destinationDir = Common.GetPath(resourceDialog.FileName); if (textureDialog.Open()) { string texturePath = Common.GetPath(textureDialog.FileName); foreach (string texture in missingTextures) { string textureName = texture + "." + texType; if (!File.Exists(texturePath + "\\" + textureName)) { MessageBox.Show("Couldn't locate " + textureName + "!"); continue; } File.Copy(texturePath + "\\" + textureName, destinationDir + "\\" + textureName); } } } // Output the mesh data to a Wavefront OBJ String meshOutputName = resourceName.Replace("." + Common.GetExtension(resourceName), ".obj"); String mtlOutputName = meshOutputName.Replace(".obj", ".mtl"); String mtlName = mtlOutputName.Substring(mtlOutputName.LastIndexOf("\\") + 1); File.WriteAllText(meshOutputName, mesh.GetObjData(mtlName)); File.WriteAllText(mtlOutputName, mesh.GetMtlData()); // Show the user it worked MessageBox.Show(meshOutputName + "\n\nProcessed " + mesh.Chunks.Count + " chunks.\n" + mesh.Vertices.Count + " vertices exported.", "Export successful!"); } return(reader); }