-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPluginMain.cpp
More file actions
146 lines (119 loc) · 3.67 KB
/
PluginMain.cpp
File metadata and controls
146 lines (119 loc) · 3.67 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include <maya/MFnPlugin.h>
#include <maya/MGlobal.h>
#include <maya/MApiNamespace.h>
#include <maya/MViewport2Renderer.h>
#include <maya/MDrawRegistry.h>
#include <stdio.h>
// nodes
#include "PartioEmitter.h"
#include "PartioVisualizer.h"
#include "PartioVisualizerDrawOverride.h"
bool RegisterPluginUI()
{
// Create menu
MGlobal::executeCommand(MString("string $mpt_root_menu = `menu -l \"Partio Tools\" -p MayaWindow -allowOptionBoxes true`"));
MGlobal::executeCommand(MString("menuItem -label \"Create visualizer node\" -command \"createPartioVisualizer()\""));
MGlobal::executeCommand(MString("menuItem -label \"Create emitter node\" -command \"createPartioEmitter()\""));
return true;
}
bool DeregisterPluginUI()
{
MGlobal::executeCommand(MString("deleteUI -m $mpt_root_menu"));
// delete template editors
MGlobal::executeCommand(MString("MPT_RemoveEditorTemplate(\"PartioEmitterNode\")"));
MGlobal::executeCommand(MString("MPT_RemoveEditorTemplate(\"PartioVisualizerNode\")"));
return true;
}
MStatus initializePlugin(MObject obj)
{
MStatus status;
MFnPlugin plugin(obj, "Jan Bender", "1.0", "Any");
MString pluginPath = plugin.loadPath();
MString scriptPath = pluginPath + "/scripts";
// add path of plugin to script path
#ifdef WIN32
MGlobal::executeCommand(MString("$s=`getenv \"MAYA_SCRIPT_PATH\"`; putenv \"MAYA_SCRIPT_PATH\" ($s + \";") + scriptPath + "\")");
#else
MGlobal::executeCommand(MString("$s=`getenv \"MAYA_SCRIPT_PATH\"`; putenv \"MAYA_SCRIPT_PATH\" ($s + \":") + scriptPath + "\")");
#endif
// execute the specified mel script
status = MGlobal::sourceFile("MayaPartioTools.mel");
if (MGlobal::mayaState() == MGlobal::kInteractive)
{
MHWRender::MRenderer* renderer = MHWRender::MRenderer::theRenderer();
if (renderer != 0 && renderer->drawAPIIsOpenGL())
{
PartioVisualizerDrawOverride::initShaders(scriptPath);
}
}
status = plugin.registerNode("PartioVisualizerNode", PartioVisualizer::id,
&PartioVisualizer::creator, &PartioVisualizer::initialize,
MPxNode::kLocatorNode, &PartioVisualizer::drawDbClassification);
if (!status)
{
status.perror("register PartioVisualizer");
return status;
}
status = MHWRender::MDrawRegistry::registerDrawOverrideCreator(
PartioVisualizer::drawDbClassification,
"PartioVisualizerDrawOverride",
PartioVisualizerDrawOverride::creator);
if (!status)
{
status.perror("register PartioVisualizerDrawOverride");
return status;
}
status = plugin.registerNode("PartioEmitterNode", PartioEmitter::m_id,
&PartioEmitter::creator, &PartioEmitter::initialize,
MPxNode::kEmitterNode);
if (!status)
{
status.perror("register PartioEmitter");
return status;
}
if (!RegisterPluginUI())
{
status.perror("Failed to create UI");
return status;
}
return status;
}
MStatus uninitializePlugin(MObject obj)
{
MStatus status;
MFnPlugin plugin(obj);
status = plugin.deregisterNode(PartioVisualizer::id);
if (!status)
{
status.perror("deregister PartioVisualizer");
return status;
}
status = MHWRender::MDrawRegistry::deregisterDrawOverrideCreator(
PartioVisualizer::drawDbClassification,
"PartioVisualizerDrawOverride");
if (!status)
{
status.perror("deregister PartioVisualizerDrawOverride");
return status;
}
if (MGlobal::mayaState() == MGlobal::kInteractive)
{
MHWRender::MRenderer* renderer = MHWRender::MRenderer::theRenderer();
if (renderer != 0 && renderer->drawAPIIsOpenGL())
{
PartioVisualizerDrawOverride::deleteShaders();
}
}
status = plugin.deregisterNode(PartioEmitter::m_id);
if (!status)
{
status.perror("deregister PartioEmitter");
return status;
}
if (!DeregisterPluginUI())
{
status.perror("Failed to deregister UI");
return status;
}
return status;
}