Blender  V3.3
abc_writer_camera.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include "abc_writer_camera.h"
9 
10 #include "BKE_camera.h"
11 
12 #include "BLI_assert.h"
13 
14 #include "DNA_camera_types.h"
15 #include "DNA_scene_types.h"
16 
17 #include "CLG_log.h"
18 static CLG_LogRef LOG = {"io.alembic"};
19 
20 namespace blender::io::alembic {
21 
22 using Alembic::AbcGeom::CameraSample;
23 using Alembic::AbcGeom::OCamera;
24 using Alembic::AbcGeom::OFloatProperty;
25 
27 {
28 }
29 
31 {
32  Camera *camera = static_cast<Camera *>(context->object->data);
33  return camera->type == CAM_PERSP;
34 }
35 
37 {
38  CLOG_INFO(&LOG, 2, "exporting %s", args_.abc_path.c_str());
39  abc_camera_ = OCamera(args_.abc_parent, args_.abc_name, timesample_index_);
40  abc_camera_schema_ = abc_camera_.getSchema();
41 
42  abc_custom_data_container_ = abc_camera_schema_.getUserProperties();
43  abc_stereo_distance_ = OFloatProperty(
44  abc_custom_data_container_, "stereoDistance", timesample_index_);
45  abc_eye_separation_ = OFloatProperty(
46  abc_custom_data_container_, "eyeSeparation", timesample_index_);
47 }
48 
49 Alembic::Abc::OObject ABCCameraWriter::get_alembic_object() const
50 {
51  return abc_camera_;
52 }
53 
54 Alembic::Abc::OCompoundProperty ABCCameraWriter::abc_prop_for_custom_props()
55 {
56  return abc_schema_prop_for_custom_props(abc_camera_schema_);
57 }
58 
60 {
61  Camera *cam = static_cast<Camera *>(context.object->data);
62 
63  abc_stereo_distance_.set(cam->stereo.convergence_distance);
64  abc_eye_separation_.set(cam->stereo.interocular_distance);
65 
66  const double apperture_x = cam->sensor_x / 10.0;
67  const double apperture_y = cam->sensor_y / 10.0;
68  const double film_aspect = apperture_x / apperture_y;
69 
70  CameraSample camera_sample;
71  camera_sample.setFocalLength(cam->lens);
72  camera_sample.setHorizontalAperture(apperture_x);
73  camera_sample.setVerticalAperture(apperture_y);
74  camera_sample.setHorizontalFilmOffset(apperture_x * cam->shiftx);
75  camera_sample.setVerticalFilmOffset(apperture_y * cam->shifty * film_aspect);
76  camera_sample.setNearClippingPlane(cam->clip_start);
77  camera_sample.setFarClippingPlane(cam->clip_end);
78 
79  if (cam->dof.focus_object) {
80  Imath::V3f v(context.object->loc[0] - cam->dof.focus_object->loc[0],
81  context.object->loc[1] - cam->dof.focus_object->loc[1],
82  context.object->loc[2] - cam->dof.focus_object->loc[2]);
83  camera_sample.setFocusDistance(v.length());
84  }
85  else {
86  camera_sample.setFocusDistance(cam->dof.focus_distance);
87  }
88 
89  /* Blender camera does not have an fstop param, so try to find a custom prop
90  * instead. */
91  camera_sample.setFStop(cam->dof.aperture_fstop);
92 
93  camera_sample.setLensSqueezeRatio(1.0);
94  abc_camera_schema_.set(camera_sample);
95 }
96 
97 } // namespace blender::io::alembic
Camera data-block and utility functions.
#define CLOG_INFO(clg_ref, level,...)
Definition: CLG_log.h:187
@ CAM_PERSP
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a or normal between camera
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_private Ray *ray)
struct Object * focus_object
float clip_end
float sensor_y
float lens
float shiftx
struct CameraStereoSettings stereo
float sensor_x
float clip_start
float shifty
struct CameraDOFSettings dof
float loc[3]