Using DModelPanel within a circle

For the past couple of hours I’ve been trying to “put the entity in the circle”, but couldn’t get it to work for the life of me.
Could somebody help me out please? I’ve read about stencils as well, but I’m not sure if I have to use them nor do I know how to use them.

Uhh, we need code. I can’t help you

ahah,you are serious?) surface.DrawCircle( 100, 100, 50, Color(255,255,255,255) ) ? Ahah


local main = vgui.Create( "DFrame" )
main:SetTitle( "NPC_NAME" )
main:SetSize( 500, 500 )
main:SetPos( ScrW()*0.383, ScrH()*0.293 )
main:SetBackgroundBlur(true)
main:MakePopup()
--[[function main:Paint(w, h)
	surface.SetDrawColor(0,0,255,255)
	surface.DrawLine(0, h/2, w, h/2)
	surface.DrawLine(w/2, 0, w/2, h)
end]]

local anim = Derma_Anim( "EaseInQuad", main, function( pnl, anim, delta, data )
	pnl:SetSize( inQuad( delta, 0, 300 ), inQuad( delta, 0, 300 ) ) -- Change the X coordinate from 200 to 200+600
end )
anim:Start( 1 ) -- Animate for two seconds
main.Think = function( self )
	if anim:Active() then
		anim:Run()
	end
end
local width, height = main:GetSize()

local textpanel = vgui.Create("DPanel", main)
textpanel:SetPos(3,200)
textpanel:SetSize(294,50)

local textfield = vgui.Create("RichText", textpanel)
textfield:SetPos(10,5)
textfield:SetSize(textpanel:GetSize())
AnimatedText(textfield, "testing dasflasdgk ffadgj sdfgj hsdfkjgh fakjg kjsdfhgkjhs ad;sfjlasgkjf;ldfgkjlsdfkgj dfsgl kjsdfg;lkjsd;flgkj ;lkfjg;lkajdg;olkdfjag;lkhdsflgkjhadfjasdgf dakj ;lkadjf;lkasdjflkasjdf;lkasdjf;l")
textfield:SizeToContents()

local npchead = vgui.Create( "DModelPanel", main )
npchead:SetSize( width*0.25, height*0.25 )
npchead:SetPos(width*0.35, height*0.1)
npchead:SetModel( "models/player/odessa.mdl" )
function npchead:LayoutEntity( Entity ) return end
local headpos = npchead.Entity:GetBonePosition( npchead.Entity:LookupBone( "ValveBiped.Bip01_Head1" ) )
npchead:SetLookAt(headpos)
npchead:SetCamPos( headpos-Vector(-12,-5,0 ) )
function npchead:PaintOver(w,h)
	surface.DrawCircle(w/2, h/2, 60, 0, 0, 0, 255)
end	

Sorry about that, here it is!

I don’t know much about stencils but trying using Stencil Masks


SetStencilWriteMask

How though?

http://forum.facepunch.com/showthread.php?t=1522945
All you need to do is the exact same thing except instead of creating an AvatarImage panel, create a DModelPanel panel

[editline]7th January 2017[/editline]

Untested code (that I copied from myself):



-- PUT ALL THIS IN A SEPARATE FILE FROM THE MAIN FILE SO IT'S NICE AND NEAT

local function DrawCircle( x, y, radius, seg )
	local cir = {}
	table.insert( cir, { x = x, y = y } )
	for i = 0, seg do
		local a = math.rad( ( i / seg ) * -360 )
		table.insert( cir, { x = x + math.sin( a ) * radius, y = y + math.cos( a ) * radius } )
	end
	local a = math.rad( 0 )
	table.insert( cir, { x = x + math.sin( a ) * radius, y = y + math.cos( a ) * radius } )
	surface.DrawPoly( cir )
end

local PANEL = {}

function PANEL:Init()
	self.panel = vgui.Create( "DModelPanel", self ) -- The magic of changing 1 line of code is amazing
	self.panel:SetPaintedManually( true )
end

function PANEL:PerformLayout()
	self.panel:SetSize( self:GetWide(), self:GetTall() )
end

function PANEL:Paint( w, h )
	render.ClearStencil()
	render.SetStencilEnable( true )

	render.SetStencilWriteMask( 1 )
	render.SetStencilTestMask( 1 )

	render.SetStencilFailOperation( STENCILOPERATION_REPLACE )
	render.SetStencilPassOperation( STENCILOPERATION_ZERO )
	render.SetStencilZFailOperation( STENCILOPERATION_ZERO )
	render.SetStencilCompareFunction( STENCILCOMPARISONFUNCTION_NEVER )
	render.SetStencilReferenceValue( 1 )

	draw.NoTexture()
	surface.SetDrawColor( Color( 0, 0, 0, 255 ) )
	DrawCircle( w/2, h/2, h/2, math.max(w,h)/2 )

	render.SetStencilFailOperation( STENCILOPERATION_ZERO )
	render.SetStencilPassOperation( STENCILOPERATION_REPLACE )
	render.SetStencilZFailOperation( STENCILOPERATION_ZERO )
	render.SetStencilCompareFunction( STENCILCOMPARISONFUNCTION_EQUAL )
	render.SetStencilReferenceValue( 1 )

	self.panel:PaintManual()

	render.SetStencilEnable( false )
	render.ClearStencil()
	
end
 
vgui.Register( "CircularModelPanel", PANEL )


Here’s an example on how to use this (which should work with your original code pretty nicely):



local modelpanel = vgui.Create( "CircularModelPanel" )
modelpanel.panel:SetSize( width*0.25, height*0.25 ) -- assuming you're running this in your original code with the width and height variables defined, this should work
modelpanel.panel:SetPos(width*0.35, height*0.1)
modelpanel.panel:SetModel( "models/player/odessa.mdl" )
-- and so on