public Unity3DTileset(Unity3DTilesetOptions tilesetOptions, AbstractTilesetBehaviour behaviour) { this.TilesetOptions = tilesetOptions; this.Behaviour = behaviour; this.RequestManager = behaviour.RequestManager; this.ProcessingQueue = behaviour.ProcessingQueue; this.LRUContent = behaviour.LRUCache; this.Traversal = new Unity3DTilesetTraversal(this, behaviour.SceneOptions); this.DeepestDepth = 0; string url = UrlUtils.ReplaceDataProtocol(tilesetOptions.Url); if (UrlUtils.GetLastPathSegment(url).EndsWith(".json", StringComparison.OrdinalIgnoreCase)) { this.basePath = UrlUtils.GetBaseUri(url); this.tilesetUrl = url; } else { this.basePath = url; this.tilesetUrl = UrlUtils.JoinUrls(url, "tileset.json"); } LoadTilesetJson(this.tilesetUrl).Then(json => { // Load Tileset (main tileset or a reference tileset) this.tileset = Schema.Tileset.FromJson(json); this.Root = LoadTileset(this.tilesetUrl, this.tileset, null); this.readyPromise.Resolve(this); }).Catch(error => { Debug.LogError(error.Message + "\n" + error.StackTrace); }); }
public Unity3DTileset(Unity3DTilesetOptions tilesetOptions, AbstractTilesetBehaviour behaviour) { TilesetOptions = tilesetOptions; Behaviour = behaviour; RequestManager = behaviour.RequestManager; ProcessingQueue = behaviour.ProcessingQueue; TileCache = behaviour.TileCache; Traversal = new Unity3DTilesetTraversal(this, behaviour.SceneOptions); DeepestDepth = 0; string url = UrlUtils.ReplaceDataProtocol(tilesetOptions.Url); string tilesetUrl = url; if (!UrlUtils.GetLastPathSegment(url).EndsWith(".json", StringComparison.OrdinalIgnoreCase)) { tilesetUrl = UrlUtils.JoinUrls(url, "tileset.json"); } LoadTilesetJson(tilesetUrl).Then(json => { // Load Tileset (main tileset or a reference tileset) schemaTileset = Schema.Tileset.FromJson(json); Root = LoadTileset(tilesetUrl, schemaTileset, null); }).Catch(error => { Debug.LogError(error.Message + "\n" + error.StackTrace); }); }
protected string MakeAbsoluteUrl(string url) { if (string.IsNullOrEmpty(url)) { return(url); } url = UrlUtils.ReplaceDataProtocol(url); if (!string.IsNullOrEmpty(baseUrl)) { if (!UrlUtils.IsAbsolute(url)) { url = UrlUtils.JoinUrls(baseUrl, url); } else { url = UrlUtils.JoinQuery(baseUrl, url); } } return(url); }
public IEnumerator Download(Promise <bool> loadComplete) { string url = UrlUtils.ReplaceDataProtocol(Url); string dir = UrlUtils.GetBaseUri(url); string file = UrlUtils.GetLastPathSegment(url); ILoader loader = AbstractWebRequestLoader.CreateDefaultRequestLoader(dir); //.glb, .gltf if (file.EndsWith(".b3dm", StringComparison.OrdinalIgnoreCase)) { loader = new B3DMLoader(loader); } var sceneImporter = new GLTFSceneImporter(file, loader); sceneImporter.SceneParent = gameObject.transform; sceneImporter.CustomShaderName = ShaderOverride ? ShaderOverride.name : null; sceneImporter.MaximumLod = MaximumLod; sceneImporter.Collider = AddColliders ? GLTFSceneImporter.ColliderType.Mesh : GLTFSceneImporter.ColliderType.None; loadComplete = loadComplete ?? new Promise <bool>(); yield return(sceneImporter.LoadScene(-1, Multithreaded, sceneObject => loadComplete.Resolve(sceneObject != null))); }
public static IEnumerator Load(IndexMode mode, string tileUrl, Action <Unity3DTileIndex> success, Action <IndexMode, string, string> fail) { if (mode == IndexMode.Default || mode == IndexMode.None) { success(null); yield break; } string url = UrlUtils.ReplaceDataProtocol(tileUrl); string dir = UrlUtils.GetBaseUri(tileUrl); string file = UrlUtils.GetLastPathSegment(tileUrl); var filesToTry = new Queue <string>(); if (mode == IndexMode.ExternalPNG) { filesToTry.Enqueue(UrlUtils.StripUrlExtension(file) + "_index.png"); filesToTry.Enqueue(UrlUtils.ChangeUrlExtension(file, ".png")); } else if (mode == IndexMode.ExternalPPM) { filesToTry.Enqueue(UrlUtils.StripUrlExtension(file) + "_index.ppm"); filesToTry.Enqueue(UrlUtils.ChangeUrlExtension(file, ".ppm")); } else if (mode == IndexMode.ExternalPPMZ) { filesToTry.Enqueue(UrlUtils.StripUrlExtension(file) + "_index.ppmz"); filesToTry.Enqueue(UrlUtils.ChangeUrlExtension(file, ".ppmz")); } else { filesToTry.Enqueue(file); } Stream stream = null; Exception exception = null; string ext = null; while (stream == null && filesToTry.Count > 0) { exception = null; IEnumerator enumerator = null; ILoader loader = null; try { file = filesToTry.Dequeue(); ext = UrlUtils.GetUrlExtension(file).ToLower(); loader = AbstractWebRequestLoader.CreateDefaultRequestLoader(dir); if (ext == ".b3dm") { loader = new B3DMLoader(loader); } //yield return loader.LoadStream(file); //works but can't catch exceptions enumerator = loader.LoadStream(file); } catch (Exception ex) { exception = ex; } while (exception == null) { try { if (!enumerator.MoveNext()) { break; } } catch (Exception ex) { exception = ex; break; } yield return(enumerator.Current); } if (exception == null && loader.LoadedStream != null && loader.LoadedStream.Length > 0) { stream = loader.LoadedStream; stream.Seek(0, SeekOrigin.Begin); } } if (stream == null || stream.Length == 0) { fail(mode, tileUrl, "download failed" + (exception != null ? (" " + exception.Message) : "")); yield break; } try { if (ext == ".b3dm" || ext == ".glb") { success(LoadFromGLB(stream)); } else if (ext == ".gltf") { success(LoadFromGLTF(stream)); } else if (ext == ".png") { success(LoadFromPNG(stream)); } else if (ext == ".ppm" || ext == ".ppmz") { success(LoadFromPPM(stream, compressed: ext == ".ppmz")); } else { fail(mode, tileUrl, "unhandled file type: " + ext); } } catch (Exception ex) { fail(mode, tileUrl, "failed to parse " + file + ": " + ex.Message + "\n" + ex.StackTrace); } }