BabylonJS/Babylon.js · error · Error

${context}: Camera perspective properties are missing

Error message

${context}: Camera perspective properties are missing

What it means

For a camera of type 'perspective', the glTF spec requires a 'perspective' object (with yfov and znear). When _loadCameraAsync finds camera.perspective missing for a PERSPECTIVE camera, it throws because fov/near/far cannot be populated.

Source

Thrown at packages/dev/loaders/src/glTF/2.0/glTFLoader.pure.ts:1715

        const promises = new Array<Promise<unknown>>();

        this.logOpen(`${context} ${camera.name || ""}`);

        this._babylonScene._blockEntityCollection = !!this._assetContainer;
        const babylonCamera = new FreeCamera(camera.name || `camera${camera.index}`, Vector3.Zero(), this._babylonScene, false);
        babylonCamera._parentContainer = this._assetContainer;
        this._babylonScene._blockEntityCollection = false;
        camera._babylonCamera = babylonCamera;

        // glTF cameras look towards the local -Z axis.
        babylonCamera.setTarget(new Vector3(0, 0, -1));

        switch (camera.type) {
            case CameraType.PERSPECTIVE: {
                const perspective = camera.perspective;
                if (!perspective) {
                    throw new Error(`${context}: Camera perspective properties are missing`);
                }

                babylonCamera.fov = perspective.yfov;
                babylonCamera.minZ = perspective.znear;
                babylonCamera.maxZ = perspective.zfar || 0;
                break;
            }
            case CameraType.ORTHOGRAPHIC: {
                if (!camera.orthographic) {
                    throw new Error(`${context}: Camera orthographic properties are missing`);
                }

                babylonCamera.mode = Camera.ORTHOGRAPHIC_CAMERA;
                babylonCamera.orthoLeft = -camera.orthographic.xmag;
                babylonCamera.orthoRight = camera.orthographic.xmag;
                babylonCamera.orthoBottom = -camera.orthographic.ymag;
                babylonCamera.orthoTop = camera.orthographic.ymag;
                babylonCamera.minZ = camera.orthographic.znear;

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Fix the asset so the camera includes a perspective object with yfov, znear (and optionally zfar)
  2. Re-export the scene from the DCC tool and validate the camera definition with glTF-Validator
  3. Edit the glTF JSON to add the missing perspective object or change the camera type to 'orthographic' if that was intended

Example fix

// before (in .gltf)
// { "cameras": [ { "type": "perspective" } ] }
// after
// { "cameras": [ { "type": "perspective", "perspective": { "yfov": 0.8, "znear": 0.1, "zfar": 1000 } } ] }
Defensive patterns

Strategy: validation

Validate before calling

// Check perspective cameras have a perspective object before loading
const badCams = (gltf.cameras ?? []).filter(c => c.type === "perspective" && !c.perspective);
if (badCams.length) throw new Error(`Perspective cameras missing 'perspective': ${badCams.length}`);

Type guard

function hasPerspectiveProps(camera) {
  return camera.type !== "perspective" ||
    (camera.perspective != null &&
      typeof camera.perspective.yfov === "number" &&
      typeof camera.perspective.znear === "number");
}

Try / catch

try {
  await loader.loadAsync(url);
} catch (e) {
  if (e.message.includes("Camera perspective properties are missing")) {
    console.error("Add a perspective object (yfov, znear) to the camera or re-export");
  } else throw e;
}

Prevention

When it happens

Trigger: Loading a glTF with a camera entry like { "type": "perspective" } but no perspective sub-object, or a perspective object omitted by a buggy exporter.

Common situations: Hand-edited glTF files; exporters that write the type but drop invalid/missing camera properties; truncated or corrupted asset conversions.

Related errors


AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30). Data as JSON: /api/errors/0734f5142ac0de5a. Report an issue: GitHub.