Ejemplo n.º 1
0
 public void UnloadChildren()
 {
     foreach (PagedLOD child in this.CommitedChildren)
     {
         GameObject.Destroy(child.Go);
     }
     this.CommitedChildren.Clear();
     this.childrenStatus = ChildrenStatus.Unstaged;
 }
Ejemplo n.º 2
0
 public bool Commit()
 {
     if (this.childrenStatus == ChildrenStatus.Staged)
     {
         this.childrenStatus = ChildrenStatus.Commited;
         //this.Content.Initialize(this.Tileset.TilesetOptions.CreateColliders);
         return(true);
     }
     return(false);
 }
Ejemplo n.º 3
0
        public PagedLOD(string name, string dir, Transform parent, int depth)
        {
            this.dir = dir;

            this.Go      = new GameObject();
            this.Go.name = name;
            this.Go.transform.SetParent(parent, false);
            //this.Go.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector;

            this.childrenStatus = ChildrenStatus.Unstaged;

            this.CommitedChildren = new List <PagedLOD>();

            this.FrameNumberOfLastTraversal = -1;

            this.Depth = depth;
        }
Ejemplo n.º 4
0
        bool MarkStagingChildren(ref int stagingCount)
        {
            if (stagingCount == 0)
            {
                return(false);
            }
            // recursively check every child's children's status to see if they are staging, if true, do NOT destory this child
            if (this.childrenStatus == ChildrenStatus.Unstaged)
            {
                return(false);
            }
            else if (this.childrenStatus == ChildrenStatus.Staging)
            {
                this.unity3MXBComponent.LRUCache.MarkUsed(this);
                return(true);
            }
            else if (this.childrenStatus == ChildrenStatus.Staged)
            {
                this.StagedChildren.Clear();
                this.childrenStatus = ChildrenStatus.Unstaged;
                --stagingCount;
                return(false);
            }

            bool hasStagingChid = false;

            foreach (PagedLOD child in this.CommitedChildren)
            {
                if (child.childrenStatus == ChildrenStatus.Staging)
                {
                    hasStagingChid = true;
                }
                else
                {
                    hasStagingChid = hasStagingChid | child.MarkStagingChildren(ref stagingCount);
                }
            }
            if (hasStagingChid)
            {
                this.unity3MXBComponent.LRUCache.MarkUsed(this);
            }
            return(hasStagingChid);
        }
