How to load heighmap in C++

Hi,

I am trying to make same world generation. I want to load few heightmaps from files and load them to landscapes. Same thing you can do in GUI. Where should I load read data? I have found in ULandscapeComponent function InitHeightmapData() ← if I will load map by this it will work? There is also ReimportHeightmapFilePath in ALandscape, but what is it at all? How to “refresh” this heighmap?

I will be very grateful for any ideas :slight_smile:

My only solution now is to create ProceduralMesh from heightmap file by myself. It doesn’t have any functionality from Landscape, by visually works.

Since nobody ever helps here with this question, I’l do. I managed to make procedural landscape in multiple ways (albeit took me a month of looking throuhg plugins, experimenting, even trying to make my own landscape solution)
.

  1. load from texture using: LandscapeTest->LandscapeComponents[i]->SetHeightmap(HeightMap);

  2. load from rendertexture using:
    ||TArray SurfData;|
    |—|—|
    ||auto RenderTarget = RTHeightMap->GameThread_GetRenderTargetResource();|
    ||RenderTarget->ReadPixels(SurfData);|

  3. just writing heights to FColor:

    for (int x = 0; x < 256; x++)
    {
    for (int y = 0; y < 256; y++)
    {
    uint8 height = x;
    SurfData.Add(FColor(height, height, height, height));
    }
    }

Additionally need to call some function to trigger the redraw and recreate collisions:

for (int i = 0; i < LandscapeTest->LandscapeComponents.Num(); i++)
{
	LandscapeTest->LandscapeComponents[i]->MarkRenderStateDirty();

	LandscapeTest->LandscapeComponents[i]->InitHeightmapData(SurfData, true);

	// NOTE: crash if edit layers is on.
	// NOTE: crash cuz of no mips.
	// NOTE: srgb collision offset?
	//LandscapeTest->LandscapeComponents[i]->SetHeightmap(HeightMap);
	LandscapeTest->LandscapeComponents[i]->RequestHeightmapUpdate(true, true);

	LandscapeTest->LandscapeComponents[i]->UpdateCachedBounds(true);
	LandscapeTest->LandscapeComponents[i]->PostLoad();
}

//for (int i = 0; i < LandscapeTest->CollisionComponents.Num(); i++)
//	LandscapeTest->CollisionComponents[i]->RecreateCollision();

LandscapeTest->RecreateCollisionComponents();