| 91 | } |
| 92 | |
| 93 | bool TerrainBlock::exportLayerMaps( const UTF8 *filePrefix, const String &format ) const |
| 94 | { |
| 95 | for(S32 i = 0; i < mFile->mMaterials.size(); i++) |
| 96 | { |
| 97 | Vector<const U8>::iterator iBits = mFile->mLayerMap.begin(); |
| 98 | |
| 99 | GBitmap output( mFile->mSize, |
| 100 | mFile->mSize, |
| 101 | false, |
| 102 | GFXFormatA8 ); |
| 103 | |
| 104 | // Copy the layer data. |
| 105 | U8 *oBits = (U8*)output.getWritableBits(); |
| 106 | dMemset( oBits, 0, mFile->mSize * mFile->mSize ); |
| 107 | |
| 108 | for ( S32 y = 0; y < mFile->mSize; y++ ) |
| 109 | { |
| 110 | for ( S32 x = 0; x < mFile->mSize; x++ ) |
| 111 | { |
| 112 | if(*iBits == i) |
| 113 | *oBits = 0xFF; |
| 114 | ++iBits; |
| 115 | ++oBits; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | // Whats the full file name for this layer. |
| 120 | UTF8 filePath[1024]; |
| 121 | dSprintf( filePath, 1024, "%s_%d_%s.%s", filePrefix, i, mFile->mMaterials[i]->getInternalName(), format.c_str() ); |
| 122 | |
| 123 | FileStream stream; |
| 124 | if ( !stream.open( filePath, Torque::FS::File::Write ) ) |
| 125 | { |
| 126 | Con::errorf( "TerrainBlock::exportLayerMaps() - Error opening file for writing: %s !", filePath ); |
| 127 | return false; |
| 128 | } |
| 129 | |
| 130 | if ( !output.writeBitmap( format, stream ) ) |
| 131 | { |
| 132 | Con::errorf( "TerrainBlock::exportLayerMaps() - Error writing %s: %s !", format.c_str(), filePath ); |
| 133 | return false; |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | return true; |
| 138 | } |
| 139 | |
| 140 | DefineEngineMethod( TerrainBlock, exportHeightMap, bool, (const char * fileNameStr, const char * format), ( "png"), "(string filename, [string format]) - export the terrain block's heightmap to a bitmap file (default: png)" ) |
| 141 | { |
no test coverage detected