forked from BabylonJS/Exporters
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMayaPlugin.cs
108 lines (93 loc) · 3.33 KB
/
MayaPlugin.cs
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
using Autodesk.Maya.OpenMaya;
using Maya2Babylon.Forms;
using System;
using System.Collections.Generic;
using System.Windows.Forms;
[assembly: MPxCommandClass(typeof(Maya2Babylon.toBabylon), "toBabylon")]
[assembly: ExtensionPlugin(typeof(Maya2Babylon.MayaPlugin), "Any")]
[assembly: MPxCommandClass(typeof(Maya2Babylon.AnimationGroups), "AnimationGroups")]
namespace Maya2Babylon
{
public class MayaPlugin : IExtensionPlugin
{
/// <summary>
/// Path to the Babylon menu
/// </summary>
string MenuPath;
bool IExtensionPlugin.InitializePlugin()
{
// Add menu to main menu bar
MenuPath = MGlobal.executeCommandStringResult($@"menu - parent MayaWindow - label ""Babylon"";");
// Add item to this menu
MGlobal.executeCommand($@"menuItem - label ""Babylon File Exporter..."" - command ""toBabylon"";");
MGlobal.executeCommand($@"menuItem - label ""Animation groups"" - command ""AnimationGroups"";");
MGlobal.displayInfo("Babylon plug-in initialized");
return true;
}
bool IExtensionPlugin.UninitializePlugin()
{
// Remove menu from main menu bar and close the form
MGlobal.executeCommand($@"deleteUI -menu ""{MenuPath}"";");
MGlobal.displayInfo("Babylon plug-in uninitialized");
toBabylon.disposeForm();
return true;
}
string IExtensionPlugin.GetMayaDotNetSdkBuildVersion()
{
String version = "20171207";
return version;
}
}
public class toBabylon : MPxCommand, IMPxCommand
{
private static ExporterForm form;
/// <summary>
/// Entry point of the plug in
/// Write "toBabylon" in the Maya console to start it
/// </summary>
/// <param name="argl"></param>
public override void doIt(MArgList argl)
{
if (form == null)
form = new ExporterForm();
form.Show();
form.BringToFront();
form.WindowState = FormWindowState.Normal;
form.closingByUser = () => { return disposeForm(); };
// TODO - save states - FORM: checkboxes and inputs. MEL: reselected meshes / nodes?
form.closingByShutDown = () => { return disposeForm(); };
// form.closingByCrash = () => { return disposeForm(); };
}
public static bool disposeForm()
{
if (form != null)
{
form.Dispose();
form = null;
}
return true;
}
}
/// <summary>
/// For the animation groups form
/// </summary>
public class AnimationGroups : MPxCommand, IMPxCommand
{
public static AnimationForm animationForm = null;
public override void doIt(MArgList args)
{
if (animationForm == null)
{
animationForm = new AnimationForm();
animationForm.On_animationFormClosed += On_animationFormClosed;
}
animationForm.Show();
animationForm.BringToFront();
animationForm.WindowState = FormWindowState.Normal;
}
private void On_animationFormClosed()
{
animationForm = null;
}
}
}