GuiService3D - Adorn Parts and GuiObjects to 3D space relative to the camera

With my GuiService3D you can adorn BaseParts and GuiObjects to 3D space relative to the camera with ease and create cool effects such as 2D GUIs rotating on 3 axes, or superimposing 3D objects on top of your game’s GUIs.

LINK TO THE MODEL

This is the API copied directly from what I have written in the GuiService3D module.

[code] You need both GuiService3D and ScreenService to run this properly. Put them under the same parent.
ScreenService will create a ScreenGui “ResolutionGetter” in each player’s PlayerGui when it’s first required.
That ScreenGui is used to get the resolution.
Be aware that GuiObjects will not display properly if you try to scale them down too small. Increase the depth to scale them up. This bug is due to the fact that SurfaceGui surfaces can’t be scaled down past 0.2 studs.
The bug also affects Parts, since they cannot be scaled down past 0.2 studs
The bug doesn’t occur for part adornments that have meshes, since the meshes can be scaled to whatever size is necessary.

API:
ScreenService
:GetResolution() {Vector2 resolution}
Returns the screen resolution.

:GetAspectRatio([Vector2 resolution]) {Number aspectRatio}
Returns the aspect ratio of the resolution you supply, or the aspect ratio of the current resolution.

:UDim2ToVector2(UDim2 udim2, Vector2 resolution) {Vector2 pixelPosition}
Converts a UDim2 into a Vector2.

GuiService3D
:GetPixel3D(Vector2 pixelPosition, Number depth) {CFrame frame}
Returns the 3D position of a pixel at the specified depth

:GetCorners3D(Number depth) {CFrame topLeft, CFrame bottomRight}
Returns the position of the top left and bottom right pixels and the specified depth.

:AdornFrame(Object frame, Number depth, String fType) {GuiData guiData}
Used to adorn a GuiObject or a BasePart to 3D space relative to the camera.
If you’re adorning a GuiObject, set fType to “Gui2D”. If you’re adorning a BasePart, set fType to “Part”
Depth is how many studs away your adornment will be from the camera.
This method returns a GuiData object which is used to further manipulate the adornment.
Every GuiObject adornment will create a Part “AdornedFrame3DTarget” in the workspace (if filtering is enabled, otherwise it will be in the current camera) that the frame will be added to

:UnadornFrame(Object frame)
Used to undo AdornFrame.

:ForceUpdate()
Used to force the frames of all the adornments to update.
Use this if you’re setting the camera’s orientation with you’re own code. If you don’t then every adornment update will be one frame late.

GuiData
This is the object returned by GuiService3D:AdornFrame

.Rotation3D = CFrame
This is the rotation offset that the object will have. Be aware that your CFrame’s position setting will still be accounted for.

.PixelPosition = Vector2
The pixel position of whatever you’re adorning. Only affects BasePart adornments.

.PixelSize = Vector2
The pixel size of whatever you’re adorning. Only affects BasePart adornments.[/code]

I’m using this in my game to superimpose a spinning gem onto my UI and I plan to be using it for a much more cool stuff.

Also, please be aware that, since adornments are in 3D space, there’s a potential for objects to appear between the adornment and the camera.

If you make anything cool with this please post about it here so everyone can see. Enjoy!

1 Like