Tutorial: Creating OpenSim terrain with Blender

tutorial opensim second life linux metaverse Technology

This tutorial will explain how to create RAW terrain files for OpenSim and Second Life using Blender and the Gimp.

Before we begin

You will need the following software for this tutorial. All of this software is free and open source.

  • Blender, a professional 3d modelling tool. Blender is powerful but complex, and basic blender knowledge is assumed for this tutorial. Blender will be used to actually create the heightmap.

  • The Gimp, a powerful program for creating and editing raster (i.e. normal) image files. The Gimp will be used for splitting the heightmap into RAW terrain files that OpenSim can use.

  • gimpterrain, a plug-in for The Gimp that allows it to open and save RAW terrain files.

  • terrainerizer (optional), a bash script I created to automate splitting the heightmap into RAW files. Terrainerizer only works on Linux, and still requires The Gimp and gimpterrain to be installed. It also requires ImageMagick.

In addition to the above software, you will also need a blank RAW terrain file. You could download a terrain file from OpenSim and transform it into a blank one (replace the Height layer with #ffffff, replace the factor layer with #808080), or you could just use the one I’ve included with terrainerizer.

Create a heightmap

A good tutorial on creating a generic heightmap in Blender can be found here.

The tutorial above creates a heightmap that is 512x512 pixels. However, an OpenSim RAW terrain file is only 256x256 pixels. This means that the above tutorial will create terrain for 4 regions, arranged in a square. If you need terrain for a different number of regions, you can modify the above tutorial to create different sized heightmaps.

For example, suppose you want to create an oblong island that is 2 regions by 4 regions in size. To do that:

1. Create the plane, but instead of scaling it to 2x2 blender units, scale it to 2x4 blender units. To do this, you can use this command sequence in blender:

  • Right-click on the object to select it.

  • Change the mode to Edit mode.

  • Press ‘s’, ‘y’, ‘2’, ‘return’.

  • Press ‘s’, ‘x’, ‘4’, ‘return’.

Now you should have a plane that is oblong instead of perfectly square.

2. When you configure the render settings, you will need to use different values.

  • In the Scene settings (F10), SizeX and SizeY should be set to 256 * (number of regions). In our case, we have 2 regions in the Y dimension, and 4 regions in the X dimension. So, SizeX should be set to 1024, and SizeY should be set to 512.

  • In the camera settings, the scale needs to be adjusted to fit the plane precisely. In our example, the scale should be set to 8. To get it just right, select the camera, and press Numpad0 to switch to camera view. You should see two concentric rectangles composed of dashed lines. Now, press F9 to view the Editing options for the camera. Now, adjust the Scale value until the outer dashed rectangle encompasses your plane completely, without including anything outside the plane. If the dashed rectangle is not the same shape as your plane, then you still need to set SizeX and SizeY in the Render settings.

Creating RAW terrain files with the Gimp

Now that you have a heightmap file, you still need to turn it into terrain files that can be uploaded into OpenSim.

Enter Domino Marama, creator of gimpterrain, an import/export plug-in for the Gimp that can handle the OpenSim RAW terrain format. Download gimpterrain and install it into your gimp plug-ins directory.

Now, if you are running Linux, you can automate the rest of this section with my terrainerizer script. See below.

We also need the blank terrain file that I mentioned earlier.

Armed with these tools, we can open a terrain file in the gimp and combine it with a portion of our heightmap.

  1. Open your blank terrain file (blank.raw) and the heightmap in the Gimp.

  2. Using the Rectangle Select tool, select a 256x256 pixel section of the heightmap, starting in the upper-left corner.

  3. Click Edit -> Copy

  4. Select the terrain file and make sure the Height layer is selected.

  5. Click Edit -> Paste. You should see the section of the heightmap you copied appear as a floating layer.

  6. Click Layer -> Anchor Layer. The Height layer should now look like the copied portion of the heightmap.

  7. Click File -> Save As and save this file as a new file with the .raw extension.

Now, repeat this process for every 256x256 pixel section in your original heightmap.

Making it easier

Performing the steps in the previous section is very tedious, especially given how long it takes to save the terrain files. To make this easier, I have automated the process with the terrainerizer script.

If you are running Linux, simply put the terrainerizer script somewhere in your path. Edit it and specify the path to your blank.raw file, then run:

terrainerizer heightmap.png

Replace ‘heightmap.png’ with your heightmap file. Now let terrainerizer work. It will handle everything we did in the previous section automatically. It may take a while, depending on how large your heightmap is.

When it is finished, terrainerizer will leave several files in your current directory, named with this scheme:


Where ‘n’ and ‘m’ are numbers starting at 0 that represent the column and row for that terrain file. So, 0x0 is the top left region of your terrain, 0x1 is the next region (moving from top to bottom), and so on. Just upload these terrain files and you’re done!

Uploading the terrain files

Now that you have the terrain files, you can upload these files into OpenSim. There are two ways to do this.

1. From the OpenSim server console, you can simply:

change region RegionName
terrain load /path/to/terrain.raw

Repeat this for each of your regions.

2. From a viewer connected to OpenSim (assuming you are using Hippo or a similar viewer):

  • Move to the region you where you want to upload terrain.
  • Navigate to World -> Region/Estate -> Terrain

  • Click “Upload RAW Terrain…” and select the terrain file you created for this region.

[caption id="attachment_190” align="alignright” width="300” caption="The Upload Terrain menu in Hippo”]The Upload Terrain menu in Hippo[/caption]

Repeat these steps for each region where you want to upload terrain.

Edit: Apparently wordpress.com doesn’t allow arbitrary files any more, so I’ve moved terrainerizer to github. The links have been fixed above, or you can simply click here.