Skip to main content

Viewport

@3dverse/livelink v0.8.10


@3dverse/livelink / Viewport

Class: Viewport

Defined in: livelink.js/sources/rendering/Viewport.ts:29

A viewport is a rendering area on a RenderingSurfaceBase that is associated with a CameraProjection.

It can have overlays that are rendered on top of the viewport. See OverlayInterface.

Viewports can overlap each other, in which case the one with the highest z-index is rendered on top.

Extends

Constructors

new Viewport()

new Viewport(params): Viewport

Defined in: livelink.js/sources/rendering/Viewport.ts:209

Creates a new viewport.

Parameters

params
core

Livelink

The Livelink core used to send commands.

rendering_surface

RenderingSurfaceBase

The rendering surface on which the viewport is displayed.

options

{ rect: RelativeRect; render_target_index: number; z_index: number; dom_element: HTMLElement; }

The options for the viewport.

options.rect

RelativeRect

The relative position and size of the viewport in relation to the rendering surface.

options.render_target_index

number

The index of the render target that is rendered on the viewport.

options.z_index

number

The z-index of the viewport.

options.dom_element

HTMLElement

The DOM element used for picking.

Returns

Viewport

Overrides

TypedEventTarget<ViewportEvents>.constructor

Accessors

rendering_surface

Get Signature

get rendering_surface(): RenderingSurfaceBase

Defined in: livelink.js/sources/rendering/Viewport.ts:99

The rendering surface on which the viewport is displayed.

Returns

RenderingSurfaceBase


camera_projection

Get Signature

get camera_projection(): null | CameraProjection

Defined in: livelink.js/sources/rendering/Viewport.ts:106

The camera projection used to render the scene.

Returns

null | CameraProjection

Set Signature

set camera_projection(camera_projection): void

Defined in: livelink.js/sources/rendering/Viewport.ts:181

Sets the camera projection used to render the scene.

Parameters
camera_projection

CameraProjection

Returns

void


width

Get Signature

get width(): number

Defined in: livelink.js/sources/rendering/Viewport.ts:113

The width of the viewport in pixels.

Returns

number


height

Get Signature

get height(): number

Defined in: livelink.js/sources/rendering/Viewport.ts:120

The height of the viewport in pixels.

Returns

number


offset

Get Signature

get offset(): Vec2

Defined in: livelink.js/sources/rendering/Viewport.ts:127

The offset of the viewport in pixels.

Returns

Vec2


aspect_ratio

Get Signature

get aspect_ratio(): number

Defined in: livelink.js/sources/rendering/Viewport.ts:137

The aspect ratio of the viewport.

Returns

number


z_index

Get Signature

get z_index(): number

Defined in: livelink.js/sources/rendering/Viewport.ts:144

The z-index of the viewport.

Returns

number

Set Signature

set z_index(z_index): void

Defined in: livelink.js/sources/rendering/Viewport.ts:165

Sets the z-index of the viewport.

Parameters
z_index

number

Returns

void


render_target_index

Get Signature

get render_target_index(): number

Defined in: livelink.js/sources/rendering/Viewport.ts:151

The index of the render target that is rendered on the viewport.

Returns

number

Set Signature

set render_target_index(render_target_index): void

Defined in: livelink.js/sources/rendering/Viewport.ts:192

The index of the render target that is rendered on the viewport.

-1 means the default render target as defined by the render graph assigned to the camera the viewport is using.

Parameters
render_target_index

number

Returns

void


relative_rect

Get Signature

get relative_rect(): RelativeRect

Defined in: livelink.js/sources/rendering/Viewport.ts:158

The relative position and size of the viewport in relation to the rendering surface.

Returns

RelativeRect

Set Signature

set relative_rect(rect): void

Defined in: livelink.js/sources/rendering/Viewport.ts:173

Sets the relative position and size of the viewport in relation to the rendering surface.

Parameters
rect

RelativeRect

Returns

void

Methods

addEventListener()

addEventListener<_EventName>(event_name, listener, options?): void

Defined in: livelink.js/sources/TypedEventTarget.ts:10

Type Parameters

_EventName extends "on-entity-hovered" | "on-entity-picked"

Parameters

event_name

_EventName

listener

(event) => void

options?

boolean | AddEventListenerOptions

Returns

void

