Blender V4.3
abc_writer_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
8
9#include "abc_writer_camera.h"
11
12#include "BKE_scene.hh"
13
15
16#include "DNA_camera_types.h"
17#include "DNA_scene_types.h"
18
19#include "CLG_log.h"
20static CLG_LogRef LOG = {"io.alembic"};
21
22namespace blender::io::alembic {
23
24using Alembic::AbcGeom::CameraSample;
25using Alembic::AbcGeom::OCamera;
26using Alembic::AbcGeom::OFloatProperty;
27
29
31{
32 const Camera *camera = static_cast<const 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 /* Export scene render resolution on cameras as userProperties, for other software (e.g.
49 * Houdini). */
50 OFloatProperty render_resx(abc_custom_data_container_, "resx");
51 OFloatProperty render_resy(abc_custom_data_container_, "resy");
52 Scene *scene = DEG_get_evaluated_scene(args_.depsgraph);
53 int width, height;
54 BKE_render_resolution(&scene->r, false, &width, &height);
55 render_resx.set(float(width));
56 render_resy.set(float(height));
57}
58
59Alembic::Abc::OObject ABCCameraWriter::get_alembic_object() const
60{
61 return abc_camera_;
62}
63
64Alembic::Abc::OCompoundProperty ABCCameraWriter::abc_prop_for_custom_props()
65{
66 return abc_schema_prop_for_custom_props(abc_camera_schema_);
67}
68
70{
71 const Camera *cam = static_cast<const Camera *>(context.object->data);
72
73 abc_stereo_distance_.set(cam->stereo.convergence_distance);
74 abc_eye_separation_.set(cam->stereo.interocular_distance);
75
76 const double apperture_x = cam->sensor_x / 10.0;
77 const double apperture_y = cam->sensor_y / 10.0;
78 const double film_aspect = apperture_x / apperture_y;
79
80 CameraSample camera_sample;
81 camera_sample.setFocalLength(cam->lens);
82 camera_sample.setHorizontalAperture(apperture_x);
83 camera_sample.setVerticalAperture(apperture_y);
84 camera_sample.setHorizontalFilmOffset(apperture_x * cam->shiftx);
85 camera_sample.setVerticalFilmOffset(apperture_y * cam->shifty * film_aspect);
86 camera_sample.setNearClippingPlane(cam->clip_start);
87 camera_sample.setFarClippingPlane(cam->clip_end);
88
89 if (cam->dof.focus_object) {
90 Imath::V3f v(context.object->loc[0] - cam->dof.focus_object->loc[0],
91 context.object->loc[1] - cam->dof.focus_object->loc[1],
92 context.object->loc[2] - cam->dof.focus_object->loc[2]);
93 camera_sample.setFocusDistance(v.length());
94 }
95 else {
96 camera_sample.setFocusDistance(cam->dof.focus_distance);
97 }
98
99 /* Blender camera does not have an fstop param, so try to find a custom prop
100 * instead. */
101 camera_sample.setFStop(cam->dof.aperture_fstop);
102
103 camera_sample.setLensSqueezeRatio(1.0);
104 abc_camera_schema_.set(camera_sample);
105}
106
107} // namespace blender::io::alembic
void BKE_render_resolution(const RenderData *r, const bool use_crop, int *r_width, int *r_height)
Definition scene.cc:2877
#define CLOG_INFO(clg_ref, level,...)
Definition CLG_log.h:179
Scene * DEG_get_evaluated_scene(const Depsgraph *graph)
@ 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 Gabor Generate Gabor noise Gradient Generate interpolated color and intensity values based on the input vector Magic Generate a psychedelic color texture 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
ATTR_WARN_UNUSED_RESULT const BMVert * v
ABCAbstractWriter(const ABCWriterConstructorArgs &args)
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, const float2 filter_uv, const float time, const float2 lens_uv, ccl_private Ray *ray)
#define LOG(severity)
Definition log.h:33
struct Object * focus_object
float clip_end
float sensor_y
struct CameraStereoSettings stereo
float sensor_x
float clip_start
struct CameraDOFSettings dof
void set(const SocketType &input, bool value)
float loc[3]
struct RenderData r