Search Unity

GLTFUtility - A simple glTF plugin

Discussion in 'Assets and Asset Store' started by Siccity, Apr 1, 2019.

  1. DerrickBarra

    DerrickBarra

    Joined:
    Nov 19, 2013
    Posts:
    210
    No but it was a related bug, and it allowed me to see that there was an issue with the glossiness parameter on the specular setup.
     
  2. DerrickBarra

    DerrickBarra

    Joined:
    Nov 19, 2013
    Posts:
    210
    @Siccity : Have you given any thought about allowing other mimeType's for the GLTFImage.cs class?

    This could be useful for introducing runtime graphics ready texture data (like ETC2, DXT1, DXT5, etc) to be read from bytes by using Texture.LoadRawImageData().

    This would be to prevent the large hitching/lag that occurs during import since Unity doesn't have a multi-threaded solution for converting jpg/png to runtime ready RGB32 textures (and those textures can easily cause crashes since they're huge).

    Any thoughts? The rest of the pipeline for import is already multithreaded as much as possible, as far as I can see texture import is the only thing left since that texture conversion happens on the main thread.
     
  3. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    Is there a standard for it? I'll need some example files to test with.
     
  4. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    I tested the specular R2D2 model.

    It seems to import correct, albeit not very pretty.

    I do not have permission to download the coin model.
     

    Attached Files:

  5. DerrickBarra

    DerrickBarra

    Joined:
    Nov 19, 2013
    Posts:
    210
    @Siccity sorry for the delay.

    - The specular R2D2 model is working for me as well after I updated to the latest version of GLTFUtility, must have been on my side since my code tends to branch off of yours a bit when I'm experimenting with functionality or fixing things.

    - The medallion coin model got its permissions changed by the creator, that can happen with Sketchfab sometimes.

    - I've been looking for a faster method of loading .jpgs and .pngs, and through my testing, I've concluded that UnityWebRequest is the way to go in this regard. It's significantly faster than using LoadImage. It still has a hitch on loading but it's inconsequential for most users. I heavily recommend that GTLFUtility switch over to it for the GLTFImage.cs class.

    - To prevent out of memory errors, I think the best thing at the moment is to check all of the textures sizes and compare our estimated size on the GPU and determine if we will have enough video memory. If not, load each texture in and then resize them to reduce memory allocation down until we meet that limit.

    - The Khronos group is talking about adding support for the .KTX container format that would store a GPU ready texture, and provide the means of determining what format it is so it can be used instead of .jpg or .png. This would be great for saving texture memory, but it doesn't look like it's anywhere close to being ready for prime time.

    - In the near future, I could always change GLTFImage.cs to load those GPU textures via LoadRawTextureData, but I'm not at the point in my project where I have those GPU ready textures for every Sketchfab model included as part of the GLTF archive download. So finding a fast way of loading .jpgs and .pngs was a huge win.
     
    Last edited: Nov 8, 2019
  6. DerrickBarra

    DerrickBarra

    Joined:
    Nov 19, 2013
    Posts:
    210
    Hi again @Siccity, I found a model on Sketchfab (Space Invaders) that loads in without textures, and instead just has colours applied to the mesh.



    However, when loaded through GLTFUtility, the materials that are instantiated are Standard (Metallic), with the colour applied to the 'Emission Color' attribute, and not the 'Color' attribute of the material.

    upload_2019-11-11_14-46-28.png
     
    Siccity likes this.
  7. mj-3dqr

    mj-3dqr

    Joined:
    Mar 30, 2017
    Posts:
    14
    Hi @Siccity,

    we are using your GLTFUtility for extending the UnityEditor to import GLTF and GLB files.

    We maybe found a problem in your implementations. Hopefully you could fix the problem, that we could use your package without any local changes.

    In your classes GLTFImporter and GLBImporter you are calling the AssetImport per File-Ending as ScriptedImporter. But in this classes the importSettings on the LoadFromFile call are NULL. So we get NullReferenceExceptions on the automatic import.

    In our case we want to copy files to the unity assetfolder and await automatic created results from unity for further steps.

    Maybe we are doing something wrong!?

    Thank you
     
    Siccity likes this.
  8. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    I will look at both of your issues as soon as possible.
     
  9. DerrickBarra

    DerrickBarra

    Joined:
    Nov 19, 2013
    Posts:
    210
    Hi again @Siccity ! Found an issue with how memory is being requested onto the Unity Heap with GLTFUtility.



    Given the test model above, I noticed that GLTFUtility is requesting nearly 2GB of RAM usage during the import process on the mono heap, which obviously crashes mobile devices. The Mono heap never shrinks once it expands, so using a lot of pages of memory quickly without letting the garbage collector clean up could be the root cause.

    This large Unity heap ram usage occurs during the bufferTask, bufferViewTask, and accessorTask's in the LoadAsync() method of Importer.cs.

    Texture RAM usage for this model is pretty normal at 136MB, just as an FYI.

    Here's a snapshot of my demo scene with some calculated stats, but you can see the same thing on the Unity profiler.

    upload_2019-12-2_19-40-52.png

    And if I load this model in a different viewer, such as the one available here, we see the total memory usage of around 33MB.

    upload_2019-12-3_11-4-50.png

    Is this a fixable issue with GLTFUtility? I assume this same issue will occur with other models as well.
     
    Last edited: Dec 3, 2019
  10. PendingFox

    PendingFox

    Joined:
    Jan 15, 2017
    Posts:
    42
    Any plans to add camera support?
     
    Siccity likes this.
  11. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    Yes. Camera should be very easy
     
  12. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    About this issue, it seems that GLTFUtility is loading it correctly. The colors are applied as emissive in Sketchfab as well.
    upload_2019-12-5_10-38-27.png upload_2019-12-5_10-38-39.png
     
  13. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    I haven't done much optimization in GLTFUtility yet so it's probably fixable.
     
    DerrickBarra likes this.
  14. PendingFox

    PendingFox

    Joined:
    Jan 15, 2017
    Posts:
    42
    Well then great :D let's do it
     
  15. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    It has been added :)
     
    PendingFox likes this.
  16. PendingFox

    PendingFox

    Joined:
    Jan 15, 2017
    Posts:
    42
    Thank you very much! Keep rocking
     
  17. Manish_hbb

    Manish_hbb

    Joined:
    Dec 5, 2019
    Posts:
    2
    Hi @Siccity , I am trying to load a gltf at runtime and the load function takes 2 parameters, I am using the GLTFUtiity version 0.6, I am not able to find the latest one, where can I find the latest version
     
  18. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    https://github.com/Siccity/GLTFUtility I recommend cloning it through git, but you can also just do an old fashioned .zip download using the green button on the right
     
  19. zurgerb

    zurgerb

    Joined:
    Aug 10, 2019
    Posts:
    1
    I hope nobody minds me stating the obvious here, but as someone that has never installed a plugin before, I am trying to find the part that explains how I use it?

    I mean, it says import the package into my Assets but then I see nothing that tells me what I do next to import a gltf model. I don't see any documentation that explains if a new menu option appears, or if I need to restart Unity, or how to check if it worked and I don't see a video showing me anyone else installing it and showing it working.

    I am a little lost sorry (sincerely) and could do with some gentle guidance on the basics.
    I just want to import a gltf model into Unity.

    Thank you,

    Z
     
    Last edited: Dec 17, 2019
  20. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    Hello,

    Just drag and drop your .gltf and .bin (or .glb) files into your project after importing GLTFUtility. When this plugin is present in your project, Unity should recognize gltf files just the same as it recognizes other 3d formats.
     
  21. DerrickBarra

    DerrickBarra

    Joined:
    Nov 19, 2013
    Posts:
    210
    @Siccity Happy new year Siccity, I was wondering if it would be possible to prioritize looking into the high ram usage I posted about a while back? This is a blocker for our team.

    Thanks for your hard work in 2019, looking forward to GLTFUtlity getting even better in 2020!
     
  22. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    Happy New year :)
    I'll take a look at it next time I work on GLTF
     
    DerrickBarra likes this.
  23. melvingr

    melvingr

    Joined:
    Feb 4, 2018
    Posts:
    1
    First, let me thank you for your work on this project, thanks!

    I have a question, when i import a model everything is working just fine. However, how do i use a animator component with these imported models? Also there is no avatar to use with said animator?

    Am i missing something?

    Kind regards
     
  24. stimul

    stimul

    Joined:
    Nov 28, 2013
    Posts:
    11
    @Siccity
    Where i can find example project? Or tutorial
     
  25. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    I'm glad you like it :)

    The animator works the same way as usual. Just add the animator component to your instanced model and drag any animation onto components header to automatically create and assign a controller.

    Avatars are not currently supported in GLTFUtility. Personally I've never found a use for them.
    Is it something you'd like to see supported?
     
  26. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
  27. stimul

    stimul

    Joined:
    Nov 28, 2013
    Posts:
    11
    How to solve this problem on Android?
    any suggestions, @Siccity
     

    Attached Files:

    Last edited: Jan 8, 2020
  28. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    For some reason property drawers don't work in custom asset importers. Anyways, it's supposed to show you a warning that you need to go to Project Settings > Graphics, then scroll down to "Always Included Shaders" and add all GLTFUtility's shaders in there. It's because Unity strips them on build when they aren't referenced directly anywhere.
     
  29. lizzl

    lizzl

    Joined:
    Nov 15, 2019
    Posts:
    3
    Hi @Siccity, Thanks for the work this far on GltfUtility. I am able to download and configure the utility 'as mentioned in the readme' but Sorry! finding it really hard to load gltf model.
    My use case is to load GLTF model at runtime using Unity.
    Please could you provide steps to load GLTF models in c# script.
    Thanks a lot!
     
    Siccity likes this.
  30. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    I'm glad you like it :)

    I added runtime import instructions on the readme https://github.com/Siccity/GLTFUtility/blob/master/README.md#runtime-import-api
     
  31. alexevaldez

    alexevaldez

    Joined:
    Jun 13, 2013
    Posts:
    6
    @Siccity This is freaking awesome thanks for doing this man!

    I just was wondering tho, is there a way to get the animation in realtime import? I've been successfully importing the animationclips using editor mode. But I was hoping to just use Importer.LoadFromFile().
     
    Siccity likes this.
  32. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    Yes! One of the overrides of LoadFromFile has an additional `out` parameter that contains animations. It's still a bit experimental, but it's the same function the internal loader is using.
     
  33. alexevaldez

    alexevaldez

    Joined:
    Jun 13, 2013
    Posts:
    6
    Oh! I saw that but I couldnt understand how to link with an Animator without the need of an editor.

    Do you have any examples perhaps? Also do you have any donation site i can drop money if I ever get some?
     
  34. DerrickBarra

    DerrickBarra

    Joined:
    Nov 19, 2013
    Posts:
    210
    @Siccity Hi again, have you had a chance to look into the high GLTF memory usage during model loading?
     
  35. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    A little, but unfortunately I haven't made any progress on it. I am currently being funded to look into sparse accessors, so that's my top priority right now. This feature will likely be pretty heavy with the current framework, so I will probably have to look into performance soon thereafter.
     
  36. DerrickBarra

    DerrickBarra

    Joined:
    Nov 19, 2013
    Posts:
    210
    @Siccity thanks for getting back to me on this!
     
  37. zrslv

    zrslv

    Joined:
    Jan 8, 2020
    Posts:
    1
    @Siccity Hi! Thanks a lot for creating this tool, truly simplifies my life.

    I use avatars to retarget mixamo animations to my models. Not being able to import avatars makes that impossible. I still can import the model as `.fbx`, then the materials from a GLTF, drag the latter onto the former and kinda make it work that way.

    edit: In fact I think one could get away with just putting an Animator referencing a mixamo-generated avatar on a GLTF-imported model. The trick would be to get the FBX and GLBT export settings right so the axes and units match.
     
  38. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    Hello again. I have made some progress on this issue. Managed to get "Brain Stem" test model from the official test repo down from 124 MB GC to just 24 MB. This enhancement still isn't complete, but you can test it out on this branch https://github.com/Siccity/GLTFUtility/tree/optimize-gc

    For some reason it performs a bit slower, but I'll have a look at that as well.
     
  39. DerrickBarra

    DerrickBarra

    Joined:
    Nov 19, 2013
    Posts:
    210
    @Siccity : That's an amazing decrease in memory use, great job!

    As soon as you think you're good to go with the performance update, let me know and I'll integrate it into our project.

    FYI on our version of GLTFUtility, we've modified it in the following ways...

    - Send out a progress update callback with a value of 0-100 via a callback during texture loading
    - Load local textures via UnityWebRequestTexture to increase performance

    If you'd like, I can send you a zipped up copy of the plugin with those changes, in case you'd like to put them into a proper update to the plugin.
     
  40. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    Yeah, I'd like to see what you've done with it :)
     
  41. DerrickBarra

    DerrickBarra

    Joined:
    Nov 19, 2013
    Posts:
    210
    @Siccity I PM'ed you a link to our modified version of GLTFUtility.

    I looked at the optimize-gc branch on Github, and I'm considering integrating with it. But I noticed you mention that it doesn't support multithreaded operations. However, does it currently support asynchronous loading?

    I know texture loading isn't non-blocking yet, as you would need to be generating textures in native code and pass the texture reference back to Unity, I'm just trying to make sure the overall operation is asynchronous.
     
  42. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    Async isn't supported in the optimized branch yet. I'm working on it.
     
  43. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    After some minor tweaks it seems to be working in async as well now.
     
    DerrickBarra likes this.
  44. DerrickBarra

    DerrickBarra

    Joined:
    Nov 19, 2013
    Posts:
    210
    @Siccity :

    So I found a bug that's causing animations to fail to import during editor and runtime import. Right now the master branch of GLTFUtility has a bug with animation playback, but if you revert this commit, then animations work!
     

    Attached Files:

    Last edited: Jan 27, 2020
    Siccity likes this.
  45. DerrickBarra

    DerrickBarra

    Joined:
    Nov 19, 2013
    Posts:
    210
    @Siccity
    Heads up, I'm revisiting some of the old models and figuring out why they're not rendering correctly in Unity. In the instance of this Space Invaders model, even though the emission color is being set up correctly by GLTFUtility, the shader requires that there be a texture in the Emission slot for the color to render in Unity. (In this example object, a blank white texture is needed)

    So the GLTF shaders just need to be changed from...
    [NoScaleOffset] _EmissionMap ("Emission", 2D) = "black" {}


    to

    [NoScaleOffset] _EmissionMap ("Emission", 2D) = "white" {}
     
    Last edited: Jan 28, 2020
  46. DerrickBarra

    DerrickBarra

    Joined:
    Nov 19, 2013
    Posts:
    210
    @Siccity I'm working on trying to figure out why GLTFUtility is having issues with some of the models I've come across. I was hoping you might have an idea or be able to implement a fix.

    R2D2 - Comparison - Download - View In Sketchfab
    In this model, the body uses a specular shader, and the glossiness value imports as 0.8. However, there is no texture data for any of the channels, just colours set to the albedo map. It doesn't need an environment cubemap to work, but it would be enhanced by having that extra data for reflectivity.

    Space Invaders - Comparison - Download - View In Sketchfab
    Requires the emission map to default to a white texture so the emission colour on the model blends correctly. (as noted in my previous post)

    Zelda Medallion - Comparison - Download - View In Sketchfab
    Comparing the Unity render to the built in Windows GLTF viewer is night and day. The metallic value is making the model super dark, because the model is expecting an environment cubemap texture. Obviously that's not part of the GLTF model archive itself, but we need a way to load a GLTF model using a custom cubemap for these types of models.
     
  47. DerrickBarra

    DerrickBarra

    Joined:
    Nov 19, 2013
    Posts:
    210
    @Siccity : So in continual research on the subject of why objects with reflectivity fail to render correctly, I've noticed that when rendered in a build (in my case, an Android phone using ARCore), the reflectivity actually renders correctly, and shows the Unity skybox.

    I'm not sure why reflectivity fails in editor, but at least it doesn't seem to be a GLTFUtility issue! So the only change needed on your end is to change the emission map in your shaders to default to a white texture instead of a black one in order to make models using the emission color channel render correctly.
     
    Siccity likes this.
  48. azad_unity

    azad_unity

    Joined:
    Jan 26, 2020
    Posts:
    2
    @Siccity
    First of all thanks you for the great work.
    I'm using GLTFUtility in iOS I had 2 problems getting it work on my ipad which I found the solution and included below
    * First one, shaders should be included in graphic settings manually
    * Second in GLTFBuffer.cs should used "File.OpenRead(directoryRoot + uri)" instead of "File.Open(directoryRoot + uri, FileMode.Open)", apparently you can't open file in iOS to write.
     
    Siccity likes this.
  49. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    802
    Great tool and interesting alternative to the official Khronos repo. I'd be especially interested in runtime export features - do you have an idea when you might be able to get to that?
     
  50. ismaeel_unity

    ismaeel_unity

    Joined:
    Oct 21, 2019
    Posts:
    12
    Does this support asset export with Universal Render Pipeline? Or just the Unity Default Render pipeline?