CHAPTER 16
MAKING ITEMS, SCENERY, AND WEAPONS

In this chapter we’re going to make a bunch of things. Most of the techniques used will basically be a review for you, so you can see this chapter as one big exercise in applying what you’ve learned to different situations.

We’re going to make a few weapons, and in order to maintain balance, we’ll make something that can be used in-game to counteract the effects of these weapons.

We’ll also make some items that one might call decorations for the game. The purpose of these items—some trees and a rock—is to provide some clutter. This is to help fill out otherwise sterile-looking game worlds, making them more interesting to wander around in.

THE HEALTH KIT

We’ll start out with an easy one, the Health Kit. Like I said, this will be a basic review, but it’s important to go over the process involved in creating an item for use in the game so that the broad steps become obvious and second nature.

The Model

The Health Kit is little more than a fancy-looking box, as you can see from Figure 16.1. So this won’t take long.

1. Create a new game folder: artshapesitemsmyHealthkit.

2. Fire up MilkShape, and create an empty document.

Figure 16.1
The Health Kit in-game.

Image

3. Use the Box tool to create a box, as shown in Figure 16.2. On the Group tab, find the box group and select it using the Select button and then in the Name box, change the name to Box0 from whatever it was immediately after you created it. This sets the object’s LOD such that the object is visible at all distances.

4. Align the box to be centered at the origin for all three axes, as you can see in Figure 16.2.

5. On the Materials tab, create a new material, using 3D3ERESOURCESCH16firstaid.png as the bitmap texture. Or you can go ahead and create your own using Gimp.

6. Name the material “healthkitMtl”.

7. Select the box group, and assign the healthkitMtl material to it.

8. Make sure that the 3D view has been set to Texture mode. (Right-click the 3D view and select Textured.) You should see a nice, shiny new first-aid kit kind of item there, like that in Figure 16.3. This one always has bandages in it!

Figure 16.2
The box.

Image

Figure 16.3
The Health Kit model.

Image

9. On the Model tab, click the Scale button and then enter 3.0 for each of the X, Y, and Z coordinate boxes in the Scale Options. Then click the Scale Into button. This sizes the box to 3 units on each side.

10. Save your work.

11. Use the DTSPlus Exporter to export your model.

12. Make sure that Copy Textures is checked and that Output dump file and Export Animations are not checked, and that the Scale is set to 0.1.

13. Click on Export DTS to export the model to artshapesitemsmyHealthkit healthkit.dts.

Testing the Health Kit

To use the Health Kit in-game, you merely have to run over it to pick it up. Then you activate it by pressing the “H” key to restore your health whenever it gets too low. You may remember using a kind of first-aid kit in one of your sample games from an earlier chapter—Emaga5—where you got health back just by running over the first-aid kit, or Health Kit. This one you have to pick up and activate; we’ll test that functionality later when we get back into server scripts. Right now we just want to see our fine creation in the game world.

Once you have spawned into the FPS Example demo, you are going to use the World Editor to insert the Health Kit into the game world. We’ll be using this procedure often, so pay attention! I’ll repeat the procedure once or twice in later chapters to make sure you don’t have to flail around too much.

Because of the demo’s restriction on how many objects you can insert in a scene, we will need to remove some objects first. Go ahead and launch the Deathball Desert level in the FPS Example demo, and then follow this procedure:

1. Press F8. This will set your player into World Camera, Standard mode so that you can fly around.

2. Press F11. This will open up the World Editor, as shown in Figure 16.4.

3. Press F1. This will open up the World Editor’s Object Editor. The Object Editor shows two tabs in the Scene tree—Scene and Library. Make sure that the Scene tab is selected. It usually is already selected by default.

4. After the game loads, you need to remove some objects from the Scene tree using the World Editor, just as you’ve done before if you haven’t already done it for yourself. (Press F11.) Remove the entire StaticMesh and Particles folders.

Figure 16.4
World Editor.

Image

5. Now select the Library tab. It will show three tabs: Scripted, Meshes, and Prefabs Level—as shown in Figure 16.5.

6. Click on the Meshes tab, and then drill down through art, shapes, items, and finally myHealthkit.

7. Inside the myHealthkit folder you will find the Health Kit you made. You should now have a view similar to Figure 16.6.

8. Make sure that the center of the view of the game world is located in an open terrain area about 10 virtual feet in front of you. To move the game world view while in the World Editor, hold down the right mouse button, and move the mouse.

Figure 16.5
Object Editor’s Library tabs.

Image

Figure 16.6
The Meshes view.

Image

Figure 16.7
Health Kit model.

Image

9. Double-click healthkit in the Tree view. The Health Kit model will appear suspended in space directly in front of you.

10. You can leave it there to admire it, or drag it down to the ground using the blue Z-axis gizmo after using the X- or Y-axis gizmos to drag the box away from you first. To do this, move the cursor over one of the axis gizmos (labelled X, Y, or Z) that sprout from the top of the Health Kit model. An axis gizmo label will become highlighted, as shown in Figure 16.8, with the arrow cursor pointing along whatever axis it is.

11. Click the vertical Z-axis gizmo to drag it down to the ground, as depicted in Figure 16.9. You might need to maneuver the camera around a few times so that you can see where the box is going.

