Handles the creation and retrieval of viewports, each of which is associated to a camera. See Viewport class for more details.
Methods
getClientCameras(clientUUID) → {Array.<Entity>}
Get the camera entities of the clients in session.
Name | Type | Description |
---|---|---|
clientUUID | string | Client unique identifier. See getClientUUIDs |
The camera entities of the client.
- Type:
- Array.<Entity>
getViewportById(viewportId) → {Viewport}
Get the viewport with the specified id.
Name | Type | Description |
---|---|---|
viewportId | uint | The viewport id |
The viewport.
- Type:
- Viewport
const viewport = SDK3DVerse.engineAPI.cameraAPI.getViewportById(0);
getViewports() → {Array.<Viewport>}
Get viewports. These viewports were previously set by a call to one functions listed below.
Array of viewports.
- Type:
- Array.<Viewport>
const viewport = SDK3DVerse.engineAPI.cameraAPI.getViewports()[0];
onMouseEvent(eventName, listener)
Register the listener function on the canvas to the MouseEvent named eventName
. When the event is raised, the listener function receives the Viewport object along with the event.
Name | Type | Description |
---|---|---|
eventName | string | The name of the event (e.g. click, dblclick, mouseup, mousedown) |
listener | ViewportMouseEventListener | The listener function |
SDK3DVerse.engineAPI.cameraAPI.onMouseEvent('dblclick', (viewport, event) =>
{
// do something with viewport, event
});
(async) setMainCamera(cameraEntity)
Setup a single viewport with an existing camera entity.
The viewport will be given a viewport id of 0, and draw over the entire canvas. This is a helper function that calls setViewports for you.
Name | Type | Description |
---|---|---|
cameraEntity | Entity | Entity that contains a camera component |
await SDK3DVerse.engineAPI.cameraAPI.setMainCamera(cameraEntity);
(async) setViewports(viewports)
Set all viewports that are drawing to the canvas. If a viewport with id specified in ViewportInfo already exists, then updates the properties of the Viewport object. Otherwise, a new Viewport is created.
Name | Type | Description |
---|---|---|
viewports | Array.<ViewportInfo> | Array of ViewportInfo objects |
const viewportInfo = {
id: 0,
width: 1.0,
height: 1.0,
left: 0.0,
top: 0.0,
defaultControllerType: SDK3DVerse.cameraControllerType.editor,
onCameraCreation: (cameraEntity) => { console.log(cameraEntity.getName(), "was created") }
};
// This will create a viewport that draws over the entire canvas.
// A default camera is also created, with an 'editor' camera controller.
// This camera is associated to the viewport, and is a transient entity. Transient entities only exist for the duration of the session.
await SDK3DVerse.engineAPI.cameraAPI.setViewports([viewportInfo]);
const viewport = SDK3DVerse.engineAPI.cameraAPI.getViewportById(viewportInfo.id);
updateControllerSettings(controllerSettings)
Update the controller settings (e.g. speed, sensitivity) of the cameras of all viewports.
Name | Type | Description |
---|---|---|
controllerSettings | Partial.<CameraControllerSettings> | A partial object containing camera controller settings |
SDK3DVerse.engineAPI.cameraAPI.updateControllerSettings({ sensitivity : 0.1 });