Entity/DrawModel

From Garry's Mod
Jump to: navigation, search
 Entity:DrawModel( )

Description

Draws the entity or model.

If called inside ENTITY:Draw or ENTITY:DrawTranslucent, it only draws the entity's model itself.
If called outside of those hooks, it will call both of said hooks depending on Entity:GetRenderGroup, drawing the entire entity again.

NOTE

When drawing an entity more than once per frame in different positions, you should call Entity:SetupBones before each draw; Otherwise, the entity will retain its first drawn position.

NOTE

This is a rendering function that requires a 3D rendering context.
This means that it will only work in hooks with a 3D rendering context.

BUG

Calling this on entities with EF_BONEMERGE and EF_NODRAW applied causes a crash.

Issue Tracker: #1558

BUG

Using this with a map model (game.GetWorld():GetModel()) crashes the game.

Issue Tracker: #2688

Examples

Example

Manually draws a single ClientsideModel 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.

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)

Output:

entity drawmodel example.png
Personal tools
Navigation