in GLTFSDK/Source/Deserialize.cpp [403:473]
Camera ParseCamera(const rapidjson::Value& v, const ExtensionDeserializer& extensionDeserializer)
{
std::unique_ptr<Projection> projection;
std::string projectionType = FindRequiredMember("type", v)->value.GetString();
if (projectionType == "perspective")
{
auto perspectiveIt = v.FindMember("perspective");
if (perspectiveIt == v.MemberEnd())
{
throw InvalidGLTFException("Camera perspective projection undefined");
}
Optional<float> aspectRatio;
auto itAspectRatio = perspectiveIt->value.FindMember("aspectRatio");
if (itAspectRatio != perspectiveIt->value.MemberEnd())
{
aspectRatio = itAspectRatio->value.GetFloat();
}
float yfov = GetValue<float>(FindRequiredMember("yfov", perspectiveIt->value)->value);
float znear = GetValue<float>(FindRequiredMember("znear", perspectiveIt->value)->value);
Optional<float> zfar;
auto itZFar = perspectiveIt->value.FindMember("zfar");
if (itZFar != perspectiveIt->value.MemberEnd())
{
zfar = itZFar->value.GetFloat();
}
auto perspective = std::make_unique<Perspective>(znear, yfov);
perspective->zfar = zfar;
perspective->aspectRatio = aspectRatio;
ParseProperty(perspectiveIt->value, *perspective, extensionDeserializer);
projection = std::move(perspective);
}
else if (projectionType == "orthographic")
{
auto orthographicIt = v.FindMember("orthographic");
if (orthographicIt == v.MemberEnd())
{
throw InvalidGLTFException("Camera orthographic projection undefined");
}
float xmag = GetValue<float>(FindRequiredMember("xmag", orthographicIt->value)->value);
float ymag = GetValue<float>(FindRequiredMember("ymag", orthographicIt->value)->value);
float zfar = GetValue<float>(FindRequiredMember("zfar", orthographicIt->value)->value);
float znear = GetValue<float>(FindRequiredMember("znear", orthographicIt->value)->value);
projection = std::make_unique<Orthographic>(zfar, znear, xmag, ymag);
ParseProperty(orthographicIt->value, *projection, extensionDeserializer);
}
// Camera constructor will throw a GLTFException when projection is null (i.e. source manifest specified an invalid projection type)
Camera camera(std::move(projection));
camera.name = GetMemberValueOrDefault<std::string>(v, "name");
if (!camera.projection->IsValid())
{
throw InvalidGLTFException("Camera's projection is not valid");
}
ParseProperty(v, camera, extensionDeserializer);
return camera;
}