All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
transformWriter.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXRUSDMAYA_TRANSFORM_WRITER_H
25 #define PXRUSDMAYA_TRANSFORM_WRITER_H
26 
28 
29 #include "pxr/pxr.h"
30 #include "usdMaya/api.h"
31 
32 #include "usdMaya/primWriter.h"
34 
35 #include "pxr/base/gf/vec3d.h"
36 #include "pxr/base/tf/token.h"
37 #include "pxr/usd/sdf/path.h"
38 #include "pxr/usd/usd/timeCode.h"
39 #include "pxr/usd/usdGeom/xformOp.h"
40 #include "pxr/usd/usdGeom/xformable.h"
41 #include "pxr/usd/usdUtils/sparseValueWriter.h"
42 
43 #include <maya/MFnDependencyNode.h>
44 #include <maya/MEulerRotation.h>
45 #include <maya/MFnTransform.h>
46 #include <maya/MPlug.h>
47 #include <maya/MString.h>
48 
49 #include <unordered_map>
50 #include <vector>
51 
52 
53 PXR_NAMESPACE_OPEN_SCOPE
54 
55 
59 {
60 public:
61  PXRUSDMAYA_API
63  const MFnDependencyNode& depNodeFn,
64  const SdfPath& usdPath,
65  UsdMayaWriteJobContext& jobCtx);
66 
70  PXRUSDMAYA_API
71  void Write(const UsdTimeCode& usdTime) override;
72 
73 private:
74  using _TokenRotationMap = std::unordered_map<
75  const TfToken, MEulerRotation, TfToken::HashFunctor>;
76 
77  enum class _XformType { Translate, Rotate, Scale, Shear };
78  enum class _SampleType { None, Static, Animated };
79 
80  // This may not be the best name here as it isn't necessarily animated.
81  struct _AnimChannel
82  {
83  MPlug plug[3];
84  _SampleType sampleType[3];
85  // defValue should always be in "maya" space. that is, if it's a
86  // rotation it should be radians, not degrees. (This is done so we only
87  // need to do conversion in one place, and so that, if we need to do
88  // euler filtering, we don't do conversions, and then undo them to use
89  // MEulerRotation).
90  GfVec3d defValue;
91  _XformType opType;
92  UsdGeomXformOp::Type usdOpType;
93  UsdGeomXformOp::Precision precision;
94  TfToken opName;
95  bool isInverse;
96  UsdGeomXformOp op;
97  };
98 
99  // For a given array of _AnimChannels and time, compute the xformOp data if
100  // needed and set the xformOps' values.
101  static void _ComputeXformOps(
102  const std::vector<_AnimChannel>& animChanList,
103  const UsdTimeCode& usdTime,
104  const bool eulerFilter,
105  UsdMayaTransformWriter::_TokenRotationMap* previousRotates,
106  UsdUtilsSparseValueWriter* valueWriter);
107 
108  // Creates an _AnimChannel from a Maya compound attribute if there is
109  // meaningful data. This means we found data that is non-identity.
110  // Returns true if we extracted an _AnimChannel and false otherwise (e.g.
111  // the data was identity).
112  static bool _GatherAnimChannel(
113  const _XformType opType,
114  const MFnTransform& iTrans,
115  const TfToken& parentName,
116  const MString& xName, const MString& yName, const MString& zName,
117  std::vector<_AnimChannel>* oAnimChanList,
118  const bool isWritingAnimation,
119  const bool setOpName);
120 
124  void _PushTransformStack(
125  const MFnTransform& iTrans,
126  const UsdGeomXformable& usdXForm,
127  const bool writeAnim);
128 
129  std::vector<_AnimChannel> _animChannels;
130  _TokenRotationMap _previousRotates;
131 };
132 
133 
134 PXR_NAMESPACE_CLOSE_SCOPE
135 
136 
137 #endif
Provides basic functionality and access to shared data for UsdMayaPrimWriters.
Schema wrapper for UsdAttribute for authoring and computing transformation operations, as consumed by UsdGeomXformable schema.
Definition: xformOp.h:111
Type
Enumerates the set of all transformation operation types.
Definition: xformOp.h:116
Functor to use for hash maps from tokens to other things.
Definition: token.h:168
PXRUSDMAYA_API void Write(const UsdTimeCode &usdTime) override
Main export function that runs when the traversal hits the node.
Utility class that manages sparse authoring of a set of UsdAttributes.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:85
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
Precision
Precision with which the value of the tranformation operation is encoded.
Definition: xformOp.h:140
Basic type for a vector of 3 double components.
Definition: vec3d.h:63
Base class for all built-in and user-defined prim writers.
Definition: primWriter.h:64
Writes transforms and serves as the base class for custom transform writers.
Base class for all transformable prims, which allows arbitrary sequences of component affine transfor...
Definition: xformable.h:252