Is it possible to use effects in a DModelPanel

So the problem is pretty much the one the title poses, I have been trying to use util.effect and attach the effect to the entity inside of the DModelPanel, but it says that the entity is a nil value. Does anyone know if this is even possible or have any examples of similar problems.

e.g


model.LayoutEntity = function()

    local effect = EffectData()
    effect:SetEntity( model.Entity )
    util.Effect("my_effect",effect )
 
end

This returns an error, any help is appreciated.

Post the error please? We can’t help without it.

The effect would return an error stating that the entity was nil (it’s a player model) when I tried to get its bone index for positioning. I also tried getting the entities position and just using that to position my effect, rather than set the entity and let it do it automatically, that didn’t work either though.

I don’t think that’s actually possible.

You would need to grab the EFFECT:Draw( ) function and run it inside

DModelPanel.DrawModel( )

[lua]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)
self.Entity:DrawModel()
render.SetScissorRect(0,0,0,0, false)
end[/lua]

This is the function for DModelPanel, needs to be overwritten to include the code FROM…

[lua]
function EFFECT:Render( )
<Your effect draw lua>
end
[/lua]

Other then that, I don’t think it’s possible.

EDIT:
You should look at DModelPanel’s code which can be found in your garrysmod/garrysmod/lua/vgui/dmodelpanel.lua directory.

Alright, I’ll give this a shot and get back to you.

Doesn’t appear to be working. The effect is drawn at the world position.



				if IsValid( self.Entity ) then
					effect = EffectData()
					effect:SetOrigin( self.vCamPos + self.Entity:GetPos())
					print( self.Entity:GetPos() )
					util.Effect( "un_bliz", effect )
				end


Tried putting that in the draw model function and the paint function, neither worked.

It wont work because util.Effect doesn’t render anything. You’d need to have something along the lines of render.DrawSprite, to render.DrawBeam in order for this to work.

You cannot use util.Effect because it creates an entity, it’s not used itself as a render function.

It is possible; I’ve done it. But, you may not get the results you’d want without a lot of work.

I rendered light effects; but instead of facing the direction they were supposed to be facing, they faced the player, not the panels camera. The panel scene is rendered at vector_origin, or 0, 0, 0… If you’re offset from that location, then the effects will face a different direction, towards the player in the 3d world and not the camera. If you want an effect to be visible, you’ll need to rewrite how things are drawn / draw everything manually ( and find a way around the direction issue. Luckily, with ParticleEmitter you can use the second argument to force the particle to render in 3d so forcing it to face the camera instead of the player should be easy enough )

This seems like a bug, but I haven’t done much with it since I found that out.