Part V
Mastering the Blender Game Engine
- Chapter 14: Creating Assets for the Blender Game Engine
- Chapter 15: Making Things Happen in the Game Engine
- Chapter 16: Python Power in the Blender Game Engine
Chapter 14
Creating Assets for the Blender Game Engine
One of Blender’s most distinctive features as a 3D tool is its built-in game engine for the creation of interactive content. In addition to games, the Blender Game Engine (BGE) can be used to create architectural walk-throughs, interactive data visualizations, educational tools, and a wide variety of other types of content. This chapter gives a complete overview of the BGE’s core functionality.
In this chapter, you will learn to
- Model, rig, and texture a 3D character for use in the Blender Game Engine
- Create a simple game environment of a maze and skybox by using texture baking
- Place objects in the game environment, and set options for materials and lighting in the game engine
Creating Content for the Game Engine
The Blender Game Engine has long been a distinctive feature of Blender among 3D content-creation applications. The BGE enables quick and simple creation of highly interactive 3D environments coupled with a state-of-the-art built-in physics engine in the Bullet physics library. With the recent release of Yo, Frankie! (the result of the Blender Foundation’s Apricot project to create an open game prototype), the BGE has garnered more attention than ever before.
The biggest strength of the BGE is its ease of use and the relative speed with which creators can create their work. The BGE lacks some of the functionality of high-powered professional game-creation tools (although the Apricot project did much to narrow the gap), but it excels in creating fast, high-quality prototypes, visualizations, and walk-throughs. Unless you are creating a high-budget commercial video game, the BGE likely will enable you to do whatever you want. In fact, Google Summer of Code 2012 includes a Blender branch codenamed Swiss Cheese, which will enable support for Open GL Mobile, allowing the development of Android games in the BGE.
In the next few chapters, you will learn the basics of using the game engine and some things that aren’t so basic. One thing that this chapter doesn’t discuss in depth is how to fully exploit the Bullet physics engine to make the most of the extraordinary real-time rigid body simulation possibilities in the BGE. Physics simulation is covered in detail in Part II of this book.
Even if you’ve never touched the game engine in your life, this chapter will get you up to speed and teach you how to create the assets you will be working with. In Chapter 15, “Making Things Happen in the Game Engine,” you will set up the interactive logic that will enable the user to participate in the game experience.
Modeling a Simple Low-Poly Character
Before you can do anything interesting with the game engine itself, you need something for the game engine logic to act on. In this section, you’ll create a character from scratch that will eventually become the protagonist in a simple game example.
There are several ways in which this character, as simple as it is, will represent the goals of modeling for the game engine. For one thing, the character will be created with a minimum of polygons and vertices. The character’s face and distinguishing characteristics will be accomplished with UV textures rather than highly detailed mesh models. This is a fundamental requirement for 3D assets that are intended for use in real time. No matter how much power and speed you have available, there are always better ways to use resources than to add unnecessary detail to the mesh geometry. On the other hand, the Subsurf modifier is not available in the game engine, which means that the mesh’s smoothness in the game environment depends on the real geometry of the mesh. A balance must be struck in which your model has enough polygons to look nice from the necessary angles but does not have an excess of vertices to weigh it down in real time. To build the simple character mesh, follow these steps:
1. Begin with the default cube. Press the 1 key on the number pad to get into Front view. Enter Edit mode by pressing the Tab key, and make sure that the entire mesh is selected (if it’s not already) by pressing the A key. Press the W key to bring up the Specials menu and select Subdivide Smooth, as shown in . The result will be a 24-sided polygon.
2. When the view is opaque, only the visible vertices are selected by the B key Box select tool. For the next step, you want to all the front and back vertices to be selected, so make sure your view is in Wireframe or Transparent Draw mode. You can toggle between Solid and Wireframe by using the Z key. In Wireframe view, press the B key and box-select the lower-right faces. Press the E key and move the extruded face downward slightly, and then scale down with the S key to result in something like what is shown in .
3. After confirming this scaling with the left mouse button, scale again by pressing the S key. This time, however, constrain the scaling to the z-axis by pressing the Z key, and then type in the numerical value 0 to scale the selection to 0 on the z-axis, flattening it as shown in .
4. Finally, complete the basic leg shape by extruding once more and scaling and translating the extruded face as shown in .
5. From here, you will model using the Mirror modifier. Select the vertices on the left half of the model and delete them with the X key, as shown in . Again, be sure you get both front and back vertices.
6. Apply a Mirror modifier by selecting it from the Add Modifier drop-down menu in the Modifiers tab, shown in .
7. Activate Clipping and set the Merge Limit value to 0.01, as shown in .
8. Select the upper-right vertical faces, where the shoulders will be, and extrude them several times, as shown in .
9. With each extrusion, rotate, scale, and translate the extruded face to form the shape of arms. After the second time extruding, scale to zero along the x-axis to flatten the face. You can select edge loops along the arms to do further tweaking by holding down the Alt key (or the Option key on a Mac) while right-clicking one of the edges of the loop, as shown in .
10. Press 3 on the number pad to change the angle to Side view. Select all vertices with the A key and scale slightly along the y-axis to slim the character as shown in .
11. Go back into Front view by pressing 1 on the number pad, and finish extruding the arms as shown in .
12. Extrude the top faces of the character to create the head, and scale down slightly and rotate to create some simple, vaguely catlike ear shapes, as shown in .
13. In the Side view, select the knee loops and translate them forward slightly along the y-axis, as shown in . Then select the elbow loops and translate them backward slightly to create the bends at the joints, as shown in .
14. The mirror modeling part is over, so make the Mirror modifier real by clicking Apply on the Mirror Modifier panel. Like Subsurf and most other modifiers, the Mirror modifier will have problems in the game engine.
15. The shape of the character is essentially finished. However, you have two more issues to address. One is that the geometry of the mesh character is really too simple to deform well, so a little extra geometry would help when working with armatures. The other issue is that the character is very blocky looking. Since you can’t use the Subsurf modifier, select all the faces, press the W key, and select Subdivide Smooth. This adds geometry while smoothing and rounding the shape, as shown in . Good news: The model is still quite low poly, so this will not weigh down the game play.
Texture Painting
For this character, a simple UV-mapped skin texture will be sufficient. In recent versions of Blender, a new Texture Paint mode has been developed that enables you to do 2D texturing directly in Blender and bypasses the need for exporting UV maps for use in other software. For this character, Texture Paint will be more than adequate for doing the texturing. To set up and use the Texture Paint feature on the character, follow these steps:
1. To unwrap the surface coordinates of the character, you need to create seams. For a simple character like this one, it is enough to create a single seam to separate the front from the back. Do this by holding down the Alt key and right-clicking one of the edges in the loop to select the edge loop, as shown in , and then press Ctrl+E and select Mark Seam to create a seam along that loop, as shown in . If this is difficult to see in grayscale, refer to the duplicate image printed in the full-color insert of this book.
2. Add a UV texture to the mesh in the Mesh Properties area, as shown in .
3. When you’ve done this, split your work area and open a UV/Image Editor, as shown in . Press the U key to unwrap the mesh so that the image can be properly mapped to the full mesh. When you’ve finished unwrapping the mesh, the mapping will be as shown in .
4. In the 3D viewport, select all vertices of the character by pressing the A key, and then select New Image from the Image menu in the UV/Image Editor header, as shown in .
5. Set the Width and Height values for the image to 1024 and select the UV Test Grid option in the dialog box that appears, as shown in .
6. Choose Textured Solid in the Display settings of the 3D viewport Properties shelf to see the texture on the surface of the model, as shown in .
7. In the 3D viewport header, select Texture Paint from the Mode drop-down menu. When you do this, the Paint tab becomes available in the Edit buttons area. You can control the color, size, opacity, falloff, spacing, blend method (mix, lighten, darken, add, multiply, burn, and so on), and other parameters of your brush on this panel and use your mouse to paint directly onto the model. A good texture painting setup involves a 3D viewport, the Tool shelf with paint tools, and a UV/Image Editor to see the actual painted image, as shown in . (You can paint directly onto this image also by selecting the paintbrush icon button in the UV/Image Editor header.)
8. If you want to retain a set of brush parameters for use later, simply add a new brush by clicking the plus icon beside the Brush drop-down menu. The previous brush will remain as it was defined. In this way, you can create your character’s surface texture something along the lines of .
Rigging and Animating the Character
Now that the character is modeled and textured, it is time to rig the character with an armature and to create a simple animated walk action for it. To rig the character, follow these steps:
1. In Object mode, select the character mesh. Press Shift+S and select Cursor To Selection to ensure that the cursor is snapped to the center of the character (this should also be the center of the 3D space). Press the spacebar and choose Add > Armature. Choose the Armature Properties area and make sure that X-Ray is selected, as shown in .
2. Choose X-Axis Mirror from under Armature Options in the 3D viewport Tool Shelf, as shown in .
3. Extrude the shoulder bones by pressing Shift+E, as shown in . Shift+E is necessary only the first time you extrude mirrored pairs of bones. After that, you can use the E key alone to extrude from a mirrored bone, and the extrusion will automatically be mirrored, as in .
4. Select the head (the thicker end of the octagon) of the original bone by right-clicking the tip, and then extrude the legs, once again using Shift+E for the original mirrored extrusion (see ) and the E key for the legs themselves (see ).
5. Tab into Object mode. Select the character mesh first, and then hold the Shift key down and right-click to select the armature as well. Press Ctrl+P to create a parent relationship between the mesh and the armature, and select Armature Deform With Automatic Weights, as shown in . For many simple rigs such as this one, it is the only step you need to completely skin your rig! No weight painting, no tweaking vertex weights.
6. You can now go ahead and experiment with posing your character, as shown in . To return your character to rest pose, simply select the posed bones (the A key selects all bones) and press Alt+R to remove rotation.
Now that the character is rigged, you can create a simple walk cycle action for use in the game engine. The focus of this exercise is just to create a basic walk action that will be integrated into the game logic in Chapter 10, “Advanced 3D/Video Compositing.”
Creating a Walk Cycle
As you probably know, a two-key walk cycle such as the one described here is not nearly an adequate demonstration of Blender’s character-animation capabilities. For a much more in-depth look at rigging for character animation and creating armature animations such as walk and run cycles, refer to my book Introducing Character Animation with Blender, 2nd Edition (Sybex, 2011). As the Yo, Frankie! game prototype demonstrated, the game engine is capable of handling quite complex levels of character animation, including inverse kinematic (IK) constraints. For the present purposes, however, a simple walk cycle is sufficient. To create it, follow these steps:
1. Make sure that you are on frame 1 on the timeline and in Pose mode with the armature selected. Select the left leg and rotate it forward by pressing the R key followed by the X key to constrain its rotation around the global x-axis, as shown in .
2. Go into Side view by pressing the 3 key on the number pad, select the other leg, and rotate it backward, as shown in .
3. Rotate the left arm backward in the same way, using the X key to constrain the rotation to the axis, as shown in , and rotate the right arm forward in Side view, as shown in .
4. Shift-select both arms and both legs, and press the I key to key location and rotation, as shown in .
5. Split your workspace and open an Action Editor window, as shown in . Press the I key to keyframe the new bone positions, as shown in . Last, select the four keys on frame 1 by using the B key to box-select. Copy those keys with Shift+D and move them 20 frames to the right, holding down the Ctrl key as you move them to constrain them to whole frames.
6. The four keys you just made should be visible on frame 1. Advance 10 frames forward by pressing the up-arrow key on your keyboard. At this frame (frame 11), you will want to key the mirror of the previous pose. To do this, use the clipboard buttons in the 3D viewport header. The clipboard buttons are shown in . The leftmost button copies the current pose to the clipboard. The middle button applies the clipboarded pose to the armature, and the rightmost button applies the mirror of the clipboarded pose to the armature. First, with the four keyed bones selected, press the leftmost button to copy this pose to the clipboard. Then press the rightmost button to apply the mirror of the pose to the armature. The character should switch poses immediately, with the keyed bones selected. While in Pose mode, copying poses can also be done with the shortcuts Ctrl+C to copy, Ctrl+V to paste, and Ctrl+Shift+V to paste the flipped pose.
Advancing the Game Engine by Flying Leaps with Yo, Frankie!
The most significant recent developments in the Blender Game Engine were the result of the Apricot project, the third major open content production project of the Blender Foundation after two short films, and the first to focus on game creation. The Apricot project was a six-month effort produced by a team of game creators and developers from around the world using Blender and the BGE in conjunction with the Crystal Space open-source game-creation platform. This resulted in the game prototype Yo, Frankie!, which is available on DVD at the Blender e-shop. The core team for the Apricot project consisted of Campbell Barton (Blender developer and Game Logic developer), Christopher Plush (art director and BGE lead game designer), Dariusz Dawidowski (Crystal Space lead game designer), Frank Richter (Crystal Space developer), Pablo Martin (B2CS developer), and Pablo Vazquez (lead artist), supported by Brecht van Lommel, Margreet Riphagen, and Ton Roosendaal of the Blender Institute.
The team got a jump on the process of game design by committing early on to reusing assets that had been created previously for the Blender Foundation’s open short film Big Buck Bunny. Frankie, the sadistic flying squirrel from Big Buck Bunny, was selected as the protagonist of the game, and the Frankie rig was adapted for game engine use, as shown here.
Basing the game world and characters on work that had been previously accomplished for the film enabled the team to focus on game play and developing the Blender game-creation tool chain. One of the goals of the Apricot project was to explore the potential of integrating Blender and Crystal Space together into a state-of-the-art game-creation pipeline. Finalizing such a pipeline proved to be beyond the scope of the project, but in the process an enormous amount of development went into the Blender game engine itself, making an even more powerful tool for visualization and prototyping. Improvements in view navigation, handling of UV textures, and asset management are among the big developments out of Apricot. Details about specific features developed for the project can be found under the Development link on the official Yo, Frankie! website at .
7. The action is now finished. If you set the start and end frames in the timeline to 1 and 20, respectively, and click the Play button (or press Alt+A while the cursor is hovered over the 3D viewport), the action will repeat continuously. In the name field in the Action Editor header, give this action the name Walk, as shown in .
Setting Up the World
Now that you’ve created a character for your game, it’s time to create the game environment. This will consist of a background sky and a maze through which the character will move.
Baking Procedural Textures for a Simple Skybox
To create a sky for games it is necessary to use a skybox, which is an actual Mesh object on which the sky texture is mapped directly. You can use any sky texture you wish for your skybox; it could be a hand-painted sky, a photograph, or an image created in a sky and terrain–simulation program. This depends on the look and atmosphere you want in your game.
The following example shows you what might be the simplest way to get a passable sky background by using procedural textures in conjunction with Blender’s powerful texture-baking functionality. To set up your skybox, follow these steps:
1. Open a fresh Blender session. Just as you did when you created the character in the previous section, enter Edit mode, select all vertices of the default cube, press the W key, and select Subdivide Smooth to create a 24-sided polygon.
2. Select the nine vertices that make up the edges shown in , forming a cross shape across the bottom of the mesh. If the edges are hard to see, check this book’s full-color insert for a color print of this image.
3. Press Ctrl+E to bring up the Edge Specials menu, and select Mark Seam from that menu.
4. The next step is to create the combination of textures that will later be baked to an image. To do this, add a material to the cube. Make sure the material is shadeless by selecting the Shadeless option on the Material tab in the Material properties area. The material needs three textures. First, create the texture shown in for the color of the sky. The texture is a linear blend texture with a color band representing the colors in the sky from horizon (on the left) to zenith (on the right).
Full-color prints of these images can be found in the color insert of the book. The mapping type is Object, and the blend progression is set to vertical so that the blend pattern goes up and down rather than left to right. The Influence value is set to Color, because this texture will represent the color of the sky. This texture is the top texture channel in the stack on the Texture panel. The third texture down is the Cloud texture. The Cloud texture itself is shown in .
Finally, in the middle channel is a Stencil texture. This texture does not influence the color of the sky directly but simply stencils out the clouds so that they fade toward the horizon. The texture is shown in .
If you render the skybox, you should see something like the image in .
The procedural textures for the sky are now in place. The next step is to bake these textures to a UV-mapped image:
1. To do this, split your workspace and open the UV/Image Editor. Make sure the Skybox object is in Edit mode and all faces are selected with the A key, and then open a new image in the UV/Image Editor by choosing New Image from the Image menu in the header, as shown in .
2. Set Width and Height to 1024, and select UV Test Grid in the New Image settings. Just as in the previous example with the character, the UV/Image Editor will be covered by a blue square representing the stacked quad polygons of the mesh.
3. Once again, add a UV texture in the Mesh panel of the Edit buttons context, and then press the E key to unwrap the mesh. Because you have already made seams, the mesh should unwrap, as shown in .
You’ll also notice that when the Textured draw type is selected from the drop-down menu of the 3D viewport, the UV test grid texture can be seen on the Skybox object, as shown in .
There are now two factors affecting the appearance of the skybox. The first is the original material you created with the sky Color and Clouds texture. The second is the UV texture from the image you just created. The draw type determines which of these is shown in the 3D viewport. If you render the image at this point, only the actual material will be visible. If you enter the game engine, the visibility will depend on the game settings you choose (as discussed in the next section of this chapter), but in any case the procedural textures on the object will not be visible.
1. Next, you need to bake the material appearance to the UV-mapped texture itself. To do this, select the Bake tab in the Render properties area, shown in . Select Textures, and click Bake.
The process of baking textures is essentially the same as rendering, except that rather than being used to create an image from the camera’s perspective, the render result is projected onto the UV-mapped image texture, as shown in .
2. Pack the image into the .blend file by choosing Pack Image or Pack Image As PNG from the Image menu in the UV/Image Editor, or by saving the image specifically to an image file by choosing Image > Save As and then packing all data from the Blender File menu. If you do not do this, the baked texture will not persist the next time you close and open Blender.
3. By default, polygons are visible only from the side of their normals in the game engine. In the case of a skybox, the mesh needs to be visible from the inside rather than the outside, which is the reverse of the default direction of the normals. To view the normals, set face normals to draw in the Properties shelf with the Skybox object selected in Edit mode, as shown in .
4. To flip the normals, click Flip Direction under Normals on the Tool shelf, as shown in , or by using the Specials menu by pressing W and selecting Flip Normals. The result of flipping the normals can be seen in .
5. Finally, change the Object name from Cube to Skybox by entering the new name into the OB field in the Links And Materials tab in the Edit buttons area.
The skybox is now complete, and the sky is now mapped onto the mesh as a textured face. The actual material is no longer necessary. If you wanted to, you could even completely delete the material from the mesh, and the skybox would still appear correctly in the game engine. The final section of this chapter describes the relationship among materials, textured faces, and the game engine in more detail.
Creating a Simple Maze
For the mock game example in Chapter 15, your character will make its way through a maze. Creating the maze is simple. Follow these instructions to model the maze:
1. In a fresh Blender session, delete the default cube and add a Plane object. In Edit mode, select all with the A key and scale upward by a factor of 50. Press W and select Subdivide, as shown in .
2. Enter 10 as the Number Of Cuts in the Tool shelf, as shown in . This results in a divided plane.
3. Enter Face Select mode by clicking the Select Mode button that is farthest to the right, shown in . The plane in Face Select mode will appear as shown in .
4. Hold down the Shift key and right-click to select faces one by one in the maze pattern shown in .
5. Rotate the space so you are not looking straight down at the plane, and extrude the maze pattern downward by pressing E and then Z to constrain the extrusion to the z-axis, as shown in . Viewed in Orthogonal Side view, the extrusion should look something like .
6. Again holding down Shift and right-clicking, select all upward-facing faces, both at the upper and lower levels of the extruded maze, as shown in . All faces except the walls of the maze should be selected.
7. Press P and choose Separate > Selection, as shown in . This will create a new, separate object from the selected portion of the mesh, as shown in . shows the walls portion on its own. You can view objects isolated by selecting the object and pressing the forward slash (/) key on the number pad ().
8. To keep things organized, give the two objects descriptive object names, such as Floor and Walls, and create a new group to place them in. In the Object And Links tab with Floor selected, choose Add New from the Add To Group menu. Name the new group Maze, as shown in . Then select the Walls object and add it to the Maze group, as shown in .
The maze is now completely modeled. In the next section, you’ll learn more details about how materials, textures, and lights work in the game engine. Combined with what you’ve learned in this chapter already, this will give you all the information you need to texture the walls and floor of the maze as you like, which will be left as an exercise to do on your own.
Getting More Familiar with the BGE Environment
The BGE environment is fairly straightforward to use. As is the case with ordinary rendered animations, layers in the 3D viewport are used to determine what is rendered (in fact, layers have a bit of extra meaning in the game engine context, which you’ll learn more about in the following chapter). Pressing P in Object mode activates the game engine and begins game play. Pressing Esc ends the game play and returns to Blender proper. Many new Blender users unfamiliar with the game engine have given themselves a shock by pressing P and watching Blender appear to freeze before their eyes. Simple as it is, there are a few things you need to be aware of in order to set up a game-based environment based on assets created in other files, and a few points about how things work in the game engine environment are worth being aware of before you go further.
Placing Your Objects in the Game World
The first thing you will want to do is to add the objects you have created for your game into a new Blender file representing the game itself. This is done by using the Append function. In this example, you’ll begin by appending the skybox and the maze to a new file. Adding the character and armature will be left as an exercise to do on your own.
To add the skybox and maze to your game environment, follow these steps:
1. Start a new session of Blender and delete the default cube with the X key. From the File menu, select Append, as shown in . A file browser window opens. Navigate to the location of the sky.blend file you created previously. The Blender file browser treats .blend files as filesystems themselves, so you can navigate into that file as though it were a directory. Drill down into the Object directory and select the object called Skybox, as shown in . Click Load Library, and the skybox appears in your 3D space.
2. Repeat step 1 to navigate into the file containing your maze objects. This time, however, don’t enter the Object directory in the .blend file, but rather enter the Group directory. Recall that you placed the Walls object and the Floor object together into a group called Maze. Select that group, as shown in , and click Load Library to load the entire group of objects into the 3D space.
3. When the maze and skybox are together in the 3D window, it will become immediately apparent that something is wrong. The skybox is no bigger than a basketball in relation to the maze! Clearly the sky needs to be much bigger. Scale the sky up by about a factor of 50, and press Ctrl+A to apply the scale.
Scaling and the Game Engine
Scaling in the game engine can be a source of trouble if not done carefully, particularly when rigid body physics and collision detection come into the picture. In general, everything in the game engine should be at scale 1. To ensure this, either scale your Mesh objects by selecting all vertices in Edit mode and scaling the mesh, or scale them in Object mode and apply the scale with Ctrl+A immediately after scaling. It is especially important that physics properties (the Actor button) should be applied only to meshes of scale 1. If you change the scale after activating physics on a mesh, the collision boundaries will be wrong.
Armatures should be scaled in Object mode and then have their scale applied with Ctrl+A. In some cases, this can cause animated actions to alter from how they were intended. I have found that in these cases, entering Edit mode, selecting all bones, and recalculating bone roll angles with Ctrl+N generally will fix animation problems caused by scaling the armature.
Setting Material Options
There are several ways to influence how things look in the BGE. The simplest way to texture things for the BGE is shown in the examples in this chapter. As you may have noticed, no mention has been made of materials. If you’re used to working with Blender for rendering or animation, you probably have noticed that the UV textures in these examples were applied directly to the mesh, without any intermediary material. This is referred to Textured-Face or TexFace in Blender, and this used to be the only way the game engine would handle surfaces. The situation has gotten a bit more complex since the early days of the TexFace-only game engine, but people familiar with the basics of Blender materials will find the current possibilities more intuitive, because you can now use actual Blender materials and powerful shaders that enable near-photorealistic scenes and surfaces to be rendered in real time.
TexFace materials remain useful. If you truly want only the texture as is, and the surface should not interact with lamps or shadows (for example, in the case of a skybox), TexFace texturing remains ideal. You can use it as discussed in this chapter, of course, without any material assigned to the object at all, and you can also use an actual material with the Face Textures option selected, as shown in . Face textures will be displayed in the game engine if the Shading mode is set to Singletexture or Multitexture on the Properties shelf, as shown in .
If you want your objects to be subject to lighting conditions in the game engine, you should have them use Blender materials. The character example earlier in this chapter is a good example. TexFace mode is excellent for doing texture painting because it enables you to see the surface texture directly in the 3D viewport and act on it in real time. For that reason, the tutorial used TexFace mode. However, in the actual game engine, it might be better to use a material, with the texture UV-mapped to the color channel of the material, just as you would for an ordinary still render or rendered animation. Set the Shading mode to GLSL for the highest-quality in-game rendering.
Using Lighting in the Game Engine
As mentioned previously, lights in the game engine do not affect TexFace objects. Blender materials, however, can be illuminated in the game engine in real time by lamps. All five Blender lamp types—omnidirectional lamps, spotlights, area lights, sun lamps, and hemi lamps—work in the game engine and can be animated or controlled in the same way as other objects.
Illuminating many objects in real time can slow things down. Furthermore, the quality of the illumination depends on the density of the mesh being illuminated, as shown in . The only difference between these setups is the number of times the mesh is subdivided. High numbers of vertices, of course, become a liability for speed of game play.
Vertex Painting for Light Effects
You can “paint” lighting-like effects directly onto meshes by using vertex painting, available in the Mode menu of the 3D viewport header, as shown in . Vertex painting works directly on the mesh: Each individual vertex can be assigned a vertex color, but the colors applied using vertex painting are visible even if there is a UV texture or a material applied. Because vertex-painted colors interact with the color of the material or the textured faces, vertex paint can be a good way to simulate the effect of lighting in a game environment. If the lighting does not change on an object, using vertex painting to fake its illumination can be a good way to speed things up. If the lights move or the object moves with respect to lights, real-time lighting will yield more-convincing results.
The Bottom Line
Model, rig, and texture a 3D character for use in the Blender Game Engine. A simple, low-poly rigged character is ideal for experimenting with the game engine. Modeling, rigging, and animating in the Action Editor can all be done quickly and easily in Blender.
Master It The example described in the tutorial uses TexFace texturing and therefore cannot be illuminated in real time with lights in the game engine. Fix this by creating a Blender material with the same UV-mapped texture so the character can be illuminated with lights in the game engine.
Create a simple game environment of a maze and a skybox by using texture mapping. Simple modeling, combined with some clever texturing tricks, is enough to create an interesting in-game environment. Baking textures to images is a great way to adapt Blender procedural effects to use in the game engine.
Master It Texture the walls and floor of your maze in an interesting way.
Place objects in the game environment, and set options for materials and lighting in the game engine. Appending objects and groups to a
.blend file is a crucial skill for managing 3D assets on any kind of nontrivial Blender project. Understanding how materials and lighting interact in the game engine will enable you to get exactly the look and atmosphere you’re after for your game or interactive environment.
Master It In this chapter, you appended the skybox and maze to the game and then resized them both to make them suitable to each other. Next, append the character to the scene as well. Use grouping to append the armature and mesh simultaneously. Resize the character appropriately, and remember to apply the new scale. Test your animated action with the new scale. If there are problems, recalculate the bone roll angles in Edit mode.