Planetside Software Forums

General => Terragen Discussion => Topic started by: dknesek on January 13, 2019, 12:05:32 AM

Title: I need to create terrain and export heights and normals to use in a simulation.
Post by: dknesek on January 13, 2019, 12:05:32 AM
I'm trying to decide if Terragen is the tool that I can use.

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.

Can anyone help with this?
Title: Re: I need to create terrain and export heights and normals to use in a simulation.
Post by: Oshyan on January 13, 2019, 06:18:38 PM
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.

- Oshyan
Title: Re: I need to create terrain and export heights and normals to use in a simulation.
Post by: dknesek on January 14, 2019, 12:55:49 PM
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.

Any further advice you may have would be welcome.  :)
Title: Re: I need to create terrain and export heights and normals to use in a simulation.
Post by: jaf on January 14, 2019, 02:10:45 PM
Not sure... maybe this would help: http://www.openexr.com/documentation/openexrfilelayout.pdf
Title: Re: I need to create terrain and export heights and normals to use in a simulation.
Post by: bobbystahr on January 14, 2019, 02:19:34 PM
I guess an important question at this point would be what format is your target format?
Title: Re: I need to create terrain and export heights and normals to use in a simulation.
Post by: dknesek on January 14, 2019, 02:49:18 PM
Not sure... maybe this would help: http://www.openexr.com/documentation/openexrfilelayout.pdf

Thanks. This will help. :)
Title: Re: I need to create terrain and export heights and normals to use in a simulation.
Post by: dknesek on January 14, 2019, 02:50:50 PM
I guess an important question at this point would be what format is your target format?

I don't really have a target format. I just want convert the terrain into a 2D array of numbers (heights) that I can use in a MASON simulation.
Title: Re: I need to create terrain and export heights and normals to use in a simulation.
Post by: bobbystahr on January 14, 2019, 03:02:06 PM
I guess an important question at this point would be what format is your target format?

I don't really have a target format. I just want convert the terrain into a 2D array of numbers (heights) that I can use in a MASON simulation.

Cool, I see....
Title: Re: I need to create terrain and export heights and normals to use in a simulation.
Post by: Oshyan on January 14, 2019, 06:08:25 PM
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.

- Oshyan