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

Method import

Engine/source/terrain/terrFile.cpp:683–761  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

681}
682
683void 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

Callers

nothing calls this directly

Calls 12

isPow2Function · 0.85
floatToFixedFunction · 0.85
mCeilFunction · 0.85
getWidthMethod · 0.45
getHeightMethod · 0.45
setSizeMethod · 0.45
compactMethod · 0.45
addressMethod · 0.45
getFormatMethod · 0.45
getBitsMethod · 0.45
getBytesPerPixelMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected