3D Game Programming All in One (Course Technology PTR Game Development Series)
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.21.
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 C:\3DGPAi1\RESOURCES\ CH16\tommygun.png as the texture for the Tommy gun's skin. You can find the extrusion guide sketch at C:\3DGPAi1\ RESOURCES\CH16\tommygun_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 in this section.
-
Select the Vertex tool, making sure that the Auto Tool check box is cleared.
-
In the Side view, start placing vertices at all the major corners and points around the components of the gun. See Figure 16.22 for reference.
Figure 16.22: Tommy gun vertices. -
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, check back to Chapter 15. Figure 16.23 shows the finished polygon faces around the muzzle, which can be a bit fiddly. Notice how far I zoomed in.
Figure 16.23: Tommy gun muzzle faces. Figure 16.24 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.24: Tommy gun barrel and forestock faces. Figure 16.25 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.25: Tommy gun metal body faces. Figure 16.26 shows the faces of the wooden shoulder stock.
Figure 16.26: Tommy gun shoulder stock faces. Now take a look at Figure 16.27. 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.
Figure 16.27: Tommy gun loses face—film at 11. If it does happen to you, fix up the wayward faces and we'll move on to the extrusion.
-
Select all the faces.
-
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.28.
Figure 16.28: Extruded Tommy gun. 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.
-
Choose Edit, Duplicate Selection.
-
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.
-
Zoom in on a few of the vertices in the Front view and make sure that the copy of the faces perfectly aligns with the edge vertices on this side of the model.
-
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.
-
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.
-
Select all parts of the model.
-
Use the Scale tool to set the scale to 0.25 in all three axes.
-
Click the Scale button to the right of the axis boxes. The gun will shrink and should appear roughly as shown in Figure 16.29.
Figure 16.29: Shrunken gun. 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.
-
Create three unconnected joints, positioned and named as shown in Figure 16.30. The three node names are mountPoint, ejectPoint, and muzzlePoint.
Figure 16.30: The Tommy gun nodes. We have one more thing to do. We need the gun to have the correct posture when held by the player model.
-
In the Top view, select all faces.
-
Rotate the gun about 8 degrees to the left, as shown in Figure 16.31.
Figure 16.31: The rotated Tommy gun. -
Move the nodes to align them with the gun, using Figure 16.31 as a guide.
Voil ! Insta-gun. Save your work.
Skinning the Tommy Gun
Way back in Chapter 13 you learned how to use UVMapper and Paint Shop Pro 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.
-
Create a new material, using the file
tommygun.bmp as the bitmap for the texture. -
Assign the new material to the Tommy gun object.
If you have more than one object, select all of the faces in all of the objects, then regroup them. After that, you can assign the new material to the single object.
-
Use the Groups tab, and select the Tommy gun object.
-
Choose Window, Texture Coordinate Editor. You will get the Texture Coordinate Editor dialog box, as shown in Figure 16.32.
Figure 16.32: Texture Coordinate Editor dialog box. 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.
-
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.
-
Click the Remap button. You should get something like that shown in Figure 16.33. 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.33 is a good guide to what the final result should look like.
Figure 16.33: Remapped view. -
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.34. As you examine it closely, you will see why it might be a good idea to redo the barrel as a cylinder.
Testing the Tommy Gun
In order to test the Tommy gun, we first need to export it from MilkShape.
-
After saving your work, choose File, Export, Torque Game Engine DTS. You will see the Torque Game Engine (DTS) Exporter appear.
-
Use the defaults, but make sure they are correct.
You want to have Export Animation and Export Material Information enabled, and the Collision Mesh set to None (this is automatic if the exporter finds that there is not a mesh whose name starts with "Collision"). Items that are used as weapons don't need to have a collision mesh created—the Torque Engine knows how to handle them without the collision mesh. Click OK when ready.
-
Export your Tommy gun to DTS format as C:\3DGPAi1\fps\data\shapes\ Tommygun\Tommygun.dts.
Next, you need to edit the script that controls the weapon so that it will look for your model, and not the default one. We'll use the simple futuristic blaster-style rifle in the fps demo that comes with Torque. It might sound funny, and the bullets will look weird, but that's okay—we just want to see our Tommy gun model in a gamelike environment.
-
Locate the file C:\3DGPAi1\fps\server\scripts\rifle.cs and open it with UltraEdit.
-
Find the line that says this:
shapeFile = "~/data/shapes/buggy/buggy.dts";
and replace it with this line:
shapeFile = "~/data/shapes/car/car.dts";
-
Then find the line that says this:
pickUpName = "a rifle";
And replace it with this line:
pickUpName = "a tommygun";
-
Save the file.
Okay, now it's time to run the fps demo.
-
Browse to C:\3DGPAi1 and click on the Run fps Demo shortcut.
-
Click Start Mission.
-
In the Launch dialog box, make sure that the Multiplayer Mission box is cleared.
-
Select Water World from the mission list.
-
Click Launch.
-
After the game loads, look around for a big gray block jutting out from the side of a hill into the water. Figure 16.4 in the earlier section about the Health Kit shows what the block (marked by the arrow) looks like.
-
Run over to the block. On top of it you will find the Tommy gun.
-
Run over the gun to automatically pick it up. You will see a message in your chat window telling you that you've picked it up.
-
Look elsewhere on the block—there are ammo boxes at the other corner. Go pick them all up by running over on top of them.
-
Find something to shoot at and let go!
After a short while, a new copy of the Tommy gun will reappear at the spot where you picked up the first one. Head back over there so you can admire your modeling handiwork as it gently rotates in the, errr…breeze. Yeah, a circular breeze—that's what it is!
There is also a primitive crossbow located on the bridge, if you are of the mind to go and check it out. Press the 1 key or the 2 key to switch back and forth between the weapons if you have more than one.
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.
Категории