-->

Thursday, 19 April 2012

Terrain Tutorial

People have asked me a lot for pieces of terrain, or my terrain "rig", which I don't really understand because there's nothing to it, it's just cubes. The reason they're smooth is because I just beveled out the edges, but I wouldn't recommend doing that if you're starting out because the UV mapping starts to get tricky and it can take up a lot of memory. Here's a quick tutorial on how I set up my terrain though. You should familiarize yourself with blender first, I'll mention some of the basic shortcuts and controls in the tutorial but don't rely on it. Keep in mind this tutorial was written with Blender 2.62.


So first add a plane and scale it up by 10 (press s, then type 10 or hold ctrl and scale it up until the number at the bottom reaches 10). Subdivide it, go into the toolbar (T) and set the number of cuts to 19. Should look like this:


The reason for that is because now each square is half the size of the default cube.



You don't have to do this, but it keeps things consistent and if you add my minecraft rig into the scene it'll be automatically set to scale. Now before you start extruding enable the snap during transform button at the bottom of the 3D view, so that everything automatically snaps to a grid and maintains alignment.


Also press ctrl+tab and enable face select mode. Now press C and select a bunch of faces, make whatever shape you want.


Press E to extrude, and drag your mouse so that everything goes up 1 square.


Keep selecting faces and extruding them to form whatever terrain you want. Right click to select individual faces and press x>delete face to delete them.


Now we have to texture it. Go into the material options and create 2 materials. Call one grass top and one grass side. Select everything (a), select grass side in the material options and hit assign. All the faces are now assigned to that material, but we want all the top faces to be assigned to the grass top material. So first make sure you have the "limit selection to visible" button enabled so that you don't select through faces.


Go to the top view (7 on numpad) and switch to isometric view (5 on numpad). Now press b, and drag the selection around everything so that it selects all the top vertices.


Now select grass top in the material options and hit assign. If you want you can re-colour grass top to green and grass side to brown and see if it worked, and also if you missed anything. So now we have to assign the  actual textures to the materials, go into the sidebar (N) and enable textured solid under display so you can see the textures in the 3D view.


Select grass side in the material options, and hit the select button. Now open up the image editor, click image and Open Image. Select your texture, you can use the terrain file with all of the textures in it from the minecraft.jar file if you want, but you have to change the uv coordinates to isolate the exact texture that you want, so I'd recommend separating them out into their own 16x16 files. Here's the basic 5 if you need them: http://dl.dropbox.com/u/53122678/Tutorials/terrain/minecraft_textures.zip
So once you've textured the grass side faces, do the same for grass top. Select grass top in the material options, hit the select button, open grass top in the image editor.


If you render it you won't see the textures though, because they're not actually assigned yet. Go into the textures panel with either grass side or grass top selected in the material options, and hit new. Change the type to Image or Movie, and under Image hit Open and select the corresponding texture. Then under Image Sampling disable MIP Map, Interpolation, and change the filter from EWA to Box. Under Mapping change the Coordinates from Generated to UV, and select the one UV map (or leave it blank, doesn't matter if you only have one).


So there you go, if you render it you'll see the textures. I'm not going to explain in detail how to make the edges smooth, but what I did basically is set the bevel weights for all the edges that I wanted to be smoothed out to 1, added two bevel modifiers and set the mode to weight, and then applied them. It messes up the uv coordinates so I unwrap the entire mesh using cube projection, and then align it the best I can in the uv editor. All the assigned textures get messed up too, so you have to redo that as well. It's not a very pleasant process but I did it anyways because I really liked the result.