This article's documentation is for anything that uses the Source engine. Click here for more information.

Compiling a model: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (added link)
 
(103 intermediate revisions by 45 users not shown)
Line 1: Line 1:
[[Category:Modeling]]
{{LanguageBar}}
 
{{src topicon}}
 
{{toc-right}}
 
[[Model]]s need to be compiled before they can be used in a game. There are three components of a compile:
 
# A set of source files ('''[[SMD]], [[DMX]], [[VTA]])''' describing a model. See [[Exporting a model]] if you don't have any. [[FBX]] enjoys limited support in ''CS:GO'' starting from update 1.34.8.4. [[w:Wavefront .obj file|OBJ]] can also be used with any branch, with the same limitations as FBX.
# A '''[[QC]] file''' that defines, in a manner not too dissimilar to a texture's [[VMT]], how the source files should be transformed into a Source engine model.
# '''[[StudioMDL]]''', the SDK program that consumes the QC and spits out a compiled model.
 
==Setting up==
Assuming that your source files have exported OK from your favorite 3D modeling software, the only step you need to take before compiling is choosing the current [[VPROJECT]]. This defines where studiomdl will write out the compiled model. You can configure the value:
 
#Globally, by selecting your game/mod in the SDK launcher's drop-down list.
#For studiomdl only, by running it with <code>-game "<full path to your [[gameinfo.txt]] folder>"</code> {{tip|Most SDK tools accept <code>-game</code>.}}


=Exporting and Compiling Models=
===Syntax highlighting===
Editing a QC file becomes much easier when you use an advanced text editor with support for [[Wikipedia:syntax highlighting|syntax highlighting]]. There are two editors with QC highlighting rules at the moment:


Follow these steps to export a model from XSI and compile it with the Source SDK tools:
* [[Notepad++ VDF languages|Notepad++]]
* [[Highlighting and Compiling QCs with ConTEXT|ConTEXT]]


1. Export the SMD files somewhere under the SDK's modelsrc directory for the game you're compiling for.
==Creating a QC==
A QC file is simply a text file with the extension <code>.qc</code>. You can create it anywhere and name it anything, but it's best to be organised and store it with your SMDs in a folder with the same name as the destination model file.


For example, for a Counter-Strike Source model:
Inside it should be a list of [[:Category:QC Commands|commands]] that tell studiomdl about the location of the model's various SMDs, where the compiled files should be written to (relative to VPROJECT), how to process animations, and potentially much, ''much'' more. You will find all known commands listed at [[:Category:QC Commands]].


<code>C:\Program Files\Steam\SteamApps\username\sourcesdk_content\cstrike\modelsrc</code>
===Example===
{{BoxOut|float=right|width=22em|
1=<strong style="font-size:1.2em;color:#fff;">File locations</strong>


or
When a source file is referenced in your QC, the compiler will look for it in the same folder. You should therefore place all your source files for a given model in the same folder. There are, however, commands to tell the compiler that you want to give it a file that is not in the same folder as the QC!


<code>C:\Program Files\Valve\Steam\SteamApps\username\sourcesdk_content\cstrike\modelsrc</code>
* With an absolute path (e.g. <code>C:\modelsrc\my_model\</code>)
* With a relative path (e.g. <code>.\subfolder</code> or <code>..\</code>) {{tip|A single period is the current folder. Two periods is the one above it. <code>..\..\</code> goes two directories up.}}
* With <code>[[$pushd]]</code> and <code>[[$popd]]</code>.
}}


Where <i>username</i> is your Steam Login name.
Here is a very simple QC file for a solid model without any animation or special properties (click on each command for details):


2. Create a .QC file in the same place as your .SMD files. You can refer to the QC files that are already in the <code>sourcesdk_content\cstrike\modelsrc</code> directory for examples. See [[.QC Commands|QC Commands]] for a detailed list of commands you can use in .QC files.
[[$modelname]] "props\myfirstmodel.mdl"
[[$body]] mybody "myfirstmodel-ref.smd"
[[$surfaceprop]] combine_metal
[[$cdmaterials]] "models/props"
[[$sequence]] idle "myfirstmodel-ref"
[[$collisionmodel]] "myfirstmodel-phys" { [[$concave]] }


3. Make sure you have the proper '''Current Game''' selected on the '''SDK Launcher''' panel (eg. Counter-Strike: Source).
You should be able to use this as a template to compile your own model, so swap in your own SMDs (of DMXes, or FBXes) and see what happens.


