AL_USDMaya  0.16.6
USD to Maya Bridge
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
VariantDB.h
1 #pragma once
2 #include <cstdint>
3 #include "maya/MDagPath.h"
4 #include "AL/usdmaya/fileio/translators/TranslatorBase.h"
5 #include "AL/usdmaya/fileio/translators/TranslatorContext.h"
6 
7 #include "pxr/usd/sdf/path.h"
8 #include "pxr/usd/usd/stage.h"
9 
10 namespace AL {
11 namespace usdmaya {
12 namespace nodes {
13 
14 //----------------------------------------------------------------------------------------------------------------------
18 //----------------------------------------------------------------------------------------------------------------------
20 {
21 public:
22 
26  SchemaNodeRef(const SdfPath& path, MObject mayaObj)
27  : m_primPath(path), m_mayaObj(mayaObj) {}
28 
31 
34  const SdfPath& primPath() const
35  { return m_primPath; }
36 
39  MObject mayaObject() const
40  { return m_mayaObj.object(); }
41 
42 private:
43  SdfPath m_primPath;
44  MObjectHandle m_mayaObj;
45 };
46 
47 
48 //----------------------------------------------------------------------------------------------------------------------
52 //----------------------------------------------------------------------------------------------------------------------
54 {
55 public:
56 
59  {
64  inline bool operator() (const SchemaNodeRef& a, const SdfPath& b) const
65  { return a.primPath() < b; }
66 
71  inline bool operator() (const SdfPath& a, const SchemaNodeRef& b) const
72  { return a < b.primPath(); }
73 
79  inline bool operator() (const SchemaNodeRef& a, const SchemaNodeRef& b) const
80  { return a.primPath() < b.primPath(); }
81  };
82 
86 
89 
93  void lock()
94  {}
95 
101  bool hasEntry(const SdfPath& path, const TfToken& type)
102  {
103  auto it = std::lower_bound(m_nodeRefs.begin(), m_nodeRefs.end(), path, value_compare());
104  if(it != m_nodeRefs.end() && (it->primPath() == path))
105  {
106  return type == context()->getTypeForPath(path);
107  }
108  return false;
109  }
110 
116  void addEntry(const SdfPath& primPath, const MObject& primObj);
117 
119  void unlock()
120  { std::sort(m_nodeRefs.begin(), m_nodeRefs.end(), value_compare()); }
121 
126  void preRemoveEntry(const SdfPath& primPath, SdfPathVector& itemsToRemove);
127 
130  void removeEntries(const SdfPathVector& itemsToRemove);
131 
134  void outputPrims(std::ostream& os);
135 
138  fileio::translators::TranslatorContextPtr context();
139 
143  { return m_translatorManufacture; }
144 
147  inline nodes::ProxyShape* proxy() const
148  { return m_proxy; }
149 
150 private:
151  void unloadPrim(
152  const SdfPath& primPath,
153  const MObject& primObj);
154  void preUnloadPrim(
155  UsdPrim& primPath,
156  const MObject& primObj);
157 
158  typedef std::vector<SchemaNodeRef> SchemaNodeRefs;
159  SchemaNodeRefs m_nodeRefs;
160  nodes::ProxyShape* const m_proxy;
161  fileio::translators::TranslatorContextPtr m_context;
162  fileio::translators::TranslatorManufacture m_translatorManufacture;
163 };
164 
165 //----------------------------------------------------------------------------------------------------------------------
166 } // nodes
167 } // usdmaya
168 } // AL
169 //----------------------------------------------------------------------------------------------------------------------
170 
const SdfPath & primPath() const
get the prim path of this reference
Definition: VariantDB.h:34
void preRemoveEntry(const SdfPath &primPath, SdfPathVector &itemsToRemove)
This is called during a variant switch to determine whether the variant switch will allow Maya nodes ...
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 unlock()
call this method after adding some entries into the DB
Definition: VariantDB.h:119
fileio::translators::TranslatorManufacture & translatorManufacture()
access the current translator factory for the schema prims
Definition: VariantDB.h:142
a mapping between a prim path and the transform node under which the prim was imported via a custom p...
Definition: VariantDB.h:19
SchemaNodeRefDB(nodes::ProxyShape *const proxy)
constructor
void addEntry(const SdfPath &primPath, const MObject &primObj)
create a mapping between the prim path, and the MObject that was created by a translator plugin when ...
~SchemaNodeRef()
dtor
Definition: VariantDB.h:30
bool hasEntry(const SdfPath &path, const TfToken &type)
This method is used to determine whether this DB has an entry for the specified prim path and the giv...
Definition: VariantDB.h:101
comparison utility (for sorting array of pointers to node references based on their path) ...
Definition: VariantDB.h:58
SchemaNodeRef(const SdfPath &path, MObject mayaObj)
ctor
Definition: VariantDB.h:26
void outputPrims(std::ostream &os)
debugging util - prints a list of the schema nodes that currently exist within maya ...
The proxy shape node needs to store a mapping of all the schema nodes it has brought into the Maya sc...
Definition: VariantDB.h:53
Forms a registry of all plug-in translator types registered.
Definition: TranslatorBase.h:191
void removeEntries(const SdfPathVector &itemsToRemove)
call this to remove a prim from the DB (you do not need to lock/unlock here).
nodes::ProxyShape * proxy() const
returns the proxy shape node associated with the schema prims in this DB
Definition: VariantDB.h:147
void lock()
When adding new schema node entries into this DB, rather than forcing a sort after each entry is adde...
Definition: VariantDB.h:93
MObject mayaObject() const
get the maya object of the node
Definition: VariantDB.h:39
bool operator()(const SchemaNodeRef &a, const SdfPath &b) const
compare schema node ref to path
Definition: VariantDB.h:64
fileio::translators::TranslatorContextPtr context()
access the current translator context for the schema prims