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