12. Now press F11 to toggle out of the World Editor.

Figure 16.8
The Z-axis label.

Image

Figure 16.9
Repositioned Health Kit.

Image

A ROCK

Oh, big deal, a rock—what’s up with that, you ask? Well, it is going to be your own hand-made rock! That should be worth something.

The point here is that, even though the rock is not much more complex than the Health Kit, it is somewhat more complex nonetheless, as you can see in Figure 16.10. It does less for us in the game, but it is one of those decoration-type items I mentioned—and stuff like this, while unglamorous, can greatly contribute to the ambience of your game.

1. Fire up MilkShape, and create an empty document.

2. Use the Sphere tool to create a sphere, as shown in Figure 16.11.

3. In the Side view, select the bottom three rows of vertices.

4. Choose Vertex, Flatten, Y. The bottom three rows should be squished together in a horizontal flat plane, as shown in Figure 16.12. Already it’s starting to look like a rock.

5. Still in the Side view, drag the vertices around on the left side until you get something resembling Figure 16.13.

6. Now in the Top view, drag some more vertices around until you get something resembling Figure 16.14. It’s almost a rock now!

7. On the Materials tab, create a new material, using 3D3ERESOURCESCH16 rock.png as the bitmap texture, or create your own.

8. Name the material “rockMtl”.

9. Select the entire rock model, and assign the rock material to it.

Figure 16.10
The rock in-game.

Image

Figure 16.11
The sphere.

Image

Figure 16.12
The truncated sphere.

Image

Figure 16.13
The stretched rock-sphere.

Image

Figure 16.14
The almost rock.

Image

10. Make sure that the 3D view has been set to Texture mode. You should see a nice lumpy and ancient-looking rock there, like that in Figure 16.15.

Figure 16.15
The rock model.

Image

11. On the Group tab, select the rock and rename it to RockO. Save your work.

12. After saving your work, export your rock using the DTSPlus Exporter. Use the same settings and procedure that you used for the Health Kit.

Testing the Rock

The rock has a bounding box set for collision because it is, after all, a rock—you can’t go through it.

1. Run the FPS Example demo.

2. After the game loads, insert your rock in the same way you did with the Health Kit. The rock should be in the Items folder along with the Health Kit.

3. Run over to the rock. Abuse it.

4. If you get blood from the rock, pat yourself on the back, and apply for a job at a collections agency. You’re a natural.

TREES

If Joyce Kilmer had been a game developer, he might have written, “I think that I shall never see a model so annoying as a tree.” Or something like that. But he didn’t, so that’s too bad. Really talented game developer–poets are rare.

Nonetheless, computer model trees really are annoying. There is this conundrum. If you can interact reasonably well with a model tree, then it looks awful. If the tree looks really good, then interacting with it is awful.

The problem is twofold. We see them everywhere, in most parts of the world, so they provide a great deal of the background to our daily lives. This means that in virtual worlds, if there are no trees in the background, we just know something’s wrong even if we can’t quite put our finger on the problem. They are ubiquitous. And that means we also have a highly developed subconscious sense of what they should look like, when we aren’t…ummm…actually looking at them. With me so far? Okay, that’s problem number one.

The other problem is that they are so dad-blamed complex! Even a sapling has lots of little branches and twigs and leaves and buds and stuff. If you have a polygon budget (and if you are making games, you have a polygon budget!), then these suckers will dry up that account faster than a barking moonbat can change its mind.

So, on the one hand, to have convincing trees that satiate the subconscious gamer’s mind, we need to be attentive to details. And on the other hand, those very details can drag our frame rates lower than a snake’s belly in a wheel rut.

To interact well with a tree means several things. When you approach it, circle it, look up into its branches and leaves, you see things properly in three-dimensional perspective. You can collide with the thicker parts like the trunk and the big lower branches, but if you fell onto a tree from above, you would likely fall a long way down through the airy upper structures before you stopped.

But unless you want to put hundreds of 50,000 polygon trees into your game world, you’ll have to compromise on all those fiddly details. There are ways to strip off a few thousand polygons here and there, but long before you get anywhere reasonable, your compromises start making the tree much less treelike. So then you have to pass a few edicts like this:

From this point hence, this tree, and all other trees like this tree that grace our fair land, may only be viewed from certain angles—all of the aforementioned angles being from a level on the ground to a level not exceeding the height that one man can jump.

But then you start to drain the flexibility out of your game world. What if you are standing on the back of a truck? Or on a nearby hill? Or flying overhead in an ornithopter? Well, you can’t do any of those things if you really want to save the trees! And don’t even talk to me about having forests of these things in a game, though there are ways to make trees look absolutely stunning from a distance and only take one or two polygons to accomplish the task! Using a technique called billboarding we can create trees that look great from any angle as long as we are at least moderately far from the tree—say, a couple dozen meters or more. But up close they are nothing but flat planes that turn to always face you. You can’t look up into them from below and search for robins’ nests. You can’t climb them. And you certainly can’t fall into them from above! I mean, what fun is that?

