Originally planned to start the terrain series, but found that if you want to logically understand the terrain-related details, it is necessary to understand the cesium data scheduling process, so as to better understand, therefore, intends to introduce the overall cesium of the rendering process, Then in the transition to one of the two main modules: terrain data and imagery data. Briefly
Imagine that the Indian Ocean warm Current, through the Himalaya Mountain, formed a drop of water, fell on the Qinghai-Tibet Plateau Tanggula, homeopathic, flooding the Pacific, the Yangtze River from this prolonged. And everything that cesium, begins with an insignificant function:
Through the Requestanimationframe function, the end of each frame is the beginning of the next frame, from the time the cesium starts, until it dies, never stops.
Now, let's start Long March the first step, and finally, the function calls the scene's Render method:
Although the method of render (scene, time) is long, the main elements of the Earth (topography & imagery) are done between the globe's Beginframe and Endframe:
The red highlighted two functions are used to maintain two important logic, Updateandexecutecommands is responsible for data scheduling, such as which tiles need to be created, these tile-related terrain data, and the involved image data between the scheduling, are maintained in the function. But the Updateandexecutecommands function is only responsible for management, that is, the tile class he created is just a one-to-one tasks, not responsible for the implementation of the tasks content (data loading and maintenance). This causes the architecture to be somewhat complex, because it is not a pipelined job, so it requires stateful maintenance. But this is also inevitable, not only to ensure that the function is efficient, not to drag the time consumption of each frame, but also because the real-time to meet the requirements of people (the number of frames can reach or close to 60), each frame required tile queue can be calculated in real time, regardless of the relationship between time and state.
It can be understood that Updateandexecutecommands is a manager, deeds, in contrast, Scene.globe.endFrame, will be involved in the frame of the Globetile download, parsing and other processing.
For example, in simple terms, Updateandexecutecommands is responsible for the above-mentioned things, according to the current frame of the camera's state, first hit a yellow grid, and then check the current state, the terrain and image data in these grids are ready, if ready, Each tile creates a drawcommand to render and draw the ball. If not ready and no matter, anyway, there are endframe function responsible, each job, everyone do their jobs, not very good.
Scene.globe.endFrame in accordance with the instructions to prepare each tile data, all is invisible work, silently dedicate their youth. Here, Promise,worker and other technologies will be used, through the asynchronous and multi-threaded way to alleviate the burden of each frame, and in the main thread, mainly the maintenance of the data state. If a tile's data parsing is complete, the status of the Globetile is updated to renderable (rendered), done. Class relationships
In this process, the relationships of the classes are roughly as follows:
The grid is divided by latitude, and each grid corresponds to a quadtreetile four-fork tree class, which has a globesurfacetile, which holds the terrain data tileterrain and the image data tileimagery. More than one grid is required under the current camera, multiple quadtreetile are required, and the queue is saved in quadtreeprimitive,quadtreeprimitive Unified maintenance of all tile management, The logic operation is realized through Globesurfacetileprovider, and quadtreeprimitive is covered with a globe and scene. Rendering process
The updateandexecutecommands relationship process is as follows:
In the quadtreeprimitive update, call selecttilesforrendering to perhaps the grid currently needed to be created, where the first frame divides the world into two tiles:
In the Queuechildrenloadanddetermineifchildrenareallrenderable function, the four-fork tree is based on these two tiles, That is, all subsequent quadtreetile can be traced back to one of these two tiles:
The created globesurfacetile are stored in the update queue, waiting for the data to be downloaded and parsed, and if there is a ready-to-render globesurfacetile in the current frame, call Adddrawcommandsfortile, Constructed as VBO, and finally rendered through WEBGL. Update process
Update the queue's logic as above, slightly more complex, or focus on the selected parts of the box:
Initially, in Processtileloadqueue, all globesurfacetile in the update queue are traversed, and if no data is found, the state is quadtreetileloadstate. Start, then, shouted: "Sisters, start to pick up."
Brothel is in Globesurfacetile.processstatemachine. Globesurfacetile is the customer here, despite the crowd, but the people here, there are only three kinds: the first time, you go to the Preparenewtile function, first to help you dredge bones: New Tileterrain (), new Terrain data class, To help you moisten the skin: _createtileimageryskeletons, create image data class; it was the old driver, then the usual, to a three warm bar: Processterrainstatemachine to take charge of terrain data loading, Createwatermasktextureifneeded is responsible for the water surface (if the tile is an ocean area), and TileImagery.prototype.processStateMachine is responsible for the loading of the image data; service satisfaction, to pay the bill: renderable = True/state = Quadtreetileloadstate.done.
Through the above description, one of the Earth's rendering processes is mainly four links:
L Grid Division
L Terrain Data
L Imagery Data
L Rendering
And these four links are staggered, although it seems a bit confusing, many functions, but do not know whether you notice, whether it is the rendering process or the update process, is the current state of the response and status updates.
From the process of talking about the general process, do not know whether we still have doubts, or the text of the wrong place, but also hope to make more comments. Of course, this particle size is still a bit large, behind, and you share in each link in the specific technology and optimization strategy.
Cesium principle: 1 The longest frame of the rendering schedule