im exporting a terrain from world machine as a 16bit raw. along with a texture.
when import the heightmap into unity, its mirrored. from what ive read i cant find out why. so thats my first question;
why is it flipped? its not when i use it in mudbox or blender. why unity?
second is, if i go into photoshop and flip the heightmap around so its correct with my texture, the texture in unity then no longer lines up properly with the terrain.
how can i manually adjust the texture in one direction, so it lines up with the heightmap again?
2 Answers
2
The “raw” format in which Unity imports heightmap data is just a stream of binary values - it’s not really a recognised file format. As such, there are no particular conventions about whether the first value (0,0) is at the top-left corner or the bottom-right corner, or whether the values are listed in row-wise or column-wise order, for example.
Depending on the conventions of the application used to output the raw heightmap file, you may therefore find that you need to flip, mirror, or rotate the heightmap to get it to appear the same in Unity. I don’t know World Machine but, when recently importing DEM data via GDAL, I found that I had to rotate the image 90’ clockwise, which I did in a script as follows:
using UnityEngine;
using System.Collections;
public class RotateTerrain : MonoBehaviour {
void Start () {
Terrain terrain = GetComponent<Terrain>();
// Get a reference to the terrain
TerrainData terrainData = terrain.terrainData;
// Populate an array with current height data
float[,] orgHeightData = terrainData.GetHeights(0,0,terrainData.heightmapWidth, terrainData.heightmapHeight);
// Initialise a new array of same size to hold rotated data
float[,] mirroredHeightData = new float[terrainData.heightmapWidth, terrainData.heightmapHeight];
for (int y = 0; y < terrainData.heightmapHeight; y++)
{
for (int x = 0; x < terrainData.heightmapWidth; x++)
{
// Rotate each element clockwise
mirroredHeightData[y,x] = orgHeightData[terrainData.heightmapHeight - y - 1, x];
}
}
// Finally assign the new heightmap to the terrainData:
terrainData.SetHeights(0, 0, mirroredHeightData);
}
}
I wrote up more details on the whole process in a blog article here:
All you have to do is add a “Flipper” device in world machine immediately before the heightmap output and then double click on it and check off flip vertically. When you rebuild and re-import it will fix the problem.
I had a similar issue, pretty sure I just flipped the texture vertically, if you mean the color map.
– supernat