$bodygroup

From Valve Developer Community
Revision as of 14:43, 25 February 2021 by MrFunreal (talk | contribs) (added example of animated bodygroup. Added it here because its more relevant here, as opposed to the animation event page)
Jump to navigation Jump to search

Template:Otherlang2

$bodygroup is a QC command that defines a group of meshes that can be turned on or off, or changed entirely. Server code can change their state.

Note.pngNote:Body groups cannot change skeletons or collision models.

Example

This body group allows a weapon to have iron sights, laser sights, or no sights at all:

$bodygroup sights
{
	studio ironsights
	studio laser_dot
	blank
}

This body group defines the entire chest region of the model, which spans multiple bones:

$bodygroup chest
{
	studio chest_with_no_armor
	studio chest_with_light_armor
	studio chest_with_heavy_armor
	studio chest_with_super_armor
}
Note.pngNote:Since body group polygons never share vertices with the base mesh in Source models, there need not be seams between properly-made components.

Bodygroups in Level of Detail Meshes

Using Level of Detail meshes - especially for high-poly geometry - is highly recommended. Body groups can be used in $lod strings in the same method as normal geometry meshes:

$lod 12
{
	replacemodel chest_with_no_armor chest_with_no_armor_lod1
	replacemodel chest_with_light_armor chest_with_light_armor_lod1
	replacemodel chest_with_heavy_armor chest_with_heavy_armor_lod1
	replacemodel chest_with_super_armor chest_with_super_armor_lod1
}

$lod 18
{
	replacemodel chest_with_no_armor chest_with_no_armor_lod2
	replacemodel chest_with_light_armor chest_with_light_armor_lod2
	replacemodel chest_with_heavy_armor chest_with_heavy_armor_lod2
	replacemodel chest_with_super_armor chest_with_super_armor_lod2
}
$shadowlod
{
	replacemodel chest_with_no_armor chest_with_no_armor_lod2
	replacemodel chest_with_light_armor chest_with_light_armor_lod2
	replacemodel chest_with_heavy_armor chest_with_heavy_armor_lod2
	replacemodel chest_with_super_armor chest_with_super_armor_lod2
}

Programming

To change a body group's state:

static int BodyGroup_Sights = FindBodygroupByName("sights"); // calculate this value once
SetBodygroup( BodyGroup_Sights , 1 ); // laser dot

By default, CBaseAnimating supports 4,294,967,296 combinations (32 bits), and CBaseViewModel supports 256 (8 bits). You can raise either of these by editing the relevant SendProp for m_nBody.

To calculate how many combinations you need, multiply the size of all your bodygroups together. The examples on this page total 3 * 4 = 12...but add two more groups the same size and you're up at 144. The figure grows exponentially.

Swithing bodygroup via $Sequence

It is possible to swap bodygroups during sequences, using the following event:

 AE_CL_BODYGROUP_SET_VALUE <frame> "<bodygroup name> <body>"
Note.pngNote:So far only tested in Left 4 Dead 2. Seems to be buggy and unreliable.

Example:

 $bodygroup "travel"
 {
 	studio "delorean_Notravel.smd"
 	studio "Delorean_Yestravel.smd"
 	blank
 }
 $sequence "charger_escape_b" {
 	"racecar_anims\charger_escape_b.smd"
 	{ event AE_CL_BODYGROUP_SET_VALUE 0   "travel 0" }  // On frame 0   Sets model to show body 0 (first variant) of the "Travel" Bodygroup. Being "delorean_Notravel.smd"
 	{ event AE_CL_BODYGROUP_SET_VALUE 50  "travel 1" }  // On frame 50  Sets model to show body 1 of the same bodygroup. Being "Delorean_Yestravel.smd"
 	{ event AE_CL_BODYGROUP_SET_VALUE 220 "travel 2" }  // On frame 220 Sets model to show body 2 of the same bodygroup. Being "Nothing"
 }

The above example has been taken from this Jimmy Gibbs racecar mod. Howe