| 256 | } |
| 257 | |
| 258 | bool TerrainBlock::import( const GBitmap &heightMap, |
| 259 | F32 heightScale, |
| 260 | F32 metersPerPixel, |
| 261 | const Vector<U8> &layerMap, |
| 262 | const Vector<String> &materials, |
| 263 | bool flipYAxis) |
| 264 | { |
| 265 | AssertFatal( isServerObject(), "TerrainBlock::import - This should only be called on the server terrain!" ); |
| 266 | |
| 267 | AssertFatal( heightMap.getWidth() == heightMap.getHeight(), "TerrainBlock::import - Height map is not square!" ); |
| 268 | AssertFatal( isPow2( heightMap.getWidth() ), "TerrainBlock::import - Height map is not power of two!" ); |
| 269 | |
| 270 | // If we don't have a terrain file then add one. |
| 271 | if ( !mFile ) |
| 272 | { |
| 273 | // Get a unique file name for the terrain. |
| 274 | String fileName( getName() ); |
| 275 | if (fileName.isEmpty()) |
| 276 | { |
| 277 | fileName = Torque::Path(Con::getVariable("$Client::MissionFile")).getFileName(); |
| 278 | |
| 279 | if (fileName.isEmpty()) |
| 280 | fileName = "terrain"; |
| 281 | } |
| 282 | String terrainFileName = FS::MakeUniquePath( "levels", fileName, "ter" ); |
| 283 | |
| 284 | if (!TerrainAsset::getAssetByFilename(terrainFileName, &mTerrainAsset)) |
| 285 | { |
| 286 | return false; |
| 287 | } |
| 288 | else |
| 289 | { |
| 290 | mFile = mTerrainAsset->getTerrainResource(); |
| 291 | } |
| 292 | |
| 293 | /*// TODO: We have to save and reload the file to get |
| 294 | // it into the resource system. This creates lots |
| 295 | // of temporary unused files when the terrain is |
| 296 | // discarded because of undo or quit. |
| 297 | TerrainFile *file = new TerrainFile; |
| 298 | file->save( mTerrFileName ); |
| 299 | delete file; |
| 300 | mFile = ResourceManager::get().load( mTerrFileName );*/ |
| 301 | } |
| 302 | |
| 303 | // The file does a bunch of the work. |
| 304 | mFile->import( heightMap, heightScale, layerMap, materials, flipYAxis ); |
| 305 | |
| 306 | // Set the square size. |
| 307 | mSquareSize = metersPerPixel; |
| 308 | |
| 309 | if ( isProperlyAdded() ) |
| 310 | { |
| 311 | // Update the server bounds. |
| 312 | _updateBounds(); |
| 313 | |
| 314 | // Make sure the client gets updated. |
| 315 | setMaskBits( HeightMapChangeMask | SizeMask ); |
no test coverage detected