SDK3DVerse.engineAPI. cameraAPI

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.

Parameters:
NameTypeDescription
clientUUIDstring

Client unique identifier. See getClientUUIDs

Returns:

The camera entities of the client.

Type: 
Array.<Entity>

getViewportById(viewportId) → {Viewport}

Get the viewport with the specified id.

Parameters:
NameTypeDescription
viewportIduint

The viewport id

Returns:

The viewport.

Type: 
Viewport
Example
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.

Returns:

Array of viewports.

Type: 
Array.<Viewport>
Example
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.

Parameters:
NameTypeDescription
eventNamestring

The name of the event (e.g. click, dblclick, mouseup, mousedown)

listenerViewportMouseEventListener

The listener function

Example
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.

Parameters:
NameTypeDescription
cameraEntityEntity

Entity that contains a camera component

Example
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.

Parameters:
NameTypeDescription
viewportsArray.<ViewportInfo>

Array of ViewportInfo objects

Example
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.

Parameters:
NameTypeDescription
controllerSettingsPartial.<CameraControllerSettings>

A partial object containing camera controller settings

Example
SDK3DVerse.engineAPI.cameraAPI.updateControllerSettings({ sensitivity : 0.1 });