Hello, i was trying to use the "assimp.net" library in unity (via C#-Script). I compiled the C#-Version of the library with ".Net v3.5" as target. However, i still have trouble calling library functions. For those who do not know assimp: it's a C++ library for loading 3D models (at runtime). There's also a C#-Wrapper library (called assimp.net). I'm getting following exception: Code (csharp): NotImplementedException: The requested feature is not implemented. System.Runtime.InteropServices.Marshal.GetHRForLastWin32Error () (at /Applications/buildAgent/work/b59ae78cff80e584/mcs/class/corlib/System.Runtime.InteropServices/Marshal.cs:412) Assimp.Unmanaged.AssimpLibraryImplementation.LoadLibrary (System.String path) Assimp.Unmanaged.AssimpLibrary.LoadLibrary (System.String libPath) Assimp.Unmanaged.AssimpLibrary.LoadLibrary (System.String lib32Path, System.String lib64Path) Assimp.Unmanaged.AssimpLibrary.LoadLibrary () Assimp.Unmanaged.AssimpLibrary.LoadIfNotLoaded () Assimp.Unmanaged.AssimpLibrary.EnableVerboseLogging (Boolean enable) Assimp.AssimpImporter.PrepareImport () Assimp.AssimpImporter.ImportFile (System.String file, PostProcessSteps postProcessFlags) NewBehaviourScript.Start () (at Assets/Scripts/NewBehaviourScript.cs:20) The unity3d documentation say, though, that this method should be compatible with the version of .Net unity is using (http://docs.unity3d.com/Documentation/ScriptReference/MonoCompatibility.html). Maybe anyone had similar problems using external libraries?
Marshal.GetHRForLastWin32Error isn't implemented in Mono at all (my guess being that it's specific to Windows so they decided to simply throw a not implemented exception). The real reason you're getting that is because the assembly can't be loaded and it's attempting to get more information as to why. Are you using Pro?
Hey, thanks for the answer. I'm using the 30-days trial, so yeah that should be pro. Actually the only thing i've done is checking out http://assimp-net.googlecode.com/svn/trunk and compiling the project (after changing target framework to ".net 3.5"). Then i imported the resulting "dll" into the "Plugins"-subfolder of the unity3d-project's assets-folder. Then i created a new C#-behaviour script with very simple code to test if the library is accessible from there. Well, assimp-net is just a C#-wrapper for the C++-project, so do i need to take care of something else i missed? Any ideas would be very appriciated. I'm quite sure some guys already managed to use assimp in unity (because that's how i got the idea from google) but somehow i got stuck at this point.
I got to the point you did before remembering that you need Pro for native plugins. I bypassed the issue you have by just commenting out the calls to that method which just result in less-useful error messages being displayed when the assembly fails to load. So if you get anywhere, I'd be curious to know what you come up with.
btw. i'm using another library (for zipping/unzipping files) so that should not be the problem. Best thing i can offer is another part of the code where i call library functions, i guess: Code (csharp): using UnityEngine; using System.Collections; using Assimp; using Assimp.Configs; public class NewBehaviourScript : MonoBehaviour { // Use this for initialization void Start () { string fileName = "C:/Users/Timm/Downloads/Monster_1/em1000.obj"; //Create a new importer AssimpImporter importer = new AssimpImporter(); // THIS SEEMS TO WORK Scene model = importer.ImportFile(fileName); // THIS THROWS THE EXCEPTION importer.Dispose(); } // Update is called once per frame void Update () { } } P.s: okey, had a look into the C# code which is throwing an exception. So you're right, it fails to load the "Assimp32.dll" (the actual C++ lib). Now i installed the complete assimp-sdk, but still doesn't find the dll. That's probably not too amazing because i really have no clue where to put it ... :-(
Sorry for the double-post. The solution is to put the "Assimp32/64.dll" into the project folder. From there the wrapper class finds it ...
Interesting - this goes along with what someone posted a week or so ago with native code DLLs loading ok from the root directory - which isn't mentioned in the documentation.
Hey, another question concering a similar problem. I want to run the same C# script on Android now, and the adb-logcat output says "unable to find Assimp32.dll". Any idea, where to put the dll to deploy it on the android device?
One problem is that the assimpnet.dll looks for the assimpPLATFORM.dll (i.e. assimp64.dll) in your PATH/TO/PROJECT/ProjectName folder. The assimpnet.dll is not written to look for the dlls dynamically and expects them to be in the executable directory (https://msdn.microsoft.com/en-us/library/system.io.directory.getcurrentdirectory(v=vs.110).aspx) If you copy them in there it should work. Sorry for necroing this thread but mayhaps someone still needs this little piece of advice.
Hey guys, I'm also attempting to get assimp up and running using the assimp-net library. However, after fixing the problem addressed in this thread, I'm receiving the following error: NullReferenceException: Object reference not set to an instance of an object (wrapper stelemref) object:stelemref (object,intptr,object) System.String.Format (System.String format, System.Object arg0, System.Object arg1, System.Object arg2) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System/String.cs:1863) Assimp.Material.CreateFullyQualifiedName (System.String baseName, TextureType texType, Int32 texIndex) Assimp.MaterialProperty.get_FullyQualifiedName () Assimp.Material.AddProperty (Assimp.MaterialProperty matProp) Assimp.Material.Assimp.IMarshalable<Assimp.Material,Assimp.Unmanaged.AiMaterial>.FromNative (Assimp.Unmanaged.AiMaterial& nativeValue) Assimp.MemoryHelper.FromNativeArray[Material,AiMaterial] (IntPtr nativeArray, Int32 length, Boolean arrayOfPointers) Assimp.Scene.Assimp.IMarshalable<Assimp.Scene,Assimp.Unmanaged.AiScene>.FromNative (Assimp.Unmanaged.AiScene& nativeValue) Assimp.MemoryHelper.FromNativePointer[Scene,AiScene] (IntPtr ptr) Assimp.Scene.FromUnmanagedScene (IntPtr scenePtr) Assimp.AssimpContext.ImportFile (System.String file, PostProcessSteps postProcessFlags) Assimp.AssimpContext.ImportFile (System.String file) assImporter.Start () (at Assets/assImporter.cs:13)
Hi sammer.mirza, I'm getting the same exception. Did you have a success on fixing that ? If yes - sharing your solution would be a great help. Thanks.
I ended up buying this asset from the Unity Store: https://www.assetstore.unity3d.com/en/#!/content/28909 This plugin uses assimp as a middleware and exports the mesh in a custom binary readable format for unity which is read at runtime.
Hi there I'm trying to use assimp.NET in unity but i cannot get a good meshes from ifc file...I think it's a probleme from the tree structure... someone succeed that before?
for me, the problem was related to String.IsNullOrEmpty - im replacing it with my function Code (CSharp): public static bool Check(String target) { try { String.Format("{0}", target); return String.IsNullOrEmpty(target); } catch { return true; } } in that c# assimp wrapper and its start to work, but it crashed unity constantly when i stop unity application
For anyone else getting this: NullReferenceException: Object reference not set to an instance of an object (wrapper stelemref) object:stelemref (object,intptr,object) As far as I can tell it is because a pointer reference is being garbage collected while it is in an unmanaged DLL (assimp64.dll). I hooked the UnityEngine.dll into AssimpNet so that I could spit out a gratuitous amount of debug messages and found that by doing so the references that were going null were somehow magically kept alive. You will have to call GC.KeepAlive(<object reference>) to keep your IntPtrs alive long enough for them to be processed through the variety of unmanaged memory calls (looks to be largely in MemoryHelper.cs) while the file is being imported. If you look at the stack trace you can see where the pointer is being lost in the midst of importing materials. I haven't got it exactly where I want it yet, but I am able to use AssimpNet 3.3 in Unity 5.5.4f to import models at runtime.
@Whitebread I am stuck with the same NullReferenceException: Object reference not set to an instance of an object (wrapper stelemref) object:stelemref (object,intptr,object). Can you please explain in detail what exactly I need to do resolve this issue? In which function I have to call GC.KeepAlive in MemoryHelper.cs? It could be great if you can post the modified MemoryHelper.cs.
I'm actually back to the drawing board on this one. GC.KeepAlive did not in fact do what I wanted it to do. The Debug messages I put in previously were somehow allowing it to work (which I assumed just meant it was keeping the references alive) but it is not working properly. I will be investigating it further in the next few weeks though. I will post again to let you know what I find.
I've just recently tested Assimp.NET 3.3.2 and the latest Assimp (Native) Dlls in Unity 2017 directly and they seem to work just fine! I used the LoadLibrary call to load the Native DLL manually Code (CSharp): Assimp.Unmanaged.AssimpLibrary.Instance.LoadLibrary (libPath);
Wow... ok. Well that gets me a little bit further. I just tried it in 5.5 and I am no longer getting crashes and null reference errors. My model did not import entirely correctly but I believe it is now an issues with how i'm handling imported data. Thanks Sameer!
No Problem. Here's what I use in the Importer Configs: Code (CSharp): Assimp.AssimpContext importer = new Assimp.AssimpContext(); importer.SetConfig(new Assimp.Configs.MeshVertexLimitConfig(60000)); importer.SetConfig(new Assimp.Configs.MeshTriangleLimitConfig(60000)); importer.SetConfig(new Assimp.Configs.RemoveDegeneratePrimitivesConfig(true)); importer.SetConfig(new Assimp.Configs.SortByPrimitiveTypeConfig(Assimp.PrimitiveType.Line | Assimp.PrimitiveType.Point)); And the PostProcessSteps: Code (CSharp): Assimp.PostProcessSteps postProcessSteps = Assimp.PostProcessPreset.TargetRealTimeMaximumQuality | Assimp.PostProcessSteps.MakeLeftHanded | Assimp.PostProcessSteps.FlipWindingOrder; Assimp.Scene assimpScene = importer.ImportFile(meshPath, postProcessSteps); Let me know if you need more help
Hi, I started a project using TriLib to load ifc/fbx files. But Im getting this error after upgrading Trilib to the new version in My Main Project error CS0246: The type or namespace name `AssetLoader' could not be found. Are you missing an assembly reference? However if i dont use my Main project and just make a smaller new project The error goes away as it may be in conflict with my Main project Files. Im currently using Unity 2017.4.18f1. I dont know if its a Unity settings issue or Trilib issue or an assimp.dll location issue. I tried setting the .NET Version to 4.6 experimental. No result Also tried copying assimp.dll to the Assets folder or the plugins folder . No result At this point im stuck , Please help. Dax Thomas
Hi there, it seems that you should remove TriLib library in your project before updating. Otherwise there are always old files or references that compete with each other. Also don't forget to look in Plugins folder for some TriLib folders maybe.