Blender V4.3
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
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{
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_PANO:
53 case CAM_PERSP: {
54 COLLADASW::PerspectiveOptic persp(mSW);
55 persp.setXFov(RAD2DEGF(focallength_to_fov(cam->lens, cam->sensor_x)), "xfov");
56 persp.setAspectRatio(float(sce->r.xsch) / float(sce->r.ysch), false, "aspect_ratio");
57 persp.setZFar(cam->clip_end, false, "zfar");
58 persp.setZNear(cam->clip_start, false, "znear");
59 COLLADASW::Camera ccam(mSW, &persp, cam_id, cam_name);
60 exportBlenderProfile(ccam, cam);
61 addCamera(ccam);
62
63 break;
64 }
65 case CAM_ORTHO:
66 default: {
67 COLLADASW::OrthographicOptic ortho(mSW);
68 ortho.setXMag(cam->ortho_scale / 2, "xmag");
69 ortho.setAspectRatio(float(sce->r.xsch) / float(sce->r.ysch), false, "aspect_ratio");
70 ortho.setZFar(cam->clip_end, false, "zfar");
71 ortho.setZNear(cam->clip_start, false, "znear");
72 COLLADASW::Camera ccam(mSW, &ortho, cam_id, cam_name);
73 exportBlenderProfile(ccam, cam);
74 addCamera(ccam);
75 break;
76 }
77 }
78}
79bool CamerasExporter::exportBlenderProfile(COLLADASW::Camera &cm, Camera *cam)
80{
81 cm.addExtraTechniqueParameter("blender", "shiftx", cam->shiftx);
82 cm.addExtraTechniqueParameter("blender", "shifty", cam->shifty);
83 cm.addExtraTechniqueParameter("blender", "dof_distance", cam->dof.focus_distance);
84 return true;
85}
#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_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
float clip_end
float sensor_x
float clip_start
struct CameraDOFSettings dof
float ortho_scale
struct LinkNode * next
struct RenderData r