Exemple #1
0
        /// <summary>
        /// Lower priority will be loaded sooner
        /// </summary>
        /// <param name="priority"></param>
        public void RequestContent(float priority)
        {
            if (this.Tileset.RequestManager.Full())
            {
                return;
            }
            if (this.HasEmptyContent)
            {
                return;
            }
            if (this.ContentState == Unity3DTileContentState.UNLOADED ||
                this.ContentState == Unity3DTileContentState.EXPIRED)
            {
                this.ContentState = Unity3DTileContentState.LOADING;

                Promise <bool> finished = new Promise <bool>();
                finished.Then((success) =>
                {
                    this.Tileset.Statistics.NetworkError       = !success;
                    this.Tileset.Statistics.RequestsThisFrame += 1;
                    if (success)
                    {
                        this.ContentState = Unity3DTileContentState.PROCESSING;
                        this.Content.SetShadowMode(this.Tileset.TilesetOptions.ShadowCastingMode, this.Tileset.TilesetOptions.RecieveShadows);
                        this.Tileset.Statistics.LoadedContentCount += 1;
                        this.Tileset.Statistics.TotalTilesLoaded   += 1;
                        // Track tile in cache as soon as it has downloaded content, but still queue it for processing
                        CacheRequestStatus status = this.Tileset.LRUContent.Add(this);
                        if (status == CacheRequestStatus.ADDED)
                        {
                            this.Tileset.ProcessingQueue.Enqueue(this);
                        }
                        else
                        {
                            UnloadContent();
                        }
                    }
                    else
                    {
                        UnloadContent();
                    }
                });

                Promise started = new Promise();
                started.Then(() =>
                {
                    GameObject go              = new GameObject(Id);
                    go.transform.parent        = this.Tileset.Behaviour.transform;
                    go.transform.localPosition = new Vector3(this.computedTransform.m03, this.computedTransform.m13, this.computedTransform.m23);
                    go.transform.localRotation = this.computedTransform.rotation;
                    go.transform.localScale    = this.computedTransform.lossyScale;
                    go.layer = this.Tileset.Behaviour.gameObject.layer;
                    go.SetActive(false);
                    var info     = go.AddComponent <TileInfo>();
                    info.Tile    = this;
                    this.Content = new Unity3DTileContent(go);

                    if (ContentType == Unity3DTileContentType.B3DM)
                    {
                        B3DMComponent b3dmCo = go.AddComponent <B3DMComponent>();
                        b3dmCo.Url           = this.ContentUrl;
                        b3dmCo.Multithreaded = this.Tileset.TilesetOptions.GLTFMultithreadedLoad;
                        b3dmCo.MaximumLod    = this.Tileset.TilesetOptions.GLTFMaximumLOD;
                        if (!string.IsNullOrEmpty(this.Tileset.TilesetOptions.ShaderOverride))
                        {
                            b3dmCo.ShaderOverride = Shader.Find(this.Tileset.TilesetOptions.ShaderOverride);
                        }
                        b3dmCo.AddColliders    = false;
                        b3dmCo.DownloadOnStart = false;
                        this.Tileset.Behaviour.StartCoroutine(b3dmCo.Download(finished));
                    }
                    else if (ContentType == Unity3DTileContentType.PNTS)
                    {
                        PNTSComponent pntsCo   = go.AddComponent <PNTSComponent>();
                        pntsCo.Url             = UrlUtils.RemoveQuery(this.ContentUrl);
                        pntsCo.ShaderOverride  = Shader.Find("Point Cloud/Point");
                        pntsCo.DownloadOnStart = false;
                        this.Tileset.Behaviour.StartCoroutine(pntsCo.Download(finished));
                    }
                });
                Request request = new Request(this, priority, started, finished);
                this.Tileset.RequestManager.EnqueRequest(request);
            }
        }
