AL_USDMaya  0.29.4
USD to Maya Bridge
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TransformIterator.h
1 //
2 // Copyright 2017 Animal Logic
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.//
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 #pragma once
17 #include "maya/MObject.h"
18 #include "maya/MDagPath.h"
19 
20 #include "pxr/usd/sdf/layer.h"
21 #include "pxr/pxr.h"
22 #include "pxr/usd/usd/prim.h"
23 
24 #include <vector>
25 #include "AL/usd/utils/ForwardDeclares.h"
26 
27 PXR_NAMESPACE_USING_DIRECTIVE
28 
29 namespace AL {
30 namespace usdmaya {
31 namespace fileio {
32 
33 //----------------------------------------------------------------------------------------------------------------------
36 //----------------------------------------------------------------------------------------------------------------------
38 {
39 public:
40 
44  TransformIterator(UsdStageRefPtr stage, const MDagPath& parentPath = MDagPath());
45 
49  TransformIterator(const UsdPrim& startPrim, const MDagPath& startMayaPath);
50 
53  inline bool done() const
54  { return m_primStack.empty(); }
55 
58  inline size_t depth() const
59  { return m_primStack.size(); }
60 
63  inline const UsdPrim& prim() const
64  { return (m_primStack.end() - 1)->m_prim; }
65 
67  void prune();
68 
71  bool next();
72 
77  inline void append(const MObject newNode)
78  {
79  if(!m_primStack.empty())
80  m_primStack[m_primStack.size() - 1].m_object = newNode;
81  }
82 
85  inline MObject parent() const
86  {
87  if(m_primStack.size() > 1)
88  {
89  if( (m_primStack.end() - 2)->m_object != MObject::kNullObj)
90  {
91  return (m_primStack.end() - 2)->m_object;
92  }
93  if( (m_primStack.end() - 1)->m_object != MObject::kNullObj)
94  {
95  return (m_primStack.end() - 1)->m_object;
96  }
97  }
98  if(m_primStack.size() == 1)
99  {
100  return (m_primStack.end() - 1)->m_object;
101  }
102  return m_parentPath.node();
103  }
104 
107  MDagPath currentPath() const;
108 
109 private:
110  struct StackRef
111  {
112  StackRef(const UsdPrim& prim);
113  StackRef(const StackRef& prim);
114  StackRef();
115  UsdPrim m_prim;
116  MObject m_object;
117  UsdPrim::SiblingIterator m_begin;
118  UsdPrim::SiblingIterator m_end;
119  int32_t m_currentChild;
120  int32_t m_numChildren;
121  };
122 
123  std::vector<StackRef> m_primStack;
124  UsdStageRefPtr m_stage;
125  size_t m_currentItem;
126  MDagPath m_parentPath;
127 
128  TfHashSet<SdfPath, SdfPath::Hash> m_visitedMasterPrimPaths;
129 };
130 
131 //----------------------------------------------------------------------------------------------------------------------
132 } // fileio
133 } // usdmaya
134 } // AL
135 //----------------------------------------------------------------------------------------------------------------------
136 
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:77
size_t depth() const
returns the current iteration depth
Definition: TransformIterator.h:58
const UsdPrim & prim() const
return the current prim
Definition: TransformIterator.h:63
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:53
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:37
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:85