-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpluginMain.cpp
More file actions
128 lines (104 loc) · 3.64 KB
/
pluginMain.cpp
File metadata and controls
128 lines (104 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <maya/MGlobal.h>
#include <maya/MFnPlugin.h>
#include <maya/MStatus.h>
#include <maya/MDrawRegistry.h>
#include <maya/MSwatchRenderRegister.h>
#include "mayato.h"
#include "mt_common/mt_renderGlobalsNode.h"
#include "swatchesRenderer/swatchRenderer.h"
#include "swatchesRenderer/NewSwatchRenderer.h"
#include "utilities/tools.h"
#include "threads/renderQueueWorker.h"
#include "world.h"
#include "mt/version.h"
#if MAYA_API_VERSION >= 201600
#include "mt_common/mt_mayaRenderer.h"
#endif
static const MString swatchName("MayaToRenderSwatch");
static const MString swatchFullName("swatch/MayaToRenderSwatch");
static const MString asDisneyMaterialId("asDisneyMaterialId");
static const MString asDisneyMaterialIdDrawDBClassification("drawdb/shader/surface/asDisneyMaterialId");
static const MString asDisneyMaterialIdFullClassification("shader/surface:MayaTo/material:" + swatchFullName + ":" + asDisneyMaterialIdDrawDBClassification);
MStatus initializePlugin( MObject obj )
{
for (auto versionElement : getFullVersionString())
MGlobal::displayInfo(versionElement.c_str());
MStatus status;
MFnPlugin plugin( obj, VENDOR, getFullVersionString()[0].c_str(), "Any");
status = plugin.registerCommand(MAYATOCMDNAME, MayaToCmd::creator, MayaToCmd::newSyntax);
if (!status) {
status.perror("cannot register command: mayato");
return status;
}
status = plugin.registerNode(MayaToGlobalsName, MayaToGlobals::id, MayaToGlobals::creator, MayaToGlobals::initialize);
if (!status) {
status.perror("cannot register node: MayaToGlobals");
return status;
}
//MString command( "if( `window -exists createRenderNodeWindow` ) {refreshCreateRenderNodeWindow(\"" );
//command += UserClassify;
//command += "\");}\n";
//MGlobal::executeCommand( command );
setRendererName("MayaTo");
setRendererShortCutName("mt");
setRendererHome(getenv("mt_HOME"));
MString cmd = MString("import MayaTo.mt_initialize as minit; minit.initRenderer()");
MGlobal::displayInfo("try to register...");
status = MGlobal::executePythonCommand(cmd, true, false);
if(!status)
{
status.perror("Problem executing cmd: mt_initialize.initRenderer()");
return status;
}
MayaTo::defineWorld();
MString loadPath = plugin.loadPath();
MayaTo::getWorldPtr()->shaderSearchPath.append(loadPath);
if (MGlobal::mayaState() != MGlobal::kBatch)
{
MSwatchRenderRegister::registerSwatchRender(swatchName, NewSwatchRenderer::creator);
}
#if MAYA_API_VERSION >= 201600
status = plugin.registerRenderer("MayaTo", mt_MayaRenderer::creator);
if (!status) {
status.perror("cannot register node: MayaTo Maya renderer");
return status;
}
#endif
return status;
}
MStatus uninitializePlugin( MObject obj)
{
MStatus status;
MFnPlugin plugin( obj );
MayaTo::deleteWorld();
std::cout << "deregister mt cmd\n";
status = plugin.deregisterCommand( MAYATOCMDNAME );
if (!status) {
status.perror("cannot deregister command: MayaToCmd");
return status;
}
if (MGlobal::mayaState() != MGlobal::kBatch)
MSwatchRenderRegister::unregisterSwatchRender(swatchName);
#if MAYA_API_VERSION >= 201600
status = plugin.deregisterRenderer("MayaTo");
if (!status) {
status.perror("cannot deregister node: Maya renderer");
return status;
}
#endif
std::cout << "deregister mt globals\n";
status = plugin.deregisterNode( MayaToGlobals::id );
if (!status) {
status.perror("cannot deregister node: MayaToGlobals");
return status;
}
std::cout << "minit.unregister()\n";
MString cmd = MString("import mt_initialize as minit; minit.unregister()");
status = MGlobal::executePythonCommand(cmd);
if(!status)
{
status.perror("Problem executing cmd: mt_initialize.unregister()");
return status;
}
return status;
}