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