static void ReadCamera()

in src/fbx/Fbx2Raw.cpp [520:585]


static void ReadCamera(RawModel& raw, FbxScene* pScene, FbxNode* pNode) {
  const FbxCamera* pCamera = pNode->GetCamera();

  double filmHeight = pCamera->GetApertureHeight();
  double filmWidth = pCamera->GetApertureWidth() * pCamera->GetSqueezeRatio();

  // note Height : Width
  double apertureRatio = filmHeight / filmWidth;

  double fovx = 0.0f;
  double fovy = 0.0f;

  switch (pCamera->GetApertureMode()) {
    case FbxCamera::EApertureMode::eHorizAndVert: {
      fovx = pCamera->FieldOfViewX;
      fovy = pCamera->FieldOfViewY;
      break;
    }
    case FbxCamera::EApertureMode::eHorizontal: {
      fovx = pCamera->FieldOfView;
      fovy = HFOV2VFOV(fovx, apertureRatio);
      break;
    }
    case FbxCamera::EApertureMode::eVertical: {
      fovy = pCamera->FieldOfView;
      fovx = VFOV2HFOV(fovy, 1.0 / apertureRatio);
      break;
    }
    case FbxCamera::EApertureMode::eFocalLength: {
      fovx = pCamera->ComputeFieldOfView(pCamera->FocalLength);
      fovy = HFOV2VFOV(fovx, apertureRatio);
      break;
    }
    default: {
      fmt::printf("Warning:: Unsupported ApertureMode. Setting FOV to 0.\n");
      break;
    }
  }

  if (pCamera->ProjectionType.Get() == FbxCamera::EProjectionType::ePerspective) {
    raw.AddCameraPerspective(
        "",
        pNode->GetUniqueID(),
        (float)pCamera->FilmAspectRatio,
        (float)fovx,
        (float)fovy,
        (float)pCamera->NearPlane,
        (float)pCamera->FarPlane);
  } else {
    raw.AddCameraOrthographic(
        "",
        pNode->GetUniqueID(),
        (float)pCamera->OrthoZoom,
        (float)pCamera->OrthoZoom,
        (float)pCamera->FarPlane,
        (float)pCamera->NearPlane);
  }

  // Cameras in FBX coordinate space face +X when rotation is (0,0,0)
  // We need to adjust this to face glTF specified -Z
  auto nodeIdx = raw.GetNodeById(pNode->GetUniqueID());
  auto& rawNode = raw.GetNode(nodeIdx);

  auto r = Quatf::FromAngleAxis(-90 * ((float)M_PI / 180.0f), {0.0, 1.0, 0.0});
  rawNode.rotation = rawNode.rotation * r;
}