Gallery Tutorials Resume Links
 
Last edited: 09/23/08

XSI to Source Engine
Level: Advanced

Software required:
Softimage XSI 6 (Mod Tool)
Valve Source Addon for XSI. (This can be found in sourcesdk/xsi)
Adobe Photoshop or GIMP
A Source Engine game (example: Team Fortress 2)
GUIStudioMDL
Photoshop VTF Plug-in or VTFEdit

Things to know

This tutorials requires some working knowledge of XSI.

Terms:

SMD -
Studio Model Data - The file format exported from XSI which stores 3D geometry data used to compile an MDL file.
QC -
Stands for Quake C. A text file that controls the process of compiling .SMD source files into the final .MDL model that is read by the engine.
MDL -
The extension for Source's proprietary model format, which holds structure, animation, bounding box, LOD, and material information.
VTF -
Valve Texture Format - Proprietary image format used by the Source engine. One or more VTF's are used to create a Material, which is applied to a model using a VMT file.
VMT -
Valve Material Type - A text file which contains all of the information needed for Source to simulate the surface visually, aurally, and physically.

For more information on using the Source SDK, visit the Valve Developer Community.

Start:

Open XSI.

The following link includes an object file and textures to use for this tutorial.

xsi2srcfiles.zip 360KB

Import the Object file into an XSI scene. Open a Texture Editor window, and verify the mesh has texture UV coordinates. All mesh files must have UV coordinates in order to properly display textures in the game engine.

Obj_Scene

A texture needs to be applied to the mesh in XSI.

In XSI, select the object, and apply a new material. Get>Material>Phong. A Material property window appears.

mat_phong

In the diffuse category, click the connector to the right of the Color sliders, and select Image from the menu. From the Image window, select New>From File. Use an image with a name that is easy to identify. For this tutorial, use the "detonator.png" image included above. The name of the texture file "detonator" will be saved in the exported SMD file, and used after compiling to locate the correct Valve Material by name. It is important to know that the name of this file is important, and not the file extension or any additional images used in XSI.

mat_img

Save the scene.

obj_tex

Before exporting geometry, it is a good idea to set up a working folder to keep all custom content organized.. Create a new folder under the Steam directory along side the game installs. For example: "C:\Program Files\Steam\steamapps\*username*\". Give the folder a descriptive name such as "Custom Props", or "New Models", etc.

Steamapps

It is best to also create a subfolder for the specific prop you're working on. Then a directory should exist located here:

"C:\Program Files\Steam\steamapps\*username*\Custom Props\Detonator\"
(create desktop shortcuts to save time)

In XSI, select the mesh object. From the main toolbar, under ValveSource, select Export SMD...
Save the SMD file to the new folder created above, with the name of the object, and the suffix "_ref". This has no function other than helping to organize the Reference mesh from the Animation SMD files, but good practice.

exportsmd

Save the scene, and close XSI.

It's time to begin writing instructions for compiling the SMD file to a format the engine will read. For this, a QC file is needed. It is often recommended to copy an existing prop QC file to use as a base template. The next few lines will explain how to create one from scratch.

Open the folder where the SMD file was saved. Right click in the window, and create a new text document. Name it detonator. Right click, and view the properties of this text file. The file type still shows as "Text Document". In the Windows Explorer window, select Tools > Folder Options. Under the View tab, uncheck "Hide extensions for known file types". You can now rename "detonator.txt" to "detonator.qc". Click yes for the window that pops up. The file is now shown as a QC file. This file will be opened with Notepad, or any preferred text editor.

