Things Named Veazie Places Named Veazie People Named Veazie The Site for All Things Veazie!

 

Creating a Basic HL2 Character Model Using XSI

 

By using a combination of the HL2 SDK model and the XSI v4.2 Man model, you can create your own basic character model ready for customization.

 

The purpose of this tutorial is to provide the basic steps and concepts for creating and compiling an HL2 character model which you can customize and animate.

 

This tutorial does not teach you how to create your own character mesh (it uses a default model supplied with XSI v4.2).

 

This tutorial does not deal with creating eyes or mouth animations used in HL2 models.

 
For this tutorial you'll need:
- the Half-Life 2 SDK installed.
- Softimage XSI Mod Tool v4.2 installed. You should have a working familiarity with most of the basic tools.
- the ValveSource addon installed with XSI so you can export model SMD files, and export and import weightmaps.
- an image editor such as Adobe Photoshop to modify images and export Targa (tga) format files
 
Outline of this tutorial:
- Setup files and directories for the character model
- Prepare the body texture for the model
- In XSI, open the HL2 male reference scene
- Import the XSI supplied Man model into the scene; scale it, position it and freeze it
- Export the HL2 reference weight map and delete the HL2 model
- Select the Man model and import the weight map
- Create a cluster for the head texture, get the facemap texture and adjust the UV coordinates for the head
- Export a model reference SMD file
- Edit the qc file for the model, compile the model and view it in the SDK model viewer.
 

Setup the files and directories for the character model

If you haven't done so, setup folders for the model and textures, preserve the original SDK HL2 model files and compile the SDK sample model as described in the tutorial HL2 Character Modeling - A First Step.
 

Prepare the Body Texture for the Model

Locate the texture file Char_UV_Texture.gif in your Softimage installation in the folder XSI_4.2_ModTool\Data\XSI_Samples\Pictures. The entire Man model is UV-mapped to this image.
Open the gif file in your image editor and size it to 1024x1024 pixels. Customize the costume as desired and save it in Targa format (tga extension) with the name Char_UV_Texture.tga to the folder sourcesdk_content\hl2\materialsrc\SDK\Models\Humans\Male.
Compile the Char_UV_Texture.tga file by dragging-and-dropping it onto your desktop vtex.exe shortcut.
Above is shown a portion of the Char_UV_Texture.tga that I used. For demonstration purposes, I overlayed a portion of the citizen_sheet.tga texture that can be found in the folder sourcesdk_content\hl2\materialsrc\models\humans\male to use with the new model. The texture file is well labeled, showing which parts of the texture are mapped to which parts of the Man model, and can be easily customized to create a custom costume for your character.
You can ignore the portion of the texture (the red area at the bottom-right) intended to be mapped to the head of the XSI Man model. Later in the tutorial, there are steps to demonstrate how a separate texture for the head can be added to the model.
 

Setting up the Reference Scene

 
Open XSI. Using File->Open, navigate to the folder sourcesdk_content\hl2\modelsrc\humans_sdk\XSI_scn_files and open SDK_Male_reference.scn.
Select the model and export the weightmap (ValveSource->WeightMap Export..). I created a WeightMaps folder under XSI_Samples, named the file sdk_male_reference and saved the file in that folder.
 

Import a Character Model Into the Scene

In the main menu, click File->Import->Model.. and select Man.emdl from the XSI_Samples\Models folder.
 

Scale The Man Model

The Man model is quite a bit smaller than the Male_06 model. You'll have to zoom out in one of the views to find it nestled between the feet of the Male_06 model.
Select the Man model (left-button drag over a portion of it).
In the next few steps, you'll attempt to match the Man polymesh as closely in position as possible to the Male_06 polymesh. By doing this, you can use the weightmap you exported to envelope the new mesh to the ValveBiped deformers (bones).
Click on the Scale button in the Transform panel. Enter 3.5 in each of the 3 axes fields. Click the Scale button again to deselect scaling.
 

Position the Arms, Legs and Feet of the Man model

