Search Unity

  1. Unity 2019.4 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  3. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

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:
    203
    Ideally should support all render pipelines. But I don't test other than the default, so you will have to test and report potential issues.
     
  2. Umresh

    Umresh

    Joined:
    Oct 14, 2013
    Posts:
    53
    Hey, have you added support for draco compression?
     
  3. hawken

    hawken

    Joined:
    Aug 22, 2013
    Posts:
    535
    got URL loading working with the following code:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Siccity.GLTFUtility;
    5. using UnityEngine.Networking;
    6. public class ModelLoader : MonoBehaviour
    7. {
    8.     string objectUrl = "http://yourwebsite.com/Duck.gltf";
    9.     string objectName = "duck_from_url.gltf";
    10.     public void OnLoadTest()
    11.     {
    12.         StartCoroutine(ImportObjectFromURL());
    13.     }
    14.     IEnumerator ImportObjectFromURL()
    15.     {
    16.         WWW www = new WWW(objectUrl);
    17.         yield return www;
    18.         string writePath = Application.dataPath + "/gltf_files/" + objectName;
    19.         System.IO.File.WriteAllBytes(writePath, www.bytes);
    20.         yield return new WaitForSeconds(1);
    21.         ImportGLTFAsync(writePath);
    22.     }
    23.     void ImportGLTFAsync(string filepath) {
    24.         Importer.ImportGLTFAsync(filepath, new ImportSettings(), OnFinishAsync);
    25.     }
    26.     void OnFinishAsync(GameObject result, GLTFAnimation.ImportResult[] air) {
    27.         Debug.Log("Finished importing " + result.name);
    28.     }
    29. }
     
  4. hawken

    hawken

    Joined:
    Aug 22, 2013
    Posts:
    535
    Siccity likes this.
  5. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    203
    I took a look at both models. I'm not sure why the grass model doesn't import correctly. As far as I can see, everything in the .gltf file is supported already.

    The mccree model comes in all black because the model uses 'KHR_materials_unlit', which is not supported yet. I also noticed that the meshes themselves load in correctly, but the transforms in the hierarchy are very weirdly set up, and this might confuse GLTFUtility.

    Both of these models need to be supported and support for KHR_materials_unlit needs to be added.
     
  6. hawken

    hawken

    Joined:
    Aug 22, 2013
    Posts:
    535
    I am now testing with a simple cube.
    http://hawkenking.com/client/modelloader/test_cube.gltf

    I'm not entirely sure why it comes in distorted either, when dragging the model into an online viewer, it works ok here:
    https://gltf-viewer.donmccurdy.com/

    and validates fine here:
    https://github.khronos.org/glTF-Validator/

    but I get a distorted result here, the same as in GLTFUtility:
    https://pissang.github.io/clay-viewer/editor/

    I tried exporting a simple cube from blender and it works fine.
    http://hawkenking.com/client/modelloader/blender_cube.gltf
     
    Last edited: Apr 2, 2020
  7. jhocking

    jhocking

    Joined:
    Nov 21, 2009
    Posts:
    773
    This sounds very useful for working gltf, so I can't wait to try it out. Just one clarification: does this support export or only import? The feature list on github has export with unchecked boxes, so I'm assuming that means it's on your roadmap but isn't implemented yet.
     
  8. DJNicky

    DJNicky

    Joined:
    Jul 17, 2017
    Posts:
    1
    It looks like all C4D exported models get distorted. The same models being exported to .gltf by other programs do seem to work
     
  9. hawken

    hawken

    Joined:
    Aug 22, 2013
    Posts:
    535
    I'm trying to reach out to them to support vertex colors so maybe it's something they can look at, the output qualifies as standard compliant... maybe it's the order of the output?
     
  10. Fangh

    Fangh

    Joined:
    Apr 19, 2013
    Posts:
    71
    EDIT : I FOUND THE ANSWER HERE

    Hello.
    I do this on PC and it's working :
    2020-05-28 18_32_34-Zukurri (Debugging) - Microsoft Visual Studio.png

    But when launch the app on my iPad, I got this error (value cannot be null (shader)) :
    upload_2020-5-28_18-33-39.png

    It may have something to do with this
    upload_2020-5-28_18-40-50.png
     
    Last edited: May 28, 2020
    Siccity likes this.
  11. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    203
    Fangh likes this.
  12. arronbbo

    arronbbo

    Joined:
    Jan 14, 2017
    Posts:
    4
    Hi Siccity, I have a question about GLTFUtilities and shadows and maybe you could clarify. I'm having an issue with gltfutilities selecting the Standard Transparency (Metallic/Specular) shader variants for materials that don't need it and would be better off with the Standard non-transparent variants, and this is an issue particularly regarding shadow culling.

    upload_2020-6-10_19-4-23.png

    This is an example of shadow culling on the GLTFUtlities Standard shader variants

    upload_2020-6-10_19-5-36.png

    This is an example of a basic cube that was assigned the Standard Transparent (Metallic) shader. This issue being the assigning of the transparent shader leaves us very little options regarding lighting and shadow culling for an otherwise opaque object.

    I believe this might stem from how GLTFUtilities determines what shader to assign, and it appears to assign a shader depending on the alphaMode determined in as part of the import task results. I can't see what logic it uses to determine the alphaModa of an imported material.

    upload_2020-6-10_19-12-13.png
    Here is a target obj we tried to load.

    upload_2020-6-10_19-12-37.png
    Here is the target object as it was loaded in-scene, you can see we have a bit of an issue with the obj being assigned the Transparent (Metallic) shader. I'm guessing it because parts of the imported combined mesh are in-fact supposed to be transparent so it assigns the Transparent shader Mesh to the entire material?

    upload_2020-6-10_19-15-31.png
    Here's an example with the Standard shader applied, also fixing our issues with shadow culling early.

    Anyways it would help greatly if we could figure out a way around this issue, so let me your thoughts if I'm missing something, or if there/s something that can be fixed your side regarding the assigning of shader or the culling of shadows on the transparent shaders, I would really appreciate it, thanks!

    And keep up the good work!
     
  13. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    203
    GLTFUtility loads the transparent shader if the GLTF file says it requires it. Otherwise, the opaque shader is loaded. It surely looks like materials that should have been exported with opaque materials though. Can you send me the test file so I can see what's in it?
     
  14. arronbbo

    arronbbo

    Joined:
    Jan 14, 2017
    Posts:
    4
  15. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    203
    Looking in the .gltf file exported by sketchfab, i can see that the body (Boden) material has alphaMode set to BLEND. This makes GLTFUtility use a transparency shader.
    upload_2020-6-11_16-50-12.png
     
  16. arronbbo

    arronbbo

    Joined:
    Jan 14, 2017
    Posts:
    4
    Okay, so these issues would have to be addressed on the artists side, and I now understand utilities reads straight from the file, thanks!
     
  17. arronbbo

    arronbbo

    Joined:
    Jan 14, 2017
    Posts:
    4
    Would it be possible to do something with the transparent shaders to prevent shadow culling?
     
  18. jonaslindberg

    jonaslindberg

    Joined:
    Nov 28, 2017
    Posts:
    5
    I'm running into issues loading any GLTF file from disk during runtime when textures needs to be loaded.

    Code I'm running:
    GameObject model = Importer.LoadFromFile(aPathInMyAssetFolderOrElsewhereOnMyDisk);


    Console says:
    Invalid AssetDatabase path: /Users/me/Library/Application Support/DefaultCompany/ProjectName/Files/GLTF_Models/Model/texture.jpg. Use path relative to the project folder.


    It doesn't matter if the gltf is within our outside the project folder.

    As well as:
    GLTFImage.cs ToTexture2D() ERROR: Cannot connect to destination host UnityEngine.Debug:LogError(Object) Siccity.GLTFUtility.<CreateTextureAsync>d__3:MoveNext() (at Assets/Plugins/GLTFUtility-master/Scripts/Spec/GLTFImage.cs:65) Siccity.GLTFUtility.<GetTextureCached>d__3:MoveNext() (at Assets/Plugins/GLTFUtility-master/Scripts/Spec/GLTFTexture.cs:29) Siccity.GLTFUtility.<CreateMaterial>d__5:MoveNext() (at Assets/Plugins/GLTFUtility-master/Scripts/Spec/GLTFMaterial.cs:166) Siccity.GLTFUtility.<CreateMaterial>d__14:MoveNext() (at Assets/Plugins/GLTFUtility-master/Scripts/Spec/GLTFMaterial.cs:42) Siccity.GLTFUtility.<OnCoroutine>d__4:MoveNext() (at Assets/Plugins/GLTFUtility-master/Scripts/Spec/GLTFMaterial.cs:318) Siccity.GLTFUtility.ImportTask1:RunSynchronously() (at Assets/Plugins/GLTFUtility-master/Scripts/Importer.cs:161) Siccity.GLTFUtility.Importer:LoadInternal(GLTFObject, String, Byte[], Int64, ImportSettings, AnimationClip[]&) (at Assets/Plugins/GLTFUtility-master/Scripts/Importer.cs:205) Siccity.GLTFUtility.Importer:ImportGLTF(String, ImportSettings, AnimationClip[]&) (at Assets/Plugins/GLTFUtility-master/Scripts/Importer.cs:141) Siccity.GLTFUtility.Importer:LoadFromFile(String, ImportSettings, AnimationClip[]&, Format) (at Assets/Plugins/GLTFUtility-master/Scripts/Importer.cs:32) Siccity.GLTFUtility.Importer:LoadFromFile(String, Format) (at Assets/Plugins/GLTFUtility-master/Scripts/Importer.cs:16) FirebaseGLTFLoader:LoadModel(String) (at Assets/FirebaseGLTFLoader.cs:77) FirebaseGLTFLoader:DebugMethod() (at Assets/FirebaseGLTFLoader.cs:26)


    I realise that this might be down to user error but if so I'd be happy to be corrected on how to use this tool correctly!

    I can't understand how to run Importer.LoadFromFile with a local path that perhaps would make
    UnityEditor.AssetDatabase.LoadAssetAtPath()
    happy...

    Example of a file that I have this issue with (I have not found any that works): https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/TextureCoordinateTest/glTF

    Also posted as an issue here: https://github.com/Siccity/GLTFUtility/issues/79 but realised I might have better luck getting an answer here.
     
  19. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    203
    in the import settings you should be able to override which shaders GLTFUtility uses. If doing runtime, there should be an import method override that takes some options that can do the same.
     
  20. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    203
    Sorry for the late response. This sounds like a bug in the runtime import process which needs to be fixed.
     
  21. DerrickBarra

    DerrickBarra

    Joined:
    Nov 19, 2013
    Posts:
    121
    @Siccity Hey Siccity! I've been working with a company called DGG that has a tool called RapidCompact, they let us optimize our GLTF files with both Draco and KTX2 textures.

    I have the opportunity to create GLTF files with both of those two optimizations, so I figured I would ask their team to take some un-optimized models from Sketchfab and convert them over so you can use them when researching or working on adding support.



    This sketchfab model has like 50+ textures, and after optimization, we create a single 4k atlas color map. And the Rapid Compact tool is generating a GLTF with both Draco and KTX2, which you can download here.

    Now I haven't actually found a GLTF Viewer or tool that can actually import this file, if you know of one feel free to let me know!

    If you can think of anything you'd like to me to throw through this optimizer tool let me know.
     
  22. TheJavierD

    TheJavierD

    Joined:
    Jan 6, 2017
    Posts:
    37
    Hi!, and thanks for your work!. I do use your importer, I like it.

    I just updated the code from a very old version that I had running, and I found that the latest code on github ends up in an infinite loop when trying to load a model Synchronously


    private static GameObject LoadInternal() is where the infinite loop happens, specifically in:


    GLTFMaterial.ImportTask materialTask = new GLTFMaterial.ImportTask(gltfObject.materials, textureTask, importSettings);
    materialTask.RunSynchronously();

    Gets stuck on an infinite loop in while (en.MoveNext()) { }; not sure why, but I thought i'd let you know.

    The model i used for testing is

    but I doubt that matters

    Async works well though!
     
    Last edited: Jun 25, 2020
    Siccity likes this.
  23. TheJavierD

    TheJavierD

    Joined:
    Jan 6, 2017
    Posts:
    37
    Hey so for some strange reason, the shaders that are built in show most of this model in black:



    If i change them to standard shader they show color, what could it be?

    **** UPDATE *****

    this issue is related to tangents, if i comment out where tangents are assigned in
    GLTFMesh.ToMesh() it works properly, it also works properly if i do mesh.RecalculateTangents();
     
    Last edited: Jul 1, 2020 at 10:17 PM
  24. DerrickBarra

    DerrickBarra

    Joined:
    Nov 19, 2013
    Posts:
    121
    @TheJavierD In my experience, it could be that your scene is missing a skybox cubemap that the metallic shader uses for lighting calculations. Set a cubemap to Window->Rendering->Lighting Settings->Environment Reflections for your scene. You can find free cubemaps available on the Asset Store.
     
  25. TheJavierD

    TheJavierD

    Joined:
    Jan 6, 2017
    Posts:
    37
    No that's not really the case, I have a skybox

    This other model also loads completely black, but changing to standard shader doesn't really help in this case. If i were to switch to a basic unlit shader it'd show the textures

     
  26. TheJavierD

    TheJavierD

    Joined:
    Jan 6, 2017
    Posts:
    37
    So I also have a ton of issues with models that use the transparent shader.

    This model for example:


    Is supposed to look like this:




    In general most models with transparency have issues
     
  27. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    203
    This is because of the way Unity draws transparency. Something to do with not writing to camera depth buffer. Not much I can do about that.
     
  28. TheJavierD

    TheJavierD

    Joined:
    Jan 6, 2017
    Posts:
    37
    Thanks Siccity, do you have any idea what could be happening with the "Game Pirate adventure map" model?.

    Also, not sure you saw but I posted an update to the issues with the "Medieval fantasy book", the problem there are tangents. What could I do to fix this?

    Thanks again!
     
  29. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    203
    Not sure. Haven't had the time to look into it. My best bet is load the gltf into unity and check its tangents with this tool https://gist.github.com/Siccity/5cbfd8dd931f03cd088df491ae24d0a8 , and compare results with another, more polished gltf importer. If they don't match, there's something wrong with my import process.
     
  30. TheJavierD

    TheJavierD

    Joined:
    Jan 6, 2017
    Posts:
    37
    Hi so I think that the tangents were probably wrong, but the thing is that it does not use a normal map so it shouldn't even try to make use of them.

    I noticed that the shaders are not paying attention to the EnableKeywords IE:
    mat.EnableKeyword("_NORMALMAP")

    So i added this
    #pragma shader_feature_local _NORMALMAP

    wrapped normal mapping in an #if _NORMALMAP and the issue with the Book is fixed.

    The issue with the pirate map remains a mystery to me.

    Another mystery is why in this model, the background (that tree, etc) is facing the wrong side

     
unityunity