MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / import

Method import

Engine/source/terrain/terrImport.cpp:258–319  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

256}
257
258bool 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 );

Callers 1

terrImport.cppFile · 0.45

Calls 10

isPow2Function · 0.85
getVariableFunction · 0.85
MakeUniquePathFunction · 0.85
getFileNameMethod · 0.80
getTerrainResourceMethod · 0.80
getNameFunction · 0.50
PathClass · 0.50
getWidthMethod · 0.45
getHeightMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected