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 EntityInheritance
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
| Property | Type | Default | Description |
|---|---|---|---|
name | string | '' | The name of this camera, used to identify it in the scene graph. |
projectionType | string | 'PERSPECTIVE' | Projection mode. Accepted values match the ProjectionType enumeration: 'PERSPECTIVE' or 'ORTHOGRAPHIC'. |
nearPlane | number | 0.1 | Distance from the camera to the near clipping plane. Objects closer than this value are not rendered. |
farPlane | number | 1000.0 | Distance from the camera to the far clipping plane. Objects farther than this value are not rendered. |
aspect | number | 1.0 | The width-to-height aspect ratio of the camera’s viewport. |
fieldOfView | number | 0.0 | Diagonal field of view in degrees (perspective projection). |
fieldOfViewX | number | 0.0 | Horizontal field of view in degrees. |
fieldOfViewY | number | 0.0 | Vertical field of view in degrees. |
orthoHeight | number | 100.0 | The height of the orthographic projection volume. Only relevant when projectionType is 'ORTHOGRAPHIC'. |
width | number | 0.0 | Sensor or viewport width, used when apertureMode controls FOV derivation. |
height | number | 0.0 | Sensor or viewport height. |
aspectRatio | number | 1.0 | Alias 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): voidParameters
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,
Camerainherits fromEntity.Lightalso extendsCamera, which meansLightobjects 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
projectionTypestring values are case-sensitive uppercase strings matching the internalProjectionTypeenumeration names ('PERSPECTIVE','ORTHOGRAPHIC').