Zh/Compiling a model: Difference between revisions

From Valve Developer Community
< Zh
Jump to navigation Jump to search
No edit summary
No edit summary
Line 18: Line 18:


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


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


=== Example ===
=== 例子 ===


{{BoxOut|float=right|width=22em|
{{BoxOut|float=right|width=22em|
1=<strong style="font-size:1.2em;color:#fff;">File locations</strong>
1=<strong style="font-size:1.2em;color:#fff;">File locations</strong>


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!
当QC文件中存储了源文件的路径时,编译器会在同一个文件夹下寻找文件。因此你应该把一个模型的所有的源文件,放到同一个文件夹下。当然,在QC文件中,也有告诉编译器寻找在其他路径下的文件的命令。


* With an absolute path (e.g. <code>C:\modelsrc\my_model\</code>)
* 使用绝对路径 (例如 <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.}}
* 使用相对路径 (例如 <code>.\subfolder</code> <code>..\</code>) {{tip:zh-cn|一个点表示当前目录。两个点表示上一级目录。 <code>..\..\</code> 表示上上一级目录}}
* With <code>[[$pushd]]</code> and <code>[[$popd]]</code>.
* 使用 <code>[[$pushd]]</code> <code>[[$popd]]</code> 命令
}}
}}


Here is a very simple QC file for a solid model without any animation or special properties (click on each command for details):
下面是一个非常简单的QC文件,用于一个没有任何动画和特殊属性的静态模型(单击某个命令以获取它的详细信息):


  [[$modelname]] "props\myfirstmodel.mdl"
  [[$modelname]] "props\myfirstmodel.mdl"
