// 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 } }
public IEnumerator SampleModelsTestCheckFiles() { yield return(GltfSampleModels.LoadGlbFileUrls()); CheckFileExist(GltfSampleModels.glbFileUrls); yield return(GltfSampleModels.LoadGltfFileUrls()); CheckFileExist(GltfSampleModels.gltfFileUrls); }
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); }
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); } }
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); } }
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 ) ) ); } }