TextureEntity* CGlobalTerrain::GetTexture(float x, float y, int nIndex) { Terrain * pTerrain = GetTerrainAtPoint(x, y); if (pTerrain) { if (nIndex >= 0) { if (pTerrain->GetTextureSet()) { Texture * pTex = pTerrain->GetTextureSet()->GetTexture(nIndex); if (pTex) { return pTex->GetTextureEntity(); } } } else if (nIndex == -1) { // -1: common texture, which is repeated several times over each terrain tile surface. TextureEntity* pTex = CGlobals::GetAssetManager()->LoadTexture("", pTerrain->GetTerrainCommonTextureFile(), TextureEntity::StaticTexture); return pTex; } else if (nIndex == -2) { // -2: main texture, which is chopped and mapped to the entire terrain surface. TextureEntity* pTex = CGlobals::GetAssetManager()->LoadTexture("", pTerrain->GetTerrainBaseTextureFile(), TextureEntity::StaticTexture); return pTex; } } return NULL; }
int CGlobalTerrain::GetTextureCount(float x, float y) { Terrain * pTerrain = GetTerrainAtPoint(x, y); if (pTerrain) { if (pTerrain->GetTextureSet()) { return pTerrain->GetTextureSet()->GetNumTextures(); } } return 0; }
bool CGlobalTerrain::ReplaceTexture(float x, float y, int nIndex, TextureEntity* TextureAsset) { Terrain * pTerrain = GetTerrainAtPoint(x, y); if (pTerrain && (nIndex >= 0 || TextureAsset != 0)) { if (nIndex >= 0) { if (pTerrain->GetTextureSet()) { if (TextureAsset) { if (pTerrain->GetTextureSet()->ReplaceTexture(nIndex, TextureAsset)) { pTerrain->SetModified(true, MODIFIED_TEXTURE); return true; } } else { // True to normalize mask of the undeleted layers. bool bNormalizeMask = true; pTerrain->GetTextureSet()->RemoveTexture(nIndex, pTerrain, bNormalizeMask); } } } else if (nIndex == -1) { // -1: common texture, which is repeated several times over each terrain tile surface. pTerrain->SetTerrainCommonTextureFile(TextureAsset->GetKey()); return true; } else if (nIndex == -2) { // -2: main texture, which is chopped and mapped to the entire terrain surface. pTerrain->SetTerrainBaseTextureFile(TextureAsset->GetKey()); return true; } } return false; }