AL_USDMaya  0.16.6
USD to Maya Bridge
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
TransformIterator.h
1 #pragma once
2 #include "AL/usdmaya/Common.h"
3 
4 #include "maya/MObject.h"
5 #include "maya/MDagPath.h"
6 
7 #include "pxr/usd/sdf/layer.h"
8 #include "pxr/usd/usd/prim.h"
9 
10 #include <vector>
11 
12 namespace AL {
13 namespace usdmaya {
14 namespace fileio {
15 
16 //----------------------------------------------------------------------------------------------------------------------
19 //----------------------------------------------------------------------------------------------------------------------
21 {
22 public:
23 
27  TransformIterator(UsdStageRefPtr stage, const MDagPath& parentPath = MDagPath());
28 
32  TransformIterator(const UsdPrim& startPrim, const MDagPath& startMayaPath);
33 
36  inline bool done() const
37  { return m_primStack.empty(); }
38 
41  inline size_t depth() const
42  { return m_primStack.size(); }
43 
46  inline const UsdPrim& prim() const
47  { return (m_primStack.end() - 1)->m_prim; }
48 
50  void prune();
51 
54  bool next();
55 
60  inline void append(const MObject newNode)
61  {
62  m_primStack[m_primStack.size() - 1].m_object = newNode;
63  }
64 
67  inline MObject parent() const
68  {
69  if(m_primStack.size() > 1)
70  {
71  if( (m_primStack.end() - 2)->m_object != MObject::kNullObj)
72  {
73  return (m_primStack.end() - 2)->m_object;
74  }
75  if( (m_primStack.end() - 1)->m_object != MObject::kNullObj)
76  {
77  return (m_primStack.end() - 1)->m_object;
78  }
79  }
80  if(m_primStack.size() == 1)
81  {
82  return (m_primStack.end() - 1)->m_object;
83  }
84  return m_parentPath.node();
85  }
86 
89  MDagPath currentPath() const;
90 
91 private:
92  struct StackRef
93  {
94  StackRef(const UsdPrim& prim);
95  StackRef(const StackRef& prim);
96  StackRef();
97  UsdPrim m_prim;
98  MObject m_object;
99  UsdPrim::SiblingIterator m_begin;
100  UsdPrim::SiblingIterator m_end;
101  int32_t m_currentChild;
102  int32_t m_numChildren;
103  };
104 
105  std::vector<StackRef> m_primStack;
106  UsdStageRefPtr m_stage;
107  size_t m_currentItem;
108  MDagPath m_parentPath;
109 
110  TfHashSet<SdfPath, SdfPath::Hash> m_visitedMasterPrimPaths;
111 };
112 
113 //----------------------------------------------------------------------------------------------------------------------
114 } // fileio
115 } // usdmaya
116 } // AL
117 //----------------------------------------------------------------------------------------------------------------------
118 
bool next()
move to the next item in the stage
void append(const MObject newNode)
in order to keep the maya path in sync with the USD prim, at each iteration step you should pass in t...
Definition: TransformIterator.h:60
size_t depth() const
returns the current iteration depth
Definition: TransformIterator.h:41
const UsdPrim & prim() const
return the current prim
Definition: TransformIterator.h:46
TransformIterator(UsdStageRefPtr stage, const MDagPath &parentPath=MDagPath())
ctor. Initialises the iterator to the root of the stage
bool done() const
return true if the iteration is complete
Definition: TransformIterator.h:36
void prune()
do not iterate over the children of this node
An iterator to walk over the transforms within a USD file.
Definition: TransformIterator.h:20
MDagPath currentPath() const
returns the current maya path equivalent of the current USD prim.
MObject parent() const
returns the parent transform of the current node.
Definition: TransformIterator.h:67