$bodygroup: Difference between revisions
m (Multipage removal)  | 
				 (Removing deprecated Category)  | 
				||
| (5 intermediate revisions by 4 users not shown) | |||
| Line 1: | Line 1: | ||
{{LanguageBar|title = $bodygroup}}  | {{LanguageBar|title = $bodygroup}}{{tabsBar|main=gs|base=$bodygroup}}  | ||
{{this is a|QC command|name=$bodygroup}}  | {{this is a|QC command|name=$bodygroup}} It defines a group of meshes that can be turned on or off, or changed entirely. Server code can change their state.  | ||
{{toc-right}}  | {{toc-right}}  | ||
{{note|Body groups '''cannot''' change [[skeleton|skeletons]] or [[collision model|collision models]].}}  | {{note|Body groups '''cannot''' change [[skeleton|skeletons]] or [[collision model|collision models]].}}  | ||
| Line 14: | Line 12: | ||
$bodygroup sights  | $bodygroup sights  | ||
{  | {  | ||
	studio ironsights  | 	studio "ironsights"  | ||
	studio laser_dot  | 	studio "laser_dot"  | ||
	blank  | 	blank  | ||
}  | }  | ||
| Line 25: | Line 23: | ||
$bodygroup chest  | $bodygroup chest  | ||
{  | {  | ||
	studio chest_with_no_armor  | 	studio "chest_with_no_armor"  | ||
	studio chest_with_light_armor  | 	studio "chest_with_light_armor"  | ||
	studio chest_with_heavy_armor  | 	studio "chest_with_heavy_armor"  | ||
	studio chest_with_super_armor  | 	studio "chest_with_super_armor"  | ||
}  | }  | ||
</source>  | </source>  | ||
| Line 41: | Line 39: | ||
$lod 12  | $lod 12  | ||
{  | {  | ||
	replacemodel chest_with_no_armor chest_with_no_armor_lod1  | 	replacemodel "chest_with_no_armor" "chest_with_no_armor_lod1"  | ||
	replacemodel chest_with_light_armor chest_with_light_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_heavy_armor" "chest_with_heavy_armor_lod1"  | ||
	replacemodel chest_with_super_armor chest_with_super_armor_lod1  | 	replacemodel "chest_with_super_armor" "chest_with_super_armor_lod1"  | ||
}  | }  | ||
$lod 18  | $lod 18  | ||
{  | {  | ||
	replacemodel chest_with_no_armor chest_with_no_armor_lod2  | 	replacemodel "chest_with_no_armor" "chest_with_no_armor_lod2"  | ||
	replacemodel chest_with_light_armor chest_with_light_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_heavy_armor" "chest_with_heavy_armor_lod2"  | ||
	replacemodel chest_with_super_armor chest_with_super_armor_lod2  | 	replacemodel "chest_with_super_armor" "chest_with_super_armor_lod2"  | ||
}  | }  | ||
$shadowlod  | $shadowlod  | ||
{  | {  | ||
	replacemodel chest_with_no_armor chest_with_no_armor_lod2  | 	replacemodel "chest_with_no_armor" "chest_with_no_armor_lod2"  | ||
	replacemodel chest_with_light_armor chest_with_light_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_heavy_armor" "chest_with_heavy_armor_lod2"  | ||
	replacemodel chest_with_super_armor chest_with_super_armor_lod2  | 	replacemodel "chest_with_super_armor" "chest_with_super_armor_lod2"  | ||
}  | }  | ||
</source>  | </source>  | ||
| Line 68: | Line 66: | ||
<source lang=cpp>  | <source lang=cpp>  | ||
int BodyGroup_Sights = FindBodygroupByName("sights"); // calculate this value once  | |||
SetBodygroup( BodyGroup_Sights , 1 ); // laser dot  | SetBodygroup( BodyGroup_Sights , 1 ); // laser dot  | ||
</source>  | </source>  | ||
| Line 86: | Line 84: | ||
   $bodygroup "travel"  |    $bodygroup "travel"  | ||
   {  |    {  | ||
   	studio "delorean_Notravel  |    	studio "delorean_Notravel"  | ||
   	studio "Delorean_Yestravel  |    	studio "Delorean_Yestravel"  | ||
   	studio "Delorean_brokentravel  |    	studio "Delorean_brokentravel"  | ||
   }  |    }  | ||
   $sequence "charger_escape_b" {  |    $sequence "charger_escape_b" {  | ||
   	"racecar_anims  |    	"racecar_anims/charger_escape_b"  | ||
   	{ 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 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 50  "travel 1"''' }  // On frame 50  Sets model to show body 1 of the same bodygroup. Being "Delorean_Yestravel.smd"  | ||
| Line 100: | Line 98: | ||
   {  |    {  | ||
   	blank			 // Disabled state  |    	blank			 // Disabled state  | ||
   	studio "myBodyGroup  |    	studio "myBodyGroup" // Enabled  state  | ||
   }  |    }  | ||
   $sequence "Sequence_1" {  |    $sequence "Sequence_1" {  | ||
   	"anims  |    	"anims/Thing_1"  | ||
   	{ event '''AE_CL_ENABLE_BODYGROUP 10 "Bodygroup_1"''' }  // On Frame 10 Enables bodygroup_1    |    	{ event '''AE_CL_ENABLE_BODYGROUP 10 "Bodygroup_1"''' }  // On Frame 10 Enables bodygroup_1    | ||
   }  |    }  | ||
   $sequence "Sequence_2" {  |    $sequence "Sequence_2" {  | ||
   	"anims  |    	"anims/Thing_2"  | ||
   	{ event '''AE_CL_DISABLE_BODYGROUP 50 "Bodygroup_1"''' }  // On Frame 50 Disables bodygroup_1     |    	{ event '''AE_CL_DISABLE_BODYGROUP 50 "Bodygroup_1"''' }  // On Frame 50 Disables bodygroup_1     | ||
   }  |    }  | ||
Latest revision as of 20:09, 16 July 2025
$bodygroup  is a   QC command  available in all 
 Source games. It defines a group of meshes that can be turned on or off, or changed entirely. Server code can change their state.
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"
}
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:
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.
Switching bodygroup via $Sequence
It is possible to swap bodygroups during sequences, using the following event:
- AE_CL_BODYGROUP_SET_VALUE <frame> "<bodyGroupName> <body>"
 - AE_CL_ENABLE_BODYGROUP <frame> "<bodyGroupName>"
 - AE_CL_DISABLE_BODYGROUP <frame> "<bodyGroupName>"
 
Examples:
 $bodygroup "travel"
 {
 	studio "delorean_Notravel"
 	studio "Delorean_Yestravel"
 	studio "Delorean_brokentravel"
 }
 $sequence "charger_escape_b" {
 	"racecar_anims/charger_escape_b"
 	{ 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 "Delorean_brokentravel"
 }
 $bodygroup "Bodygroup_1" 
 {
 	blank			 // Disabled state
 	studio "myBodyGroup" // Enabled  state
 }
 $sequence "Sequence_1" {
 	"anims/Thing_1"
 	{ event AE_CL_ENABLE_BODYGROUP 10 "Bodygroup_1" }  // On Frame 10 Enables bodygroup_1 
 }
   
 $sequence "Sequence_2" {
 	"anims/Thing_2"
 	{ event AE_CL_DISABLE_BODYGROUP 50 "Bodygroup_1" }  // On Frame 50 Disables bodygroup_1  
 }