| 681 | } |
| 682 | |
| 683 | void TerrainFile::import( const GBitmap &heightMap, |
| 684 | F32 heightScale, |
| 685 | const Vector<U8> &layerMap, |
| 686 | const Vector<String> &materials, |
| 687 | bool flipYAxis ) |
| 688 | { |
| 689 | AssertFatal( heightMap.getWidth() == heightMap.getHeight(), "TerrainFile::import - Height map is not square!" ); |
| 690 | AssertFatal( isPow2( heightMap.getWidth() ), "TerrainFile::import - Height map is not power of two!" ); |
| 691 | |
| 692 | const U32 newSize = heightMap.getWidth(); |
| 693 | if ( newSize != mSize ) |
| 694 | { |
| 695 | mHeightMap.setSize( newSize * newSize ); |
| 696 | mHeightMap.compact(); |
| 697 | mSize = newSize; |
| 698 | } |
| 699 | |
| 700 | // Convert the height map to heights. |
| 701 | U16 *oBits = mHeightMap.address(); |
| 702 | if ( heightMap.getFormat() == GFXFormatL16) |
| 703 | { |
| 704 | const F32 toFixedPoint = ( 1.0f / (F32)U16_MAX ) * floatToFixed( heightScale ); |
| 705 | const U16 *iBits = (const U16*)heightMap.getBits(); |
| 706 | if ( flipYAxis ) |
| 707 | { |
| 708 | for ( U32 i = 0; i < mSize * mSize; i++ ) |
| 709 | { |
| 710 | U16 height = convertBEndianToHost( *iBits ); |
| 711 | *oBits = (U16)mCeil( (F32)height * toFixedPoint ); |
| 712 | ++oBits; |
| 713 | ++iBits; |
| 714 | } |
| 715 | } |
| 716 | else |
| 717 | { |
| 718 | for(S32 y = mSize - 1; y >= 0; y--) { |
| 719 | for(U32 x = 0; x < mSize; x++) { |
| 720 | U16 height = convertBEndianToHost( *iBits ); |
| 721 | mHeightMap[x + y * mSize] = (U16)mCeil( (F32)height * toFixedPoint ); |
| 722 | ++iBits; |
| 723 | } |
| 724 | } |
| 725 | } |
| 726 | } |
| 727 | else |
| 728 | { |
| 729 | const F32 toFixedPoint = ( 1.0f / (F32)U8_MAX ) * floatToFixed( heightScale ); |
| 730 | const U8 *iBits = heightMap.getBits(); |
| 731 | if ( flipYAxis ) |
| 732 | { |
| 733 | for ( U32 i = 0; i < mSize * mSize; i++ ) |
| 734 | { |
| 735 | *oBits = (U16)mCeil( ((F32)*iBits) * toFixedPoint ); |
| 736 | ++oBits; |
| 737 | iBits += heightMap.getBytesPerPixel(); |
| 738 | } |
| 739 | } |
| 740 | else |
nothing calls this directly
no test coverage detected