Line 57: Line 57:
  [[$collisionmodel]] "myfirstmodel-phys.smd" { [[$concave]] }
  [[$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.
你可以把这个文件作为你的模型的QC文件模板,把其中的参数换成你自己的SMD文件(或 DMX,或 FBX)看看会发生什么。


{{note|All models must have at least one <code>$sequence</code>, even if they aren't actually animated!}}
{{note:zh-cn|每个模型至少需要一个 <code>$sequence</code>,即便模型没有任何动画效果}}


=== Tutorials ===
=== 其他教程 ===


* For physically-simulated objects, see '''<code>[[Prop Data|prop_data]]</code>'''
* 物理模型,见 '''<code>[[Prop Data|嵌入物理数据]]</code>'''
* For characters or player models, see '''[[Compiling a character model]]'''
* 人物和玩家模型,见 '''[[Player_Models|人物模型编译]]'''
* For weapons, see '''[[Creating worldmodels from viewmodels]]'''
* 武器模型,见 '''[[Creating worldmodels from viewmodels]]'''
* For vehicles, see '''[[Compiling a vehicle model]]'''
* 载具模型,见 '''[[Compiling a vehicle model|载具模型编译]]'''
* For general help with compiling models, see '''[[:Category:QC Commands]]'''
* 模型编译的常见问题 '''[[:Category:QC Commands|分类:编译QC]]'''


== Compiling ==
== 模型编译 ==


=== With your text editor ===
=== 使用文本编辑器 ===


The easiest way to compile a model is with the built-in launch features of advanced text editors.
编译模型最简单的方式是使用装好编译插件的高级文本编辑器。


* [[Notepadpp VDF languages#Compiling QC files|With Notepad++]]
* [[Notepadpp VDF languages#Compiling QC files|使用 Notepad++ 编译]]
* [[Highlighting and Compiling QCs with ConTEXT|With ConTEXT]]
* [[Highlighting and Compiling QCs with ConTEXT|使用 ConTEXT 编译]]


=== 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>.
如果你不能(或不想)用高级文本编辑器,在Windows下你可以通过把QC文件拖动到Studiomdl中来编译。Studiomdl程序位于 <code>sourcesdk/bin/[orangebox|ep1]/bin/</code> 路径下。


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:
如果创建一个 .cmd 文件来自动化地编译,这个过程会方便的多。把.txt重命名为.cmd就可以了,文件内容如下:


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


Drop your QC file onto the CMD as you would studiomdl itself; it's essentially a shortcut to the executable.
把你的QC文件拖动到CMD文件上来运行;它相当于Studiomdl程序的快捷方式。


=== 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
你也可以使用像 [[Crowbar]] 这样的工具来编译你的模型。只需要读取你的QC文件,选择对应的起源引擎游戏,然后点击编译按钮就可以了。


== Common errors == <!-- linked to from [[studiomdl]] -->
== 常见错误 == <!-- linked to from [[studiomdl]] -->


* <code>Error opening <model>! (Check for write enable)</code>
* 错误 <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.
: Studiomdl 遇到不存在的路径时,不会自己新建文件夹;你必须在编译前,为你的.mdl文件手动创建对应文件夹。
* <code>[[Costly collision model]]</code>
* 错误 <code>[[Costly collision model]]</code>
* <code>[[Duplicate weightlist pelvisonly]]</code>
* 错误 <code>[[Duplicate weightlist pelvisonly]]</code>
* <code>[[Short conversion out of range]]</code>
* 错误 <code>[[Short conversion out of range]]</code>
* <code>[[WARNING: (4768124) : ERROR: 'EXCEPTION ACCESS VIOLATION' (assert: 1)]]</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>EXCEPTION_ACCESS_VIOLATION</code> 错误但没有错误码,尝试在运行 [[HLMV|模型浏览器]] 的同时编译。
* <code>WARNING: Bad collision model, check your smoothing groups!!!</code>
* 错误 <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.
: 如果你使用XSI来创建碰撞模型,你需要关闭 Geometry Approximation's Automatic Discontinuity 选项(Explorer -> Your Mesh -> Geometry Approximation -> Polygon Mesh -> Discontinuity -> Untick Automatic) 让平滑组(smoothing groups)能够被正确地导出.
{{note|If disabling automatic discontinuity doesn't work, try making your collision model simpler.}}
{{note:zh-cn|如果关闭了automatic discontinuity 选项还是不能正常工作,尝试简化你的碰撞模型。}}
* <code>WARNING: Model  has 2-dimensional geometry (less than 0.500 inches thick on any axis)!!!</code>
* 错误 <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]
: 当碰撞模型的一个或多个面不在同一个平滑组中会导致该错误。解决方法只需把所有的面分配到 smoothing group 1(因为你只能使用一个平滑组)中即可。非常感谢 Vaenyc 的  [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.)
: 当碰撞模型的构件太小时也会出现该错误。它还可能与缩放模型的 [[$scale]] 命令有关,尤其是在重编译全尺寸的 [[3D Skybox|3D天空盒]] 时。(在这种情况下,把碰撞模型替换为一个空模型也是可行的,因为天空盒通常不需要碰撞体积)
* <code>Bounding box out of range</code>
* 错误 <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.
: 编译错误 '''''"bounding box out of range"''''' 后面跟着一串坐标,表示碰撞模型超出了允许的最大值;各方向上的最大值固定为16384单位。错误通常发生在,你把模型放大得过大导致碰撞体积超出了上限,或者你的动画让碰撞范围超过了最大值时。
: {{tip|A solution might be to divide the model into several smaller pieces if possible.}}
: {{tip:zh-cn|一个解决方案是,在可行情况下,把你的模型分割成几个小模型。}}
: 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 ==
== SDK 中的样例 ==


The SDK has numerous sample models, including several fully-articulated characters and players. They can be found at <code>sourcesdk_content\<game>\modelsrc\</code>.
SDK 中有许多样例模型,包括几个完整的人物和玩家模型。可以在 <code>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>}}
{{note:zh-cn|求生之路和求生之路2的模型位于 <code><game>\sdk_content\modelsrc\</code>}}
; <code>sdk</code>
; <code>sdk</code>
: Complete SMD source for both player models in [[Day of Defeat: Source]].
: 完整的 SMD 人物模型源文件 [[Day of Defeat: Source|胜利之日:起源]].
; <code>tf</code>
; <code>tf</code>
: Complete, but outdated, [[DMX]] source for all TF2 classes. Rigged [[reference mesh|reference meshes]] are also available as [[SMD]] and [[Maya]].
: 完整的,过时的,各类 [[DMX]] 格式军团要塞2源文件。其中Rigged模型 [[reference mesh|reference meshes]] 还提供了 [[SMD]] 格式和 [[Maya]] 格式。
; <code>generic</code>
; <code>generic</code>
: A tweaked [[ValveBiped]] rig (no meshes)
: A tweaked [[ValveBiped]] rig (no meshes)
Line 145: Line 145:
: Crumbling Ceiling dynamic prop example
: Crumbling Ceiling dynamic prop example


== See also ==
== 另见 ==
* [[Qc|QC]]
* [[Qc|QC]]
* [[:Category:QC Commands]]
* [[:Category:QC Commands]]

Revision as of 06:39, 21 December 2017

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所在文件夹的完整路径>" Template:Tip:zh-cn

句法高亮

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

创建一个QC

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

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

例子

File locations

当QC文件中存储了源文件的路径时,编译器会在同一个文件夹下寻找文件。因此你应该把一个模型的所有的源文件,放到同一个文件夹下。当然,在QC文件中,也有告诉编译器寻找在其他路径下的文件的命令。

  • 使用绝对路径 (例如 C:\modelsrc\my_model\)
  • 使用相对路径 (例如 .\subfolder..\) Template:Tip:zh-cn
  • 使用 $pushd$popd 命令

下面是一个非常简单的QC文件,用于一个没有任何动画和特殊属性的静态模型(单击某个命令以获取它的详细信息):

$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 }

你可以把这个文件作为你的模型的QC文件模板,把其中的参数换成你自己的SMD文件(或 DMX,或 FBX)看看会发生什么。

Template:Note:zh-cn

其他教程

模型编译

使用文本编辑器

编译模型最简单的方式是使用装好编译插件的高级文本编辑器。

使用批处理文件

如果你不能(或不想)用高级文本编辑器,在Windows下你可以通过把QC文件拖动到Studiomdl中来编译。Studiomdl程序位于 sourcesdk/bin/[orangebox|ep1]/bin/ 路径下。

如果创建一个 .cmd 文件来自动化地编译,这个过程会方便的多。把.txt重命名为.cmd就可以了,文件内容如下:

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

把你的QC文件拖动到CMD文件上来运行;它相当于Studiomdl程序的快捷方式。

使用编译工具

你也可以使用像 Crowbar 这样的工具来编译你的模型。只需要读取你的QC文件,选择对应的起源引擎游戏,然后点击编译按钮就可以了。

常见错误

  • 错误 Error opening <model>! (Check for write enable)
Studiomdl 遇到不存在的路径时,不会自己新建文件夹;你必须在编译前,为你的.mdl文件手动创建对应文件夹。
如果你遇到了 EXCEPTION_ACCESS_VIOLATION 错误但没有错误码,尝试在运行 模型浏览器 的同时编译。
  • 错误 WARNING: Bad collision model, check your smoothing groups!!!
如果你使用XSI来创建碰撞模型,你需要关闭 Geometry Approximation's Automatic Discontinuity 选项(Explorer -> Your Mesh -> Geometry Approximation -> Polygon Mesh -> Discontinuity -> Untick Automatic) 让平滑组(smoothing groups)能够被正确地导出.

Template:Note:zh-cn

  • 错误 WARNING: Model has 2-dimensional geometry (less than 0.500 inches thick on any axis)!!!
当碰撞模型的一个或多个面不在同一个平滑组中会导致该错误。解决方法只需把所有的面分配到 smoothing group 1(因为你只能使用一个平滑组)中即可。非常感谢 Vaenyc 的 this thread
当碰撞模型的构件太小时也会出现该错误。它还可能与缩放模型的 $scale 命令有关,尤其是在重编译全尺寸的 3D天空盒 时。(在这种情况下,把碰撞模型替换为一个空模型也是可行的,因为天空盒通常不需要碰撞体积)
  • 错误 Bounding box out of range
编译错误 "bounding box out of range" 后面跟着一串坐标,表示碰撞模型超出了允许的最大值;各方向上的最大值固定为16384单位。错误通常发生在,你把模型放大得过大导致碰撞体积超出了上限,或者你的动画让碰撞范围超过了最大值时。
Template:Tip:zh-cn
在你的模型不会与其他物件发生碰撞的情况下,似乎你也可以忽略这些错误,因为它似乎不影响游戏运行。

SDK 中的样例

在 SDK 中有许多样例模型,包括几个完整的人物和玩家模型。可以在 sourcesdk_content\<game>\modelsrc\ 中找到。 Template:Note:zh-cn

sdk
完整的 SMD 人物模型源文件 胜利之日:起源.
tf
完整的,过时的,各类 DMX 格式军团要塞2源文件。其中Rigged模型 reference meshes 还提供了 SMD 格式和 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

另见