Skip to main content

Class: SpatialPanel

Defined in: src/ui/layouts/SpatialPanel.ts:15

A fundamental UI container that displays content on a 2D quad in 3D space. It supports background colors, rounded corners (squircles), and can be made interactive and draggable. It serves as a base for building complex user interfaces.

The panel intelligently selects a shader:

  • SpatialPanelShader: For interactive, draggable panels with hover/select highlights.
  • SquircleShader: For static, non-interactive panels with a clean, rounded look.

Extends

Constructors

Constructor

new SpatialPanel(options): SpatialPanel

Defined in: src/ui/layouts/SpatialPanel.ts:24

Creates an instance of SpatialPanel.

Parameters

options

SpatialPanelOptions = {}

Returns

SpatialPanel

Overrides

Panel.constructor

Properties

aspectRatio

aspectRatio: number = 1.0

Defined in: src/ui/core/View.ts:72

The calculated aspect ratio (width / height) of this view.

Inherited from

Panel.aspectRatio


backgroundColor

backgroundColor: string = '#c2c2c255'

Defined in: src/ui/core/Panel.ts:80

The background color of the panel, expressed as a CSS color string.

Inherited from

Panel.backgroundColor


dragFacingCamera

dragFacingCamera: boolean = true

Defined in: src/ui/layouts/SpatialPanel.ts:19

Keeps the panel facing the camera as it is dragged.


draggable

draggable: boolean = false

Defined in: src/ui/core/Panel.ts:55

Determines if the panel can be dragged by the user.

Inherited from

Panel.draggable


draggingMode?

optional draggingMode: DragMode

Defined in: src/ui/core/Panel.ts:58

Dragging mode, defaults to true if draggable else undefined.

Inherited from

Panel.draggingMode


height

height: number = 1

Defined in: src/ui/core/View.ts:42

The height of the view, as a 0-1 ratio of its parent's available space.

Inherited from

Panel.height


isPanel

isPanel: boolean = true

Defined in: src/ui/core/Panel.ts:49

Type identifier for easy checking with instanceof.

Inherited from

Panel.isPanel


isQuad

isQuad: boolean = true

Defined in: src/ui/core/View.ts:27

Flag indicating View behaves as a 2D quad in layout calculations.

Inherited from

Panel.isQuad


isRoot

isRoot: boolean = false

Defined in: src/ui/core/View.ts:29

Flag indicating if this is the root view of a layout.

Inherited from

Panel.isRoot


isView

isView: boolean = true

Defined in: src/ui/core/View.ts:31

Type identifier for easy checking with instanceof.

Inherited from

Panel.isView


isXRScript

isXRScript: boolean = true

Defined in: src/core/Script.ts:53

Inherited from

Panel.isXRScript


keepFacingCamera

keepFacingCamera: boolean = true

Defined in: src/ui/core/Panel.ts:43

Inherited from

Panel.keepFacingCamera


mesh

mesh: PanelMesh

Defined in: src/ui/core/Panel.ts:52

The underlying mesh that renders the panel's background.

Inherited from

Panel.mesh


name

name: string = 'Panel'

Defined in: src/ui/core/Panel.ts:46

Text description of the view

Inherited from

Panel.name


onFadeComplete()?

optional onFadeComplete: () => void

Defined in: src/ui/core/Panel.ts:116

An optional callback function to execute when a fade animation completes.

Returns

void

Inherited from

Panel.onFadeComplete


opacity

opacity: number = 1.0

Defined in: src/ui/core/View.ts:68

The overall opacity of the view and its children.

Inherited from

Panel.opacity


paddingX

paddingX: number = 0

Defined in: src/ui/core/View.ts:59

Horizontal padding, as a 0-1 ratio of the parent's width.

Inherited from

Panel.paddingX


paddingY

paddingY: number = 0

Defined in: src/ui/core/View.ts:61

Vertical padding, as a 0-1 ratio of the parent's height.

Inherited from

Panel.paddingY


paddingZ

paddingZ: number = 0

Defined in: src/ui/core/View.ts:63

Depth padding, for z-axis adjustment to prevent z-fighting.

Inherited from

Panel.paddingZ


selectable

selectable: boolean = true

Defined in: src/ui/core/View.ts:33

Determines if this view can be targeted by user input.

Inherited from

Panel.selectable


showHighlights

showHighlights: boolean = false

Defined in: src/ui/core/Panel.ts:77

Whether to show highlights for the spatial panel.

Inherited from

Panel.showHighlights


touchable

