diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2016-07-10 17:04:29 -0400 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2016-07-10 17:04:29 -0400 |
| commit | 1de5f9ac6f038bfed2230cc1272b253794b2f41a (patch) | |
| tree | 15bc9d515f1f48c036522afb7cc71f60243849a9 /gamemode/client/vgui/vgui_DMultiModelPanel.lua | |
| download | artery-1de5f9ac6f038bfed2230cc1272b253794b2f41a.tar.gz artery-1de5f9ac6f038bfed2230cc1272b253794b2f41a.tar.bz2 artery-1de5f9ac6f038bfed2230cc1272b253794b2f41a.zip | |
Initial commit
Diffstat (limited to 'gamemode/client/vgui/vgui_DMultiModelPanel.lua')
| -rw-r--r-- | gamemode/client/vgui/vgui_DMultiModelPanel.lua | 161 |
1 files changed, 161 insertions, 0 deletions
diff --git a/gamemode/client/vgui/vgui_DMultiModelPanel.lua b/gamemode/client/vgui/vgui_DMultiModelPanel.lua new file mode 100644 index 0000000..37d0883 --- /dev/null +++ b/gamemode/client/vgui/vgui_DMultiModelPanel.lua @@ -0,0 +1,161 @@ +local PANEL = {} + +AccessorFunc( PANEL, "m_fAnimSpeed", "AnimSpeed" ) +AccessorFunc( PANEL, "vCamPos", "CamPos" ) +AccessorFunc( PANEL, "fFOV", "FOV" ) +AccessorFunc( PANEL, "vLookatPos", "LookAt" ) +AccessorFunc( PANEL, "aLookAngle", "LookAng" ) +AccessorFunc( PANEL, "colAmbientLight", "AmbientLight" ) +AccessorFunc( PANEL, "colColor", "Color" ) +AccessorFunc( PANEL, "bAnimated", "Animated" ) + +function PANEL:Init() + + self.Entities = {} + self.LastPaint = 0 + self.DirectionalLight = {} + self.FarZ = 4096 + + self:SetCamPos( Vector( 50, 50, 50 ) ) + self:SetLookAt( Vector( 0, 0, 40 ) ) + self:SetFOV( 70 ) + + self:SetText( "" ) + self:SetAnimSpeed( 0.5 ) + self:SetAnimated( false ) + + self:SetAmbientLight( Color( 50, 50, 50 ) ) + + self:SetDirectionalLight( BOX_TOP, Color( 255, 255, 255 ) ) + self:SetDirectionalLight( BOX_FRONT, Color( 255, 255, 255 ) ) + + self:SetColor( Color( 255, 255, 255, 255 ) ) + +end + +function PANEL:SetDirectionalLight( iDirection, color ) + self.DirectionalLight[ iDirection ] = color +end + +function PANEL:AddModel( strModelName ) + + -- Note: Not in menu dll + if ( !ClientsideModel ) then return end + + self.Entities[#self.Entities+1] = ClientsideModel(strModelName, RENDER_GROUP_OPAQUE_ENTITY) + if ( !IsValid( self.Entities[#self.Entities] ) ) then return end + + self.Entities[#self.Entities]:SetNoDraw( true ) + self.Entities[#self.Entities]:SetIK( false ) + +end + +function PANEL:DrawModel() + + local curparent = self + local rightx = self:GetWide() + local leftx = 0 + local topy = 0 + local bottomy = self:GetTall() + local previous = curparent + while( curparent:GetParent() != nil ) do + curparent = curparent:GetParent() + local x, y = previous:GetPos() + topy = math.Max( y, topy + y ) + leftx = math.Max( x, leftx + x ) + bottomy = math.Min( y + previous:GetTall(), bottomy + y ) + rightx = math.Min( x + previous:GetWide(), rightx + x ) + previous = curparent + end + render.SetScissorRect( leftx, topy, rightx, bottomy, true ) + + for k,v in pairs(self.Entities) do + local ret = self:PreDrawModel( v ) + if ( ret != false ) then + v:DrawModel() + self:PostDrawModel( v ) + end + end + + render.SetScissorRect( 0, 0, 0, 0, false ) + +end + +function PANEL:PreDrawModel( ent ) + return true +end + +function PANEL:PostDrawModel( ent ) + +end + +function PANEL:Paint( w, h ) + for k,v in pairs(self.Entities) do + if ( !IsValid( v ) ) then continue end + + local x, y = self:LocalToScreen( 0, 0 ) + + self:LayoutEntity( v ) + + local ang = self.aLookAngle + if ( !ang ) then + ang = ( self.vLookatPos - self.vCamPos ):Angle() + end + + cam.Start3D( self.vCamPos, ang, self.fFOV, x, y, w, h, 5, self.FarZ ) + + render.SuppressEngineLighting( true ) + render.SetLightingOrigin( v:GetPos() ) + render.ResetModelLighting( self.colAmbientLight.r / 255, self.colAmbientLight.g / 255, self.colAmbientLight.b / 255 ) + render.SetColorModulation( self.colColor.r / 255, self.colColor.g / 255, self.colColor.b / 255 ) + render.SetBlend( ( self:GetAlpha() / 255 ) * ( self.colColor.a / 255 ) ) + + for i = 0, 6 do + local col = self.DirectionalLight[ i ] + if ( col ) then + render.SetModelLighting( i, col.r / 255, col.g / 255, col.b / 255 ) + end + end + + self:DrawModel() + + render.SuppressEngineLighting( false ) + cam.End3D() + + self.LastPaint = RealTime() + end +end + +--[[ +function PANEL:StartScene( name ) + + if ( IsValid( self.Scene ) ) then + self.Scene:Remove() + end + + self.Scene = ClientsideScene( name, self.Entity ) + +end +]] + +function PANEL:LayoutEntity( Entity ) + + -- + -- This function is to be overriden + -- + + if ( self.bAnimated ) then + self:RunAnimation() + end + Entity:SetAngles( Angle( 0, RealTime() * 10 % 360, 0 ) ) + +end + +function PANEL:OnRemove() + for k,v in pairs(self.Entities) do + v:Remove() + self.Entities[k] = nil + end +end + +derma.DefineControl( "DModelPanel", "A panel containing a model", PANEL, "DModelPanel" ) |
