Ejemplo n.º 1
0
    // Use this for initialization
    IEnumerator Start()
    {
        yield return(GltfSampleModels.LoadGltfFileUrls());

        var baseUrl = local ? GltfSampleModels.baseUrlLocal : GltfSampleModels.baseUrl;

        // Wait a bit to make sure profiling works
        yield return(new WaitForSeconds(1));

        foreach (var n in GltfSampleModels.gltfFileUrls)
        {
            var url = string.Format(
                "{0}{1}"
                , baseUrl
                , n
                );
            var go = new GameObject(System.IO.Path.GetFileNameWithoutExtension(url));

#if UNITY_GLTF
            var gltf = go.AddComponent <UnityGLTF.GLTFComponent>();
            gltf.GLTFUri = url;
#endif

#if !NO_GLTFAST
            // GLTFast.GLTFast.LoadGlbFile( url, go.transform );
            var gltfAsset = go.AddComponent <GLTFast.GltfAsset>();
            gltfAsset.url = url;
#endif
        }
    }
Ejemplo n.º 2
0
    public IEnumerator SampleModelsTestLoadAllGlb()
    {
        yield return(GltfSampleModels.LoadGlbFileUrls());

        foreach (var file in GltfSampleModels.glbFileUrls)
        {
            var path = string.Format(
#if UNITY_ANDROID && !UNITY_EDITOR
                "{0}"
#else
                "file://{0}"
#endif
                , file
                );

            Debug.LogFormat("Testing {0}", path);

            var go        = new GameObject();
            var gltfAsset = go.AddComponent <GltfAsset>();

            bool done = false;

            gltfAsset.onLoadComplete += (success) => { done = true; Assert.IsTrue(success); };
            gltfAsset.url             = path;

            while (!done)
            {
                yield return(null);
            }
            Object.Destroy(go);
        }
    }
Ejemplo n.º 3
0
    void AddPaths(string[] paths)
    {
#if !UNITY_EDITOR
        string prefix = GltfSampleModels.baseUrl;
#else
        string prefix = GltfSampleModels.baseUrlLocal;
#endif

        var tmpLocalPath = localPath;
        items      = new List <Tuple <string, string> >();
        itemsLocal = new List <Tuple <string, string> >();
        foreach (var path in paths)
        {
            var name = GltfSampleModels.GetNameFromPath(path);
            if (!string.IsNullOrEmpty(prefix))
            {
                var p = string.Format(
                    "{0}/{1}"
                    , prefix
                    , path
                    );
                items.Add(new Tuple <string, string>(name, p));
            }
            var localPath = string.Format(
                "{0}/{1}"
                , tmpLocalPath
                , path
                );
            itemsLocal.Add(new Tuple <string, string>(name, localPath));
        }
    }
Ejemplo n.º 4
0
    public IEnumerator SampleModelsTestCheckFiles()
    {
        yield return(GltfSampleModels.LoadGlbFileUrls());

        CheckFileExist(GltfSampleModels.glbFileUrls);

        yield return(GltfSampleModels.LoadGltfFileUrls());

        CheckFileExist(GltfSampleModels.gltfFileUrls);
    }
Ejemplo n.º 5
0
    public IEnumerator SampleModelsTestCheckFiles()
    {
        yield return(GltfSampleModels.LoadGlbFileUrls());

        Assert.AreEqual(GltfSampleModels.glbFileUrls.Length, 44);
        CheckFileExist(GltfSampleModels.glbFileUrls);

        yield return(GltfSampleModels.LoadGltfFileUrls());

        Assert.AreEqual(GltfSampleModels.gltfFileUrls.Length, 120);
        CheckFileExist(GltfSampleModels.gltfFileUrls);
    }
Ejemplo n.º 6
0
    public IEnumerator SampleModelsTestLoadAllGltf()
    {
        yield return(GltfSampleModels.LoadGltfFileUrls());

        foreach (var file in GltfSampleModels.gltfFileUrls)
        {
            var path = string.Format(
#if UNITY_ANDROID && !UNITY_EDITOR
                "{0}"
#else
                "file://{0}"
#endif
                , Path.Combine(Application.streamingAssetsPath, Path.Combine(prefix, file))
                );

            Debug.LogFormat("Testing {0}", path);

            var webRequest = UnityWebRequest.Get(path);
            yield return(webRequest.SendWebRequest());

            Assert.Null(webRequest.error, webRequest.error);
            Assert.IsFalse(webRequest.isNetworkError);
            Assert.IsFalse(webRequest.isHttpError);
            var json = webRequest.downloadHandler.text;

            Assert.NotNull(json);
            Assert.Greater(json.Length, 0);

            var go = new GameObject(GltfSampleModels.GetNameFromPath(file));
            var materialGenerator = new DefaultMaterialGenerator();
            var glTFast           = new GLTFast.GLTFast(materialGenerator);
            glTFast.LoadGltf(json, path);
            Assert.IsFalse(glTFast.LoadingError);

            yield return(glTFast.WaitForBufferDownloads());

            Assert.False(glTFast.LoadingError);
            yield return(glTFast.WaitForTextureDownloads());

            Assert.False(glTFast.LoadingError);
            yield return(glTFast.Prepare());

            Assert.False(glTFast.LoadingError);
            var success = glTFast.InstantiateGltf(go.transform);
            Assert.IsTrue(success);

            yield return(null);

            glTFast.Destroy();
            Object.Destroy(go);
        }
    }
