Porting GoldSrc content to Source: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m ({{note}} & char fixup)
(massive overhaul, editing, etc.)
Line 1: Line 1:
{{tutpov}}
Porting a [[Goldsource]] model to the Source engine is a short process. For best results, have all original source content ready for the model: original 3d package file, textures, and [[.QC]] file. [[SMD]] files may also be useful if the original 3d package file is unavailable. For help with obtaining such files, see
{{cleanup}}
[[Category:Modeling]]
Porting your current [[Goldsource]] .mdl to the Source engine is a short process. For this process, I'm going to assume that you have all the original source content for the model. I'm referring to the original 3d package file, textures and .qc file at the bare minimum. If you have the .smd files, this could save you some time but not in every case, and if you have the original 3d source, then you can always re-export new .smd's. If you do not have the source content, don't loose hope. See the end of this document for instructions on how to decompile your .mdl file then start from the beginning.


=Overview=
For the most part, porting models is straightforward: Set the [[VPROJECT]] properly, convert old textures to [[VTF]] format, tweak .QC file to include new Source syntax, and then compile the new content into a new Source model file.


For the most part, porting your models is brainless "robotmonkey" work. It's a process with straightforward steps that someone needs to push buttons to make happen. First we'll make sure your VPROJECT is set properly, and then convert your old textures to Source materials. Next tweak your .qc file to some new Source syntax, and then compile the new content into your new Source .mdl.
=Set VPROJECT=


=Step 1. VPROJECT=
{{main|[[Game Directory]]}}


