current position:Home>Unity loading oblique photography-C# analysis osgb (1)

Unity loading oblique photography-C# analysis osgb (1)

2022-11-24 09:40:14I don't want to either but

下载 https://download.csdn.net/download/WantFK/87009338https://download.csdn.net/download/WantFK/87009338
1.提取osgb的图片信息\mesh顶点 \UV\ 三角序列\下一级name\bounds\视距 和保存  (提取

        目的 解析osgbThe process is too cumbersome These few data are really used

2.unity Make the initial tile prefab Organized into a spatial quadtree 优化索引                                            (预制件 

        目的  The part that the camera looks at is always only a part and the part that cannot be seen is reducedGPUStress needs to be hidden

        At the same time, how to quickly determine which targets the camera is looking at

        Index optimization when loading tiles(It was all mindless traversal before)

        Calculated ahead of time for each tilebounds(Previously, the center point and radius were used) Quadtree leavesboundsand more accurate individual tilesbounds

3.读取并使用                                                                                                                (解压

4.数据结构分析

        

         

 

        Store all data as a quadtree 

        主干TreeFour 

        自身bounds and four leavesbounds Four leaf objects

        叶子Leaf

         自身 The next level is four leavesbounds和对象 Individuals contained in each child leaf

        I only have two layers here No amount of it would be appropriate, but it would increase the burden

Doing it every frame is definitely not advisable Do some delays Roughly proportional to moving the camera a tile-sized distance in place

 void FixedUpdate()
    {
        //延迟处理 When the camera position movement amount deviation is 10Or the rotation amount is ~ 进行更新
        if ((CameraMin.transform.position - oldCamera_position).magnitude > 10)//10 Real-time detection interval   || !oldCamera_rotation.Equals(CameraMin.transform.rotation)Add rotation as desired How the rotation sets the interval?
        {
            slope = Mathf.Tan(CameraMin.fieldOfView * Mathf.Deg2Rad * 0.5f);
            GeometryUtility.CalculateFrustumPlanes(CameraMin, _currentFrustum);
            oldCamera_position = CameraMin.transform.position;
            //oldCamera_rotation = CameraMin.transform.rotation;
            // 先进行加载 隐藏 
            StartCoroutine(All_LoadLayer());
            //卸载 队列 1 Store unloading requirements Uninstall the aggregate  
        }

        StartCoroutine(All_LoadLayer());

     Find the set of tile-level individuals that the camera is looking at 通过遍历判断AABBWhether to store in the camera rangeList<user_osg>

public class user_osg 
{
    public float distanceold = 0;           //Record the last distance 减少循环
    public int isOnselect = 0;              //Record whether it has left the camera 减少循环
    public Bounds _bounds;
    public Transform ThisObj;               //The initial tile entity
    public Transform _pagedDatas;           //关联下一级
    public Transform ThisTransform;         //自己
    public user_osg(Transform B, Transform A,Transform C, Bounds _bounds)
    {
        this._pagedDatas = B;
        this.ThisObj = A;
        this.ThisTransform = C;
        this._bounds = _bounds;
    }
}

        Determine whether the individual is within the range of the camera(Although it has been judged roughly from the above  There are trade-offs here Choose Default In Camera and Judge Again 各有优劣)

        结果存在

         //加载栈 后进先出 Amortize the data to each frame execution
    Stack<Transform> TaskDels1 = new Stack<Transform>();

          加载栈 

 if (!isLoading)
        {
            if (TaskDels1.Count == 0) return;
            LoadWork();
        }
    }
    async void LoadWork()
    {
        isLoading = true;
        await RequestLoadAndUnload(TaskDels1.Pop());
        isLoading = false;
        //TaskDels1.Pop();
    }

        (You didn't design the unload queue for the whole scenario  At this stage, if all the tiles are loaded to the end, the memory will actually be used total file2/3大小  这里只加载了17到19层级)
        

一 提取osgbinformation and write a new document

1.打开ReaderOSGB.cs 组件 关闭Ceshis.cs

 

 Set the read file directory onclickbutton("E:/接收文件/osgb/1");

 文件写入目录 可以自定义 (But it is best to store it outside the project

PathName = Path.Combine(Path.Combine(Application.dataPath, "../"), "OsgbData") ;

需要手动设置

0.  ReaderOSGB.cs 173 out directory where empty files can be output       

 if (!File.Exists(rootFileL + ".osgb"))
                {
                    Debug.Log(rootFileL+"The name is abnormal");
                    break;
                }

1.ReaderOSGB.cs It needs to be filled in according to the actual situation  Initial tile level(例如 17 The file is not forked and at the same time clearer) and the final level you want (19 为止 Adjust upwards as needed)  osgbThe initial level of the structure(14 Some files are inconsistent So it needs to be adjusted manually 15 16都有可能)

2.

  InsideFuntion(scencepatent, a, PathName); The initial tile

  InsideFuntionQI(scencepatent, a, PathName);17Tiles

分别输出 A block of output data will be messed up

3.先输出  InsideFuntionQI(scencepatent, a, PathName);17Tiles  如果debug 数据异常 It is possible that the data folder is empty and needs to be deleted manually Otherwise, the main process will be stuck

二 预制件 

如果加载的是osgb文件集 The position of each module needs to be adjusted 

The specific steps are not written in too much detail Leave a message if you need it

copyright notice
author[I don't want to either but],Please bring the original link to reprint, thank you.
https://en.hqmana.com/2022/328/202211240938306987.html

Random recommended