-
Notifications
You must be signed in to change notification settings - Fork 308
/
BabylonExporter.Logger.cs
210 lines (189 loc) · 8.63 KB
/
BabylonExporter.Logger.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
using Autodesk.Max;
using System;
using System.Drawing;
namespace Max2Babylon
{
internal partial class BabylonExporter
{
public enum LogLevel
{
ERROR,
WARNING,
MESSAGE,
VERBOSE
}
// TODO - Update log level for release
public LogLevel logLevel = LogLevel.MESSAGE;
public event Action<int> OnExportProgressChanged;
public event Action<string, int> OnError;
public event Action<string, int> OnWarning;
public event Action<string, Color, int, bool> OnMessage;
public event Action<string, Color, int, bool> OnVerbose;
public void ReportProgressChanged(int progress)
{
if (OnExportProgressChanged != null)
{
OnExportProgressChanged(progress);
}
}
public void ReportProgressChanged(float progress)
{
ReportProgressChanged((int)progress);
}
public void RaiseError(string error, int rank = 0)
{
if (OnError != null && logLevel >= LogLevel.ERROR)
{
OnError(error, rank);
}
}
public void RaiseWarning(string warning, int rank = 0)
{
if (OnWarning != null && logLevel >= LogLevel.WARNING)
{
OnWarning(warning, rank);
}
}
public void RaiseMessage(string message, int rank = 0, bool emphasis = false)
{
RaiseMessage(message, Color.Black, rank, emphasis);
}
public void RaiseMessage(string message, Color color, int rank = 0, bool emphasis = false)
{
if (OnMessage != null && logLevel >= LogLevel.MESSAGE)
{
OnMessage(message, color, rank, emphasis);
}
}
public void RaiseVerbose(string message, int rank = 0, bool emphasis = false)
{
RaiseVerbose(message, Color.FromArgb(100, 100, 100), rank, emphasis);
}
public void RaiseVerbose(string message, Color color, int rank = 0, bool emphasis = false)
{
if (OnVerbose != null && logLevel >= LogLevel.VERBOSE)
{
OnVerbose(message, color, rank, emphasis);
}
}
public void Print(IIParamBlock2 paramBlock, int logRank)
{
RaiseVerbose("paramBlock=" + paramBlock, logRank);
if (paramBlock != null)
{
RaiseVerbose("paramBlock.NumParams=" + paramBlock.NumParams, logRank + 1);
for (short i = 0; i < paramBlock.NumParams; i++)
{
ParamType2 paramType = paramBlock.GetParameterType(i);
#if MAX2022 || MAX2023 || MAX2024
RaiseVerbose("paramBlock.GetLocalName(" + i + ")=" + paramBlock.GetLocalName(i, 0, false) + ", type=" + paramType, logRank + 1);
#else
RaiseVerbose("paramBlock.GetLocalName(" + i + ")=" + paramBlock.GetLocalName(i, 0) + ", type=" + paramType, logRank + 1);
#endif
switch (paramType)
{
case ParamType2.String:
RaiseVerbose("paramBlock.GetProperty(" + i + ")=" + paramBlock.GetStr(i, 0, 0), logRank + 2);
break;
case ParamType2.Int:
RaiseVerbose("paramBlock.GetProperty(" + i + ")=" + paramBlock.GetInt(i, 0, 0), logRank + 2);
break;
case ParamType2.Float:
RaiseVerbose("paramBlock.GetProperty(" + i + ")=" + paramBlock.GetFloat(i, 0, 0), logRank + 2);
break;
case ParamType2.Bool2:
RaiseVerbose("paramBlock.GetProperty(" + i + ")=" + paramBlock.GetInt(i, 0, 0), logRank + 2);
break;
case ParamType2.Rgba:
RaiseVerbose("paramBlock.GetProperty(" + i + ")=" + paramBlock.GetColor(i, 0, 0), logRank + 2);
break;
default:
RaiseVerbose("Unknown property type", logRank + 2);
break;
}
}
}
}
public void Print(IIPropertyContainer propertyContainer, int logRank)
{
RaiseVerbose("propertyContainer=" + propertyContainer, logRank);
if (propertyContainer != null)
{
RaiseVerbose("propertyContainer.NumberOfProperties=" + propertyContainer.NumberOfProperties, logRank + 1);
for (int i = 0; i < propertyContainer.NumberOfProperties; i++)
{
var prop = propertyContainer.GetProperty(i);
if (prop != null)
{
RaiseVerbose("propertyContainer.GetProperty(" + i + ")=" + prop.Name, logRank + 1);
switch (prop.GetType_)
{
case PropType.StringProp:
string propertyString = "";
RaiseVerbose("prop.GetPropertyValue(ref propertyString, 0)=" + prop.GetPropertyValue(ref propertyString, 0), logRank + 2);
RaiseVerbose("propertyString=" + propertyString, logRank + 2);
break;
case PropType.IntProp:
int propertyInt = 0;
RaiseVerbose("prop.GetPropertyValue(ref propertyInt, 0)=" + prop.GetPropertyValue(ref propertyInt, 0), logRank + 2);
RaiseVerbose("propertyInt=" + propertyInt, logRank + 2);
break;
case PropType.FloatProp:
float propertyFloat = 0;
RaiseVerbose("prop.GetPropertyValue(ref propertyFloat, 0, true)=" + prop.GetPropertyValue(ref propertyFloat, 0, true), logRank + 2);
RaiseVerbose("propertyFloat=" + propertyFloat, logRank + 2);
RaiseVerbose("prop.GetPropertyValue(ref propertyFloat, 0, false)=" + prop.GetPropertyValue(ref propertyFloat, 0, false), logRank + 2);
RaiseVerbose("propertyFloat=" + propertyFloat, logRank + 2);
break;
case PropType.Point3Prop:
IPoint3 propertyPoint3 = Loader.Global.Point3.Create(0, 0, 0);
RaiseVerbose("prop.GetPropertyValue(ref propertyPoint3, 0)=" + prop.GetPropertyValue(propertyPoint3, 0), logRank + 2);
RaiseVerbose("propertyPoint3=" + Point3ToString(propertyPoint3), logRank + 2);
break;
case PropType.Point4Prop:
IPoint4 propertyPoint4 = Loader.Global.Point4.Create(0, 0, 0, 0);
RaiseVerbose("prop.GetPropertyValue(ref propertyPoint4, 0)=" + prop.GetPropertyValue(propertyPoint4, 0), logRank + 2);
RaiseVerbose("propertyPoint4=" + Point4ToString(propertyPoint4), logRank + 2);
break;
case PropType.UnknownProp:
default:
RaiseVerbose("Unknown property type", logRank + 2);
break;
}
}
else
{
RaiseVerbose("propertyContainer.GetProperty(" + i + ") IS NULL", logRank + 1);
}
}
}
}
// -------------------------
// --------- Utils ---------
// -------------------------
private string ColorToString(IColor color)
{
if (color == null)
{
return "";
}
return "{ r=" + color.R + ", g=" + color.G + ", b=" + color.B + " }";
}
private string Point3ToString(IPoint3 point)
{
if (point == null)
{
return "";
}
return "{ x=" + point.X + ", y=" + point.Y + ", z=" + point.Z + " }";
}
private string Point4ToString(IPoint4 point)
{
if (point == null)
{
return "";
}
return "{ x=" + point.X + ", y=" + point.Y + ", z=" + point.Z + ", w=" + point.W + " }";
}
}
}