The first thing to take care of is your VPROJECT environment variable. This variable is referenced by a handful of Source tools, 3 of which you will use to port your models. Studiomdl and Vtex both use VPROJECT to know where to place your compiled models and materials respectively. Half-Live Model Viewer (HLMV) uses VPROJECT to find the materials your model uses. If you have already set your VPROJECT, skip to step 2.
The VPROJECT variable is referenced by several [[Source SDK]] tools: basically, it directs applications where to find or place compiled models (.MDL) and materials (.VTF). [Studiomdl]] and [[Vtex]] both use VPROJECT to place compiled models and materials in the correct directory. [[Half-Live Model Viewer]] (HLMV) uses VPROJECT to find model materials. To set the VPROJECT (Current Game), use the [[Source SDK launcher]] or [[The Game Directory#Using VConfig to set the game directory|VConfig.exe]].  


To set your VPROJECT('''Current Game'''), you can use Source SDK launcher or [[The Game Directory#Using VConfig to set the game directory|VConfig.exe]].
=Convert old textures to new materials=


=Step 2. Convert old textures to new materials=
{{seealso|[[Material system]]}}


In [[Goldsource]], .bmp textures were built right into the .mdl. However in Source, we now author our source files (diffuse, specular, bumpmaps, etc) as .tga files then use the tool Vtex to convert the .tga into a .vtf, which is referenced by the .mdl but not compiled into it. In addition to .vtf's, there are .vmt files. These files are just text files that define the attributes of your material. The primary things in the .vmt are the pointers to the different versions of the texture, namely the diffuse, specular, and bump. However there are also other arguments that can be set. For more information, see the [[:category:Material System|Material System]] documentation in the SDK.
In the Goldsource engine, .BMP textures were compiled into the .MDL file. However in the Source engine, developers export textures as .VTF files, which are simply referenced and not actually compiled into the .MDL file.  


Before we compile any .tga's, I should point out that you should create a 'materialsrc' and 'materials' directory inside your mod directory. For example <code>C:\MyMod\materialsrc</code> and <code>C:\Program Files\Valve\Steam\SteamApps\SourceMods\MyMod\materials</code>. The 'materialsrc' directory is where you should keep all of your original source content (your .tga's). The materials directory is where Vtex will output all your .vmt's and .vtf's to. Of note is that if you create a subdirectory in the 'materialsrc' directory and also have that directory mirrored in your 'materials' directory, when you compile a .tga from that directory with Vtex it will automatically put the .vmt and/or .vtf into that directory. So for example if you make both <code>C:\MyMod\materialsrc\player</code> and <code>C:\Program Files\Valve\Steam\SteamApps\SourceMods\MyMod\materials\player</code>, when you run Vtex on a file inside the materialsrc\player directory, the .vmt/.vtf will be exported into the materials\player directory. If you are not using the –mkdir Vtex argument, and the directories are not mirrored, you will get an error when using Vtex so make sure you have equivalent directories if you run into a problem.  
Originally, in the preliminary release of the Source SDK, developers were confined to using the included command-line exporter [[Vtex]] to compile materials. Since then, a variety of community produced tools provide Windows-friendly GUIs and interfaces, batch conversions, and texture previewing. [[VTFedit]] is highly recommended; though there are also [[Vtf#Utilities|other tools available]]. This tutorial will assume that the user is using Vtex.


I'd also like to preface with a few tool tips in reference to Vtex that I use to make my life a little easier. The first is a shortcut to Vtex that will create a .vmt for you, the second is a quick way to re-compile a .tga assuming you already have a .vmt for the material.
{{main|[[Creating a Material]]}}


Tip #1 Shortcut for Creating NEW materials
First, convert all old texture files to .TGA format, using Photoshop or a similar image editing application.


# Create a shortcut to vtex.exe on your desktop. Vtex.exe is located in your SourceSDK\bin directory.
# Create a shortcut to vtex.exe on your desktop. Vtex.exe is located in the SourceSDK\bin directory.
# Right-Click the shortcut and select the 'properties' option.
# Right-click the shortcut and select the "Properties" option.
# In the "Target" box, add "-mkdir -shader vertexlitgeneric" after vtex.exe with a space between them.
# In the "Target" box, add "-mkdir -shader vertexlitgeneric" after vtex.exe with a space between them. Click OK.
# Click OK.


You should use this shortcut whenever you need to convert a texture to a material that you have never converted before. The argument "-mkdir" will automatically create the materialsrc directory you're compiling from in the materials directory if you have not already done so. The argument <code>-shader VertexLitGeneric</code> will tell Vtex to automatically make you a new .vmt for your .vtf that points to the .vtf as the diffuse texture.
Use this shortcut when converting new materials by dragging each .TGA file onto the desktop shortcut itself. The argument "-mkdir" will automatically create the materialsrc directory. The argument <code>-shader VertexLitGeneric</code> tells Vtex to automatically make a new .VMT that points to the .VTF as the diffuse texture.


{{note|The VertexLitGeneric shader is only used for models; it should not be used for sprites or brushes. Check the [[:category:Material System|Materials]] documentation for more info.}}
{{note|The VertexLitGeneric shader is only used for models; it should not be used for sprites or brushes. Check the [[:category:Material System|Materials]] documentation for more info.}}


Tip #2 TGA to VTF right-click shortcut
=Export .SMD files=
 
# Open a Windows Explorer window (Windows key + E).
# Go to Tools > Folder options.
# Select the "File Types" tab and scroll down until you see the TGA extension.
# Click TGA so that it is highlighted.
# Click the "Advanced" button at the bottom of the panel.
# You should now see the "Edit File Type" panel.
# Click the "New..." button.
# In the "Action:" box type "TGA to VTF".
# Now click the "Browse..." button and locate your vtex.exe file. (It will be in "bin" directory wherever you have installed SourceSDK. For example <codeC:\Program Files\Valve\Steam\SteamApps\username\sourcesdk\bin</code>)
# The "Application used to perform action:" box should now read something like "C:\Program Files\Valve\Steam\SteamApps\username\sourcesdk\bin\vtex.exe "%1"".
# Click in the little box next to "Use DDE".
# In the "Application" box type "vtex".
# In the "Topic" box type "System".
# Hit OK on all the panels to accept the changes.
 
You can now right-click on any .tga file that you have an existing .vmt for and select the "TGA to VTF" option and Vtex will recompile your texture. This is useful for when you make changes to a texture you have previously compiled.
 
Now to convert your textures, we can use our new tools to save us some typing in a DOS window.
 
# Save all your .bmp's as .tga's with your favorite image editing application into their appropriate materialsrc directory.
# Drag your .tga onto the new Vtex desktop shortcut you've created.
# Do this for all the textures for your model.


{{note|For a much more in depth explanation of materials and their options, see the [[:category:Material System|Materials]] documentation.}}
{{seealso|[[Model Creation Overview#.SMD_files|Model Creation Overview]]}}


=Step 3. Tweak the .qc file=
If the original 3D model file is lost, use an SMD plug-in (e.g. Valve Addon for Softimage|XSI) and import the .smd directly for editing.


For the most part old .qc files will work with the new Studiomdl, however there have been a few syntax changes that you will need to implement in order for the model to build correctly.
=Modify .QC file=


* $modelname now works in conjunction with your VPROJECT and automatically assumes a directory output location of your VPROJECT + a 'models' directory. For example <code>C:\Program Files\Valve\Steam\SteamApps\SourceMods\MyMod\models</code>. So if your were to set your $modelname to "player\myplayer.mdl", Studiomdl will compile the model and write it to <code>C:\Program Files\Valve\Steam\SteamApps\SourceMods\MyMod\models\player\myplayer.mdl</code>. Of note is that Studiomdl will not make directories for you, nor does it have a –mkdir argument so you will have to make sure the directory that you're writing to already exits before you start the compile.
{{main|[[.QC]]}}
* Replace $cdtexture with $cdmaterials. $cdmaterials also uses your VPROJECT and assumes the output directory to be your VPROJECT + a 'materials' directory. So for example <code>C:\Program Files\Valve\Steam\SteamApps\SourceMods\MyMod\materials</code>. As a rule of thumb we break our material tree up based on what the material is being applied to. In this case a model. So keeping the same example as in the $modelname step above, you could set $cdmaterials to "models\player" and the model will look for its materials in the directory <code>C:\Program Files\Valve\Steam\SteamApps\SourceMods\MyMod\materials\models\player</code>.


=Step 4. Collision Model (aka Physbox)=
While old .QC files will work with the new Studiomdl, there have been syntax changes for Source models to compile correctly.


A "Collision Model" (aka "Collision Hull," "Physics Hull," or "Physbox") is the simplified mesh that defines how the model will interact with the world when it is being physically simulated. This document will not cover the details of creating a physbox, but I would like to quickly discuss if you need to create one by hand or have Studiomdl create one for you.
* <code>$modelname</code> now works in conjunction with VPROJECT and automatically assumes a directory output location of VPROJECT + a 'models' directory. For example: <code>C:\Program Files\Valve\Steam\SteamApps\SourceMods\MyMod\models</code>. So if <code>$modelname</code> were set to "player\myplayer.mdl", Studiomdl will compile the model and write it to <code>C:\Program Files\Valve\Steam\SteamApps\SourceMods\MyMod\models\player\myplayer.mdl</code>. Note that Studiomdl will not create new directories, nor does it have a –mkdir argument, so make sure a directory already exists before compiling.
* Replace <code>$cdtexture</code> with <code>$cdmaterials</code>. <code>$cdmaterials</code> also uses VPROJECT and assumes the output directory to be VPROJECT + 'materials' directory. For example: <code>C:\Program Files\Valve\Steam\SteamApps\SourceMods\MyMod\materials</code>. Break the material directory tree up based on context - in this case, a model. Keeping the same example as in the <code>$modelname</code> step above, set <code>$cdmaterials</code> to "models\player" so that the model will look for materials in the directory <code>C:\Program Files\Valve\Steam\SteamApps\SourceMods\MyMod\materials\models\player</code>.


Studiomdl will create a physics hull for you if you do not specify one, however it will do a quick and dirty job of it. It will not "vacuum seal" the model. It will connect all the furthest points of the model together directly.
=Create a Collision Model (Physbox)=


To demonstrate this, imagine looking down on your model and that it is shaped like a +...
{{seealso|[[Physics and Ragdolls]]}}


[[Image:Phys demo3.jpg|Phys demo3.jpg]]
A "collision model" is the simplified mesh that defines how the model will interact with the world when it is being physically simulated. This document will not cover the details of creating a physbox. While Studiomdl will create a physics hull if one is not specified, the result will be extremely simple. It will not "vacuum seal" the model; it will simply connect all the furthest points of the model together directly. To demonstrate, imagine looking down on a model and that it is shaped like a plus sign.


You've deemed that it must have a correct physbox because it is going to be seen frequently reacting with the world and/or player, thus needs to bounce and spin correctly. So you want your physbox to resemble something like this, the red lines...
The most correct collision hull would resemble the plus sign.


[[Image:Phys_demo2.jpg]]
[[Image:Phys_demo2.jpg]]


However if you were to let Studiomdl create the physbox for you, it would create a mesh that connected all the most extended parts directly. Like this...
The automatically generated collision hull would connect all the most extended parts directly.


[[Image:Phys_demo3.jpg]]
[[Image:Phys_demo3.jpg]]


In some cases, that's ok. If the object is insignificant, or is rarely used in some dark corner, etc. However if this example object were a revolving door, then this physbox would be unacceptable. For more information, see the "Physics" section of the modeling documentation.
In some cases, it is acceptable if the object is insignificant or does not interact with the player or the game world. However, if the example object were a revolving door, then this physbox would be unacceptable.  


=Step 5. Run Studiomdl to compile the model.=
=Compile the Model=


The actual process of compiling hasn't changed outside of Studiomdl using your VPROJECT. The following steps can make the job a little easier though by associating all .qc files with Studiomdl so that whenever you double-click them, they will automatically be compiled. If this isn't something you would like, then skip it and run Studiomdl by any method you prefer. See the [[:category:Modeling|Modeling]] documentation for more information on Studiomdl.
{{main|[[Compiling Models]]}}


To associate .qc files with Studiomdl for double-click compiling:
The actual process of compiling hasn't changed outside of Studiomdl using VPROJECT. To associate .QC files with Studiomdl for double-click compiling:


# Open a Windows Explorer. (Windows Key + E)
# Open a Windows Explorer. (Windows Key + E)
Line 103: Line 76:
# Close the "Folder Options" panel with the "Close button.
# Close the "Folder Options" panel with the "Close button.


You should now be able to compile your model as a Source model by simply double-clicking the models .qc file.
=Check the Model with the Half-Life Model Viewer=


=Step 6. Check your new source .mdl with Half-Life Model Viewer=
Find the [[Half-Life Model Viewer]] in the "Bin" directory with the rest of the Source SDK tools, and open the model. Some common problems:


To make sure everything is working correctly, you can run the new Half-Life Model Viewer to view your new model. HLMV can be found in the "Bin" directory with the rest of the tools. Go to File>Load Model option at the top of HLMV and browse to the location of your model then hit the "Open" button.
* A black and pink checkerboard texture: the materials are not in the location specified by the .QC file.
* Incorrect collision hull: select the "Render" tab and click the "Physics Model" checkbox to view the model's collision hull.


Some problems you might run into:
[[Category:Modeling]]
 
* If your model has a black and pink texture, it's because the materials are not in the location the .qc has pointed the model to look for them in.
* With the "Render" tab at the bottom of HLMV selected, at the top right corner of the panel click the checkbox next to "Physics Model." If your physics model does not look as you have expected it to, see the Modeling documentation to help diagnose your problem.
 
That should do it. If you're still having problems, try going through the Modeling documentation to see if there are any issues you might need to take care of.
 
=P.S. I've Lost My Original Source...=
 
If you've lost your original source, you can use SMD importer for your 3D package(e.g. Valve Addon for Softimage|XSI) and import your .smd directly for editing. One way to get a hold of your textures for converting to materials is to use the [[Goldsource]] version of HLMV and extracting the textures from the Texture tab. If all of these options fail you, maybe starting from scratch isn't such a bad idea after all.


{{otherlang:en}} {{otherlang:en:jp|Porting Goldsource content to Source:jp}}
{{otherlang:en}} {{otherlang:en:jp|Porting Goldsource content to Source:jp}}

Revision as of 13:27, 29 July 2006

Porting a Goldsource model to the Source engine is a short process. For best results, have all original source content ready for the model: original 3d package file, textures, and .QC file. SMD files may also be useful if the original 3d package file is unavailable. For help with obtaining such files, see

For the most part, porting models is straightforward: Set the VPROJECT properly, convert old textures to VTF format, tweak .QC file to include new Source syntax, and then compile the new content into a new Source model file.

Set VPROJECT

Main article:  [[Game Directory|Game Directory]]

The VPROJECT variable is referenced by several Source SDK tools: basically, it directs applications where to find or place compiled models (.MDL) and materials (.VTF). [Studiomdl]] and Vtex both use VPROJECT to place compiled models and materials in the correct directory. Half-Live Model Viewer (HLMV) uses VPROJECT to find model materials. To set the VPROJECT (Current Game), use the Source SDK launcher or VConfig.exe.

Convert old textures to new materials

See also:  Material system

In the Goldsource engine, .BMP textures were compiled into the .MDL file. However in the Source engine, developers export textures as .VTF files, which are simply referenced and not actually compiled into the .MDL file.

Originally, in the preliminary release of the Source SDK, developers were confined to using the included command-line exporter Vtex to compile materials. Since then, a variety of community produced tools provide Windows-friendly GUIs and interfaces, batch conversions, and texture previewing. VTFedit is highly recommended; though there are also other tools available. This tutorial will assume that the user is using Vtex.

First, convert all old texture files to .TGA format, using Photoshop or a similar image editing application.

  1. Create a shortcut to vtex.exe on your desktop. Vtex.exe is located in the SourceSDK\bin directory.
  2. Right-click the shortcut and select the "Properties" option.
  3. In the "Target" box, add "-mkdir -shader vertexlitgeneric" after vtex.exe with a space between them. Click OK.

Use this shortcut when converting new materials by dragging each .TGA file onto the desktop shortcut itself. The argument "-mkdir" will automatically create the materialsrc directory. The argument -shader VertexLitGeneric tells Vtex to automatically make a new .VMT that points to the .VTF as the diffuse texture.

Note.pngNote:The VertexLitGeneric shader is only used for models; it should not be used for sprites or brushes. Check the Materials documentation for more info.

Export .SMD files

If the original 3D model file is lost, use an SMD plug-in (e.g. Valve Addon for Softimage|XSI) and import the .smd directly for editing.

Modify .QC file

Main article:  [[.QC|.QC]]

While old .QC files will work with the new Studiomdl, there have been syntax changes for Source models to compile correctly.

  • $modelname now works in conjunction with VPROJECT and automatically assumes a directory output location of VPROJECT + a 'models' directory. For example: C:\Program Files\Valve\Steam\SteamApps\SourceMods\MyMod\models. So if $modelname were set to "player\myplayer.mdl", Studiomdl will compile the model and write it to C:\Program Files\Valve\Steam\SteamApps\SourceMods\MyMod\models\player\myplayer.mdl. Note that Studiomdl will not create new directories, nor does it have a –mkdir argument, so make sure a directory already exists before compiling.
  • Replace $cdtexture with $cdmaterials. $cdmaterials also uses VPROJECT and assumes the output directory to be VPROJECT + 'materials' directory. For example: C:\Program Files\Valve\Steam\SteamApps\SourceMods\MyMod\materials. Break the material directory tree up based on context - in this case, a model. Keeping the same example as in the $modelname step above, set $cdmaterials to "models\player" so that the model will look for materials in the directory C:\Program Files\Valve\Steam\SteamApps\SourceMods\MyMod\materials\models\player.

Create a Collision Model (Physbox)

A "collision model" is the simplified mesh that defines how the model will interact with the world when it is being physically simulated. This document will not cover the details of creating a physbox. While Studiomdl will create a physics hull if one is not specified, the result will be extremely simple. It will not "vacuum seal" the model; it will simply connect all the furthest points of the model together directly. To demonstrate, imagine looking down on a model and that it is shaped like a plus sign.

The most correct collision hull would resemble the plus sign.

Phys demo2.jpg

The automatically generated collision hull would connect all the most extended parts directly.

Phys demo3.jpg

In some cases, it is acceptable if the object is insignificant or does not interact with the player or the game world. However, if the example object were a revolving door, then this physbox would be unacceptable.

Compile the Model

Main article:  [[Compiling Models|Compiling Models]]

The actual process of compiling hasn't changed outside of Studiomdl using VPROJECT. To associate .QC files with Studiomdl for double-click compiling:

  1. Open a Windows Explorer. (Windows Key + E)
  2. At the top of the window, click "Tools", then "Folder Options...".
  3. Click the "File Types" tab then scroll down to QC. If you do not have a QC extension in your list, you can add it by hitting the "New" button below the list, and enter "QC" in the box. Hit "OK" to enter the extension into the list.
  4. Click the QC extension. It should become highlighted.
  5. In the "Details for 'QC' extension" area of the "Folder Options" panel, click the "Change..." button to the right of the text "Opens with:".
  6. Click the "Browse..." button at the bottom right of the "Open With" panel.
  7. Browse to the file "studiomdl.exe" in the SDK tools. Click the "Open" button.
  8. Make sure that "studiomdl.exe" is highlighted in the "Open With" panel. Click the "OK" button.
  9. Close the "Folder Options" panel with the "Close button.

Check the Model with the Half-Life Model Viewer

Find the Half-Life Model Viewer in the "Bin" directory with the rest of the Source SDK tools, and open the model. Some common problems:

  • A black and pink checkerboard texture: the materials are not in the location specified by the .QC file.
  • Incorrect collision hull: select the "Render" tab and click the "Physics Model" checkbox to view the model's collision hull.

Template:Otherlang:en Template:Otherlang:en:jp