Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

3D Game Programming All In One (2004)

.pdf
Скачиваний:
140
Добавлен:
17.08.2013
Размер:
17.91 Mб
Скачать

This page intentionally left blank

Team LRN

chapter 17

Making Structures

There are quite a few different options available to the game developer when creating objects for use in a game. We've already seen how to make things like trees and weapons using MilkShape to create DTS-type objects. But what about complex

structures, like buildings and bridges?

Well, you can also use DTS objects for those, making sure to create multiple collision meshes where needed. Buildings have a lot of surfaces that either you can walk on or at the very least you can't walk through. So you will spend a great deal of effort creating collision meshes. Also, DTS objects don't inherently understand the concept of lighting and shadows, so if you make a building as a DTS object, you will also have to light it yourself using another object—which is possible, but you'll have to do that for every building. This is a real issue for structures that are interiors. Bridges and ramps are not such a big deal when it comes to lighting, but you still have the collision mesh workload.

Fortunately, there is a solution to this problem. In Torque a different kind of object is sup- ported—a DIF-type object, also called an interior. Now, using the word interior is a bit misleading, because you could, and probably will, use the same kind of object for complex structures that don't have interior lighting but do have many collidable surfaces. Therefore, I prefer to use the word structure to describe DIF objects.

There are several tools available to use for creating DIF objects. A very good open source (it doesn't cost you anything to use and it is published under the GNU General Public License) is QuArK (short for Quake Army Knife).

499

Team LRN

500 Chapter 17 Making Structures

Installing QuArK

All of the parts you will need to install QuArK on your hard drive are included on the companion CD. After installing the program, you'll need to verify the configuration, as described in the following sections.

Using the Installer

When you install QuArK, you will also be installing a stripped-down version of the Python scripting language.

Do the following:

1.Browse to your CD in the \QuArK directory.

2.Locate the Setup.exe file and double-click it to run it.

3.Click the Next button for the Welcome screen.

4.Follow the various screens, and take the default options for each one, unless you know you have a specific reason to do otherwise.

Figure 17.1 QuArK directory structure.

Note that this is not the official QuArK installer—there isn't any. This installer is only available on the companion CD for this book.

After installation you will have QuArK installed into a directory structure that should look exactly like that in Figure 17.1.

Configuration

The installation program will have already ensured that you have the correct configuration for use with this book. However, it's a good idea to double-check the configuration.

1.Launch QuArK by choosing Start, Programs, 3DGPAi1, QuArK, Launch QuArK.

2.After the QuArK window appears, choose Edit, Configuration (see Figure 17.2).

The Configuration utility will appear. On the right side is a large blank area where various parameters will appear to be edited, depending on what you choose in the left area, which contains the configuration categories.

3.Click the Torque category, located in the Games section (see Figure 17.3).

The parameter page for Torque will appear, as shown in Figure 17.4.

Team LRN

Quick Start

501

4.Verify the setting of each parameter by checking it against Table 17.1. All parameters not listed in the table should be left blank. Also note that the settings in the first program through the sixth program entries are almost identical, with the only difference being the middle of the three command-line switches in the fixed command-line arguments parameter for each program.

5.Close the Configuration utility when you are finished.

Next, let's make something!

Quick Start

What we'll do is fire up the QuArK Map Editor and quickly create a structure that we can stick in our sample Torque game and poke around with.

Figure 17.2 QuArK Edit menu.

n o t e

More taxing terminology! In QuArK development circles what you create are often called rooms. This harkens back to QuArK's beginnings as an editor for Quake, where everything was a room. There were no outdoor areas as such— no external terrain. When we create the rooms and save them, we save them as map files, because Valve used the word map to describe their version of what id Software (the guys who made Quake) called a room. Clear as mud?

And of course, just to be difficult, GarageGames calls these creations interiors (which fetches back to the term rooms in a way) in Torque. I use the word structure, which I think is both pithy and generic at the same time. My use of structure can encompass room, map, and interior as they are used in their respective contexts while still also applying to things like bridges and guard towers.

So room = map = interior = structure. In any event, the source format for the files we will be dealing with are MAP, a text file format, while the compiled version is called DIF, a binary format. We save our work as .map and compile the work to .dif for use in Torque.

1.Start the QuArK Map Editor by first selecting what game you are working with in the Games menu. For now click new Torque map, as shown in Figure 17.5.

You will then get the Map Editor, as shown in Figure 17.6. A default structure (or room, remember?) will appear, all ready for you to hack away at. This is convenient, because you will probably be creating roomlike structures most of the time anyway. This makes a useful starting place.

Figure 17.3

Configuration sections and categories.

Team LRN

502 Chapter 17 Making Structures

Figure 17.4 Torque configuration page.

Figure 17.5 The Torque button in QuArK.

t i p

To delete the default room, locate the Tree view on the left side of the Map Editor window, and select the sample_group entry, as shown in Figure 17.7.

Figure 17.7 The Tree view.

You can press the Delete key or rightclick on the entry to get the pop-up menu. Then choose Edit, Delete.

You should now have a blank slate.

Figure 17.6 The Torque Map Editor in QuArK.

Team LRN

Quick Start

503

Table 17.1 Torque Settings for QuArK

Parameter

Value

Torque converter

map2dif_DEBUG.EXE

Directory of Torque files

C:\QuArK 6.3\Torque

Run these build programs

selected (in QuArK's console)

Run tools from base directory

cleared

Output Map Format

Valve 220

1st program

 

program executable (path optional)

C:\QuArK 6.3\torque\tmpquark\map2dif_DEBUG.exe

fixed command-line arguments

-v -h -o ./maps -t ./textures %mapfile%

2nd program

 

program executable (path optional)

C:\QuArK 6.3\torque\tmpquark\map2dif_DEBUG.exe

fixed command-line arguments

-v -l -o ./maps -t ./textures %mapfile%

3rd program

 

program executable (path optional)

C:\QuArK 6.3\torque\tmpquark\map2dif_DEBUG.exe

fixed command-line arguments

-v -p -o ./maps -t ./textures %mapfile%

4th program

 

program executable (path optional)

C:\QuArK 6.3\torque\tmpquark\map2dif_DEBUG.exe

fixed command-line arguments

-v -e -o ./maps -t ./textures %mapfile%

5th program

 

program executable (path optional)

C:\QuArK 6.3\torque\tmpquark\map2dif_DEBUG.exe

fixed command-line arguments

-v -n -o ./maps -t ./textures %mapfile%

6th program

 

program executable (path optional)

C:\QuArK 6.3\torque\tmpquark\map2dif_DEBUG.exe

fixed command-line arguments

-v -g -o ./maps -t ./textures %mapfile%

2.Choose from the menu Torque, Export mapfile only. This creates newmap.map.

3.Now, from the menu, choose Torque, Build DIF only, as shown in Figure 17.8.

You will see a console window appear, and a bunch of stuff will be written into it. This is the output of the map2dif_DEBUG.exe map compiler program that comes with Torque. We are using the debug version because its output provides a lot more information that could help solve problems that we can encounter with more complex maps. The program takes newmap.map and compiles it into DIF form.

Anyway, you should see a line near the bottom of the output that reads something like this:

Writing Resource: persist..(./maps/newmap.dif) Done.

Team LRN

504 Chapter 17 Making Structures

If you see this, your map has successfully compiled.

4.Next, from the same menu, choose Torque, Prepare used textures.

This will create a list of all the textures used in your creation and copy them to the prepared textures directory. After a brief pause, you will get an information alert, like that shown in Figure 17.9.

5.Browse to your map output directory, C:\QuArK 6.3\torque\tmpquark\maps, and locate newmap.dif.

6.Copy newmap.dif to your Emaga6 sample game, into the directory C:\aEmagaCh6\ control\data\structures.

7.Browse to your prepared textures directory, C:\QuArK 6.3\torque\tmpquark\ textures, and locate concrete.jpg and NULL.jpg.

8.Copy concrete.jpg and NULL.jpg to the directory C:\aEmagaCh6\control\data\ structures.

9.Use UltraEdit to open the mission file for Emaga6, C:\aEmagaCh6\control\data\ maps\book_ch6.mis.

10.Locate the first instance of this line:

interiorFile = "~/data/structures/hovelb.dif";

and change it to the following, to reflect your new structure:

interiorFile = "~/data/structures/newmap.dif";

11. Directly above that, find this line (the numbers might be different):

position = "-4.05031 54.9271 207.919";

Figure 17.8 Selecting Build DIF only.

Figure 17.9 The texture information alert.

Team LRN

Building Bridges

505

and replace it with this exactly:

position = "8 50 198";

The preceding steps are a way to manually insert your creation into the mission map file at the location of one of the existing hovel structures. Because of differences in construction between the two structures, you needed to adjust the position of the new structure somewhat.

12.Run your Emaga6 sample game. After spawning in, you should see the new structure directly in front of you, as shown in Figure 17.10. Run on over and go inside. Take a good look around. There's your first structure created with QuArK!

Building Bridges

So, you've had a taste of how you can use QuArK. Now let's dive in and muck about with it a bit and actually create something. Because this is our first structure from scratch, we'll start out with something not too complex—a stone bridge.

1. Launch QuArK and open the

 

Torque Map Editor, as you

 

learned in the last section.

 

2. Delete the default room.

 

n o t e

 

QuArK and other similar programs that

 

are based on constructive solid geometry

 

use something called brushes to create

 

their objects. A brush in this sense is like

 

a building block. You select a particular

 

brush (also called a polyhedron in

 

QuArK) for a particular need and apply it

 

to your model.

Figure 17.10 The test structure in Emaga6.

3.Select the Cube brush by clicking its icon, as shown in Figure 17.11.

After clicking the Cube brush icon, you will see a cube appear in your model, as shown by Figure 17.12. Notice that it has a small solid square in the center, called the handle, and small "empty" squares on each edge, called face handles. You use the face handles for resizing the brush and the center handle for moving the brush. Simply click the mouse cursor

Figure 17.11 The Cube brush.

Team LRN

506 Chapter 17 Making Structures

in the handle, hold down the button, and then drag the brush around to resize or move it as needed.

Also, you should note the texture that the brush sports—a striped texture. This is the default texture for new brushes; the texture's name is Construction. You will assign your own textures later.

4.Using the handles, resize and move the brush until you have something resembling Figure 17.13. This is the roadbed of the bridge.

5.Create two more Cube brushes and place them as shown in Figure 17.14. These will be the bridge pylons.

Next, you are going to add some texture to the bridge.

6.Click inside the Roadbed brush to select it.

7.Right-click anywhere in the view to get the pop-up menu. As long as you have a brush selected, you will get a pop-up menu containing functions that will be applied to that brush, even though you haven't actually right-clicked on the selected brush.

8.Choose Texture, as shown in Figure 17.15.

The Texture Browser will appear,

Figure 17.12 A new cube.

Figure 17.13 Reshaped cube.

as shown in Figure 17.16. Locate the Book folder and select the 256_BrickA texture. You can see any of the textures in the preview pane at the right by selecting the texture in the browser frame on the left.

9.Double-click the 256_BrickA texture, and the Texture Browser window will go away. Your texture will be applied to the selected brush.

10.Add the 256_BrickA texture to all of the other brushes in the bridge model.

Team LRN

Building Bridges

507

You will end up with a textured bridge (see Figure 17.17) in your 3D view at the upper left.

11.For safety's sake, save your work, by Choosing File, Save As File. In the Save As Type combo box, select Quake map file (*.map).

12.Choose Torque, Export220map/Build High Detail DIF.

This will export the map again,

overwriting what you just

Figure 17.14 A new cube.

saved (so you can see that you

 

could have gotten away with not doing the initial Save

As operation), and then compile the map to DIF format and gather all of the used textures into the used textures directory. Contrast this all-in-one operation with the discrete steps we executed earlier when we did the quick start with the default room. This is certainly more convenient!

13.Copy the textures and the bridge.map file to C:\aEmagaCh6\control\data\structures.

There is already a bridge with that name in that directory that is being used in the mission file. Go ahead and replace that file, as well as the textures, if necessary.

14.Launch Emaga6 and when you spawn in, turn to your right and run to the edge of the wadi. You should see your bridge spanning the wadi ahead of you, as depicted in Figure 17.18.

Figure 17.15 The Texture item in the Object pop-up menu.

Team LRN