fromJson static method
Implementation
static DVSceneCameraData fromJson(Object? json, String path) {
final Map<String, Object?> map = _map(json, path);
if (map['projection'] != 'perspective') {
throw DV3DSceneFormatException(
'$path.projection', "only 'perspective' is supported");
}
final double fov = _number(map['fovY'] ?? 45, '$path.fovY');
final double near = _number(map['near'] ?? 0.1, '$path.near');
final double far = _number(map['far'] ?? 1000, '$path.far');
if (fov <= 0 || fov >= 180) {
throw DV3DSceneFormatException('$path.fovY', 'must be between 0 and 180');
}
if (near <= 0 || far <= near) {
throw DV3DSceneFormatException(
'$path.near', 'near must be positive and less than far');
}
final Object? orbit = map['orbit'];
if (orbit == null) {
return DVSceneCameraData.perspective(fovYDegrees: fov, near: near, far: far);
}
final Map<String, Object?> o = _map(orbit, '$path.orbit');
final double distance = _number(o['distance'], '$path.orbit.distance');
if (distance <= 0) {
throw DV3DSceneFormatException(
'$path.orbit.distance', 'must be positive');
}
final double yaw = _number(o['yaw'] ?? 0, '$path.orbit.yaw');
final double pitch = _number(o['pitch'] ?? 0, '$path.orbit.pitch');
if (pitch < -90 || pitch > 90) {
throw DV3DSceneFormatException('$path.orbit.pitch', 'must be between -90 and 90 degrees');
}
return DVSceneCameraData._(
fovYDegrees: fov,
near: near,
far: far,
orbitTarget: _vec3(o['target'] ?? const <double>[0, 0, 0], '$path.orbit.target'),
orbitDistance: distance,
controls: _bool(o['controls'] ?? false, '$path.orbit.controls'),
orbitYawDegrees: yaw,
orbitPitchDegrees: pitch,
);
}