Beispiel #1
0
        public bool Process()
        {
            if (ContentState == Unity3DTileContentState.PROCESSING)
            {
                ContentState = Unity3DTileContentState.READY;

                Content.SetShadowMode(Tileset.TilesetOptions.ShadowCastingMode,
                                      Tileset.TilesetOptions.RecieveShadows);

                Content.Initialize(Tileset.TilesetOptions.CreateColliders);

                var indexMode = Tileset.TilesetOptions.LoadIndices;
                if (indexMode != IndexMode.Default && indexMode != IndexMode.None)
                {
                    Action <IndexMode, string, string> fail = (mode, url, msg) =>
                    {
                        //we could log a warning here, but if indices are expected but not available
                        //that might not actually be a true error condition
                        //and this would spam the log
                        if (Unity3DTileIndex.EnableLoadWarnings)
                        {
#pragma warning disable 0162
                            Debug.LogWarning("failed to load " + mode + " index for " + ContentUrl + ": " + msg);
#pragma warning restore 0162
                        }
                    };
                    Action <Unity3DTileIndex> success = index => { Content.Index = index; };
                    Tileset.Behaviour.StartCoroutine(Unity3DTileIndex.Load(indexMode, ContentUrl, success, fail));
                }

                return(true);
            }
            return(false);
        }
Beispiel #2
0
 public void UnloadContent()
 {
     if (HasEmptyContent)
     {
         return;
     }
     ContentState = Unity3DTileContentState.UNLOADED;
     if (Content != null && Content.Go != null)
     {
         GameObject.Destroy(Content.Go);
         Content = null;
         Tileset.Behaviour.RequestUnloadUnusedAssets();
     }
 }
Beispiel #3
0
        /// <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));
        }
Beispiel #4
0
        public Unity3DTile(Unity3DTileset tileset, string basePath, Schema.Tile schemaTile, Unity3DTile parent)
        {
            hashCode        = (int)UnityEngine.Random.Range(0, int.MaxValue);
            Tileset         = tileset;
            this.schemaTile = schemaTile;
            if (schemaTile.Content != null)
            {
                Id = Path.GetFileNameWithoutExtension(schemaTile.Content.GetUri());
            }
            if (parent != null)
            {
                parent.Children.Add(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
            transform = schemaTile.UnityTransform();
            var parentTransform = (parent != null) ? parent.computedTransform : tileset.GetRootTransform();

            computedTransform = parentTransform * transform;

            BoundingVolume = CreateBoundingVolume(schemaTile.BoundingVolume, computedTransform);

            // TODO: Add 2D bounding volumes

            if (schemaTile.Content != null && schemaTile.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.
                ContentBoundingVolume = CreateBoundingVolume(schemaTile.Content.BoundingVolume, computedTransform);
            }
            else
            {
                // Default to tile bounding volume
                ContentBoundingVolume = CreateBoundingVolume(schemaTile.BoundingVolume, computedTransform);
            }
            // TODO: Add viewer request volume support
            //if(schemaTile.ViewerRequestVolume != null && schemaTile.ViewerRequestVolume.IsDefined())
            //{
            //    viewerRequestVolume = CreateBoundingVolume(schemaTile.ViewerRequestVolume, transform);
            //}

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

            Parent = parent;

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