Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
ValidateFBXPlugin.c
Go to the documentation of this file.
1[BaseContainerProps(configRoot: true)]
3{
4 [Attribute(desc: "Array of all possible bloodtypes with randomization weight. Keep combined randomization weight at 100 for ease of use", category: "Data")]
5 protected ref array<string> m_aAssetTypes;
6
7 bool GetData(inout array<string> data)
8 {
9 foreach(auto assetType : m_aAssetTypes)
10 {
11 data.Insert(assetType);
12 }
13 return data;
14 }
15};
16
17
18[WorkbenchPluginAttribute(name: "Validate Asset", wbModules: {"ResourceManager"},resourceTypes: {"fbx","xob"} , awesomeFontCode: 0xf0ad, description:"Validates checks on FBX on various issues that can be tedious and time-consuming to verify manually", category:"EBT Validation")]
19class ValidateFBXPlugin: WorkbenchPlugin
20{
21 [Attribute("0", UIWidgets.ComboBox, "", "", enums: GetAssetTypes(), category: "Asset Type")]
22 int Type;
23
24 [Attribute("", uiwidget: UIWidgets.FileNamePicker, desc: "Must be defined if FBX report is wanted!! Path to a folder where temporary log file will be stored.", params: "folders FileNameFormat=absolute", category: "Path")]
25 string log_file_folder_path;
26
27 static ref array<string> allFbxs = new array<string>;
28
29
30 protected static const ref ParamEnum DEFAULT_ENUM = new ParamEnum("GENERIC", "0");
31 protected static ref ParamEnumArray s_AssetTypes = {DEFAULT_ENUM};
32
33 static ref ParamEnumArray GetAssetTypes()
34 {
35 return s_AssetTypes;
36 }
37
38 static void FillAssetTypes()
39 {
40 s_AssetTypes.Clear();
42
44 filter.fileExtensions = {"conf"};
45 filter.searchStr = {"AssetTypes"};
46
47 array<string> addons = {};
48 GameProject.GetLoadedAddons(addons);
49 foreach(string addon : addons)
50 {
51 string addonName = GameProject.GetAddonID(addon);
52
53 }
54
55 array<string> configFiles = {};
56 ResourceDatabase.SearchResources(filter, configFiles.Insert);
57
58 if(configFiles.Count() != 0)
59 {
60 ResourceName config = configFiles[0];
61 Resource container = BaseContainerTools.LoadContainer(config);
62 if(container != null)
63 {
64 AssetTypes configData = AssetTypes.Cast(BaseContainerTools.CreateInstanceFromContainer(container.GetResource().ToBaseContainer()));
65 if(configData != null)
66 {
67 array<string> configDataArr = {};
68 configData.GetData(configDataArr);
69 for (int i = 1; i <= configDataArr.Count(); i++)
70 {
71 s_AssetTypes.Insert(new ParamEnum(configDataArr[i-1], i.ToString()));
72 }
73 }
74 }
75 }
76 return;
77 }
78
79 override void OnResourceContextMenu(notnull array<ResourceName> resources)
80 {
81 ValidateMaterialPlugin.materials.Clear();
83 if (Workbench.ScriptDialog("Validate FBXs", "Select one FBX file you want to validate, also possible to select whole folder", this))
84 {
85 if(resources.Count() == 0)
86 {
87 Print("No fbx file selected. Please select at least one fbx file in the resource browser.",LogLevel.WARNING);
88 return;
89 }
90 else if(resources.Count() > 1)
91 {
92 Print("Validating multiple FBXs at once is not supported yet! Please select only one FBX.", LogLevel.WARNING);
93 return;
94 }
95
96
97
98 // fbxPath
99 string fbxPath;
100 Workbench.GetAbsolutePath(resources[0].GetPath(),fbxPath);
101
102 if (fbxPath.EndsWith(".xob"))
103 fbxPath.Replace(".xob", ".fbx");
104 // Clean log file from previous report
105 string log_file = log_file_folder_path;
106 if(log_file != "")
107 {
108 log_file += "/MQA_Log.txt";
109 }
110
111 log_file.Replace("\\","/");
112 if (FileIO.FileExists(log_file))
113 {
114 FileIO.DeleteFile(log_file);
115 }
116
117 // Blender Validation
118 if (!EBTConfigPlugin.HasBlenderRegistered())
119 {
120 Print("Blender is not registered in EBT Config, skipping a few checks");
121 }
122 else
123 {
125 EBTEmatUtils ematUtils = new EBTEmatUtils();
126 bool meta = ematUtils.GetMaterials(resources[0].GetPath(), materials);
127
128 for(int i = 0; i < materials.Count(); i++)
129 {
130 ValidateMaterialPlugin.materials.Insert(materials.Get(materials.GetKey(i)));
131 }
132
133 BlenderOperatorDescription operatorDescription = new BlenderOperatorDescription("modelqa");
134 operatorDescription.blIDName = "ebt.mqa_report_background";
135 operatorDescription.AddParam("log_file_path",log_file);
136 operatorDescription.AddParam("fbx_path", fbxPath);
137 operatorDescription.AddParam("asset_type", s_AssetTypes.Get(Type).m_Key);
138 operatorDescription.AddParam("mat_count", ValidateMaterialPlugin.materials.Count());
139 StartBlenderWithOperator(operatorDescription, true);
140 }
141
142 }
143 }
144
145 override void Run()
146 {
147 ValidateMaterialPlugin.materials.Clear();
149 if (Workbench.ScriptDialog("Validate FBXs", "Select one or multiple FBX files you want to validate, also possible to select whole folder", this))
150 {
151 ResourceManager resourceManager = Workbench.GetModule(ResourceManager);
152 array<ResourceName> resources = {};
153 resourceManager.GetResourceBrowserSelection(resources.Insert, true);
154
155 if(resources.Count() == 0)
156 {
157 Print("No fbx file selected. Please select at least one fbx file in the resource browser.",LogLevel.WARNING);
158 return;
159 }
160 else if(resources.Count() > 1)
161 {
162 Print("Validating multiple FBXs at once is not supported yet! Please select only one FBX.", LogLevel.WARNING);
163 return;
164 }
165
166
167 // fbxPath
168 string fbxPath;
169 Workbench.GetAbsolutePath(resources[0].GetPath(),fbxPath);
170
171 if (fbxPath.EndsWith(".xob"))
172 fbxPath.Replace(".xob", ".fbx");
173 // Clean log file from previous report
174 string log_file = log_file_folder_path;
175 if(log_file != "")
176 {
177 log_file += "/MQA_Log.txt";
178 }
179
180 log_file.Replace("\\","/");
181 if (FileIO.FileExists(log_file))
182 {
183 FileIO.DeleteFile(log_file);
184 }
185
186
187 // Blender Validation
188 if (!EBTConfigPlugin.HasBlenderRegistered())
189 {
190 Print("Blender is not registered in EBT Config, skipping a few checks");
191 }
192 else
193 {
195 EBTEmatUtils ematUtils = new EBTEmatUtils();
196 bool meta = ematUtils.GetMaterials(resources[0].GetPath(), materials);
197
198 for(int i = 0; i < materials.Count(); i++)
199 {
200 ValidateMaterialPlugin.materials.Insert(materials.Get(materials.GetKey(i)));
201 }
202 BlenderOperatorDescription operatorDescription = new BlenderOperatorDescription("modelqa");
203 operatorDescription.blIDName = "ebt.mqa_report_background";
204 operatorDescription.AddParam("log_file_path",log_file);
205 operatorDescription.AddParam("fbx_path", fbxPath);
206 operatorDescription.AddParam("asset_type", s_AssetTypes.Get(Type).m_Key);
207 operatorDescription.AddParam("mat_count", ValidateMaterialPlugin.materials.Count());
208 StartBlenderWithOperator(operatorDescription, true);
209 }
210
211 }
212 }
213
214 [ButtonAttribute("Validate")]
215 bool OK()
216 {
217 return true;
218 }
219
220 [ButtonAttribute("Cancel")]
221 bool Cancel()
222 {
223 return false;
224 }
225
226};
227
228class FBXReportToolRequest: JsonApiStruct
229{
230 string logFile;
231
232 void FBXReportToolRequest()
233 {
234 RegV("logFile");
235 }
236};
237
238class FBXReportToolResponse: JsonApiStruct
239{
240 string Output;
241
242 void FBXReportToolResponse()
243 {
244 RegV("Output");
245 }
246};
247
248
249class FBXReportToolMessage: NetApiHandler
250{
251 override JsonApiStruct GetRequest()
252 {
253 return new FBXReportToolRequest();
254 }
255
256 override JsonApiStruct GetResponse(JsonApiStruct request)
257 {
258 FBXReportToolRequest req = FBXReportToolRequest.Cast(request);
260
261
262 FileHandle fRead = FileIO.OpenFile(req.logFile, FileMode.READ);
263
264
265 array<string> errors = new array<string>;
266 int warning_count = 0;
267 int info_count = 0;
268 if(req.logFile)
269 {
270 PrintFormat("FBX Mesh Report:", level:LogLevel.DEBUG);
271 string fLine;
272 while (fRead.ReadLine(fLine) != -1)
273 {
274 string logLevel = fLine.Substring(0,3);
275 LogLevel level;
276 string reportLine = fLine.Substring(3,fLine.Length()-3);
277 reportLine.Replace("'",string.Empty);
278
279 switch(logLevel)
280 {
281 case "[W]":
282 level = LogLevel.WARNING;
283 warning_count += 1;
284 break;
285 case "[I]":
286 level = LogLevel.DEBUG;
287 info_count += 1;
288 break;
289 case "[E]":
290 level = LogLevel.ERROR;
291 errors.Insert(reportLine);
292 break;
293 default:
294 level = LogLevel.NORMAL;
295 break;
296 }
297
298 Print(string.ToString(reportLine),level);
299 }
300 fRead.Close();
301
302 string summary = "\n";
303
304 summary += string.ToString("------------ VALIDATION SUMMARY ------------\n");
305 summary += string.ToString("Errors - (" + errors.Count() + ")\n");
306
307 Print(string.ToString("------------ VALIDATION SUMMARY ------------"));
308 Print(string.ToString("Errors - (" + errors.Count() + ")"), LogLevel.ERROR);
309 for (int i = 0; i < errors.Count(); i++)
310 {
311 summary += string.ToString(errors[i] + "\n");
312 Print(string.ToString(errors[i]),LogLevel.ERROR);
313 }
314 summary += string.ToString("Warnings - (" + warning_count + ")\n");
315 summary += string.ToString("Infos - (" + info_count + ")\n");
316 Print(string.ToString("Warnings - (" + warning_count + ")"), LogLevel.WARNING);
317 Print(string.ToString("Infos - (" + info_count + ")"), LogLevel.DEBUG);
318 System.ExportToClipboard(summary);
319 }
320 return response;
321 }
322}
323
void ParamEnum(string key, string value, string desc="")
Definition attributes.c:25
GenerateFlowMaps WorkbenchPlugin WorkbenchPluginAttribute("Regenerate river flow-maps", "Generate and save/overwrite river flow-maps", "", "", {"WorldEditor"}, "", 0xf773)
Definition FlowmapTool.c:59
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
SCR_AICombatMoveRequestBase GetRequest()
Get all prefabs that have the spawner data
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
class WorkbenchDialog_AbortRetryIgnore ButtonAttribute("OK", true)
bool GetData(inout array< string > data)
ref array< string > m_aAssetTypes
base classes for filtering in server browser
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
Object used for holding filtering params for ResourceDatabase.SearchResources() method.
Definition System.c:9
static void FillAssetTypes()
static const ref ParamEnum DEFAULT_ENUM
override void OnResourceContextMenu(notnull array< ResourceName > resources)
override void Run()
static ref ParamEnumArray GetAssetTypes()
static ref ParamEnumArray s_AssetTypes
Definition Types.c:486
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
proto void PrintFormat(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL, LogLevel level=LogLevel.NORMAL)
SCR_FieldOfViewSettings Attribute
FileMode
Mode for opening file. See FileSystem::Open.
Definition FileMode.c:14
proto external string ToString()
Plain C++ pointer, no weak pointers, no memory management.