Skip to main content

Camera

Enum

ClassTypeNameInterface Description
EnumEnumEnum.CameraClearTypeFunction: Defines how the camera clears the buffer.
EnumEnumEnum.CameraTypeFunction: Defines the type of camera (e.g., perspective camera or orthographic camera).

CameraType

TypeEnumeration MembersInterface Description
EnumOrthoOrthographic Camera
EnumPerspectivePerspective Camera

CameraClearType

TypeEnumeration MembersInterface Description
EnumColorClear color only
EnumColorDepthClear color and depth
EnumColorDepthStencilClear color, depth and stencil
EnumColorStencilClear color and stencil
EnumDepthClear depth only
EnumDepthStencilClear depth and stencil
EnumDontClear nothing
EnumStencilClear stencil only
EnumTextureClear color with a texture
EnumTextureDepthClear depth with a texture

Camera

TypeNameInterface DescriptionExample
VariablesclearColor: ColorFunction: Defines the color used when the camera clears the buffer.Code block

1 cam.clearColor = new

2 API.Color(1,0,0);

VariablesclearType: CameraClearTypeFunction: Specifies how the camera clears the buffer.Code block

1 cam.clearType =

2 API.CameraClearType.ColorDep

3 thStencil;

Examples

clearColor: Color

 cam.clearColor = new APJS.Color(1,1,0);

clearType: CameraClearType

cam.clearType = APJS.CameraClearType.ColorDepthStencil;

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Camera');
let camera = child?.getComponent('Camera') as APJS.Camera;
if(!camera) return;

this.time += deltaTime;
camera.clearType = APJS.CameraClearType.Color;
camera.clearColor = new APJS.Color(
(Math.cos(this.time) + 1) * 0.5,
(Math.sin(this.time) + 1) * 0.5,
(this.time - Math.floor(this.time)));
}
}

DemoCameraClear.zip

TypeNameInterface Description
Variablesorthographic.numberFunction: The height of the camera view in orthographic projection mode.

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Camera');
let camera = child?.getComponent('Camera') as APJS.Camera;
if(!camera) return;

this.time += deltaTime;
camera.orthoHeight = 15 + Math.sin(this.time) * 3;
}
}
TypeNameInterface Description
Variablesfar: numberFunction: The distance of the camera's far clipping plane.
Variablesnear: numberFunction: The distance of the camera's near clipping plane.

Examples

far: number

cam.far = 100;

near: number

cam.near = 0.1;

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Camera');
let camera = child?.getComponent('Camera') as APJS.Camera;
if(!camera) return;

this.time += deltaTime;
console.log(`near:${camera.near}\nfar:${camera.far}`);
}
}

DemoCameraFarNear.zip

TypeNameInterface Description
Variablesfov: numberFunction: The field of view (FOV) of the camera, used in perspective projection mode.

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Camera');
let camera = child?.getComponent('Camera') as APJS.Camera;
if(!camera) return;

this.time += deltaTime;
camera.fov = 60 + Math.sin(this.time) * 30;
}
}

DemoCameraFov.zip

TypeNameInterface Description
VariablesinputTexture: Texture | nullFunction: Input texture which can serve as the input source for camera rendering.

Example

cam.inputTexture = tex;

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
private texture;// get a texture in some way
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Camera');
let camera = child?.getComponent('Camera') as APJS.Camera;
if(!camera) return;

if (camera.inputTexture === null)
camera.inputTexture = this.texture;
else
camera.inputTexture = null;
}
}
TypeNameInterface Description
VariablesrenderLayer: LayerSetFunction: Specify the layers visible to the camera.

Example

cam.renderLayer = 1;

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Camera');
let camera = child?.getComponent('Camera') as APJS.Camera;
if(!camera) return;

console.log('renderLayer:',camera.renderLayer);
}
}
TypeNameInterface Description
VariablesrenderTexture: TextureFunction: The output texture of camera rendering.

Example

cam.renderTexture = outputTex;

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Camera');
let camera = child?.getComponent('Camera') as APJS.Camera;
if(!camera) return;

console.log('renderTexture:',camera.renderTexture.name);
}
}
TypeNameInterface Description
Variablesviewport: RectFunction: Defines the viewport area rendered by the camera.

Example

cam.viewport = new APJS.Rect(0,0,1,1);

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Camera');
let camera = child?.getComponent('Camera') as APJS.Camera;
if(!camera) return;

console.log('viewport:',camera.viewport);
}
}

DemoCemaraViewport.zip

TypeNameInterface Description
VariablesrenderOrder: numberFunction: Defines the rendering order of the camera.

Example

camera.renderLayer = 2;

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Camera');
let camera = child?.getComponent('Camera') as APJS.Camera;
if(!camera) return;

console.log('renderLayer:',camera.renderLayer);
}
}
TypeNameInterface Description
VariablesprojectionMatrix: Matrix4x4f [Read Only]Function: The projection matrix of the camera.

Example

let mat = cam.projectionMatrix;

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Camera');
let camera = child?.getComponent('Camera') as APJS.Camera;
if(!camera) return;

