Object2Terrain

Authors: Eric Haines (Eric5h5): original. Jessy: C# conversion. Bit Barrel Media: added functionality.

Description
Converts an object mesh to a heightmap. This way you can create terrain meshes in a standard 3D app such as Blender or Maya and convert it to a Unity terrain. It uses raycasting instead of file conversion, so it works with any object which has a mesh.

See also TerrainObjExporter, which saves a Unity terrain as an .obj file.

Usage
You must place the script in a folder named Editor in your project's Assets folder for it to work properly. The source object must contain a mesh. Selecting a parent object will not work.

If in doubt, simply open the mesh asset in the project view, then drag the bare mesh into the scene or hierarchy:

Note: The script uses the axis-aligned bounding box of the mesh, so object rotations on the x and z axis other than 0, or rotations on the y axis other than multiples of 90 degrees, may give somewhat odd results.

C# (updated): -Click on an object in the scene view or hierarchy. -Select from the top menu: Terrain->Object to Terrain. -A new terrain GameObject is automatically created.

Java (original): -Add a default terrain GameObject to the scene. -Click on an object in the scene view or hierarchy. -Select from the top menu: Terrain->Object to Terrain. -The object is then converted to the heightmap in the active terrain.

Settings (C# only)
-Resolution: the resolution of the generated terrain. -Add terrain: add blank terrain to the front/back, left/right and above. Handy if you want to create additional content. Increase this if the edge of the terrain is cut off. -Shift height: move the terrain up or down. The terrain GameObject will stay in the same position. Range limited to the vertical terrain size. -Bottom up: terrain is generated from the bottom up. This will ensure a 1 to 1 resemblance of the source object. -Top down: terrain is generated from top to bottom. This will stretch the terrain if a larger y value of "Add terrain" is used. This is the original mode but gives somewhat odd results. -Create terrain: start generating the terrain. Depending on the resolution, this might take a while.