Blender V5.3
abc_writer_transform.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
12#include "intern/abc_util.h"
13
14#include "BKE_object.hh"
15
17#include "BLI_math_matrix.hh"
18
19#include "DNA_object_types.h"
20
21#include "CLG_log.h"
22
23namespace blender {
24
25static CLG_LogRef LOG = {"io.alembic"};
26
27namespace io::alembic {
28
29using Alembic::Abc::OObject;
30using Alembic::AbcGeom::OXform;
31using Alembic::AbcGeom::OXformSchema;
32using Alembic::AbcGeom::XformSample;
33
39
41{
42 CLOG_DEBUG(&LOG, "exporting %s", args_.abc_path.c_str());
43 abc_xform_ = OXform(args_.abc_parent, args_.abc_name, timesample_index_);
44 abc_xform_schema_ = abc_xform_.getSchema();
45}
46
47Alembic::Abc::OCompoundProperty ABCTransformWriter::abc_prop_for_custom_props()
48{
49 return abc_schema_prop_for_custom_props<OXformSchema>(abc_xform_schema_);
50}
51
53{
54 const Object *object = context.object;
55 return object->id.properties;
56}
57
59{
60 /* The object matrix relative to the parent. */
61 float4x4 parent_relative_matrix = context.parent_matrix_inv_world * context.matrix_world;
62
63 /* After this, parent_relative_matrix uses Y=up. */
64 copy_m44_axis_swap(parent_relative_matrix.ptr(), parent_relative_matrix.ptr(), ABC_YUP_FROM_ZUP);
65
66 /* If the parent is a camera, undo its to-Maya rotation (see below). */
67 bool is_root_object = context.export_parent == nullptr;
68 if (!is_root_object && context.export_parent->type == OB_CAMERA) {
70 parent_relative_matrix = rot_mat * parent_relative_matrix;
71 }
72
73 /* If the object is a camera, apply an extra rotation to Maya camera orientation. */
74 if (context.object->type == OB_CAMERA) {
76 parent_relative_matrix = parent_relative_matrix * rot_mat;
77 }
78
79 /* Only apply scaling to root objects, parenting will propagate it. */
80 if (is_root_object) {
81 /* A float4 so we also scale translation */
83 parent_relative_matrix = math::scale(parent_relative_matrix, scale);
84
85 parent_relative_matrix[3][3] /=
86 args_.export_params->global_scale; /* Normalize the homogeneous component. */
87 }
88
89 XformSample xform_sample;
90 xform_sample.setMatrix(convert_matrix_datatype(parent_relative_matrix.ptr()));
91 xform_sample.setInheritsXforms(true);
92 abc_xform_schema_.set(xform_sample);
93
94 write_visibility(context);
95}
96
98{
99 return abc_xform_;
100}
101
103{
104 if (context.duplicator != nullptr) {
105 /* This object is being duplicated, so could be emitted by a particle system and thus
106 * influenced by forces. TODO(Sybren): Make this more strict. Probably better to get from the
107 * depsgraph whether this object instance has a time source. */
108 return true;
109 }
110 if (check_has_physics(context)) {
111 return true;
112 }
113 return BKE_object_moves_in_time(context.object, context.animation_check_include_parent);
114}
115
116} // namespace io::alembic
117} // namespace blender
General operations, lookup, etc. for blender objects.
#define M_PI_2
#define CLOG_DEBUG(clg_ref,...)
Definition CLG_log.h:191
Object is a sort of wrapper for general info.
static bool check_has_physics(const HierarchyContext &context)
void write_visibility(const HierarchyContext &context)
ABCAbstractWriter(const ABCWriterConstructorArgs &args)
Alembic::Abc::OCompoundProperty abc_schema_prop_for_custom_props(T abc_schema)
const ABCWriterConstructorArgs args_
uint32_t time_sampling_index_transforms() const
Alembic::Abc::OObject get_alembic_object() const override
void create_alembic_objects(const HierarchyContext *context) override
Alembic::Abc::OCompoundProperty abc_prop_for_custom_props() override
const IDProperty * get_id_properties(const HierarchyContext &context) const override
ABCTransformWriter(const ABCWriterConstructorArgs &args)
bool check_is_animated(const HierarchyContext &context) const override
void do_write(HierarchyContext &context) override
float3x3 scale(float3x3 mat, float2 scale)
void copy_m44_axis_swap(float dst_mat[4][4], float src_mat[4][4], AbcAxisSwapMode mode)
Imath::M44d convert_matrix_datatype(const float mat[4][4])
Definition abc_util.cc:46
MatBase< T, NumCol, NumRow > scale(const MatBase< T, NumCol, NumRow > &mat, const VectorT &scale)
EulerXYZBase< float > EulerXYZ
MatT from_rotation(const RotationT &rotation)
BMesh Iterators.
bool BKE_object_moves_in_time(const Object *object, bool recurse_parent)
Definition object.cc:4968
MatBase< float, 4, 4 > float4x4
VecBase< float, 4 > float4
static CLG_LogRef LOG
Definition logging.cpp:12
const c_style_mat & ptr() const