Viewmodel: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
mNo edit summary
(Added compiling and console related info)
 
(45 intermediate revisions by 24 users not shown)
Line 1: Line 1:
[http://wwwisevil.profil.bz/lib/tvguide-online/ tvguide online] [http://gogenator.friko.pl/library/custom-wine/ custom wine cellars] [http://gogenator.friko.pl/library/ice-hockey/ ice hockey equipment shops] [http://amoresperros812.profil.in/text/katydids-candy/ katydids candy] [http://krisbabe47.ugu.pl/small/sanyo-tv.html sanyo tv] [http://andrewjvb.aboutus.vg/resources/nude-wife/ nude wife] [http://krisbabe47.ugu.pl/small/bb-gun.html bb gun] [http://krisbabe47.ugu.pl/small/online-toy.html online toy stores] [http://theiamina.w8w.pl/content/back-in.html back in black] [http://theiamina.w8w.pl/content/jenna-jamason.html jenna jamason] [http://bendxthexsky.nightmail.ru/articles/stand-up.html stand up tall] [http://theunknowntao.profil.bz/styles/hot-wives.html hot wives] [http://misssakic.profil.ms/data/shipping-car.html shipping car] [http://thesaucernews.profil.bz/genting/ genting] [http://misssakic.profil.ms/data/missy-elliott.html missy elliott] [http://theunknowntao.profil.bz/styles/throat-gagging.html throat gagging blowjobs] [http://wizzu.profil.in/new/unique-bike/ unique bike seat] [http://nehpetsca.profil.cn/new/floods/ floods] [http://cockroachkiller.nm.ru/small/white-bitches/ white bitches] [http://krisbabe47.ugu.pl/small/live-cruise.html live cruise cam] [http://twinkletoeash.profil.bz/topic/environmental-justice/ environmental justice act of 2005] [http://cah9i.friko.pl/new/anal-passions/ anal passions] [http://nehpetsca.profil.cn/new/amazing-boobs/ amazing boobs] [http://cah9i.friko.pl/new/no-mercy/ no mercy where] [http://krisbabe47.ugu.pl/small/scarborough-fair.html scarborough fair] [http://krisbabe47.ugu.pl/small/filipino-sex.html filipino sex] [http://theiamina.w8w.pl/content/diphenhydramine.html diphenhydramine] [http://lord-griever.nightmail.ru/small/american-pile/ american pile driving] [http://wwwisevil.profil.bz/lib/cpu-usage/ cpu usage] [http://krisbabe47.ugu.pl/small/air-taser.html air taser] [http://baler.ugu.pl/new/motor-home/ motor home for sale] [http://theiamina.w8w.pl/content/spanking-links.html spanking links] [http://cahert.aboutus.vg/styles/belks/ belks] [http://klgrem.aboutus.vg/library/record-label.html record label in houston] [http://eldritchrainbow.hotmail.ru/library/ziyi-zhang.html ziyi zhang] [http://gogenator.friko.pl/library/septic-tank/ septic tank problems] [http://wwwisevil.profil.bz/lib/jerk-off/ jerk off movies] [http://kinkyjedi.about.vg/text/mercury-information/ mercury information element] [http://nutribun.profil.in/resources/cum-mom/ cum mom] [http://lord-griever.nightmail.ru/small/selling-advertising/ selling advertising on websites] [http://theiamina.w8w.pl/content/amateur-links.html amateur links movie] [http://cah9i.friko.pl/new/mikhail-baryshnikov/ mikhail baryshnikov] [http://cah9i.friko.pl/new/free-amateur/ free amateur nudes] [http://gogenator.friko.pl/library/thrifty-car/ thrifty car rentals] [http://klgrem.aboutus.vg/library/lily-thai.html lily thai porn star] [http://thesaucernews.profil.bz/baby-porn/ baby porn] [http://baler.ugu.pl/new/the-stone/ the stone cutter] [http://theiamina.w8w.pl/content/jerk-off.html jerk off studs] [http://baler.ugu.pl/new/solar-pump/ solar pump] [http://baler.ugu.pl/new/adult-looney/ adult looney toon costumes] [http://krisbabe47.ugu.pl/small/deans-planet.html deans planet] [http://gogenator.friko.pl/library/middle-school/ middle school girls in the locker room] [http://theiamina.w8w.pl/content/lip-plumpers.html lip plumpers] [http://krisbabe47.ugu.pl/small/home-generator.html home generator] [http://closedforlunch.profil.in/costa-rican.html costa rican] [http://theiamina.w8w.pl/content/sims.html sims] [http://kinkyjedi.about.vg/text/diva/ diva] [http://gogenator.friko.pl/library/very-hairy/ very hairy chest] [http://theiamina.w8w.pl/content/skull-and.html skull and bones] [http://gogenator.friko.pl/library/adoption-support/ adoption support groups nj] [http://theiamina.w8w.pl/content/women-over.html women over 40] [http://gogenator.friko.pl/library/big-bear/ big bear cabin rentals] [http://gogenator.friko.pl/library/monty-hall/ monty hall probability problem] [http://gogenator.friko.pl/library/lipitor-side/ lipitor side effects] [http://cah9i.friko.pl/new/mountain-laurel/ mountain laurel] [http://thesaucernews.profil.bz/tenjho-tenge/ tenjho tenge] [http://theunknowntao.profil.bz/styles/pedo-lolita.html pedo lolita] [http://misssakic.profil.ms/data/mexican-pharmacies.html mexican pharmacies online] [http://gogenator.friko.pl/library/b-and/ b and h photo] [http://cah9i.friko.pl/new/debauchery/ debauchery] [http://twinkletoeash.profil.bz/topic/coleman-powermate/ coleman powermate] [http://yhwhadonai.profil.ms/topic/how-to.html how to spank] [http://cah9i.friko.pl/new/salon-supplies/ salon supplies] [http://wwwisevil.profil.bz/lib/dragonball-z/ dragonball z xxx] [http://nutribun.profil.in/resources/north-garland/ north garland high school garland texas] [http://cah9i.friko.pl/new/www-persiankitty/ www persiankitty com] [http://wizzu.profil.in/new/royalty-free/ royalty free kid music] [http://wwwisevil.profil.bz/lib/pornstar-lingerie/ pornstar lingerie] [http://baler.ugu.pl/new/personal-site/ personal site hosting] [http://antisilence.profil.gs/topic/toll-free/ toll free listing] [http://theiamina.w8w.pl/content/tra-cuu.html tra cuu dien thoai] [http://cah9i.friko.pl/new/oklahoma-off/ oklahoma off track betting] [http://theiamina.w8w.pl/content/filipina-pussy.html filipina pussy] [http://amoresperros812.profil.in/text/schoolgirl-hentai/ schoolgirl hentai anime uncensored] [http://theiamina.w8w.pl/content/salmon-recipes.html salmon recipes] [http://baler.ugu.pl/new/princess-cut/ princess cut diamond rings] [http://cah9i.friko.pl/new/deflowering-popping/ deflowering popping cherry] [http://theiamina.w8w.pl/content/original-oil.html original oil paintings] [http://bendxthexsky.nightmail.ru/articles/free-orgasm.html free orgasm video] [http://antilos.profil.in/html/xxx-digimon.html xxx digimon manga] [http://twinkletoeash.profil.bz/topic/bates-boots/ bates boots] [http://krisbabe47.ugu.pl/small/women-in.html women in rap videos] [http://krisbabe47.ugu.pl/small/big-butt.html big butt white girls] [http://bendxthexsky.nightmail.ru/articles/midnight.html midnight] [http://wizzu.profil.in/new/gladiators/ gladiators] [http://gogenator.friko.pl/library/stockings/ stockings] [http://tersky.profil.bz/library/car-cd.html car cd players] [http://baler.ugu.pl/new/airline-flight/ airline flight paths] [http://antisilence.profil.gs/topic/camcorderxxx/ camcorderxxx] [http://theiamina.w8w.pl/content/young-gay.html young gay penis] [http://earlysignofpregnancy.net/pregnancycalendar/wp-content/themes/default/cache/eqevga.html oregon fishing guide] [http://mesotheliomalaywer.com/yg/CSS/data/touch/nccccq.html alyssa milano adult movie] [http://instantinfocenter.com/CP/images/pic/skohlf.html hand crafted jewelry] [http://credit-report-repair.com/yg/CSS/data/cache/thwgpw.html cool wallpapers] [http://earlysignofpregnancy.net/pregnancycalendar/wp-content/themes/default/cache/inqvtb.html faerie] [http://credit-report-repair.com/yg/CSS/data/cache/umjbbs.html kids books about friendship] [http://instantinfocenter.com/CP/images/pic/eiijpd.html maui taylor] [http://earlysignofpregnancy.net/pregnancycalendar/wp-content/themes/default/cache/frhmnn.html plastic conveyors] [http://mesotheliomalaywer.com/yg/CSS/data/touch/owitul.html swat wallpapers] [http://credit-report-repair.com/yg/CSS/data/cache/pogaur.html las vegas home] [http://freeseotips.com/wp-content/themes/classic/cache/bsmoqo.html health products] [http://freeseotips.com/wp-content/themes/classic/cache/toupxi.html angelsofporn] [http://freeseotips.com/wp-content/themes/classic/cache/svljcg.html horny hentai] [http://freeseotips.com/wp-content/themes/classic/cache/erqhjj.html extreme nipples] [http://earlysignofpregnancy.net/pregnancycalendar/wp-content/themes/default/cache/lirehm.html looney toons nude] [http://earlysignofpregnancy.net/pregnancycalendar/wp-content/themes/default/cache/mjnwrc.html abc kids] [http://mesotheliomalaywer.com/yg/CSS/data/touch/hwdali.html cardinals tickets] [http://mesotheliomalaywer.com/yg/CSS/data/touch/bvphve.html kareena nude] [http://earlysignofpregnancy.net/pregnancycalendar/wp-content/themes/default/cache/qabksf.html hot latina] [http://credit-report-repair.com/yg/CSS/data/cache/fwhegp.html spirited away] [http://mesotheliomalaywer.com/yg/CSS/data/touch/urlgjv.html nude posters] [http://mesotheliomalaywer.com/yg/CSS/data/touch/kwwxdd.html koalaswim] [http://earlysignofpregnancy.net/pregnancycalendar/wp-content/themes/default/cache/pmahjr.html london underground map] [http://earlysignofpregnancy.net/pregnancycalendar/wp-content/themes/default/cache/gqwulf.html on surveillance cameras] [http://credit-report-repair.com/yg/CSS/data/cache/luthri.html teen tease] [http://mesotheliomalaywer.com/yg/CSS/data/touch/nvjcuo.html army military occupational specialties] [http://earlysignofpregnancy.net/pregnancycalendar/wp-content/themes/default/cache/swsggx.html pornstar videos] [http://freeseotips.com/wp-content/themes/classic/cache/uraeag.html asian ladies] [http://earlysignofpregnancy.net/pregnancycalendar/wp-content/themes/default/cache/dhfpmk.html nba allstar games history] [http://instantinfocenter.com/CP/images/pic/nesfap.html tiny lolita angels] [http://instantinfocenter.com/CP/images/pic/juogbx.html free full downloadable games] [http://instantinfocenter.com/CP/images/pic/ushaab.html greek letters] [http://earlysignofpregnancy.net/pregnancycalendar/wp-content/themes/default/cache/rxdsrj.html pacific sun wear stores] [http://freeseotips.com/wp-content/themes/classic/cache/hloejd.html pregnant anal] [http://earlysignofpregnancy.net/pregnancycalendar/wp-content/themes/default/cache/ferfjo.html patchwork] [http://mesotheliomalaywer.com/yg/CSS/data/touch/dehwht.html ying yang twins whisper song] [http://earlysignofpregnancy.net/pregnancycalendar/wp-content/themes/default/cache/pthxeu.html sissy husbands] [http://freeseotips.com/wp-content/themes/classic/cache/qcvkir.html text] [http://earlysignofpregnancy.net/pregnancycalendar/wp-content/themes/default/cache/tgqqxc.html black moms id like to fuck] [http://credit-report-repair.com/yg/CSS/data/cache/mgqlhm.html the movie pink] [http://instantinfocenter.com/CP/images/pic/tgxnjf.html goatlist] [http://instantinfocenter.com/CP/images/pic/pnrnfn.html aurora illinois real estate] [http://mesotheliomalaywer.com/yg/CSS/data/touch/ewsxbc.html yamaha drum parts] [http://earlysignofpregnancy.net/pregnancycalendar/wp-content/themes/default/cache/egufvr.html nissan off road accessories] [http://instantinfocenter.com/CP/images/pic/hvrcjw.html girls undies] [http://freeseotips.com/wp-content/themes/classic/cache/ubcebe.html amatuer girls] [http://instantinfocenter.com/CP/images/pic/irpdsp.html naughty jessica rabbit] [http://instantinfocenter.com/CP/images/pic/lqifdb.html tulum] [http://credit-report-repair.com/yg/CSS/data/cache/jljqci.html free blow job clip] [http://credit-report-repair.com/yg/CSS/data/cache/onbwlf.html lesson plan side story west] [http://instantinfocenter.com/CP/images/pic/iiswdu.html yorba linda real estate] [http://mesotheliomalaywer.com/yg/CSS/data/touch/urtvld.html daisy dukes thongs] [http://credit-report-repair.com/yg/CSS/data/cache/wborwc.html ethnic models] [http://mesotheliomalaywer.com/yg/CSS/data/touch/jlffvu.html world smallest bikini] [http://mesotheliomalaywer.com/yg/CSS/data/touch/muvlaq.html everyone has aids] [http://mesotheliomalaywer.com/yg/CSS/data/touch/hcsghe.html episode iii star wars] [http://freeseotips.com/wp-content/themes/classic/cache/nbeomf.html zoophilia stories] [http://freeseotips.com/wp-content/themes/classic/cache/dtefue.html slaves] [http://instantinfocenter.com/CP/images/pic/mrucma.html teen girls in diapers] [http://instantinfocenter.com/CP/images/pic/agvuqv.html boned] [http://credit-report-repair.com/yg/CSS/data/cache/eouqao.html underage lolita models] [http://mesotheliomalaywer.com/yg/CSS/data/touch/uefphj.html animals wildlife] [http://earlysignofpregnancy.net/pregnancycalendar/wp-content/themes/default/cache/ubutda.html respiratory system] [http://credit-report-repair.com/yg/CSS/data/cache/kxlerd.html arezzo new york city] [http://instantinfocenter.com/CP/images/pic/jknvxd.html tropical rain forest] [http://instantinfocenter.com/CP/images/pic/kcgeui.html vicki vette] [http://instantinfocenter.com/CP/images/pic/gbdnmq.html tim wilson] [http://mesotheliomalaywer.com/yg/CSS/data/touch/qmbqoi.html nba play] [http://earlysignofpregnancy.net/pregnancycalendar/wp-content/themes/default/cache/giejri.html rough lesbian sex] [http://mesotheliomalaywer.com/yg/CSS/data/touch/iqkgcx.html babes free nude] [http://earlysignofpregnancy.net/pregnancycalendar/wp-content/themes/default/cache/pborlx.html polish lolita] [http://instantinfocenter.com/CP/images/pic/kvmpma.html pinellas county schools] [http://freeseotips.com/wp-content/themes/classic/cache/ambdll.html bukkake on her face] [http://earlysignofpregnancy.net/pregnancycalendar/wp-content/themes/default/cache/qwuoul.html famous nude women] [http://instantinfocenter.com/CP/images/pic/veiruq.html sue] [http://freeseotips.com/wp-content/themes/classic/cache/emceev.html united states road map] [http://mesotheliomalaywer.com/yg/CSS/data/touch/avhoba.html shaved nudist] [http://freeseotips.com/wp-content/themes/classic/cache/exvowu.html literacy need assessment] [http://mesotheliomalaywer.com/yg/CSS/data/touch/nccsri.html australian] [http://mesotheliomalaywer.com/yg/CSS/data/touch/lvpbgf.html hot tub reviews] [http://instantinfocenter.com/CP/images/pic/xeoqfa.html sedu hair care] [http://mesotheliomalaywer.com/yg/CSS/data/touch/gdemvt.html jenny mccarthy nude free] [http://earlysignofpregnancy.net/pregnancycalendar/wp-content/themes/default/cache/ddjehn.html paul pierce] [http://instantinfocenter.com/CP/images/pic/ndbjku.html nipple stretchers] [http://earlysignofpregnancy.net/pregnancycalendar/wp-content/themes/default/cache/smucuf.html nude modeling] [http://earlysignofpregnancy.net/pregnancycalendar/wp-content/themes/default/cache/gjbnvo.html chester bennington] [http://earlysignofpregnancy.net/pregnancycalendar/wp-content/themes/default/cache/fwisxq.html flash superhero] [http://instantinfocenter.com/CP/images/pic/ucmovo.html wireless spy camera] [http://earlysignofpregnancy.net/pregnancycalendar/wp-content/themes/default/cache/mhthwc.html safe credit union] [http://mesotheliomalaywer.com/yg/CSS/data/touch/ftbbfh.html epochs definition] [http://earlysignofpregnancy.net/pregnancycalendar/wp-content/themes/default/cache/fvadcm.html assholes] [http://earlysignofpregnancy.net/pregnancycalendar/wp-content/themes/default/cache/womlxv.html swimming boys underwear] [http://mesotheliomalaywer.com/yg/CSS/data/touch/cmkpvq.html exercise bikes ratings] [http://credit-report-repair.com/yg/CSS/data/cache/gxxrux.html nursing compact] [http://freeseotips.com/wp-content/themes/classic/cache/fgavvv.html early pregnancy symptom discharge] [http://credit-report-repair.com/yg/CSS/data/cache/igjadv.html ozzy crazy train] [http://credit-report-repair.com/yg/CSS/data/cache/kcueca.html teen obesity] [http://instantinfocenter.com/CP/images/pic/xlspwc.html tight shirt gallery] [http://earlysignofpregnancy.net/pregnancycalendar/wp-content/themes/default/cache/oxpgmh.html svetlana] [http://mesotheliomalaywer.com/yg/CSS/data/touch/khkbwe.html search engine optimization firm]  
[[File:Shotgun vm.jpg|thumb|A viewmodel on-screen]]
[[Image:hl2-1.jpg|thumb|300px|right|The shotgun in the picture is a typical viewmodel.]]
[[File:v_shotgun_hlmv.jpg|thumb|Elongation is often employed]]
{{CD|CBaseViewModel|file1=1}}


A '''viewmodel''' is a model, typically a weapon, which is held in the players hands and can only be seen from the first person view. As it doesn't interfere with the rest of the game world, you can think of it as an overlay on the player's screen. In multiplayer, both the [[Creating Characters|player model]] and the [[World Models|world model]] are rendered on players' screens for them to see.
A '''viewmodel''' is a specially-designed [[model]] used to represent the player's active weapon in first-person view (as opposed to the ordinary "[[:Category:World Models|worldmodel]]s" used elsewhere).


== Characteristics of viewmodels ==
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:
[[Image:v_shotgun_hlmv.jpg|thumb|300px|right|The same model seen from another angle]]


* A viewmodel is usually very detailed and uses high resolution textures.
# Parts that the player will never see are removed
* Backfaces of the model that the player isn't going to see are often deleted to increase the performance a little bit.
# Parts that the player does see are very detailed
* Viewmodels have neither physical properties (like $surfaceprop) nor a $collisionmodel.
# The model as a whole is distorted to look its best from the one viewing angle
* Usually named with a '''v_''' prefix, whereas its world model starts with '''w_''' - example: ''v_shotgun.mdl'' and ''w_shotgun.mdl''
 
Each player has two [[CBaseViewModel|viewmodel entities]] (to allow for dual wielding etc), the models of which are changed as appropriate. Both entities are, of course, only transmitted to their owner.
:{{bug|hidetested=1|Some viewmodels in {{hl2dm|4}} are missing viewbob.{{fix|Follow [https://www.youtube.com/watch?v{{=}}reVpIiCZi6Q this YouTube guide] to fix the issues in the code.}}}}
The Viewmodel entity is already set up to have [[VGUI on entity|VGUI panel]]s attached.
 
{{tip|By default Viewmodels are drawn with a 54° field of view, which approximates a 35mm camera lens. This is considerably lower than the world view's default of 75°.  Another thing to be aware of is some programs may use half angles for the FOV so instead of 54° you might have something like 27°.}}
 
== 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.
 
If you still can't see your viewmodel, try using the console command <code>thirdperson</code> or <code>mat_wireframe 2</code>. It might be facing the wrong way or outside geometry.
 
[[ent_attachments]] viewmodel will show the attachments.
 
=== Basic activities ===
See [[Compiling a model]]
 
<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>
 
== Programming ==
 
 
 
=== CBaseViewModel ===
 
; <code>void SetWeaponModel( const [[char]]* modelname, [[CBaseCombatWeapon]]* weapon )</code>
: Updates the VM's model. This function is only used during the HL2 suit equip animation.
; <code>void CalcViewModelView()</code>
: Calculates the VM's bob (due to player movement), swing (due to player turning), and shake (due to [[env_shake]] etc) ''on the client only''. This function calls <code>AddViewModelBob()</code> and <code>CalcViewModelLag()</code>.
; <code>[[int]] ViewModelIndex()</code>
: Which of the owner's viewmodels this is.
; <code>void SendViewModelMatchingSequence(int)</code>
: Just changes the animation. The fancy name is probably a holdover.
; <code>[[bool]] ShouldFlipViewModel()</code>
: Whether the VM should be mirrored so that it appears on the other side of the screen.
; <code>bool ShouldReceiveProjectedTextures()</code>
: Whether the VM should receive [[env_projectedtexture|projected textures]].
 
=== CBaseCombatWeapon ===
 
; <code>void SetViewModel()</code>
: Updates the owner's VM to this weapon's.
; <code>void SetViewModelIndex([[int]])</code>
: Which of the player's VM entities this weapon uses.
; <code>void SendViewModelAnim(int nSequence)</code>
; <code>[[float]] GetViewModelSequenceDuration()</code>
; <code>[[bool]] IsViewModelSequenceFinished()</code>
: Pass-throughs for standard <code>[[CBaseAnimating]]</code> funcs.


== See also ==
== See also ==
* [[Viewmodels in XSI|Creating Viewmodels]]
* [[World Models|Creating Worldmodels]]


[[Category:Glossary]]
* [[Viewmodels in XSI]]
* [[Viewmodels in Blender]]
* [[Creating worldmodels from viewmodels]]
* <code>[[CBaseViewModel]]</code>
 
[[Category:Weapons]]
 
[[Category:Modeling]]
[[Category:C++]]

Latest revision as of 17:17, 22 October 2025

A viewmodel on-screen
Elongation is often employed
C++ Class hierarchy
CBaseViewModel
CBaseAnimatingOverlay
CBaseAnimating
CBaseEntity
C++ baseviewmodel_shared.cpp

A viewmodel is a specially-designed model used to represent the player's active weapon in first-person view (as opposed to the ordinary "worldmodels" 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

Each player has two viewmodel entities (to allow for dual wielding etc), the models of which are changed as appropriate. Both entities are, of course, only transmitted to their owner.

Icon-Bug.pngBug:Some viewmodels in Half-Life 2: Deathmatch Half-Life 2: Deathmatch are missing viewbob.
Note.pngFix:Follow this YouTube guide to fix the issues in the code.

The Viewmodel entity is already set up to have VGUI panels attached.

Tip.pngTip:By default Viewmodels are drawn with a 54° field of view, which approximates a 35mm camera lens. This is considerably lower than the world view's default of 75°. Another thing to be aware of is some programs may use half angles for the FOV so instead of 54° you might have something like 27°.

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.

If you still can't see your viewmodel, try using the console command thirdperson or mat_wireframe 2. It might be facing the wrong way or outside geometry.

ent_attachments viewmodel will show the attachments.

Basic activities

See Compiling a model

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,

Programming

CBaseViewModel

void SetWeaponModel( const char* modelname, CBaseCombatWeapon* weapon )
Updates the VM's model. This function is only used during the HL2 suit equip animation.
void CalcViewModelView()
Calculates the VM's bob (due to player movement), swing (due to player turning), and shake (due to env_shake etc) on the client only. This function calls AddViewModelBob() and CalcViewModelLag().
int ViewModelIndex()
Which of the owner's viewmodels this is.
void SendViewModelMatchingSequence(int)
Just changes the animation. The fancy name is probably a holdover.
bool ShouldFlipViewModel()
Whether the VM should be mirrored so that it appears on the other side of the screen.
bool ShouldReceiveProjectedTextures()
Whether the VM should receive projected textures.

CBaseCombatWeapon

void SetViewModel()
Updates the owner's VM to this weapon's.
void SetViewModelIndex(int)
Which of the player's VM entities this weapon uses.
void SendViewModelAnim(int nSequence)
float GetViewModelSequenceDuration()
bool IsViewModelSequenceFinished()
Pass-throughs for standard CBaseAnimating funcs.

See also