Garry's Mod

Garry's Mod

Not enough ratings
Rounded Poly Box/Border
   
Award
Favorite
Favorited
Unfavorite
Content Type: Addon
Addon Type: Effects
File Size
Posted
9.412 KB
26 Aug, 2021 @ 3:07am
1 Change Note ( view )

Subscribe to download
Rounded Poly Box/Border

In 1 collection by Goofus
Rounded Poly Box/Border
1 item
Description
Rounded Poly Box/Border
This addon allows you to create rounded boxes and borders using surface.drawpoly.

Rounded Poly Box:
This works just like the gmod's draw.roundedboxEX except the pivot point is located at the center of the shape.

/*code*\
/*prec defines the number of slices you want for a rounded corner.
u & v are for uv tiling & cache makes the function return a table of the calculated shape
(use whenever you can for better performance)*\

draw.RoundedPolyBoxEX( radius, x, y, w, h, prec, u, v, tl, tr, bl, br, cache )

/*usage w/ cache*/
local box = draw.RoundedPolyBoxEX( 124, 0, 0, 256, 256, 5, 1, 1, true, true, true, true, true )

(in drawing hook)
for i = 1, #box do
surface.DrawPoly( box )
end

NOTE
You can just call surface.SetMaterial() for applying a texture with no use of stencils, but what I didn't realize was that each triangle created with drawpoly will sample the texture (you can view by activating texture budget in console) which is bad so use stencils when you can especially if you're making a lot of these.

I like to use this for derma panels.

Rounded Poly Border:
This compliments Poly Box by creating an outline around it, but you can use it for other stuff too. The real power is in it's calculated uvs that wrap around the border.

/*code*\
/*Prec defines the number of slices you want for a rounded corner.
Extrude defines the outline width.
u & v are for uv tiling, u_offset & v_offset take a value from -1 to 1.
Cache works just the same, but you really want to use it for this when you can*\

draw.RoundedPolyBorderEX( radius, extrude, x, y, w, h, prec, u, v, u_offset, v_offset, tl, tr, bl, br, cache )

/*usage w/ cache*/
local outline = draw.RoundedPolyBorderEX( 124, 24, 0, 0, 256 , 256, 10, 1, 1, 0, 0, true, true, true, true, true )

(in drawing hook)
for i = 1, #outline do
surface.DrawPoly( outline )
end

NOTE
Really use the cache for something like this since drawing this is way more expensive. Watch out for too narrow bends this can lead to uv anomalies. Seams are going to exist of course tho I only noticed them when I applied a scrolling texture and tanked my fps to 35.

I like to use this for making rounded or circular gauges/progress bars using RT textures. Having control of the uvs can make this look way better than the other drawpoly codes out there and can make refactoring a breeze.

All of these functions have a lot of overhead (due to how versatile they are), but it should be easy for you to create ones for specific problems.