Inherited from

TypedEventTarget.addEventListener


removeEventListener()

removeEventListener<_EventName>(event_name, listener, options?): void

Defined in: livelink.js/sources/TypedEventTarget.ts:21

Type Parameters

_EventName extends "on-entity-hovered" | "on-entity-picked"

Parameters

event_name

_EventName

listener

(event) => void

options?

boolean | EventListenerOptions

Returns

void

Inherited from

TypedEventTarget.removeEventListener


isValid()

isValid(): boolean

Defined in: livelink.js/sources/rendering/Viewport.ts:232

Returns whether the viewport is valid.

A viewport is valid if a camera projection is set on it.

Returns

boolean


release()

release(): void

Defined in: livelink.js/sources/rendering/Viewport.ts:239

Releases the resources used by the viewport.

Returns

void


activatePicking()

activatePicking(): void

Defined in: livelink.js/sources/rendering/Viewport.ts:252

Activates picking on the viewport.

If picking is activated, the viewport will emit an on-entity-picked event when it is clicked.

Returns

void


deactivatePicking()

deactivatePicking(): void

Defined in: livelink.js/sources/rendering/Viewport.ts:269

Deactivates picking on the viewport.

If picking is deactivated, the viewport will no longer emit an on-entity-picked event when it is clicked.

Returns

void


activateHovering()

activateHovering(): void

Defined in: livelink.js/sources/rendering/Viewport.ts:291

Experimental

Activates entity hovering on the viewport.

If hovering is activated, the viewport will emit an on-entity-hovered event when it is hovered.

Returns

void


deactivateHovering()

deactivateHovering(): void

Defined in: livelink.js/sources/rendering/Viewport.ts:310

Experimental

Deactivates entity hovering on the viewport.

If hovering is deactivated, the viewport will no longer emit an on-entity-hovered event when it is hovered.

Returns

void


castScreenSpaceRay()

castScreenSpaceRay(params): Promise<null | { entity: Entity; world_position: Vec3; world_normal: Vec3; }>

Defined in: livelink.js/sources/rendering/Viewport.ts:341

Casts a screen space ray and returns the first entity and world space position and normal that the ray intersects. If no entity is intersected, null is returned.

Note that transparent objects will be picked if they are in front of opaque objects even if their opacity is set to 0.

Do not use this method for picking objects using the mouse cursor. Instead activate picking on the viewport using activatePicking and listen for the on-entity-picked event.

Parameters

params
screen_position

Vec2

The screen space position to cast the ray from.

mode

HighlightMode = "None"

The highlight mode to use.

Returns

Promise<null | { entity: Entity; world_position: Vec3; world_normal: Vec3; }>

The entity and world space position and normal that the ray intersects, or null if no entity is intersected.


projectWorldToScreen()

projectWorldToScreen(params): Vec3

Defined in: livelink.js/sources/rendering/Viewport.ts:383

Projects a world space position to screen space.

The position is projected using the camera projection set on the viewport.

Parameters

params
world_position

Vec3

The position in world space to project.

out_screen_position

Vec3 = ...

The output position in screen space.

Returns

Vec3

The position in screen space.


addOverlay()

addOverlay(params): void

Defined in: livelink.js/sources/rendering/Viewport.ts:412

Adds an overlay to the viewport.

Parameters

params
overlay

OverlayInterface

The overlay to add. Must not have been added to the viewport before.

Returns

void


removeOverlay()

removeOverlay(params): void

Defined in: livelink.js/sources/rendering/Viewport.ts:428

Removes an overlay from the viewport.

The overlay is released and should not be used after this method is called.

Parameters

params
overlay

OverlayInterface

The overlay to remove. Must have been added to the viewport before.

Returns

void


drawOverlays()

drawOverlays(): null | OffscreenCanvas

Defined in: livelink.js/sources/rendering/Viewport.ts:443

Returns

null | OffscreenCanvas


getScreenPositionFromEvent()

getScreenPositionFromEvent(params): Vec2

Defined in: livelink.js/sources/rendering/Viewport.ts:486

Return the screen position from a mouse event.

Parameters

params
event

MouseEvent

The mouse event.

Returns

Vec2

The screen position as a Vec2. (0, 0) is the top-left corner of the viewport, (1, 1) is the bottom-right corner.