Class Camera

Package: @aspose/3d (v24.12.0)

Camera is an Entity that can be attached to a Node to define a viewpoint in the scene. It supports both perspective and orthographic projections, controlled by the projectionType property. Camera parameters are stored in the 3D file when the scene is saved to a format that supports cameras (FBX, COLLADA, glTF).

export class Camera extends Entity

Inheritance

A3DObject ← SceneObject ← Entity ← Camera

Examples

Add a perspective camera to a scene and configure its frustum.

import { Scene, Node } from '@aspose/3d';
import { Camera } from '@aspose/3d';

const scene = new Scene();

const camNode = scene.rootNode.createChildNode('mainCamera');
const camera = new Camera('mainCamera', 'PERSPECTIVE');
camNode.entity = camera;

camera.nearPlane = 0.1;
camera.farPlane = 500;
camera.fieldOfView = 60;
camera.aspect = 16 / 9;

scene.save('output.gltf');
console.log(`Camera projection: ${camera.projectionType}`);
// Camera projection: PERSPECTIVE

Properties

PropertyTypeDefaultDescription
namestring''The name of this camera, used to identify it in the scene graph.
projectionTypestring'PERSPECTIVE'Projection mode. Accepted values match the ProjectionType enumeration: 'PERSPECTIVE' or 'ORTHOGRAPHIC'.
nearPlanenumber0.1Distance from the camera to the near clipping plane. Objects closer than this value are not rendered.
farPlanenumber1000.0Distance from the camera to the far clipping plane. Objects farther than this value are not rendered.
aspectnumber1.0The width-to-height aspect ratio of the camera’s viewport.
fieldOfViewnumber0.0Diagonal field of view in degrees (perspective projection).
fieldOfViewXnumber0.0Horizontal field of view in degrees.
fieldOfViewYnumber0.0Vertical field of view in degrees.
orthoHeightnumber100.0The height of the orthographic projection volume. Only relevant when projectionType is 'ORTHOGRAPHIC'.
widthnumber0.0Sensor or viewport width, used when apertureMode controls FOV derivation.
heightnumber0.0Sensor or viewport height.
aspectRationumber1.0Alias for the aspect ratio, provided for compatibility with some FBX-originated scenes.

Methods

moveForward(distance)

Moves the camera forward along its look direction by the given distance.

moveForward(distance: number): void

Parameters

distance number

The distance to move forward. Negative values move the camera backward.

Returns

void

Examples

import { Scene } from '@aspose/3d';
import { Camera } from '@aspose/3d';

const scene = new Scene();
const camNode = scene.rootNode.createChildNode('cam');
const camera = new Camera('cam', 'PERSPECTIVE');
camNode.entity = camera;

camera.moveForward(10);
console.log('Camera moved forward by 10 units.');

Notes

  • In the source, Camera inherits from Entity. Light also extends Camera, which means Light objects have all camera properties in the type hierarchy; this reflects the FBX data model where lights and cameras share a common base node type.
  • The projectionType string values are case-sensitive uppercase strings matching the internal ProjectionType enumeration names ('PERSPECTIVE', 'ORTHOGRAPHIC').