x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to read landscape height map data from C++

I would like the read the height map data of the editor initialized landscape (in C++) so that I can pass the data to our server application which internally handles physics.

But I could not find a satisfactory method of doing it. And I have many questions.

I've retrieved the the only ALandscape instance (the landscape) in my scene and iterated over its ULanscapeComponents. At each landscape component there is the HeightMapTexture variable which supposedly holds the data.

I've adapted the following code from the Import method that resides inside LandscapeEdit.cpp...

 Terrain * ConvertUnrealLandscapeToTerrain(ALandscape * landscape)
 { 
    ...
    ...
 
    TInlineComponentArray<ULandscapeComponent*> components;
    landscape->GetComponents<ULandscapeComponent>(components);
     
     for (auto i = components.CreateIterator(); i; i++) {
        UTexture2D * heightMapTexture = (*i)->HeightmapTexture;
        FColor* heightMapData = (FColor*)heightMapTexture->Source.LockMip(0);
     
        //TODO: Read the data from the array here and convert.
     
        heightMapTexture->Source.UnlockMip(0);
     }
 
    ...
    ...
 }

landscape is the instance of the ALandscape actor class which I've retrieved from the scene. The problem here is that the heightMapData array entries does not make any sense when I check them in debug mode and Visual Studio shows some weird text characters in place of the RGBA channels of the FColors.

How does Unreal store height map of a landscape internally? Is it an 16 bit greyscale image encoded in two channels (8 bits * 2). If that is so which channels.

How to decode and properly access this data in general?

Thanks in advance for answers.

Product Version: UE 4.15
Tags:
more ▼

asked May 03 '17 at 02:10 PM in C++ Programming

avatar image

Matiati
154 17 20 39

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first
more ▼

answered May 12 '17 at 04:15 PM

avatar image

Matiati
154 17 20 39

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question