Blender V4.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
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 "CLG_log.h"
20static CLG_LogRef LOG = {"io.alembic"};
21
22namespace blender::io::alembic {
23
24using Alembic::Abc::OObject;
25using Alembic::AbcGeom::OXform;
26using Alembic::AbcGeom::OXformSchema;
27using Alembic::AbcGeom::XformSample;
28
34
36{
37 CLOG_INFO(&LOG, 2, "exporting %s", args_.abc_path.c_str());
38 abc_xform_ = OXform(args_.abc_parent, args_.abc_name, timesample_index_);
39 abc_xform_schema_ = abc_xform_.getSchema();
40}
41
42Alembic::Abc::OCompoundProperty ABCTransformWriter::abc_prop_for_custom_props()
43{
44 return abc_schema_prop_for_custom_props<OXformSchema>(abc_xform_schema_);
45}
46
48{
49 const Object *object = context.object;
50 return object->id.properties;
51}
52
54{
55 float parent_relative_matrix[4][4]; /* The object matrix relative to the parent. */
56 mul_m4_m4m4(parent_relative_matrix, context.parent_matrix_inv_world, context.matrix_world);
57
58 /* After this, parent_relative_matrix uses Y=up. */
59 copy_m44_axis_swap(parent_relative_matrix, parent_relative_matrix, ABC_YUP_FROM_ZUP);
60
61 /* If the parent is a camera, undo its to-Maya rotation (see below). */
62 bool is_root_object = context.export_parent == nullptr;
63 if (!is_root_object && context.export_parent->type == OB_CAMERA) {
64 float rot_mat[4][4];
65 axis_angle_to_mat4_single(rot_mat, 'X', M_PI_2);
66 mul_m4_m4m4(parent_relative_matrix, rot_mat, parent_relative_matrix);
67 }
68
69 /* If the object is a camera, apply an extra rotation to Maya camera orientation. */
70 if (context.object->type == OB_CAMERA) {
71 float rot_mat[4][4];
72 axis_angle_to_mat4_single(rot_mat, 'X', -M_PI_2);
73 mul_m4_m4m4(parent_relative_matrix, parent_relative_matrix, rot_mat);
74 }
75
76 if (is_root_object) {
77 /* Only apply scaling to root objects, parenting will propagate it. */
78 float scale_mat[4][4];
80 scale_mat[3][3] = args_.export_params->global_scale; /* also scale translation */
81 mul_m4_m4m4(parent_relative_matrix, parent_relative_matrix, scale_mat);
82 parent_relative_matrix[3][3] /=
83 args_.export_params->global_scale; /* Normalize the homogeneous component. */
84 }
85
86 XformSample xform_sample;
87 xform_sample.setMatrix(convert_matrix_datatype(parent_relative_matrix));
88 xform_sample.setInheritsXforms(true);
89 abc_xform_schema_.set(xform_sample);
90
91 write_visibility(context);
92}
93
95{
96 return abc_xform_;
97}
98
100{
101 if (context.duplicator != nullptr) {
102 /* This object is being duplicated, so could be emitted by a particle system and thus
103 * influenced by forces. TODO(Sybren): Make this more strict. Probably better to get from the
104 * depsgraph whether this object instance has a time source. */
105 return true;
106 }
107 if (check_has_physics(context)) {
108 return true;
109 }
110 return BKE_object_moves_in_time(context.object, context.animation_check_include_parent);
111}
112
113} // 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_INFO(clg_ref, level,...)
Definition CLG_log.h:179
@ OB_CAMERA
static CLG_LogRef LOG
static bool check_has_physics(const HierarchyContext &context)
void write_visibility(const HierarchyContext &context)
Alembic::Abc::OCompoundProperty abc_schema_prop_for_custom_props(T abc_schema)
const ABCWriterConstructorArgs args_
uint32_t time_sampling_index_transforms() const
virtual Alembic::Abc::OObject get_alembic_object() const override
virtual 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)
virtual bool check_is_animated(const HierarchyContext &context) const override
virtual void do_write(HierarchyContext &context) override
#define LOG(severity)
Definition log.h:33
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:74
IDProperty * properties
Definition DNA_ID.h:456