DModelPanel Issue

I’m trying some stuff out with VGUI and I bumped into DModelPanel. I have 2 question:
Why does the model gets cut off about half way:

How do I center the text?

[lua]function vguiInterface()

local modelpanel = vgui.Create( "DFrame" );
	modelpanel:SetSize( 200, 200 );
	modelpanel:AlignLeft( 10 );
	modelpanel:AlignTop( 10 );
	modelpanel:SetTitle( "You" );
	
local icon = vgui.Create( "DModelPanel", Dermapanel )
	icon:SetModel( LocalPlayer():GetModel() );
	icon:AlignLeft( 10 );
	icon:AlignTop( 100 );
	icon:SetSize( 180, 180 );
	icon:SetCamPos( Vector( 50, 50, 60 ) );
	icon:SetLookAt( Vector( 0, 0, 0 ) );

end
usermessage.Hook( “call_interface”, vguiInterface )[/lua]

Never worked with DModelPanel before. You do have a mistake though, you never parented the DModelPanel to the actual frame.

[lua]function vguiInterface()

local modelpanel = vgui.Create( "DFrame" );
	modelpanel:SetSize( 200, 200 );
	modelpanel:AlignLeft( 10 );
	modelpanel:AlignTop( 10 );
	modelpanel:SetTitle( "You" );
	
local icon = vgui.Create( "DModelPanel", modelpanel )
	icon:SetModel( LocalPlayer():GetModel() );
	icon:AlignLeft( 10 );
	icon:AlignTop( 100 );
	icon:SetSize( 180, 180 );
	icon:SetCamPos( Vector( 50, 50, 60 ) );
	icon:SetLookAt( Vector( 0, 0, 0 ) );

end
usermessage.Hook( “call_interface”, vguiInterface )[/lua]

Dunno if that will fix it, but give it a try.

Also it may be cutting off half way because
icon:SetSize( 180, 180 )
180 is too little space vertical-wise to see the whole model.

I parented it before, it only got more fucked up then this.

And how big should it be?

Try a width of 128 and heigth of 256. If not just double 180 or mess around with the numbers.

No matter what the scale is, I keep getting the same issue.

Probably because you set SetLookAt to be 0,0,0, which is the feet. Try raising it up a little, like modelpanel:SetLookAt(Vector(0,0,50))

Thank you very much kind sir. All thats left now is finding the correct settings.

If it helps, here’s a snippet of code from a model panel I’ve used…

[lua]local prop = ents.Create( “prop_physics”)
prop:SetModel(string.Replace(filenode.FileDir, “…/”, “”))
if string.match(filenode.FileDir, “models/player/”) then
function mdlviewer:LayoutEntity(Entity)
self:RunAnimation();
end
mdlviewer:SetCamPos( Vector( 50, 0, 50 ) )
mdlviewer:SetLookAt( Vector( 0, 0, 51 ) )
else
function mdlviewer:LayoutEntity(Entity)
Entity:SetAngles( Angle( 0, math.fmod(CurTime(),360)*5, 0) )
end
mdlviewer:SetCamPos(prop:OBBCenter()-Vector(prop:BoundingRadius()*2,0,-prop:BoundingRadius()/12))
mdlviewer:SetLookAt(prop:OBBCenter()-Vector(0,0,-prop:BoundingRadius()/12))
end
mdlviewer:SetModel(string.Replace(filenode.FileDir, “…/”, “”))
MakeVisible(mdlviewer)
prop:Remove()[/lua]

There’s a few things to this. The first is, when you want to make a panel that can show models both big and small, you have to set the LookAt and CamPos relative to the size (I just experimented for a while and it worked fairly well eventually). I also wanted to make it so when it showed player models, it ran the walking animation, but when it showed prop models it just rotated them as usual.

So in essence, that model panel was good for pretty much any type of model you can think of.

I don’t fully get your code, but oh well. I got mine working, and made the panel smaller, since it was so big.

