| 294 | |
| 295 | |
| 296 | void TerrCell::_init( TerrainBlock *terrain, |
| 297 | const Point2I &point, |
| 298 | U32 size, |
| 299 | U32 level ) |
| 300 | { |
| 301 | PROFILE_SCOPE( TerrCell_Init ); |
| 302 | |
| 303 | mTerrain = terrain; |
| 304 | mPoint = point; |
| 305 | mSize = size; |
| 306 | mLevel = level; |
| 307 | |
| 308 | // Generate a VB (and maybe a PB) for this cell, unless we are the Root cell. |
| 309 | if ( level > 0 ) |
| 310 | { |
| 311 | _updateVertexBuffer(); |
| 312 | _updatePrimitiveBuffer(); |
| 313 | } |
| 314 | |
| 315 | if ( mSize <= smMinCellSize ) |
| 316 | { |
| 317 | // Update our bounds and materials... the |
| 318 | // parent will use it to update itself. |
| 319 | _updateBounds(); |
| 320 | _updateMaterials(); |
| 321 | return; |
| 322 | } |
| 323 | |
| 324 | // Create our children and update our |
| 325 | // bounds and materials from them. |
| 326 | |
| 327 | const U32 childSize = mSize / 2; |
| 328 | const U32 childLevel = mLevel + 1; |
| 329 | |
| 330 | mChildren[0] = new TerrCell; |
| 331 | mChildren[0]->_init( mTerrain, |
| 332 | Point2I( mPoint.x, mPoint.y ), |
| 333 | childSize, |
| 334 | childLevel ); |
| 335 | mBounds = mChildren[0]->getBounds(); |
| 336 | mMaterials = mChildren[0]->getMaterials(); |
| 337 | |
| 338 | mChildren[1] = new TerrCell; |
| 339 | mChildren[1]->_init( mTerrain, |
| 340 | Point2I( mPoint.x + childSize, mPoint.y ), |
| 341 | childSize, |
| 342 | childLevel ); |
| 343 | mBounds.intersect( mChildren[1]->getBounds() ); |
| 344 | mMaterials |= mChildren[1]->getMaterials(); |
| 345 | |
| 346 | mChildren[2] = new TerrCell; |
| 347 | mChildren[2]->_init( mTerrain, |
| 348 | Point2I( mPoint.x, mPoint.y + childSize ), |
| 349 | childSize, |
| 350 | childLevel ); |
| 351 | mBounds.intersect( mChildren[2]->getBounds() ); |
| 352 | mMaterials |= mChildren[2]->getMaterials(); |
| 353 | |