GetRenderBounds? Scaling DModelPanels automatically?

Hey, so i’m working on the clientside for my inventory system and i am looking for some advice on how i would use GetRenderBounds with a DModelPanel to make it so the model automatically fits into the Panel, if that was clear?

TL;DR:

I would like some help with making model panels automatically scale the models and set the camera position so that everything is visible in the panel

Thanks in advance!

That’s possible with some magic school maths.



    local min, max = modelpanel.Entity:GetRenderBounds()
    local size = 0
    -- Get maximum value of all axis
    size = math.max(size, math.abs(min.x) + math.abs(max.x))
    size = math.max(size, math.abs(min.y) + math.abs(max.y))
    size = math.max(size, math.abs(min.z) + math.abs(max.z))

    modelpanel:SetFOV(45)
    modelpanel:SetCamPos(Vector(size, size, size))
    modelpanel:SetLookAt((min + max) * 0.5) -- Add & multiply vector by 0.5, to get the "middle" between the two


Worked fine, thanks very much!