Difference between revisions of "$bodygroup"

From Valve Developer Community
Jump to: navigation, search
(Russian language link)
(Edited page to include information about $lod usage.)
 
(7 intermediate revisions by 4 users not shown)
Line 1: Line 1:
See [[Body Groups]].
+
{{otherlang2|ru=$bodygroup:ru}}
  
== Syntax ==
+
'''$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.
To define one or more body groups:
 
  
$bodygroup (name)
+
{{note|Body groups '''cannot''' change [[skeleton|skeletons]] or [[collision model|collision models]].}}
{
 
studio (modelname)
 
["studio" modelname]
 
[blank]
 
}
 
  
{{otherlang:en}}
+
== Example ==
{{otherlang:en:ru|$bodygroup:ru}}
 
  
[[Category:QC Commands|bodygroup]]__NOTOC__
+
This body group allows a weapon to have iron sights, laser sights, or no sights at all:
 +
 
 +
<source lang=php>
 +
$bodygroup sights
 +
{
 +
studio ironsights
 +
studio laser_dot
 +
blank
 +
}
 +
</source>
 +
 
 +
This body group defines the entire chest region of the model, which spans multiple bones:
 +
 
 +
<source lang=php>
 +
$bodygroup chest
 +
{
 +
studio chest_with_no_armor
 +
studio chest_with_light_armor
 +
studio chest_with_heavy_armor
 +
studio chest_with_super_armor
 +
}
 +
</source>
 +
 
 +
{{note|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 [[LOD|Level of Detail]] meshes - ''especially for high-poly geometry'' - is '''highly recommended'''. Body groups can be used in <code>[[$lod]]</code> strings in the same method as normal geometry meshes:
 +
 
 +
<source lang=php>
 +
$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
 +
}
 +
</source>
 +
 
 +
== Programming ==
 +
 
 +
To change a body group's state:
 +
 
 +
<source lang=cpp>
 +
static int BodyGroup_Sights = FindBodygroupByName("sights"); // calculate this value once
 +
SetBodygroup( BodyGroup_Sights , 1 ); // laser dot
 +
</source>
 +
 
 +
By default, <code>[[CBaseAnimating]]</code> supports 4,294,967,296 combinations (32 bits), and <code>[[CBaseViewModel]]</code> supports 256 (8 bits). You can raise either of these by editing the relevant [[SendProp]] for <code>m_nBody</code>.
 +
 
 +
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.
 +
 
 +
[[Category:QC Commands|b]]

Latest revision as of 10:11, 26 August 2019

Русский

$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: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: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.