Blender V4.3
abc_reader_camera.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "abc_reader_camera.h"
10#include "abc_util.h"
11
12#include "DNA_camera_types.h"
13#include "DNA_object_types.h"
14
15#include "BLI_math_base.h"
16
17#include "BKE_camera.h"
18#include "BKE_object.hh"
19
20#include "BLT_translation.hh"
21
22using Alembic::AbcGeom::CameraSample;
23using Alembic::AbcGeom::ICamera;
24using Alembic::AbcGeom::ICompoundProperty;
25using Alembic::AbcGeom::IFloatProperty;
26using Alembic::AbcGeom::ISampleSelector;
27using Alembic::AbcGeom::kWrapExisting;
28
29namespace blender::io::alembic {
30
31AbcCameraReader::AbcCameraReader(const Alembic::Abc::IObject &object, ImportSettings &settings)
32 : AbcObjectReader(object, settings)
33{
34 ICamera abc_cam(m_iobject, kWrapExisting);
35 m_schema = abc_cam.getSchema();
36
38}
39
41{
42 return m_schema.valid();
43}
44
46 const Alembic::AbcCoreAbstract::ObjectHeader &alembic_header,
47 const Object *const ob,
48 const char **r_err_str) const
49{
50 if (!Alembic::AbcGeom::ICamera::matches(alembic_header)) {
51 *r_err_str = RPT_(
52 "Object type mismatch, Alembic object path pointed to Camera when importing, but not any "
53 "more");
54 return false;
55 }
56
57 if (ob->type != OB_CAMERA) {
58 *r_err_str = RPT_("Object type mismatch, Alembic object path points to Camera");
59 return false;
60 }
61
62 return true;
63}
64
65void AbcCameraReader::readObjectData(Main *bmain, const ISampleSelector &sample_sel)
66{
67 Camera *bcam = static_cast<Camera *>(BKE_camera_add(bmain, m_data_name.c_str()));
68
69 CameraSample cam_sample;
70 m_schema.get(cam_sample, sample_sel);
71
72 ICompoundProperty customDataContainer = m_schema.getUserProperties();
73
74 if (customDataContainer.valid() && customDataContainer.getPropertyHeader("stereoDistance") &&
75 customDataContainer.getPropertyHeader("eyeSeparation"))
76 {
77 IFloatProperty convergence_plane(customDataContainer, "stereoDistance");
78 IFloatProperty eye_separation(customDataContainer, "eyeSeparation");
79
80 bcam->stereo.interocular_distance = eye_separation.getValue(sample_sel);
81 bcam->stereo.convergence_distance = convergence_plane.getValue(sample_sel);
82 }
83
84 const float lens = float(cam_sample.getFocalLength());
85 const float apperture_x = float(cam_sample.getHorizontalAperture());
86 const float apperture_y = float(cam_sample.getVerticalAperture());
87 const float h_film_offset = float(cam_sample.getHorizontalFilmOffset());
88 const float v_film_offset = float(cam_sample.getVerticalFilmOffset());
89 const float film_aspect = apperture_x / apperture_y;
90
91 bcam->lens = lens;
92 bcam->sensor_x = apperture_x * 10;
93 bcam->sensor_y = apperture_y * 10;
94 bcam->shiftx = h_film_offset / apperture_x;
95 bcam->shifty = v_film_offset / apperture_y / film_aspect;
96 bcam->clip_start = max_ff(0.1f, float(cam_sample.getNearClippingPlane()));
97 bcam->clip_end = float(cam_sample.getFarClippingPlane());
98 bcam->dof.focus_distance = float(cam_sample.getFocusDistance());
99 bcam->dof.aperture_fstop = float(cam_sample.getFStop());
100
102 m_object->data = bcam;
103}
104
105} // namespace blender::io::alembic
Camera data-block and utility functions.
void * BKE_camera_add(struct Main *bmain, const char *name)
General operations, lookup, etc. for blender objects.
Object * BKE_object_add_only_object(Main *bmain, int type, const char *name) ATTR_RETURNS_NONNULL
MINLINE float max_ff(float a, float b)
#define RPT_(msgid)
Object is a sort of wrapper for general info.
@ OB_CAMERA
AbcCameraReader(const Alembic::Abc::IObject &object, ImportSettings &settings)
bool accepts_object_type(const Alembic::AbcCoreAbstract::ObjectHeader &alembic_header, const Object *const ob, const char **r_err_str) const override
void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel) override
draw_view in_light_buf[] float
void get_min_max_time(const Alembic::AbcGeom::IObject &object, const Schema &schema, chrono_t &min, chrono_t &max)
Definition abc_util.h:82
float clip_end
float sensor_y
struct CameraStereoSettings stereo
float sensor_x
float clip_start
struct CameraDOFSettings dof