From 8b643aef65e3cc187756cf0876b3fbf596b3dc77 Mon Sep 17 00:00:00 2001 From: biwa <6475593+biwa@users.noreply.github.com> Date: Fri, 6 Nov 2020 20:59:13 +0100 Subject: [PATCH] Wavefront OBJ exporter: improved handling of long texture names. Probably fixes #495 --- .../BuilderModes/IO/WavefrontExporter.cs | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/Source/Plugins/BuilderModes/IO/WavefrontExporter.cs b/Source/Plugins/BuilderModes/IO/WavefrontExporter.cs index 1e137ae2..2fe56895 100755 --- a/Source/Plugins/BuilderModes/IO/WavefrontExporter.cs +++ b/Source/Plugins/BuilderModes/IO/WavefrontExporter.cs @@ -163,7 +163,12 @@ namespace CodeImp.DoomBuilder.BuilderModes.IO Bitmap bmp = id.ExportBitmap(); lock (bmp) { - bmp.Save(Path.Combine(settings.ObjPath, Path.GetFileNameWithoutExtension(s) + ".PNG"), ImageFormat.Png); + string filepath = Path.Combine(settings.ObjPath, Path.GetDirectoryName(s), Path.GetFileNameWithoutExtension(s) + ".png"); + + // Make sure the directory is there + Directory.CreateDirectory(Path.GetDirectoryName(filepath)); + + bmp.Save(filepath, ImageFormat.Png); } } else @@ -232,9 +237,12 @@ namespace CodeImp.DoomBuilder.BuilderModes.IO foreach(string s in settings.Textures) { if(s == DEFAULT) continue; - mtl.Append("newmtl " + s.ToUpperInvariant() + Environment.NewLine); + + string filepath = Path.Combine(settings.ObjPath, Path.GetDirectoryName(s), Path.GetFileNameWithoutExtension(s) + ".png"); + + mtl.Append("newmtl " + s + Environment.NewLine); mtl.Append("Kd 1.0 1.0 1.0" + Environment.NewLine); - if(settings.ExportTextures) mtl.Append("map_Kd " + Path.Combine(settings.ObjPath, s.ToUpperInvariant() + ".PNG") + Environment.NewLine); + if(settings.ExportTextures) mtl.Append("map_Kd " + filepath + Environment.NewLine); mtl.Append(Environment.NewLine); } } @@ -244,16 +252,18 @@ namespace CodeImp.DoomBuilder.BuilderModes.IO foreach(string s in settings.Flats) { if(s == DEFAULT) continue; - mtl.Append("newmtl " + s.ToUpperInvariant() + Environment.NewLine); + mtl.Append("newmtl " + s + Environment.NewLine); mtl.Append("Kd 1.0 1.0 1.0" + Environment.NewLine); if(settings.ExportTextures) { // Handle duplicate names - string flatname = s; + string flatsuffix = string.Empty; if(settings.Textures != null && Array.IndexOf(settings.Textures, s) != -1) - flatname += "_FLAT"; + flatsuffix = "_FLAT"; - mtl.Append("map_Kd " + Path.Combine(settings.ObjPath, flatname.ToUpperInvariant() + ".PNG") + Environment.NewLine); + string filepath = Path.Combine(settings.ObjPath, Path.GetDirectoryName(s), Path.GetFileNameWithoutExtension(s) + flatsuffix + ".png"); + + mtl.Append("map_Kd " + Path.Combine(settings.ObjPath, filepath) + Environment.NewLine); } mtl.Append(Environment.NewLine); }