diff --git a/AssimpNet/AssimpContext.cs b/AssimpNet/AssimpContext.cs index cfc3b01..d8ba7ed 100755 --- a/AssimpNet/AssimpContext.cs +++ b/AssimpNet/AssimpContext.cs @@ -238,11 +238,11 @@ public Scene ImportFile(string file) /// Thrown if there was a general error in importing the model. /// Thrown if the file could not be located. /// Thrown if the context has already been disposed of. - public Scene ImportFile(string file, PostProcessSteps postProcessFlags) + public unsafe Scene ImportFile(string file, PostProcessSteps postProcessFlags) { CheckDisposed(); - IntPtr ptr = IntPtr.Zero; + AiScene* ptr = null; IntPtr fileIO = IntPtr.Zero; //Only do file checks if not using a custom IOSystem @@ -259,24 +259,24 @@ public Scene ImportFile(string file, PostProcessSteps postProcessFlags) try { - ptr = AssimpLibrary.Instance.ImportFile(file, PostProcessSteps.None, fileIO, m_propStore); + ptr = AssimpLibrary.aiImportFileExWithProperties(file, PostProcessSteps.None, (AiFileIO*)fileIO, m_propStore); - if(ptr == IntPtr.Zero) + if(ptr == null) throw new AssimpException("Error importing file: " + AssimpLibrary.Instance.GetErrorString()); - TransformScene(ptr); + TransformScene(new(ptr)); - ptr = ApplyPostProcessing(ptr, postProcessFlags); + ptr = (AiScene*)ApplyPostProcessing(new(ptr), postProcessFlags); - return Scene.FromUnmanagedScene(ptr); + return Scene.FromUnmanagedScene(new(ptr)); } finally { CleanupImport(); - if(ptr != IntPtr.Zero) + if(ptr != null) { - AssimpLibrary.Instance.ReleaseImport(ptr); + AssimpLibrary.Instance.ReleaseImport(new(ptr)); } } } @@ -444,7 +444,7 @@ public bool ConvertFromFileToFile(string inputFilename, string outputFilename, s /// Thrown if there was a general error in importing the model. /// Thrown if the file could not be located. /// Thrown if the context has already been disposed of. - public bool ConvertFromFileToFile(string inputFilename, PostProcessSteps importProcessSteps, string outputFilename, string exportFormatId, PostProcessSteps exportProcessSteps) + public unsafe bool ConvertFromFileToFile(string inputFilename, PostProcessSteps importProcessSteps, string outputFilename, string exportFormatId, PostProcessSteps exportProcessSteps) { CheckDisposed(); @@ -468,7 +468,7 @@ public bool ConvertFromFileToFile(string inputFilename, PostProcessSteps importP try { - ptr = AssimpLibrary.Instance.ImportFile(inputFilename, PostProcessSteps.None, fileIO, m_propStore); + ptr = (IntPtr)AssimpLibrary.aiImportFileExWithProperties(inputFilename, PostProcessSteps.None, (AiFileIO*)fileIO, m_propStore); if(ptr == IntPtr.Zero) throw new AssimpException("Error importing file: " + AssimpLibrary.Instance.GetErrorString()); @@ -534,7 +534,7 @@ public ExportDataBlob ConvertFromFileToBlob(string inputFilename, string exportF /// Thrown if there was a general error in importing the model. /// Thrown if the file could not be located. /// Thrown if the context has already been disposed of. - public ExportDataBlob ConvertFromFileToBlob(string inputFilename, PostProcessSteps importProcessSteps, string exportFormatId, PostProcessSteps exportProcessSteps) + public unsafe ExportDataBlob ConvertFromFileToBlob(string inputFilename, PostProcessSteps importProcessSteps, string exportFormatId, PostProcessSteps exportProcessSteps) { CheckDisposed(); @@ -558,7 +558,7 @@ public ExportDataBlob ConvertFromFileToBlob(string inputFilename, PostProcessSte try { - ptr = AssimpLibrary.Instance.ImportFile(inputFilename, PostProcessSteps.None, fileIO, m_propStore); + ptr = (IntPtr)AssimpLibrary.aiImportFileExWithProperties(inputFilename, PostProcessSteps.None, (AiFileIO*)fileIO, m_propStore); if(ptr == IntPtr.Zero) throw new AssimpException("Error importing file: " + AssimpLibrary.Instance.GetErrorString()); diff --git a/AssimpNet/Unmanaged/AssimpLibrary.cs b/AssimpNet/Unmanaged/AssimpLibrary.cs index d7ead1f..badd20f 100755 --- a/AssimpNet/Unmanaged/AssimpLibrary.cs +++ b/AssimpNet/Unmanaged/AssimpLibrary.cs @@ -30,7 +30,7 @@ namespace Assimp.Unmanaged /// /// Singleton that governs access to the unmanaged Assimp library functions. /// - public sealed class AssimpLibrary : UnmanagedLibrary + public sealed partial class AssimpLibrary : UnmanagedLibrary { private static readonly object s_sync = new object(); @@ -83,9 +83,9 @@ private static AssimpLibrary CreateInstance() /// Post process flags specifying what steps are to be run after the import. /// Property store containing config name-values, may be null. /// Pointer to the unmanaged data structure. - public IntPtr ImportFile(string file, PostProcessSteps flags, IntPtr propStore) + public static unsafe IntPtr ImportFile(string file, PostProcessSteps flags, IntPtr propStore) { - return ImportFile(file, flags, IntPtr.Zero, propStore); + return (IntPtr)aiImportFileExWithProperties(file, flags, null, propStore); } /// @@ -97,14 +97,8 @@ public IntPtr ImportFile(string file, PostProcessSteps flags, IntPtr propStore) /// any associated file the loader needs to open, passing NULL uses the default implementation. /// Property store containing config name-values, may be null. /// Pointer to the unmanaged data structure. - public IntPtr ImportFile(string file, PostProcessSteps flags, IntPtr fileIO, IntPtr propStore) - { - LoadIfNotLoaded(); - - Functions.aiImportFileExWithProperties func = GetFunction(FunctionNames.aiImportFileExWithProperties); - - return func(file, (uint) flags, fileIO, propStore); - } + [LibraryImport("assimp", StringMarshalling = StringMarshalling.Utf8)] + public static unsafe partial AiScene* aiImportFileExWithProperties(string file, PostProcessSteps flags, AiFileIO* fileIO, IntPtr propStore); /// /// Imports a scene from a stream. This uses the "aiImportFileFromMemory" function. The stream can be from anyplace, @@ -1076,7 +1070,6 @@ internal static class FunctionNames public const string aiImportFile = "aiImportFile"; public const string aiImportFileEx = "aiImportFileEx"; - public const string aiImportFileExWithProperties = "aiImportFileExWithProperties"; public const string aiImportFileFromMemory = "aiImportFileFromMemory"; public const string aiImportFileFromMemoryWithProperties = "aiImportFileFromMemoryWithProperties"; public const string aiReleaseImport = "aiReleaseImport"; @@ -1176,7 +1169,7 @@ internal static class FunctionNames /// /// Defines all of the delegates that represent the unmanaged assimp functions. /// - internal static class Functions + internal static partial class Functions { #region Import Delegates @@ -1187,9 +1180,6 @@ internal static class Functions [UnmanagedFunctionPointer(CallingConvention.Cdecl), UnmanagedFunctionName(FunctionNames.aiImportFileEx)] public delegate IntPtr aiImportFileEx([In, MarshalAs(UnmanagedType.LPUTF8Str)] string file, uint flags, IntPtr fileIO); - [UnmanagedFunctionPointer(CallingConvention.Cdecl), UnmanagedFunctionName(FunctionNames.aiImportFileExWithProperties)] - public delegate IntPtr aiImportFileExWithProperties([In, MarshalAs(UnmanagedType.LPUTF8Str)] string file, uint flag, IntPtr fileIO, IntPtr propStore); - [UnmanagedFunctionPointer(CallingConvention.Cdecl), UnmanagedFunctionName(FunctionNames.aiImportFileFromMemory)] public delegate IntPtr aiImportFileFromMemory(byte[] buffer, uint bufferLength, uint flags, [In, MarshalAs(UnmanagedType.LPUTF8Str)] string formatHint);