Entity/DrawModel

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
(Added jetpack drawing example)
(Added preview)
Line 8: Line 8:
 
{{Example
 
{{Example
 
|Description=Manually draws a {{GlobalFunction|ClientsideModel}} on the specified bone, on the given offset.
 
|Description=Manually draws a {{GlobalFunction|ClientsideModel}} on the specified bone, on the given offset.
|Code=
+
|Code=local modelexample = ClientsideModel( "models/thrusters/jetpack.mdl" )
local modelexample = ClientsideModel( "models/thrusters/jetpack.mdl" )
+
 
modelexample:SetNoDraw( true )
 
modelexample:SetNoDraw( true )
  
Line 36: Line 35:
 
 
 
end)
 
end)
 +
|Output=[[File:entity_drawmodel_example.png]]
 
}}
 
}}

Revision as of 13:45, 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)

Output:

entity drawmodel example.png
Personal tools
Navigation