convert VB to C#
This commit is contained in:
144
Pilz.Simple3DFileParser/Other/LoaderModule.cs
Normal file
144
Pilz.Simple3DFileParser/Other/LoaderModule.cs
Normal file
@@ -0,0 +1,144 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using global::Assimp.Unmanaged;
|
||||
|
||||
namespace Pilz.S3DFileParser
|
||||
{
|
||||
public class File3DLoaderModule
|
||||
{
|
||||
public delegate Object3D LoaderAction(string fileName, LoaderOptions options);
|
||||
|
||||
public delegate void ExporterAction(Object3D obj, string fileName);
|
||||
|
||||
private static File3DLoaderModule[] _LoaderModules = null;
|
||||
private static File3DLoaderModule[] _ExporterModules = null;
|
||||
private readonly Delegate method = null;
|
||||
|
||||
public string Name { get; private set; }
|
||||
public IReadOnlyDictionary<string, string> SupportedFormats { get; private set; }
|
||||
|
||||
public File3DLoaderModule(string name, LoaderAction method, IReadOnlyDictionary<string, string> supportedFormats)
|
||||
{
|
||||
Name = name;
|
||||
this.method = method;
|
||||
SupportedFormats = supportedFormats;
|
||||
}
|
||||
|
||||
public File3DLoaderModule(string name, ExporterAction method, IReadOnlyDictionary<string, string> supportedFormats)
|
||||
{
|
||||
Name = name;
|
||||
this.method = method;
|
||||
SupportedFormats = supportedFormats;
|
||||
}
|
||||
|
||||
public Task InvokeAsync(Object3D obj, string fileName)
|
||||
{
|
||||
return Task.Run(() => Invoke(obj, fileName));
|
||||
}
|
||||
|
||||
public void Invoke(Object3D obj, string fileName)
|
||||
{
|
||||
method.Method.Invoke(null, new object[] { obj, fileName });
|
||||
}
|
||||
|
||||
public Task<Object3D> InvokeAsync(string fileName, LoaderOptions options)
|
||||
{
|
||||
return Task.Run(() => Invoke(fileName, options));
|
||||
}
|
||||
|
||||
public Object3D Invoke(string fileName, LoaderOptions options)
|
||||
{
|
||||
return (Object3D)method.Method.Invoke(null, new object[] { fileName, options });
|
||||
}
|
||||
|
||||
public static File3DLoaderModule[] LoaderModules
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_LoaderModules is null)
|
||||
{
|
||||
_LoaderModules = GetLoaderModules();
|
||||
}
|
||||
|
||||
return _LoaderModules;
|
||||
}
|
||||
}
|
||||
|
||||
public static File3DLoaderModule[] ExporterModules
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_ExporterModules is null)
|
||||
{
|
||||
_ExporterModules = GetExporterModules();
|
||||
}
|
||||
|
||||
return _ExporterModules;
|
||||
}
|
||||
}
|
||||
|
||||
private static File3DLoaderModule[] GetLoaderModules()
|
||||
{
|
||||
var list = new List<File3DLoaderModule>();
|
||||
list.Add(new File3DLoaderModule("Simple File Parser", LoadViaSimpleFileParser, new Dictionary<string, string>() { { "obj", "OBJ" } }));
|
||||
AssimpModule.AssimpLoader.LoadAssimpLibs();
|
||||
var exts = new Dictionary<string, string>();
|
||||
foreach (Assimp.ExportFormatDescription fd in AssimpLibrary.Instance.GetExportFormatDescriptions())
|
||||
{
|
||||
if (!exts.ContainsKey(fd.FileExtension))
|
||||
{
|
||||
exts.Add(fd.FileExtension, fd.FormatId + " - " + fd.Description);
|
||||
}
|
||||
}
|
||||
|
||||
exts.Add("blend", "Blender");
|
||||
list.Add(new File3DLoaderModule("Assimp", LoadViaAssimp, exts));
|
||||
list.Add(new File3DLoaderModule("Aspose.3D", LoadViaAspose3D, new Dictionary<string, string>() { { "obj", "OBJ" }, { "dae", "DAE" }, { "fbx", "FBX" }, { "stl", "STL" }, { "3ds", "3DS" }, { "3d", "3D" }, { "gltf", "glTF" }, { "drc", "DRC" }, { "rvm", "RVM" }, { "pdf", "PDF" }, { "x", "X" }, { "jt", "JT" }, { "dfx", "DFX" }, { "ply", "PLY" }, { "3mf", "3MF" }, { "ase", "ASE" } }));
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
private static File3DLoaderModule[] GetExporterModules()
|
||||
{
|
||||
var list = new List<File3DLoaderModule>();
|
||||
list.Add(new File3DLoaderModule("Simple File Parser", ExportViaSimpleFileParser, new Dictionary<string, string>() { { "obj", "OBJ" } }));
|
||||
AssimpModule.AssimpLoader.LoadAssimpLibs();
|
||||
var exts = new Dictionary<string, string>();
|
||||
foreach (Assimp.ExportFormatDescription fd in AssimpLibrary.Instance.GetExportFormatDescriptions())
|
||||
{
|
||||
if (!exts.ContainsKey(fd.FileExtension))
|
||||
exts.Add(fd.FileExtension, fd.FormatId + " - " + fd.Description);
|
||||
}
|
||||
|
||||
list.Add(new File3DLoaderModule("Assimp", ExportViaAssimp, exts));
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
private static Object3D LoadViaSimpleFileParser(string fileName, LoaderOptions options)
|
||||
{
|
||||
return ObjModule.ObjFile.FromFile(fileName, options.LoadMaterials, options.UpAxis);
|
||||
}
|
||||
|
||||
private static Object3D LoadViaAssimp(string fileName, LoaderOptions options)
|
||||
{
|
||||
AssimpModule.AssimpLoader.LoadAssimpLibs();
|
||||
return AssimpModule.AssimpLoader.FromFile(fileName, options.LoadMaterials, options.UpAxis);
|
||||
}
|
||||
|
||||
private static Object3D LoadViaAspose3D(string fileName, LoaderOptions options)
|
||||
{
|
||||
return Aspose3DModule.Aspose3DLoader.FromFile(fileName, options.LoadMaterials, options.UpAxis);
|
||||
}
|
||||
|
||||
private static void ExportViaSimpleFileParser(Object3D o, string fileName)
|
||||
{
|
||||
ObjModule.ObjFile.ToFile(fileName, o);
|
||||
}
|
||||
|
||||
private static void ExportViaAssimp(Object3D o, string fileName)
|
||||
{
|
||||
AssimpModule.AssimpLoader.LoadAssimpLibs();
|
||||
AssimpModule.AssimpLoader.ToFile(fileName, o);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user