Entity/DrawModel

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
(Added jetpack drawing example)
Line 5: Line 5:
 
|Name=DrawModel
 
|Name=DrawModel
 
|Parent=Entity
 
|Parent=Entity
 +
}}
 +
{{Example
 +
|Description=Manually draws a {{GlobalFunction|ClientsideModel}} on the specified bone, on the given offset.
 +
|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)
 
}}
 
}}

Revision as of 13:29, 10 August 2016

 Entity:DrawModel( )

Description

Draws the entity. If called outside of ENTITY:Draw or ENTITY:DrawTranslucent it will call both of said functions.

Examples

Example

Manually draws a ClientsideModel on the specified bone, on the given offset.

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)


Personal tools
Navigation