Viewmodel: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
(redone)
Line 1: Line 1:
[[Image:hl2-1.jpg|thumb|300px|right|The shotgun in the picture is a typical viewmodel.]]
[[File:Shotgun vm.jpg|thumb|A viewmodel on-screen.]]
[[File:v_shotgun_hlmv.jpg|thumb|Elongation is common.]]


A '''viewmodel''' is a special type of [[model]] used only to represent the player's current weapon in the first-person view. Viewmodels are animated to show the players hands operating the weapon in response to player inputs. Viewmodels have no collision properties or any kind of presence in the World; they exist only as part of the player's HUD. The only reason they're not 2D [[sprite]]s is so they can reflect World lighting ([[cubemaps]]). In multiplayer, each [[Player Entity]] and his current weapon are represented to other players using Worldmodels: an npc_model and a w_weapon model respectively.
A '''viewmodel''' is a special [[model]] used by the viewmodel entity to represent the player's active weapon in first-person view (as opposed to the ordinary "worldmodel" used elsewhere). Because they appear so prominently on the screen and are only seen from a limited set of angles, viewmodels generally have the following distinguishing features:


== Characteristics of viewmodels ==
# Parts that the player will never see are removed
[[Image:v_shotgun_hlmv.jpg|thumb|300px|right|The same model seen from another angle]]
# Parts that the player does see are very detailed
# The model as a whole is distorted to look its best from the one viewing angle


* A viewmodel is usually modelled in high detail and uses high resolution textures with expensive shaders.
Although the viewmodel entity does exist on the server, it is only positioned in the world on the client. The only time a viewmodel has any interaction with the world is when emitting client-side visual effects (e.g. tracers from the muzzle).
* Backfaces of the model - that the player isn't going to see - are often deleted to increase the performance a little bit.
 