touchable: boolean = false

Defined in: src/ui/core/Panel.ts:61

Determines if the panel can be touched by the user's hands.

Inherited from

Panel.touchable


useBorderlessShader

useBorderlessShader: boolean = false

Defined in: src/ui/core/Panel.ts:72

Panel by default uses borderless shader. This flag indicates whether to use borderless shader for Spatial Panels.

Inherited from

Panel.useBorderlessShader


useDefaultPosition

useDefaultPosition: boolean = true

Defined in: src/ui/core/Panel.ts:66

If true, a root panel will automatically spawn in front of the user.

Inherited from

Panel.useDefaultPosition


ux

ux: UX

Defined in: src/core/Script.ts:52

Inherited from

Panel.ux


weight

weight: number = 0.5

Defined in: src/ui/core/View.ts:38

Proportional size used in layouts like Row or Col.

Inherited from

Panel.weight


width

width: number = 1

Defined in: src/ui/core/View.ts:40

The width of the view, as a 0-1 ratio of its parent's available space.

Inherited from

Panel.width


x

x: number = 0

Defined in: src/ui/core/View.ts:47

The local x-coordinate within the parent's layout, from -0.5 to 0.5. For root view (Panel), this will be addition to the global positioning.

Inherited from

Panel.x


y

y: number = 0

Defined in: src/ui/core/View.ts:52

The local y-coordinate within the parent's layout, from -0.5 to 0.5. For root view (Panel), this will be addition to the global positioning.

Inherited from

Panel.y


z

z: number = 0

Defined in: src/ui/core/View.ts:57

The local z-coordinate within the parent's layout. For root view (Panel), this will be addition to the global positioning.

Inherited from

Panel.z


dependencies

static dependencies: object

Defined in: src/ui/core/Panel.ts:41

timer

timer: typeof Timer = THREE.Timer

user

user: typeof User = User

Inherited from

Panel.dependencies

Accessors

rangeX

Get Signature

get rangeX(): number

Defined in: src/ui/core/View.ts:79

Gets the effective horizontal range for child elements, normalized to 1.0 for the smaller dimension.

Returns

number

The horizontal layout range.

Inherited from

Panel.rangeX


rangeY

Get Signature

get rangeY(): number

Defined in: src/ui/core/View.ts:88

Gets the effective vertical range for child elements, normalized to 1.0 for the smaller dimension.

Returns

number

The vertical layout range.

Inherited from

Panel.rangeY

Methods

add()

add(...children): SpatialPanel

Defined in: src/ui/core/View.ts:215

Overrides THREE.Object3D.add to automatically trigger a layout update when a new View is added as a child.

Parameters

children

...Object3D<Object3DEventMap>[]

Returns

SpatialPanel

Inherited from

Panel.add


addGrid()

addGrid(): Grid

Defined in: src/ui/core/Panel.ts:290

Adds a Grid layout as a direct child of this panel.

Returns

Grid

The newly created Grid instance.

Inherited from

Panel.addGrid


dispose()

dispose(): void

Defined in: src/core/Script.ts:196

Called when the script is removed from the scene. Opposite of init.

Returns

void

Inherited from

Panel.dispose


dpToLocalUnits()

dpToLocalUnits(dp): number

Defined in: src/ui/core/View.ts:123

Converts a value from Density-Independent Pixels (DP) to local units.

Parameters

dp

number

The value in density-independent pixels.

Returns

number

The equivalent value in local units.

Inherited from

Panel.dpToLocalUnits


fadeIn()

fadeIn(duration?, onComplete?): void

Defined in: src/ui/core/Panel.ts:186

Starts fading the panel and its children in.

Parameters

duration?

number

Optional fade duration in seconds.

onComplete?

() => void

Optional callback when fade completes.

Returns

void

Inherited from

Panel.fadeIn


fadeOut()

fadeOut(duration?, onComplete?): void

Defined in: src/ui/core/Panel.ts:197

Starts fading the panel and its children out.

Parameters

duration?

number

Optional fade duration in seconds.

onComplete?

() => void

Optional callback when fade completes.

Returns

void

Inherited from

Panel.fadeOut


getHeight()

getHeight(): number

Defined in: src/ui/core/Panel.ts:321

Gets the panel's height in meters.

Returns

number

The height in meters.

Inherited from

Panel.getHeight


getWidth()

getWidth(): number

Defined in: src/ui/core/Panel.ts:313

Gets the panel's width in meters.

Returns

number

The width in meters.

Inherited from

Panel.getWidth


