LogoObsidian

Viewport

Viewports embed 3D objects inside your UI using Roblox viewport frames.

Playground

Allow orbit + zoom controls
Focus on object automatically

Usage

You can create a Viewport by calling the AddViewport method on a Groupbox.

Arguments

local Viewport = Groupbox:AddViewport("MyViewport", {
    Object = Instance.new("Part"),
    Camera = Instance.new("Camera"),
    Interactive = true,
    AutoFocus = true,
    Height = 200,
})
Arg IdxArgument DescriptionTypeDefault
1Index/ID of the viewport elementstringnil
2Viewport configuration tabletablenil

Configuration Table

Prop

Type

Methods

You can use the following methods to interact with the viewport element:

SetObject

Changes the displayed 3D object.

Viewport:SetObject(object)
Arg IdxArgument DescriptionTypeDefault
1Object instance to displayInstancenil

SetCamera

Updates the camera instance.

Viewport:SetCamera(camera)
Arg IdxArgument DescriptionTypeDefault
1Camera instanceInstance (Camera)nil

SetInteractive

Toggles user interaction.

Viewport:SetInteractive(interactive)
Arg IdxArgument DescriptionTypeDefault
1Whether the viewport is interactivebooleannil

SetHeight

Adjusts the viewport frame height.

Viewport:SetHeight(height)
Arg IdxArgument DescriptionTypeDefault
1Frame height in pixelsnumbernil

Focus

Focuses the camera on the object.

Viewport:Focus()
Arg IdxArgument DescriptionTypeDefault
1No arguments

Example

local Options = Library.Options
 
local Viewport = Groupbox:AddViewport("DemoViewport", {
    Object = Instance.new("Part"),
    Camera = Instance.new("Camera"),
    Interactive = true,
    AutoFocus = true,
    Height = 240,
})
 
Viewport:SetInteractive(true)
Viewport:SetHeight(260)
Viewport:Focus()

On this page