|
1 |
| -# ui3d2d |
2 |
| -A simple and optimised library for drawing 3D2D UIs in Garry's Mod. Supports both immediate mode drawing and VGUI (found in the extras file). |
| 1 | +# UI3D2D |
| 2 | +A Garry's Mod helper library for drawing user interfaces within 3D space. |
3 | 3 |
|
4 |
| -# Example Usage |
5 |
| -## Adding UI to an entity: |
6 |
| -```lua |
7 |
| -ENT.RenderGroup = RENDERGROUP_TRANSLUCENT |
8 |
| - |
9 |
| -local pos = Vector(0, 0, 0) |
10 |
| -local angles = Angle(0, 0, 0) |
11 |
| - |
12 |
| -local color_red = Color(255, 0, 0) |
13 |
| - |
14 |
| -function ENT:DrawTranslucent() |
15 |
| - if not ui3d2d.startDraw(self:WorldToLocal(pos), self:WorldToLocalAngles(angles), .1, self) then return end --Skip drawing if the player can't see the UI |
16 |
| - |
17 |
| - --Draw your UI here |
18 |
| - surface.SetFont("DermaLarge") |
19 |
| - local w, h = surface.GetTextSize("Hover me!") |
20 |
| - |
21 |
| - draw.RoundedBox(0, 0, 0, w, h, color_white) |
22 |
| - |
23 |
| - if ui3d2d.isPressed() then --Flash red if input was pressed this frame |
24 |
| - draw.RoundedBox(0, 0, 0, w, h, color_red) |
25 |
| - end |
26 |
| - |
27 |
| - if ui3d2d.isHovering(0, 0, w, h) then --Check if the box is being hovered |
28 |
| - if ui3d2d.isPressing() then --Check if input is being held |
29 |
| - draw.SimpleText("Wow!", nil, 0, 0, color_black) |
30 |
| - else |
31 |
| - draw.SimpleText("Click me!", nil, 0, 0, color_black) |
32 |
| - end |
33 |
| - else |
34 |
| - draw.SimpleText("Hover me!", nil, 0, 0, color_black) |
35 |
| - end |
36 |
| - |
37 |
| - ui3d2d.endDraw() --Finish the UI render |
38 |
| -end |
39 |
| -``` |
40 |
| - |
41 |
| -## Adding UI to the world: |
42 |
| -```lua |
43 |
| -local pos = Vector(0, 0, 0) |
44 |
| -local angles = Angle(0, 0, 0) |
45 |
| - |
46 |
| -hook.Add("PostDrawTranslucentRenderables", "DrawMyUI", function(_, depthDrawing) |
47 |
| - if depthDrawing then return end |
48 |
| - |
49 |
| - if ui3d2d.startDraw(pos, angles, .1) then |
50 |
| - --Draw your UI here |
51 |
| - ui3d2d.endDraw() |
52 |
| - end |
53 |
| -end) |
54 |
| -``` |
55 |
| - |
56 |
| -# Global Functions |
57 |
| -## ui3d2d.startDraw |
58 |
| -```lua |
59 |
| -ui3d2d.startDraw(pos :: Vector, angles :: Angle, scale :: number, ignoredEntity :: Entity) :: boolean |
60 |
| -``` |
61 |
| -This starts a UI3D2D rendering context in immediate mode, calling this will calculate your mouse position and input status for the same frame. |
62 |
| -- The ignoredEntity paramater is optional, this is used for disabling eyetrace collisions with the entity you're attaching your UI to. |
63 |
| - |
64 |
| -## ui3d2d.endDraw |
65 |
| -```lua |
66 |
| -ui3d2d.endDraw() |
67 |
| -``` |
68 |
| -This ends a UI3D2D rendering context, only call this if you have called startDraw already and it has returned true. |
69 |
| - |
70 |
| -## ui3d2d.isPressing |
71 |
| -```lua |
72 |
| -ui3d2d.isPressing() :: boolean |
73 |
| -``` |
74 |
| -This returns true if the user is holding down the UI input key. |
75 |
| - |
76 |
| -## ui3d2d.isPressed |
77 |
| -```lua |
78 |
| -ui3d2d.isPressed() :: boolean |
79 |
| -``` |
80 |
| -This returns true if the user started pressing the UI input key on this frame. |
81 |
| - |
82 |
| -## ui3d2d.getCursorPos |
83 |
| -```lua |
84 |
| -ui3d2d.getCursorPos() :: number, number |
85 |
| -``` |
86 |
| -This returns two numbers, the x and y values of the cursor position on the current UI. |
87 |
| -- This will return nil if the player isn't looking at the UI. |
88 |
| - |
89 |
| -## ui3d2d.isHovering |
90 |
| -```lua |
91 |
| -ui3d2d.isHovering(x :: number, y :: number, w :: number, h :: number) :: boolean |
92 |
| -``` |
93 |
| -This will return true if the cursor is currently within the bounds of the box specified in the parameters. |
94 |
| - |
95 |
| -## ui3d2d.drawVgui (Extra only) |
96 |
| -```lua |
97 |
| -ui3d2d.drawVgui(panel :: Panel, pos :: Vector, angles :: Angle, scale :: number, ignoredEntity :: Entity) |
98 |
| -``` |
99 |
| -This will draw a VGUI panel in 3D space and allow the user to interact with it. |
100 |
| -- The ignoredEntity paramater is optional, this is used for disabling eyetrace collisions with the entity you're attaching your UI to. |
| 4 | +# Documentation |
| 5 | +The API reference and help articles for UI3D2D can be found [here](https://docs.tomdotbat.dev/ui3d2d/getting-started). |
101 | 6 |
|
102 | 7 | # Credits
|
103 | 8 | - The main library code was based on [IMGUI by Wyozi](https://github.com/wyozi-gmod/imgui).
|
|
0 commit comments