AL_USDMaya  0.16.6
USD to Maya Bridge
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
TranslatorContext.h
1 #pragma once
2 #include "AL/usdmaya/Common.h"
3 #include "maya/MPxData.h"
4 #include "maya/MGlobal.h"
5 #include "maya/MObject.h"
6 #include "maya/MObjectHandle.h"
7 #include "maya/MObjectArray.h"
8 #include "maya/MDGModifier.h"
9 #include "pxr/base/tf/refPtr.h"
10 #include "pxr/usd/usd/prim.h"
11 
12 #include <map>
13 #include <unordered_map>
14 #include <string>
15 
16 namespace AL {
17 namespace usdmaya {
18 namespace fileio {
19 namespace translators {
20 
21 typedef std::vector<MObjectHandle> MObjectHandleArray;
22 
23 //----------------------------------------------------------------------------------------------------------------------
27 //----------------------------------------------------------------------------------------------------------------------
29  : public TfRefBase
30 {
31 public:
33  typedef TfRefPtr<This> RefPtr;
34 
38  static RefPtr create(nodes::ProxyShape* proxyShape)
39  { return TfCreateRefPtr(new This(proxyShape)); }
40 
44  { return m_proxyShape; }
45 
48  UsdStageRefPtr getUsdStage() const;
49 
55  bool getTransform(const UsdPrim& prim, MObjectHandle& object)
56  { return getTransform(prim.GetPath(), object); }
57 
63  bool getTransform(const SdfPath& path, MObjectHandle& object);
64 
74  bool getMObject(const UsdPrim& prim, MObjectHandle& object, MTypeId type)
75  { return getMObject(prim.GetPath(), object, type); }
76 
86  bool getMObject(const SdfPath& path, MObjectHandle& object, MTypeId type);
87 
97  bool getMObject(const UsdPrim& prim, MObjectHandle& object, MFn::Type type)
98  { return getMObject(prim.GetPath(), object, type); }
99 
109  bool getMObject(const SdfPath& path, MObjectHandle& object, MFn::Type type);
110 
115  bool getMObjects(const UsdPrim& prim, MObjectHandleArray& returned)
116  { return getMObjects(prim.GetPath(), returned); }
117 
122  bool getMObjects(const SdfPath& path, MObjectHandleArray& returned);
123 
128  void insertItem(const UsdPrim& prim, MObjectHandle object);
129 
133  void removeItems(const UsdPrim& prim)
134  { removeItems(prim.GetPath()); }
135 
139  void removeItems(const SdfPath& path);
140 
143 
147  TfToken getTypeForPath(SdfPath path) const
148  {
149  const auto it = m_primMapping.find(path.GetString());
150  if(it != m_primMapping.end())
151  {
152  return it->second.m_type;
153  }
154  return TfToken();
155  }
156 
162  void registerItem(const UsdPrim& prim, MObjectHandle object);
163 
166  MString serialise() const;
167 
170  void deserialise(const MString& string);
171 
172 private:
173 
174  TranslatorContext(const nodes::ProxyShape* proxyShape)
175  : m_proxyShape(proxyShape), m_primMapping()
176  {}
177 
178  const nodes::ProxyShape* m_proxyShape;
179 
180  struct PrimLookup
181  {
182  TfToken m_type;
183  MObjectHandle m_object;
184  MObjectHandleArray m_createdNodes;
185  };
186 
187  // map between a usd prim path and either a dag parent node or
188  // a dependency node
189  std::unordered_map<std::string, PrimLookup> m_primMapping;
190 };
191 
192 typedef TfRefPtr<TranslatorContext> TranslatorContextPtr;
193 
194 //----------------------------------------------------------------------------------------------------------------------
195 } // translators
196 } // fileio
197 } // usdmaya
198 } // AL
199 //----------------------------------------------------------------------------------------------------------------------
This class provides a context to store mappings between UsdPrims, and the Maya nodes that represent t...
Definition: TranslatorContext.h:28
TfRefPtr< This > RefPtr
pointer to this type
Definition: TranslatorContext.h:33
A custom proxy shape node that attaches itself to a USD file, and then renders it. The stage is held internally as a member variable, and it will be composed based on a change to the "filePath" attribute.
Definition: ProxyShape.h:33
void deserialise(const MString &string)
deserialises the string back into the translator context
UsdStageRefPtr getUsdStage() const
return the usd stage associated with this context
TranslatorContext This
this type
Definition: TranslatorContext.h:32
bool getMObjects(const UsdPrim &prim, MObjectHandleArray &returned)
returns all of the maya nodes that were created by the specific prim
Definition: TranslatorContext.h:115
void removeItems(const UsdPrim &prim)
during a variant switch, if we lose a prim, then it's path will be passed into this method...
Definition: TranslatorContext.h:133
const nodes::ProxyShape * getProxyShape() const
return the proxy shape associated with this context
Definition: TranslatorContext.h:43
bool getTransform(const UsdPrim &prim, MObjectHandle &object)
given a USD prim, this will see whether a maya node exists for it. If it does, that will be returned ...
Definition: TranslatorContext.h:55
bool getMObject(const UsdPrim &prim, MObjectHandle &object, MTypeId type)
given a USD prim, this will see whether a maya node exists for it. If it does, that will be returned ...
Definition: TranslatorContext.h:74
void insertItem(const UsdPrim &prim, MObjectHandle object)
If within your custom translator plug-in you need to create any maya nodes, associate that maya node ...
static RefPtr create(nodes::ProxyShape *proxyShape)
construct a new context for the specified proxy shape node
Definition: TranslatorContext.h:38
MString serialise() const
serialises the content of the translator context to a text string.
bool getMObject(const UsdPrim &prim, MObjectHandle &object, MFn::Type type)
given a USD prim, this will see whether a maya node exists for it. If it does, that will be returned ...
Definition: TranslatorContext.h:97
void registerItem(const UsdPrim &prim, MObjectHandle object)
Internal method. If within your custom translator plug-in you need to create any maya nodes...
TfToken getTypeForPath(SdfPath path) const
given a path to a prim, return the prim type we are aware of at that path
Definition: TranslatorContext.h:147