A bit off topic question how do I close and reopen a frame with a checkbox? I got this, but don’t know what function it needs:
[lua] local modelddtwo = vgui.Create( “DCheckBoxLabel” )
modelddtwo:SetText( “Disable Model” )
– Function
modelddtwo:SetValue( 0 )
modelddone:SizeToContents()
modeldisplayddlist:AddItem( modelddtwo )[/lua]

And yes I know it looks a bit chaotic.

What do you mean by close and reopen? Do you mean something like this?

[lua]modelddtwo.OnChange = function()
if modelddtwo:GetChecked() == true then modelpanel:SetVisible(false)
else modelpanel:SetVisible(true)
end[/lua]

Odd, getting this error after I added it:



hudtesting/gamemode/cl_init.lua:277: 'end' expected (to close 'function' at line 230) near '<eof>'


This is the lua:
[lua] local modelddone = vgui.Create( “DCheckBoxLabel” )
modelddone:SetText( “Disable Background” )
modelddone.OnChange = function( modelpanel ) – 230
if modelddone:GetChecked() == true then modelpanel:SetVisible( false )
else modelpanel:SetVisible( true )
end
modelddone:SetValue( 0 )
modelddone:SizeToContents()
modeldisplayddlist:AddItem( modelddone )

local modelddtwo = vgui.Create( "DCheckBoxLabel" )
modelddtwo:SetText( "Disable Model" )
modelddtwo.OnChange = function( icon )
	if modelddtwo:GetChecked() == true then icon:SetVisible( false )
	else icon:SetVisible( true )
end
modelddtwo:SetValue( 0 )
modelddone:SizeToContents()

modeldisplayddlist:AddItem( modelddtwo )
[/lua]

I think isn’t counting the ends on the code, because if I add 2 ends at the end of the code, the gamemode functions agian but when I use the dropdown, the checkboxes go to the top left corner and I get this error:


includes\util.lua:131: stack overflow

Erm, well the first error, there’s just an end missing to the if/else statement.

Dunno about the second one.

edit Why did you put icon and modelpanel as inputs to the OnChanged functions? You don’t need to do so (and can’t; the OnChanged doesn’t take inputs, it’s just a hook type thing).

Because then I get this error:


hudtesting/gamemode/cl_init.lua:231: attempt to index global 'modelpanel' (a nil value)

Paste whats on line 231.

This:
[lua] if modelddone:GetChecked() == true then modelpanel:SetVisible( false )
[/lua]

It’s a part of this:
[lua]
local modelddone = vgui.Create( “DCheckBoxLabel” )
modelddone:SetText( “Disable Background” )
modelddone.OnChange = function()
if modelddone:GetChecked() == true then modelpanel:SetVisible( false )
else modelpanel:SetVisible( true )
end
modelddone:SetValue( 0 )
modelddone:SizeToContents()
modeldisplayddlist:AddItem( modelddone )
[/lua]

And you’ve defined modelpanel earlier in the script, right?

Yes, but at a different function

It needs to be in the same function or outside a function.

Ok, but let me post the entire code, you see on the modelpanel I have a usermessage hook, so it opens on start. And on the menu’s I have a console command to make it open on F1. I thought that that wouldnt work well in one combination:
[lua]function vguiInterface()

local modelpanel = vgui.Create( "DFrame" );
	modelpanel:SetSize( 160, 180 );
	modelpanel:AlignLeft( 10 );
	modelpanel:AlignTop( 10 );
	modelpanel:SetTitle( "You" );
	modelpanel:ShowCloseButton( false );
	modelpanel:SetDeleteOnClose( false );
	modelpanel:SetDraggable( false );
	
local icon = vgui.Create( "DModelPanel", Dermapanel );
	icon:SetModel( LocalPlayer():GetModel() );
	icon:AlignLeft();  
	icon:AlignTop();  
	icon:SetSize( 180, 180 );
	icon:SetCamPos( Vector( 65, 65, 65 ) );
	icon:SetLookAt( Vector( 0, 0, 50 ) );

