Search Unity

GLTFUtility - A simple glTF plugin

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

  1. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    173
    For far too long I've been annoyed by the lack of glTF 2.0 support in Unity, so I decided to make a plugin on my own.

    A few months of loose development later I've checked most of the things I wanted off the list.

    GLTFUtility supports meshes with submeshes, up to 8 uv channels, vertex colors, normals, tangents, embedded textures, materials, rigs and animations. And it's easy to set up. Just drop it anywhere in your project and you're ready to go.

    Currently only edit-time import is supported, but export and runtime capabilities are on the roadmap as well.

    The project is opensource and available on github.

    Feedback, contributions and requests all welcome.
     
  2. 40detectives

    40detectives

    Joined:
    Apr 9, 2016
    Posts:
    74
    Just discovered rencently about GLTF and also found https://github.com/KhronosGroup/UnityGLTF from the Khronos Group itself, so was curious about what's GLTFUtility capable vs the UnityGLTF one. No hostilty, just asking.
     
  3. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    173
    The key differences lie in their complexity and features. While UnityGLTF boasts more features, it seems like an extremely messy project, and having to compile a DLL for it to work makes it inaccessible to most of the people who actually need it.

    GLTFUtility is built with simplicity as the main focus, uses no external libraries, and is easy to navigate for potential contributors. It's plug and play.
     
  4. janvetulani3r

    janvetulani3r

    Joined:
    Feb 8, 2017
    Posts:
    9
    Hi!

    How would one go about actually configuring a model in Unity using the GLTFUtility?|
    What I mean is, setting up all the animation clips like I would with a .blend or .fbx, setting up colliders, changing the rig to humanoid etc. Also extracting the embedded materials out of the file into the project so I can change to a custom shader etc.

    All I get is a model I can drag into the scene with no configuration options.

    When will you support BlendShapes/vertex animation?

    The UnityGLTF seems like a HUGE mess, with a lot of stuff that is completely useless for an average user that just wants to import a model into Unity and set it up, with a ton of weird server stuff that I have absolutely no use for.

    Cheers!
     
  5. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    173
    Hey,

    Sorry for the lack of reply.
    What you mentioned is on the roadmap, but this plugin is developed entirely out of personal interest, so there is no saying when certain features arrive.
     
  6. Spanky11

    Spanky11

    Joined:
    Mar 9, 2015
    Posts:
    307
    Hi, I'm pretty sure I just emailed you also...Anyway, I'm wondering when (or if) runtime imports for GLTF will be added?
     
  7. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    173
    I think it might work already, actually. Try experimenting with something like this

    Code (CSharp):
    1. GLTFObject gltfObject = GLTFObject.Load(filepath);
    2. GameObject[] roots = gltfObject.Create();
     
  8. Spanky11

    Spanky11

    Joined:
    Mar 9, 2015
    Posts:
    307
    Thanks, I'll try it. So how do you use this in the Editor? I don't see any new menu's and the documentation is sparce.
    The gltfObject.Load takes 2 arguments, not 1. Should this work?

    gltfObject.Load("C:\\Users\\stephen\\AppData\\LocalLow\\BuilderWorldVR\\BuilderWorldVR\\unzip\\SkyCastle", "scene.gltf") ;

    where scene.gltf is a file within the SkyCastle folder.
     
  9. Spanky11

    Spanky11

    Joined:
    Mar 9, 2015
    Posts:
    307
    When I try the above, it's showing an error. It would be good to include a sample!


    upload_2019-8-20_19-48-44.png
     
  10. Spanky11

    Spanky11

    Joined:
    Mar 9, 2015
    Posts:
    307
  11. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    173
    Please update GLTFUtility to latest version and try again.
     
  12. Spanky11

    Spanky11

    Joined:
    Mar 9, 2015
    Posts:
    307
    Hmm, did you make a change? I just downloaded this a couple days ago, and GitHub says that last commit was 12 days ago. Unless I'm mistaken, I do have the latest version.

    Hey could you try testing with the 2 attached GLTF files? Both of these are from Sketchfab (both are creative commons license, but I don't have the authors handy to give proper credit)

    Both of these I can open using the "Sketchfab for Unity" asset and they work fine. Both fail with errors when I use UniGLTF-1.28. I was curious to see if they worked with your asset.

    I need runtime GLTF loading, and I can't use "Sketchfab for Unity" because it seems coded so that when you load a GLTF file, it imports the file and creates a prefab. I'm pretty certain a prefab can only be created in the Editor, and not in a standalone application. But it's also really slow because if the GLTF has 100 pieces within it (meshes or whatever) then Unity takes its sweet time doing the import for all of these.

    So "Sketchfab for Unity" seems to lack a simple method that lets you load a GLTF and return a Unity Game Object. That's what I need.

    I'm not sure if UnityGLTF has this (the Khronos asset), but getting it working is a nightmare. As others have mentioned, it's a mess! I spent a whole day messing with it.

    Regarding UniGLTF-1.28, when it works, it works quite well, and I'm pleased with how quickly it can create a GameObject. The only problem is that, as I pointed out above, I see errors with some of the files I have tried. I wanted to try out your asset to see if it works better than UniGLTF
     

    Attached Files:

  13. Spanky11

    Spanky11

    Joined:
    Mar 9, 2015
    Posts:
    307
    Also, can you explain how to use your asset in the Editor? I was expecting a new menu that could be used to import files, but I don't see anything. thanks!
     
  14. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    173
    I made a few changes regarding runtime loading, yes. Loading only takes a single parameter now. If yours takes two parameters, you got the wrong version.

    I can't test your files till next week

    In the editor, the asset should do what it does automatically. Put the gltf/glb files in your assets folder and it will be imported as if it were an fbx or obj. This works for all of the official example files. If it doesn't work for yours, then I got some work to do
     
    davtam likes this.
  15. danilo-defilippis

    danilo-defilippis

    Joined:
    Oct 3, 2014
    Posts:
    3
    Does this project supports runtime loading of GLTF from remote url?
     
  16. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    173
    Not yet. It focuses on local files.
     
  17. DerrickBarra

    DerrickBarra

    Joined:
    Nov 19, 2013
    Posts:
    119
    Great work on this so far! Is runtime import from a remote URL prioritized on your roadmap?

    Our team is evaluating the various gltf runtime importers that are available right now that support animation. Our plan is to use the Sketchfab API to download models and then use GLTFUtility to import the gltf models.

    Our team is working on a mobile AR app, and this is one of our most important features to implement. So if you're already working on it, we would rather work with GLTFUtiltiy since it's open-source and written well instead of the alternatives.
     
  18. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    173
    Remote import is definitely on the roadmap, but right now i'm working on switching the serialization out with Json.NET which will enable exports.

    HOWEVER, if the sketchfab API allows .glb files, you could maybe feed that binary data directly into GLTFUtility without too much modification. Would this be an option for you?
     
    davtam likes this.
  19. DerrickBarra

    DerrickBarra

    Joined:
    Nov 19, 2013
    Posts:
    119
    Sketchfab only supports downloading models in the standard .gltf format in a .zip archive. It would be pretty awesome if there was also a .glb file for simple downloading and use at runtime, but that's not something they plan on supporting.

    .glb support is also important though! We could instead download the .gltf on our web server and convert it to .glb format there, and then download the .glb formatted file during mobile runtime. That would basically do the same thing.

    So yeah, downloading and using a .glb would also be a good way to go. Is this something you'll need to add to GLTFUtility or is it already possible?

    As a side question, does GLTFUtility support animations for the .glb format?
     
    Last edited: Sep 7, 2019
  20. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    173
    It is not already possible, although it could probably be done with slight modifications. Loading .glb with raw data input will probably come before remote .gltf does.

    And yeah, animations are supported for both formats already.
     
  21. DerrickBarra

    DerrickBarra

    Joined:
    Nov 19, 2013
    Posts:
    119
    Thanks Siccity, looking forward to it!

    Is this something you would be okay prioritizing after you've finished switching out the serialization to json.NET?
     
  22. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    173
    Yeah i can look into it. But no promises.

    Can you send me a file using remote images to test on?
     
  23. DerrickBarra

    DerrickBarra

    Joined:
    Nov 19, 2013
    Posts:
    119
    Siccity likes this.
  24. DerrickBarra

    DerrickBarra

    Joined:
    Nov 19, 2013
    Posts:
    119
    Siccity likes this.
  25. MobilCC

    MobilCC

    Joined:
    Aug 12, 2019
    Posts:
    4
    Hi guys,

    @Siccity I really like this plugin, it's much more lightweight than the other one. (KhronosGroup)
    I want to import glb files (with animations and textures) in runtime. The static import without animations is working correctly, as you mentioned in a previous comment.

    Code (CSharp):
    1. GLTFObject gltfObject = new GLTFObject(pathToFile);
    2. GameObject[] roots = gltfObject.Create();
    But when I try to import with any kind of animation in runtime I got the non-legacy AnimationClip error.
    (SetCurve will only work at runtime for legacy animation clips. For non-legacy AnimationClips it is an editor-only function. https://docs.unity3d.com/ScriptReference/AnimationClip.SetCurve.html)

    I tried to change the clip to legacy but it doesn't solve my problem at all. :(

    Any idea?

    This is just not possible this way?

    Thanks!
     
    Siccity likes this.
  26. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    173
    I will have to research if unity supports creating non-legacy animations in some way. If it is possible, GLTFUtility should definitely be able to do it.
     
    MobilCC likes this.
  27. DerrickBarra

    DerrickBarra

    Joined:
    Nov 19, 2013
    Posts:
    119
    @Siccity I've made progress importing .gltf models from the SketchFab API and loading them at runtime (save to local storage first, then load it into GLTFUtility). I won't be needing the .glb/.gltf runtime importer after all!

    I have noticed a couple of things I want to give you feedback on...

    1) In the readme, you should add that the GLTFUtility's Standard-Metallic and Standard-Specular shaders should be force-added to the project via the Project Settings -> Always Included Shaders section. That way GLTFMaterial.cs doesn't fail when making the Shader.Find() call outside of the Unity Editor.

    2) In GLTFImage.cs, I ended up changing the OnLoad() function to use File.ReadAllBytes() to load the texture instead of Asset cache system, this allows GLTFUtility to load assets on mobile via the PersistentDataPath since the standard Assets folder doesn't exist at mobile runtime.

    Code (CSharp):
    1. if (!string.IsNullOrEmpty(uri) && File.Exists(glTFObject.directoryRoot + uri))
    2.             {
    3.                 //Debug.Log( "GLTFImage.cs OnLoad() Loaded texture at " + glTFObject.directoryRoot + uri );
    4.  
    5.                 byte[ ] fileData = File.ReadAllBytes( glTFObject.directoryRoot + uri );
    6.                 cache = new Texture2D( 2, 2 );
    7.                 cache.LoadImage( fileData );
    8.  
    9.                 imageIsAsset = true;
    10.                 return true;
    11.             }
    3) In my current SketchFab .gltf test, I downloaded a Pac Man arcade cabinet model that has the animation clip "Take 001". This animation successfully plays when testing this on the SketchFab website viewer and via DonMcCurdy's "three-gltf-viewer".

    Using GLTFUtility this model imports without animations. Or if it does, I have no idea where they are or how to play them. Any kind of documentation or pointing me in the right direction would be appreciated.

    4) In the same Pac Man model there is also a texture/material/shader combination that seems to give GLTFUtility some problems (Check out the "scheibe") material that gets generated.

    For comparison, I loaded this .gltf using DonMcCurdy's "three-gltf-viewer" and SketchFab's official Unity Editor importer. I believe GLTFUtility is failing to set up this material correctly because it's intended to be a Standard shader with transparency setup.
     
    Last edited: Sep 11, 2019
    Siccity likes this.
  28. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    173
    @DerrickBarra I'm glad that worked for you :)

    1) I'm not a fan of post-installation setup, but if there really is no other way to keep the shaders in builds, I guess I'll have to. Thanks for bringing it up.

    2) I think for best results we need to use both. The Asset cache system ensures we dont get dublicates in the editor.

    3) There is some animation support in GLTFUtility, but it is likely that something in that particular model isn't supported yet. You can test an animation in unity by selecting it in the project window. It will show up in the preview window under the inspector.

    4) Transparency is not yet supported in the shader. I might be adding support very soon.
     
    Last edited: Sep 13, 2019
    DerrickBarra likes this.
  29. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    173
    GLTFUtility now supports different alpha modes on the new jsondotnet branch which will soon be merged into master

    upload_2019-9-13_19-11-5.png
     
    pachermann and DerrickBarra like this.
  30. DerrickBarra

    DerrickBarra

    Joined:
    Nov 19, 2013
    Posts:
    119
    @Siccity dang that was quick! Awesome work!
     
    Siccity likes this.
  31. MobilCC

    MobilCC

    Joined:
    Aug 12, 2019
    Posts:
    4
    Hi,


    @Siccity Thanks for the updated version, it works well so far, but I have some questions with the animations ...

    I updated to the latest GLTFUtility, (and using the JSON.net version) but I can't make the animation work with the legacy clips.

    First of all, how should I access the animations? I use the GLTFUtility Importer class and the ImportGLB function.
    It returns a GameObject but no animations in it. (I tried to access these with GetComponent<Animation>()).

    If I add the animations inside the Importer (inside LoadInternal()), I got an animation component but it doesn't play anything when I call the anim.play().

    Code (CSharp):
    1. Animation anim = go.AddComponent<Animation>() as Animation;
    2. foreach (GLTFAnimation.ImportResult animation in animations)
    3. {
    4.        anim.AddClip(animation.clip, animation.clip.name);
    5. }
    Am I doing something wrong?

    Thanks in advance! :)
     
    Last edited: Sep 17, 2019
  32. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    173
    Importer.ImportGLB has an overload that takes 3 parameters.
    Code (CSharp):
    1. public static GameObject ImportGLB(string filepath, ImportSettings importSettings, out GLTFAnimation.ImportResult[] animations)
    That last parameter returns the animations found by the importer. (animations[n].clip)

    I don't think it returns legacy animations though. Try setting the 'legacy' bool manually

    https://docs.unity3d.com/ScriptReference/AnimationClip-legacy.html
     
  33. MobilCC

    MobilCC

    Joined:
    Aug 12, 2019
    Posts:
    4
    OMG, I don't know how I missed this parameter. o_O Thanks!

    I'll try it with the legacy (I already tried it in an earlier version, but I hope it will work now) and I'll tell you if it's working.
     
    Siccity likes this.
  34. MobilCC

    MobilCC

    Joined:
    Aug 12, 2019
    Posts:
    4
    Yeah, it's definitely works with the legacy "hack".
    Although I got some glitch effect with this modell while animating: ,
    but I think it's because I exported the gltf to glb with blender and maybe I misconfigured something. ¯\_(ツ)_/¯

    Now I tested with this:
    )

    and works perfectly. :)
     
    Siccity likes this.
  35. DerrickBarra

    DerrickBarra

    Joined:
    Nov 19, 2013
    Posts:
    119
    @Siccity I modified your latest version of the GLTFImage.cs GetImage() to work with both the Unity editor and on mobile, you should place this modified function into your next release.

    Code (CSharp):
    1. public ImportResult GetImage(string directoryRoot, GLTFBufferView.ImportResult[] bufferViews) {
    2.             ImportResult result = new ImportResult();
    3.             result.isAsset = false;
    4.  
    5.             if (!string.IsNullOrEmpty(uri) && File.Exists(directoryRoot + uri)) {
    6. #if UNITY_EDITOR
    7.                 result.texture = UnityEditor.AssetDatabase.LoadAssetAtPath(directoryRoot + uri, typeof(Texture2D)) as Texture2D;
    8.  
    9.                 if( result.texture != null )
    10.                 {
    11.                     result.isAsset = true;
    12.                     return result;
    13.                 }
    14.                 else
    15.                 {
    16.                     byte[ ] fileData = File.ReadAllBytes( directoryRoot + uri );
    17.                     result.texture = new Texture2D( 2, 2 );
    18.                     result.texture.LoadImage( fileData );
    19.  
    20.                     result.isAsset = true;
    21.                     return result;
    22.                 }
    23. #else
    24.                 byte[ ] fileData = File.ReadAllBytes( directoryRoot + uri );
    25.                 result.texture = new Texture2D( 2, 2 );
    26.                 result.texture.LoadImage( fileData );
    27.  
    28.                 result.isAsset = true;
    29.                 return result;
    30. #endif
    31.                 Debug.Log("Couldn't load texture at " + directoryRoot + uri);
    32.                 return null;
    33.             } else if (bufferView.HasValue && !string.IsNullOrEmpty(mimeType)) {
    34.                 byte[] bytes = bufferViews[bufferView.Value].bytes;
    35.                 result.texture = new Texture2D(2, 2);
    36.                 // If this fails, you may need to find "Image Conversion" package and enable it
    37.                 if (result.texture.LoadImage(bytes)) {
    38.                     return result;
    39.                 } else {
    40.                     Debug.Log("mimeType not supported: " + mimeType);
    41.                     return null;
    42.                 }
    43.             } else {
    44.                 Debug.Log("Couldn't find texture at " + directoryRoot + uri);
    45.                 return null;
    46.             }
    47.         }
     
  36. DerrickBarra

    DerrickBarra

    Joined:
    Nov 19, 2013
    Posts:
    119
    @Siccity Sorry to double post, I just finished testing out some GLTF models on mobile (Android) that contain animations. The Legacy clip loading works well in Editor. However, loading a model in mobile runtime causes the following errors...

    Code (CSharp):
    1. AndroidPlayer(ADB@127.0.0.1:34999)</i> Can't use AnimationClip::SetCurve at Runtime on non Legacy AnimationClips
    2. UnityEngine.AnimationClip:SetCurve(String, Type, String, AnimationCurve)
    3. Siccity.GLTFUtility.GLTFAnimation:Import(ImportResult[], ImportResult[]) (at D:\Unity Hub\Git Repos\BrandXR-Discovery\Assets\Plugins\Format Readers\GLTFUtility\Scripts\Spec\GLTFAnimation.cs:103)
    4. Siccity.GLTFUtility.GLTFAnimationExtensions:Import(List`1, ImportResult[], ImportResult[]) (at D:\Unity Hub\Git Repos\BrandXR-Discovery\Assets\Plugins\Format Readers\GLTFUtility\Scripts\Spec\GLTFAnimation.cs:137)
    5. Siccity.GLTFUtility.Importer:LoadInternal(GLTFObject, String, ImportSettings, ImportResult[]&) (at D:\Unity Hub\Git Repos\BrandXR-Discovery\Assets\Plugins\Format Readers\GLTFUtility\Scripts\Importer.cs:93)
    6. Siccity.GLTFUtility.Importer:ImportGLTF(String, ImportSettings, ImportResult[]&) (at D:\Unity Hub\Git Repos\BrandXR-Discovery\Assets\Plugins\Format Readers\GLTFUtility\Scripts\Importer.cs:78)
    7. BrandXR.SketchfabManager:LoadGLTFModel(String) (at D:\Unity Hub\Git Repos\BrandXR-Discovery\Assets\Scripts\Model Loading\SketchfabManager.cs:910)
    8. BrandXR.<ModelInitialize>d__44:MoveNext() (at D:\Unity Hub\Git Repos\BrandXR-Discovery\Assets\Scripts\Model Loading\SketchfabManager.cs:514)
    9. UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
    10.  
    11. [/Users/builduser/buildslave/unity/build/Runtime/Animation/AnimationClip.cpp line 1296]
    12. (Filename: D Line: 0)
    To fix this is pretty simple, in GLTFAnimation.cs Import(), add the line result.clip.legacy = true; right after the clip is named! Voila, working animations on mobile.
     
  37. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    173
    Why are you setting result.isAsset to true for loaded images that aren't assets? I'm pretty sure that will cause issues in the editor.
     
    DerrickBarra likes this.
  38. DerrickBarra

    DerrickBarra

    Joined:
    Nov 19, 2013
    Posts:
    119
    No reason actually, I didn't dive too deeply into the code, I assumed result.isAsset was a flag used by a return function to determine if the asset was found. I've edited my code appropriately, thanks for the heads up!
     
  39. Umresh

    Umresh

    Joined:
    Oct 14, 2013
    Posts:
    45
    Hi, I have a .glb file on s3 and i want to load it. Is there a possible way to load ?
     
  40. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    173
    What is s3? If it's a website you should download the file first, then load it.
     
  41. Umresh

    Umresh

    Joined:
    Oct 14, 2013
    Posts:
    45
    Amazon s3 (AWS) online storage. My requirement is to load from url in runtime.
     
  42. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    173
    They probably have an API as well to download the file. Once you got it downloaded you can load it with Importer.LoadFromFile
     
  43. DerrickBarra

    DerrickBarra

    Joined:
    Nov 19, 2013
    Posts:
    119
    @Siccity : Just wanted to give you props, so far we've been able to demo our Sketchfab loader and things are working well. I can't wait to implement the async/multithreading version once it's been completed!
     
    Siccity likes this.
  44. DerrickBarra

    DerrickBarra

    Joined:
    Nov 19, 2013
    Posts:
    119
    @Siccity : I tried downloading the latest from the main branch (which includes multithreading). And there are a number of errors after importing. It looks like scripts in the Editor folder are trying to reference scripts outside of the editor folder so they can't be located (even though they are all in the same namespace).

    upload_2019-10-6_20-55-52.png
     
  45. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    173
    There are two asmdef files in the project, one for runtime and one for editor. Try selecting the editor one, and in the inspector, under references, add the runtime one.

    It seems to me that Unity changed the way that list is serialized, which destroys compatability.
     
  46. DerrickBarra

    DerrickBarra

    Joined:
    Nov 19, 2013
    Posts:
    119
    @Siccity I narrowed those bugs down to an incorrect import on my end, so you're good!

    I started using the new Importer.ImportGLTFAsync() function. But I noticed that the Action callback doesn't receive a reference to the generated 3D model or the animations. I didn't spot anywhere else these variables would be received either.

    So I modified ImportGLTFAsync() and LoadAsync() accordingly to make it pass the generated model and animations to the Action callback. Feel free to add this functionality to the main branch on Github.

    Code (CSharp):
    1. public static void ImportGLTFAsync(string filepath, ImportSettings importSettings, Action<GameObject, GLTFAnimation.ImportResult[]> onFinished) {
    2.             string json = File.ReadAllText(filepath);
    3.  
    4.             // Parse json
    5.             LoadAsync(json, filepath, importSettings, onFinished).RunCoroutine();
    6.         }
    Code (CSharp):
    1. private static IEnumerator LoadAsync(string json, string filepath, ImportSettings importSettings, Action<GameObject, GLTFAnimation.ImportResult[ ]> onFinished ) {
    2.             // Threaded deserialization
    3.             Task<GLTFObject> deserializeTask = new Task<GLTFObject>(() => JsonConvert.DeserializeObject<GLTFObject>(json));
    4.             deserializeTask.Start();
    5.             while (!deserializeTask.IsCompleted) yield return null;
    6.             GLTFObject gltfObject = deserializeTask.Result;
    7.  
    8.             // directory root is sometimes used for loading buffers from containing file, or local images
    9.             string directoryRoot = Directory.GetParent(filepath).ToString() + "/";
    10.  
    11.             importSettings.shaders.CacheDefaultShaders();
    12.  
    13.             // Setup import tasks
    14.             List<ImportTask> importTasks = new List<ImportTask>();
    15.  
    16.             GLTFBuffer.ImportTask bufferTask = new GLTFBuffer.ImportTask(gltfObject.buffers, filepath);
    17.             importTasks.Add(bufferTask);
    18.             GLTFBufferView.ImportTask bufferViewTask = new GLTFBufferView.ImportTask(gltfObject.bufferViews, bufferTask);
    19.             importTasks.Add(bufferViewTask);
    20.             GLTFAccessor.ImportTask accessorTask = new GLTFAccessor.ImportTask(gltfObject.accessors, bufferViewTask);
    21.             importTasks.Add(accessorTask);
    22.             GLTFImage.ImportTask imageTask = new GLTFImage.ImportTask(gltfObject.images, directoryRoot, bufferViewTask);
    23.             importTasks.Add(imageTask);
    24.             GLTFTexture.ImportTask textureTask = new GLTFTexture.ImportTask(gltfObject.textures, imageTask);
    25.             importTasks.Add(textureTask);
    26.             GLTFMaterial.ImportTask materialTask = new GLTFMaterial.ImportTask(gltfObject.materials, textureTask, importSettings);
    27.             importTasks.Add(materialTask);
    28.             GLTFMesh.ImportTask meshTask = new GLTFMesh.ImportTask(gltfObject.meshes, accessorTask, materialTask, importSettings);
    29.             importTasks.Add(meshTask);
    30.             GLTFSkin.ImportTask skinTask = new GLTFSkin.ImportTask(gltfObject.skins, accessorTask);
    31.             importTasks.Add(skinTask);
    32.             GLTFNode.ImportTask nodeTask = new GLTFNode.ImportTask(gltfObject.nodes, meshTask, skinTask);
    33.             importTasks.Add(nodeTask);
    34.  
    35.             // Ignite
    36.             for (int i = 0; i < importTasks.Count; i++) {
    37.                 TaskSupervisor(importTasks[i]).RunCoroutine();
    38.             }
    39.  
    40.             // Fire onFinished when all tasks have completed
    41.             if (onFinished != null) {
    42.                 // Wait for all tasks to finish
    43.                 while (!importTasks.All(x => x.IsCompleted)) yield return null;
    44.  
    45.                 GLTFAnimation.ImportResult[ ] animations = gltfObject.animations.Import( accessorTask.Result, nodeTask.Result );
    46.  
    47.                 onFinished( nodeTask.Result.GetRoot(), animations );
    48.             }
    49.         }
     
    Last edited: Oct 7, 2019
    Siccity likes this.
  47. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    173
    Added :)

    Working on making room for a draco extension now
     
  48. DerrickBarra

    DerrickBarra

    Joined:
    Nov 19, 2013
    Posts:
    119
    Hey @Siccity, here's a couple of notes, these are basically feature requests, let me know what you think...

    1 - Progress Callback & Value : It would be beneficial to have a loading progress value and a callback on progress updates, so we can provide users with a loading bar during import progress.

    2 - Cancel Import : In scenarios where the device gives us a Low Memory warning (which means a crash is about to happen), it would be very useful to have a command to Cancel the loading operation and free up the resources from the in-progress import (so we don't end up with a memory leak)

    3 - Expected Import Size : Being able to query GLTFUtility to see the expected performance requirements for a model would prevent scenarios where imports are attempted on models + textures that bring the devices in use memory into Low Memory territory, prevent crashes during model import. This could be done by evaluating the models textures and import sizes to generate the number of bytes necessary to complete the import.

    4 - Import Settings : Going along with the previous feature, being able to request that GLTFUtility import textures using optional settings ( max texture size, mipmap on/off, color depth ) would be beneficial in preventing low memory crashes during import.
     
    Siccity likes this.
  49. DerrickBarra

    DerrickBarra

    Joined:
    Nov 19, 2013
    Posts:
    119
    Hi again @Siccity, I've been testing out GLTFUtility against a few different models from the web. In my testing, I'm expecting to see import results similar to the Sketchfab viewer.

    upload_2019-10-30_12-22-39.png
    I'm using a testing scene with a single directional light, nothing special here...

    upload_2019-10-30_12-21-37.png

    - This model loads in using the Metallic material, but the metallic values are between .9 and 1. Making the model come in incredibly dark.

    ---

    upload_2019-10-30_12-27-54.png

    - This R2-D2 model loads in using a specular material with a very high glossiness value for its materials (.7-1). Like before the model shows up incredibly dark. If we switch to the metallic shader for testing you'll see that it looks as expected.

    ---

    upload_2019-10-30_12-36-7.png

    - And just for reference, here's a similar R2-D2 that only uses the metallic shader, it imports as expected with all metallic materials.


    I've mentioned before the project I'm working on loads in models from the Sketchfab API, so I have no control over them. But users will likely expect similar results to the Sketchfab viewer, any ideas what's causing these odd imports?
     
  50. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    173
    I see that you submitted an issue on GitHub with a solution. Did it solve this problem?
     
unityunity