public override bool LoadStaticObject(string path, System.Text.Encoding Encoding, bool PreserveVertices, out StaticObject Object) { if (base.LoadStaticObject(path, Encoding, PreserveVertices, out Object)) { return(true); } if (System.IO.File.Exists(path) || System.IO.Directory.Exists(path)) { Encoding = TextEncoding.GetSystemEncodingFromFile(path, Encoding); for (int i = 0; i < Program.CurrentHost.Plugins.Length; i++) { if (Program.CurrentHost.Plugins[i].Object != null) { try { if (Program.CurrentHost.Plugins[i].Object.CanLoadObject(path)) { try { UnifiedObject unifiedObject; if (Program.CurrentHost.Plugins[i].Object.LoadObject(path, Encoding, out unifiedObject)) { StaticObject staticObject = unifiedObject as StaticObject; if (staticObject != null) { staticObject.OptimizeObject(PreserveVertices, Interface.CurrentOptions.ObjectOptimizationBasicThreshold, Interface.CurrentOptions.ObjectOptimizationVertexCulling); Object = staticObject; StaticObjectCache.Add(ValueTuple.Create(path, PreserveVertices), Object); return(true); } Object = null; Interface.AddMessage(MessageType.Error, false, "Attempted to load " + path + " which is an animated object where only static objects are allowed."); } Interface.AddMessage(MessageType.Error, false, "Plugin " + Program.CurrentHost.Plugins[i].Title + " returned unsuccessfully at LoadObject"); } catch (Exception ex) { Interface.AddMessage(MessageType.Error, false, "Plugin " + Program.CurrentHost.Plugins[i].Title + " raised the following exception at LoadObject:" + ex.Message); } } } catch (Exception ex) { Interface.AddMessage(MessageType.Error, false, "Plugin " + Program.CurrentHost.Plugins[i].Title + " raised the following exception at CanLoadObject:" + ex.Message); } } } Interface.AddMessage(MessageType.Error, false, "No plugin found that is capable of loading object " + path); } else { ReportProblem(OpenBveApi.Hosts.ProblemType.PathNotFound, path); } Object = null; return(false); }
internal static StaticObject LoadStaticObject(string FileName, Encoding Encoding, bool PreserveVertices) { if (String.IsNullOrEmpty(FileName)) { return(null); } #if !DEBUG try { #endif if (!System.IO.Path.HasExtension(FileName)) { while (true) { string f = OpenBveApi.Path.CombineFile(System.IO.Path.GetDirectoryName(FileName), System.IO.Path.GetFileName(FileName) + ".x"); if (System.IO.File.Exists(f)) { FileName = f; break; } f = OpenBveApi.Path.CombineFile(System.IO.Path.GetDirectoryName(FileName), System.IO.Path.GetFileName(FileName) + ".csv"); if (System.IO.File.Exists(f)) { FileName = f; break; } f = OpenBveApi.Path.CombineFile(System.IO.Path.GetDirectoryName(FileName), System.IO.Path.GetFileName(FileName) + ".b3d"); if (System.IO.File.Exists(f)) { FileName = f; } break; } } StaticObject Result = null; string e = System.IO.Path.GetExtension(FileName); if (e == null) { Interface.AddMessage(MessageType.Error, false, "The file " + FileName + " does not have a recognised extension."); return(null); } switch (e.ToLowerInvariant()) { case ".csv": case ".b3d": case ".x": case ".obj": UnifiedObject obj; Program.CurrentHost.LoadObject(FileName, Encoding, out obj); Result = (StaticObject)obj; break; case ".animated": case ".s": Interface.AddMessage(MessageType.Error, false, "Tried to load an animated object even though only static objects are allowed: " + FileName); break; /* * This will require implementing a specific static object load function- Leave alone for the moment * * case ".xml": * Result = XMLParser.ReadObject(FileName, Encoding, ForceTextureRepeatX, ForceTextureRepeatY); * break; */ default: Interface.AddMessage(MessageType.Error, false, "The file extension is not supported: " + FileName); return(null); } if (Result != null) { Result.OptimizeObject(PreserveVertices, Interface.CurrentOptions.ObjectOptimizationBasicThreshold, Interface.CurrentOptions.ObjectOptimizationVertexCulling); } return(Result); #if !DEBUG } catch (Exception ex) { Interface.AddMessage(MessageType.Error, true, "An unexpected error occured (" + ex.Message + ") while attempting to load the file " + FileName); return(null); } #endif }