Maximize the Front view and switch to Wireframe display (if needed). Zoom out and adjust the view so you can see the right arms of both models.
Select the Vertex Select Tool and select all the vertices of the Man model right arm by dragging a box from the shoulder area of the Man model out past the ends of the fingers. You should end up with the vertices in the arm selected as shown below.
Click the Rotate button in the Transform panel, and click the Global and Sym buttons. Click the COG to deselect it. All your model manipulations should be in Global coordinates for this tutorial. The Sym button will apply the same manipulations to the left arm as well. Nice, huh?
Hold down the alt key and click near the center of the right shoulder (at the point where the red and green indicators cross as shown below) to change the center of rotation to the shoulder area. With the scaling you applied, the Man and Male_06 shoulders should be pretty closely overlayed.
Release the alt key and position the mouse point over the blue circle to get the z-axis rotation cursor. Click-drag to rotate the arm down to a position close to the Male_06 arm angle.
Deselect rotation and deselect all the vertices (ctrl-shift-A).
Select all the vertices in the right leg (but none in the hip area). Select rotation, Global and Sym. Position the center of rotation near the top-center of the right leg and rotate the leg so the Man leg closely overlays the Male_06 leg.
Deselect rotation and deselect all vertices.
Select the vertices in the right foot of the Man model. Make sure you select all the vertices as shown below.
Select rotate, Global and Sym.
Press alt and click in the right ankle area to set the center of rotation for the foot. Release alt, position the mouse over the blue circle and rotate the foot into a more natural position.
Deselect rotate and deselect all vertices.
Select the Object Select tool (the button with the white arrow in the button bar above the views), select translate in the Transform panel, click on Global and turn off Sym.
Click on the y beside the translate button to select only the y axis for movement.
Click-drag the Man mesh up just a little so the bottom of the feet are even with the bottom of the Male_06 mesh.
Deselect translate.
You've finished setting up the reference position for the Man model, so, in the main menu, click Transform->Freeze All Transforms. This is a VERY important step! If you don't freeze the transforms (the rotations and translations) for the mesh, the model will not compile correctly and it'll look very messy or it may not compile at all.
 

Delete the Male_06 Model

We don't need the Male_06 model any more, so open up Explorer (press 8 or click on the Explorer button in the button bar), click the Male_06 node and press Delete.
 

Import the WeightMap to the Man model

Expand the Man node in Explorer and middle-click on the Man mesh name (it has the white mesh-like icon beside it) to select the mesh.
In the main menu, click ValveSource->WeightMap Import.. and select the weightmap file you exported earlier. Click Okay.
It may take a minute or so for XSI to apply the weightmap to the Man mesh. Be patient. When I do it, a portion of the screen turns white. If that happens to you, that's okay. XSI is just busy applying the weights for each bone to the surrounding mesh.
WeightMaps are factors applied to each vertex in the model. They determine how much a particular vertex moves when the bone or bones that it is weighted to move.
You should now have a WeightImportProperty in the scene and the Man mesh is highlighted with colors indicating which portions of the mesh are weighted to which deformers.
 

Finishing up and Saving Your Work

