Blender  V2.93
usd_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  * The Original Code is Copyright (C) 2019 Blender Foundation.
17  * All rights reserved.
18  */
19 #include "usd_writer_transform.h"
20 #include "usd_hierarchy_iterator.h"
21 
22 #include <pxr/base/gf/matrix4f.h>
23 #include <pxr/usd/usdGeom/xform.h>
24 
25 #include "BKE_object.h"
26 
27 #include "BLI_math_matrix.h"
28 
29 #include "DNA_layer_types.h"
30 
31 namespace blender::io::usd {
32 
34 {
35 }
36 
38 {
39  float parent_relative_matrix[4][4]; /* The object matrix relative to the parent. */
40  mul_m4_m4m4(parent_relative_matrix, context.parent_matrix_inv_world, context.matrix_world);
41 
42  /* Write the transform relative to the parent. */
43  pxr::UsdGeomXform xform = pxr::UsdGeomXform::Define(usd_export_context_.stage,
45  if (!xformOp_) {
46  xformOp_ = xform.AddTransformOp();
47  }
48  xformOp_.Set(pxr::GfMatrix4d(parent_relative_matrix), get_export_time_code());
49 }
50 
52 {
53  if (context.duplicator != nullptr) {
54  /* This object is being duplicated, so could be emitted by a particle system and thus
55  * influenced by forces. TODO(Sybren): Make this more strict. Probably better to get from the
56  * depsgraph whether this object instance has a time source. */
57  return true;
58  }
60  return true;
61  }
62  return BKE_object_moves_in_time(context.object, context.animation_check_include_parent);
63 }
64 
65 } // namespace blender::io::usd
General operations, lookup, etc. for blender objects.
bool BKE_object_moves_in_time(const struct Object *object, bool recurse_parent)
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
Definition: math_matrix.c:262
static bool check_has_physics(const HierarchyContext &context)
pxr::UsdTimeCode get_export_time_code() const
const USDExporterContext usd_export_context_
USDTransformWriter(const USDExporterContext &ctx)
bool check_is_animated(const HierarchyContext &context) const override
void do_write(HierarchyContext &context) override
struct SELECTID_Context context
Definition: select_engine.c:47