Exemple #2
0
        /// <summary>
        /// Lower priority will be loaded sooner
        /// </summary>
        /// <param name="priority"></param>
        public void RequestContent(float priority)
        {
            if (this.tileset.RequestManager.Full())
            {
                return;
            }
            if (this.HasEmptyContent)
            {
                return;
            }
            if (this.ContentState == Unity3DTileContentState.UNLOADED ||
                this.ContentState == Unity3DTileContentState.EXPIRED)
            {
                this.ContentState = Unity3DTileContentState.LOADING;

                Promise <bool> finished = new Promise <bool>();
                finished.Then((success) =>
                {
                    this.tileset.Statistics.NetworkError       = !success;
                    this.tileset.Statistics.RequestsThisFrame += 1;
                    if (success)
                    {
                        this.ContentState = Unity3DTileContentState.PROCESSING;
                        this.tileset.ProcessingQueue.Enqueue(this);
                        this.Content.SetShadowMode(this.tileset.Options.ShadowCastingMode, this.tileset.Options.RecieveShadows);
                        this.tileset.Statistics.LoadedContentCount += 1;
                        this.tileset.Statistics.TotalTilesLoaded   += 1;
                    }
                    else
                    {
                        UnloadContent();
                    }
                });

                Promise started = new Promise();
                started.Then(() =>
                {
                    GameObject go              = new GameObject(Id);
                    go.transform.parent        = this.tileset.Behaviour.transform;
                    go.transform.localPosition = Vector3.zero;
                    go.transform.localRotation = Quaternion.identity;
                    go.layer = this.tileset.Behaviour.gameObject.layer;
                    go.SetActive(false);
                    this.Content = new Unity3DTileContent(go);

                    if (ContentType == Unity3DTileContentType.B3DM)
                    {
                        B3DMComponent b3dmCo   = go.AddComponent <B3DMComponent>();
                        b3dmCo.Url             = this.ContentUrl;
                        b3dmCo.Multithreaded   = this.tileset.Options.GLTFMultithreadedLoad;
                        b3dmCo.MaximumLod      = this.tileset.Options.GLTFMaximumLOD;
                        b3dmCo.ShaderOverride  = this.tileset.Options.GLTFShaderOverride;
                        b3dmCo.addColliders    = false;
                        b3dmCo.DownloadOnStart = false;
                        this.tileset.Behaviour.StartCoroutine(b3dmCo.Download(finished));
                    }
                    else if (ContentType == Unity3DTileContentType.PNTS)
                    {
                        PNTSComponent pntsCo   = go.AddComponent <PNTSComponent>();
                        pntsCo.Url             = UriHelper.RemoveQuery(this.ContentUrl);
                        pntsCo.ShaderOverride  = Shader.Find("Point Cloud/Point");
                        pntsCo.DownloadOnStart = false;
                        this.tileset.Behaviour.StartCoroutine(pntsCo.Download(finished));
                    }
                });
                Request request = new Request(this, priority, started, finished);
                this.tileset.RequestManager.EnqueRequest(request);
            }
        }
        /// <summary>
        /// Lower priority will be loaded sooner
        /// </summary>
        /// <param name="priority"></param>
        public void RequestContent(float priority)
        {
            if (HasEmptyContent || ContentState != Unity3DTileContentState.UNLOADED)
            {
                return;
            }

            Promise <bool> finished = new Promise <bool>();

            finished.Then((success) =>
            {
                Tileset.Statistics.RequestsThisFrame++;
                Tileset.Statistics.NetworkErrorsThisFrame += success ? 0 : 1;
                bool duplicate = false;
                if (success && Tileset.TileCache.Add(this, out duplicate))
                {
                    ContentState = Unity3DTileContentState.PROCESSING;
                    Tileset.ProcessingQueue.Enqueue(this);
                }
                else if (!duplicate)
                {
                    UnloadContent();
                }
            });

            Promise started = new Promise();

            started.Then(() =>
            {
                GameObject go              = new GameObject(Id);
                go.transform.parent        = Tileset.Behaviour.transform;
                go.transform.localPosition =
                    new Vector3(computedTransform.m03, computedTransform.m13, computedTransform.m23);
                go.transform.localRotation = computedTransform.rotation;
                go.transform.localScale    = computedTransform.lossyScale;
                go.layer = Tileset.Behaviour.gameObject.layer;
                go.SetActive(false);
                var info        = go.AddComponent <Unity3DTileInfo>();
                info.Tile       = this;
                info.FrameState = FrameState;
                Content         = new Unity3DTileContent(go);

                if (ContentType == Unity3DTileContentType.B3DM)
                {
                    B3DMComponent b3dmCo = go.AddComponent <B3DMComponent>();
                    b3dmCo.Url           = ContentUrl;
                    b3dmCo.Multithreaded = Tileset.TilesetOptions.GLTFMultithreadedLoad;
                    b3dmCo.MaximumLod    = Tileset.TilesetOptions.GLTFMaximumLOD;
                    if (!string.IsNullOrEmpty(Tileset.TilesetOptions.ShaderOverride))
                    {
                        b3dmCo.ShaderOverride = Shader.Find(Tileset.TilesetOptions.ShaderOverride);
                    }
                    b3dmCo.AddColliders    = false;
                    b3dmCo.DownloadOnStart = false;
                    Tileset.Behaviour.StartCoroutine(b3dmCo.Download(finished));
                }
                else if (ContentType == Unity3DTileContentType.PNTS)
                {
                    PNTSComponent pntsCo   = go.AddComponent <PNTSComponent>();
                    pntsCo.Url             = UrlUtils.RemoveQuery(ContentUrl);
                    pntsCo.ShaderOverride  = Shader.Find("Point Cloud/Point");
                    pntsCo.DownloadOnStart = false;
                    Tileset.Behaviour.StartCoroutine(pntsCo.Download(finished));
                }
            });

            Tileset.RequestManager.EnqueRequest(new Request(this, started, finished));
        }