end

usermessage.Hook( “call_interface”, vguiInterface )

function vguiMenus()

local menupanel = vgui.Create( "DFrame" );
	menupanel:SetSize(  700, 500 );
	menupanel:Center();
	menupanel:SetTitle( "Main Menu" );
	menupanel:MakePopup();
	menupanel:SetDraggable( true );
	menupanel:SetDeleteOnClose( false );
-- pages	
local menutabs = vgui.Create( "DPropertySheet" );
	menutabs:SetParent ( menupanel );
	menutabs:SetPos( 0, 24 );
	menutabs:SetSize( 700, 16 );
	menutabs:AddSheet( "Options", modeldisplaypanel, "gui/silkicons/wrench.vtf", true, true )
-- dropdown starts here!!!	
local modeldisplaypanel = vgui.Create( "DPanel", menupanel )
modeldisplaypanel:SetPos( 5, 50 );
modeldisplaypanel:SetSize( 150, 100 );
modeldisplaypanel.Paint = function()
	surface.SetDrawColor( 50, 50, 50, 255 )
	surface.DrawRect( 0, 0, modeldisplaypanel:GetWide(), modeldisplaypanel:GetTall() )
end
	
local modeldisplaydd = vgui.Create( "DCollapsibleCategory", modeldisplaypanel )
modeldisplaydd:SetSize( 150, 50 );
modeldisplaydd:CenterVertical();
modeldisplaydd:AlignTop();
modeldisplaydd:AlignLeft();
modeldisplaydd:SetExpanded( 0 );
modeldisplaydd:SetLabel( "Model Display Options" );

modeldisplayddlist = vgui.Create( "DPanelList" )
modeldisplayddlist:SetAutoSize( true )
modeldisplayddlist:SetSpacing ( 5 )
modeldisplayddlist:EnableHorizontal( false )

modeldisplaydd:SetContents( modeldisplayddlist )
– Checkbox starts here!
local modelddone = vgui.Create( “DCheckBoxLabel” )
modelddone:SetText( “Disable Background” )
modelddone.OnChange = function()
if modelddone:GetChecked() == true then modelpanel:SetVisible( false )
else modelpanel:SetVisible( true )
end
modelddone:SetValue( 0 )
modelddone:SizeToContents()
modeldisplayddlist:AddItem( modelddone )

local modelddtwo = vgui.Create( "DCheckBoxLabel" )
modelddtwo:SetText( "Disable Model" )
modelddtwo.OnChange = function()
	if modelddtwo:GetChecked() == true then icon:SetVisible( false )
	else icon:SetVisible( true )
end
modelddtwo:SetValue( 0 )
modelddone:SizeToContents()

modeldisplayddlist:AddItem( modelddtwo )

/* local modelddthree = vgui.Create( “DCheckBoxLabel” )
modelddthree:SetText( “Disable All” )
– Remove?
modelddthree:SetValue( 0 )
modelddthree:SizeToContents()
modeldisplayddlist:AddItem( modelddthree )

local modelddfour = vgui.Create( "DCheckBoxLabel" )
modelddfour:SetText( "Enable All" )
-- Remove?
modelddfour:SetValue( 0 )
modelddfour:SizeToContents()

modeldisplayddlist:AddItem( modelddfour )
– And ends here*/
/* local modelpanelbutton = vgui.Create( “DButton” );
modelpanelbutton:SetParent( “menupanel” );
modelpanelbutton:SetSize( 60, 20 );
modelpanelbutton:SetPos( 50, 30 );
modelpanelbutton:SetText( “Model” )
modelpanelbutton.DoClick = function( modelpanel )
modelpanel:Close();
end
modelpanelbutton.DoClick = function( icon )
icon:Close();
end*/

end
end
end

concommand.Add( “menu”, vguiMenus )[/lua]

Perhaps I should remove these options, or just remove it from the top left corner and put it in a menu. Since now I have a bit of a idea in what direction I need to work in…