Compiling a model: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (fixed)
No edit summary
Line 1: Line 1:
__TOC__
<div style="float:right;padding:0 1em;background:#FFF;">__TOC__</div>
This article explains how to use the [[Source SDK]] tool <code>studiomdl.exe</code>, located in the <code>sourcesdk/bin</code> directory. Studiomdl is used to compile source [[SMD|.SMD]] files exported from a [[:category:Modeling|modeling]] package, combined with a [[Qc|.QC]] script file, into a [[MDL|.MDL]] file that can be used by the engine.


== Exporting and compiling models ==
This article will explain how to compile [[model]]s for use in-game with [[studiomdl]]. You will need some existing [[Studio Model Data|SMD]] files to compile before you begin; if you don't have any, see [[Exporting a model]].
Follow these steps to export a model from [[XSI]] and compile it with the Source SDK tools:
# Export the .SMD files somewhere under the SDK's <code>modelsrc</code> directory for the game being compiled for.
#: For example, for a [[Counter-Strike Source]] model:
#: <code>C:\Program Files\Steam\SteamApps\username\sourcesdk_content\cstrike\modelsrc</code>
#: or
#: <code>C:\Program Files\Valve\Steam\SteamApps\username\sourcesdk_content\cstrike\modelsrc</code>
#: Where <i>username</i> is your Steam Login name.
# Create a [[Qc|.QC]] file (using Notepad or a similar text editor) in the same place as the .SMD files. Refer to the QC files that are already in the <code>sourcesdk_content\cstrike\modelsrc</code> directory for examples. See [[:Category:QC Commands]] for a (not complete) glossary of available QC commands.
# Ensure the proper "Current Game" is selected on the SDK Launcher panel (eg. Counter-Strike: Source).
# Run <code>studiomdl.exe</code> on the .QC file. To do this, open a Windows command prompt, and type:
#: <code>cd "%sourcesdk%"</code>
#: <code>bin\studiomdl -game <YourGameDir> ..\sourcesdk_content\cstrike\modelsrc\mymodel.qc</code>
#: {{note|This makes use of an environment variable called "sourcesdk" to simplify things. This environment variable is created upon installation of the Source SDK.}}
# As an alternative to running <code>studiomdl.exe</code> in a command prompt window, a desktop shortcut to <code>studiomdl.exe</code> can be created. Model .QC files can then be "dragged-and-dropped" from a Windows Explorer window to the desktop shortcut to perform the compiling.
#: Open Windows Explorer, navigate to the <code>..sourcesdk\bin</code> folder, right-click on <code>studiomdl.exe</code> and select <code>Send To.. Desktop (create shortcut)</code>.
#: {{note|Disadvantage of the shortcut method - it is difficult to view errors reported by <code>studiomdl.exe</code> during the compile process using the shortcut method as the compile window will close immediately after the error is reported. However, you can edit the shortcut to allow the window to stay open. Right click on the shortcut, and add '''C:\WINDOWS\system32\cmd.exe /K''' in the target field in front of the address.  There should be a space between the /K and the beginning of the address. If your windows directory is on a different drive letter than C, change the string accordingly. Example: '''C:\WINDOWS\system32\cmd.exe /K E:\Valve\Steam\SteamApps\USERNAME\sourcesdk\bin\orangebox\bin\studiomdl.exe -nop4'''.  While this works for me, some people have been unable to get this to work, and it may have to do with having spaces in the address (i.e. if part of your location includes Program Files). This has only been tested on XP. If the model does not appear to compile correctly, use the command prompt window method to determine if <code>studiomdl.exe</code> reports error(s) during the compile process.}}
# If there are no errors with the .QC file or the .SMD files, a .MDL file will be created in the location specified by the <code>$modelname</code> key in the .QC file.
# [[Half-Life Model Viewer|Model Viewer]] can now be run in the SDK launcher to open and view the model file.


