Blender  V2.93
abc_writer_transform.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include "abc_writer_transform.h"
22 #include "abc_hierarchy_iterator.h"
24 #include "intern/abc_util.h"
25 
26 #include "BKE_object.h"
27 
28 #include "BLI_math_matrix.h"
29 #include "BLI_math_rotation.h"
30 
31 #include "DNA_layer_types.h"
32 
33 #include "CLG_log.h"
34 static CLG_LogRef LOG = {"io.alembic"};
35 
36 namespace blender::io::alembic {
37 
38 using Alembic::Abc::OObject;
39 using Alembic::AbcGeom::OXform;
40 using Alembic::AbcGeom::OXformSchema;
41 using Alembic::AbcGeom::XformSample;
42 
44  : ABCAbstractWriter(args)
45 {
47 }
48 
50 {
51  CLOG_INFO(&LOG, 2, "exporting %s", args_.abc_path.c_str());
52  abc_xform_ = OXform(args_.abc_parent, args_.abc_name, timesample_index_);
53  abc_xform_schema_ = abc_xform_.getSchema();
54 }
55 
56 Alembic::Abc::OCompoundProperty ABCTransformWriter::abc_prop_for_custom_props()
57 {
58  return abc_schema_prop_for_custom_props<OXformSchema>(abc_xform_schema_);
59 }
60 
62 {
63  const Object *object = context.object;
64  return object->id.properties;
65 }
66 
68 {
69  float parent_relative_matrix[4][4]; /* The object matrix relative to the parent. */
70  mul_m4_m4m4(parent_relative_matrix, context.parent_matrix_inv_world, context.matrix_world);
71 
72  /* After this, parent_relative_matrix uses Y=up. */
73  copy_m44_axis_swap(parent_relative_matrix, parent_relative_matrix, ABC_YUP_FROM_ZUP);
74 
75  /* If the parent is a camera, undo its to-Maya rotation (see below). */
76  bool is_root_object = context.export_parent == nullptr;
77  if (!is_root_object && context.export_parent->type == OB_CAMERA) {
78  float rot_mat[4][4];
79  axis_angle_to_mat4_single(rot_mat, 'X', M_PI_2);
80  mul_m4_m4m4(parent_relative_matrix, rot_mat, parent_relative_matrix);
81  }
82 
83  /* If the object is a camera, apply an extra rotation to Maya camera orientation. */
84  if (context.object->type == OB_CAMERA) {
85  float rot_mat[4][4];
86  axis_angle_to_mat4_single(rot_mat, 'X', -M_PI_2);
87  mul_m4_m4m4(parent_relative_matrix, parent_relative_matrix, rot_mat);
88  }
89 
90  if (is_root_object) {
91  /* Only apply scaling to root objects, parenting will propagate it. */
92  float scale_mat[4][4];
94  scale_mat[3][3] = args_.export_params->global_scale; /* also scale translation */
95  mul_m4_m4m4(parent_relative_matrix, parent_relative_matrix, scale_mat);
96  parent_relative_matrix[3][3] /=
97  args_.export_params->global_scale; /* Normalize the homogeneous component. */
98  }
99 
100  XformSample xform_sample;
101  xform_sample.setMatrix(convert_matrix_datatype(parent_relative_matrix));
102  xform_sample.setInheritsXforms(true);
103  abc_xform_schema_.set(xform_sample);
104 
106 }
107 
109 {
110  return abc_xform_;
111 }
112 
114 {
115  if (context.duplicator != nullptr) {
116  /* This object is being duplicated, so could be emitted by a particle system and thus
117  * influenced by forces. TODO(Sybren): Make this more strict. Probably better to get from the
118  * depsgraph whether this object instance has a time source. */
119  return true;
120  }
121  if (check_has_physics(context)) {
122  return true;
123  }
124  return BKE_object_moves_in_time(context.object, context.animation_check_include_parent);
125 }
126 
127 } // namespace blender::io::alembic
General operations, lookup, etc. for blender objects.
bool BKE_object_moves_in_time(const struct Object *object, bool recurse_parent)
#define M_PI_2
Definition: BLI_math_base.h:41
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
Definition: math_matrix.c:262
void scale_m4_fl(float R[4][4], float scale)
Definition: math_matrix.c:2309
void axis_angle_to_mat4_single(float R[4][4], const char axis, const float angle)
#define CLOG_INFO(clg_ref, level,...)
Definition: CLG_log.h:201
@ OB_CAMERA
static CLG_LogRef LOG
static bool check_has_physics(const HierarchyContext &context)
void write_visibility(const HierarchyContext &context)
const ABCWriterConstructorArgs args_
uint32_t time_sampling_index_transforms() const
Definition: abc_archive.cc:217
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
void copy_m44_axis_swap(float dst_mat[4][4], float src_mat[4][4], AbcAxisSwapMode mode)
Imath::M44d convert_matrix_datatype(float mat[4][4])
Definition: abc_util.cc:93
struct SELECTID_Context context
Definition: select_engine.c:47