Esempio n. 1
0
        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);
            });
        }
Esempio n. 2
0
        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);
            });
        }
Esempio n. 3
0
        public Unity3DTileset(Unity3DTilesetOptions options, MonoBehaviour behaviour, RequestManager requestManager)
        {
            this.Options        = options;
            this.Behaviour      = behaviour;
            this.RequestManager = requestManager;
            this.traversal      = new Unity3DTilesetTraversal(this);
            this.LRUContent     = new LRUCache <Unity3DTile>();
            this.DeepestDepth   = 0;

            // TODO: Detect data Uri?
            if (Path.GetExtension(options.Url) == ".json")
            {
                this.tilesetUrl = this.Options.Url;
                this.basePath   = UriHelper.GetBaseUri(this.Options.Url, true);
            }
            else
            {
                this.basePath   = this.Options.Url;
                this.tilesetUrl = UriHelper.JoinUrls(this.Options.Url, "tileset.json", true);
            }
            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);
            });
        }
Esempio n. 4
0
        private Unity3DTile LoadTileset(string tilesetUrl, Schema.Tileset tileset, Unity3DTile parentTile)
        {
            if (tileset.Asset == null)
            {
                Debug.LogError("Tileset must have an asset property");
                return(null);
            }
            if (tileset.Asset.Version != "0.0" && tileset.Asset.Version != "1.0")
            {
                Debug.LogError("Tileset must be 3D Tiles version 0.0 or 1.0");
                return(null);
            }
            // Add tileset version to base path
            bool hasVersionQuery = new Regex(@"/[?&]v=/").IsMatch(tilesetUrl);

            if (!hasVersionQuery && !new Uri(tilesetUrl).IsFile)
            {
                string version = "0.0";
                if (tileset.Asset.TilesetVersion != null)
                {
                    version = tileset.Asset.TilesetVersion;
                }
                string versionQuery = "v=" + version;

                this.basePath = UrlUtils.SetQuery(this.basePath, versionQuery);
                tilesetUrl    = UrlUtils.SetQuery(tilesetUrl, versionQuery);
            }
            // A tileset.json referenced from a tile may exist in a different directory than the root tileset.
            // Get the basePath relative to the external tileset.
            string      basePath = UrlUtils.GetBaseUri(tilesetUrl);
            Unity3DTile rootTile = new Unity3DTile(this, basePath, tileset.Root, parentTile);

            Statistics.NumberOfTilesTotal++;

            // Loop through the Tile json data and create a tree of Unity3DTiles
            Stack <Unity3DTile> stack = new Stack <Unity3DTile>();

            stack.Push(rootTile);
            while (stack.Count > 0)
            {
                Unity3DTile tile3D = stack.Pop();
                for (int i = 0; i < tile3D.tile.Children.Count; i++)
                {
                    Unity3DTile child = new Unity3DTile(this, basePath, tile3D.tile.Children[i], tile3D);
                    this.DeepestDepth = Math.Max(child.Depth, this.DeepestDepth);
                    Statistics.NumberOfTilesTotal++;
                    stack.Push(child);
                }
                // TODO consider using CullWithChildrenBounds optimization here
            }
            this.loadTimestamp = DateTime.UtcNow;
            return(rootTile);
        }