-
Notifications
You must be signed in to change notification settings - Fork 314
/
Copy pathLoader.cs
157 lines (134 loc) · 4.87 KB
/
Loader.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
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
146
147
148
149
150
151
152
153
154
155
156
157
using Autodesk.Maya.OpenMaya;
using System;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Maya2Babylon
{
class Loader
{
static MGlobal global;
public static MGlobal Global
{
get
{
return global;
}
}
public static int GetMinTime()
{
MGlobal.executeCommand("playbackOptions -q -animationStartTime", out double minTime);
return (int)minTime;
}
public static int GetMaxTime()
{
MGlobal.executeCommand("playbackOptions -q -animationEndTime", out double maxTime);
return (int)maxTime;
}
public static double GetCurrentTime()
{
MGlobal.executeCommand("currentTime -q", out double currentTime);
return currentTime;
}
public static double SetCurrentTime(double time)
{
MGlobal.executeCommand($"currentTime {time.ToString(System.Globalization.CultureInfo.InvariantCulture)}", out double currentTime);
return currentTime;
}
public static int GetFPS()
{
MGlobal.executeCommand("currentTimeUnitToFPS", out double framePerSecond);
return (int)framePerSecond;
}
/// <summary>
/// Using MEL command, it return the visibility of a Maya object.
/// </summary>
/// <param name="objectFullPathName">The name of the Maya object</param>
/// <returns>
/// 0 if invisible
/// 1 if visible
/// </returns>
public static float GetVisibility(string objectFullPathName)
{
MGlobal.executeCommand($"getAttr {objectFullPathName}.visibility", out double visibility);
return (float)visibility;
}
/// <summary>
/// Using MEL command, it return the visibility of a Maya object at a specific frame.
/// </summary>
/// <param name="objectFullPathName">The name of the Maya object</param>
/// <param name="currentFrame">The frame to use</param>
/// <returns>
/// 0 if invisible
/// 1 if visible
/// </returns>
public static float GetVisibility(string objectFullPathName, int currentFrame)
{
MGlobal.executeCommand($"getAttr -t {currentFrame} {objectFullPathName}.visibility", out double visibility);
return (float)visibility;
}
/// <summary>
/// Mthodes to load/save data from/in the maya file
/// </summary>
///
private static char separator = ';';
public static string[] GetStringArrayProperty(string property)
{
string value = "";
string[] values = { };
if(GetUserPropString(property, ref value))
{
values = value.Split(separator);
}
return values;
}
public static void SetStringArrayProperty(string property, List<string> values)
{
string value = string.Join(separator.ToString(), values);
SetStringProperty(property, value);
}
internal static bool GetUserPropString(string property, ref string value)
{
MCommandResult result = new MCommandResult();
MGlobal.executeCommand($"fileInfo -q \"{property}\"", result);
if (result.resultType == MCommandResult.Type.kStringArray)
{
MStringArray stringArray = new MStringArray();
result.getResult(stringArray);
value = string.Join("", stringArray.ToArray());
}
else
{
value = null;
}
return !string.IsNullOrEmpty(value);
}
internal static void SetStringProperty(string property, string value)
{
MGlobal.executeCommand($"fileInfo \"{property}\" \"{value}\"");
}
public static void DeleteProperty(string property)
{
MGlobal.executeCommand($"fileInfo -remove \"{property}\"");
}
internal static bool GetBoolProperty(string property, bool defaultValue = false)
{
bool value = defaultValue;
MCommandResult result = new MCommandResult();
MGlobal.executeCommand($"fileInfo -q \"{property}\"", result);
if (result.resultType == MCommandResult.Type.kStringArray)
{
MStringArray stringArray = new MStringArray();
result.getResult(stringArray);
value = string.Join("", stringArray.ToArray()).Equals(true.ToString());
}
return value;
}
internal static void SetBoolProperty(string property, bool value)
{
SetStringProperty(property, value.ToString());
}
}
}