Skip to main content

Viewport

Creates a ViewportFrame with size fitting and drag controls. This means that the viewport will center the camera around the given instance, and allow the user to control the camera itself.

local viewport = Viewport.new()
viewport:SetInstance(instance)

maid:GiveTask(viewport:Render({
	Parent = target;
}):Subscribe())

Functions

new

Viewport.new() → Viewport

Constructs a new viewport. Unlike a normal BasicPane this will not render anything immediately. See Viewport.Render for details.

blend

Viewport.blend(props{string}) → Observable<Instance>

Creates a Viewport and render it to Blend. The following properties are supported

  • Ambient - Color3
  • AnchorPoint - Vector2
  • FieldOfView - number
  • Instance - Instance
  • LayoutOrder - number
  • LightColor - Color3
  • Parent - Instance
  • Position - UDim2
  • Size - Vector3
  • Transparency - number

Properties may be anything Blend would take as computable. See Blend for details.

SetTransparency

Viewport:SetTransparency(transparencynumber) → ()

Sets the field of view on the viewport.

SetFieldOfView

Viewport:SetFieldOfView(fieldOfViewnumber) → ()

Sets the field of view on the viewport.

SetInstance

Viewport:SetInstance(instanceInstance?) → ()

Set the instance to be rendered. The instance will be reparented to the viewport.

warning

The instance you set here will NOT be destroyed by the viewport. This lets the performance be optimized or the instance used in good transitions. However, be sure to destroy it if you need to.

NotifyInstanceSizeChanged

Viewport:NotifyInstanceSizeChanged() → ()

Notifies the viewport of the instance size changing. We don't connect to any events here because the instance can be anything.

Render

Viewport:Render(props{any}) → Observable<ViewportFrame>

Renders the viewport. Allows the following properties.

  • Ambient - Color3
  • ImageColor3 - Color3
  • AnchorPoint - Vector2
  • LayoutOrder - number
  • LightColor - Color3
  • Parent - Instance
  • Position - UDim2
  • Size - Vector3
  • Transparency - number
warning

This should only be called once per a Viewport instance, since the Instance property is not duplicated.

Show raw api
{
    "functions": [
        {
            "name": "new",
            "desc": "Constructs a new viewport. Unlike a normal [BasicPane] this will not render anything\nimmediately. See [Viewport.Render] for details.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Viewport"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 48,
                "path": "src/viewport/src/Client/Viewport.lua"
            }
        },
        {
            "name": "blend",
            "desc": "Creates a Viewport and render it to Blend. The following properties are supported\n\n* Ambient - Color3\n* AnchorPoint - Vector2\n* FieldOfView - number\n* Instance - Instance\n* LayoutOrder - number\n* LightColor - Color3\n* Parent - Instance\n* Position - UDim2\n* Size - Vector3\n* Transparency - number\n\nProperties may be anything Blend would take as computable. See [Blend] for details.",
            "params": [
                {
                    "name": "props",
                    "desc": "",
                    "lua_type": "{ string }"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<Instance>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 86,
                "path": "src/viewport/src/Client/Viewport.lua"
            }
        },
        {
            "name": "SetTransparency",
            "desc": "Sets the field of view on the viewport.",
            "params": [
                {
                    "name": "transparency",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 134,
                "path": "src/viewport/src/Client/Viewport.lua"
            }
        },
        {
            "name": "SetFieldOfView",
            "desc": "Sets the field of view on the viewport.",
            "params": [
                {
                    "name": "fieldOfView",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 145,
                "path": "src/viewport/src/Client/Viewport.lua"
            }
        },
        {
            "name": "SetInstance",
            "desc": "Set the instance to be rendered. The instance will be reparented\nto the viewport.\n\n:::warning\nThe instance you set here will NOT be destroyed by the viewport. This lets the\nperformance be optimized or the instance used in good transitions. However,\nbe sure to destroy it if you need to.\n:::",
            "params": [
                {
                    "name": "instance",
                    "desc": "",
                    "lua_type": "Instance?"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 163,
                "path": "src/viewport/src/Client/Viewport.lua"
            }
        },
        {
            "name": "NotifyInstanceSizeChanged",
            "desc": "Notifies the viewport of the instance size changing. We don't connect to\nany events here because the instance can be anything.",
            "params": [],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 179,
                "path": "src/viewport/src/Client/Viewport.lua"
            }
        },
        {
            "name": "Render",
            "desc": "Renders the viewport. Allows the following properties.\n\n* Ambient - Color3\n* ImageColor3 - Color3\n* AnchorPoint - Vector2\n* LayoutOrder - number\n* LightColor - Color3\n* Parent - Instance\n* Position - UDim2\n* Size - Vector3\n* Transparency - number\n\n:::warning\nThis should only be called once per a Viewport instance, since the Instance property is\nnot duplicated.\n:::",
            "params": [
                {
                    "name": "props",
                    "desc": "",
                    "lua_type": "{ any }"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<ViewportFrame>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 227,
                "path": "src/viewport/src/Client/Viewport.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "Viewport",
    "desc": "Creates a ViewportFrame with size fitting and drag controls. This means that the\nviewport will center the camera around the given instance, and allow the user\nto control the camera itself.\n\n```lua\nlocal viewport = Viewport.new()\nviewport:SetInstance(instance)\n\nmaid:GiveTask(viewport:Render({\n\tParent = target;\n}):Subscribe())\n```",
    "source": {
        "line": 17,
        "path": "src/viewport/src/Client/Viewport.lua"
    }
}