BabylonJS/Babylon.js · error · Error
${context}: Invalid camera type (${camera.type})
Error message
${context}: Invalid camera type (${camera.type}) What it means
The glTF camera loader only supports "perspective" and "orthographic" camera types per the glTF 2.0 spec. When camera.type holds any other value, the switch falls to the default branch and throws this error. It protects downstream camera-construction code from unknown types.
Source
Thrown at packages/dev/loaders/src/glTF/2.0/glTFLoader.pure.ts:1738
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;
babylonCamera.maxZ = camera.orthographic.zfar;
break;
}
default: {
throw new Error(`${context}: Invalid camera type (${camera.type})`);
}
}
GLTFLoader.AddPointerMetadata(babylonCamera, context);
this._parent.onCameraLoadedObservable.notifyObservers(babylonCamera);
assign(babylonCamera);
this.logClose();
return Promise.all(promises).then(() => {
return babylonCamera;
});
}
private _loadAnimationsAsync(): Promise<void> {
this._parent._startPerformanceCounter("Load animations");
const animations = this._gltf.animations;
View on GitHub (pinned to 0592b347b8)
Solutions
- Set camera.type to "perspective" or "orthographic" in the glTF JSON.
- Re-export the asset with a spec-compliant exporter.
- Remove or replace the invalid camera entry if it is not needed.
- Validate the asset with glTF-Validator before loading.
Example fix
// before
"cameras": [{ "type": "ortho", "orthographic": { "xmag": 1, "ymag": 1, "znear": 0.1, "zfar": 100 } }]
// after
"cameras": [{ "type": "orthographic", "orthographic": { "xmag": 1, "ymag": 1, "znear": 0.1, "zfar": 100 } }] Defensive patterns
Strategy: validation
Validate before calling
for (const cam of gltf.cameras ?? []) {
if (cam.type !== "perspective" && cam.type !== "orthographic") {
throw new Error(`Invalid camera type: ${cam.type}`);
}
} Type guard
function isValidCameraType(t: string): t is "perspective" | "orthographic" {
return t === "perspective" || t === "orthographic";
} Try / catch
try { await loadAsset(); } catch (e) {
if (/Invalid camera type/.test((e as Error).message)) {
console.warn("Skipping asset with non-spec camera type");
}
} Prevention
- Validate assets with glTF-Validator before shipping.
- Use only spec-compliant exporters.
- Reject unknown camera types at asset-ingestion time.
When it happens
Trigger: Loading a glTF where cameras[i].type is not "perspective" or "orthographic" — e.g. an empty string, a typo like "ortho", or a future/custom type added by a non-conformant exporter.
Common situations: Hand-edited glTF files, custom exporter extensions that misuse the type field, corrupted JSON, or assets generated by tools that predate glTF 2.0 camera conventions.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- ${context}: Camera orthographic properties are missing
- ${context}/target/path: Invalid value (${channel.target.path
- ${context}/interpolation: Invalid value (${sampler.interpola
- ${context}: Camera perspective properties are missing
- ${context}/target/path: Could not find interpolation propert
AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30).
Data as JSON: /api/errors/5b51bf4fe97ac691.
Report an issue: GitHub.