AL_USDMaya  0.29.4
USD to Maya Bridge
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
PluginRegister.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 "pxr/pxr.h"
18 #include "pxr/imaging/glf/glew.h"
19 #include "AL/maya/utils/CommandGuiHelper.h"
20 #include "AL/maya/utils/MenuBuilder.h"
21 #include "AL/usdmaya/Global.h"
22 #include "AL/usdmaya/StageData.h"
23 #include "AL/usdmaya/DrivenTransformsData.h"
24 #include "AL/usdmaya/cmds/CreateUsdPrim.h"
25 #include "AL/usdmaya/cmds/DebugCommands.h"
26 #include "AL/usdmaya/cmds/EventCommand.h"
27 #include "AL/usdmaya/cmds/LayerCommands.h"
28 #include "AL/usdmaya/cmds/ProxyShapeCommands.h"
29 #include "AL/usdmaya/cmds/ProxyShapeSelectCommands.h"
30 #include "AL/usdmaya/cmds/RendererCommands.h"
31 #include "AL/usdmaya/cmds/UnloadPrim.h"
32 #include "AL/usdmaya/fileio/Export.h"
33 #include "AL/usdmaya/fileio/ExportTranslator.h"
34 #include "AL/usdmaya/fileio/Import.h"
35 #include "AL/usdmaya/fileio/ImportTranslator.h"
36 #include "AL/usdmaya/nodes/Layer.h"
37 #include "AL/usdmaya/nodes/LayerManager.h"
38 #include "AL/usdmaya/nodes/ProxyDrawOverride.h"
39 #include "AL/usdmaya/nodes/ProxyShape.h"
40 #include "AL/usdmaya/nodes/ProxyShapeUI.h"
41 #include "AL/usdmaya/nodes/RendererManager.h"
42 #include "AL/usdmaya/nodes/Transform.h"
43 #include "AL/usdmaya/nodes/TransformationMatrix.h"
44 
45 #include "maya/MDrawRegistry.h"
46 #include "maya/MGlobal.h"
47 #include "maya/MStatus.h"
48 
49 PXR_NAMESPACE_USING_DIRECTIVE
50 
51 namespace AL {
52 namespace usdmaya {
53 
54 //----------------------------------------------------------------------------------------------------------------------
60 //----------------------------------------------------------------------------------------------------------------------
61 template<typename AFnPlugin>
62 MStatus registerPlugin(AFnPlugin& plugin)
63 {
64  GlfGlewInit();
65 
66  if(!MGlobal::optionVarExists("AL_usdmaya_selectMode"))
67  {
68  MGlobal::setOptionVarValue("AL_usdmaya_selectMode", 0);
69  }
70 
71  if(!MGlobal::optionVarExists("AL_usdmaya_selectResolution"))
72  {
73  MGlobal::setOptionVarValue("AL_usdmaya_selectResolution", 10);
74  }
75 
76  if(!MGlobal::optionVarExists("AL_usdmaya_pickMode"))
77  {
78  MGlobal::setOptionVarValue("AL_usdmaya_pickMode", static_cast<int>(nodes::ProxyShape::PickMode::kPrims));
79  }
80 
81  MStatus status;
82 
83  // gpuCachePluginMain used as an example.
84  if (MGlobal::kInteractive == MGlobal::mayaState()) {
85  const auto otherPriority = MSelectionMask::getSelectionTypePriority("polymesh");
86  if (!MSelectionMask::registerSelectionType(AL::usdmaya::nodes::ProxyShape::s_selectionMaskName, otherPriority)) {
87  status.perror("Error registering selection mask!");
88  return MS::kFailure;
89  }
90 
91  MString cmd = "addSelectTypeItem(\"Surface\",\"";
92  cmd += AL::usdmaya::nodes::ProxyShape::s_selectionMaskName;
93  cmd += "\",\"";
94  cmd += "AL Proxy Shape";
95  cmd += "\")";
96 
97  status = MGlobal::executeCommand(cmd);
98  if (!status) {
99  status.perror("Error adding al_ProxyShape selection type!");
100  return status;
101  }
102  }
103 
104  AL_REGISTER_DATA(plugin, AL::usdmaya::StageData);
105  AL_REGISTER_DATA(plugin, AL::usdmaya::DrivenTransformsData);
106  AL_REGISTER_COMMAND(plugin, AL::maya::utils::CommandGuiListGen);
107  AL_REGISTER_COMMAND(plugin, AL::usdmaya::cmds::CreateUsdPrim);
108  AL_REGISTER_COMMAND(plugin, AL::usdmaya::cmds::LayerCreateLayer);
109  AL_REGISTER_COMMAND(plugin, AL::usdmaya::cmds::LayerGetLayers);
110  AL_REGISTER_COMMAND(plugin, AL::usdmaya::cmds::LayerCurrentEditTarget);
111  AL_REGISTER_COMMAND(plugin, AL::usdmaya::cmds::LayerSave);
112  AL_REGISTER_COMMAND(plugin, AL::usdmaya::cmds::LayerSetMuted);
113  AL_REGISTER_COMMAND(plugin, AL::usdmaya::cmds::ManageRenderer);
114  AL_REGISTER_COMMAND(plugin, AL::usdmaya::cmds::ProxyShapeImport);
115  AL_REGISTER_COMMAND(plugin, AL::usdmaya::cmds::ProxyShapeFindLoadable);
116  AL_REGISTER_COMMAND(plugin, AL::usdmaya::cmds::ProxyShapeImportAllTransforms);
117  AL_REGISTER_COMMAND(plugin, AL::usdmaya::cmds::ProxyShapeRemoveAllTransforms);
118  AL_REGISTER_COMMAND(plugin, AL::usdmaya::cmds::ProxyShapeResync);
119  AL_REGISTER_COMMAND(plugin, AL::usdmaya::cmds::ProxyShapeImportPrimPathAsMaya);
120  AL_REGISTER_COMMAND(plugin, AL::usdmaya::cmds::ProxyShapePrintRefCountState);
121  AL_REGISTER_COMMAND(plugin, AL::usdmaya::cmds::ChangeVariant);
122  AL_REGISTER_COMMAND(plugin, AL::usdmaya::cmds::ActivatePrim);
123  AL_REGISTER_COMMAND(plugin, AL::usdmaya::cmds::ProxyShapeSelect);
124  AL_REGISTER_COMMAND(plugin, AL::usdmaya::cmds::ProxyShapePostSelect);
125  AL_REGISTER_COMMAND(plugin, AL::usdmaya::cmds::InternalProxyShapeSelect);
126  AL_REGISTER_COMMAND(plugin, AL::usdmaya::cmds::UsdDebugCommand);
127  AL_REGISTER_COMMAND(plugin, AL::usdmaya::cmds::ListEvents);
128  AL_REGISTER_COMMAND(plugin, AL::usdmaya::cmds::ListCallbacks);
129  AL_REGISTER_COMMAND(plugin, AL::usdmaya::cmds::Callback);
130  AL_REGISTER_COMMAND(plugin, AL::usdmaya::cmds::TriggerEvent);
131  AL_REGISTER_COMMAND(plugin, AL::usdmaya::cmds::DeleteCallbacks);
132  AL_REGISTER_COMMAND(plugin, AL::usdmaya::cmds::CallbackQuery);
133  AL_REGISTER_COMMAND(plugin, AL::usdmaya::cmds::Event);
134  AL_REGISTER_COMMAND(plugin, AL::usdmaya::cmds::EventQuery);
135  AL_REGISTER_COMMAND(plugin, AL::usdmaya::cmds::EventLookup);
136  AL_REGISTER_COMMAND(plugin, AL::usdmaya::cmds::TranslatePrim);
137  AL_REGISTER_COMMAND(plugin, AL::usdmaya::cmds::LayerManager);
138  AL_REGISTER_COMMAND(plugin, AL::usdmaya::fileio::ImportCommand);
139  AL_REGISTER_COMMAND(plugin, AL::usdmaya::fileio::ExportCommand);
140  AL_REGISTER_TRANSLATOR(plugin, AL::usdmaya::fileio::ImportTranslator);
141  AL_REGISTER_TRANSLATOR(plugin, AL::usdmaya::fileio::ExportTranslator);
142  AL_REGISTER_DRAW_OVERRIDE(plugin, AL::usdmaya::nodes::ProxyDrawOverride);
144  AL_REGISTER_TRANSFORM_NODE(plugin, AL::usdmaya::nodes::Transform, AL::usdmaya::nodes::TransformationMatrix);
145  AL_REGISTER_DEPEND_NODE(plugin, AL::usdmaya::nodes::RendererManager);
146  AL_REGISTER_DEPEND_NODE(plugin, AL::usdmaya::nodes::Layer);
147  // Since AL_MAYA_DECLARE_NODE / AL_MAYA_DEFINE_NODE declare/define "creator"
148  // method, and AL_REGISTER_DEPEND_NODE registers "creator", in order to
149  // define custom creator, need to either 'override' one of those... chose to
150  // replace AL_REGISTER_DEPEND_NODE
151  //AL_REGISTER_DEPEND_NODE(plugin, AL::usdmaya::nodes::LayerManager);
152  {
153  MStatus status = plugin.registerNode(
154  AL::usdmaya::nodes::LayerManager::kTypeName,
155  AL::usdmaya::nodes::LayerManager::kTypeId,
157  AL::usdmaya::nodes::LayerManager::initialise);
158  if(!status) {
159  status.perror("unable to register depend node LayerManager");
160  return status;
161  }
162  }
163 
164  // generate the menu GUI + option boxes
167  AL::usdmaya::cmds::constructDebugCommandGuis();
170 
171  CHECK_MSTATUS(AL::maya::utils::MenuBuilder::generatePluginUI(plugin, "AL_usdmaya"));
173  return status;
174 }
175 
176 //----------------------------------------------------------------------------------------------------------------------
182 //----------------------------------------------------------------------------------------------------------------------
183 template<typename AFnPlugin>
184 MStatus unregisterPlugin(AFnPlugin& plugin)
185 {
186  MStatus status;
187 
188  // gpuCachePluginMain used as an example.
189  if (MGlobal::kInteractive == MGlobal::mayaState()) {
190  MString cmd = "deleteSelectTypeItem(\"Surface\",\"";
191  cmd += AL::usdmaya::nodes::ProxyShape::s_selectionMaskName;
192  cmd += "\")";
193 
194  status = MGlobal::executeCommand(cmd);
195  if (!status) {
196  status.perror("Error removing al_ProxyShape selection type!");
197  return status;
198  }
199 
200  if (!MSelectionMask::deregisterSelectionType(AL::usdmaya::nodes::ProxyShape::s_selectionMaskName)) {
201  status.perror("Error deregistering selection mask!");
202  return MS::kFailure;
203  }
204  }
205 
206  AL_UNREGISTER_COMMAND(plugin, AL::maya::utils::CommandGuiListGen);
207  AL_UNREGISTER_COMMAND(plugin, AL::usdmaya::cmds::InternalProxyShapeSelect);
208  AL_UNREGISTER_COMMAND(plugin, AL::usdmaya::cmds::ProxyShapePostSelect);
209  AL_UNREGISTER_COMMAND(plugin, AL::usdmaya::cmds::ProxyShapeSelect);
210  AL_UNREGISTER_COMMAND(plugin, AL::usdmaya::cmds::ActivatePrim);
211  AL_UNREGISTER_COMMAND(plugin, AL::usdmaya::cmds::ChangeVariant);
212  AL_UNREGISTER_COMMAND(plugin, AL::usdmaya::cmds::LayerCreateLayer);
213  AL_UNREGISTER_COMMAND(plugin, AL::usdmaya::cmds::LayerCurrentEditTarget);
214  AL_UNREGISTER_COMMAND(plugin, AL::usdmaya::cmds::LayerGetLayers);
215  AL_UNREGISTER_COMMAND(plugin, AL::usdmaya::cmds::LayerSave);
216  AL_UNREGISTER_COMMAND(plugin, AL::usdmaya::cmds::LayerSetMuted);
217  AL_UNREGISTER_COMMAND(plugin, AL::usdmaya::cmds::ManageRenderer);
218  AL_UNREGISTER_COMMAND(plugin, AL::usdmaya::cmds::ProxyShapeImport);
219  AL_UNREGISTER_COMMAND(plugin, AL::usdmaya::cmds::ProxyShapeFindLoadable);
220  AL_UNREGISTER_COMMAND(plugin, AL::usdmaya::cmds::ProxyShapeImportAllTransforms);
221  AL_UNREGISTER_COMMAND(plugin, AL::usdmaya::cmds::ProxyShapeRemoveAllTransforms);
222  AL_UNREGISTER_COMMAND(plugin, AL::usdmaya::cmds::ProxyShapeResync);
223  AL_UNREGISTER_COMMAND(plugin, AL::usdmaya::cmds::ProxyShapeImportPrimPathAsMaya);
224  AL_UNREGISTER_COMMAND(plugin, AL::usdmaya::cmds::ProxyShapePrintRefCountState);
225  AL_UNREGISTER_COMMAND(plugin, AL::usdmaya::cmds::Callback);
226  AL_UNREGISTER_COMMAND(plugin, AL::usdmaya::cmds::ListCallbacks);
227  AL_UNREGISTER_COMMAND(plugin, AL::usdmaya::cmds::ListEvents);
228  AL_UNREGISTER_COMMAND(plugin, AL::usdmaya::cmds::TriggerEvent);
229  AL_UNREGISTER_COMMAND(plugin, AL::usdmaya::cmds::DeleteCallbacks);
230  AL_UNREGISTER_COMMAND(plugin, AL::usdmaya::cmds::CallbackQuery);
231  AL_UNREGISTER_COMMAND(plugin, AL::usdmaya::cmds::Event);
232  AL_UNREGISTER_COMMAND(plugin, AL::usdmaya::cmds::EventQuery);
233  AL_UNREGISTER_COMMAND(plugin, AL::usdmaya::cmds::EventLookup);
234  AL_UNREGISTER_COMMAND(plugin, AL::usdmaya::cmds::UsdDebugCommand);
235  AL_UNREGISTER_COMMAND(plugin, AL::usdmaya::fileio::ImportCommand);
236  AL_UNREGISTER_COMMAND(plugin, AL::usdmaya::fileio::ExportCommand);
237  AL_UNREGISTER_COMMAND(plugin, AL::usdmaya::cmds::TranslatePrim);
238  AL_UNREGISTER_COMMAND(plugin, AL::usdmaya::cmds::LayerManager);
239  AL_UNREGISTER_COMMAND(plugin, AL::usdmaya::cmds::CreateUsdPrim);
240  AL_UNREGISTER_TRANSLATOR(plugin, AL::usdmaya::fileio::ImportTranslator);
241  AL_UNREGISTER_TRANSLATOR(plugin, AL::usdmaya::fileio::ExportTranslator);
242  AL_UNREGISTER_DRAW_OVERRIDE(plugin, AL::usdmaya::nodes::ProxyDrawOverride);
243  AL_UNREGISTER_NODE(plugin, AL::usdmaya::nodes::ProxyShape);
244  AL_UNREGISTER_NODE(plugin, AL::usdmaya::nodes::Transform);
245  AL_UNREGISTER_NODE(plugin, AL::usdmaya::nodes::RendererManager);
246  AL_UNREGISTER_NODE(plugin, AL::usdmaya::nodes::Layer);
247  AL_UNREGISTER_NODE(plugin, AL::usdmaya::nodes::LayerManager);
248  AL_UNREGISTER_DATA(plugin, AL::usdmaya::DrivenTransformsData);
249  AL_UNREGISTER_DATA(plugin, AL::usdmaya::StageData);
250 
252  return status;
253 }
254 
255 #undef AL_RUN_TESTS
256 
257 //----------------------------------------------------------------------------------------------------------------------
258 } // usdmaya
259 } // AL
260 //----------------------------------------------------------------------------------------------------------------------
static AL_USDMAYA_PUBLIC void * conditionalCreator()
Creates the node, but only if there is not a non-referenced one in the scene already.
Given some selected proxy shape node, return the layer names.
Definition: LayerCommands.h:75
ProxyShapeResync.
Definition: ProxyShapeCommands.h:200
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:244
A command that lists the events available on either a particular node, or the global set of events...
Definition: EventCommand.h:117
static AL_USDMAYA_PUBLIC void onPluginLoad()
initialise the global state
A command that allows you to register and unregister new Event types from script. ...
Definition: EventCommand.h:54
ProxyShapeSelect.
Definition: ProxyShapeCommands.h:240
ProxyShapeSelect.
Definition: ProxyShapeCommands.h:220
Get / Set renderer plugin settings.
Definition: RendererCommands.h:39
MStatus registerPlugin(AFnPlugin &plugin)
This method is basically the main initializePlugin routine. The reason for it being a template is sim...
Definition: PluginRegister.h:62
TranslatePrim.
Definition: ProxyShapeCommands.h:278
A command that allows you to query information about a specific event.
Definition: EventCommand.h:74
AL_USDMAYA_PUBLIC void constructProxyShapeCommandGuis()
This function will generate all of the MEL script menus, and the option boxes, for all of the proxy s...
The layer manager node handles serialization and deserialization of all layers used by all ProxyShape...
Definition: RendererManager.h:43
InternalProxyShapeSelect.
Definition: ProxyShapeCommands.h:258
The UI component of the proxy shape node.
Definition: ProxyShapeUI.h:31
Get / Set whether the layer is currently muted.
Definition: LayerCommands.h:168
A command that allows you to register and unregister new Event types from script. ...
Definition: CreateUsdPrim.h:34
This code is effectively copied from the pixar plugin. It's just used to pass the usd stage through t...
Definition: StageData.h:36
This class provides the draw override for the USD proxy shape node.
Definition: ProxyDrawOverride.h:44
A command to activate / deactivate a prim - just a maya convenience wrapper around USD functionality...
Definition: UnloadPrim.h:56
A thin MEL command layer that just wraps the AL::usdmaya::fileio::Export process. ...
Definition: Export.h:96
A command that lists the events available on either a particular node, or the global set of events...
Definition: EventCommand.h:176
ProxyShapeFindLoadable.
Definition: ProxyShapeCommands.h:101
This class provides a transformation matrix that allows you to apply tweaks over some read only trans...
Definition: TransformationMatrix.h:41
Given some selected or passed in proxy shape node, create a layer in maya parented to the layer match...
Definition: LayerCommands.h:91
The AL::usdmaya::nodes::Transform node is a custom transform node that allows you to manipulate a USD...
Definition: Transform.h:83
A command that allows you to create / delete callbacks assigned to a specific event within AL_usdmaya...
Definition: EventCommand.h:100
The layer manager node handles serialization and deserialization of all layers used by all ProxyShape...
Definition: LayerManager.h:232
A command to import a USD file into Maya (partially supporting Animal Logic specific things) ...
Definition: Import.h:70
Imports a proxy shape into maya.
Definition: ProxyShapeCommands.h:79
Command to introspect and pull out data from the layer manager.
Definition: LayerCommands.h:186
The driven transform data passed through the DG.
Definition: DrivenTransformsData.h:40
ProxyShapePrintRefCountState.
Definition: ProxyShapeCommands.h:186
A command that lists the events available on either a particular node, or the global set of events...
Definition: EventCommand.h:162
MStatus unregisterPlugin(AFnPlugin &plugin)
This method is basically the main uninitializePlugin routine. The reason for it being a template is s...
Definition: PluginRegister.h:184
ProxyShapeImportAllTransforms From a proxy shape, this will import all usdPrims in the stage as AL_us...
Definition: ProxyShapeCommands.h:116
A command that allows you to query information about an event.
Definition: EventCommand.h:87
Save the specified layer.
Definition: LayerCommands.h:115
A command that will trigger all callbacks on an event.
Definition: EventCommand.h:131
The layer node stores a reference to an SdfLayer. Obsolete. LayerManager now used instead...
Definition: Layer.h:39
AL_USDMAYA_PUBLIC void constructRendererCommandGuis()
function called on startup to generate the menu & option boxes for the layer commands ...
A command to force a variant switch - just a maya convenience wrapper around USD functionality.
Definition: UnloadPrim.h:42
A command that allows you to query and modify the current status of the TfDebug symbols.
Definition: DebugCommands.h:37
ProxyShapeImportPrimPathAsMaya A command that will import a portion of a proxyNode as Maya geometry/t...
Definition: ProxyShapeCommands.h:153
AL_USDMAYA_PUBLIC void constructLayerCommandGuis()
function called on startup to generate the menu & option boxes for the layer commands ...
Get / Set the current edit target for the stage.
Definition: LayerCommands.h:143
static AL_USDMAYA_PUBLIC void onPluginUnload()
uninitialise the global state
A command that will delete all callback ids specified as an argument.
Definition: EventCommand.h:145
ProxyShapeRemoveAllTransforms A command that will remove all AL::usdmaya::nodes::Transform nodes from...
Definition: ProxyShapeCommands.h:135
AL_USDMAYA_PUBLIC void constructPickModeCommandGuis()
Construct menu and commands for setting pick modes.