Ejemplo n.º 7
0
    public IEnumerator SampleModelsTestLoadAllGlb()
    {
        yield return(GltfSampleModels.LoadGlbFileUrls());

        foreach (var file in GltfSampleModels.glbFileUrls)
        {
            var path = string.Format(
#if UNITY_ANDROID && !UNITY_EDITOR
                "{0}"
#else
                "file://{0}"
#endif
                , Path.Combine(Application.streamingAssetsPath, Path.Combine(prefix, file))
                );

            Debug.LogFormat("Testing {0}", path);

            var webRequest = UnityWebRequest.Get(path);
            yield return(webRequest.SendWebRequest());

            Assert.Null(webRequest.error);
            var bytes = webRequest.downloadHandler.data;

            Assert.NotNull(bytes);
            Assert.Greater(bytes.Length, 0);

            var go      = new GameObject();
            var glTFast = new GLTFast.GLTFast();
            glTFast.LoadGlb(bytes, path);
            Assert.False(glTFast.LoadingError);
            yield return(glTFast.WaitForBufferDownloads());

            Assert.False(glTFast.LoadingError);
            yield return(glTFast.WaitForTextureDownloads());

            Assert.False(glTFast.LoadingError);
            yield return(glTFast.Prepare());

            Assert.False(glTFast.LoadingError);
            var success = glTFast.InstanciateGltf(go.transform);
            Assert.True(success);
            yield return(null);

            glTFast.Destroy();
            Object.Destroy(go);
        }
    }
Ejemplo n.º 8
0
    public IEnumerator SampleModelsTestLoadAllGltf()
    {
        yield return(GltfSampleModels.LoadGltfFileUrls());

        var deferAgent = new UninterruptedDeferAgent();

        foreach (var file in GltfSampleModels.gltfFileUrls)
        {
            var path = string.Format(
#if UNITY_ANDROID && !UNITY_EDITOR
                "{0}"
#else
                "file://{0}"
#endif
                , file
                );

            Debug.LogFormat("Testing {0}", path);

            var webRequest = UnityWebRequest.Get(path);
            yield return(webRequest.SendWebRequest());

            Assert.Null(webRequest.error, webRequest.error);
            Assert.IsFalse(webRequest.isNetworkError);
            Assert.IsFalse(webRequest.isHttpError);
            var json = webRequest.downloadHandler.text;

            Assert.NotNull(json);
            Assert.Greater(json.Length, 0);

            var go        = new GameObject(GltfSampleModels.GetNameFromPath(path));
            var gltfAsset = go.AddComponent <GltfAsset>();

            bool done = false;

            gltfAsset.onLoadComplete += (asset, success) => { done = true; Assert.IsTrue(success); };
            gltfAsset.loadOnStartup   = false;
            gltfAsset.Load(path, null, deferAgent);

            while (!done)
            {
                yield return(null);
            }
            Object.Destroy(go);
        }
    }
Ejemplo n.º 9
0
    IEnumerator InitGui()
    {
        #if !UNITY_EDITOR
        string prefix = GltfSampleModels.baseUrl;
#else
        string prefix = GltfSampleModels.baseUrlLocal;
#endif

        var prefixLocal = GltfSampleModels.localPath;

        yield return(GltfSampleModels.LoadGltfFileUrls());

        var names = GltfSampleModels.gltfFileUrls;

        foreach (var n in names)
        {
            var t = GltfSampleModels.GetNameFromPath(n);
            testItems.Add(new System.Tuple <string, string>(
                              t,
                              string.Format(
                                  "{0}/{1}"
                                  , prefix
                                  , n
                                  )
                              )
                          );
            testItemsLocal.Add(new System.Tuple <string, string>(
                                   t,
                                   string.Format(
                                       "{0}/{1}"
                                       , prefixLocal
                                       , n
                                       )
                                   )
                               );
        }
    }