4. Run <code>studiomdl.exe</code> on your .QC file. To do this, open a Windows command prompt, and type:
{{note|All models must have at least one <code>$sequence</code>, even if they aren't actually animated!}}


<pre>
===Tutorials===
      cd "%sourcesdk%"
* For physically-simulated objects, see '''<code>[[Prop Data|prop_data]]</code>'''
      bin\studiomdl ..\sourcesdk_content\cstrike\modelsrc\mymodel.qc
* For characters or player models, see '''[[Player_Models|Compiling a character model]]'''
</pre>
* For weapons, see '''[[Creating worldmodels from viewmodels]]'''
* For vehicles, see '''[[Vehicles (modeling)]]'''
* For general help with compiling models, see '''[[:Category:QC Commands]]'''


'''Note:''' This makes use of an environment variable called "sourcesdk" to simplify things. This environment variable is created upon installation of the Source SDK.
==Compiling==
===With your text editor===
The easiest way to compile a model is with the built-in launch features of advanced text editors.


5. If there are no errors with the .QC file or your .SMD files, then you will have a .MDL file in the location specified by the <code>$modelname</code> key in the .QC file.
* [[Notepadpp VDF languages#Compiling QC files|With Notepad++]]
* [[Highlighting and Compiling QCs with ConTEXT|With ConTEXT]]


6. You can now run '''Model Viewer''' in the '''SDK launcher''' and open your model file.
===With a batch file===
If you can't (or don't want to) use an advanced text editor, you will be compiling QCs by dragging them onto studiomdl in Windows. You can find the executable file in <code>sourcesdk/bin/[orangebox|ep1]/bin/</code>.


=Placing models=
The process will be easier if you create a .cmd file somewhere more accessible to automate it. This is simply a renamed .txt file containing something like this:


You can place a model with the Hammer level editor to see it inside the game.
"%sourcesdk%/bin/orangebox/bin/studiomdl" -nop4 %1
pause


'''Note:''' This copying step will not be required in the full SDK release.
Drop your QC file onto the CMD as you would studiomdl itself; it's essentially a shortcut to the executable.


To place a compiled model in Hammer:
===With Compiling Tools===
Third party tools, such as {{crowbar|4}}, include model compiling, and decompiling, tools. All you have to do with programs like these is specify the QC file, select the game you are using, and press compile. It will automatically do all the steps listed above.


1. Open the Hammer Editor from the SDK Launcher.
== Common errors == <!-- linked to from [[studiomdl]] -->


2. Add a prop entity with the Entity Tool (<code>prop_static</code>, <code>prop_dynamic</code> or <code>prop_physics_multiplayer</code>, depending on your model type). In the '''Object Properties''' for the entity, browse the model tree to view and place the model. See the Hammer documentation for information on how to use the '''Entity Tool'''.
* <code>Error opening <model>! (Check for write enable)</code>
: Studiomdl won't create folders that don't exist; you must manually create a path to your .mdl before compiling.
* <code>[[Costly collision model]]</code>
* <code>[[Duplicate weightlist pelvisonly]]</code>
* <code>[[Short conversion out of range]]</code>
* <code>[[WARNING: (4768124) : ERROR: 'EXCEPTION ACCESS VIOLATION' (assert: 1)]]</code>
: If you receive <code>EXCEPTION_ACCESS_VIOLATION</code> without an error code, try compiling with [[HLMV]] running.
* <code>WARNING: Bad collision model, check your smoothing groups!!!</code>
: If you created the collision model with XSI then you need to turn off Geometry Approximation's Automatic Discontinuity (Explorer -> Your Mesh -> Geometry Approximation -> Polygon Mesh -> Discontinuity -> Untick Automatic) for the smoothing groups to be exported properly.
{{note|If disabling automatic discontinuity doesn't work, try making your collision model simpler.}}
* <code>WARNING: Model  has 2-dimensional geometry (less than 0.500 inches thick on any axis)!!!</code>
: This will happen if one, or more, face isn't in the same smoothing group as the rest of the collision model. To fix this simply assign all faces of your mesh to the smoothing goup 1 (since you can only use 1 smoothing group). Many thanks to Vaenyc for [http://forums.steampowered.com/forums/showthread.php?t=964995&highlight=WARNING%3A+Model+2-dimensional+geometry this thread]
: This also happens if there literally is too thin geometry in a collision model. This might be related to scaling down a model with [[$scale]], especially if the intent was to recompile a full-sized model for [[3D Skybox|skybox]] usage. (In that case, replacing the collision model by an empty one might be adequate as skybox content usually won't need collisions.)
* <code>Bounding box out of range</code>
: The compile error '''''"bounding box out of range"''''' followed by a string of coordinates means that the collision model for your mesh is larger than the maximum allowed size which seems to be hard coded at 16384 units in any direction. This often happens when you either scale up a model too much forcing the collision outside the range, or if your animation causes your collisionjoints to move outside this range.
: {{tip|A solution might be to divide the model into several smaller pieces if possible.}}
: In the case where your model isn't going to be colliding with other objects in the world, it seems that you can also ignore this error if need be as it doesn't seem to impact performance.


Sample Models
==SDK samples==
The SDK has numerous sample models, including several fully-articulated characters and players. They can be found at <code>steamapps\common\sourcesdk_content\<game>\modelsrc\</code>.
{{note|Left 4 Dead and Left 4 Dead 2 sample models can be found at <code><game>\sdk_content\modelsrc\</code>}}
; <code>sdk</code>
: Complete SMD source for both player models and weapons in {{dods|4}}.
; <code>tf</code>
: Complete, but outdated, [[DMX]] source for all TF2 classes. Rigged [[reference mesh|reference meshes]] are also available as [[SMD]] and {{Maya|4.1}}.
; <code>generic</code>
: A tweaked ValveBiped rig (no meshes)
; <code>cstrike</code>
: "Urban CT" player model
: Several static props
; <code>hl2</code>
: [[Airboat]] and [[Buggy]]
: [[Antlion Guard]]
: Male citizen (old version with only a few animations)
: Some CS stuff that is probably a duplicate of <code>\cstrike</code>'s content
: Viewmodels for all HL2 weapons
; <code>hl2mp</code>
: ''All with multiplayer animations only:''
: Combine soldier
: Metrocop
: Male rebel
; {{l4d|3.1}}
: Common infected Models, Bodygroups, and commands necessary for Dynamic Skins
: Breakable Woodrail prop example
: Explosive Weapon examples for red gas cans and propane tanks
; {{l4d2|3.1}}
: Breakable Woodrail prop example different from the one found in Left 4 Dead 1
: Crumbling Ceiling dynamic prop example
; {{asw|3.1}}
: Drone alien and marine source files


There are a number of Counter-Strike: Source and Half-Life 2 sample models in the <code>sourcesdk_content</code> directory that you can refer to for examples. They are compiled in the same way as models you create yourself. For example, you can type these commands at a command prompt to compile the lamp holder sample:
==See also==
* [[Qc|QC]]
* [[:Category:QC Commands]]
* {{Crowbar|4.1}}
* [[studiomdl]]
** [[Studiocompiler]], a graphical interface for studiomdl
** [[GUIStudioMDL]], another graphical interface
* [[Highlighting and Compiling QCs with ConTEXT]]
* [[Notepad++ VDF languages]]
* [http://wallworm.com/projects/utilities/docs/troubleshooting/compile_errors.html Common Compile Errors and Some Solutions]


<pre>
[[Category:Modeling]]
cd "%sourcesdk%"
[[Category:Tutorials]]
bin\studiomdl ..\sourcesdk_content\cstrike\modelsrc\lamp\it_lampholder1.qc
</pre>

Latest revision as of 12:47, 16 August 2024

English (en)Français (fr)한국어 (ko)Русский (ru)中文 (zh)Translate (Translate)

Models need to be compiled before they can be used in a game. There are three components of a compile:

  1. A set of source files (SMD, DMX, VTA) describing a model. See Exporting a model if you don't have any. FBX enjoys limited support in CS:GO starting from update 1.34.8.4. OBJ can also be used with any branch, with the same limitations as FBX.
  2. A QC file that defines, in a manner not too dissimilar to a texture's VMT, how the source files should be transformed into a Source engine model.
  3. StudioMDL, the SDK program that consumes the QC and spits out a compiled model.

Setting up

Assuming that your source files have exported OK from your favorite 3D modeling software, the only step you need to take before compiling is choosing the current VPROJECT. This defines where studiomdl will write out the compiled model. You can configure the value:

  1. Globally, by selecting your game/mod in the SDK launcher's drop-down list.
  2. For studiomdl only, by running it with -game "<full path to your gameinfo.txt folder>"
    Tip.pngTip:Most SDK tools accept -game.

Syntax highlighting

Editing a QC file becomes much easier when you use an advanced text editor with support for syntax highlighting. There are two editors with QC highlighting rules at the moment:

Creating a QC

A QC file is simply a text file with the extension .qc. You can create it anywhere and name it anything, but it's best to be organised and store it with your SMDs in a folder with the same name as the destination model file.

Inside it should be a list of commands that tell studiomdl about the location of the model's various SMDs, where the compiled files should be written to (relative to VPROJECT), how to process animations, and potentially much, much more. You will find all known commands listed at Category:QC Commands.

Example

File locations

When a source file is referenced in your QC, the compiler will look for it in the same folder. You should therefore place all your source files for a given model in the same folder. There are, however, commands to tell the compiler that you want to give it a file that is not in the same folder as the QC!

  • With an absolute path (e.g. C:\modelsrc\my_model\)
  • With a relative path (e.g. .\subfolder or ..\)
    Tip.pngTip:A single period is the current folder. Two periods is the one above it. ..\..\ goes two directories up.
  • With $pushd and $popd.

Here is a very simple QC file for a solid model without any animation or special properties (click on each command for details):

$modelname	"props\myfirstmodel.mdl"
$body mybody	"myfirstmodel-ref.smd"

$surfaceprop	combine_metal
$cdmaterials	"models/props"

$sequence idle	"myfirstmodel-ref"

$collisionmodel	"myfirstmodel-phys" { $concave }

You should be able to use this as a template to compile your own model, so swap in your own SMDs (of DMXes, or FBXes) and see what happens.

Note.pngNote:All models must have at least one $sequence, even if they aren't actually animated!

Tutorials

Compiling

With your text editor

The easiest way to compile a model is with the built-in launch features of advanced text editors.

With a batch file

If you can't (or don't want to) use an advanced text editor, you will be compiling QCs by dragging them onto studiomdl in Windows. You can find the executable file in sourcesdk/bin/[orangebox|ep1]/bin/.

The process will be easier if you create a .cmd file somewhere more accessible to automate it. This is simply a renamed .txt file containing something like this:

"%sourcesdk%/bin/orangebox/bin/studiomdl" -nop4 %1
pause

Drop your QC file onto the CMD as you would studiomdl itself; it's essentially a shortcut to the executable.

With Compiling Tools

Third party tools, such as Crowbar Crowbar, include model compiling, and decompiling, tools. All you have to do with programs like these is specify the QC file, select the game you are using, and press compile. It will automatically do all the steps listed above.

Common errors

  • Error opening <model>! (Check for write enable)
Studiomdl won't create folders that don't exist; you must manually create a path to your .mdl before compiling.
If you receive EXCEPTION_ACCESS_VIOLATION without an error code, try compiling with HLMV running.
  • WARNING: Bad collision model, check your smoothing groups!!!
If you created the collision model with XSI then you need to turn off Geometry Approximation's Automatic Discontinuity (Explorer -> Your Mesh -> Geometry Approximation -> Polygon Mesh -> Discontinuity -> Untick Automatic) for the smoothing groups to be exported properly.
Note.pngNote:If disabling automatic discontinuity doesn't work, try making your collision model simpler.
  • WARNING: Model has 2-dimensional geometry (less than 0.500 inches thick on any axis)!!!
This will happen if one, or more, face isn't in the same smoothing group as the rest of the collision model. To fix this simply assign all faces of your mesh to the smoothing goup 1 (since you can only use 1 smoothing group). Many thanks to Vaenyc for this thread
This also happens if there literally is too thin geometry in a collision model. This might be related to scaling down a model with $scale, especially if the intent was to recompile a full-sized model for skybox usage. (In that case, replacing the collision model by an empty one might be adequate as skybox content usually won't need collisions.)
  • Bounding box out of range
The compile error "bounding box out of range" followed by a string of coordinates means that the collision model for your mesh is larger than the maximum allowed size which seems to be hard coded at 16384 units in any direction. This often happens when you either scale up a model too much forcing the collision outside the range, or if your animation causes your collisionjoints to move outside this range.
Tip.pngTip:A solution might be to divide the model into several smaller pieces if possible.
In the case where your model isn't going to be colliding with other objects in the world, it seems that you can also ignore this error if need be as it doesn't seem to impact performance.

SDK samples

The SDK has numerous sample models, including several fully-articulated characters and players. They can be found at steamapps\common\sourcesdk_content\<game>\modelsrc\.

Note.pngNote:Left 4 Dead and Left 4 Dead 2 sample models can be found at <game>\sdk_content\modelsrc\
sdk
Complete SMD source for both player models and weapons in Day of Defeat: Source Day of Defeat: Source.
tf
Complete, but outdated, DMX source for all TF2 classes. Rigged reference meshes are also available as SMD and Maya Maya.
generic
A tweaked ValveBiped rig (no meshes)
cstrike
"Urban CT" player model
Several static props
hl2
Airboat and Buggy
Antlion Guard
Male citizen (old version with only a few animations)
Some CS stuff that is probably a duplicate of \cstrike's content
Viewmodels for all HL2 weapons
hl2mp
All with multiplayer animations only:
Combine soldier
Metrocop
Male rebel
Left 4 Dead
Common infected Models, Bodygroups, and commands necessary for Dynamic Skins
Breakable Woodrail prop example
Explosive Weapon examples for red gas cans and propane tanks
Left 4 Dead 2
Breakable Woodrail prop example different from the one found in Left 4 Dead 1
Crumbling Ceiling dynamic prop example
Alien Swarm
Drone alien and marine source files

See also