public IEnumerator Download(Promise <bool> loadComplete) { string url = UrlUtils.ReplaceDataProtocol(Url); string dir = UrlUtils.GetBaseUri(url); string file = UrlUtils.GetLastPathSegment(url); if (file.EndsWith(".3mxb", StringComparison.OrdinalIgnoreCase)) { this.Root = new PagedLOD("root", this.transform, dir, 0); this.Root.unity3MXBComponent = this; this.Root.MaxScreenDiameter = 0; this.Root.BoundingSphere = new TileBoundingSphere(new Vector3(0, 0, 0), 1e30f); this.Root.ChildrenFiles = new List <string>(); this.Root.ChildrenFiles.Add(file); yield return(null); } }
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; }); } } } }