Zh/Compiling a model

From Valve Developer Community
< Zh
Revision as of 17:05, 6 October 2015 by Apache553 (talk | contribs)
Jump to navigation Jump to search

Template:Otherlang2

模型在游戏中使用之前需要被编译。编译他你需要以下三个东西:

  1. 一套用于描述模型的文件(像SMD, DMX, VTA)。如果你没有,请参见导出一个模型。FBX格式在CSGO的1.34.8.4版本后获得有限的支持。
  2. 一个QC文件它定义了这里源文件该如何被转换成为一个起源引擎模型,它与材质文件的 VMT文件较为相似。
  3. 模型工作室程序,这个SDK中的程序利用QC文件来编译输出一个编译过的模型(但愿如此!)

一些设置

假如你已经成功的从你最喜欢的3D建模软件中导出了模型源文件,在编译前,最后一步就是设置VPROJECT环境变量。它定义了模型工作室工具将会在那里输出编译好了的模型。你可以用以下方法改变输出位置:

  1. 一般地,你可以在SDK启动器(SDK Launcher)中的下拉菜单中选择你当前工作的游戏或者模组来改变它。
  2. 但你只用模型工作室工具时,在命令行中添加-game "<指向你gameinfo.txt所在文件夹的完整路径>"
    Tip.png提示:大部分SDK工具都支持-game命令行参数

句法高亮

当你使用支持 句法高亮的高级文本编辑器时,编辑QC文件将会变得非常简单。下面是目前支持QC高亮显示规则的两款文本编辑器:

创建一个QC

QC文件仅仅是一个拥有.qc后缀名的文本文件。你可以在任何地方以任何名字命名它,但是最好将他存储在你SMD文件所在的目录下并且命名它为你目标模型文件的名字。

在文件中应该是一个告诉模型工作室模型的各个SMD文件的位置,编译后文件应该被写入的位置,如何处理动画以及其他特性的一个QC命令列表,你可以在QC命令中找到所有已知命令的列表。

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.png提示: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"
$staticprop
$surfaceprop	combine_metal
$cdmaterials	"models\props"

$sequence idle	"myfirstmodel-ref.smd"

$collisionmodel	"myfirstmodel-phys.smd" { $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.png注意: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

You can also use tools like Crowbar to compile your model. You can simply load your QC file, select your Source Game and then click Compile

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.png注意: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.png提示: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 sourcesdk_content\<game>\modelsrc\.

Note.png注意: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 in Day of Defeat: Source.
tf
Complete, but outdated, DMX source for all TF2 classes. Rigged reference meshes are also available as SMD and 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 求生之路2
Breakable Woodrail prop example different from the one found in Left 4 Dead 1
Crumbling Ceiling dynamic prop example

See also