API Reference

Class List

pc.CameraComponent

Extends: pc.Component

The Camera Component enables an Entity to render the scene. A scene requires at least one enabled camera component to be rendered. Note that multiple camera components can be enabled simulataneously (for split-screen or offscreen rendering, for example).

// Add a pc.CameraComponent to an entity
var entity = new pc.Entity();
entity.addComponent('camera', {
    nearClip: 1,
    farClip: 100,
    fov: 55
});
// Get the pc.CameraComponent on an entity
var cameraComponent = entity.camera;
// Update a property on a camera component
entity.camera.nearClip = 2;

Summary

Properties

aspectRatioThe aspect ratio of the camera.
clearColorThe color used to clear the canvas to before the camera starts to render.
clearColorBufferIf true the camera will clear the color buffer to the color set in clearColor.
clearDepthBufferIf true the camera will clear the depth buffer.
clearStencilBufferIf true the camera will clear the stencil buffer.
farClipThe distance from the camera after which no rendering will take place.
fovThe field of view of the camera in degrees.
frustumQueries the camera's frustum shape.[read only]
frustumCullingControls the culling of mesh instances against the camera frustum.
horizontalFovSet which axis to use for the Field of View calculation.
nearClipThe distance from the camera before which no rendering will take place.
orthoHeightThe half-height of the orthographic view window (in the Y-axis).
postEffectsThe post effects queue for this camera.
priorityControls the order in which cameras are rendered.
projectionThe type of projection used to render the camera.
projectionMatrixQueries the camera's projection matrix.[read only]
rectControls where on the screen the camera will be rendered in normalized screen coordinates.
renderTargetThe render target of the camera.
viewMatrixQueries the camera's view matrix.[read only]
vrDisplayThe pc.VrDisplay that the camera is current displaying to.

Methods

enterVrAttempt to start presenting this camera to a pc.VrDisplay.
exitVrAttempt to stop presenting this camera.
screenToWorldConvert a point from 2D screen space to 3D world space.
worldToScreenConvert a point from 3D world space to 2D screen space.

Inherited

Properties

enabledEnables or disables the component.

Details

Constructor

CameraComponent(system, entity)

Create a new Camera Component.

// Add a pc.CameraComponent to an entity
var entity = new pc.Entity();
entity.addComponent('camera', {
    nearClip: 1,
    farClip: 100,
    fov: 55
});
// Get the pc.CameraComponent on an entity
var cameraComponent = entity.camera;
// Update a property on a camera component
entity.camera.nearClip = 2;

Parameters

systempc.CameraComponentSystemThe ComponentSystem that created this Component.
entitypc.EntityThe Entity that this Component is attached to.

Properties

NumberaspectRatio

The aspect ratio of the camera. This is the ratio of width divided by height. Default to 16/9.

pc.ColorclearColor

The color used to clear the canvas to before the camera starts to render.

BooleanclearColorBuffer

If true the camera will clear the color buffer to the color set in clearColor.

BooleanclearDepthBuffer

If true the camera will clear the depth buffer.

BooleanclearStencilBuffer

If true the camera will clear the stencil buffer.

NumberfarClip

The distance from the camera after which no rendering will take place.

Numberfov

The field of view of the camera in degrees. Usually this is the Y-axis field of view, see pc.CameraComponent#horizontalFov. Used for pc.PROJECTION_PERSPECTIVE cameras only. Defaults to 45.

pc.Frustumfrustum

Queries the camera's frustum shape.[read only]

BooleanfrustumCulling

Controls the culling of mesh instances against the camera frustum. If true, culling is enabled. If false, all mesh instances in the scene are rendered by the camera, regardless of visibility. Defaults to false.

BooleanhorizontalFov

Set which axis to use for the Field of View calculation. Defaults to false (use Y-axis).

NumbernearClip

The distance from the camera before which no rendering will take place.

NumberorthoHeight

The half-height of the orthographic view window (in the Y-axis). Used for pc.PROJECTION_ORTHOGRAPHIC cameras only. Defaults to 10.

pc.PostEffectQueuepostEffects

The post effects queue for this camera. Use this to add or remove post effects from the camera.

Numberpriority

Controls the order in which cameras are rendered. Cameras with smaller values for priority are rendered first.

Numberprojection

The type of projection used to render the camera. Can be:

Defaults to pc.PROJECTION_PERSPECTIVE.

pc.Mat4projectionMatrix

Queries the camera's projection matrix.[read only]

pc.Vec4rect

Controls where on the screen the camera will be rendered in normalized screen coordinates. The order of the values is [x, y, width, height].

pc.RenderTargetrenderTarget

The render target of the camera. Defaults to null, which causes the camera to render to the canvas' back buffer. Setting a valid render target effectively causes the camera to render to an offscreen buffer, which can then be used to achieve certain graphics effect (normally post effects).

pc.Mat4viewMatrix

Queries the camera's view matrix.[read only]

pc.VrDisplayvrDisplay

The pc.VrDisplay that the camera is current displaying to. This is set automatically by calls to pc.CameraComponent#enterVr or pc.CameraComponent#exitVr. Setting this property to a display directly enables the camera to use the transformation information from a display without rendering stereo to it, e.g. for "magic window" style experiences.

// enable magic window style interface
var display = this.app.vr.display;
if (display) {
    this.entity.camera.vrDisplay = display;
}

var camera = this.entity.camera;
camera.enterVr(function (err) {
if (err) { return; }
    var display = camera.vrDisplay; // access presenting pc.VrDisplay
});

Methods

enterVr([display], callback)

Attempt to start presenting this camera to a pc.VrDisplay.

// On an entity with a camera component
this.entity.camera.enterVr(function (err) {
    if (err) {
        console.error(err);
        return;
    } else {
        // in VR!
    }
});

Parameters

displaypc.VrDisplayThe VrDisplay to present. If not supplied this uses pc.VrManager#display as the default
callbackfunctionFunction called once to indicate success of failure. The callback takes one argument (err). On success it returns null on failure it returns the error message.

exitVr(callback)

Attempt to stop presenting this camera.

this.entity.camera.exitVr(function (err) {
    if (err) {
        console.error(err);
    } else {

    }
});

Parameters

callbackfunctionFunction called once to indicate success of failure. The callback takes one argument (err). On success it returns null on failure it returns the error message.

screenToWorld(screenx, screeny, cameraz, [worldCoord])

Convert a point from 2D screen space to 3D world space.

// Get the start and end points of a 3D ray fired from a screen click position
var start = entity.camera.screenToWorld(clickX, clickY, entity.camera.nearClip);
var end = entity.camera.screenToWorld(clickX, clickY, entity.camera.farClip);

// Use the ray coordinates to perform a raycast
app.systems.rigidbody.raycastFirst(start, end, function (result) {
    console.log("Entity " + result.entity.name + " was selected");
});

Parameters

screenxNumberx coordinate on PlayCanvas' canvas element.
screenyNumbery coordinate on PlayCanvas' canvas element.
camerazNumberThe distance from the camera in world space to create the new point.
worldCoordpc.Vec33D vector to recieve world coordinate result.

Returns

pc.Vec3 The world space coordinate.

worldToScreen(worldCoord, [screenCoord])

Convert a point from 3D world space to 2D screen space.

Parameters

worldCoordpc.Vec3The world space coordinate.
screenCoordpc.Vec33D vector to recieve screen coordinate result.

Returns

pc.Vec3 The screen space coordinate.

Inherited

Properties

Booleanenabled

Enables or disables the component.