== Placing models ==
{{tip|The name "studio" is a throwback to the development [[Half-Life 1]], during which Valve used [[3D Studio Max]] to create their models.}}
A model can be placed in a map with the Hammer level editor to see it inside the game.


To place a compiled model in Hammer:
== QC file ==


# Open the [[Hammer|Hammer Editor]] from the SDK Launcher.
As well as SMD data files, you will need a [[Qc|QC]] file that defines how the raw SMD data should be interpreted in a manner not too dissimilar to a texture's [[VMT]]. This is where you will spend the majority of your time when setting up a compile.
# Add an entity with the Entity Tool (<code>prop_static</code>, <code>prop_dynamic</code>, <code>prop_physics</code>,  <code>prop_physics_multiplayer</code> or <code>generic_actor</code> depending on the model type and game). In the Object Properties or World Model property 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]].


== Sample models ==
A QC file is simply a text file with the <code>.qc</code> extension. 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.
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:


  cd "%sourcesdk%"
== Compile environment ==
  bin\studiomdl ..\sourcesdk_content\cstrike\modelsrc\lamp\it_lampholder1.qc
 
While you can edit your QC with Notepad, you really ought to use an advanced text editor that supports syntax highlighting and can run studiomdl on the file without any messing about at the Windows command line. There are two editors with such support at the moment:
 
*[[Notepadpp VDF languages|Notepad++]]
*[[Highlighting and Compiling QCs with ConTEXT|ConTEXT]]
 
Once you've downloaded the highlighting rules and set up the execution command, you're all set!
 
== QC commands ==
 
:'''''For a list of all documented QC commands''', see [[:Category:QC Commands]]''
 
Here is a QC file for a non-animated, static prop:
 
[[$modelname]] "props_sdk/myfirstmodel.mdl"
[[$body]] mybody "myfirstmodel-ref.smd"
[[$staticprop]]
[[$surfaceprop]] combine_metal
[[$cdmaterials]] "models/props_sdk"
  [[$sequence]] idle "myfirstmodel-idle.smd" loop fps 1
  [[$collisionmodel]] "myfirstmodel-phys.smd" { [[$concave]] }
 
Here is a brief summary of what each command does (for more detail, click on the names):
 
