Search Unity

TriLib - Model Loading Package

Discussion in 'Assets and Asset Store' started by rickomax, Jun 21, 2017.

  1. fatblueduck

    fatblueduck

    Joined:
    Feb 27, 2018
    Posts:
    5
    @rickomax I tried adding a linux condition for loading the .so file --it worked :) I'm now able to load the fbx file. The diff showing the change is pasted below. Thank you for your responses,

    $ git diff Assets/TriLib/TriLib/Scripts/AssetLoader/AssimpInterop.cs
    diff --git a/Assets/TriLib/TriLib/Scripts/AssetLoader/AssimpInterop.cs b/Assets/TriLib/TriLib/Scripts/AssetLoader/AssimpInterop.cs
    index 14c42e3..0a32165 100644
    --- a/Assets/TriLib/TriLib/Scripts/AssetLoader/AssimpInterop.cs
    +++ b/Assets/TriLib/TriLib/Scripts/AssetLoader/AssimpInterop.cs
    @@ -16,6 +16,8 @@ namespace TriLib
    #if (!UNITY_WINRT && UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN)
    public const string DllPath = "assimp";
    +#elif (UNITY_STANDALONE_LINUX)
    + public const string DllPath = "assimp";
    #elif (UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX)
    public const string DllPath = "libassimp";
    #elif (UNITY_IOS && !UNITY_EDITOR)
     
    rickomax likes this.
  2. rickomax

    rickomax

    Joined:
    Jun 11, 2013
    Posts:
    683
    Thank you for your feeback!
    I'll add your fix to the next Trilib update.
     
  3. ethang1996

    ethang1996

    Joined:
    Jul 8, 2017
    Posts:
    1
    Is there any way to load the textures from an .obj model when being loaded from memory?
     
  4. rickomax

    rickomax

    Joined:
    Jun 11, 2013
    Posts:
    683
    I'm expanding the material pipeline to allow more flexibility when dealing with this kind of issue. With the new material system
    I'll be investigating.
     
  5. quibi

    quibi

    Joined:
    Jul 24, 2017
    Posts:
    1
    Hey @rickomax ,

    When I load my fbx with some glass meshes it shows well in the editor run.
    But it shows no glass (just a white mesh) when I play it in the build (windows 64x).

    A way to fix this?

    Kind regards.
     
  6. rickomax

    rickomax

    Joined:
    Jun 11, 2013
    Posts:
    683
    I was working on your issue, and I ask you to wait till after the next update, as we will have to write a custom IO system to deal with additional memory file loading.
     
  7. rickomax

    rickomax

    Joined:
    Jun 11, 2013
    Posts:
    683
  8. jariwake

    jariwake

    Joined:
    Jun 2, 2017
    Posts:
    100
    Hi. Thanks for this great asset, I just started using it.

    However, I noticed that loading a large .fbx file (96 MB) from the disk using assetLoader.LoadFromFile() takes around 25 seconds to load. Also unity editor is unresponsive during the load. I know I cannot expect to load that amount of data in an instant, but is there anything I could do to speed things up? In contrast, if the same model is imported and put into a unity scene, it loads in a couple of seconds.

    Also, any update when the async loading would be available?
     
  9. rickomax

    rickomax

    Joined:
    Jun 11, 2013
    Posts:
    683
    We are planning to add async support to TriLib. At the moment you could try setting your model textures to file-based textures instead of embedded textures, if you have any.
     
  10. jariwake

    jariwake

    Joined:
    Jun 2, 2017
    Posts:
    100
    Hi. I actually do not have any texture files in this case. In my tests am using a simple monkey head model from Blender that only has one colored material for all the mesh.

    Trilib being single threaded unfortunately pretty much makes it useless at least for my case. Loading a 1 megabyte .fbx file takes 0.2 seconds and because the loading happens in the main thread and blocks it, this results in a clearly visible hickup. And loading a 70 MB .fbx file lasts 11 seconds, which would mean the application is seemingly frozen for 11 seconds!

    I investigated the possibility to load the models in a separate thread, but as Trilib uses Unity API, I get error "Load can only be called from the main thread." at line 300 in AssetLoader.cs (
    _notFoundTexture = Resources.Load("NotFound") as Texture2D;)

    Is there really no way around this? Is there any way to do the model loading in a thread?
     
  11. rickomax

    rickomax

    Joined:
    Jun 11, 2013
    Posts:
    683
    I'm working on an experimental Thread Ninja implementation on TriLib. I'll keep you updated.
     
  12. jariwake

    jariwake

    Joined:
    Jun 2, 2017
    Posts:
    100
    Good to know. Can you give any estimation on when this would be available? Within a month? Within 6 months?

    I experimented with Trilib and made a solution where the file data is loaded in a separate thread and then Trilib is used to instantiate the model using LoadFromMemory(). It works, but still the Trilib loading has to happen in the main thread, so it still freezes the application. Turns out, loading the file bytes is not what takes time, loading a 70 MB .fbx files takes just 0.02 seconds. Its the LoadFromMemory() part that takes more than 10 seconds.
     
    Last edited: Apr 6, 2018
  13. rickomax

    rickomax

    Joined:
    Jun 11, 2013
    Posts:
    683
    Hi. I don't have any estimative yet.

    Best regards,
    Ricardo Reis.
     
  14. rickomax

    rickomax

    Joined:
    Jun 11, 2013
    Posts:
    683
    Cleaning up interoperability and adding async loading to TriLib:

    upload_2018-4-10_22-24-27.png

    There should be a beta update to existing customers till the end of the week.
     
    jariwake and mfleurent like this.
  15. gulanxiu

    gulanxiu

    Joined:
    Mar 4, 2014
    Posts:
    14
    woo! async loading has been waiting. Thank you for your effort. This is a great plug-in resource.
     
  16. jariwake

    jariwake

    Joined:
    Jun 2, 2017
    Posts:
    100
    Nice! How exactly can I get this beta update? From asset store?
     
  17. rickomax

    rickomax

    Joined:
    Jun 11, 2013
    Posts:
    683
    Beta releases are avaliable on "Download Update" area on my website:
    https://ricardoreis.net/?p=217

    The async beta update is not ready yet, I'll post here when it be ready.
     
  18. rickomax

    rickomax

    Joined:
    Jun 11, 2013
    Posts:
    683
    Hi.

    Here is the link for the TriLib Async Beta (use your invoice number and select “Beta” version):
    https://ricardoreis.net/?p=217

    Please keep in mind that this is a beta version without all optimizations and that may still contain bugs.

    The usage is simple, please open the "Samples/Scenes/Scene4" and take a look at “LoadingSampleAsync.cs” usage.

    Best regards,
    Ricardo Reis.
     
  19. sledgeman

    sledgeman

    Joined:
    Jun 23, 2014
    Posts:
    389
    What about the most important platform : webGL !? Does this asset support it ?
     
    ina likes this.
  20. rickomax

    rickomax

    Joined:
    Jun 11, 2013
    Posts:
    683
    Not yet.
     
  21. sledgeman

    sledgeman

    Joined:
    Jun 23, 2014
    Posts:
    389
    Not yet...sounds like its in the plan !? When will we have it, which release ?
     
    ina likes this.
  22. jariwake

    jariwake

    Joined:
    Jun 2, 2017
    Posts:
    100
    I just downloaded the beta, but there is no "Samples/Scenes/Scene4"..

    EDIT: nevermind, I did not check the "beta" checkbox when downloading.

    The async loading seems to be working! =) There is still a couple of slight (0,5 - 1 second) hickups on the main thread when instantiating the model, but I guess that is inevitable when the model is 70 MB big..

    I noticed something: with the following code, the myOnModelLoaded() does not get called. I think this is because of the assetLoader only is alive within the using -block, so when the model instantiating finishes, the assetLoader object is already gone (it does not throw an error though).

    Now, what is the preferred way to use the AssetLoaderAsync class if I want to simultaneously load multiple files with it, and always run an event handler in the main thread when a model loading finishes? I tried making the assetLoader global (like in the example scene 4) and used it for all simultaneous model loads. It works, but the loaded event handler gets called 3 times each time one of the 3 models get loaded.

    Code (CSharp):
    1. private void Instantiate3DModel(path)
    2. {
    3.      using (var assetLoader = new AssetLoaderAsync())
    4.      {
    5.          try
    6.          {
    7.              var assetLoaderOptions = ScriptableObject.CreateInstance<AssetLoaderOptions>();
    8.              assetLoaderOptions.RotationAngles = Vector3.zero;
    9.              assetLoaderOptions.AutoPlayAnimations = true;
    10.                      
    11.              assetLoader.LoadFromFile(path, gameObject, myOnModelLoaded, assetLoaderOptions);        
    12.          }
    13.          catch (Exception e)
    14.          {
    15.              Debug.LogError(e.ToString());
    16.          }
    17.      }
    18.  
    19.  
    20.      Debug.Log("End of Instantiate3DModel");
    21. }
    22.  
    23. private void myOnModelLoaded(GameObject loadedGameObject)
    24. {
    25.      Debug.Log("Start of myOnModelLoaded ");
    26. }
     
    Last edited: Apr 16, 2018
  23. rickomax

    rickomax

    Joined:
    Jun 11, 2013
    Posts:
    683
    Yes. It's on the plans. I'll start to work more on that after the official async release.
     
  24. rickomax

    rickomax

    Joined:
    Jun 11, 2013
    Posts:
    683
    @jarileon you could do something like (populating your _paths list before calling the Instantiate3DModels function):

    Code (CSharp):
    1. private List<string> _paths = new List<string>();
    2.  
    3. private void Instantiate3DModels()
    4. {
    5.     using (var assetLoader = new AssetLoaderAsync())
    6.     {
    7.         try
    8.         {
    9.             var assetLoaderOptions = ScriptableObject.CreateInstance<AssetLoaderOptions>();
    10.             assetLoaderOptions.RotationAngles = Vector3.zero;
    11.             assetLoaderOptions.AutoPlayAnimations = true;
    12.             foreach (var path in _paths)
    13.             {
    14.                 assetLoader.LoadFromFile(path, gameObject, delegate(GameObject gameObject)
    15.                     {
    16.                         myOnModelLodaded(gameObject, path);
    17.                     }, assetLoaderOptions);
    18.             }
    19.         }
    20.         catch (Exception e)
    21.         {
    22.             Debug.LogError(e.ToString());
    23.         }
    24.     }
    25.  
    26.     Debug.Log("End of Instantiate3DModel");
    27. }
    28.  
    29. private void myOnModelLoaded(GameObject loadedGameObject, string path)
    30. {
    31.     Debug.Log("Start of myOnModelLoaded ");
    32.     _paths.Remove(path);
    33.     if (_paths.Count == 0)
    34.     {
    35.         Debug.Log("All models downloaded");
    36.     }
    37. }
    38.  
     
  25. gulanxiu

    gulanxiu

    Joined:
    Mar 4, 2014
    Posts:
    14
    HI, I can't download the upgrade , the beta for https://ricardoreis.net/?p=217
    Prompt:The reCAPTCHA wasn't entered correctly. Go back and try it again.
    I sent you an e-mail, please help me add my invoice number , so that I can download it.
    My Email is: nixiaofei@markorhome.com
    thank you very mush!
     
  26. jariwake

    jariwake

    Joined:
    Jun 2, 2017
    Posts:
    100
    You misunderstood the problem a bit: the problem is not how to do simultaneous async loading, that works. The problem is that the myOnModelLoaded() never gets called. Using the code above it loads all the models whose paths are listed in the _paths list as expected, but the myOnModelLoaded() is never called.

    And also, is it correct to assume that the "right" way to do simultaneous model loading is to have one instance of AssetLoaderAsync and then do multiple LoadFromFile() calls on it or would it be better to have a separate AssetLoaderAsync for each loaded model?
     
  27. mikko_forsman

    mikko_forsman

    Joined:
    Jul 10, 2017
    Posts:
    22
    Hi @rickomax, I tried downloading the async-loader beta, and it seems to be working fine with all .fbx, .obj and .stl files that I tried with, but importing ifc files is somehow bugged. Importing ifc files results in the following error:

    ArgumentException: An element with the same key already exists in the dictionary.
    System.Collections.Generic.Dictionary`2[System.String,TriLib.NodeData].Add (System.String key, TriLib.NodeData value) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:404)
    TriLib.AssetLoaderAsync+<BuildObject>c__AnonStorey2A.<>m__1 () (at Assets/TriLib/TriLib/Scripts/AssetLoader/AssetLoaderAsync.cs:1612)
    TriLib.Dispatcher.Update () (at Assets/TriLib/TriLib/Scripts/Extensions/Dispatcher.cs:129)


    EDIT: Some larger IFC files also seem to crash Unity completely, would you like me to send the Unity crash logs to you somewhere?

    Best regards,
    Mikko Forsman
     
    Last edited: Apr 18, 2018
  28. rickomax

    rickomax

    Joined:
    Jun 11, 2013
    Posts:
    683
    Yes, please send to: contato@ricardoreis.net
     
  29. rickomax

    rickomax

    Joined:
    Jun 11, 2013
    Posts:
    683
    Ok. I will check why the function isn't being called.
    For the methodology, there is really no difference between using multiple instances or a single AssetLoaderAsync instance. I would use just only one, to keep things simpler.
     
    Last edited: Apr 20, 2018
  30. mikko_forsman

    mikko_forsman

    Joined:
    Jul 10, 2017
    Posts:
    22
    Hi,
    I sent you a message with the crash logs, and another email to point out where you can get an .ifc file that causes the crash.

    Best regards,
    Mikko Forsman
     
  31. jariwake

    jariwake

    Joined:
    Jun 2, 2017
    Posts:
    100
    I noticed that in the latest beta, if you call assetLoader.LoadFromFile() and pass a null string as the first parameter, Unity crashes (tested with 2017.3.1f1).

    Any update on when the async loading would be in an official Trilib release?
     
  32. rickomax

    rickomax

    Joined:
    Jun 11, 2013
    Posts:
    683
    Thank you for the finding. I'm still getting some feedback from users and fixing issues with the async loading, as soon I have more positive feedbacks and have these issues fixed, I'll send it as an official update.
     
  33. rickomax

    rickomax

    Joined:
    Jun 11, 2013
    Posts:
    683
    Thank you. I'm pretty busy recently, but as soon as I finish current tasks, I'll take a look at your log file.
     
  34. jariwake

    jariwake

    Joined:
    Jun 2, 2017
    Posts:
    100
    I also noticed another problem regarding the onObjectLoaded callback in LoadFromFileAsync(). It seems that the onObjectLoaded callback is caller multiple times when it should be called only once per finished asset load. Heres the problem in code:

    Code (CSharp):
    1.  
    2.     private void foo()
    3.     {
    4.         List<string> myAssets = new List<string();
    5.         myAssets.Add("C:\\foo.fbx");
    6.         myAssets.Add("C:\\bar.fbx");
    7.         myAssets.Add("C:\\woo.fbx");
    8.  
    9.         foreach (var item in myAssets)
    10.         {
    11.             Instantiate3DAsset(item); //instantiate all 3 all assets..
    12.         }
    13.     }
    14.  
    15.     private void Instantiate3DAsset(string assetPath)
    16.     {
    17.         try
    18.         {
    19.             var assetLoaderOptions = AssetLoaderOptions.CreateInstance();
    20.             assetLoaderOptions.RotationAngles = Vector3.zero;
    21.             assetLoaderOptions.AutoPlayAnimations = true;
    22.  
    23.             assetLoader.LoadFromFile(assetPath, modelContainer, delegate (GameObject loadedGameObject)
    24.             {
    25.                 OnModelLoaded(loadedGameObject, assetPath);
    26.             }, assetLoaderOptions);
    27.         }
    28.         catch (System.Exception e)
    29.         {
    30.             Debug.LogError(e.ToString());
    31.         }
    32.     }
    33.  
    34.     private void OnModelLoaded(GameObject loadedGameObject, string assetPath)
    35.     {
    36.         //This method gets called 3 times every time one of the assets is loaded
    37.         //The expected behavior is to get called only once per the asset that actually got loaded
    38.         Debug.Log("Model instantiated from file " + assetPath);
    39.     }
    40.  
    EDIT: I noticed another thing: the loadedGameObject inside OnModelLoaded seems to refer to whatever I passed as the wrapperGameObject to LoadFromFileAsync(). Isnt it supposed to refer to the instantiated gameobject, not to the parent?

    EDIT 2: I also tested this on Mac/OS X. It seems that calling the LoadFromFileAsync() crashes Unity completely. Did you (or anyone in this following this thread) test the async load on a Mac?
     
    Last edited: Apr 26, 2018
  35. rickomax

    rickomax

    Joined:
    Jun 11, 2013
    Posts:
    683
    I'll be testing on Mac today
     
  36. maxOculavis

    maxOculavis

    Joined:
    Apr 27, 2018
    Posts:
    8
    Hello and greetings form Germany!
    I really love TriLib! really glad that it´s possible to have platform independent asset loading.
    i'm currently using the Async beta and ran into this problem today:
    My Code:
    Code (CSharp):
    1.             assetLoaderAsync = new AssetLoaderAsync();
    2.             try
    3.             {
    4.                 var assetLoaderOptions = AssetLoaderOptions.CreateInstance();
    5.                 assetLoaderOptions.RotationAngles = Vector3.zero; ;
    6.                 assetLoaderOptions.AutoPlayAnimations = false;
    7.                 assetLoaderAsync.LoadFromMemory(meshReq.downloadHandler.data, id + ".obj", delegate (GameObject loadedGameObject)
    8.                 {
    9.                     loadedGameObject.transform.localPosition = Vector3.zero;
    10.                 }, assetLoaderOptions);
    11.             }
    12.             catch (Exception e)
    13.             {
    14.                 Debug.LogError(e.ToString());
    15.             }
    Gave me the following Errors:

    I know there´s probably a lot on your schedule right now, but I would be so glad
    if you are able to point me to a solution here.

    Kind Regards, Max
     
  37. CogumeloSoft

    CogumeloSoft

    Joined:
    Dec 28, 2012
    Posts:
    88
    Hi!
    How is the GLTF 2.0 working? It supports the Draco compression? I could not find any information about it in the website.
    Bye!
     
  38. rickomax

    rickomax

    Joined:
    Jun 11, 2013
    Posts:
    683
    I'll check this information with Assimp team.
     
  39. rickomax

    rickomax

    Joined:
    Jun 11, 2013
    Posts:
    683
    Hi. I'm still fixing issues with async implementation.
    Without simulating your exactly scenario, it's hard to catch the error source.
    I'll be updating the async beta soon, if you be able to wait some days, we could check it again with the new update.
     
  40. ina

    ina

    Joined:
    Nov 15, 2010
    Posts:
    1,085
    What's the timeline for WebGL support
     
  41. rickomax

    rickomax

    Joined:
    Jun 11, 2013
    Posts:
    683
    I don't have a timeline yet. Some tests have been done, but as the next TriLib version will have a new Assimp version integrated, new tests and compilations will have to be done.
     
    gulanxiu likes this.
  42. gulanxiu

    gulanxiu

    Joined:
    Mar 4, 2014
    Posts:
    14
    I am looking forward to the update of the new version. Thank you for your efforts.
     
  43. centur10n

    centur10n

    Joined:
    Jan 28, 2014
    Posts:
    6
    Hi!
    I just downloaded beta version and my Unity 2017.3.1 and 2017.2.1 (iOS) crashes on loading fbx. It crashes even on start example. Any help? What version of Unity I need to use or maybe some hotfixes? I really need async loading. Thanks!

    Also there is compilation error in DownloadSamples.cs line 166 if TRILIB_USE_ZIP is false

    Unity crashes on AssetLoader.cs line 2100 or AssetLoaderAsync.cs line 1610

    Code (CSharp):
    1. gameObject.transform.LoadMatrix(AssimpInterop.aiNode_GetTransformation(node));
    Device crashes too if i start on iPhoneX
     
    Last edited: May 25, 2018
  44. zlllwy520

    zlllwy520

    Joined:
    Feb 27, 2018
    Posts:
    4
    When I ran the PC version, I loaded the.fbx file normally. When I packaged it on Android platform, System.DllNotFoundException:libassimp at(wrapper managed-to-native)
    can you hlep me?
     
  45. rickomax

    rickomax

    Joined:
    Jun 11, 2013
    Posts:
    683
    What's the Android device model you're using?
     
  46. rickomax

    rickomax

    Joined:
    Jun 11, 2013
    Posts:
    683
    I'll verify the current iOS build
     
  47. zlllwy520

    zlllwy520

    Joined:
    Feb 27, 2018
    Posts:
    4
    My current device model is HUAWEI 6S, and I want to use this feature on a APP, all of which need to be compatible with most of the devices, such as apple mobile devices, and so on.
     
  48. rickomax

    rickomax

    Joined:
    Jun 11, 2013
    Posts:
    683
    Your processor has a Armv8-A architecture. Unity till the latest 2018 update wasn't supporting native plugins from this architecture. I will work on a new TriLib update after the one that is about to be released that will include Armv8 Android native plugins. But it means you will probably have to update to Unity 2018 to support it.
     
  49. rickomax

    rickomax

    Joined:
    Jun 11, 2013
    Posts:
    683
    TriLib 1.8 is waiting aproval on Asset Store.
    Meanwhile, you can download it using your invoice number from:
    https://ricardoreis.net/?p=217 (Please make sure to select Beta Version)

    This version includes many bugfixes, performance improvements and async support.
    A new scene has been added showing the async capabilities.
     
  50. zlllwy520

    zlllwy520

    Joined:
    Feb 27, 2018
    Posts:
    4
    Thank you again for your constant reply, I have failed to download the 1.8 version here. When I enter the invoice number, the result is: The reCAPTCHA wasn't entered correctly. Go back and try it again.
    what is this problem, my invoice number is clear and correct, I hope you will help again, thank you.