So why all the blather, you ask? Well, I’ll tell you. We’re going to look at modeling some game-friendly trees in this section, and I want you to enter into this prepared, understanding why I’m going to show you two different ways to model a tree. There are other ways, but these two ways represent the opposite extremes. First, we’ll create a “normal” low-polygon solid tree with a collision mesh. One that you could potentially climb using appropriate program code. One that you could actually get beneath and peer up into. It won’t look all that great, but it will look like a tree. After that, we’ll create a billboard tree, which can be used to make vast forests of trees that will actually look like forests.

Steroids for Trees


Torque 3D has a nifty tool called the Forest Editor, which can be used to “paint” trees into a scene. One of the big deals about the Forest Editor is that the individual trees in the forest, while they are 3D objects, are not transmitted from the server to client. Since the trees are not tracked over the net connections, a great deal of processing time is saved and a large number of network packets are eliminated.

There are also other tools and object types that help with this sort of thing, like Ground Cover, for example.

In any event, the two tree types covered here are exactly the kind of things you need to be able to make to take advantage of the Forest Editor, or Ground Cover, or any of several other similar performance-enhancing tools and objects in Torque 3D.


The Solid Tree

The solid tree is constructed of 3D object primitives, mostly cylinders that join end to end and taper. The one we’ll make won’t have any leaves—it’s a generic big backyard tree in the winter.

I should warn you now that we aren’t going to build a megapolygon old oak tree or anything like that here. Instead, we’re going to do just enough so you’ll have a good idea where you can go with the model and what’s involved with this approach.

Having said all that, go ahead and create a new empty document in MilkShape, and let’s get crackin’.

1. Select the Cylinder tool, and set it to 4 stacks and 12 slices in the parameter boxes.

2. Click your cursor in the Side view, and drag down and to the right to create a cylinder like the one shown in Figure 16.16.

Figure 16.16
Four-stack cylinder.

Image

3. Still in the Side view, select the vertices in the second row from the bottom, and then use the Move tool to shift them to one side.

4. Switch to the Top view, and do the same thing, moving the vertices slightly away from being aligned with the center of the cylinder.

5. Repeat steps 3 and 4 with the next two rows of vertices going up, one row at a time, using Figure 16.17 as a guide.

6. Do an incremental scaling, working from the second row of vertices going up, so that you get a tapered trunk, like that shown in Figure 16.18.

7. Use the Duplicate function to make a copy of the trunk.

Figure 16.17
Crooked cylinder.

Image

Figure 16.18
Crooked cylinder becomes a tree trunk.

Image

Tip


If you’ve forgotten how to duplicate an object, I’ll go over it quickly here.

First, make sure that the object to be copied has been selected in face mode. Then choose Edit, Duplicate Selection. Make sure you only do that once, and don’t click your mouse in the window.

It will look like nothing happened, but a copy was made in place. Select the Move tool, and then drag the selected object to a clear area. There you go—you will have the copy, and the original object will have been left behind.


8. Move the copy to one side. Then scale it and rotate it so that you get something that looks like Figure 16.19.

9. Drag the branch over to the trunk, and place it with the larger end inside the bounds of the trunk.

10. Make more copies of the branch, scaling, rotating, and tweaking them as desired, until you get something like the model shown in Figure 16.20.

11. On the Materials tab, create a new material, using 3D3ERESOURCESCH16ark.png as the bitmap texture, or create your own.

Figure 16.19
Branching out.

Image

Figure 16.20
Adding more branches.

Image

12. Name the material “bark.”

13. Select the trunk using the Groups tab, and assign the bark material to it.

14. Assign the bark material to each of the branches. Do not select them all at once and assign the material; instead, assign them one at a time.

15. Make sure that the 3D view has been set to Texture mode. You should see the textured tree there, like in Figure 16.21.

Okay, we’ll stop there. Of course, we could go on and on, making it more detailed, and that’s certainly something I encourage you to do later. It’s just pointlessly repetitive to do it right now. Let’s move along and add a collision mesh.

16. Create a box, and position it as shown in Figure 16.22.

17. Rename the box, calling it “Collision.”

18. Save your work.

19. After saving your work, choose File, Export, Torque Game Engine DTS.

Figure 16.21
The textured tree.

Image

Figure 16.22
The tree collision mesh.

Image

20. You want to take all the defaults (Collision Mesh should be set to Bounding Box).

21. Export the box to artshapes reessolidtree.dts.

Testing the Solid Tree

The solid tree has a collision mesh—you can’t go through it. You also can’t climb it as is (you could if you wrote the appropriate script code). Anyway, to test out our solid tree, do the following:

1. Run the FPS Example demo

2. Using the world camera, whip on over to a little clear area somewhere.

3. Open the Mission Editor with F11, then go visit the library, as I showed you earlier.

4. Drill down through art, shapes, and trees, where you will locate the solid tree object, and place it in the game world.

5. Exit the Mission Editor with F11, press F7 to spawn your character where the camera is, and then run over to the tree and admire your handiwork.

6. Try to run through the tree. If you hurt your head, you know where the first-aid kit is!

Now, you might be thinking that perhaps the collision box doesn’t let you get realistically close to the tree from some angles. It could happen and you might be right. There is another trick Torque 3D will let us use. Instead of using the built-in collision box that we made, we can tell Torque 3D to ignore that, and use the visible mesh of the tree as a collision mesh.

