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