Blender V5.0
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
16#include "BLI_math_matrix.h"
17#include "BLI_math_rotation.h"
18
19#include "DNA_object_types.h"
20
21#include "CLG_log.h"
22static CLG_LogRef LOG = {"io.alembic"};
23
24namespace blender::io::alembic {
25
26using Alembic::Abc::OObject;
27using Alembic::AbcGeom::OXform;
28using Alembic::AbcGeom::OXformSchema;
29using Alembic::AbcGeom::XformSample;
30
32 : ABCAbstractWriter(args)
33{
34 timesample_index_ = args_.abc_archive->time_sampling_index_transforms();
35}
36
38{
39 CLOG_DEBUG(&LOG, "exporting %s", args_.abc_path.c_str());
40 abc_xform_ = OXform(args_.abc_parent, args_.abc_name, timesample_index_);
41 abc_xform_schema_ = abc_xform_.getSchema();
42}
43
44Alembic::Abc::OCompoundProperty ABCTransformWriter::abc_prop_for_custom_props()
45{
46 return abc_schema_prop_for_custom_props<OXformSchema>(abc_xform_schema_);
47}
48
50{
51 const Object *object = context.object;
52 return object->id.properties;
53}
54
56{
57 float parent_relative_matrix[4][4]; /* The object matrix relative to the parent. */
58 mul_m4_m4m4(parent_relative_matrix, context.parent_matrix_inv_world, context.matrix_world);
59
60 /* After this, parent_relative_matrix uses Y=up. */
61 copy_m44_axis_swap(parent_relative_matrix, parent_relative_matrix, ABC_YUP_FROM_ZUP);
62
63 /* If the parent is a camera, undo its to-Maya rotation (see below). */
64 bool is_root_object = context.export_parent == nullptr;
65 if (!is_root_object && context.export_parent->type == OB_CAMERA) {
66 float rot_mat[4][4];
67 axis_angle_to_mat4_single(rot_mat, 'X', M_PI_2);
68 mul_m4_m4m4(parent_relative_matrix, rot_mat, parent_relative_matrix);
69 }
70
71 /* If the object is a camera, apply an extra rotation to Maya camera orientation. */
72 if (context.object->type == OB_CAMERA) {
73 float rot_mat[4][4];
74 axis_angle_to_mat4_single(rot_mat, 'X', -M_PI_2);
75 mul_m4_m4m4(parent_relative_matrix, parent_relative_matrix, rot_mat);
76 }
77
78 if (is_root_object) {
79 /* Only apply scaling to root objects, parenting will propagate it. */
80 float scale_mat[4][4];
81 scale_m4_fl(scale_mat, args_.export_params->global_scale);
82 scale_mat[3][3] = args_.export_params->global_scale; /* also scale translation */
83 mul_m4_m4m4(parent_relative_matrix, parent_relative_matrix, scale_mat);
84 parent_relative_matrix[3][3] /=
85 args_.export_params->global_scale; /* Normalize the homogeneous component. */
86 }
87
88 XformSample xform_sample;
89 xform_sample.setMatrix(convert_matrix_datatype(parent_relative_matrix));
90 xform_sample.setInheritsXforms(true);
91 abc_xform_schema_.set(xform_sample);
92
93 write_visibility(context);
94}
95
97{
98 return abc_xform_;
99}
100
102{
103 if (context.duplicator != nullptr) {
104 /* This object is being duplicated, so could be emitted by a particle system and thus
105 * influenced by forces. TODO(Sybren): Make this more strict. Probably better to get from the
106 * depsgraph whether this object instance has a time source. */
107 return true;
108 }
109 if (check_has_physics(context)) {
110 return true;
111 }
112 return BKE_object_moves_in_time(context.object, context.animation_check_include_parent);
113}
114
115} // namespace blender::io::alembic
General operations, lookup, etc. for blender objects.
bool BKE_object_moves_in_time(const Object *object, bool recurse_parent)
#define M_PI_2
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
void scale_m4_fl(float R[4][4], float scale)
void axis_angle_to_mat4_single(float R[4][4], char axis, float angle)
#define CLOG_DEBUG(clg_ref,...)
Definition CLG_log.h:191
Object is a sort of wrapper for general info.
@ OB_CAMERA
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_
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
#define LOG(level)
Definition log.h:97
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:39