You do this by going back into the World Editor, selecting your tree, and changing Collision Type to Visible Mesh. I’ll be mean and not give you the procedure for doing this. But I will tell you that you just have to select the 3D tree in the Scene tree view of the editor, and then in the Inspector pane, locate the Collision properties section, and make the change right there.

SCENERY SPREADING

There used to be two tools in Torque, the fxShapeReplicator and the fxFoliageReplicator, that provided ways to insert large numbers of 3D shapes or billboard objects into a scene, with the placement specific to a bounded location. In other words, you would define an area where the objects are to appear. These tools have been deprecated (i.e., they are no longer supported) for Torque 3D. If you have any replicator objects that were created in older version of Torque, they will still work. However, they are no longer supported in the editors, so you can’t add new ones. If you do want to add new replicators, you will have to do it in code, by editing the mission files.

From a scene optimization perspective, replicators are good stuff. But from a level designer’s perspective, it can be an onerous task, especially when dealing with situations like trees lining a boulevard, and the tiny parkettes that sprinkle a city. You spend a lot of time trying get the boundary sizes just right, and then you have to mix in multiple replicators with different scenery objects to get the natural blend of flora. It’s a slow and deliberate process.

A better way would be to be able to arbitrarily place your scenery elements wherever you want to, when you want to, while still enjoying the benefits of client-side rendering with minimal or near-zero network updates that you get from the replicators. And while we’re dreaming, toss in some customizable randomization of shapes so everything doesn’t look boringly the same. Oh yeah, and it would be nice to start off with detailed 3D shapes for the up-close scenery, which gets replaced by billboard objects when the scenery is so far away that the 3D shapes aren’t necessary for visual accuracy.

Well, guess what? We have such a beast, so stop dreaming and read on.

The Forest Editor

The Forest Editor is the Heavy Hitter of the tree and foliage placement world. With it you can specify a mixed bag of different trees, with randomized and weighted size variations, densities, and other useful parameters. You can also remove individual trees if you don’t like the placement. You can also move individual tree objects around for optimal placement.

And you get to paint the forest (or woods, copse, or spinney) onto the map in a manner very much like painting terrain! You define a set of distinct brushes, each with its own set of parameters, like shape file, height/width ratios, random weighting, and so on.

AND you don’t have to restrict yourself to trees. You could define a couple of Forest brushes to actually place rocks, pebbles, and boulders. Or bushes. Or street trash and garbage. Or cars in a parking lot.

Let’s put some trees in a scene.

Making a Forest

We’ll kick things off by launching the FPS Example Demo, and then choosing the Blank Room mission, and spawning there. Once you have spawned in, change to the World Camera by pressing F8. Look down, and then “fly backward” into the sky using the “S” key. When you have a little bit of altitude, stop flying and open the World Editor with F11. Then select the Forest Editor by pressing F8, or by clicking on the 8th button from the left in the Editor toolbar—it’s the one that looks like a green leaf.

1. With the Forest Editor now active, click anywhere in the scene, and you will be presented with a small query dialog telling you that there is no Forest in this mission, and do you want to add one. Click Yes.

2. Over on the right side in the Forest Editor settings pane, in the Brushes tab, select ExampleForestBrush.

3. Move your cursor over top of the ground plane in the world view, click the mouse button, and start painting, moving slowly. You might notice a brief pause at the beginning as the Editor software revs up. Figure 16.23 shows the result of a slow pass across the ground plane.

Figure 16.23
Painting some tree scenery.

Image

4. After painting on a few trees, change to the Forest Editor Move Item mode by clicking in the Tool options pane over on the left side of the window, as shown in Figure 16.24.

Figure 16.24
The Move Item button.

Image

5. When you’ve chosen the Move Item tool, take your cursor back into the scene and hover it over several of the trees, one at a time. Notice the white lines that appear, marking the corners of each tree’s bounding box.

6. Click on one of the trees while its boundary corners are visible, and you will see the move, or translate, axis bug appear. Go ahead and grab the axis arrows as you see fit, and drag the tree around a bit, to confirm for yourself that you can indeed move the tree around. You can do this for all objects painted into the scene using the Forest Editor.

7. Note that you can do the same with rotation and scaling.

8. You can tidy up a forest by moving around and otherwise adjusting individual trees. However, sometimes a tree just needs choppin’ down. So select the Erase tool (second from bottom in the Tool options pane) and then move your Tree brush on the ground plane such that your brush outline encompasses the base of a tree destined for the woodpile. A single mouse click removes the tree.

9. Take the next few moments to try using various different Tree brushes, and pay particular attention to the Rocks, and how they are set up.

10. Also try deleting trees. Once you have painted on trees using more than one brush, you will find that when deleting trees, only trees that are part of the currently selected brush are deleted. This is a very handy feature.

Caution


If you delete a Forest brush from the forest, by clicking the trash can icon while a brush is selected, you will delete the brush from the list and therefore be unable to use it again. However, the trees you’ve placed in the scene using that brush will not be removed from the scene. You need to remove those trees using the Erase item tool before deleting the brush.

