Vertex animation: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (Fixed the templates)
(Rewrite Template:Lang to Template:LanguageBar. This action was performed by a bot.)
 
(11 intermediate revisions by 5 users not shown)
Line 1: Line 1:
'''Vertex animation''' is the keyframed animation of individual [[vertex|vertices]] of a mesh. It's good for very complicated motion like that of cloth, hair, or water. It uses a flex controller bone to move the model through a series of flexes (one for each frame).
{{LanguageBar|Vertex animation}}
'''Vertex animation''' is the keyframed animation of the individual [[vertex|vertices]] of a mesh. It is useful for complex motion, such as that of cloth, hair, or water. Each frame of the vertex animation is stored as a unique flex, and a special flex controller bone drives the animation by progressing through the flexes. In this way, vertex animation is implemented as a superset of [[flex animation]]. This approach allows vertex animation to be combined with typical [[skeletal animation]], just like flex animations.


Vertex animation was added in [[Alien Swarm]] and is available in all games that branch from it, including [[Portal 2]], [[Counter-Strike: Global Offensive]], [[Source Filmmaker]], and [[Dota 2]].
{{bug|hidetested=1|Using the [[$scale]] command breaks vertex animation. {{TODO|In what way?}}}}
{{todo|Check if vertex animation was actually added in L4D or L4D2}}
{{bug|Using the [[$scale]] command breaks vertex animation.}}




