Jump to content

Move LandscapeLayerMap along z-Axis via API


photo

Recommended Posts

Hi Everyone,

I'm trying to move a LandscapeLayerMap up or down along the z-Axis. This can't be done via LandscapeLayerMap::setWorldPosition() because of how the terrain system works as far as I understand. Changing the z-component of the LandscapeLayerMap in the editor has no effect.

I achieved the desired effect in the editor using the import settings for the height map.

hmap_import_settings0.png.30714cc27387233f0cb8e4b2412b901a.png  hmap_import_settings1.png.2f8c142d9ee777eba0f1681cefaa1b66.png

Left: default import settings, base of terrain is located at z = 0;       Right: "moving" LandscapeLayerMap to z = -5

Is this the correct way to do it?

How can this be achieved via API? I tried to use LandscapeMapFileCreator and LandscapeMapFileSettings as described in Working with Landscape Terrain via Code, however I could not find corresponding functions to manipulate the Min/Max values.
I even tried remapping the values of the heightmap myself while loading it according to the Tutorial Working with Landscape Terrain via Code but setting negative values to the height map breaks it.

Any help is appreciated.

Kind regards

Edited by ipg_jallmenroeder
Link to comment

Hi @morbid,

thanks for your reply.
Here are my import settings:

import_settings_terrain_highlighted.png.c312ad8cc68748472ec9d1b3aebe8aec.png

As I understand it, LandscapeLayerMap::setHeightScale corresponds to the height scale, marked in green. What I want to change via API are the Min and Max values for height import, marked in red. I did not find API functions to set those values so I tried to remap the heightmap myself.

If I read the Documentation correctly, the Height Min and Max values are used to remap the values from the heightmap. So with my import settings above, the normalized heightmap with values in [0,1] is remapped to [-2,-1].
To achieve this behaviour without setting the Height Min and Max values (as I dont know how) I tried to remap the 32F values of the height texture myself, but changing the heightmap values to something negative apparently breaks the heightmap.

I am looking for a way to either set those Height Min/Max values marked in red via API before importing or to perform the remapping of the heightmap according to those values myself.

Did my problem become clearer now? Thanks for looking into this! If somethings unclear, I'm happy to answer questions.

Kind regards

Edited by ipg_jallmenroeder
Link to comment

Thank you, 

Unfortunately, Min/Max height is not exposed in the API, it's a part of an import process performed by the editor. This operation still can be handled manually, we can share a code snippet with you:

float *pixels = reinterpret_cast<float *>(image->getPixels());
size_t num_pixels = size_t(image->getWidth()) * size_t(image->getHeight());
float range = import_params.height_max - import_params.height_min;
for (size_t i = 0; i < num_pixels; ++i)
pixels[i] = import_params.height_min + (pixels[i] * range);

Let me know if this helps.

  • Like 1

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment

Hi @morbid,

thanks for the support! The shared code did the trick!

I tried the same a slightly different way before, turns out it was just a texture format missmatch. I loaded a DDS texture (because I had nothing better at hand) and decompressed it to RGBA8, which then was wrongly interpreted as a float. This is what ultimately broke the heightmap.

It would be neat to have a corresponding API call for the height Min/Max import settings in the future.

Kind regards

Link to comment
×
×
  • Create New...