Blender  V3.3
CameraExporter.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include <string>
8 
9 #include "COLLADASWCamera.h"
10 
11 #include "DNA_camera_types.h"
12 
13 #include "CameraExporter.h"
14 
15 #include "collada_internal.h"
16 
17 CamerasExporter::CamerasExporter(COLLADASW::StreamWriter *sw, BCExportSettings &export_settings)
18  : COLLADASW::LibraryCameras(sw), export_settings(export_settings)
19 {
20 }
21 
22 template<class Functor>
23 void forEachCameraObjectInExportSet(Scene *sce, Functor &f, LinkNode *export_set)
24 {
25  LinkNode *node;
26  for (node = export_set; node; node = node->next) {
27  Object *ob = (Object *)node->link;
28 
29  if (ob->type == OB_CAMERA && ob->data) {
30  f(ob, sce);
31  }
32  }
33 }
34 
36 {
37  openLibrary();
38 
39  forEachCameraObjectInExportSet(sce, *this, this->export_settings.get_export_set());
40 
41  closeLibrary();
42 }
44 {
45  Camera *cam = (Camera *)ob->data;
46  std::string cam_id(get_camera_id(ob));
47  std::string cam_name(id_name(cam));
48 
49  switch (cam->type) {
50  case CAM_PANO:
51  case CAM_PERSP: {
52  COLLADASW::PerspectiveOptic persp(mSW);
53  persp.setXFov(RAD2DEGF(focallength_to_fov(cam->lens, cam->sensor_x)), "xfov");
54  persp.setAspectRatio((float)(sce->r.xsch) / (float)(sce->r.ysch), false, "aspect_ratio");
55  persp.setZFar(cam->clip_end, false, "zfar");
56  persp.setZNear(cam->clip_start, false, "znear");
57  COLLADASW::Camera ccam(mSW, &persp, cam_id, cam_name);
58  exportBlenderProfile(ccam, cam);
59  addCamera(ccam);
60 
61  break;
62  }
63  case CAM_ORTHO:
64  default: {
65  COLLADASW::OrthographicOptic ortho(mSW);
66  ortho.setXMag(cam->ortho_scale / 2, "xmag");
67  ortho.setAspectRatio((float)(sce->r.xsch) / (float)(sce->r.ysch), false, "aspect_ratio");
68  ortho.setZFar(cam->clip_end, false, "zfar");
69  ortho.setZNear(cam->clip_start, false, "znear");
70  COLLADASW::Camera ccam(mSW, &ortho, cam_id, cam_name);
71  exportBlenderProfile(ccam, cam);
72  addCamera(ccam);
73  break;
74  }
75  }
76 }
77 bool CamerasExporter::exportBlenderProfile(COLLADASW::Camera &cm, Camera *cam)
78 {
79  cm.addExtraTechniqueParameter("blender", "shiftx", cam->shiftx);
80  cm.addExtraTechniqueParameter("blender", "shifty", cam->shifty);
81  cm.addExtraTechniqueParameter("blender", "dof_distance", cam->dof.focus_distance);
82  return true;
83 }
#define RAD2DEGF(_rad)
float focallength_to_fov(float focal_length, float sensor)
void forEachCameraObjectInExportSet(Scene *sce, Functor &f, LinkNode *export_set)
struct Camera Camera
@ CAM_PERSP
@ CAM_PANO
@ CAM_ORTHO
@ OB_CAMERA
void operator()(Object *ob, Scene *sce)
void exportCameras(Scene *sce)
CamerasExporter(COLLADASW::StreamWriter *sw, BCExportSettings &export_settings)
std::string get_camera_id(Object *ob)
std::string id_name(void *id)
OperationNode * node
ccl_gpu_kernel_postfix ccl_global float int int int sw
float clip_end
float lens
float shiftx
float sensor_x
float clip_start
float shifty
struct CameraDOFSettings dof
float ortho_scale
void * data
struct RenderData r