== Implementation ==
==Availability==
{{todo | CLEANUP! OUTDATED!}}
Vertex animation was added in {{as|4.1}} and is available in all games that branch from it, including {{portal2|4}}, {{sfm|4}}, {{csgo|4}}, and {{dota2|4}}. Starting with Alien Swarm, the v49 MDL format (IDST1) was extended to include the additional data required for vertex animation. Only Alien Swarm's studiomdl or newer (SFM, Portal 2, etc) can compile v49 MDLs with vertex animation. Studiomdls from earlier IDST1 games, including {{l4d|4.1}} and {{l4d2|4.1}}, compile v49 MDLs but do '''not''' support vertex animation.
# Create a vertex animation in your modelling tool.
 
# Export a Vertex Cache file. Currently only the official Maya exporter can do this, and only to SMD.
{{todo|Check if technological support for vertex animation is truly absent from L4D/L4D2 or if exists but is simply unused}}
# Add the <code>vcafile</code> command to your [[$model (QC)|$model]] block (see example below).
 
{{Note | DMX does not require a vertex cache file, so if you're using DMX ignore these two steps. The vertex animation data can be exported by Blender Source Tools to DMX.}}
====Vertex Animation in Other Games====
Some games on older engine branches may support vertex animation through backported or custom implementations. Such games include:
* {{gmod|4}} supports vertex animation (since update 2021.06.09) on its own non-standard v48 MDL format '''and''' on v49 MDLs compiled with Alien Swarm, Source Filmmaker, or similar. Gmod's studiomdl creates MDLs that extend the {{src13|4.1}} v48 MDL format with additional features, including vertex animation. These non-standard v48 MDLs are '''not''' compatible with other games. Gmod's studiomdl does '''not''' create v49 MDLs.
 
==Compiling Models with Vertex Animation==
===Using SMD===
* Create a vertex animation with your modeling package.
* Export a Vertex Cache file. Currently, only the official Maya exporter can do this.
* Include the vertex cache file in your <code>[[$model (QC)|$model]]</code> block with the <code>vcafile</code> command (see example below).
<syntaxhighlight lang=php>
$model "body" "reference_mesh.smd" {
vcafile "my_vertex_animation.vta"
}
</syntaxhighlight>


This produces two flex controllers named after your VCA file. The first defines the blend weight of the animation, the second (prefixed with <code>multi_</code>) defines the active frame.
This produces two flex controllers named after your VCA file. The first defines the blend weight of the animation, the second (prefixed with <code>multi_</code>) defines the active frame.


A programmer can now control your animation. If you need to map the vertex animation to a standard animation sequence, perform these extra steps:
A programmer can now control your vertex animation. If you want to use your vertex animation like an ordinary <code>[[$sequence]]</code>, you must define and animate a special driver bone. See the next section, '''Driving Vertex Animations'''.
 
===Using DMX===
* The DMX format can store vertex animations with the reference mesh and does not require an additional VCA file.
* Configure your modeling package to include your vertex animation in the DMX export. You can include multiple vertex animations in a single DMX file.
:* In Blender Source Tools, use the '''Vertex Animation''' options under Scene > Source Engine Exportables.
* The exported DMX file contains both the reference mesh and one or more vertex animation(s). Use [[$model (QC)|$model]] to include the DMX file (see example below).
<syntaxhighlight lang=php>
$model "body" "reference_mesh_animated.dmx"
</syntaxhighlight>
 
==Driving Vertex Animations==
A standard <code>[[$sequence]]</code> can drive a vertex animation without the need for a programmer. The position of a special driver bone in your model's skeleton is used to specify the frame and intensity of the vertex animation. By animating the driver bone, you can play the vertex animation, as well as combine it with regular skeletal animation.


# Add a new bone which will drive the vertex animation. It doesn't need to have any vertices attached.
* In your modeling package, create a bone at the origin (0,0,0). You do not have to weight any vertices to it.
# Add two <code>[[$boneflexdriver]]</code> commands to bind your vertex animation to the new bone (see example).
:* Alternatively, you can use <code>[[$definebone]]</code> in your QC file.
# Add at least one <code>[[$sequence]]</code> in which the new bone is animated in its X and Y axes. Its X position defines the blend weight of the vertex animation (0-1), and its Y position defines the frame of vertex animation (0-1). {{bug|Currently the flex driver sequence ''must'' be defined with [[$upaxis|$upaxis Y]]. This doesn't affect the rest of the model.}}
* Add two <code>[[$boneflexdriver]]</code> commands to bind your vertex animation to the driver bone. '''Each command requires specific names and parameters.''' Refer to the QC example below.
:* The first <code>$boneflexdriver</code> must use axis <code>tx</code> and the name of your vcafile (or, if using DMX, the name of the vertex animation block inside the DMX).
:* The second <code>$boneflexdriver</code> must use axis <code>ty</code> and the name of the your vcafile with "multi_" prepended.
* Add at least one <code>[[$sequence]]</code> in which the driver bone is animated on its X and Y axes.
:* The driver bone's X position sets the blend weight (i.e. intensity) of the vertex animation, from 0.0 to 1.0.
:* Its Y position sets the progress of vertex animation, from 0.0 to 1.0.
::* For example, if your vertex animation is 120 frames long, frame 90 will be displayed when the driver bone's Y position is 0.75.
::* If your modeling package is a Z-up world (like Blender or 3ds Max), you may need to translate the driver bone along its '''Z''' axis instead of Y. See the bug note below.


== Example ==
{{bug|hidetested=1|Currently the flex driver sequence '''must''' be defined with [[$upaxis|$upaxis Y]]. This doesn't affect the rest of the model.}}


===QC Example===
<syntaxhighlight lang=php>
<syntaxhighlight lang=php>
$model "body" "ref_mesh.smd" {
$model "body" "reference_mesh.smd" {
vcafile "vertex_animation.vta"
vcafile "my_vertex_animation.vta"
}
}
// If using DMX instead:
// $model "body" "reference_mesh_animated.dmx"


// Optional:
$definebone "vertexAnimDriver" "" 0 0 0 0 0 0


$boneflexdriver "flexAnimBone" tx "vertex_animation" 0 1
$boneflexdriver "vertexAnimDriver" tx "my_vertex_animation" 0 1
$boneflexdriver "flexAnimBone" ty "multi_vertex_animation" 0 1
$boneflexdriver "vertexAnimDriver" ty "multi_my_vertex_animation" 0 1
// "my_vertex_animation" is the name of the vcafile when using SMD (or name of the vertex animation block embedded in the DMX when using DMX)


$upaxis Y // currently flex driver sequences must be Y-up
$upaxis Y // currently flex driver sequences must be Y-up
$sequence "vertex_animation" "flexAnimBone_anim.smd"
$sequence "idle" {
"vertexAnimDriver_anim.smd" // SMD animation which moves the "vertexAnimDriver" bone
fps 30
}
</syntaxhighlight>
</syntaxhighlight>


== Example Videos ==
==Example Videos==
* [http://www.youtube.com/watch?v=O2iZZHwDcZg A simple video showing the use of Vertex animation for hair.]
* [http://www.youtube.com/watch?v=O2iZZHwDcZg A simple video showing the use of Vertex animation for hair.]
* [http://www.youtube.com/watch?v=0ZZ8xH_nvX0 A simple video showing the use of Vertex animation for cloth.]
* [http://www.youtube.com/watch?v=0ZZ8xH_nvX0 A simple video showing the use of Vertex animation for cloth.]
* [http://www.youtube.com/watch?v=r5aV5C6kryU Example of vertex animation in Source Filmmaker.]
* [http://www.youtube.com/watch?v=r5aV5C6kryU Example of vertex animation in Source Filmmaker.]
* [https://www.youtube.com/watch?v=cP3M0Vu-_7I&feature=youtu.be Example of vertex animation in Portal 2's HLMV.]  
* [https://www.youtube.com/watch?v=cP3M0Vu-_7I&feature=youtu.be Example of vertex animation in Portal 2's HLMV.]  
== See also ==


==See also==
* <code>[[$boneflexdriver]]</code>
* <code>[[$boneflexdriver]]</code>
* [[Flex animation]]
* [[Skeletal animation]]
* [[Skeletal animation]]
* [[Flex animation]]
 
[[Category:Modeling]]
[[Category:Modeling]]

Latest revision as of 17:42, 18 July 2025

English (en)Translate (Translate)

Vertex animation is the keyframed animation of the individual vertices of a mesh. It is useful for complex motion, such as that of cloth, hair, or water. Each frame of the vertex animation is stored as a unique flex, and a special flex controller bone drives the animation by progressing through the flexes. In this way, vertex animation is implemented as a superset of flex animation. This approach allows vertex animation to be combined with typical skeletal animation, just like flex animations.

Icon-Bug.pngBug:Using the $scale command breaks vertex animation.
Todo: In what way?


Availability

Vertex animation was added in Alien Swarm Alien Swarm and is available in all games that branch from it, including Portal 2 Portal 2, Source Filmmaker Source Filmmaker, Counter-Strike: Global Offensive Counter-Strike: Global Offensive, and Dota 2 Dota 2. Starting with Alien Swarm, the v49 MDL format (IDST1) was extended to include the additional data required for vertex animation. Only Alien Swarm's studiomdl or newer (SFM, Portal 2, etc) can compile v49 MDLs with vertex animation. Studiomdls from earlier IDST1 games, including Left 4 Dead Left 4 Dead and Left 4 Dead 2 Left 4 Dead 2, compile v49 MDLs but do not support vertex animation.

Todo: Check if technological support for vertex animation is truly absent from L4D/L4D2 or if exists but is simply unused

Vertex Animation in Other Games

Some games on older engine branches may support vertex animation through backported or custom implementations. Such games include:

  • Garry's Mod Garry's Mod supports vertex animation (since update 2021.06.09) on its own non-standard v48 MDL format and on v49 MDLs compiled with Alien Swarm, Source Filmmaker, or similar. Gmod's studiomdl creates MDLs that extend the Source 2013 Source 2013 v48 MDL format with additional features, including vertex animation. These non-standard v48 MDLs are not compatible with other games. Gmod's studiomdl does not create v49 MDLs.

Compiling Models with Vertex Animation

Using SMD

  • Create a vertex animation with your modeling package.
  • Export a Vertex Cache file. Currently, only the official Maya exporter can do this.
  • Include the vertex cache file in your $model block with the vcafile command (see example below).
$model "body" "reference_mesh.smd" {
	vcafile "my_vertex_animation.vta"
}

This produces two flex controllers named after your VCA file. The first defines the blend weight of the animation, the second (prefixed with multi_) defines the active frame.

A programmer can now control your vertex animation. If you want to use your vertex animation like an ordinary $sequence, you must define and animate a special driver bone. See the next section, Driving Vertex Animations.

Using DMX

  • The DMX format can store vertex animations with the reference mesh and does not require an additional VCA file.
  • Configure your modeling package to include your vertex animation in the DMX export. You can include multiple vertex animations in a single DMX file.
  • In Blender Source Tools, use the Vertex Animation options under Scene > Source Engine Exportables.
  • The exported DMX file contains both the reference mesh and one or more vertex animation(s). Use $model to include the DMX file (see example below).
$model "body" "reference_mesh_animated.dmx"

Driving Vertex Animations

A standard $sequence can drive a vertex animation without the need for a programmer. The position of a special driver bone in your model's skeleton is used to specify the frame and intensity of the vertex animation. By animating the driver bone, you can play the vertex animation, as well as combine it with regular skeletal animation.

  • In your modeling package, create a bone at the origin (0,0,0). You do not have to weight any vertices to it.
  • Alternatively, you can use $definebone in your QC file.
  • Add two $boneflexdriver commands to bind your vertex animation to the driver bone. Each command requires specific names and parameters. Refer to the QC example below.
  • The first $boneflexdriver must use axis tx and the name of your vcafile (or, if using DMX, the name of the vertex animation block inside the DMX).
  • The second $boneflexdriver must use axis ty and the name of the your vcafile with "multi_" prepended.
  • Add at least one $sequence in which the driver bone is animated on its X and Y axes.
  • The driver bone's X position sets the blend weight (i.e. intensity) of the vertex animation, from 0.0 to 1.0.
  • Its Y position sets the progress of vertex animation, from 0.0 to 1.0.
  • For example, if your vertex animation is 120 frames long, frame 90 will be displayed when the driver bone's Y position is 0.75.
  • If your modeling package is a Z-up world (like Blender or 3ds Max), you may need to translate the driver bone along its Z axis instead of Y. See the bug note below.
Icon-Bug.pngBug:Currently the flex driver sequence must be defined with $upaxis Y. This doesn't affect the rest of the model.

QC Example

$model "body" "reference_mesh.smd" {
	vcafile "my_vertex_animation.vta"
}
// If using DMX instead:
// 	$model "body" "reference_mesh_animated.dmx"

$definebone "vertexAnimDriver" "" 0 0 0 0 0 0

$boneflexdriver "vertexAnimDriver" tx "my_vertex_animation" 0 1
$boneflexdriver "vertexAnimDriver" ty "multi_my_vertex_animation" 0 1
// "my_vertex_animation" is the name of the vcafile when using SMD (or name of the vertex animation block embedded in the DMX when using DMX)

$upaxis Y // currently flex driver sequences must be Y-up
$sequence "idle" {
	"vertexAnimDriver_anim.smd"	// SMD animation which moves the "vertexAnimDriver" bone
	fps 30
}

Example Videos

See also