hide()

hide(): void

Defined in: src/ui/core/View.ts:137

Makes the view and all its descendants invisible.

Returns

void

Inherited from

Panel.hide


init()

init(__namedParameters): void

Defined in: src/ui/core/Panel.ts:159

Initializes the panel, setting its default position if applicable.

Parameters

__namedParameters
timer

Timer

user

User

Returns

void

Inherited from

Panel.init


initPhysics()

initPhysics(_physics): void | Promise<void>

Defined in: src/core/Script.ts:72

Enables depth-aware interactions with physics. See /demos/ballpit

Parameters

_physics

Physics

Returns

void | Promise<void>

Inherited from

Panel.initPhysics


onHoverEnter()

onHoverEnter(_controller): void

Defined in: src/core/Script.ts:157

Called when the controller starts hovering over this object with reticle.

Parameters

_controller

Object3D

An XR controller.

Returns

void

Inherited from

Panel.onHoverEnter


onHoverExit()

onHoverExit(_controller): void

Defined in: src/core/Script.ts:162

Called when the controller hovers over this object with reticle.

Parameters

_controller

Object3D

An XR controller.

Returns

void

Inherited from

Panel.onHoverExit


onHovering()

onHovering(_controller): void

Defined in: src/core/Script.ts:167

Called when the controller hovers over this object with reticle.

Parameters

_controller

Object3D

An XR controller.

Returns

void

Inherited from

Panel.onHovering


onKeyDown()

onKeyDown(_event): void

Defined in: src/core/Script.ts:109

Called on keyboard keypress.

Parameters

_event

KeyEvent

Event containing .code to read the keyboard key.

Returns

void

Inherited from

Panel.onKeyDown


onKeyUp()

onKeyUp(_event): void

Defined in: src/core/Script.ts:110

Parameters

_event

KeyEvent

Returns

void

Inherited from

Panel.onKeyUp


onObjectGrabbing()

onObjectGrabbing(_event): void

Defined in: src/core/Script.ts:187

Called every frame a hand is grabbing this object.

Parameters

_event

ObjectGrabEvent

Returns

void

Inherited from

Panel.onObjectGrabbing


onObjectGrabEnd()

onObjectGrabEnd(_event): void

Defined in: src/core/Script.ts:191

Called when a hand stops grabbing this object.

Parameters

_event

ObjectGrabEvent

Returns

void

Inherited from

Panel.onObjectGrabEnd


onObjectGrabStart()

onObjectGrabStart(_event): void

Defined in: src/core/Script.ts:183

Called when a hand starts grabbing this object (touching + pinching).

Parameters

_event

ObjectGrabEvent

Returns

void

Inherited from

Panel.onObjectGrabStart


onObjectSelectEnd()

onObjectSelectEnd(_event): boolean

Defined in: src/core/Script.ts:150

Called when the controller stops selecting this object the script represents, e.g. View, ModelView.

Parameters

_event

SelectEvent

event.target holds its controller.

Returns

boolean

Whether the event was handled

Inherited from

Panel.onObjectSelectEnd


onObjectSelectStart()

onObjectSelectStart(_event): boolean

Defined in: src/core/Script.ts:141

Called when the controller starts selecting this object the script represents, e.g. View, ModelView.

Parameters

_event

SelectEvent

event.target holds its controller.

Returns

boolean

Whether the event was handled

Inherited from

Panel.onObjectSelectStart


onObjectTouchEnd()

onObjectTouchEnd(_event): void

Defined in: src/core/Script.ts:179

Called when a hand's index finger stops touching this object.

Parameters

_event

ObjectTouchEvent

Returns

void

Inherited from

Panel.onObjectTouchEnd


onObjectTouching()

onObjectTouching(_event): void

Defined in: src/core/Script.ts:175

Called every frame that a hand's index finger is touching this object.

Parameters

_event

ObjectTouchEvent

Returns

void

Inherited from

Panel.onObjectTouching


onObjectTouchStart()

onObjectTouchStart(_event): void

Defined in: src/core/Script.ts:171

Called when a hand's index finger starts touching this object.

Parameters

_event

ObjectTouchEvent

Returns

void

Inherited from

Panel.onObjectTouchStart


onSelect()

onSelect(_event): void

Defined in: src/core/Script.ts:98

Called whenever pinch / mouse click successfully completes, globally.

Parameters

_event

SelectEvent

event.target holds its controller.

Returns

void

Inherited from

Panel.onSelect


onSelectEnd()

onSelectEnd(_event): void

