Blender  V2.93
abc_reader_camera.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include "abc_reader_camera.h"
22 #include "abc_reader_transform.h"
23 #include "abc_util.h"
24 
25 #include "DNA_camera_types.h"
26 #include "DNA_object_types.h"
27 
28 #include "BKE_camera.h"
29 #include "BKE_object.h"
30 
31 #include "BLI_math.h"
32 
33 using Alembic::AbcGeom::CameraSample;
34 using Alembic::AbcGeom::ICamera;
35 using Alembic::AbcGeom::ICompoundProperty;
36 using Alembic::AbcGeom::IFloatProperty;
37 using Alembic::AbcGeom::ISampleSelector;
38 using Alembic::AbcGeom::kWrapExisting;
39 
40 namespace blender::io::alembic {
41 
42 AbcCameraReader::AbcCameraReader(const Alembic::Abc::IObject &object, ImportSettings &settings)
43  : AbcObjectReader(object, settings)
44 {
45  ICamera abc_cam(m_iobject, kWrapExisting);
46  m_schema = abc_cam.getSchema();
47 
49 }
50 
52 {
53  return m_schema.valid();
54 }
55 
57  const Alembic::AbcCoreAbstract::ObjectHeader &alembic_header,
58  const Object *const ob,
59  const char **err_str) const
60 {
61  if (!Alembic::AbcGeom::ICamera::matches(alembic_header)) {
62  *err_str =
63  "Object type mismatch, Alembic object path pointed to Camera when importing, but not any "
64  "more.";
65  return false;
66  }
67 
68  if (ob->type != OB_CAMERA) {
69  *err_str = "Object type mismatch, Alembic object path points to Camera.";
70  return false;
71  }
72 
73  return true;
74 }
75 
76 void AbcCameraReader::readObjectData(Main *bmain, const ISampleSelector &sample_sel)
77 {
78  Camera *bcam = static_cast<Camera *>(BKE_camera_add(bmain, m_data_name.c_str()));
79 
80  CameraSample cam_sample;
81  m_schema.get(cam_sample, sample_sel);
82 
83  ICompoundProperty customDataContainer = m_schema.getUserProperties();
84 
85  if (customDataContainer.valid() && customDataContainer.getPropertyHeader("stereoDistance") &&
86  customDataContainer.getPropertyHeader("eyeSeparation")) {
87  IFloatProperty convergence_plane(customDataContainer, "stereoDistance");
88  IFloatProperty eye_separation(customDataContainer, "eyeSeparation");
89 
90  bcam->stereo.interocular_distance = eye_separation.getValue(sample_sel);
91  bcam->stereo.convergence_distance = convergence_plane.getValue(sample_sel);
92  }
93 
94  const float lens = static_cast<float>(cam_sample.getFocalLength());
95  const float apperture_x = static_cast<float>(cam_sample.getHorizontalAperture());
96  const float apperture_y = static_cast<float>(cam_sample.getVerticalAperture());
97  const float h_film_offset = static_cast<float>(cam_sample.getHorizontalFilmOffset());
98  const float v_film_offset = static_cast<float>(cam_sample.getVerticalFilmOffset());
99  const float film_aspect = apperture_x / apperture_y;
100 
101  bcam->lens = lens;
102  bcam->sensor_x = apperture_x * 10;
103  bcam->sensor_y = apperture_y * 10;
104  bcam->shiftx = h_film_offset / apperture_x;
105  bcam->shifty = v_film_offset / apperture_y / film_aspect;
106  bcam->clip_start = max_ff(0.1f, static_cast<float>(cam_sample.getNearClippingPlane()));
107  bcam->clip_end = static_cast<float>(cam_sample.getFarClippingPlane());
108  bcam->dof.focus_distance = static_cast<float>(cam_sample.getFocusDistance());
109  bcam->dof.aperture_fstop = static_cast<float>(cam_sample.getFStop());
110 
112  m_object->data = bcam;
113 }
114 
115 } // namespace blender::io::alembic
Camera data-block and utility functions.
void * BKE_camera_add(struct Main *bmain, const char *name)
Definition: camera.c:217
General operations, lookup, etc. for blender objects.
struct Object * BKE_object_add_only_object(struct Main *bmain, int type, const char *name) ATTR_NONNULL(1) ATTR_RETURNS_NONNULL
Definition: object.c:2193
MINLINE float max_ff(float a, float b)
Object is a sort of wrapper for general info.
@ OB_CAMERA
bool accepts_object_type(const Alembic::AbcCoreAbstract::ObjectHeader &alembic_header, const Object *const ob, const char **err_str) const
AbcCameraReader(const Alembic::Abc::IObject &object, ImportSettings &settings)
void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel)
void get_min_max_time(const Alembic::AbcGeom::IObject &object, const Schema &schema, chrono_t &min, chrono_t &max)
Definition: abc_util.h:80
float clip_end
float sensor_y
float shiftx
struct CameraStereoSettings stereo
float sensor_x
float clip_start
float shifty
struct CameraDOFSettings dof
Definition: BKE_main.h:116
void * data