Garry's Mod Wiki

Revision Difference

Entity:DrawModel#528770

<function name="DrawModel" parent="Entity" type="classfunc"> <description> Draws the entity or model. If called inside <page>ENTITY:Draw</page> or <page>ENTITY:DrawTranslucent</page>, it only draws the entity's model itself. ⤶ ⤶ If called outside of those hooks, it will call both of said hooks depending on <page>Entity:GetRenderGroup</page>, drawing the entire entity again.⤶ ⤶ If called outside of those hooks, it will call both of said hooks depending on <page>Entity:GetRenderGroup</page>, drawing the entire entity again.⤶ <note>When drawing an entity more than once per frame in different positions, you should call <page>Entity:SetupBones</page> before each draw; Otherwise, the entity will retain its first drawn position.</note> <rendercontext hook="false" type="3D"></rendercontext> <bug issue="1558">Calling this on entities with <page text="EF_BONEMERGE">Enums/EF</page> and <page text="EF_NODRAW">Enums/EF</page> applied causes a crash.</bug> <bug issue="2688">Using this with a map model (<page>game.GetWorld</page>():<page text="GetModel">Entity:GetModel</page>()) crashes the game.</bug> </description> <args> <arg name="flags" type="number" default="STUDIO_RENDER">The optional <page text="STUDIO_">Enums/STUDIO</page> flags, usually taken from <page>ENTITY:Draw</page> and similar hooks.</arg> </args> <realm>Client</realm> </function> <example> <description> Manually draws a single <page>Global.ClientsideModel</page> on the specified bone, on the given offset for every player affected by this hook. This is useful in case you want to reuse a single model without having to create one for each player. </description> <code> local modelexample = ClientsideModel( "models/thrusters/jetpack.mdl" ) modelexample:SetNoDraw( true ) local offsetvec = Vector( 3, -5.6, 0 ) local offsetang = Angle( 180, 90, -90 ) hook.Add( "PostPlayerDraw" , "manual_model_draw_example" , function( ply ) local boneid = ply:LookupBone( "ValveBiped.Bip01_Spine2" ) if not boneid then return end local matrix = ply:GetBoneMatrix( boneid ) if not matrix then return end local newpos, newang = LocalToWorld( offsetvec, offsetang, matrix:GetTranslation(), matrix:GetAngles() ) modelexample:SetPos( newpos ) modelexample:SetAngles( newang ) modelexample:SetupBones() modelexample:DrawModel() end) </code> <output><image src="entity_drawmodel_example.png"/></output> ⤶ </example></example>