* Viewmodels have no physical properties (like $surfaceprop) or a $collisionmodel.
{{tip|By default, Viewmodels are drawn with a 54° field of view. This is considerably lower than the world view's default of 75°.}}
* Viewmodels are rigged for human handling and animated to a high level of detail.
 
* The viewmodel version of a weapon is prefixed with '''v_''' to distinguish it from the worldmodel version (used by NPCs) which starts with '''w_'''; eg: <code>v_shotgun.mdl</code> and <code>w_shotgun.mdl</code>.
== Creating a viewmodel ==
 
Three golden rules:
 
* You must attach a sequence to the <code>ACT_VM_IDLE</code> [[activity]] before the model will appear.
* You should use [[$origin]] to adjust the location of the model, or it will be drawn in the centre of screen.
* In your modelling package, create a camera at the appropriate position and keep it visible while you work.
 
=== Basic activities ===
 
<div style="max-height:25em;overflow:auto;">
<source lang=cpp>
ACT_VM_DRAW,
ACT_VM_HOLSTER,
ACT_VM_IDLE,
ACT_VM_FIDGET,
ACT_VM_PULLBACK,
ACT_VM_PULLBACK_HIGH,
ACT_VM_PULLBACK_LOW,
ACT_VM_THROW,
ACT_VM_PULLPIN,
ACT_VM_PRIMARYATTACK, // fire
ACT_VM_SECONDARYATTACK, // alt. fire
ACT_VM_RELOAD,
ACT_VM_DRYFIRE, // fire with no ammo loaded.
ACT_VM_HITLEFT, // bludgeon, swing to left - hit (primary attk)
ACT_VM_HITLEFT2, // bludgeon, swing to left - hit (secondary attk)
ACT_VM_HITRIGHT, // bludgeon, swing to right - hit (primary attk)
ACT_VM_HITRIGHT2, // bludgeon, swing to right - hit (secondary attk)
ACT_VM_HITCENTER, // bludgeon, swing center - hit (primary attk)
ACT_VM_HITCENTER2, // bludgeon, swing center - hit (secondary attk)
ACT_VM_MISSLEFT, // bludgeon, swing to left - miss (primary attk)
ACT_VM_MISSLEFT2, // bludgeon, swing to left - miss (secondary attk)
ACT_VM_MISSRIGHT, // bludgeon, swing to right - miss (primary attk)
ACT_VM_MISSRIGHT2, // bludgeon, swing to right - miss (secondary attk)
ACT_VM_MISSCENTER, // bludgeon, swing center - miss (primary attk)
ACT_VM_MISSCENTER2, // bludgeon, swing center - miss (secondary attk)
ACT_VM_HAULBACK, // bludgeon, haul the weapon back for a hard strike (secondary attk)
ACT_VM_SWINGHARD, // bludgeon, release the hard strike (secondary attk)
ACT_VM_SWINGMISS,
ACT_VM_SWINGHIT,
ACT_VM_IDLE_TO_LOWERED,
ACT_VM_IDLE_LOWERED,
ACT_VM_LOWERED_TO_IDLE,
ACT_VM_RECOIL1,
ACT_VM_RECOIL2,
ACT_VM_RECOIL3,
ACT_VM_PICKUP,
ACT_VM_RELEASE,
 
ACT_VM_ATTACH_SILENCER,
ACT_VM_DETACH_SILENCER,
</source>
</div>


== See also ==
== See also ==
* [[Viewmodels in XSI|Creating Viewmodels]]
 
* [[Adding Mesh To Existing Viewmodels]]
* [[Viewmodels in XSI]]
* [[Viewmodels in Blender|Creating Viewmodels in Blender]]
* [[Viewmodels in Blender]]
* [[Creating worldmodels from viewmodels]]
* [[Creating worldmodels from viewmodels]]
* [http://calebsewell.com/blog/?page_id=14 Weapon ViewModel Implementation Tutorial (Using XSI)]
* <code>[[CBaseViewModel]]</code>
 
 


[[Category:Glossary]]
[[Category:Glossary]]

Revision as of 11:54, 6 December 2010

A viewmodel on-screen.
Elongation is common.

A viewmodel is a special model used by the viewmodel entity to represent the player's active weapon in first-person view (as opposed to the ordinary "worldmodel" used elsewhere). Because they appear so prominently on the screen and are only seen from a limited set of angles, viewmodels generally have the following distinguishing features:

  1. Parts that the player will never see are removed
  2. Parts that the player does see are very detailed
  3. The model as a whole is distorted to look its best from the one viewing angle

Although the viewmodel entity does exist on the server, it is only positioned in the world on the client. The only time a viewmodel has any interaction with the world is when emitting client-side visual effects (e.g. tracers from the muzzle).

Tip.pngTip:By default, Viewmodels are drawn with a 54° field of view. This is considerably lower than the world view's default of 75°.

Creating a viewmodel

Three golden rules:

  • You must attach a sequence to the ACT_VM_IDLE activity before the model will appear.
  • You should use $origin to adjust the location of the model, or it will be drawn in the centre of screen.
  • In your modelling package, create a camera at the appropriate position and keep it visible while you work.

Basic activities

ACT_VM_DRAW,
ACT_VM_HOLSTER,
ACT_VM_IDLE,
ACT_VM_FIDGET,
ACT_VM_PULLBACK,
ACT_VM_PULLBACK_HIGH,
ACT_VM_PULLBACK_LOW,
ACT_VM_THROW,
ACT_VM_PULLPIN,
ACT_VM_PRIMARYATTACK,		// fire
ACT_VM_SECONDARYATTACK,		// alt. fire
ACT_VM_RELOAD,			
ACT_VM_DRYFIRE,				// fire with no ammo loaded.
ACT_VM_HITLEFT,				// bludgeon, swing to left - hit (primary attk)
ACT_VM_HITLEFT2,			// bludgeon, swing to left - hit (secondary attk)
ACT_VM_HITRIGHT,			// bludgeon, swing to right - hit (primary attk)
ACT_VM_HITRIGHT2,			// bludgeon, swing to right - hit (secondary attk)
ACT_VM_HITCENTER,			// bludgeon, swing center - hit (primary attk)
ACT_VM_HITCENTER2,			// bludgeon, swing center - hit (secondary attk)
ACT_VM_MISSLEFT,			// bludgeon, swing to left - miss (primary attk)
ACT_VM_MISSLEFT2,			// bludgeon, swing to left - miss (secondary attk)
ACT_VM_MISSRIGHT,			// bludgeon, swing to right - miss (primary attk)
ACT_VM_MISSRIGHT2,			// bludgeon, swing to right - miss (secondary attk)
ACT_VM_MISSCENTER,			// bludgeon, swing center - miss (primary attk)
ACT_VM_MISSCENTER2,			// bludgeon, swing center - miss (secondary attk)
ACT_VM_HAULBACK,			// bludgeon, haul the weapon back for a hard strike (secondary attk)
ACT_VM_SWINGHARD,			// bludgeon, release the hard strike (secondary attk)
ACT_VM_SWINGMISS,
ACT_VM_SWINGHIT,
ACT_VM_IDLE_TO_LOWERED,
ACT_VM_IDLE_LOWERED,
ACT_VM_LOWERED_TO_IDLE,
ACT_VM_RECOIL1,
ACT_VM_RECOIL2,
ACT_VM_RECOIL3,
ACT_VM_PICKUP,
ACT_VM_RELEASE,

ACT_VM_ATTACH_SILENCER,
ACT_VM_DETACH_SILENCER,

See also