It gets worse. If you delete a brush and leave behind orphaned trees that were inserted into the scene with that now-defunct brush, you will not be able to delete those trees from the scene!

But despair not brave woodsman! All you need to do to work around this little annoyance is create another brush with the same trees in it that you need to delete, and proceed to delete the once-orphaned trees. Just make sure you read the section “Creating a Custom Forest Brush.”


You’ve probably noticed that the Rocks brush is actually made up of more than one rock element. When you have more than one element, you can specify different properties for each element, the most important of which is the probability setting. A probability of 0.2 means that there is a twenty percent chance that this tree will be applied in a given area. The remaining eighty percent is distributed amongst the remaining tree elements, based upon their probability settings.

Creating a Custom Forest Brush.

Let’s create a sort-of Generic Forest brush that will put down a good representative mix of scenery objects in an area, whenever we need a bit of wild and wooly outdoorsiness.

1. In the Forest Editor, with the Brushes tab selected, locate the Add New Brush Group button. It’s got the “paintbrush/breezy tree” look about it, with a little plus (+) sign in its top-left corner. Or maybe it looks like a leaf. You decide. Click it to create an empty brush group in the Brushes list.

Table 16.1 Generic Brush Element Settings

Image

2. The new brush is added to the list with the default name of “Brush.” Double-click on the name, and you will be permitted to edit the name. Change it to something meaningful, like “Generic Forest.” Press the Enter key to commit the new name.

3. Next, click on the Meshes tab, and then double-click once on each of: ExampleForestMesh, desertree, smallrock_02, longleaf_plant, and agaveplant.

4. Switch back to the Brushes tab. You will see one example of each of the Meshes you clicked on added to the list, each as its own brush.

5. Select each of those brushes and drag them, individually or collectively, up and drop them in the Generic Forest brush you created earlier, such that they become elements of the Generic Forest brush.

6. For each of the elements, select it, then move down to the Properties pane below the Brushes tab, and change the properties to match those shown in Table 16.1.

7. Change the Pressure setting, located in the Brush Settings toolbar, to 100%.

8. Change the Size to 25.

9. Click your brush somewhere in the scene. Move and do it again. And again. Do it until you have a decent-sized forest. Then fly over it, press F11 to exit the World Editor, and then F7 to spawn your player there, and go run around the woods. If you think there is too much of one or the other elements, go back to the Brushes tab, and tweak the probability of the affected element.

By the way, it’s okay if the total probabilities add up to more than 100%. The point is that the probabilities are compared to each other to determine the likelihood that an object will be put at the location. They are not compared to 100% as such.

So, you can see how blindingly easy the Forest Editor makes the task of spreading scenery around the game world. The fact that we used trees, bushes, and rocks underlines the concept that we can use any 3D shape as an element in a brush.

MATERIAL-SPECIFIC SCENERY

There is another way to place objects en masse that is not based upon location boundaries, but upon certain characteristics of the placement destination, specifically the terrain material, or layer, that is applied at any given spot.

The Ground Cover Object

Using the terrain material to specify where a certain type or collection of types of objects are placed is an extremely powerful tool. Think about it—make a forest floor material with lots of pine needles in it, paint it onto the terrain, and have a pine forest rendered only where that forest floor appears—anywhere on the map!

To try out this baby, we need an actual terrain to work with. You can use a terrain that you created in Chapter 12, or you can do what I’m going to do next—“autogen” a terrain.

Auto-Generating a Terrain

In order to have terrain materials to use with our ground cover, let’s create a smallish flat terrain with a sand material as the base texture when starting out.

1. In the World Editor, make sure you are using the World Camera, and have positioned yourself some 20 or 30 meters above the ground plane, looking down at about a 45-degree angle.

2. In the File menu, choose Create Blank Terrain.

3. In the Create New Terrain dialog that appears, type in a name, like myTerrain, and keep the rest of the default settings, which should be desert_sand_03 material, a resolution of 256, and the Flat radio button checked. If you don’t have one or more of these settings, adjust them until you do. Then click on Create New.

4. Your new flat terrain will be inserted into the scene.

Most likely you won’t see it, but you might see the axis bug appear in the middle of your screen. If it does appear, grab the blue axis arrow and drag the terrain upward until it just clears the ground plane. Otherwise you can select it in the Scene tree and then grab the axis to move it.

You probably have trees and rocks left over from your earlier fiddling with the Forest Editor. If you do, great! If you don’t, no worries. We don’t need them. However, if you do have rocks and trees, just make sure you don’t drag the terrain too high. Just get it high enough to clear the ground plane, and no higher.

If your new terrain was created above the ground plane already, lower it until it is just barely above the ground plane. Figure 16.25 shows an example.

Figure 16.25
Positioning the auto-genned terrain.

Image

5. Once you have your new terrain in, fly down to the terrain and spawn your player somewhere not too cluttered with trees and rocks. Use the Alt-W key combo to do the spawning.

6. Ensure that you have the Object Editor selected (F1). Then over on the right in the Library tab, find your way to the Level tab and into the Environment folder.

7. Locate the Ground Cover object and double-click on it. You will get a Create Object: GroundCover dialog.