Defined in: src/core/Script.ts:92

Called whenever pinch / mouse click discontinues, globally.

Parameters

_event

SelectEvent

event.target holds its controller

Returns

void

Inherited from

Panel.onSelectEnd


onSelecting()

onSelecting(_event): void

Defined in: src/core/Script.ts:103

Called whenever pinch / mouse click is happening, globally.

Parameters

_event

SelectEvent

Returns

void

Inherited from

Panel.onSelecting


onSelectStart()

onSelectStart(_event): void

Defined in: src/core/Script.ts:86

Called whenever pinch / mouse click starts, globally.

Parameters

_event

SelectEvent

event.target holds its controller

Returns

void

Inherited from

Panel.onSelectStart


onSimulatorStarted()

onSimulatorStarted(): void

Defined in: src/core/Script.ts:78

Returns

void

Inherited from

Panel.onSimulatorStarted


onSqueeze()

onSqueeze(_event): void

Defined in: src/core/Script.ts:132

Called whenever gamepad trigger successfully completes, globally.

Parameters

_event

SelectEvent

event.target holds its controller.

Returns

void

Inherited from

Panel.onSqueeze


onSqueezeEnd()

onSqueezeEnd(_event): void

Defined in: src/core/Script.ts:121

Called whenever gamepad trigger stops, globally.

Parameters

_event

SelectEvent

event.target holds its controller.

Returns

void

Inherited from

Panel.onSqueezeEnd


onSqueezeStart()

onSqueezeStart(_event): void

Defined in: src/core/Script.ts:116

Called whenever gamepad trigger starts, globally.

Parameters

_event

SelectEvent

event.target holds its controller.

Returns

void

Inherited from

Panel.onSqueezeStart


onSqueezing()

onSqueezing(_event): void

Defined in: src/core/Script.ts:126

Called whenever gamepad is being triggered, globally.

Parameters

_event

SelectEvent

Returns

void

Inherited from

Panel.onSqueezing


onTriggered()

onTriggered(_id): void

Defined in: src/ui/core/View.ts:230

Hook called on a complete select action (e.g., a click) when this view is the target. Intended for override by subclasses.

Parameters

_id

number

The ID of the controller that triggered the action.

Returns

void

Inherited from

Panel.onTriggered


onXRSessionEnded()

onXRSessionEnded(): void

Defined in: src/core/Script.ts:76

Returns

void

Inherited from

Panel.onXRSessionEnded


onXRSessionStarted()

onXRSessionStarted(_session?): void

Defined in: src/core/Script.ts:75

Parameters

_session?

XRSession

Returns

void

Inherited from

Panel.onXRSessionStarted


physicsStep()

physicsStep(): void

Defined in: src/core/Script.ts:73

Returns

void

Inherited from

Panel.physicsStep


resetLayout()

resetLayout(): void

Defined in: src/ui/core/View.ts:195

Resets the layout state of this view. Intended for override by subclasses.

Returns

void

Inherited from

Panel.resetLayout


resetLayouts()

resetLayouts(): void

Defined in: src/ui/core/View.ts:198

Resets the layout state for this view and all its descendants.

Returns

void

Inherited from

Panel.resetLayouts


show()

show(): void

Defined in: src/ui/core/View.ts:129

Makes the view and all its descendants visible.

Returns

void

Inherited from

Panel.show


update()

update(): void

Defined in: src/ui/layouts/SpatialPanel.ts:34

Updates the fade animation progress each frame.

Returns

void

Overrides

Panel.update


updateLayout()

updateLayout(): void

Defined in: src/ui/core/Panel.ts:299

Updates the panel's visual dimensions based on its layout properties.

Returns

void

Inherited from

Panel.updateLayout


updateLayouts()

updateLayouts(): void

Defined in: src/ui/core/View.ts:171

Triggers a layout update for this view and all its descendants.

Returns

void

Inherited from

Panel.updateLayouts


updateLayoutsBFS()

updateLayoutsBFS(): void

Defined in: src/ui/core/View.ts:179

Performs a Breadth-First Search (BFS) traversal to update the layout tree, ensuring parent layouts are calculated before their children.

Returns

void

Inherited from

Panel.updateLayoutsBFS


dpToMeters()

static dpToMeters(dp): number

Defined in: src/ui/core/View.ts:114

Converts a value from Density-Independent Pixels (DP) to meters.

Parameters

dp

number

The value in density-independent pixels.

Returns

number

The equivalent value in meters.

Inherited from

Panel.dpToMeters