DModelPanel
Description
DModelPanel is a VGUI element that projects a 3D model onto a 2D plane.
Parent
Derives methods, etc not listed on this page from DButton.
Events
DModelPanel:PostDrawModel( Entity ent )
Called when the entity of the DModelPanel was drawn.
This is a rendering hook with 3d drawing context.
Methods
DModelPanel:DrawModel()
This is used internally - although you're able to use it you probably shouldn't.
Used by the DModelPanel's paint hook to draw the model and background.
boolean DModelPanel:GetAnimated()
Returns whether or not the panel entity should be animated when the default DModelPanel:LayoutEntity function is called.
number DModelPanel:GetAnimSpeed()
Returns the animation speed of the panel entity, see DModelPanel:SetAnimSpeed.
Angle DModelPanel:GetLookAng()
Returns the angles of the model viewing camera. Is nil until changed with DModelPanel:SetLookAng.
DModelPanel:LayoutEntity( Entity entity )
This is used internally - although you're able to use it you probably shouldn't.
By default, this function slowly rotates and animates the entity being rendered.
If you want to change this behavior, you should override it.
DModelPanel:RunAnimation()
This function is used in the DModelPanel:LayoutEntity. It will set the active model to the last set animation using Entity:SetSequence. By default, it is the walking animation.
DModelPanel:SetAnimated( boolean animated )
Sets whether or not to animate the entity when the default DModelPanel:LayoutEntity is called.
DModelPanel:SetAnimSpeed( number animSpeed )
Sets the speed used by DModelPanel:RunAnimation to advance frame on an entity sequence.
Entity:FrameAdvance doesn't seem to have any functioning arguments and therefore changing this will not have any affect on the panel entity's sequence speed without reimplementation. It only affects the value returned by DModelPanel:GetAnimSpeed
DModelPanel:SetColor( table color )
Sets the color of the rendered entity.
This does not work on Garry's Mod player models since they use a different color system. To modify a player model color, see Example 2 on the DModelPanel page
DModelPanel:SetDirectionalLight( number direction, table color )
Sets the directional lighting used on the rendered entity.
DModelPanel:SetEntity( Entity ent )
Sets the entity to be rendered by the model panel.
If you set ent to a shared entity you must set ent to nil before removing this panel or else a "Trying to remove server entity on client!" error is thrown
DModelPanel:SetLookAt( Vector pos )
Makes the panel's camera face the given position. Basically sets the camera's angles (DModelPanel:SetLookAng) after doing some math.
DModelPanel:SetModel( string model )
Sets the model of the rendered entity.
This function may give a different model than expected. This is not a bug, however this problem may appear with some player models which are renamed several times in a wrong way. To solve that, you can use Entity:SetModel and Entity:SetModelName on the internal panel entity. More information : https://github.com/Facepunch/garrysmod-issues/issues/4534.
Example
Creates a DModelPanel and sets its model to your playermodel.
Example
Creates a DModelPanel and sets its model to the Alyx playermodel, then changes its player color to red. Also disables default rotation animation.
local Panel = vgui.Create( "DPanel" )
Panel:SetPos( 10, 10 )
Panel:SetSize( 200, 200 )
local icon = vgui.Create( "DModelPanel", Panel )
icon:SetSize(200,200)
icon:SetModel( "models/player/alyx.mdl" ) -- you can only change colors on playermodels
function icon:LayoutEntity( Entity ) return end -- disables default rotation
function icon.Entity:GetPlayerColor() return Vector (1, 0, 0) end --we need to set it to a Vector not a Color, so the values are normal RGB values divided by 255.
Output: 