8. In the dialog, give the object a name, like myCover. In the Material Name box area, click on the Round icon to the right of the box. This will open the Material Selector. Over in the Tags section on the left, click once on the Vegetation entry.

9. In the Materials pane with the Vegetation tag selected, find the material that starts with “groundcover_” for the name and click on it so that a picture of the material appears in the Diffuse Preview pane with the name “groundcover_ grass” below the image.

Tip


If you don’t see the material you are looking for change the number of material thumbnails that are displayed on the page. The setting is near the bottom of the Materials pane, called Thumbnails per Page.


10. Click on the Select button. Material Selector goes away.

11. Now click on the Create New button to finish off the dialog. The dialog vamooses and an axis bug appears in the middle of your scene, labeled “myCover” or whatever you named your ground cover object.

Tip


In order to get the axis bug to appear for an object, you will need to have either the Move Selection, Scale Selection, or Rotate Selection tool selected in the toolbox on the left.


12. You will also see some new billboard shapes in the scene, all jittery and jumpy like. Something like Figure 16.26. If they aren’t jittery, that’s okay.

Notice that each placement actually seems to be four different images. That’s because the ground cover image we are using has four different tufts of dried grass in it. But we can tidy that up easily.

1. Ensure that you have the Scene tab selected and can see the Scene tree. Select the entry for your ground cover by clicking on it in the Scene tree. Down below the Scene tab, in the Inspector pane, you can see that there are very many different properties that you can set.

2. Scroll down until you see a grouping called Types, with a little plus (+) sign to the left of the word Types. Click on the plus sign to expand the types into eight entries, zero to seven.

3. Expand the first (number 0) entry.

4. The first entry is called billboardUVs. Click on the square icon on the far-right side of this entry. The UV Editor will be opened.

5. Drag the blue adjustment handles around until the image you end up with is approximately the same as the one in Figure 16.27.

6. Click the OK button.

Figure 16.26
Newly inserted Ground Cover.

Image

Figure 16.27
UV Editor with subselection.

Image

7. You will see the ground cover vanish momentarily, and then return, tuft by tuft. This time it’s only the portion of the image that we outlined in the UV Editor that’s visible.

Now, if you go wander around the scene a bit, you will find that the tufts of grass appear all over the place, rather indiscriminately. Our next procedure will provide a great deal of focus for the placement of these tufts.

First, we need to create a new Terrain Material layer, and apply a material to it.

1. In the World Editor, press F3, or click on the third button from the left in the Editor toolbar (it looks like a paintbrush). This opens the Terrain Painter.

2. Over on the right side, in the Terrain Painter Material Selector panel, click on the New Layer button. This will open the Terrain Materials Editor dialog.

3. Look through the list of materials on the left side of the dialog until you find dirt_grass. Click on it to select it, then click on the Apply & Select button at the lower right of the dialog. A new layer appears in the Terrain Painter Material Selector panel, called dirt_grass.

4. Click on the dirt_grass layer to ensure that it is selected.

5. Up at top center in the Brush Settings toolbar, set the size to 5, and Pressure to 100.

6. Find a bare spot of the sandy desert-like terrain, and paint on some dirt_grass, as shown in Figure 16.28.

7. Now switch back to the Object Editor (first button in Editor toolbar on the left, or F1) and select the GroundCover object you created a short time ago.

8. Repeat steps 1, 2, and 3 from the previous procedure where we fiddled with the billboard UVs.

Instead of working with the first entry in the Types[0] section as we did in step 4 of the previous procedure, we are interested this time in the third entry: layer.

9. To the right of the layer field lurks the Layer button, which looks like this: Image Click on it to open the Material Selector.

10. You should find two materials as shown in Figure 16.29. These are the two materials that you’ve painted onto the terrain. Of course, if you went ahead and added other materials to the terrain, then your selection of materials will be different.

11. Click on dirt_grass, then click on the Select button.

Figure 16.28
Painting the dirt_grass material onto the terrain.

Image

Figure 16.29
Available terrain materials.

Image

12. Press the Enter key to ensure that your edit is committed (not strictly necessary, but sometimes the interface needs a little encouragement).

13. You may or may not see tufts of grass appear in the scene. If you do, it will likely be only one or two—a handful at most. That’s normal. However, before proceeding, take a look around at the sandy desert parts of the terrain. Notice that the tufts that were scattered about are now gone! Next we have to tweak some values in our GroundCover object.

14. Ensure that the GroundCover object is selected, and that you are still in the Object Editor. Scroll through the properties panel on the right side examining the properties of the GroundCover you created until you find the radius property in the “Ground Cover General” area. It is probably set to 200. Change it to 30.

15. Change the dissolveRadius property to 25. You should see many more tufts of grass appear as in Figure 16.30.

The radius property dictates how far away, at maximum, the GroundCover will be rendered. None of the selected GroundCover will appear beyond that radius. The dissolveRadius property tells the engine at what distance from your camera to start fading away the rendering of the GroundCover to nothing. This is so that there will be a smooth transition from something to nothing.

Figure 16.30
Grass tufts on the dirt_grass material.

Image

Note that the larger the radius, the more dispersed the GroundCover will be.

16. Change the maxElements property to 3000. With three times the number of elements, the grass tufts are much denser.

Tip


