Submitted by
yesukai on Sat, 2005-03-26 22:41.
Creating a 'prop_physics entity'
A big part about mapping for Half-Life 2 (and Source games in general) is the use of props to spice up a level while allowing the engine to remove the detail to preserve performance. I will guide you through the creation of a prop_physics entity, which may also be used as a prop_static entity. Anything you see in grey boxes is an explanation on why something is the way it is; you can safely ignore them if you don't care why. We are going to pick a nice simple object to start with: a can of Spam.
Modeling
Start up XSI. First we are going to change the backface settings of XSI to make it more Source friendly. Go to View -> Display Options (All Cameras) . Then click the Performance tab, and select backface culling.
Why? Because the Source engine, like most 3D games, does not display backfaces. With backface culling turned off in XSI (the default), you can't easily see which side of a polygon is the backface and which isn't. You could accidentally make your entire model inside out. It's safer just to have XSI display models the same way the Source engine will.
|
With that set, we are ready to start building our model.
Go to Get -> Primitive -> Polygon Mesh -> Cube .
This will create a cube on the grid. Now, a can of Spam is not quite a square, it's more of a rounded rectangle. To make the cube rounded, we need to add some more edges to the sides. Press I to use the Edge Select Tool , then click the top and bottom edges of one side while holding CTRL. They will both show red once they have been selected. Now, hit Shift-D to bring up the Subdivide Edge Op dialog. By default, the subdivision amount is set to 2, this means what was once one piece (a square) is now two pieces (two rectangles). This really will not make the edges of the can look that round, so let's increase it. A value of 5 works well here, as it gives us one polygon in the middle to use as the side of the can, then two edges to use for each corner. After splitting the edges, select the top and bottom edges of the opposite side of the can, and repeat the subdivision process.
With the sides divided up, we are able to move the points out to make for a better looking can.
Press T for point selection mode, then drag the selection box over all of the model's points. As the can is symmetrical, it would be in our best interest to move both side's points out the same amount and at the same time. To do this, we use the scale tool. Press X to use the scale tool. From the any viewport, click and hold the axis bar that points away from the center in the direction of the sides of the can. Drag the mouse to the side, and the can gets wider on that axis, all points moving away from each other on that axis; you now have a rectangular can. To make the can rounded, select only the four inner points on the sides, and scale them on that axis again, just a bit farther outward. Select the two inner-most points on each side and push those out even farther. You will probably have to use the "Translate Tool" ( V ) to move the points around to make for a better shape, as shown in the image.
Now that we have the basic shape of the can, we need to make sure it's proportional to a real can of Spam. This is where rotoscopy comes in handy. Rotoscopy is pretty much the process of putting a picture behind your object to help you model it. A good picture to use for this was found off of Google Image Search, and can be found here . In the front view, go to the part that says wireframe , then go down the menu to rotoscope . In the dialog box that pops open, Click New and navigate to your reference shot of a can of Spam. Scale the model until it is approximately the same size as the can of Spam.
This next step is extremely important: go to transform -> Set Neutral Pose then go to transform -> Freeze All Transforms.
Why? XSI stores the points as being where they were created. All transformations used on them are just numbers that are applied to these points. When you export your SMD later, it will export where XSI says the points are, but not the translations. This means that your exported model would be the square you started with. By freezing the transformations, you are telling XSI that the points current position (with transformations applied) should be its starting position. Thus, it will export properly.
|
The basic model should now be done.
Texturing
Texturing is the process of assigning texture coordinates to a model. The goal is to get all the polygons arranged on top of a texture while minimizing the amount of distortion. To do this, first we go to Get -> Property -> Texture Projection -> Cubic . This will lay the polygons flat onto the texture projection. What decides which polygons go together is the direction they face. In this case, the front, back, left side, right side, bottom, and top will all be separate pieces or "islands" on the projection. To see what the texture projection looks like or to edit it, you need to click the view (such as top) on one of you viewports, and select Texture Editor from the menu. This changes that viewport to the texture editor. You should see the Spam picture we used earlier covered with yellow lines and red shading. First thing to do is to change that picture of Spam to a more suitable background for texturing. This is the texture provided by valve, it is a checkerboard pattern, which is helpful in determining the amount of distortion. Download that image, then click Clips -> Import Clips in the texture editor. Select the checkerboard image you just downloaded and hit OK. This changes the background image in the texture editor to the checkerboard. All of the flattened pieces of our image are stacked on top of each other: we must remedy this. Press I to turn on island select . In your camera (3D) view, press U to enter Polygon Select Mode . Holding CTRL , select the three polygons that make up the front of our can. They will be selected in the texture editor as well. Press V with the mouse in the texture editor to enter translate mode, and then click-drag to move the island for the front of the Spam to the side. Do the same with the back, sides, top, and bottom of the can. It may be necessary to pan/zoom the view. This is done by pressing Z in the texture editor.
Once you have all the islands pulled out, you need to resize each to get rid of distortion. First, change your 3D/Camera view to textured so you can see your changes. Using the Scale tool, X in the texture editor, resize each piece along whatever axis is necessary to get the checkerboard's boxes to be square instead of rectangular. After you do this for each island, move them into a close as a square as you can, then select them all and scale them so that they all fit inside your square checkerboard clip.
Why? Texture coordinates are stored as a UV value, from 0,0 to 1,1 on the U and V axis. The clip represents this area, with the top left being 0,0 and the bottom right being 1,1.
|
You have now assigned every surface on your model a "piece" of the texture. Click the maximize icon on the top right of the texture editor. Use the pan/zoom tool (Z) to position the clip in the center to make it as big as possible while still being able to see the entire clip. Press Print Screen on your keyboard, then load up your favorite editing program (from here on in: Photoshop) and create a new image/paste the screenshot of your desktop into the program. Using the Crop tool, make yourself an image of only the clip area with the islands you arranged in it. Check to make sure the image is square with Image -> Image Size . Now we have the texture to work on.
Creating the texture is pretty much just a process of coloring in the islands with whatever you want that particular set of polygons to look like. I used this image of Spam as a base, by copy/pasting it into my texture and resizing it to fit inside the lines that define the "front" polygon. I then used the Eyedropper tool to select the blue color from the image, and painted in the rest of the sides with blue. A cool thing here is that your preschool teacher lied to you. It's perfectly OK to color outside the lines; anything outside the lines isn't assigned to a polygon and hence will not be viewed. I added some text that is too small to read on the "back" island, and colored the top and bottom with a gold color. Of course, how you design you skin and how much detail you put into is entirely up to you. Once you have the skin done, resize it. For something as trivial as a can of Spam, I resized the texture to 256x256, though for more detailed models you may need more pixels. Remember though, texture size affects the render speed in game, so don't use the largest texture size available just because you can. Save the texture and go back to XSI.
All textures in Half-Life 2/Source need to be in VTF format, so we will run the texture through VTEX and place the resulting file in half-life 2\ hl2\ materials\ models\ spam . We also need to create a VMT file so that the engine knows what to do with this texture. Using notepad, create a file called spam.VMT that contains this:
"VertexLitGeneric"
{
"$baseTexture" "models/spam/spam"
"$model" 1
}
This lets the engine know where the texture is relative to the materials directory and that it will be used for a model.
After that little field trip, we are back in XSI. Remember the Clip button in the texture browser? Click it again, and select Import Clip again. Browse to your texture, and hit OK. You should now see your islands lined up with your skins in the texture editor, and a textured model in the 3D/Camera view. But wait, before you go jumping for joy, you need to (semi)permanently affix the texture to your model. Press 3 to change XSI to render mode. Go to Get -> material -> phong. In the dialog box that pops up, click the little wrench icon across from color, then go down the menu to clips and select you texture. Your object is now textured.
Bones and Exporting
The prop needs at least one bone, as far as I'm aware, so, we're going to give it one. Press 2 to enter animation mode in XSI, then go to create -> skeleton -> Draw 2D Chain. In one of your 2D views, click twice inside the can of Spam do draw a bone. Right click to stop drawing the bone (you only need one), then select your can. Go to Deform -> Envelope -> Set Envelope. It will have you pick a bone, select the bone that you just created. Voila. The can of Spam now has a bone. It has come to my attention that you may simply skip this step, as studiomdl will add its own bone by default if the model has none.Time to move on to exporting.
Thanks to the Valve extension for XSI, we have a fairly simple export method. With your can of Spam selected, go to ValveSource -> Export SMD. In the dialog box, navigate to the hl2\modelsrc directory under the sdk_content folder in your steam directory. I used the name prop_spam for the model. Make sure the dialog says Model (.smd) for the file type, uncheck remove all unused bones (because it says so, I have no idea why.), then hit OK. Having exported the Reference SMD, you may believe that we need to export a Physics SMD and at least one Animation SMD. Good job for reading the SDK, but you're wrong. A physics SMD is a volume that defines the shape of the model while being convex. Well, our can of Spam is already convex, so we can just use the reference SMD as the physics SMD. Same goes for the animation, as it's a prop_physics and has no animations, we can use the reference SMD as the animation SMD as well. Isn't that great? Anyhow, now to move on to the wacky world of QC files.
Compiling
The good news is, we are done with XSI. The bad news is, we are starting on QC files. QC files have the reputation of being a pain, and they deserve it. I personally messed with this QC file for about 3 hours before I understood it. You see, it's easy to just copy and paste stuff out of a QC, but if you don't understand what it's doing, you are liable to make mistakes, so sit down and listen up.
These are the parts of our QC file, each line explained:
$modelname "prop_spam.mdl"
This tells the compiler what to name the final model.
$scale 1.0
This tells the compiler how big to make the model. If you accidentally made the model 10x bigger/smaller than it should be, this is a way to fix it. For now, leave it at 1.
$body "Body" prop_spam.smd
This tells the compiler what the reference model is. In this case, prop_spam.smd.
$sequence idle "prop_spam" fps 15 ACT_IDLE 1
This is the animation. Everything, even a prop_physics, needs at least one animation (even if it's static). The name of animation is idle, the name of the SMD that has that animation is prop_spam. The rest of that has to do with function calls/code, so best leave it alone.
$surfaceprop "metal"
This tells the metal can of Spam to act like metal. Pretty simple.
$keyvalues { "prop_data" { "base" "glass.small" } }
This sets the prop_data for the model. I believe that most of this determines how the object acts in the physics system. This value was the default of the QC file I messed with to create this one, and as it appears to work just fine, "if it ain't broke, don't fix it". If you really want to, prop_data.txt has a lot more types to use.
$cdmaterials "models\spam"
This is the path, relative to the materials directory, that we have our material in. In this case, it's going to be in the models\ spam subdirectory of the materials directory.
$collisionmodel "prop_spam.smd" { $mass 2.0 }
This line tells the compiler what to use for the physics volume, which is our model, because it's already convex. It also tells the physics system the prop's mass.
That's it for the QC file. All these lines should be in a file called prop_spam.qc in the same directory as your SMD files. Make sure that the SDK is currently set to be modding Half-Life 2 which is done through the Steam menu. Double-click the QC file, and if you have not already, tell it to open with studiomdl.exe in the sourcedk\ bin directory. You should see a command prompt appear for a brief time, then dissapear. If all went well, you now have a couple new files in half-life 2\ hl2\ models , including a MDL file. We now have a compiled model. The model will now show up in Hammer when you go to select a world model on a prop_physics. You can also load the model in HLMV to see it without putting it in-game.
Common Problems
- Modeling
- I keep selecting points behind the point I want to select
Try pressing U to turn on Ray-Cast polygon select, then click the Point button on the far right of the screen. This should make it so only one point gets selected at a time. Or you could just select your points in the 3D/Camera view from an angle so you know there is nothing behind it.
- Texturing
- When I try to move an island over, it just moves one point/part of the island instead of all three flattened polygons that make up the island.
Did you press I to make sure island select was on?
- Compiling
- The model exists, but it has 0 polys and I can't see it
You did not select the can of Spam before exporting it.
- The model is textured with a pink and black checkerboard
Either your texture is in the wrong directory, your QC file points to the wrong directory, or you didn't change your texture into a VTF/VMT.
- The model is deformed, almost square
You didn't freeze your model in XSI like I said to after the words "very important step".
Spam's Away
We are done now, and the model is safely in-game. It's a fairly simple process once you know how to do it. Just think, you gained the knowledge in one article that it took me a week to figure out. As usual, if you are confused about the article or have any questions for me, send me an email at jeffca51 at yahoo dot com, or post a comment here.
If you have any questions about modeling not related to this article, post them in the Softimage forum.
Symmetrical Editing With Softimage XSI