Viewport Class
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.
Item Index
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:
The aspect ratio of the viewport.
getNormalized
-
canvas
-
mouse
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
ComponentCanvas for offset calculation.
-
mouse
MouseMouse object with coordinates inside of the canvas.
Returns:
Normalized coordinated of the mouse.
isInside
-
canvas
-
mouse
Check if the mouse is inside this viewport.
Parameters:
-
canvas
ComponentCanvas for offset calculation.
-
mouse
MouseMouse object with coordinates inside of the canvas.
toJSON
()
Object
Serializer viewport data to JSON.
Returns:
Serialized viewport object.
toJSON
-
data
Fill viewport data from serialized JSON data.
Parameters:
-
data
ObjectSerialized 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
ViewportViewport 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.