I am wondering if there is a way to get the landscape spline section to read spline components for adjusting the terrain height. If not then I’m assuming that I can generate a terrain spine via C++ to follow the same path of the root spline component?
Edit:
Tried this, only updates LOD of the terrain…
/**/
void ACityPathBuilder::UpdateCollision(ULandscapeHeightfieldCollisionComponent* InComponent, uint16 *InSource)
{
uint16 *Dest = (uint16*)InComponent->CollisionHeightData.Lock(LOCK_READ_WRITE);
for (int i = 0; i < InComponent->CollisionHeightData.GetElementCount(); i++, InSource++, Dest++)
*Dest = *InSource;
InComponent->CollisionHeightData.Unlock();
}
void ACityPathBuilder::UpdateTexture(UTexture2D *InTexture, uint16 *InSource,int32 size)
{
for (int m = 0; m < InTexture->PlatformData->Mips.Num(); m++)
{
FTexture2DMipMap& Mip = InTexture->PlatformData->Mips[m];
int32 sz = Mip.BulkData.GetBulkDataSize();
UE_LOG(LogTemp, Log, TEXT("terrainSize: %d"), sz);
void* Data = Mip.BulkData.Lock(LOCK_READ_WRITE);
FMemory::Memcpy(Data, InSource, sz);
Mip.BulkData.Unlock();
}
InTexture->UpdateResource();
}
void GenerateHeights(int32 row, int32 col, int Value, uint16 *Heights)
{
for (int32 i = 0; i < row*col; i++)
{
Heights[i] = Value;
}
}
void ACityPathBuilder::CreateTerrain()
{
// Generate 8x8 array with height 65000
uint16 Heights[512*512];
uint16 * pHeight = Heights;
UE_LOG(LogTemp, Log, TEXT("CreateTerrain1"));
GenerateHeights(512 , 512, 1000, Heights);
UE_LOG(LogTemp, Log, TEXT("CreateTerrain2"));
if (pHeight == nullptr)return;
UE_LOG(LogTemp, Log, TEXT("CreateTerrain3"));
for (TActorIterator<ALandscape> ActorItr(GetWorld()); ActorItr; ++ActorItr)
{
TArray<ULandscapeHeightfieldCollisionComponent*> Components = ActorItr->CollisionComponents;
for (int c = 0; c < ActorItr->LandscapeComponents.Num(); c++)
{
ULandscapeComponent * temp = (ULandscapeComponent*)ActorItr->LandscapeComponents[c];
UTexture2D * currTexture = nullptr;
if (temp != nullptr){
currTexture= temp->HeightmapTexture;
}
if (currTexture != nullptr){
UpdateTexture(currTexture, pHeight, 512* 512);
}
}
}
}