- Home /
Terrain flipped, then texture doesnt line up?
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?
I had a similar issue, pretty sure I just flipped the texture vertically, if you mean the color map.
Answer by tanoshimi · Nov 20, 2013 at 09:33 AM
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:
http://alastaira.wordpress.com/2013/11/12/importing-dem-terrain-heightmaps-for-unity-using-gdal/
Great script. I used it to flip my raw height maps produced with World $$anonymous$$achine. Worked like a charm. Thanks!
Answer by TorQueMoD · Jan 28, 2016 at 10:31 AM
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.
Your answer
Follow this Question
Related Questions
Randomized terrain? 0 Answers
Smoothing Terrain after setting its Heightmap in a script 0 Answers
How to use Height Maps 2 Answers
Edit Terrain Script 0 Answers
Stitching grid of terrains together 1 Answer