Loading...
 
Blender Static Tutorial        

Blender Static Tutorial

We show how to create a simple static scene in Blender and export it into the Grit Game Engine.

We assume the following:
  • Blender is installed
  • Grit Export addon is enabled.
  • Reader is familiar with basic Blender modelling (polygon editing, object positioning, uv mapping, etc)

First Steps


You will need a directory under the Grit game directory into which to place your files. Let us assume Grit is installed in C:\Grit and you choose to put your work in C:\Grit\mywork.

The first step is to run Blender, and save the empty scene into this directory. Let's call the file c:\Grit\mywork\mywork.blend. This blend file will contain your scene.

Creating The Ground


We will now define a Grit class with one Grit mesh for graphical visualisation and one Grit collision mesh for physical representation. We will then instantiate this class to be the ground in our map.

To create a class, position the cursor somewhere under the z=0 plane, and click the 'New Class' button. Let us call the class 'Ground' and have it use a gcol with trimesh.

Image

This creates a dummy and 2 cubes. These cubes are the collision (left) and graphics (right) representations.

Image

Since the ground is going to be mostly flat, we shall move them so the collision mesh is below the graphics mesh. Also, let us select the dummy that is their parent. This represents the Grit class. We should change its rendering distance to be 400m, and make it cast shadows, using the Grit tools (left hand panel).

Image

Modelling The Grit .mesh


Now, we can start modelling. If, at this point, you already have a ground mesh, then switch the Grit mesh object to use the mesh you have already modeled, and continue to the next section. Otherwise, model the mesh as you like. Be sure to actually be editting the mesh, i.e. to be in edit mode. If you scale/rotate the object only, you will be changing its appearance in the modeller but not changing the actual mesh. Here, we deleted all but the top face of the cube, scaled it up, subdivided it, and created two levels of altitude to make it interesting. We also assigned a new material called 'Ground'.

Image

Now, we UV map the mesh by loading an image into the UV map space.

Image

Although the Blender material does not actually have a texture set, this is not actually a requirement for the exporter. All that is required is that the mesh have uvs mapped properly, and that the assigned material has the right name (more on this later).

Modelling The Grit .gcol


For a simple mesh like this, one can reuse the graphical mesh to define the physics mesh. This is achieved by changing the mesh of the collision mesh (currently a cube) to be the same as the graphical mesh.

Image

We will, however have to remap the materials, since graphical materials are not valid physical materials. At this point, it is possible to clone the mesh by making a single user copy, and then make whatever changes to it are needed. This is appropriate if you want to change the geometry. But in this case we only want to set different materials on the Grit .gcol, so duplicating the geometry would just make the asset harder to manage. In the lower object, we will therefore override the Ground material from the shared mesh to use the predefined material /common/pmat/GrassPlain. Simply setting the material will change the Grit .mesh, which we do not want. So, change Data to Object to allow the .gcol to override the .mesh materials (see Blender Fundamental Concepts)

Image

The class is now defined. Since the collision mesh is reusing a graphical mesh, it will have a UV channel. However, this is ignored when exporting to .gcol format. In the above screenshot, the Ground collision mesh is showing rendering with the grass texture used in the Ground graphical mesh. However, this is not because it is using the wrong material, it is simply because it has a UV channel and Blender is visualising that UV channel by texture-mapping the image Grass_d.dds that we chose from the UV map space. This behaviour can be controlled by disabling the 'Textured Solid' option in the Display panel on the right hand side of the 3D view.

Instantiating The Ground


Position the cursor above the z=0 plane and click 'Instantiate Class'. Select the Ground class and the ground will appear.

Image

Exporting


Click 'Export Whole Scene' in the Grit Export panel in the right hand side of the 3D view. This will generate the following files:

classes.lua
Ground.gcol
Ground.mesh
Ground.mesh.xml (temporary file that can be deleted)
map.lua
OgreXMLConverter.log (temporary file that can be deleted)

Loading Into Grit


Remember to save your blend file before exiting Blender.

Before we load this ground mesh into Grit, there is a Lua file that must be written by hand. We need to define the materials used in .blend (In this case, just 'Ground'). This we will do in an init.lua file, and it is also convenient to 'include' the generated classes.lua and map.lua files in init.lua, so that only one file needs to be processed for Grit to 'see' all the content. We write the following init.lua file in the mywork directory:

init.lua
material "Ground" { diffuseMap="/common/tex/davec/Grass_d.dds" }
include "classes.lua"
include "map.lua"


Now, the content can be loaded into the Grit Game engine with the command include "mywork/init.lua":

Image

Further Development of The Map


Additional classes can be defined for rocks, buildings, etc, and instantiated with the Ground. New materials need to be added to init.lua.