/gmod-3d2d-clipping

✂️ Simple library for efficient and cross-platform clipping of 3D2D GUI in Garry's Mod

Primary LanguageLuaMIT LicenseMIT

3d2d-clipping

✂️ Simple library for efficient and cross-platform clipping of 3D2D GUI in Garry's Mod

Example

Example

Left: No clipping
Right: 2D clipped

Usage

Loading the Library

my_addon.clip = include("lib/clip.lua")

Clipping 2D Rectangles

local width, height = 200, 400
cam.Start3D2D(pos, ang, scale)
    my_addon.clip:Scissor2D(width, height)
        -- Draw 2D clipped stuff here!
    my_addon.clip()
cam.End3D2D()

Clipping 3D Bounding Boxes

local mins, maxs = ent:OBBMins(), ent:OBBMaxs()
-- or
local mins, maxs = ent:GetModelBounds()

my_addon.clip:Scissor3D(pos, ang, mins, maxs)
    cam.Start3D2D(pos, ang, scale)
        -- Draw 3D clipped stuff here!
    cam.End3D2D()
my_addon.clip()

In most cases, this is not recommended because stencils are fundamentally 2D, leading to depth issues like this:

Depth Problems Example