Viewport Class

Module: Cameras

The viewport object is used to handle virtual visualization windows for the WebGL renderer.

It uses normalized coordinates [0 to 1] when using RELATIVE mode or pixel based coordinated for ABSOLUTE mode.

Methods

enable

(
  • renderer
)

Enable this viewport for rendering using a WebGLRenderer

After rendering the WebGL renderer has to manually reset to the original values.

Parameters:

  • renderer WebGLRenderer

getAspectRatio

() Number

Get the aspect ratio of this viewport in x / y.

Returns:

Number:

The aspect ratio of the viewport.

getNormalized

(
  • canvas
  • mouse
)
Vector2

Get normalized coordinates between [-1, 1] for a canvas size and mouse position.

Usefull to use raycasting for object picking in a viewport.

Parameters:

  • canvas Component

    Canvas for offset calculation.

  • mouse Mouse

    Mouse object with coordinates inside of the canvas.

Returns:

Vector2:

Normalized coordinated of the mouse.

isInside

(
  • canvas
  • mouse
)

Check if the mouse is inside this viewport.

Parameters:

  • canvas Component

    Canvas for offset calculation.

  • mouse Mouse

    Mouse object with coordinates inside of the canvas.

toJSON

() Object

Serializer viewport data to JSON.

Returns:

Object:

Serialized viewport object.

toJSON

(
  • data
)

Fill viewport data from serialized JSON data.

Parameters:

  • data Object

    Serialized viewport object.

update

(
  • container
)

Update the viewport box from the values.

Has to be called after applying changes to the viewport, the viewport is resized of the

Parameters:

  • container Viewport

    Viewport that contains this viewport (optional).

Properties

anchor

Number

Positioning anchor of the viewport.

height

Number

Height of the final output canvas.

This height should match the canvas size / rendering resolution.

mode

Number

Viewport sizing mode.

Can be RELATIVE or ABSOLUTE.

offset

Vector2

Camera viewport offset.

Values range from 0.0 to 1.0 in screen space when in RELATIVE mode.

size

Vector2

Camera viewport size.

Values range from 0.0 to 1.0 in screen space when in RELATIVE mode.

viewport

Vector4

Calculated absolute viewport values (x, y, width, height) stored in a vector.

It is calculated using the update() method that should be called after applying changes.

width

Number

Width of the final output canvas.

This width should match the canvas size / rendering resolution.

Attributes

ABSOLUTE

static

Viewport defined absolutely in pixels.

RELATIVE

static

Viewport calculated relatively to the screen viewport.