AL_USDMaya  0.16.6
USD to Maya Bridge
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Utils.h
1 #pragma once
2 #include "AL/maya/SIMD.h"
3 #include "AL/usdmaya/Common.h"
4 
5 #include "maya/MObject.h"
6 #include "maya/MString.h"
7 #include "maya/MUuid.h"
8 #include "maya/MFnDependencyNode.h"
9 
10 #include <map>
11 #include <string>
12 
13 namespace AL {
14 namespace usdmaya {
15 
16 //----------------------------------------------------------------------------------------------------------------------
25 //----------------------------------------------------------------------------------------------------------------------
26 void mapUsdPrimToMayaNode(const UsdPrim& usdPrim, const MObject& mayaObject, const MDagPath* const proxyShapeNode = nullptr);
27 
28 //----------------------------------------------------------------------------------------------------------------------
35 //----------------------------------------------------------------------------------------------------------------------
36 void matrixToSRT(GfMatrix4d& value, double S[3], MEulerRotation& R, double T[3]);
37 
38 //----------------------------------------------------------------------------------------------------------------------
43 //----------------------------------------------------------------------------------------------------------------------
44 inline MString convert(const std::string& str)
45 {
46  return MString(str.data(), str.size());
47 }
48 
49 //----------------------------------------------------------------------------------------------------------------------
54 //----------------------------------------------------------------------------------------------------------------------
55 inline std::string convert(const MString& str)
56 {
57  return std::string(str.asChar(), str.length());
58 }
59 
60 //----------------------------------------------------------------------------------------------------------------------
61 // code to speed up comparisons of MObject guids
62 //----------------------------------------------------------------------------------------------------------------------
63 
66 struct guid
67 {
68  uint8_t uuid[16];
69 };
70 
71 #if AL_MAYA_ENABLE_SIMD
72 
75 struct guid_compare
76 {
77  inline bool operator () (const i128 a, const i128 b) const
78  {
79  const uint32_t lt_mask = movemask16i8(cmplt16i8(a, b));
80  const uint32_t eq_mask = 0xFFFF & (~movemask16i8(cmpeq16i8(a, b)));
81  if(!eq_mask) return false;
82 
83  // find first bit value that is not equal
84  const uint32_t index = __builtin_ctz(eq_mask);
85  // now see whether that bit has been set
86  return (lt_mask & (1 << index)) != 0;
87  }
88 };
89 
90 #else
91 
95 {
100  inline bool operator () (const guid& a, const guid& b) const
101  {
102  for(int i = 0; i < 16; ++i)
103  {
104  if(a.uuid[i] < b.uuid[i]) return true;
105  if(a.uuid[i] > b.uuid[i]) return false;
106  }
107  return false;
108  }
109 };
110 #endif
111 
112 //----------------------------------------------------------------------------------------------------------------------
116 //----------------------------------------------------------------------------------------------------------------------
118 {
122  inline bool insert(const MFnDependencyNode& fn)
123  {
124  #if AL_MAYA_ENABLE_SIMD
125  union
126  {
127  __m128i sse;
128  guid uuid;
129  };
130  fn.uuid().get(uuid.uuid);
131  bool contains = m_nodeMap.find(sse) != m_nodeMap.end();
132  if(!contains)
133  m_nodeMap.insert(std::make_pair(sse, fn.object()));
134  #else
135  guid uuid;
136  fn.uuid().get(uuid.uuid);
137  bool contains = m_nodeMap.find(uuid) != m_nodeMap.end();
138  if(!contains)
139  m_nodeMap.insert(std::make_pair(uuid, fn.object()));
140  #endif
141  return contains;
142  };
143 
147  inline bool contains(const MFnDependencyNode& fn)
148  {
149  #if AL_MAYA_ENABLE_SIMD
150  union
151  {
152  __m128i sse;
153  guid uuid;
154  };
155  fn.uuid().get(uuid.uuid);
156  bool contains = m_nodeMap.find(sse) != m_nodeMap.end();
157  #else
158  guid uuid;
159  fn.uuid().get(uuid.uuid);
160  bool contains = m_nodeMap.find(uuid) != m_nodeMap.end();
161  #endif
162  return contains;
163  };
164 
165 private:
166  #if AL_MAYA_ENABLE_SIMD
167  std::map<i128, MObject, guid_compare> m_nodeMap;
168  #else
169  std::map<guid, MObject, guid_compare> m_nodeMap;
170  #endif
171 };
172 
173 } // usdmaya
174 //----------------------------------------------------------------------------------------------------------------------
175 } // AL
176 //----------------------------------------------------------------------------------------------------------------------
uint8_t uuid[16]
the UUID for a Maya node
Definition: Utils.h:68
bool contains(const MFnDependencyNode &fn)
returns true if the dependency node is in the map
Definition: Utils.h:147
void mapUsdPrimToMayaNode(const UsdPrim &usdPrim, const MObject &mayaObject, const MDagPath *const proxyShapeNode=nullptr)
Captures the mapping of UsdPrim -> Maya Object and stores it into the session layer. usdMayaShapeNode is an optional argument, if it is passed and the passed in mayaObject's path couldnt be determined, then the corresponding maya path is determined using this AL::usdmaya::nodes::ProxyShape and the usdPrim path. It is to get around the delayed creation of nodes using a Modifier.
A type to store a UUID from a maya node.
Definition: Utils.h:66
bool insert(const MFnDependencyNode &fn)
insert a node into the map.
Definition: Utils.h:122
std::string convert(const MString &str)
convert string types
Definition: Utils.h:55
A class that acts as a lookup table for dependency nodes. It works by storing a sorted map based on t...
Definition: Utils.h:117
void matrixToSRT(GfMatrix4d &value, double S[3], MEulerRotation &R, double T[3])
convert a 4x4 matrix to an SRT transformation. Assumes that there is no shearing. ...
Less than comparison utility for sorting via 128bit guid.
Definition: Utils.h:94
bool operator()(const guid &a, const guid &b) const
performs a less than comparison between two UUIDs. Used to sort the entries in an MObjectMap ...
Definition: Utils.h:100