20 #include "AL/usdmaya/fileio/translators/DgNodeTranslator.h"
21 #include "AL/usdmaya/fileio/translators/TranslatorBase.h"
23 #include "maya/MPlug.h"
24 #include "maya/MString.h"
25 #include "maya/MDagPath.h"
26 #include "maya/MObjectHandle.h"
35 #include "pxr/usd/usd/stage.h"
37 PXR_NAMESPACE_USING_DIRECTIVE
42 bool operator () (
const MPlug& a,
const MPlug& b)
const
44 return strcmp(a.name().asChar(), b.name().asChar()) < 0;;
51 bool operator () (
const MDagPath& a,
const MDagPath& b)
const
53 return strcmp(a.fullPathName().asChar(), b.fullPathName().asChar()) < 0;;
68 typedef std::map<MPlug, UsdAttribute, compare_MPlug> PlugAttrVector;
69 typedef std::map<MDagPath, UsdAttribute, compare_MDagPath> MeshAttrVector;
70 typedef std::map<MPlug, ScaledPair, compare_MPlug> PlugAttrScaledVector;
90 static bool isAnimated(
const MObject& node,
const MObject& attr,
const bool assumeExpressionIsAnimated =
true)
91 {
return isAnimated(MPlug(node, attr), assumeExpressionIsAnimated); }
103 static bool isAnimated(MPlug attr,
bool assumeExpressionIsAnimated =
true);
129 inline void addPlug(
const MPlug& plug,
const UsdAttribute& attribute,
const bool assumeExpressionIsAnimated)
131 if(m_animatedPlugs.find(plug) != m_animatedPlugs.end())
133 if(
isAnimated(plug, assumeExpressionIsAnimated))
134 m_animatedPlugs.emplace(plug, attribute);
143 inline void addPlug(
const MPlug& plug,
const UsdAttribute& attribute,
const float scale,
const bool assumeExpressionIsAnimated)
145 if(m_scaledAnimatedPlugs.find(plug) != m_scaledAnimatedPlugs.end())
147 if(
isAnimated(plug, assumeExpressionIsAnimated))
148 m_scaledAnimatedPlugs.emplace(plug,
ScaledPair{attribute, scale});
157 inline void addTransformPlug(
const MPlug& plug,
const UsdAttribute& attribute,
const bool assumeExpressionIsAnimated)
159 if(m_animatedTransformPlugs.find(plug) != m_animatedTransformPlugs.end())
161 if (
isAnimated(plug, assumeExpressionIsAnimated))
162 m_animatedTransformPlugs.emplace(plug, attribute);
171 if(m_animatedTransformPlugs.find(plug) == m_animatedTransformPlugs.end())
172 m_animatedTransformPlugs.emplace(plug, attribute);
180 inline void forceAddPlug(
const MPlug& plug,
const UsdAttribute& attribute,
const float scale)
182 if(m_scaledAnimatedPlugs.find(plug) == m_scaledAnimatedPlugs.end())
183 m_scaledAnimatedPlugs.emplace(plug,
ScaledPair{ attribute, scale });
190 inline void forceAddPlug(
const MPlug& plug,
const UsdAttribute& attribute)
192 if(m_animatedPlugs.find(plug) == m_animatedPlugs.end())
193 m_animatedPlugs.emplace(plug, attribute);
199 inline void addMesh(
const MDagPath& path,
const UsdAttribute& attribute)
201 if(m_animatedMeshes.find(path) == m_animatedMeshes.end())
202 m_animatedMeshes.emplace(path, attribute);
215 { m_animatedNodes.push_back({translator, dagPath, usdPrim}); }
218 static bool considerToBeAnimation(
const MFn::Type nodeType);
219 static bool inheritTransform(
const MDagPath &path);
220 static bool areTransformAttributesConnected(
const MDagPath &path);
222 struct NodeExportInfo
228 std::vector<NodeExportInfo> m_animatedNodes;
229 PlugAttrVector m_animatedPlugs;
230 PlugAttrScaledVector m_scaledAnimatedPlugs;
231 PlugAttrVector m_animatedTransformPlugs;
232 MeshAttrVector m_animatedMeshes;
243 constexpr
static int transformAttributesCount {13};
247 inline std::array<MObject, transformAttributesCount>::const_iterator begin()
const {
return m_commonTransformAttributes.cbegin();}
248 inline std::array<MObject, transformAttributesCount>::const_iterator end()
const {
return m_commonTransformAttributes.cend();}
249 inline MObject inheritTransformAttribute()
const {
return m_inheritTransformAttribute;}
252 MStatus initialise();
253 std::array<MObject, transformAttributesCount> m_commonTransformAttributes;
254 MObject m_inheritTransformAttribute;
parameters for the exporter. These parameters are constructed by any command or file translator that ...
Definition: ExportParams.h:35
void forceAddPlug(const MPlug &plug, const UsdAttribute &attribute)
add an animated plug to the animation translator (if the plug is animated)
Definition: AnimationTranslator.h:190
void forceAddTransformPlug(const MPlug &plug, const UsdAttribute &attribute)
add a transform plug to the animation translator (if the plug is animated)
Definition: AnimationTranslator.h:169
void addMesh(const MDagPath &path, const UsdAttribute &attribute)
add a mesh to the animation translator
Definition: AnimationTranslator.h:199
static AL_USDMAYA_PUBLIC bool isAnimatedTransform(const MObject &transformNode)
returns true if the transform node is animated
an attribute that has a scaling on it (due to unit differences)
Definition: AnimationTranslator.h:62
UsdAttribute attr
the attribute to export
Definition: AnimationTranslator.h:64
void forceAddPlug(const MPlug &plug, const UsdAttribute &attribute, const float scale)
add a scaled plug to the animation translator (if the plug is animated)
Definition: AnimationTranslator.h:180
void addPlug(const MPlug &plug, const UsdAttribute &attribute, const float scale, const bool assumeExpressionIsAnimated)
add a plug to the animation translator (if the plug is animated)
Definition: AnimationTranslator.h:143
AL_USDMAYA_PUBLIC void exportAnimation(const ExporterParams ¶ms)
After the scene has been exported, call this method to export the animation data on various attribute...
void addCustomAnimNode(translators::TranslatorBase *translator, MDagPath dagPath, UsdPrim usdPrim)
insert a prim into the anim translator for custom anim export.
Definition: AnimationTranslator.h:214
Base class for maya translator usd plugins. The TfType of these plugins has to be derived from the ba...
Definition: TranslatorBase.h:177
static bool isAnimated(const MObject &node, const MObject &attr, const bool assumeExpressionIsAnimated=true)
returns true if the attribute is animated
Definition: AnimationTranslator.h:90
operator to compare MDagPaths with < operator
Definition: AnimationTranslator.h:49
static AL_USDMAYA_PUBLIC bool isAnimatedMesh(const MDagPath &mesh)
returns true if the mesh is animated
float scale
the scale to apply
Definition: AnimationTranslator.h:65
operator to compare MPlugs with < operator
Definition: AnimationTranslator.h:40
void addPlug(const MPlug &plug, const UsdAttribute &attribute, const bool assumeExpressionIsAnimated)
add a plug to the animation translator (if the plug is animated)
Definition: AnimationTranslator.h:129
void addTransformPlug(const MPlug &plug, const UsdAttribute &attribute, const bool assumeExpressionIsAnimated)
add a transform plug to the animation translator (if the plug is animated)
Definition: AnimationTranslator.h:157
A utility class to help with exporting animated plugs from maya.
Definition: AnimationTranslator.h:76