Ejemplo n.º 5
0
        public void Traverse(int frameCount, CamState[] camStates, ref int loadCount, ref int stagingCount)
        {
            if (camStates.Length == 0)
            {
                return;
            }
            this.FrameNumberOfLastTraversal = frameCount;

            // TODO: optimize run speed

            // cull by bounding sphere
            bool  isInSide       = false;
            float screenDiameter = 0;

            foreach (CamState camState in camStates)
            {
                PlaneClipMask mask = this.BoundingSphere.IntersectPlanes(camState.planes, PlaneClipMask.GetDefaultMask());
                if (mask.Intersection != IntersectionType.OUTSIDE)
                {
                    isInSide       = true;
                    screenDiameter = Mathf.Max(screenDiameter, this.BoundingSphere.ScreenDiameter(camState.pixelSizeVector));
                }
            }
            if (isInSide == false)
            {
                this.EnableRenderer(false);
                MarkStagingChildren(ref stagingCount);
                return;
            }

            // traverse based on screenDiameter
            if (screenDiameter < MaxScreenDiameter || this.ChildrenFiles.Count == 0)
            {
                this.EnableRenderer(true);
                MarkStagingChildren(ref stagingCount);
            }
            else
            {
                // commit
                if (this.childrenStatus == ChildrenStatus.Staged)
                {
                    this.EnableRenderer(true);
                    if (loadCount >= 5) // TODO: export 5 as a global option
                    {
                        return;
                    }
                    foreach (RawPagedLOD stagedChild in this.StagedChildren)
                    {
                        PagedLOD commitedChild = new PagedLOD(stagedChild.id, this.Go.transform, stagedChild.dir, this.Depth + 1);
                        commitedChild.unity3MXBComponent = this.unity3MXBComponent;
                        commitedChild.BBMin             = stagedChild.BBMin;
                        commitedChild.BBMax             = stagedChild.BBMax;
                        commitedChild.BoundingSphere    = stagedChild.BoundingSphere;
                        commitedChild.MaxScreenDiameter = stagedChild.MaxScreenDiameter;
                        commitedChild.ChildrenFiles     = stagedChild.ChildrenFiles;
                        if (stagedChild.IsPointCloud)
                        {
                            commitedChild.AddPointCloud(stagedChild.PointClouds);
                        }
                        else
                        {
                            commitedChild.AddMeshTexture(stagedChild.TexMeshs);
                        }
                        this.CommitedChildren.Add(commitedChild);
                    }
                    this.StagedChildren.Clear();
                    this.childrenStatus = ChildrenStatus.Commited;
                    this.unity3MXBComponent.LRUCache.Add(this);
                    --stagingCount;
                    ++loadCount;
                }
                // commited
                if (this.childrenStatus == ChildrenStatus.Commited)
                {
                    this.EnableRenderer(false);
                    this.unity3MXBComponent.LRUCache.MarkUsed(this);
                    foreach (PagedLOD pagedLOD in this.CommitedChildren)
                    {
                        pagedLOD.Traverse(Time.frameCount, camStates, ref loadCount, ref stagingCount);
                    }
                }
                else
                {
                    this.EnableRenderer(true);
                    if (this.childrenStatus == ChildrenStatus.Unstaged)
                    {
                        this.childrenStatus = ChildrenStatus.Staging;
                        ++stagingCount;
                        PCQueue.Current.EnqueueItem(() =>
                        {
                            // stage
                            StageChildren(this.dir, this.ChildrenFiles, this.StagedChildren);
                            this.childrenStatus = ChildrenStatus.Staged;
                        });
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public void Traverse(int frameCount, List <CamState> camStates)
        {
            if (camStates.Count == 0)
            {
                return;
            }
            this.FrameNumberOfLastTraversal = frameCount;

            // TODO: optimize run speed

            // cull by bounding sphere
            bool  isInSide       = false;
            float screenDiameter = 0;
            float minDistance    = float.MaxValue;

            foreach (CamState camState in camStates)
            {
                PlaneClipMask mask = this.BoundingSphere.IntersectPlanes(camState.planes, PlaneClipMask.GetDefaultMask());
                if (mask.Intersection != IntersectionType.OUTSIDE)
                {
                    isInSide       = true;
                    screenDiameter = Mathf.Max(screenDiameter, this.BoundingSphere.ScreenDiameter(camState.pixelSizeVector));
                    float distance = this.BoundingSphere.DistanceTo(camState.position);
                    minDistance = Mathf.Min(distance, minDistance); // We take the min in case multiple cameras, reset dist to max float on frame reset
                }
            }
            if (isInSide == false)
            {
                this.EnableRenderer(false);
                MarkStagingChildren();
                return;
            }

            // traverse based on screenDiameter
            if (screenDiameter < MaxScreenDiameter || this.ChildrenFiles.Count == 0)
            {
                this.EnableRenderer(true);
                MarkStagingChildren();
            }
            else
            {
                // commited
                if (this.childrenStatus == ChildrenStatus.Commited)
                {
                    this.EnableRenderer(false);
                    this.unity3mxComponent.LRUCache.MarkUsed(this);
                    foreach (PagedLOD pagedLOD in this.CommitedChildren)
                    {
                        pagedLOD.Traverse(Time.frameCount, camStates);
                    }
                }
                else if (this.childrenStatus == ChildrenStatus.Staged)
                {
                    this.EnableRenderer(true);
                    this.unity3mxComponent.LRUCache.MarkUsed(this);
                }
                else
                {
                    this.EnableRenderer(true);
                    if (this.childrenStatus == ChildrenStatus.Unstaged)
                    {
                        if (!RequestManager.Current.Full())
                        {
                            this.childrenStatus = ChildrenStatus.Staging;

                            Promise <bool> finished = new Promise <bool>();
                            finished.Then((success) =>
                            {
                                if (this.CommitedChildren.Count >= this.ChildrenFiles.Count)
                                {
                                    this.childrenStatus = PagedLOD.ChildrenStatus.Staged;
                                    this.unity3mxComponent.LRUCache.Add(this);
                                    this.unity3mxComponent.CommitingQueue.Enqueue(this);
                                }
                                else
                                {
                                    this.childrenStatus = ChildrenStatus.Unstaged;
                                }
                            });

                            Promise started = new Promise();
                            started.Then(() =>
                            {
                                this.unity3mxComponent.StartCoroutine(this.StageChildrenCo(finished));
                            });
                            Request request = new Request(this, this.Priority(minDistance), started, finished);
                            RequestManager.Current.EnqueRequest(request);
                        }
                    }
                }
            }
        }