Body Groups

From Valve Developer Community
Revision as of 12:44, 3 June 2006 by Kenb (talk | contribs)
Jump to navigation Jump to search

Body Groups

Body Groups are sub-meshes of a model that can have changable states. Server code can change the state a model's body groups.

To define a body groups, you need to add a lines in the .qc.

$bodygroup (name)
{
	studio (modelname)
	["studio" modelname]
	[blank]
}

For example (a single .mdl could be used for characters with and without glasses):

$bodygroup studio
{
	studio "dude.smd"
}

$bodygroup eyewear
{
	studio "glasses.smd"
	blank
}

This example has two body groups numbered 0 and 1. Group 0 uses a single mesh and group 1 uses 2, a model of a pair of glasses (state 0) and the built-in "no-polygons" model (state 1) which is used to "turn-off" the glasses.

You can have multiple entries in a bodygroup, for example you could have 4 different sets of the chest, each with different styles:

$bodygroup chest
{
	studio "chest_with_no_armor.smd"
	studio "chest_with_light_armor.smd"
	studio "chest_with_heavy_armor.smd"
	studio "chest_with_super_armor.smd"
}

You could also just put the armor pieces in their own group and always draw the underlying chest without armor, but it's less efficient and often there's no clean "base" set, such as if you're using bodygroups to define multiple heads.

The models used in bodygroups can span any number of bones.

To change a body group's state call CBaseAnimating::SetBodygroup( int iGroup, int iValue ) in server code. For example, this would randomly give 1 out of 5 characters glasses:

SetBodyGroup( 1, ( RandInt( 1, 5 ) == 1 )?1:0 );

Bodygroups are limited to 32 bits of combinations, which is a total of 4,294,967,296 combinations. If you used the above eyewear and chest examples, the total combinations would be eyewear x chest, or 2 x 4, or a total of 8 combinations. Just multiply all your bodygroup combinations together to make sure your total is less than the max. Weapons by default are limited to 256 combinations, though it's just a network limit which is easy for your mod to change. See:

BEGIN_NETWORK_TABLE_NOBASE(CBaseViewModel, DT_BaseViewModel)
...
SendPropInt		(SENDINFO(m_nBody), 8),

See also