Expand the Man polygon mesh node (the node with the white mesh icon), expand the Polygon Mesh node (the node with the icon of a P in a diamond) and check to see if there are any "unfrozen" operators (e.g., labeled MoveComponent[6]. If so, click on the operator to expand it, right-click on one of the entries and click Freeze to clear the operators from the stack.
As shown below, click on MoveComponent [6] and the node will expand to show some Move operators still on the stack.
Right-click on one of the MoveComponent entries (e.g., MoveComponent[5] as shown below) and click Freeze.
The operators will be removed from the stack and the MoveComponent node will disappear from the Explorer tree.
Close Explorer and save your scene with a name of sdk_custom_male or something equally recognizable.
 

Checking the model

To make sure everything you've done to this point is correct, follow the steps in the section Exporting the SMD and Compiling the Model below. Make sure your model compiles correctly and (as ugly as it is) appears okay in the ModelViewer.
 
As you can see, the default texture for the Man model that XSI supplies includes a mapping for the head which is just the color red. Not very exciting. You'll now learn how to setup a separate texture just for the head of the model.
 

Create a Polygon Cluster for the Head

First, you must create a cluster in XSI for the portion of the mesh to which you can apply a separate texture.
With the Man model selected, press y to activate the Polygon Select tool. With this tool, you can drag a box around portions of the model to select all the polygons, including the backfacing polygons, that lie entirely within the box.
Drag a box around the entire head and part of the neck to select all the polygons in the head.
You may have to use the RaycastPolygon Select Tool (press u or click the button to the right of the Object Select button in the button bar with the icon of a single polygon). Click on any polygons as needed to make the selection correct as shown below.
When all the polygons in the head have been selected, in the main menu, click Edit->Create Cluster to create a cluster of polygons selected from the Man polygon mesh.
This doesn't change the mesh itself. It creates a new object (a cluster) referencing a set of polygons from the mesh to which materials other than the default scene material can be assigned.
Open Explorer and expand the polymesh node and the cluster node.
Double-click on the Cluster named Polygon and give it a meaningful name by typing in tex_head in the name field of the property box.
Close the property box and the Explorer panel.
 

Get a New Texture for the Head

With the cluster selected, in the main menu, cllick Render->Get Texture->Image. Click Yes to make a local copy of the material.
In the dialog box, click New and New From File... to pick a texture for the cluster.
In the file-selection box that pops up, navigate to the hl2\materialsrc\SDK\Models\Humans\Male folder and select sandro_facemap.tga, the texture used for the Male_06 model. You'll use that same texture to learn how to map a texture to a cluster.
You don't have to select a texture projection for the new image because the entire Man model is already UV-mapped. However, you'll have to change the mapping of head vertices because things look pretty bad at this point.
The sandro_facemap texture you selected is a wraparound type texture. The entire head from neck to top of head and from front to back appears in one texture.
Close the dialog boxes.
 

Change the Texture Mapping of the Head Cluster, Point by Point

Select the tex_head cluster. If necessary, open Explorer and middle-click on the tex_head cluster to select it.
Open the Texture Editor (I'll be calling it "texed" - pronounced tex-edd) by pressing alt-7.
What you see are the existing UV coordinates of the vertices in the cluster mapped onto the new texture.

It looks like only the right side of the head cluster has been mapped. Actually, the UV coordinates for the left side have been mirrored and overlay the right side coordinates. That is, any part of the image mapped to one side of the head will also be mapped to the other side in reverse. When the mapping is correct for the right eye, the eye portion of the image will texture the left eye of the model as well. This should become clearer as you adjust the coordinates.

With the mouse over the texed and all the points selected, press v or click on the t button in the texed to select the translate tool.
Drag the coordinates to the left and position the coordinates of the ear somewhere close to the ear on the left of the image.
As a first approximation, it's not too bad.
Obviously the ears needs work and the texture around the eyes needs badly to be repositioned.
I'm not going to lead you through a complete remapping of the head. I'll demonstrate how to move a couple of the points and leave the rest to you to practice on.
Tips for UV Mapping:
  The idea is to select a point in the texed, note where it appears on the model and move the point to a similar position on the image. For example, move the point at the corner of the eye on the model to the corner of the eye in the image.
  Another very important tip: always deselect all points in the texed (ctrl-shift-A) before selecting another point. If you forget to do this, you'll drag several points around at once and really get things messed up.
  Another tip: always select a point by dragging a box around it. Don't click on a point to select it. Each of the "points" in the texed is really several points overlayed, one on top of the other. By dragging over the point, you'll select all the overlayed points and move them in unison. If you click on a point, you may not select all the overlayed points and, when you move the selection, you may leave a point or two behind.
  Don't move any points too far. Iterate up and down and back and forth, moving each point just a little.
  Don't let any lines cross. That will cause confusion.
  When you move a point in the texed, watch the effect on the texture on the model to help you decide where the point on the image should go. The texture on the model is updated realtime so you can see the immediate effect of moving a point in the texed.
In the texed, zoom in on the area below the mouth in the image. Press z to select the pan tool, middle-click to zoom in, left-click to zoom out.
Press alt-shift-A to deselect all the points.
Drag-select the point in the middle at the bottom right.
Note that this is the point on the model (zoom and pan in a Camera or User view) at the middle of the throat just under the chin.
Press v (translate) and drag the point toward the middle of the image where it you think "just under the chin" is.
Press v again to deselect the translate tool and deselect all points in the texed (ctrl-shift-A when the mouse pointer in the texed view). On the model, it's on the underside of the chin.
In the texed, select the point just above the one you just moved.
In the texed, move that point to a position directly above the first point you moved.
Work your way up toward the mouth, moving points on the image to approximate the location on the model.
You may find points, which when selected, show colored edges around an "opening" in the map coverage. This indicates that two or more points which should be overlayed, are not overlayed. Notice, in the case shown below, that the two selected points in the texed map are the same selected vertex on the model.
You may have to select and deselect points around the perimeter of the "opening" in the map to find which points need to be overlayed.
Move one of the points (it doesn't matter which one) directly over the other point.

Drag-select both points and click on the Heal button to overlay the points exactly.
 
There are two more points in this example that need to be healed.

Move one of the points over the other, drag-select them both and click the Heal button.
There are a couple of points that, when you select them in the texed, you won't see them selected on the model. There's a point in the middle of the nostril that's up inside the model and a couple similar ones around the ear and the back of the ear. Move the nostril point to the dark area in the middle of the nostril in the image, etc.
Also, the model has no eyeballs. Remap the points around the eyelids as shown below so that the eye portion of the image doesn't appear on the model.

Shown above is my final mapping, details of the mapping around the ear and details of the mapping around the eye.
When you're satisfied with your progress (or you get too tired of it), save your scene file and see what the compiled model looks like.
Note: You selected the sandro_facemap for the head texture. The compiled texture (the vmt and vtf files) should already be in the half-life 2\hl2\materials\SDK\Models\Humans\Male folder. When (or if) you retexture your custom model, remember to compile the texture and place it in the correct folder in the game directory.
 

Exporting the SMD File to be Used for Compiling

Click ValveSource->Export SMD...
Untick the Remove All Unused Bones option. I'm not sure if it has any effect but it doesn't seem to hurt and a couple of articles on the web recommend it. [shrug]
Select Model as the type and click the "..." button beside the filename field. Save your file with a name like sdk_custom_male in the sourcesdk_content\hl2\modelsrc\humans_sdk\Male_sdk folder.
Close XSI. Having XSI open may interfere with the operation of ModelViewer. I think it may be because both programs use an OpenGL context for rendering and sometimes there are problems having several contexts open simultaneously.
 

Preparing the QC File for The Model

In the folder sourcesdk_content\hl2\modelsrc\humans_sdk\Male_sdk folder, open the file Male_06_sdk.qc in Notepad (or other ASCII editor).

For the editing, refer to the sample file shown below. If you named the SMD file as suggested and saved it to the Male_SDK folder, the sample file should work.

Delete the lines beginning eyeball, eyelid, mouth and flexfile as this model doesn't use those (perhaps a later tutorial). Delete the LOD sections as Level of Detail files have not been created for this model. Add two lines:

$surfaceprop "flesh"
$mostlyopaque

Change the $alwayscollapse line to "Man.Man" from "Male_06."

Change the model name and smd filename to the name you saved it under.

You should end up with a file that looks similar to the following:

/*
==============================================================================

sdk_custom_male

==============================================================================
*/


$modelname sdk\Humans\sdk_custom_male.mdl
$cdmaterials sdk\models\Humans\Male

//start eye/face data
$eyeposition 0 0 70

// head controllers
$attachment "eyes" "ValveBiped.Bip01_Head1" 0.043 -4.2197 67.5554 absolute
$attachment "mouth" "ValveBiped.Bip01_Head1" 1.00 -6.30 0.00 rotate 0 -80 -90


$model sdk_custom_male "sdk_custom_male.smd"{
$include "../bodyrules_xsi.qci"

}
//end eye/face data

$surfaceprop "flesh"
$mostlyopaque
$include "../standardhierarchy.qci"
$alwayscollapse "Man.Man"
$alwayscollapse "XSISceneRoot"


$proceduralbones "../male.vrd"

$pushd "../male_animations_sdk"
$include "../male_animations_sdk/male_shared_XSI_sdk.qci"
$include "../male_animations_sdk/body_poses_lean.qci"
$include "../male_animations_sdk/WeaponAnims_shared_sdk.qci"
$popd

$include "hitbox.qci"
$include "ragdoll.qci"

Save the file as sdk_custom_male.qc in the Male_sdk folder.
Storing multiple model files in the same folder is not a problem. I do it on purpose in this tutorial to take advantage of the ragdoll and animation files already there.
 

Compiling the Model

Drag and drop the sdk_custom_male.qc file you just saved onto your studiomdl desktop shortcut.
It should compile and produce a bunch of files in the half-life 2\hl2\models\sdk\Humans folder with extensions of vtx (3 of them), mdl, phy and vvd.
If not, double-check that your qc file looks like the sample above. If that's okay, you can open a command prompt window, change to the sourcesdk\bin folder and run studiomdl with the command line:
studiomdl "c:\program files\valve\steam\steamapps\[your logon]\sourcesdk_content\hl2\modelsrc\humans_sdk\male_sdk\sdk_custom_male.qc"
Include the quotation marks. Look at the studiomdl output for errors. Correct them and try again.
One time in the past, I somehow missed a right toe. I corrected it by starting from scratch (importing the scene file, etc.) and paid close attention to selecting all the vertices in the arm, leg and foot before I rotated them.
When your model compiles successfully, open ModelViewer, Load Model.. and select your model from the sdk\Males folder to view it. It should appear with your custom body texture and head texture (if you applied one).
He's kind of blocky (the Man model from XSI is very low poly) and your model won't have eyes yet, just empty holes. You'll add eyes in the next tutorial.
You can now use your custom model in HL2 maps by inserting a generic_actor entity and selecting your model as the World Model property of the generic_actor.
 

Continuing on..

You can change the texture of the body of the model (or portions of it - shirt separate from the pants, etc.) by selecting polygons from the model in the appropriate arrangement and creating a cluster. With the cluster selected, click Render->Get Texture.., etc., to apply another texture to that portion of your model.
You can translate or scale portions of the model to change proportions. The Man model has pretty anemic arms and legs. Rescale portions of the model or manipulate vertices to build some better looking muscles.
If you want to smooth the surface of the model, you can split polygons to reduce angulation. Be sure to envelope the new points to the right deformer and map the new points to the correct place in the correct texture.
You can add animations to the model as described in other tutorials. For the scene used in this tutorial, you'll have to click View->Unhide All Objects to see and use the animation controls. Select and hide the eyeballs that are still part of the scene. They can be used later.

 


updated 17-Sept-2005