Esempio n. 1
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. 2
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. 3
0
        public override IEnumerator Send(string rootUri, string httpRequestPath, Action <string, string> onDownloadString = null, Action <byte[], string> onDownloadBytes = null)
        {
            if (onDownloadBytes == null && onDownloadString == null ||
                onDownloadBytes != null && onDownloadString != null)
            {
                throw new Exception("Send must use either string or byte[] data type");
            }

            string uri = null;

            if (!string.IsNullOrEmpty(rootUri) && !string.IsNullOrEmpty(httpRequestPath))
            {
                uri = UrlUtils.JoinUrls(rootUri, httpRequestPath);
            }
            else if (!string.IsNullOrEmpty(rootUri))
            {
                uri = rootUri;
            }
            else if (!string.IsNullOrEmpty(httpRequestPath))
            {
                uri = httpRequestPath;
            }
            else
            {
                throw new Exception("root URI and http request path both empty");
            }

            UnityWebRequest www = new UnityWebRequest(uri, "GET", new DownloadHandlerBuffer(), null);

            www.timeout = 5000;

#if UNITY_2017_2_OR_NEWER
            yield return(www.SendWebRequest());
#else
            yield return(www.Send());
#endif
            if ((int)www.responseCode >= 400)
            {
                Debug.LogErrorFormat("{0} - {1}", www.responseCode, www.url);
                throw new Exception("Response code invalid");
            }
            if (www.downloadedBytes > int.MaxValue)
            {
                throw new Exception("Stream is larger than can be copied into byte array");
            }
            bool isError = (www.isNetworkError || www.isHttpError);
            onDownloadString?.Invoke(www.downloadHandler.text, isError ? www.error : null);
            onDownloadBytes?.Invoke(www.downloadHandler.data, isError ? www.error : null);
        }
Esempio n. 4
0
 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);
 }
Esempio n. 5
0
        public Unity3DTile(Unity3DTileset tileset, string basePath, Schema.Tile tile, Unity3DTile parent)
        {
            this.hashCode   = (int)UnityEngine.Random.Range(0, int.MaxValue);
            this.Tileset    = tileset;
            this.tile       = tile;
            this.FrameState = new TileFrameState();
            if (tile.Content != null)
            {
                this.Id = Path.GetFileNameWithoutExtension(tile.Content.GetUri());
            }
            if (parent != null)
            {
                parent.Children.Add(this);
                this.Depth = parent.Depth + 1;
            }

            // TODO: Consider using a double percision Matrix library for doing 3d tiles root transform calculations
            // Set the local transform for this tile, default to identity matrix
            this.transform = this.tile.UnityTransform();
            var parentTransform = (parent != null) ? parent.computedTransform : tileset.GetRootTransform();

            this.computedTransform = parentTransform * this.transform;

            this.BoundingVolume = CreateBoundingVolume(tile.BoundingVolume, this.computedTransform);

            // TODO: Add 2D bounding volumes

            if (tile.Content != null && tile.Content.BoundingVolume.IsDefined())
            {
                // Non-leaf tiles may have a content bounding-volume, which is a tight-fit bounding volume
                // around only the features in the tile.  This box is useful for culling for rendering,
                // but not for culling for traversing the tree since it does not guarantee spatial coherence, i.e.,
                // since it only bounds features in the tile, not the entire tile, children may be
                // outside of this box.
                this.ContentBoundingVolume = CreateBoundingVolume(tile.Content.BoundingVolume, this.computedTransform);
            }
            else
            {
                // Default to tile bounding volume
                this.ContentBoundingVolume = CreateBoundingVolume(tile.BoundingVolume, this.computedTransform);
            }
            // TODO: Add viewer request volume support
            //if(tile.ViewerRequestVolume != null && tile.ViewerRequestVolume.IsDefined())
            //{
            //    this.viewerRequestVolume = CreateBoundingVolume(tile.ViewerRequestVolume, transform);
            //}

            if (!tile.Refine.HasValue)
            {
                tile.Refine = (parent == null) ? Schema.TileRefine.REPLACE : parent.tile.Refine.Value;
            }

            this.Parent = parent;

            if (this.HasEmptyContent)
            {
                this.ContentState = Unity3DTileContentState.READY;
            }
            else
            {
                ContentState    = Unity3DTileContentState.UNLOADED;
                this.ContentUrl = UrlUtils.JoinUrls(basePath, tile.Content.GetUri());
            }

            this.HasRenderableContent = false;
            this.HasTilesetContent    = false;
        }
Esempio n. 6
0
        public override IEnumerator LoadStream(string filePath)
        {
            string uri = null;

            if (!string.IsNullOrEmpty(_rootURI) && !string.IsNullOrEmpty(filePath))
            {
                uri = UrlUtils.JoinUrls(_rootURI, filePath);
            }
            else if (!string.IsNullOrEmpty(_rootURI))
            {
                uri = _rootURI;
            }
            else if (!string.IsNullOrEmpty(filePath))
            {
                uri = filePath;
            }
            else
            {
                throw new Exception("root URI and http request path both empty");
            }

#if POOL_DOWNLOAD_HANDLERS
            var downloadBuffer  = bufferPool.Acquire();
            var downloadHandler = new DownloadHandlerPooled(streamPool.Acquire(), downloadBuffer.Buffer);
#else
            var downloadHandler = new DownloadHandlerBuffer();
#endif
            using (UnityWebRequest www = new UnityWebRequest(uri, "GET", downloadHandler, null)) {
                www.timeout = 5000;

#if UNITY_2017_2_OR_NEWER
                yield return(www.SendWebRequest());
#else
                yield return(www.Send());
#endif
                if ((int)www.responseCode >= 400)
                {
                    throw new Exception(string.Format("{0} - {1}", www.responseCode, www.url));
                }
                if (www.downloadedBytes > int.MaxValue)
                {
                    throw new Exception("Stream is larger than can be copied into byte array");
                }
                if (www.isNetworkError || www.isHttpError)
                {
                    LoadedStream = new MemoryStream(new byte[] { }, 0, 0, true, true);
                }
                else
                {
#if POOL_DOWNLOAD_HANDLERS
                    LoadedStream = ((DownloadHandlerPooled)downloadHandler).Stream;
#else
                    byte[] data = downloadHandler.data;
                    LoadedStream = new MemoryStream(data, 0, data.Length, true, true);
#endif
                }
            }
#if POOL_DOWNLOAD_HANDLERS
            bufferPool.Return(downloadBuffer);
            //Debug.Log("buffer pool size " + bufferPool.PoolSize());
#endif
        }