Blender  V2.93
abc_writer_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_writer_camera.h"
22 #include "abc_hierarchy_iterator.h"
23 
24 #include "BKE_camera.h"
25 
26 #include "BLI_assert.h"
27 
28 #include "DNA_camera_types.h"
29 #include "DNA_scene_types.h"
30 
31 #include "CLG_log.h"
32 static CLG_LogRef LOG = {"io.alembic"};
33 
34 namespace blender::io::alembic {
35 
36 using Alembic::AbcGeom::CameraSample;
37 using Alembic::AbcGeom::OCamera;
38 using Alembic::AbcGeom::OFloatProperty;
39 
41 {
42 }
43 
45 {
46  Camera *camera = static_cast<Camera *>(context->object->data);
47  return camera->type == CAM_PERSP;
48 }
49 
51 {
52  CLOG_INFO(&LOG, 2, "exporting %s", args_.abc_path.c_str());
53  abc_camera_ = OCamera(args_.abc_parent, args_.abc_name, timesample_index_);
54  abc_camera_schema_ = abc_camera_.getSchema();
55 
56  abc_custom_data_container_ = abc_camera_schema_.getUserProperties();
57  abc_stereo_distance_ = OFloatProperty(
58  abc_custom_data_container_, "stereoDistance", timesample_index_);
59  abc_eye_separation_ = OFloatProperty(
60  abc_custom_data_container_, "eyeSeparation", timesample_index_);
61 }
62 
63 Alembic::Abc::OObject ABCCameraWriter::get_alembic_object() const
64 {
65  return abc_camera_;
66 }
67 
68 Alembic::Abc::OCompoundProperty ABCCameraWriter::abc_prop_for_custom_props()
69 {
70  return abc_schema_prop_for_custom_props(abc_camera_schema_);
71 }
72 
74 {
75  Camera *cam = static_cast<Camera *>(context.object->data);
76 
77  abc_stereo_distance_.set(cam->stereo.convergence_distance);
78  abc_eye_separation_.set(cam->stereo.interocular_distance);
79 
80  const double apperture_x = cam->sensor_x / 10.0;
81  const double apperture_y = cam->sensor_y / 10.0;
82  const double film_aspect = apperture_x / apperture_y;
83 
84  CameraSample camera_sample;
85  camera_sample.setFocalLength(cam->lens);
86  camera_sample.setHorizontalAperture(apperture_x);
87  camera_sample.setVerticalAperture(apperture_y);
88  camera_sample.setHorizontalFilmOffset(apperture_x * cam->shiftx);
89  camera_sample.setVerticalFilmOffset(apperture_y * cam->shifty * film_aspect);
90  camera_sample.setNearClippingPlane(cam->clip_start);
91  camera_sample.setFarClippingPlane(cam->clip_end);
92 
93  if (cam->dof.focus_object) {
94  Imath::V3f v(context.object->loc[0] - cam->dof.focus_object->loc[0],
95  context.object->loc[1] - cam->dof.focus_object->loc[1],
96  context.object->loc[2] - cam->dof.focus_object->loc[2]);
97  camera_sample.setFocusDistance(v.length());
98  }
99  else {
100  camera_sample.setFocusDistance(cam->dof.focus_distance);
101  }
102 
103  /* Blender camera does not have an fstop param, so try to find a custom prop
104  * instead. */
105  camera_sample.setFStop(cam->dof.aperture_fstop);
106 
107  camera_sample.setLensSqueezeRatio(1.0);
108  abc_camera_schema_.set(camera_sample);
109 }
110 
111 } // namespace blender::io::alembic
Camera data-block and utility functions.
#define CLOG_INFO(clg_ref, level,...)
Definition: CLG_log.h:201
@ CAM_PERSP
static CLG_LogRef LOG
ATTR_WARN_UNUSED_RESULT const BMVert * v
Alembic::Abc::OCompoundProperty abc_schema_prop_for_custom_props(T abc_schema)
const ABCWriterConstructorArgs args_
Alembic::Abc::OCompoundProperty abc_prop_for_custom_props() override
virtual bool is_supported(const HierarchyContext *context) const override
virtual Alembic::Abc::OObject get_alembic_object() const override
ABCCameraWriter(const ABCWriterConstructorArgs &args)
virtual void do_write(HierarchyContext &context) override
virtual void create_alembic_objects(const HierarchyContext *context) override
ccl_device_inline void camera_sample(KernelGlobals *kg, int x, int y, float filter_u, float filter_v, float lens_u, float lens_v, float time, ccl_addr_space Ray *ray)
struct SELECTID_Context context
Definition: select_engine.c:47
struct Object * focus_object
float clip_end
float sensor_y
float shiftx
struct CameraStereoSettings stereo
float sensor_x
float clip_start
float shifty
struct CameraDOFSettings dof
float loc[3]