Compiling a model: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
Line 87: Line 87:
== Common errors ==
== Common errors ==


=== Costly collision model ===
*[[Costly collision model]]
 
*[[Duplicate weightlist pelvisonly]]
A costly collision model is one of over 20 convex parts. You will receive this error when going over it:
*[[Short conversion out of range]]
 
*[[WARNING: (4768124) : ERROR: 'EXCEPTION ACCESS VIOLATION' (assert: 1)]]
WARNING: COSTLY COLLISION MODEL!!!! (30 parts - 20 allowed)
*:If you receive "EXCEPTION_ACCESS_VIOLATION" without an error code, try compiling with [[HLMV]] running.
WARNING: Error with convex elements of myfirstmodel-phys.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 30''' }
 
''(Episode One engine users must run studiomdl with the <code>-fullcollide</code> parameter when compiling instead.)''
 
=== 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>.
 
That file contains a <code>$weightlist pelvisonly</code> line identical to a line in the included file <code>male_shared_XSI_sdk.qci</code>.
 
* In the <code>Male_Animations_sdk</code> folder, make a copy of the <code>WeaponsAnims_Shared_sdk.qci</code> file.
* Rename the copy to <code>WeaponsAnims_Shared_sdk_X.qci</code> (or other unique name).
* Edit the <code>WeaponsAnims_Shared_sdk_X.qci</code> file and comment out the $weightlist line by inserting <code>//</code> at the beginning of the line.
//$weightlist pelvisonly ...
* Open for editing the file <code>male_06_sdk.qc</code>.
* 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 <code>male_06_sdk.qc</code> file.
* Recompile <code>male_06_sdk.qc</code> 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 <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.
 
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 <code>$shadowlod</code>'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 ==
== See also ==
* [[Qc|QC]]
* [[Qc|QC]]
*[[:Category:QC Commands]]
* [[studiomdl]]
* [[studiomdl]]
* [[Studiocompiler]], a graphical interface for studiomdl
* [[Studiocompiler]], a graphical interface for studiomdl

Revision as of 14:29, 27 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 of 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 in a manner not too dissimilar to a texture's VMT how the raw SMD data should be interpreted. 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

The most important step in setting your computer up for a compile is choosing the correct VPROJECT variable. You can do this:

  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>"

When it comes to editing your QC, you really, really want to use an advanced text editor which supports syntax highlighting and which can run studiomdl without any command line or batch file fiddling. There are two editors with such support at the moment:

Once you've downloaded the editor and 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 15

$collisionmodel	"myfirstmodel-phys.smd" { $concave }
Tip.pngTip:The default location for SMDs is the same folder as the QC file. You can specify relative or absolute paths with any command if it needs to access a different folder.

Here is a brief summary of what each of those commands does. For more detail, click on the names.

$modelname
Defines the name and location of the model's core output file relative to <mod folder>/models/. 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, skeleton 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. The value is relative to <mod folder>/materials/.
$sequence
Even though this model is $staticprop and therefore not animated, Source needs an empty 'idle' animation to correctly handle it. If the animation is truly idle it will only have one frame, rendering the fps property meaningless (but it's included anyway as a demonstration.
$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).
Tip.pngTip:If your collision model needs to be animated, use $collisionjoints instead.
$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 instead be merged into one shape that wraps them all around.

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

Compiling more advanced models

Samples

Valve provide numerous sample models in the SDK for you to learn from, including several fully-articulated characters and players. They can be found at:

  • sourcesdk_content\cstrike\modelsrc
  • sourcesdk_content\hl2\modelsrc
  • sourcesdk_content\hl2mp\modelsrc
  • sourcesdk_content\generic\modelsrc (a walking animation for Valve's default skeleton)

Common errors

See also

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