3D Game Programming All in One (Course Technology PTR Game Development Series)
In this chapter we are going to build a complete wheeled vehicle—the runabout, which will wear the skin you created in Chapter 9. Then we will insert it into a little test game so that we can carom about and drive our insurance rates through the roof!
The Sketch
I find the best way to start a new model is with a sketch. Doodle out some ideas, and keep working them up on paper until you get something that suits your needs. Then choose a view (Left or Right, Top or Bottom, Front or Back) that presents you with the most number of intersections of lines to use as points.
Figure 15.1 shows a sketch of the runabout from the right-hand side. Notice that it is really a sketch and not a drawing. As long as the general proportions and coarse features are present, it's satisfactory. Now if you were going to model a real car, you might need to use a more detailed sketch or perhaps something that would qualify more as a drawing than a sketch. Then again you may not—it all depends on how much detail is necessary to suit your needs.
The Side view is the main sketch we will use to make our model. When modeling most vehicles, you will usually use a Side view as your primary source for extrusion modeling. The reason for this is pretty obvious: Most vehicles are longer than they are tall or wide. The symmetries of vehicles (how one side mirrors the other) tend to reflect around the longitudinal axis, the one that runs from the rear to the front of the vehicle up the middle.
The Top view of the runabout is shown in Figure 15.2. The purpose for sketching this view is to provide a guide for your modeling efforts as they proceed. You will find yourself checking back against this drawing quite often.
One more useful thing is to make a copy of the Side view and, using Paint Shop Pro, adjust the brightness of the image. This is because when we import the sketch into MilkShape, we don't want the image to overpower any of the on-screen modeling marks we make. I find the best approach is to darken the whole image by around 40 to 50 percent and reduce the contrast by about 50 to 60 percent or so. Figure 15.3 shows the adjusted Side view. I keep the original sketches as they were so that I can print them out for reference purposes (and also just to pin up on the wall because it's a cool artsy thing to do).
The Model
So pour some gasoline in the ol' computer, grab the pull-start, and fire up MilkShape again if it isn't already running. If you need a quick refresher, you can jump back to Chapter 14. Set your MilkShape GUI display to the four-view mode by choosing Window, Viewports, 4 Window.
Create a fresh new MilkShape document. It's a good idea to save the empty file right now, just to get the path set up and establish the file name.
Then you want to import the side sketch as the background in the Side view (Top Right view). Right-click in the Side view and choose Choose Background Image from the pop-up menu. Select your sketch and click OK. You can use my sketch if you want—it's located at C:\3DGPAi1\RESOURCES\CH15\ref_sketch.bmp.
You should end up with something like Figure 15.4.
So now we start.
Building the Body
First, we'll build the body:
-
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 edge of the car's body—don't do the fenders yet. See Figure 15.5 for reference.
Figure 15.5: Placing vertices over the reference sketch. Note There is also a string of vertices across the "waist" of the body—in Figure 15.5 they are highlighted as black squares (they show red in MilkShape).These extra vertices are added for two reasons: First, they act as useful anchors for creating the faces that we'll make later. And second, they help add more malleability to the model for shaping the sides of the car.
After we have the vertices placed, we move on to creating the faces joined by the vertices.
Tip It's important to remember that when we create faces using the Face tool, we click on three vertices in sequence to create one face.The order we click on the vertices is important.To create a face or polygon that is facing toward us, we need to select the vertices in a counterclockwise order, as shown in Figure 15.6. For most cases this is not hard to do, but it's possible to get confused and lose track of the sequence. In this case you can use the Edit, Undo menu item to back up until the sequence is clear. You can also abort any three-vertex sequence by just clicking on the Selection tool (or any other tool) and then clicking back on the Face tool again. Then you can start with a fresh trio of vertices.
Figure 15.6: Vertex order for creating faces. -
Starting at the right side (the front of the car), begin creating faces, moving to the left along the top as you proceed, including the window area, as shown in Figure 15.7.
Figure 15.7: Creating faces starting from the right. When you reach the left side, you should have something resembling Figure 15.8.
Figure 15.8: Finishing the top row of faces. -
After completing the top row of faces, start making faces along the bottom, from the left back over to the right (see Figure 15.9).
Figure 15.9: Working the bottom row of faces. -
Finish up the faces for the side of the body. You should end up with something like Figure 15.10.
Figure 15.10: Completed plane of body faces. Okay, so now we have a plane of body faces. We want to make sure they are all oriented correctly. The quickest way to do this is to look at the output in the 3D Perspective view. Make sure the view (it should be the Bottom Right view) is set to either Flat Shaded or Smooth Shaded by right-clicking on the view and then choosing either Flat Shaded or Smooth Shaded in the pop-up menu.
What you should see is the outline of the body rendered in white or light gray, just as in Figure 15.11.
Figure 15.11: The 3D view of the initial body faces. Tip This is a long one, so make sure you've got some popcorn handy!
Sometimes you end up with two overlapping faces: one oriented correctly, and the other reversed. These are hard to catch until they start showing strange results when rendering, as the model grows more complex. There is another way to check for misoriented faces that is a little more involved:
-
Pick the Selection tool and set it to Face mode. Make sure that the Ignore Backfaces check box is selected.
-
Now use the Selection tool to select all the faces by dragging the selection rectangle around all of them. This will highlight all the faces.
-
Now choose Edit, Hide Selection. All of the correctly oriented faces will vanish, leaving behind only the ones facing the wrong way.
-
To fix the problem, unhide all the hidden faces, clear the Ignore Backfaces check box, and select all the faces again. This will select all correct and incorrect faces.
-
Then choose Face, Reverse Vertex Order. This will make the good ones bad, and the bad ones good. Still with me?
-
Okay, now deselect everything by clicking the Select tool in an open area, and select the Ignore Backfaces check box again.
-
Drag select over all the faces one more time. Now only the faces that were originally incorrect will be selected.
-
Choose Face, Reverse Vertex Order with those faces selected.
-
Then for one final time clear the Ignore Backfaces check box, select all the faces, and choose Reverse Vertex Order. This should flip all faces back to the correct orientation. If this reminds you of manipulating a Rubik's Cube, then you think a lot like I do!
So now we'll move on to adding some width to the body.
-
-
Choose the Selection tool and set it to Face mode.
-
Select all the faces.
-
Click the Extrude tool and fill in the X entry of the XYZ boxes with the value −10.0 (that's minus ten point zero). Leave Y and Z at 0.0.
-
Click on the Extrude button to the right of the XYZ boxes. You should get a new set of polygons negatively offset in the X-axis by 10 units, as shown in Figure 15.12.
Figure 15.12: First extrusion. Notice the way that the image in the 3D view looks—now the body has some depth to it. It's not just a plane of faces anymore.
-
Repeat step 9 four more times, until you get five segments as shown in Figure 15.13. Warning: Do not click on any other tool or in the edit windows. After the fifth extrusion you want to end up with the body faces still selected.
Figure 15.13: After extruding the body faces five times. -
The body faces should still be selected if you got my warning in time. Choose Edit, Duplicate Selection.
-
Click the Move tool, then go to the Top view at the lower left, and drag the highlighted faces (these will now be the copies, not the originals) to the right, clear of the extrusion segments, so that you get something like that shown in Figure 15.14.
Figure 15.14: After duplicating and moving the copies. -
Choose Face, Reverse Vertex Order.
-
Using the Side views and Top views, align the vertices of the copy of the body faces with their counterparts in the main body.
-
In the Top view drag the body face copy over to the right edge of the rest of the body polygons. Align the vertices as best you can by eye.
Tip We want to make sure that the vertices in Step 15 are perfectly aligned. To do this, we'll scale our entire model up. Making our model larger in relation to the grid allows us more precision with the grid. This will help ensure good results when we snap our vertices to the grid, which is going to happen shortly.
-
Select the entire set of polygons in all the faces, and then use the Scale tool to make the entire model four times larger.
-
Select the entire model in vertex selection mode, and choose Vertex, Snap To Grid.
-
Choose Vertex, Weld Vertices.
-
Scale the model by 0.25. This will restore the model back to its original size.
-
In the Top view make sure the entire model is selected, and then use the Move tool to drag the model over the sketch so that it is aligned around the longitudinal center of the car in the sketch.
You should now have a model that looks like that shown in Figure 15.15.
Figure 15.15: Scaling the nose of the runabout. -
In the Top view select the bottom nine rows (or forwardmost nine rows) of vertices.
-
Use the Scale tool to scale the selection to 0.9 in the X-axis only; leave the other values at 0.0. Figure 15.16 shows the result of this operation.
Figure 15.16: After scaling the bottom nine rows. -
Change your selection to be the bottom eight rows and scale to 0.9.
-
Repeat the decrementing and scaling of the selection, reducing your selection vertices one row at a time until you run out of victims…ummm…I mean vertices.
You should now have something that resembles that shown in Figure 15.17.
Figure 15.17: After scaling the nose. -
Repeat this iterative scaling process for the rows of vertices as seen in the Top view at the other end of the car body, until it, too, tapers, as shown in Figure 15.18. You may find it necessary to manually move a few vertices at either end to achieve the appropriate amount of taper.
Figure 15.18: After scaling the tail. -
Now perform the same sort of iterative scaling operations on the Front view of the car, getting it to look something like the view shown in Figure 15.19.
Figure 15.19: Shaping the Front view. -
Next, use the Selection and Move tools to place the car so that it is centered around the origin (0,0,0), as shown in Figure 15.20. The axis "bug" at the origin has been enhanced as thick black lines to emphasize its location.
Figure 15.20: Centering the Front view. -
Finally, select all the polygons and use the Groups tools to regroup all polygons into a single group—name it "body".
Building the Fenders
Next, we will tackle the wheel well and fender assemblies.
-
Hide the body group.
-
On the Model tab, select the Sphere tool, and create a sphere that matches the forward curves of the forward fender, as shown in Figure 15.21.
Figure 15.21: Fender sphere. -
Select the bottom two rows of faces and delete them. Then move the bottom row of vertices up a bit, to get something that looks like Figure 15.22.
Figure 15.22: Lopping off the bottom of the fender sphere. -
Select the leftmost three rows of vertices and move them farther left, as shown in Figure 15.23.
Figure 15.23: Stretching the fender. -
Continue to reshape the fender to match the sketch as shown in Figure 15.24, until you are happy.
Figure 15.24: Shaping the fender. The next bit is a little tricky, so move slowly. We want to drag certain of the vertices from the fender over to the exact position of vertices on the body. The vertex rows we want from the fender are the two bottom ones, and we are interested in the vertices on the body side. By dragging them over to the body, we create a fairing-cum-running board sort of affair.
-
Unhide the body.
-
Drag the fender away from the body so that it is in the clear in the Top and Front views.
-
Select the vertices and drag them, one at a time, as shown in Figure 15.25. The vertices are on the two bottom rows and are the ones that face the body.
Figure 15.25: The fender vertices. Make sure to place the vertices exactly where they mate with a corresponding vertex. A close-up view is shown in Figure 15.26.
Figure 15.26: Close-up of moved vertices. -
After each vertex is placed with a mate, use Snap To Grid to make sure they are exactly coincident, and use Weld Vertex to convert each pair of vertices into one vertex. Once you have done this for all the appropriate vertices along the fender bottom, you will get something like Figure 15.27.
Figure 15.27: All vertices moved. -
Finally, move the fender back to a position that matches the sketched fender in the Top view, as shown in Figure 15.28.
Figure 15.28: Finished fender. -
Repeat steps 2 to 10 for each of the other fenders. Remember to hide the body and the other fenders when necessary to remove clutter from the screen. You should end up with the finished car as shown in Figure 15.29. But we aren't done yet!
The Mount Nodes
In Chapter 14 you learned how to make a skeleton for an animated character in MilkShape using joints. In this section we are going to use the same feature, the joint, to create nodes that tell Torque where to mount certain things on models.
-
As shown in Figure 15.30, create four unconnected joints, or mounts, on the four corners of the car where the wheel hubs would be. To ensure that the joints are unconnected, you need to use the Select tool to deselect each node after it's been created.
Figure 15.30: Mounts on all four corners. -
Name each of the joints with the names shown in Figure 15.30, with hub0 being the left front joint.
-
Add two more unconnected joints to the locations shown in Figure 15.31. Name the front one "eye" and the rear one "cam".
Figure 15.31: Eye and camera mounts. -
Finally, add two unconnected joints to the locations shown in Figure 15.32. Name the one on the right (the left-hand seat position) "mount0" and the other one "mount1".
Now, the last two pairs of mounts are used for different, and mutually exclusive, purposes. The eye and cam mounts are used for games where the car becomes the player's avatar. The sample racing game that comes with Torque works like that. The eye node located at the point of the eye mount is the normal first-person point-of-view location for the view's eye. The cam node is for the third-person point of view—the actual camera is offset from the location of this node and so is usually actually behind and above the vehicle.
The mount0 and mount1 mounts are used for games where the player's character actually gets "in" the vehicle; they specify where the player's avatar will be mounted. The game continues to use the player's avatar's camera and eye nodes. You saw those in use back in Chapter 14.
Skins
Chapter 9 covered the subject of skins and UV mapping, so I refer you back there to map the textures for your new car. You can find a copy of the skin to use at C:\3DGPAi1\RESOURCES\CH15\
Collision Mesh
For all objects except player models, we need to create at least one collision mesh if we want the engine to detect when it collides with another object, so use the Box tool in the Model tab to create a box that surrounds the vehicle, as shown in Figure 15.33.
Name the collision mesh "Collision". Any name that starts with "collision" will do, like "Collision-1", "CollisionA", and so on. You can have more than one collision mesh if you like.
You should also hide the collision mesh and then save the model before exporting the model.
Категории