The maxElements property is an odd duck. One would expect it to be used to define the maximum number of GroundCover elements that would appear on the materials that the cover has been assigned to. This doesn’t seem to be the case. Instead, it seems to me that it defines the max number of elements that would be rendered within the radius around the player, in all directions, regardless of material. This likely means that the density calculations in the code for GroundCover occur first, and then the material is used to filter the locations where the cover can actually be rendered.

I’m not sure if this was the design intent, or a bug. But the result is that you get the odd circumstance of setting the cover to have a maximum of 3000 elements, yet only 20 or 30 are actually rendered, simply because the area covered by the reference material layer is small. So just keep that in mind. If no GroundCover is showing where you think it should, reduce the radius to increase the density, or increase the maxElements count by 10 times or even 100 times.


So experiment now with the GroundCover properties. For each Type, you can set the probability that the cover will appear. You can even invert the rules, setting the cover to not appear on the assigned layer, but to appear everywhere else. Plus a great deal of other settings. This object is brimming with tweaky-goodness.

Now let’s move away from scenery and on to something a little different.

THE TOMMY GUN

The famous Thompson submachine gun is a somewhat obsolete weapon that most people are familiar with visually, even if they don’t know what it’s called.

The technique we will use is the Extrusion method. When it comes to modeling weapons, Extrusion is probably the method of choice for the simple reason that it often works well when using photographs for source material. There are dozens and dozens of books and many Internet resources available that have photographs and technical drawings of weapons, but remember that much of the source material is copyrighted.

For our tommy gun, I’ll work from a sketch I made, shown in Figure 16.31.

Figure 16.31
Tommy gun sketch.

Image

Tip


To create your weapons, you can use a photograph or detailed diagram of your own if you like; however, you are perfectly free to use my sketches and artwork in any way you want to. The choice is yours.


The sketch is rough and not very detailed, but it will do just fine for our purposes. This model will have as few polygons in it as I think we can get away with. I’ve made two versions of it for you to use: one for the skin and one to act as the extrusion reference image.

Making the Model

Get MilkShape running and warming up in the driveway, and we’ll get started in a minute. We will use 3D3ERESOURCESCH16 ommygun.png as the texture for the tommy gun’s skin. You can find the extrusion guide sketch at 3D3ERESOURCES CH16 ommygun_ref.bmp. You need to set the latter as the background image for the Side view window in MilkShape; we’ll use the former later on in this section.

1. Select the Vertex tool, making sure that the Auto Tool checkbox is cleared.

2. In the Side view, start placing vertices at all the major corners and points around the components of the gun. See Figure 16.32 for reference.

3. Start making faces. No! I meant in the model, not at me! You will probably have to zoom in some to get enough separation between the vertices.

Be careful as you move along, making sure you get all the faces. For tips and other information on faces, review Chapter 15. Figure 16.33 shows the finished polygon faces around the muzzle, which can be a bit fiddly. Notice how far I zoomed in.

Figure 16.32
Tommy gun vertices.

Image

Figure 16.34 shows the barrel and forestock faces. A warning about the barrel is in order here, I think. In this model we will stick with a straight extrusion exercise, but I highly recommend that after you complete this section you rework the model and make the barrel a cylinder object. The results will be nicer.

Figure 16.35 shows the faces completed for the grip, the receiver, the magazine, and other metal parts of the main body of the gun. Note that I haven’t modeled the trigger or the trigger guard hole—leaving these out saves a ton of polygons. If you want you can add in the detail for the trigger, but you will probably take a hit on frame rate in the game.

Figure 16.36 shows the faces of the wooden shoulder stock.

Now take a look at Figure 16.37. Notice the missing polygon down there in the 3D view? It’s not evident by looking at the wire-frame view that the polygon was missed, but its absence really shows in the 3D view. Don’t let this happen to you! Heh.

If it does happen to you, fix up the wayward faces, and we’ll move on to the extrusion.

Figure 16.33
Tommy gun muzzle faces.

Image

Figure 16.34
Tommy gun barrel and forestock faces.

Image

Figure 16.35
Tommy gun metal body faces.

Image

Figure 16.36
Tommy gun shoulder stock faces.

Image

Figure 16.37
Tommy gun loses face—film at 11.

Image

4. Select all the faces.

5. Use an X value of −2.0, and then click the Extrude button. Do not deselect the highlighted faces after this operation. You should get something that looks like Figure 16.38.

Next, we will have to cap off one end of the extrusion, like we did with the car model. It’s a simple operation but sometimes a bit touchy.

6. Choose Edit, Duplicate Selection and then quickly reverse the normals by choosing Face, Reverse Vertex order while the duplicate is still selected. This is so that the faces on the duplicate will be oriented 180 degrees from the original. You might also have to reverse the normals on some of the faces on the top or bottom of the gun. If the face shows black in the 3D view, then just select the face and choose Face, Reverse Vertex Order.

Figure 16.38
Extruded tommy gun.

Image

7. Use the Move tool to drag the copy of the faces back over to the side of the model, using the Front view window to monitor the activity.

8. Zoom in on a few of the vertices in the Front view, and make sure that the copy of the faces perfectly align with the edge vertices on this side of the model.

