AL_USDMaya  0.16.6
USD to Maya Bridge
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Common.h
1 #pragma once
2 #include <cstdint>
3 
4 // The plug-in auto-generates a lot of MEL script GUI code in the background. If you want to see the generated
5 // code, set this define to 1
6 #if !defined(AL_MAYA_PRINT_UI_CODE)
7 # define AL_MAYA_PRINT_UI_CODE 0
8 #endif
9 
10 // forward declare maya api types
11 class MAngle;
12 class MArgList;
13 class MArgDatabase;
14 class MBoundingBox;
15 class MColor;
16 class MDagPath;
17 class MDagModifier;
18 class MDataBlock;
19 class MDistance;
20 class MDGModifier;
21 class MEulerRotation;
22 class MFloatPoint;
23 class MFloatVector;
24 class MFloatMatrix;
25 class MMatrix;
26 class MFnDependencyNode;
27 class MFnDagNode;
28 class MFnMesh;
29 class MFnTransform;
30 class MMatrix;
31 class MObject;
32 class MPlug;
33 class MPoint;
34 class MPxData;
35 class MStatus;
36 class MString;
37 class MSyntax;
38 class MTime;
39 class MVector;
40 class MUserData;
41 
42 // forward declare usd types
43 namespace AL {
44 namespace maya {
45 class CommandGuiHelper;
46 class CommandGuiHelperTestCMD;
47 template<typename T> class FileTranslatorBase;
49 class MenuBuilder;
50 class NodeHelper;
51 class NodeHelperUnitTest;
52 class OptionsParser;
53 class Profiler;
55 class ProfilerSectionTag;
56 } // maya
57 } // AL
58 
59 // If you need to modify this file for some reason, you'll notice that I'm using some SSE and AVX2 intrinsics in this file.
60 // If you're not comfortable with SIMD intrinsics, I apologize. The following macro will disable the intrinsics and fallback
61 // to bog standard C++.
62 #if !defined(AL_MAYA_ENABLE_SIMD)
63 # define AL_MAYA_ENABLE_SIMD 1
64 #endif
65 
66 // If neither of these are defined, don't use SIMD at all.
67 #if !defined(__SSE3__) && !defined(__AVX2__)
68 # undef AL_MAYA_ENABLE_SIMD
69 # define AL_MAYA_ENABLE_SIMD 0
70 #endif
71 
75 #define AL_MAYA_CHECK_ERROR(status, ErrorString) { \
76  MStatus _status_##__LINE__ = status; \
77  if (!_status_##__LINE__) \
78  { \
79  MString maya_error_string = __FILE__ ":"; \
80  maya_error_string += __LINE__; \
81  maya_error_string += " "; \
82  maya_error_string += _status_##__LINE__.errorString(); \
83  maya_error_string += " : "; \
84  maya_error_string += ErrorString; \
85  MGlobal::displayError(maya_error_string); \
86  return status; \
87  } }
88 
92 #define AL_MAYA_CHECK_ERROR2(status, ErrorString) { \
93  MStatus _status_##__LINE__ = status; \
94  if ((_status_##__LINE__) != MS::kSuccess) \
95  { \
96  MString maya_error_string = __FILE__ ":"; \
97  maya_error_string += __LINE__; \
98  maya_error_string += " "; \
99  maya_error_string += _status_##__LINE__.errorString(); \
100  maya_error_string += " : "; \
101  maya_error_string += ErrorString; \
102  MGlobal::displayError(maya_error_string); \
103  } }
104 
108 #define AL_MAYA_CHECK_ERROR_RETURN_NULL_MOBJECT(status, ErrorString) { \
109  MStatus _status_##__LINE__ = status; \
110  if (!_status_##__LINE__) \
111  { \
112  MString maya_error_string = __FILE__ ":"; \
113  maya_error_string += __LINE__; \
114  maya_error_string += " "; \
115  maya_error_string += _status_##__LINE__.errorString(); \
116  maya_error_string += " : "; \
117  maya_error_string += ErrorString; \
118  MGlobal::displayError(maya_error_string); \
119  return MObject::kNullObj; \
120  } }
121 
124 #define LAYER_HANDLE_CHECK(X) \
125  if(!X) \
126  std::cout << "Layer is invalid " << __FILE__ << " " << __LINE__ << std::endl;
127 
128 #if AL_GENERATING_DOCS
129 # define AL_MAYA_DECLARE_COMMAND()
132 
136 // name in Maya will be "AL_usdmaya_MyMelCommand"
138 # define AL_MAYA_DEFINE_COMMAND(COMMAND, NAMESPACE)
139 
142 # define AL_MAYA_DECLARE_NODE()
143 
147 // name in Maya will be "AL_usdmaya_MyNode"
149 # define AL_MAYA_DEFINE_NODE(NODE, TYPEID, NAMESPACE)
150 
153 # define AL_MAYA_COMMAND_HELP(database, __helpText)
154 #else
155 # define AL_MAYA_DECLARE_COMMAND() \
156  static const char* const g_helpText; \
157  static void* creator(); \
158  static MSyntax createSyntax(); \
159  static const MString kName;
160 
161 # define AL_MAYA_DEFINE_COMMAND(COMMAND, NAMESPACE) \
162  void* COMMAND :: creator() { return new COMMAND; } \
163  const MString COMMAND :: kName(#NAMESPACE "_" #COMMAND);
164 
165 # define AL_MAYA_DECLARE_NODE() \
166  static void* creator(); \
167  static MStatus initialise(); \
168  static const MString kTypeName; \
169  static const MTypeId kTypeId;
170 
171 # define AL_MAYA_DEFINE_NODE(NODE, TYPEID, NAMESPACE) \
172  void* NODE :: creator() { return new NODE; } \
173  const MString NODE :: kTypeName(#NAMESPACE "_" #NODE); \
174  const MTypeId NODE :: kTypeId(TYPEID);
175 
176 # define AL_MAYA_COMMAND_HELP(database, __helpText) \
177  if(database.isFlagSet("-h")) { \
178  MGlobal::displayInfo( __helpText ); \
179  return MS::kSuccess; \
180  }
181 #endif
182 
185 #define AL_REGISTER_COMMAND(plugin, X) { \
186  MStatus status = plugin.registerCommand( \
187  X ::kName, \
188  X ::creator, \
189  X ::createSyntax); \
190  if(!status) { \
191  status.perror("unable to register command " #X); \
192  return status; \
193  }}
194 
197 #define AL_REGISTER_TRANSLATOR(plugin, X) { \
198  MStatus status = X ::registerTranslator(plugin); \
199  if(!status) { \
200  status.perror("unable to register file translator " #X); \
201  return status; \
202  }}
203 
206 #define AL_REGISTER_DEPEND_NODE(plugin, X){ \
207  MStatus status = plugin.registerNode( \
208  X ::kTypeName, \
209  X ::kTypeId, \
210  X ::creator, \
211  X ::initialise); \
212  if(!status) { \
213  status.perror("unable to register depend node " #X); \
214  return status; \
215  }}
216 
219 #define AL_REGISTER_SHAPE_NODE(plugin, X, UI, DRAW){ \
220  MStatus status = plugin.registerShape( \
221  X ::kTypeName, \
222  X ::kTypeId, \
223  X ::creator, \
224  X ::initialise, \
225  UI ::creator, \
226  &DRAW ::kDrawDbClassification); \
227  if(!status) { \
228  status.perror("unable to register shape node " #X); \
229  return status; \
230  }}
231 
234 #define AL_REGISTER_TRANSFORM_NODE(plugin, NODE, MATRIX){ \
235  MStatus status = plugin.registerTransform( \
236  NODE ::kTypeName, \
237  NODE ::kTypeId, \
238  NODE ::creator, \
239  NODE ::initialise, \
240  MATRIX ::creator, \
241  MATRIX ::kTypeId); \
242  if(!status) { \
243  status.perror("unable to register transform node " #NODE); \
244  return status; \
245  }}
246 
249 #define AL_REGISTER_DATA(plugin, X){ \
250  MStatus status = plugin.registerData( \
251  X ::kName, \
252  X ::kTypeId, \
253  X ::creator); \
254  if(!status) { \
255  status.perror("unable to register data " #X); \
256  return status; \
257  }}
258 
261 #define AL_REGISTER_DRAW_OVERRIDE(plugin, X) { \
262  MStatus status = MHWRender::MDrawRegistry::registerDrawOverrideCreator( \
263  X ::kDrawDbClassification, \
264  X ::kDrawRegistrantId, \
265  X ::creator); \
266  if (!status) { \
267  status.perror("unable to register draw override " #X); \
268  return status; \
269  }}
270 
273 #define AL_UNREGISTER_COMMAND(plugin, X) { \
274  MStatus status = plugin.deregisterCommand(X ::kName); \
275  if (!status) { \
276  status.perror("deregisterCommand AL::usdmaya::" #X); \
277  return status; \
278  }}
279 #define AL_UNREGISTER_NODE(plugin, X) { \
282  MStatus status = plugin.deregisterNode(X ::kTypeId); \
283  if (!status) { \
284  status.perror("deregisterNode AL::usdmaya::" #X); \
285  return status; \
286  }}
287 #define AL_UNREGISTER_DATA(plugin, X) {\
290  MStatus status = plugin.deregisterData(X ::kTypeId); \
291  if (!status) { \
292  status.perror("deregisterData AL::usdmaya::" #X); \
293  return status; \
294  }}
295 #define AL_UNREGISTER_TRANSLATOR(plugin, X) {\
298  MStatus status = X ::deregisterTranslator(plugin); \
299  if(!status) { \
300  status.perror("deregisterTranslator AL::usdmaya::" #X); \
301  return status; \
302  }}
303 #define AL_UNREGISTER_DRAW_OVERRIDE(plugin, X) { \
306  MStatus status = MHWRender::MDrawRegistry::deregisterDrawOverrideCreator( \
307  X ::kDrawDbClassification, \
308  X ::kDrawRegistrantId); \
309  if (!status) { \
310  status.perror("deregisterDrawOverrideCreator " #X); \
311  return status; \
312  }}
313 
This class implements a very simple incode profiler. This profiler is NOT thread safe. It is mainly used to get some basic stats on the where the bottlenecks are during a file import/export operation. A simple example of usage:
Definition: CodeTimings.h:168
Utility class that constructs the file translator export GUI from the export options you want to supp...
Definition: FileTranslatorOptions.h:148
Utility class that parses the file translator options passed through by Maya.
Definition: FileTranslatorOptions.h:17
A utility class that provides a 'unique' base class to derive new translator from.
Definition: Common.h:47
This class provides a static hash that should be unique for a line within a specific function...
Definition: CodeTimings.h:22
This class represents a path made up of ProfilerSectionTag's. It is used so that we can distinguish b...
Definition: CodeTimings.h:84
You shouldn't need to care about this class (sort of). Probably the only thing you'll want to do is e...
Definition: MenuBuilder.h:39
This is a little helper object designed to reduce the amount of boilerplate GUI code you need to jump...
Definition: NodeHelper.h:175