console.log('projectionMatrix:',camera.projectionMatrix);
}
}
TypeNameInterface Description
VariablescameraType: CameraTypeFunction: The type of camera (perspective or orthographic).

Example

    cam.cameraType = APJS.CameraType.Ortho;

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Camera');
let camera = child?.getComponent('Camera') as APJS.Camera;
if(!camera) return;

console.log('cameraType:',camera.cameraType);
}
}
TypeNameInterface Description
FunctionsviewportWorldToBoid(point: Vector3f): Vector3fFunction: Convert viewport coordinates to world coordinates.

Example

camera.viewportToWorldPoint(new Vector3f(0.5,0.5,0.5));

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Camera');
let camera = child?.getComponent('Camera') as APJS.Camera;
if(!camera) return;

let viewportPoint = new Vector3f(0.5, 0.5, 0.5);
let worldPoint = camera.viewportToWorldPoint(viewportPoint);
console.log(`Viewport point ${viewportPoint} converted to world point ${worldPoint}`);
}
}
TypeNameInterface Description
FunctionsworldToViewportPoint(point: Vector3f): Vector3fFunction: Convert world coordinates to viewport coordinates.

Example

let viewportPoint = camera.worldToViewportPoint(new Vector3f(10,10,10));

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Camera');
let camera = child?.getComponent('Camera') as APJS.Camera;
if(!camera) return;

let worldPoint = new Vector3f(10, 10, 10);
let viewportPoint = camera.worldToViewportPoint(worldPoint);
console.log(`World point ${worldPoint} converted to viewport point ${viewportPoint}`);
}
TypeNameInterface Description
FunctionsscreenToWorldPoint(screen: Vector3f): Vector3fFunction: Convert screen coordinates to world coordinates.

Example

let worldPointFromScreen = camera.screenToWorldPoint(new Vector2f(400, 300), 10);

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Camera');
let camera = child?.getComponent('Camera') as APJS.Camera;
if(!camera) return;

let screenPoint = new Vector2f(400, 300);
let depth = 10;
let worldPointFromScreen = camera.screenToWorldPoint(screenPoint, depth);
console.log(`Screen point ${screenPoint} with depth ${depth} converted to world point ${worldPointFromScreen}.`);
}
TypeNameInterface Description
FunctionsworldToViewportPoint(point: Vector3f): Vector3fFunction: Convert world coordinates to screen coordinates.

Example

let camera = new Camera();
let worldPoint = new Vector3f(10, 10, 10);
let screenPoint = camera.worldToScreenPoint(worldPoint);
console.log(World point ${worldPoint} converted to screen point ${screenPoint}.);

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Camera');
let camera = child?.getComponent('Camera') as APJS.Camera;
if(!camera) return;

let worldPoint = new Vector3f(10, 10, 10);
let screenPoint = camera.worldToScreenPoint(worldPoint);
console.log(`World point ${worldPoint} converted to screen point ${screenPoint}.`);
}
TypeNameInterface Description
FunctionsgetCameraToWorldMatrix(): Matrix4x4f

Returns: Matrix4x4f

Description: The transformation matrix from camera space to world space.

Description: Get the matrix that transforms from camera space to world space. Use this to calculate where in the world a specific camera space point is located.

FunctionsgetWorldToCameraMatrix(): Matrix4x4f

Returns: Matrix4x4f

Description: The transformation matrix from world space to camera space.

Description: Retrieves the matrix that transforms coordinates from world space to camera space.

This matrix is commonly known as the "view matrix" in graphics literature.

It can be used to determine the position of game objects in camera space or to specify a custom camera location independent of its transform.

FunctionsgetLookAt(): Vector3f

Returns: Vector3f

Description: The forward direction vector of the camera.

Description: Gets the camera's forward direction, also known as the "look at" direction.

FunctionsviewportPointToRay(viewportPoint: Vector2f): Ray

Parameters: viewportPoint: Vector2f

Returns: Ray

Description: A point in viewport space represented as a Vector2f.

Returns: Ray

Description: The calculated world space ray as a Ray object.

Description: Generates a ray from the specified position in the camera's viewport space.

Examples

getCameraToWorldMatrix(): Matrix4x4f

let mat = camera.getCameraToWorldMatrix()

getWorldToCameraMatrix(): Matrix4x4f

let mat = camera.getWorldToCameraMatrix()

getLookAt(): Vector3f

let vec = camera.getLookAt();

viewportPointToRay(viewportPos: Vector2f): Ray;

let ray = camera.viewportPointToRay(new Vector2f(0.5, 0.5));

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Camera');
let camera = child?.getComponent('Camera') as APJS.Camera;
if(!camera) return;

console.log("cameraToWorldMatrix",camera.getCameraToWorldMatrix());
console.log("worldToCameraMatrix",camera.getWorldToCameraMatrix());
console.log("getLookAt",camera.getLookAt());
const ray = camera.viewportPointToRay(new APJS.Vector2f(0.5, 0.5));
console.log("ray",ray);
}
}

DemoCamera4API.zip

Copyright © 2025 TikTok. All rights reserved.
About TikTokHelp CenterCareersContactLegalCookies