9. Select all vertices in the model, and then choose Vertex, Snap To Grid. One or two of the vertices might snap to an awkward location, so go ahead and manually fix them.

10. Choose Vertex, Weld Together.

The model as built so far is fine, except that it was created at a scale four times larger than we want for use in-game. This was deliberate. A larger scale allows us to use larger reference images for the background image, which gives us access to more detail. Also, the larger the scale, the finer the granularity available when we want to snap points to the grid. So after all this work, we need to scale the model back to the correct size.

11. Select all parts of the model.

12. Use the Scale tool to set the scale to 0.25 in all three axes.

13. Click the Scale button to the right of the axis boxes. The gun will shrink and should appear roughly as shown in Figure 16.39.

Figure 16.39
Shrunken gun.

Image

Next, we have three nodes to add: one to indicate where the gun is held, one to indicate where the muzzle is, and one to indicate where expended shells are ejected. These nodes inform the engine where these spots are; a script that will be defined later dictates how they are used.

14. Create three unconnected joints, positioned and named as shown in Figure 16.40. The three node names are mountPoint, ejectPoint, and muzzlePoint.

We have one more thing to do. We need the gun to have the correct posture when held by the player model.

15. In the Top view, select all faces.

16. Rotate the gun about 8 degrees to the left, as shown in Figure 16.41.

17. Move the nodes to align them with the gun, using Figure 16.41 as a guide.

VoilĂ ! Insta-gun. Save your work.

Figure 16.40
The tommy gun nodes.

Image

Figure 16.41
The rotated tommy gun.

Image

Skinning the Tommy Gun

Way back in Chapter 13 you learned how to use UVMapper and the Gimp to create a skin for objects. In this chapter we’ll look at using the built-in Texture Coordinate Editor in MilkShape to accomplish the same thing. It can be awkward to use but is suitable for our purpose here because we will already have a texture to use for the skin—in this case, we will use a version of my original sketch.

1. Create a new material, using the file tommygun.bmp as the bitmap for the texture.

2. Assign the new material to the tommy gun object.

If you have more than one object, select all the faces in all the objects, then regroup them. After that you can assign the new material to the single object.

3. Use the Groups tab, and select the tommy gun object.

4. Choose Window, Texture Coordinate Editor. You will get the Texture Coordinate Editor dialog box, as shown in Figure 16.42.

Figure 16.42
Texture Coordinate Editor dialog box.

Image

When the Texture Coordinate Editor first opens, you often see just some confusing white lines over the top of the texture assigned to the object you are skinning. Not to worry.

5. Select the appropriate view from the view selection combo box at the right side of the dialog box. In the case of the tommy gun, this is the Left view.

6. Click the Remap button. You should get something like that shown in Figure 16.43. The shape of the tommy gun may not line up with the texture, so go ahead and use the Select and Move buttons inside this editor to move the vertices until they are in place. Figure 16.43 is a good guide to what the final result should look like.

Figure 16.43
Remapped view.

Image

7. Close the Texture Coordinate Editor dialog box, and take a look in your 3D view (make sure that it is set to Texture mode). There it is—your tommy gun! Compare your work with Figure 16.44. As you examine it closely, you will see why it might be a good idea to redo the barrel as a cylinder.

You might notice that the gun appears to be textured only on one side in the 3D view. This is because of the rotation. It actually is textured on both sides, but the lighting effect in the 3D view casts one side in shadow.

Testing the Tommy Gun

In order to test the tommy gun, we first need to export it from MilkShape.

1. Create a new folder, artshapesTommygun, and save your work there, too, if you like.

Figure 16.44
Finished tommy gun.

Image

2. Use the DTSPlus Exporter to export your gun, using the same settings as used earlier in this chapter for the other exports.

3. Click DTS Export to send the gun on its merry way to its new life as artshapesTommygunTommygun.dts.

Okay, now it’s time to see the gun in the game. I can hear you now: “woohoo! Mayhem and noise and stuff!”. Relax, the mayhem comes in a later chapter.

1. Run the FPS Example demo.

2. Follow the same procedure as you did with the Health Kit and the rock, but this time insert the tommy gun into the game world instead.

3. Go over and have a look. The gun is, at the moment, a static shape—it doesn’t know how to do that cool machine gun stuff yet. We’ll get to that later.

So much for the mayhem. Patience, grasshopper!

The Tommy Gun Script

Just as we encountered with the runabout in Chapter 15, making the model for a weapon is not the whole job. We have yet to create the weapon script that defines how the weapon works. That is something we will cover later, in Chapter 22, when we look at the code that brings all of these models together in our sample game.

MOVING RIGHT ALONG

This chapter was a bit of a review of techniques covered in earlier chapters, but we applied these techniques to a few different kinds of items with different features: collision meshes, no collision meshes, billboard textures, and translucent textures. This helps demonstrate the wide variety of characteristics that modeled items can have in a game world.

We learned how to insert scenery decorations into our scenes for a more realistic look.

We also looked at the MilkShape’s Texture Coordinate Editor a little bit, enough to be able to use it to tweak texture maps if the situation warrants.

In the next chapter we’ll learn a new sort of 3D modeling tool and use it to make structures.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.148.104.242