terraintile
I solved this problem. To help others I'll explain my ideas here, so other can use this information as well.
The wrong part in my structure was the function were I modified the height values.
To explain my idea of the right way, it is required to understand how the tiles are initialized.
- Step 1: When the tile is added to the scene graph, it will be traversed in the next frame. - TerrainTile.cpp, line 120
- Step 2: If it is the first traversal, the tile's init() function is called. - TerrainTile.cpp, line 143
- Step 3: If no terrainTechnique is assigned, it assigns the terrainTechnique. - TerrainTile.cpp, line 169
- Step 4: Now a terrainTechnique should be available, so it's init() function is called. - TerrainTile.cpp, line 184
- Step 5: The drawable geometry is created from heightfield in generateGeometry(). - GeometryTechnique.cpp, line 135
- Step 6: The color- and transparency layer are created from imagelayer and blending policy in applyColorLayers() / applyTransparency(). - GeometryTechnique.cpp, line 135+
- Step7: The created tile data buffer is assigned to the _newBufferData pointer, so the next update traversal will use it as current data to display. - GeometryTechnique.cpp, line 145 / 150
If the color / transparency or geometry data should be modified, it must be done prior the data is used to compile the data to display.
e.g. To modify the geometry, you can subclass GeometryTechnique and overwrite the init function. There in you can modify all of the tile's layers. afterwards you call the baseclass implementation via
| Code: � Select � � Contract � |
|
void myTerrainTechnique::init(int dirtyMask, bool assumeMultiThreaded) { // Modify the data [...] // Call base class implementation to init the tile correctly: GeometryTechnique::init(dirtyMask, assumeMultiThreaded); } |
If you have to
modify more than only the tile data you have to overwrite the generating
function.
Example:
In my case I want to cut holes in the terrain,
this means the tile drawable is not longer a regular grid of triangles. This
irregular drawable must be created by my specialized generateGeometry()
function, I have to implement in my subclassed TerrainTechnique.
I know
it is a very simple approach, but oftern the first contact is quite hard, so
this may be a good starter for other beginners out there
So far, thanks to the community
which helped me to reach this point!
I'll be back with my generateGeometry()
problems
Cheers,
浙公网安备 33010602011771号