Example #1
0
    public void LoadUrl(string url)
    {
#if !NO_GLTFAST
        if (gltf1 != null)
        {
            gltf1.onLoadComplete -= GLTFast_onLoadComplete;
            gltf1 = null;
        }
#endif
#if UNITY_GLTF
        if (gltf2 != null)
        {
            gltf2.onLoadComplete -= UnityGltf_OnLoadComplete;
            gltf2 = null;
        }
#endif

        if (go1 != null)
        {
            Destroy(go1);
        }
        if (go2 != null)
        {
            Destroy(go2);
        }

        Debug.Log("loading " + url);

        startTime = Time.realtimeSinceStartup;
#if !NO_GLTFAST
        time1Update(-1);
#endif
#if UNITY_GLTF
        time2Update(-1);
#endif

        go1 = new GameObject();
        go2 = new GameObject();

#if !NO_GLTFAST
        gltf1 = url.EndsWith(".gltf", System.StringComparison.OrdinalIgnoreCase)
            ? go1.AddComponent <GLTFast.GltfAsset>()
            : go1.AddComponent <GLTFast.GlbAsset>();
        gltf1.url             = url;
        gltf1.onLoadComplete += GLTFast_onLoadComplete;
#endif
#if UNITY_GLTF
        go2.transform.rotation = Quaternion.Euler(0, 180, 0);
        gltf2                 = go2.AddComponent <UnityGLTFLoader>();
        gltf2.GLTFUri         = url;
        gltf2.onLoadComplete += UnityGltf_OnLoadComplete;
#endif

        urlChanged(url);
    }
Example #2
0
    public async Task LoadUrl(string url)
    {
#if UNITY_GLTF
        if (gltf2 != null)
        {
            gltf2.onLoadComplete -= UnityGltf_OnLoadComplete;
            gltf2 = null;
        }
#endif

        if (go1 != null)
        {
            gltf1.ClearScenes();
            Destroy(go1);
        }
        if (go2 != null)
        {
            Destroy(go2);
        }

        // Wait one frame to minimize distortion by current frame's delta time
        await Task.Yield();

        Debug.Log("loading " + url);

        startTime = Time.realtimeSinceStartup;
        urlChanged(url);
        loadingBegin();

#if !NO_GLTFAST
        go1 = new GameObject();

#if UNITY_DOTS_HYBRID
        gltf1 = go1.AddComponent <GltfEntityAsset>();
#else
        gltf1 = go1.AddComponent <GltfAsset>();
#endif
        gltf1.loadOnStartup = false;
        var success = await gltf1.Load(url, null, deferAgent);

        loadingEnd();
        if (success)
        {
            if (!gltf1.currentSceneId.HasValue && gltf1.sceneCount > 0)
            {
                // Fallback to first scene
                Debug.LogWarning("glTF has no main scene. Falling back to first scene.");
                gltf1.InstantiateScene(0);
            }
            GLTFast_onLoadComplete(gltf1);
        }
        else
        {
            Debug.LogError("TestLoader: loading failed!");
        }
#endif
#if UNITY_GLTF
        go2 = new GameObject();
        go2.transform.rotation = Quaternion.Euler(0, 180, 0);
        gltf2                 = go2.AddComponent <UnityGLTFLoader>();
        gltf2.GLTFUri         = url;
        gltf2.onLoadComplete += UnityGltf_OnLoadComplete;
#endif
    }