Author
Topic: I need to create terrain and export heights and normals to use in a simulation. (Read 235 times)

I am building an agent-based simulation where agents (animals) are moving around a complex and mountainous terrain. The way I would like to capture the terrain in the simulation as a 2D array of height values. I might add the surface normal vectors if I get ambitious.

Does Terragen enable export of the height and normal vectors (is this called terrain "geometry"?) into a non-binary format that I can parse easily with my simulation software. I would also like to export a nice looking 2D rectangular top-down view of the terrain to load into the simulation.

There are two ways you can export a terrain, either as a Heightfield (EXR or TER format), or as Geometry (OBJ or FBX format). Since you want an "array of 2d values" you basically want a heightfield, and while EXR might not be directly supported by your simulation software, you should be able to convert to something that will be.

The export process for heightfields varies slightly depending on how you build your terrain. If you are using heightfields already in Terragen (e.g. Heightfield Generate), you can simply right-click the node and Save As to get a heightfield version of it. If you are using Procedural shaders (e.g. Power Fractal, Alpine Fractal, etc.), you will need to convert into a heightfield format to export. So you'd create a new Heightfield Generate and plug the last node in your terrain network into the Shader input of the Heightfield Generate, then set the size, resolution, and position parameters to cover the area you want to export, click Generate when that's done, and then again right-click and Save As. During save you specify the output format (EXR), file name, and location.

For normals, if you get the Professional version you'll have access to a Normals render element, I'm not 100% sure that's what you want, but it's available. There is also a "visualize normals" shader node which may be appropriate.

For the simple 2D rectangular top-down view, just move your camera up above the terrain and point it down, or use an Orthographic camera with appropriate settings.

You can test most of this in the Free version, with the exception of the Render Elements. You can apply for a 30 day evaluation license of Professional if you need to test that.

There are two ways you can export a terrain, either as a Heightfield (EXR or TER format), or as Geometry (OBJ or FBX format). Since you want an "array of 2d values" you basically want a heightfield, and while EXR might not be directly supported by your simulation software, you should be able to convert to something that will be.

Thank you for the response, Oshyan. Can you point me in the direction of an EXR file spec? I can't seem to find one. I may be able to find a Java library that will allow me to extract this information from one of the file formats you suggest.

More specifically for Terragen, it will output an EXR file with the values in meters. So the value of each pixel will be a height in meters. It should be fairly simple to interpret and use in your simulation, either if an EXR plugin is available, or you can do custom coding to load it. If you have to convert the data you will need to find a way to maintain correct scaling values since meter values won't likely convert correctly to, say, a normal grayscale image representation.