In the QC file, paste this information (note the use of "/" for system directories, instead of "\"):

//name of the MDL
$modelname props_explosives/detonator.mdl
//SMD file used as a reference model
$body "Body" "detonator_ref.smd"

//size in game relative to original mesh scale
$scale 1.0
//used to define this mesh as a model that will not be controlled by physics or animation
$staticprop
//the sound produced when the model is collided with
$surfaceprop "metal"
//location of the material file
$cdmaterials "models/props_explosives/"
//the animation sequence of the model (idle is the default motionless sequence for the model)
$sequence "idle" "detonator_ref" loop fps 1
//collision information, uses reference model
$collisionmodel "detonator_ref.smd"
{
//Mass in kilograms
$mass 35.0
$convex
}

Lines that begin with "//" are comments, providing explanations of the following lines, and are not read by Source.

Start Steam. Steam must be running in order to compile MDLs. Minize the window for now.

Under the steamapps directly, navigate to "sourcesdk\bin\orangebox\bin". This is where GUIStudioMDL should be installed. It's important to install it under "orangebox\bin" when creating content for any OrangeBox games, i.e. Episode Two, Team Fortress 2, Portal. GUIStudioMDL is simply a front end for the "studiomdl.exe" found here.

Run GUIStudioMDL. For SDK version, select Orange Box. For Target Mod, select "Team Fortress 2". From the File menu, load the newly created QC file. Press Compile.

mdl_error

Some text will appear in the window. Observe the last lines begins with "Error opening...". This is a common error. The reason for this error is simple. In order to compile a MDL to a specified folder in the game install, that directory must first be created manually. Observe the first line of the QC file:

$modelname props_explosives/detonator.mdl

Navigate to "steamapps\*username*\team fortress 2\tf". Create a folder named "models". In that folder, create a subfolder named "props_explosives". This folder is simply for organization, and can be given any name, as long as it is the same name specified in the QC file. Any custom mesh exported to Source must be converted to a location under the "models" folder of the game install. Now when Compile is pressed in GUIStudioMDL, the MDL file will be placed in this folder, which the Source Engine can locate..

mdl_done

If all went well, close GUIStudioMDL. Importing the mesh is complete.

Restore the Steam window. Under the Tools tab, launch the Source SDK, and set Engine Version and Current Game to The Orange Box and Team Fortress 2, respectively.

current game

Launch Model Viewer. File>Load Model... Find the "props_explosives" folder, and open the detonator.mdl. If all has gone well up to this point, the model will be shown in the viewport.

viewer no texture

Success! Perhaps? Why is the model black and purple? Because the material for this model has not been created, so Source displays a default texture until it is found.

As of this writing, current generation games often render object materials using 3 images: Color (often Diffuse or Albedo), Normal Map, and Specular. In Source, the Specular Mask can be added to the Normal Map image as an alpha channel, and called from the Valve Material Type using a command. The VMT is a text file, much like the QC file, which instructs source on how to display images as a material on a model. A Material is a collection of images and commands used to render a surface on a mesh. For example, a model's material can be reflective, glowing, transparent, etc.

Previously, a folder was created under the game install directory named "models". Beside "models", create a new folder named "materials". Within this new folder, create a subfolder named "models". In that folder, create a subfolder named "props_explosives". This folder is where the VMT and VTF files need to be saved.

"C:\Program Files\Steam\steamapps\*username*\team fortress 2\tf\materials\models\props_explosives\"

Create a new text file named "detonator.vmt" in the same method the QC file was created earlier, or copy an existing file. Remember, the name of the VMT should be the same name as the image used in XSI. Paste this information into the VMT, and save.

"VertexLitGeneric"
{

//default color texture-----
"$basetexture" "models/props_explosives/detonator_c"

//specifies normal map image-----
"$bumpmap" "models/props_explosives/detonator_n"

//alpha channel of normal map contains specular map info-----
"$normalmapalphaenvmapmask" 1

//sets cubemap usage for specular in game or image file-----
"$envmap" "env_cubemap"

//Phong parameters (all optional OrangeBox commands), gives great results for rendering reflections-----
"$phong" "1"
"$phongexponent" "5"
"$phongboost" "6"
"$phongfresnelranges" "[0.5 0.5 1]"
"$halflambert" "1"
"$rimlight" "1"
"$rimlightexponent" "1"
"$rimlightboost" "1"

//created using StudioMDL-----
"$model" 1

}

This material instructs Source on where to find the Color and Normal Map images for the model, and also to use the Alpha Channel of the Normal Map image as the Specular. The specular values will use the "env_cubemap" entity in game to display reflection. Other commands can be added for a more complex shader.

In Photoshop, open the "detonator_c" image and save it in VTF format, using the VTF Plugin (File>Save As...>. In the VTF Options window, select Compressed Texture as the Template. Save to the folder where the VMT file is located.

vtf_color

Open the "detonator_n" and "detonator_s" images. Select all of the specular mask image (Ctrl-A), and copy it (Ctrl-C). Open the Normal Map image channel's tab. At the bottom of the window, press "Create New Channel". A new "Alpha 1" channel is created. Click on the new channel, and paste into it (Ctrl-V). The alpha channel of the Normal Map is now the Specular Mask.

spec mask

Save the image in VTF format to the same folder as the VMT. In the Save As window, remember to check "Alpha Channels" under Save Options. In the VTF Options window, select "Normal Map With Alpha" as the Template. Press OK.

vtf_normal

(If Photoshop is not used, VTFEdit can convert images to VTF format.)

Open the Model Viewer as before, and Load the model once again. Congrats! The model is now visible inside the Source Engine.

viewer_tex

The model can now be placed in a level using Hammer.

Information on getting started with Hammer can be found here. http://developer.valvesoftware.com/wiki/Your_First_Map

To summarize, create a simple room using the Brush tool. With the Entity tool, add an "info_player_start" or "info_player_teamspawn" (TF2). The room also needs a "light", and an "env_cubemap" entity placed in the center. Once that's complete, add a "prop_static". Double-click on the "prop_static" box in the camera view to open its properties. Highlight "World Model", and Browse for the folder that holds the model. The model with appear shiny in editor, but will appear as intended once the map and cubemaps are built.

mdl_browse

Press OK, and Apply. Once all necessary entities are placed, save the Map as "cp_mytestmap". From the File menu, Run Map. After compiling, the game will launch and start the level. Once the level loads, press ` to bring up the developer console (must be enabled in Options Menu). Type "buildcubemaps". A series of images will quickly appear on the corner of the screen. Type "map cp_mytestmap". The level will reload with all cubemaps functioning, giving objects with Specular Masks a nice reflective surface.

in game

 
Any trademarks mentioned on this website are the property of their respective owners.
All content on this website, unless stated otherwise, is Copyright © 2001-2008 Will Cox. All rights reserved.