;<code>[[$modelname]]</code>
:Defines the core output model file. Several other files will be created as well, with variations of this value as their name.
;<code>[[$body]]</code>
:Defines the SMD that contains the [[vertex]], [[UV map]] and [[envelope]] data for the model. Without this, your model will have no physical appearance.
:A name ('mybody') is given because it is possible for a model to have several bodies - like the [[npc_metropolice|metrocop]], who has one with a [[npc_manhack|manhack]] attached and one without.
:{{tip|More complex models use <code>[[$model]]</code> instead of $body.}}
;<code>[[$staticprop]]</code>
:Tells studiomdl that the model has no moving parts, allowing it to perform several important optimisations. It does ''not'' have anything to do with [[prop_static]]!
;<code>[[$surfaceprop]]</code>
:How the object's surface reacts to other entities in the world. Also helps define the weight of the object, if the QC command to calculate it is used.
:{{note|An identical command is used in [[material]]s. Should they clash on a model, the QC version is chosen. It isn't clear why this functionality is duplicated.}}
;<code>[[$cdmaterials]]</code>
:The folder to load the model's material(s) from. Remember that the materials must be the same name as the ones you applied in your modelling package.
;<code>[[$sequence]]</code>
:Even though this model is not animated, Source needs an empty 'idle' animation to correctly load it. By setting it to one frame per second, we eliminate a small amount of overhead.
;<code>[[$collisionmodel]]</code>
:Defines the SMD that will be used to calculate [[physics]] collisions by the engine. Without a collision model, physical objects will simply fly through the model (which in some cases may be what you want).
;<code>[[$concave]]</code>
:A collision model must be [[Wikipedia:convex|convex]], but you can create [[Wikipedia:concave|concave]] shapes by combining more than one of them into the same model. This command tells studiomdl that this is what you intend - without it, all of your collision SMD's meshes will be merged into one shape that wraps them all around.
 
You will be able to use this sample to compile your own model (except any animations), so swap in your own SMDs and see what happens.
 
== Common errors ==
 
=== Costly collision model ===
 
A costly collision model is one of over 20 convex parts. You will receive this error when going over it:
 
WARNING: COSTLY COLLISION MODEL!!!! (30 parts - 20 allowed)
WARNING: Error with convex elements of physmodel.smd, building single convex!!!!
Model has 31 convex sub-parts
Collision model completed.
 
The appearance of "error with convex elements" is itself an error, so ignore it. Your meshes are (probably) fine.
 
The solution to this is either to decrease the number of convex meshes, or if you really do need that many of them (usually only excusable on very large models), to use the <code>[[$maxconvexpieces]]</code> command to override the limit to one of your own preference. For instance:
 
$collisionmodel "myfirstmodel-phys.smd" { $concave '''$maxconvexpieces 40''' }
 
''(Episode One engine users must run studiomdl with the <code>-fullcollide</code> parameter when compiling instead.)''


== Compile errors ==
=== Duplicate weightlist pelvisonly ===
=== Duplicate weightlist pelvisonly ===
If Studiomdl displays the error "<code>duplicate weightlist pelvisonly</code>" when compiling the <code>male_06_sdk</code> model, the problem may be the inclusion of the file <code>Male_Animations_sdk/WeaponsAnims_Shared_sdk.qci</code>.
If Studiomdl displays the error "<code>duplicate weightlist pelvisonly</code>" when compiling the <code>male_06_sdk</code> model, the problem may be the inclusion of the file <code>Male_Animations_sdk/WeaponsAnims_Shared_sdk.qci</code>.
Line 52: Line 94:
* Recompile <code>male_06_sdk.qc</code> to determine if the error was corrected.
* Recompile <code>male_06_sdk.qc</code> to determine if the error was corrected.


=== Costly collision model ===
=== Short conversion out of range ===
By default, Studiomdl simplifies a collision model with more than 20 convex parts into a single hull, for performance reasons.
 
  WARNING: COSTLY COLLISION MODEL!!!! (<xx> parts)
  Generating optimized mesh "c:\steam\steamapps\SourceMods\mod\models/your/model.sw.vtx":
Truncating model!!!!
  ERROR: short conversion out of range XXXXX
Model has 1 convex sub-parts
  ERROR: Aborted Processing on 'your/model.mdl'
In some instances, though, it's necessary to have a collision model that is more complex or detailed than what can be achieved with 20 separate pieces. To disable this behavior pass the argument <code>-fullcollide</code> to <code>studiomdl.exe</code> when compiling your model. This can be done in the command prompt, as
studiomdl -fullcollide "path/to/model.qc"
with a drag-and-drop DOS batch file, as
  @echo on
cd "%sourcesdk%/bin"
studiomdl.exe -fullcollide %1
@pause
or with a tool like [[GUIStudioMDL]] or [[Studiocompiler]].<br>
This has been reported by some people not to work Studiomdl gives the same error and the output looks the same.
Using any of these methods on a collision model that would normally be truncated should return:
  WARNING: COSTLY COLLISION MODEL!!!!
Truncation DISABLED!!!!
Model has <xx> convex sub-parts
Collision model completed.


=== Short conversion out of range ===
The problem is that <code>studiomdl.exe</code> is trying to write out a triangle strip with more than 32767 vertices, which is more than Source supports (and also more than any model should ever need). You have run into a  engine limitation and you need to reduce the complexity of a portion of the model.
<pre>
Generating optimized mesh "c:\steam\steamapps\SourceMods\mod\models/your/model.sw.vtx":
ERROR: short conversion out of range XXXXX
ERROR: Aborted Processing on 'your/model.mdl'
</pre>


The problem is that <code>studiomdl.exe</code> is trying to write out a triangle strip with more than 32767 indices. The indices reported is more than Source supports. You have run into a  engine limitation and you will need to reduce the complexity of a portion of the model.
As an example, Valve's highest [[LOD]] .SMD for dog is only 1.72 MB and contains 17,433 vertices. Which then divides down to a little less than 6,000 polygons. 10,000 polygons is kind of an informal maximum for the Source engine, hence the maximum vertices being roughly 10,000 x 3 (32767).
As an example, Valve's highest [[LOD]] .SMD for dog is only 1.72 MB and contains 17,433 vertices. Which then divides down to a little less than 6,000 polygons. 10,000 polygons is kind of an informal maximum for the Source engine, hence the maximum vertices being roughly 10,000 x 3 (32767).


Line 97: Line 119:


== See also ==
== See also ==
* [[Qc|.QC File Basics]]
* [[Qc|QC]]
* [[Studiocompiler]]
* [[studiomdl]]
* [[GUIStudioMDL]]
* [[Studiocompiler]], a graphical interface for studiomdl
* [[GUIStudioMDL]], another graphical interface
* [[Highlighting and Compiling QCs with ConTEXT]]
* [[Highlighting and Compiling QCs with ConTEXT]]
* [[Notepadpp VDF languages|Notepad++ VDF languages]]


{{otherlang:en}}
{{otherlang:en}}
Line 106: Line 130:


[[Category:Modeling]]
[[Category:Modeling]]
[[Category:Tutorials]]

Revision as of 12:09, 24 April 2008

This article will explain how to compile models for use in-game with studiomdl. You will need some existing SMD files to compile before you begin; if you don't have any, see Exporting a model.

Tip.pngTip:The name "studio" is a throwback to the development Half-Life 1, during which Valve used 3D Studio Max to create their models.

QC file

As well as SMD data files, you will need a QC file that defines how the raw SMD data should be interpreted in a manner not too dissimilar to a texture's VMT. This is where you will spend the majority of your time when setting up a compile.

A QC file is simply a text file with the .qc extension. 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.

Compile environment

While you can edit your QC with Notepad, you really ought to use an advanced text editor that supports syntax highlighting and can run studiomdl on the file without any messing about at the Windows command line. There are two editors with such support at the moment:

Once you've downloaded the highlighting rules and set up the execution command, you're all set!

QC commands

For a list of all documented QC commands, see Category:QC Commands

Here is a QC file for a non-animated, static prop:

$modelname	"props_sdk/myfirstmodel.mdl"
$body mybody	"myfirstmodel-ref.smd"
$staticprop
$surfaceprop	combine_metal
$cdmaterials	"models/props_sdk"

$sequence idle	"myfirstmodel-idle.smd" loop fps 1

$collisionmodel	"myfirstmodel-phys.smd" { $concave }

Here is a brief summary of what each command does (for more detail, click on the names):

$modelname
Defines the core output model file. Several other files will be created as well, with variations of this value as their name.
$body
Defines the SMD that contains the vertex, UV map and envelope data for the model. Without this, your model will have no physical appearance.
A name ('mybody') is given because it is possible for a model to have several bodies - like the metrocop, who has one with a manhack attached and one without.
Tip.pngTip:More complex models use $model instead of $body.
$staticprop
Tells studiomdl that the model has no moving parts, allowing it to perform several important optimisations. It does not have anything to do with prop_static!
$surfaceprop
How the object's surface reacts to other entities in the world. Also helps define the weight of the object, if the QC command to calculate it is used.
Note.pngNote:An identical command is used in materials. Should they clash on a model, the QC version is chosen. It isn't clear why this functionality is duplicated.
$cdmaterials
The folder to load the model's material(s) from. Remember that the materials must be the same name as the ones you applied in your modelling package.
$sequence
Even though this model is not animated, Source needs an empty 'idle' animation to correctly load it. By setting it to one frame per second, we eliminate a small amount of overhead.
$collisionmodel
Defines the SMD that will be used to calculate physics collisions by the engine. Without a collision model, physical objects will simply fly through the model (which in some cases may be what you want).
$concave
A collision model must be convex, but you can create concave shapes by combining more than one of them into the same model. This command tells studiomdl that this is what you intend - without it, all of your collision SMD's meshes will be merged into one shape that wraps them all around.

You will be able to use this sample to compile your own model (except any animations), so swap in your own SMDs and see what happens.

Common errors

Costly collision model

A costly collision model is one of over 20 convex parts. You will receive this error when going over it:

WARNING: COSTLY COLLISION MODEL!!!! (30 parts - 20 allowed)
WARNING: Error with convex elements of physmodel.smd, building single convex!!!!
Model has 31 convex sub-parts
Collision model completed.

The appearance of "error with convex elements" is itself an error, so ignore it. Your meshes are (probably) fine.

The solution to this is either to decrease the number of convex meshes, or if you really do need that many of them (usually only excusable on very large models), to use the $maxconvexpieces command to override the limit to one of your own preference. For instance:

$collisionmodel	"myfirstmodel-phys.smd" { $concave $maxconvexpieces 40 }

(Episode One engine users must run studiomdl with the -fullcollide parameter when compiling instead.)

Duplicate weightlist pelvisonly

If Studiomdl displays the error "duplicate weightlist pelvisonly" when compiling the male_06_sdk model, the problem may be the inclusion of the file Male_Animations_sdk/WeaponsAnims_Shared_sdk.qci.

That file contains a $weightlist pelvisonly line identical to a line in the included file male_shared_XSI_sdk.qci.

  • In the Male_Animations_sdk folder, make a copy of the WeaponsAnims_Shared_sdk.qci file.
  • Rename the copy to WeaponsAnims_Shared_sdk_X.qci (or other unique name).
  • Edit the WeaponsAnims_Shared_sdk_X.qci file and comment out the $weightlist line by inserting // at the beginning of the line.
//$weightlist pelvisonly ...
  • Open for editing the file male_06_sdk.qc.
  • Change the line $include "../male_animations_sdk/WeaponAnims_shared_sdk.qci" to
$include "../male_animations_sdk/WeaponAnims_shared_sdk_X.qci" //(or as otherwise renamed above)
  • Save the male_06_sdk.qc file.
  • Recompile male_06_sdk.qc to determine if the error was corrected.

Short conversion out of range

Generating optimized mesh "c:\steam\steamapps\SourceMods\mod\models/your/model.sw.vtx":
ERROR: short conversion out of range XXXXX
ERROR: Aborted Processing on 'your/model.mdl'

The problem is that studiomdl.exe is trying to write out a triangle strip with more than 32767 vertices, which is more than Source supports (and also more than any model should ever need). You have run into a engine limitation and you need to reduce the complexity of a portion of the model.

As an example, Valve's highest LOD .SMD for dog is only 1.72 MB and contains 17,433 vertices. Which then divides down to a little less than 6,000 polygons. 10,000 polygons is kind of an informal maximum for the Source engine, hence the maximum vertices being roughly 10,000 x 3 (32767).

Error codes

* WARNING: (4768124) : ERROR: 'EXCEPTION_ACCESS_VIOLATION' (assert: 1)

This is caused by having the $shadowlod's curly bracket in the same line as the command. Change:

$shadowlod {

to

$shadowlod
{

Also without the "WARNING: (4768124)":

* ERROR: 'EXCEPTION_ACCESS_VIOLATION' (assert: 1)

If getting this error while compiling with Studiomdl try compiling models with the HLMV running. (18/11/07) - Laz84

See also

Template:Otherlang:en Template:Otherlang:en:ru