History: SoC2012 Improve and Demo the Terrain System
Source of version: 35
- «
- »
Copy to clipboard
{maketoc}
!Project Information
Proposal and discussion thread: [http://www.ogre3d.org/forums/viewtopic.php?f=13&t=69553|http://www.ogre3d.org/forums/viewtopic.php?f=13&t=69553]
Mercurial repository: [https://bitbucket.org/xiaoxq/ogre_soc_tpi/overview|https://bitbucket.org/xiaoxq/ogre_soc_tpi/overview]
The basement project: [http://www.ogre3d.org/tikiwiki/SoC2011+Terrain+Paging+Improvements|SoC2011 Terrain Paging Improvements]
!Implementation Design
!!New Terrain File Format
To be able to load LOD asynchronously, we should save height/delta data separately according to the lowest level it belongs to. So the terrain file format has been adjusted as follows:
{BOX(class="")}<pre>
<TERRAIN_CHUNK>
<TERRAINGENERALINFO_CHUNK>
uint8 align; uint16 Size; Real WorldSize;
uint16 MaxBatchSize; uint16 MinBatchSize;
Vector3 Pos;
</TERRAINGENERALINFO_CHUNK>
<TERRAINLODDATA_CHUNK>zip( LOD{n-1} HeightData, DeltaData; )</TERRAINLODDATA_CHUNK>
...
<TERRAINLODDATA_CHUNK>zip( LOD{0} HeightData, DeltaData; )</TERRAINLODDATA_CHUNK>
LayerInstanceList Layers;
LayerBlendData;
<TERRAINDERIVEDDATA_CHUNK> NormalData; </TERRAINDERIVEDDATA_CHUNK>
<TERRAINDERIVEDDATA_CHUNK> ColourMap; </TERRAINDERIVEDDATA_CHUNK>
<TERRAINDERIVEDDATA_CHUNK> LightMap; </TERRAINDERIVEDDATA_CHUNK>
<TERRAINDERIVEDDATA_CHUNK> CompositeMap; </TERRAINDERIVEDDATA_CHUNK>
QuadTree;
</TERRAIN_CHUNK></pre>
{BOX}
The new TERRAIN_CHUNK_ID is 2, but it's not finished yet - by now only LOD data is compressed, which makes the terrain file 3 times larger than previous.
The LOD saving process happens at TerrainLodManager::saveLodData();
When some LOD is requested, just open the file, skip the TERRAINGENERALINFO_CHUNK chunk, and skip the unmatched TERRAINLODDATA_CHUNK chunk, then read the height/delta data into memory. These are done at TerrainLodManager::readLodData();
!!LOD State Machine
Previously, the terrain has only 3 states: Not Prepared, Fully Prepared, Fully Loaded. But now LODs are loaded asynchronously, so the terrain may be only partially prepared/loaded. Every LOD gets its own 3-states, as shown below:
{img fileId="2135" rel="box[g]"}
!!LOD Requests Interface and Implementation
!Guide for Users
!Guide for Developers
!Introduction to the Endless World Sample
!Weekly Progress
!!2012-04-29
*Create repository by importing from kuxv's, and create this wiki page.
*A small fix to make it compilable on my x64 system. Then it runs quite well.
*Merge new changesets from trunk.
*Confirm my development environment: Thinkpad T410s( Intel i5, Nvidia NVS 3100M, 8G memory ), Ubuntu 12.04 64bit. I also have a Win7 64bit, but only for testing.
!!2012-05-06
*Some code cleanup.
!!2012-05-14
*Keep on warming up with the code.
*Start drawing a sequence diagram to show the work flow of LOD and paging.
!!2012-05-20
*Finish the sequence diagram, and get to understand most of the previous implementation ideas.
*Have found some possible buggy point. See them above for detail.
!!2012-05-27
*Start reviewing the code, I think I have understood the idea deeply.
*Small refactoring, extract out a TerrainLodManager, which makes the Terrain component as clear as the original.(80% completed)
!!2012-06-03
*Almost finish extracting the LodManager from Terrain.
*Going to read height/delta once for all.