735
edits
Line 46: | Line 46: | ||
* The materials are built into a SGMaterialLibrary (simgear/simgear/scene/material/matlib.cxx). | * The materials are built into a SGMaterialLibrary (simgear/simgear/scene/material/matlib.cxx). | ||
* In the old scenery, the terrain consists of a triangular mesh that describes both the shape (elevation) of the terrain and the landclass of the terrain. Each triangle of the terrain mesh as a single landclass (e.g. "EvergreenBroadCover"). | * In the old scenery, the terrain consists of a triangular mesh that describes both the shape (elevation) of the terrain and the landclass of the terrain. Each triangle of the terrain mesh as a single landclass (e.g. "EvergreenBroadCover"). | ||
* In the WS3.0 scenery, the terrain mesh only contains shape (elevation) information. The landclass of the terrain is provided by the texture. Each triangle can contain bits of multiple landclasses. | * In the WS3.0 scenery, the terrain mesh only contains shape (elevation) information, and is created at runtime from a heightmap. The landclass of the terrain is provided by the texture. Each triangle can contain bits of multiple landclasses. | ||
=== How Trees are grown - old scenery === | === How Trees are grown - old scenery === | ||
Line 63: | Line 63: | ||
#### generates a series of random points across the triangle, each of which will be rendered into a tree. | #### generates a series of random points across the triangle, each of which will be rendered into a tree. | ||
### line 1089 converts that intermediate datastructure into the OSG code to actually render the trees. | ### line 1089 converts that intermediate datastructure into the OSG code to actually render the trees. | ||
=== How to grow trees in WS3.0 === | |||
As noted above, one of the key differences between the old scenery and WS3.0 is that a given triangle in the terrain mesh doesn't have a single landclass. Instead we need to look it up. | |||
* simgear/simgear/scene/tgdb/VPBTechnique.cxx is used to create the mesh from the heightmap. | |||
* The key function is VPBTechnique::init. At present this creates a BufferData containing an EffectGeode. | |||
* We (probably?) want to change that so it creates an osg::Group node, which contains both the EffectGeode, plus some other nodes containing the trees and other random objects. | |||
** Because this is already loaded in a PagedLOD, provided we generate this at the right LOD Level (_terrainTile->getTileID().level==6 perhaps? or configurable), we don't need to mess around with any callbacks. | |||
* The landclass information is stored in the first texture, assigned by applyColorLayers(). | |||
* It should be possible to interpolate between the texture coordinates of the generated mesh and lookup the landclass of the texture. (osg::Texture2D.getImage()->getColor(const Vec2 &texcoord). | |||
* We could extend the MaterialLibrary to include lookup via landclass code. The simplest way would be to add new <name> values that match the values from the landclass texture as integers. For the hackathon, I suggest just adding landclasses 22-24 to the "EvergreenForest" material. | |||
So the pseudo-code might look like this: | |||
# IF (_terrainTile->getTileID().level==6) THEN | |||
# FOREACH triangle (geometry) : | |||
## Generate a set of random points on the triangle | |||
## FOREACH point (random points) : | |||
### Determine the texture coordinate of the point | |||
### Determine the landclass of the point in the texture | |||
### Lookup the landclass in the MaterialsLibrary | |||
### IF the landclass has mat->get_wood_coverage() > 0 THEN add the point to an appropriate TreeBin in an SGTreeBinList | |||
# use the SGTileDetailsCallback::createForest() method to create the appropriate forest in OSG |