/[gr2lib]/trunk/gr2lib_UnitTest/Program.cs
ViewVC logotype

Contents of /trunk/gr2lib_UnitTest/Program.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 191 - (show annotations) (download)
Sat Jul 24 06:31:50 2010 UTC (9 years, 1 month ago) by william
File size: 21555 byte(s)
In coreapi:
*Add more texture methods
*Move everthing into related classes, to group related methods,etc
*Update all classes to use these grouped classes

1 //#define HAVE_GRN_REFERENCE // when defined enabled GRN_REFERNCE in Header, else it is disabled
2 //#define HAVE_GRANNY_API_LOGGER // when enabled, enable granny_log_callback_builder
3 using System;
4 using System.Collections.Generic;
5 using System.Text;
6
7 using gr2lib.core;
8 //using gr2lib.core.coretypes;
9 using gr2lib.core.apiversion;
10 using gr2lib.core.exceptions;
11 using gr2lib.core.helpers;
12 using gr2lib.core.coretypes.implementation;
13 using System.Runtime.CompilerServices;
14 using gr2lib.core.header;
15 using System.Windows.Forms;
16 using System.Diagnostics;
17 using gr2lib.core.ui.rigeditor;
18 using gr2lib.core.coreclasses.header;
19 using gr2lib.core.typedefs;
20 using System.Runtime.InteropServices;
21
22 namespace gr2lib_UnitTest
23 {
24
25 class Program
26 {
27 private static granny_file grn_file = null;
28 [STAThreadAttribute]
29 static void Main(string[] args)
30 {
31 string GrannyFilename = shared.GRANNY_TEST_FILE;
32
33 try
34 {
35
36 #region GRANNY2_DLL_COPY_BY_VERSION_SUPPORT
37 if (shared.COPY_DLL_BY_VERSION)
38 {
39 string path = Application.StartupPath + "\\";
40 string source_dll = shared.GRANNY2_DLL_PREFIX + "_" + shared.EXPECTED_API_VERSION + shared.GRANNY2_DLL_SUFFIX;
41 string target_dll = shared.GRANNY2_DLL_PREFIX + shared.GRANNY2_DLL_SUFFIX;
42
43 try
44 {
45 System.IO.File.Copy(path + source_dll, path + target_dll, true);
46 }
47 catch
48 {
49 }
50
51 }
52 #endregion
53
54 #region Check Granny2 API Version
55 // Setup access to check loaded Granny2 API Version
56 granny2apiversion apiversion = new granny2apiversion(shared.EXPECTED_API_VERSION);
57
58 // Check if the Loaded API Version Matches
59 if (!apiversion.apiversionsmatch)
60 {
61 // the loaded version does not match
62 Console.WriteLine("Warning:\n" +
63 "\t Loaded Granny2 DLL Version: " + apiversion.apiversion.ToString() + "\n" +
64 "\t Expected Version: " + apiversion.expectedapiversion.ToString());
65 // return from void to exit application
66 return;
67 }
68 else
69 {
70 // the loaded version matches
71 Console.WriteLine("Loaded granny2.dll: " + apiversion.apiversion.ToString());
72 }
73 #endregion
74
75 if (!shared.USE_RIGEDITOR_CONTROL)
76 {
77
78 #region Parse Commandline
79 if (args.Length == 1)
80 {
81 GrannyFilename = args[0];
82 }
83 else if (args.Length > 1)
84 {
85 throw new InvalidOperationException("ERROR: Recieved Invalid Commandline: " + new arraytostring<string, string[]>(args));
86 }
87
88 if (System.IO.File.Exists(GrannyFilename))
89 {
90 Console.WriteLine("Using Granny2 File: " + GrannyFilename);
91 }
92 else
93 {
94 throw new System.IO.FileNotFoundException("Unable to find: " + GrannyFilename);
95 }
96 #endregion
97
98 grn_file = new granny_file(new granny_log_callback_builder.OnMessageLogged(OnMessageLoggedEventHandler));
99 //grn_file = new granny_file();
100 grn_file = granny_file.ReadFromFile(GrannyFilename, ref grn_file, new granny_log_callback_builder.OnMessageLogged(OnMessageLoggedEventHandler));
101 //grnfileinfo info = grnfileinfo.GetFileInfo(grn_file);
102 grnfileinfo info = grn_file.GrannyFileInfo;
103
104 #region Read Granny2 Data
105
106
107 #region granny_file data
108 Console.WriteLine();
109 if (grn_file != null)
110 {
111 ReadTopLevelGrannyData(grn_file);
112 if (grn_file.HaveHeader)
113 {
114 ReadHeaderData(grn_file.Header);
115 }
116 else { Console.WriteLine("Header: " + "No Header Available"); }
117
118 if (grn_file.HaveMagic)
119 {
120 ReadMagicData(grn_file.SourceMagicValue);
121 }
122 else { Console.WriteLine("Magic: " + "No Magic Available"); }
123 }
124 else { Console.WriteLine("Granny File: " + "No Data Available from this file {this is probably a major error}"); }
125 Console.WriteLine("Press {ENTER} to Continue."); Console.ReadLine();
126 #endregion
127
128 #region Read FromFileName
129 Console.WriteLine();
130 if (info.HaveFromFileName)
131 {
132 ReadFromFileName(info);
133 }
134 else { Console.WriteLine("From File Name: " + "No From File Name Available"); }
135 Console.WriteLine("Press {ENTER} to Continue."); Console.ReadLine();
136 #endregion
137
138 #region Read ArtToolInfo
139 Console.WriteLine();
140 if (info.HaveArtToolInfo)
141 {
142 ReadArtToolInfo(info.ArtToolInfo);
143 }
144 else { Console.WriteLine("Art Tool Data: " + "No Art Tool Info Available"); }
145 Console.WriteLine("Press {ENTER} to Continue."); Console.ReadLine();
146 #endregion
147
148 #region Read ExporterInfo
149 Console.WriteLine();
150 if (info.HaveExporterInfo)
151 {
152 ReadExporterInfo(info.ExporterInfo);
153 }
154 else { Console.WriteLine("Exporter Info: " + "No Exporter Info Available"); }
155 Console.WriteLine("Press {ENTER} to Continue."); Console.ReadLine();
156 #endregion
157
158 #region Read Textures
159 Console.WriteLine();
160 if (info.HaveTextures)
161 {
162 ReadTexture(info.Textures);
163 }
164 else { Console.WriteLine("Texture List: " + "No Textures Available"); }
165 Console.WriteLine("Press {ENTER} to Continue."); Console.ReadLine();
166 #endregion
167
168 #region Read Materials
169 Console.WriteLine();
170 if (info.HaveMaterials)
171 {
172 ReadMaterials(info.Materials);
173 }
174 else { Console.WriteLine("Material List: " + "No Materials Available"); }
175 Console.WriteLine("Press {ENTER} to Continue."); Console.ReadLine();
176 #endregion
177
178 #region Read Skeletons
179 Console.WriteLine();
180 if (info.HaveSkeletons)
181 {
182 ReadSkeletons(info.Skeletons);
183
184 }
185 else { Console.WriteLine("Skeleton List: " + "No Skeletons Available"); }
186 Console.WriteLine("Press {ENTER} to Continue."); Console.ReadLine();
187 #endregion
188
189 #if HAVE_GRANNY_API_LOGGER
190 grn_file.GrannyAPILogger.StopLogging();
191 #endif
192 #endregion
193 }
194 else
195 {
196 granny_log_callback_builder.OnMessageLogged OnMessageLogged = new granny_log_callback_builder.OnMessageLogged(OnMessageLoggedEventHandler);
197 grn_file = new granny_file(OnMessageLogged);
198 grn_file = granny_file.ReadFromFile(GrannyFilename, ref grn_file, OnMessageLogged);
199 UserRigEditorControlfrm editor = new UserRigEditorControlfrm(ref grn_file);
200 editor.OnMessageLoggedEventHandler = OnMessageLogged;
201 editor.ParseGrannyFile();
202 editor.ShowDialog();
203
204 #region Granny2Data Update Testing Code (Code used to check if values were changed/updated)
205 #endregion
206
207 Console.WriteLine("Press {ENTER} to Continue."); Console.ReadLine();
208
209 //grn_file.GrannyAPILogger.StopLogging();
210 }
211
212
213
214 }
215
216
217 catch (granny2apiloadexception ex)
218 {
219 StackTrace st = new StackTrace(true);
220 Granny2ExceptionWriter.WriteToConsole(ex, st);
221 }
222 catch (Exception ex)
223 {
224 StackTrace st = new StackTrace(true);
225 RuntimeWrappedException rwe = ex as RuntimeWrappedException;
226 if (rwe != null)
227 {
228 Granny2ExceptionWriter.WriteToConsole(rwe, st);
229 }
230 else
231 {
232 Granny2ExceptionWriter.WriteToConsole(ex, st);
233 }
234 }
235 }
236
237 #region Data Output Methods
238 #region private static void ReadTopLevelGrannyData(granny_file granny)
239 private static void ReadTopLevelGrannyData(granny_file granny)
240 {
241 Console.WriteLine("grann_file data:");
242 Console.WriteLine("\tIs Byte Reversed: {0}", granny.IsByteReversed.ToString());
243 Console.WriteLine("\tIs Marshalled: {0}", granny.Marshalled.ToString());
244 Console.WriteLine("\tIs User Memory: {0}", granny.IsUserMemory.ToString());
245 Console.WriteLine("\tSection Count: 0x{0}", granny.SectionCount.ToString("X8"));
246 Console.WriteLine("\tSections Pointer: 0x{0}", granny.Sections.ToString("X8"));
247 Console.WriteLine("\tConversion Buffer Pointer: 0x{0}", granny.ConversionBuffer.ToString("X8"));
248 }
249 #endregion
250 #region private static void ReadMagicData(granny_magic magic)
251 private static void ReadMagicData(granny_magic magic)
252 {
253 Console.WriteLine("\tMagic: ");
254 Console.WriteLine("\t\tMagic Value: {0}", new arraytostring<int, int[]>(magic.MagicValue, false));
255 Console.WriteLine("\t\tMagic Header Size: 0x{0}", magic.HeaderSize.ToString("X8"));
256 Console.WriteLine("\t\tMagic Header Format: 0x{0}", magic.HeaderFormat.ToString("X8"));
257 Console.WriteLine("\t\tMagic Reserved: {0}", new arraytostring<int, int[]>(magic.Reserved, false));
258 }
259 #endregion
260 #region private static void ReadHeaderData(granny_header header)
261 private static void ReadHeaderData(granny_header header)
262 {
263 Console.WriteLine("\tHeader: ");
264 Console.WriteLine("\t\tHeader Version: 0x{0}", header.Version.ToString("X2"));
265 Console.WriteLine("\t\tHeader Total Size: 0x{0}", header.TotalSize.ToString("X8"));
266 Console.WriteLine("\t\tHeader CRC: 0x{0}", header.CRC.ToString("X8"));
267 Console.WriteLine("\t\tHeader Section Array Offset: 0x{0}", header.SectionArrayOffset.ToString("X4"));
268 Console.WriteLine("\t\tHeader Section Array Count: 0x{0}", header.SectionArrayCount.ToString("X4"));
269
270 #if HAVE_GRN_REFERENCE
271 Console.WriteLine("\t\tHeader RootObjectTypeDefinition:");
272 Console.WriteLine("\t\t\tSectionIndex: " +header.RootObjectTypeDefinition.SectionIndex);
273 Console.WriteLine("\t\t\tOffset: " + header.RootObjectTypeDefinition.Offset);
274
275 Console.WriteLine("\t\tHeader RootObject:");
276 Console.WriteLine("\t\t\tSectionIndex: " + header.RootObject.SectionIndex);
277 Console.WriteLine("\t\t\tOffset: " + header.RootObject.Offset);
278 #endif
279
280 Console.WriteLine("\t\tHeader Type Tag: 0x{0}", header.TypeTag.ToString("X8"));
281 Console.WriteLine("\t\tHeader Extra Tags: {0}", new arraytostring<int, int[]>(header.ExtraTags, false));
282 Console.WriteLine("\t\tHeader String Database CRC: 0x{0}", header.StringDatabaseCRC.ToString("X8"));
283 Console.WriteLine("\t\tHeader Reserved Unused: {0}", new arraytostring<int, int[]>(header.ReservedUnused, false));
284 }
285 #endregion
286 #region private static void ReadFromFileName(grnfileinfo info)
287 private static void ReadFromFileName(grnfileinfo info)
288 {
289 Console.WriteLine("From File Name: " + info.FromFileName);
290 Console.WriteLine("ExtendedData: " + info.ExtendedData);
291 }
292 #endregion
293 #region private static void ReadArtToolInfo(ArtToolInfo info)
294 private static void ReadArtToolInfo(ArtToolInfo info)
295 {
296 Console.WriteLine("Art Tool Data:");
297 Console.WriteLine("\tTool Name: " + info.FromArtToolName);
298 Console.WriteLine("\tTool Version: " + string.Format("{0}.{1}", info.ArtToolMajorRevision, info.ArtToolMinorRevision));
299 Console.WriteLine("\tTool Units Per Meter: " + info.UnitsPerMeter);
300
301 Console.WriteLine("\tTool Origin: " + string.Format("[{0},{1},{2}]", info.Origin.x, info.Origin.y, info.Origin.z));
302 Console.WriteLine("\tTool Right: " + string.Format("[{0},{1},{2}]", info.Right.x, info.Right.y, info.Right.z));
303 Console.WriteLine("\tTool Up: " + string.Format("[{0},{1},{2}]", info.Up.x, info.Up.y, info.Up.z));
304 Console.WriteLine("\tTool Back: " + string.Format("[{0},{1},{2}]", info.Back.x, info.Back.y, info.Back.z));
305
306 Console.WriteLine("\tTool ExtendedData: " + info.ExtendedData);
307 }
308 #endregion
309 #region private static void ReadExporterInfo(ExporterInfo info)
310 private static void ReadExporterInfo(ExporterInfo info)
311 {
312 Console.WriteLine("Exporter Info:");
313 Console.WriteLine("\tExporter Name: " + info.ExporterName);
314
315 Console.WriteLine("\tExporter Version: " +
316 string.Format("{0}.{1}.{2}.{3}",
317 info.ExporterMajorRevision,
318 info.ExporterMinorRevision,
319 info.ExporterCustomization,
320 info.ExporterBuildNumber));
321
322 Console.WriteLine("\tExporter ExtendedData: " + info.ExtendedData);
323 }
324 #endregion
325 #region private static void ReadTexture(List<Texture> t)
326 private static void ReadTexture(List<Texture> texture)
327 {
328 Console.WriteLine("Texture List:");
329 foreach (Texture t in texture)
330 {
331 Console.WriteLine("\tName: " + t.FromFileName);
332 Console.WriteLine("\tType: " + t.TextureType);
333 Console.WriteLine("\tWidth: " + t.Width);
334 Console.WriteLine("\tHeight: " + t.Height);
335 Console.WriteLine("\tEncoding: " + t.Encoding);
336 Console.WriteLine("\tSubFormat: " + t.SubFormat);
337 // layout
338 Console.WriteLine("\tBytes Per Pixel: " + t.Layout.BytesPerPixel);
339 Console.WriteLine("\tShiftForComponent: " + new arraytostring<int, int[]>(t.Layout.ShiftForComponent, false));
340 Console.WriteLine("\tBitsForComponent: " + new arraytostring<int, int[]>(t.Layout.BitsForComponent, false));
341 // images
342 Console.WriteLine("\tImage List:");
343 foreach (Image img in t.Images)
344 {
345 foreach (MIPLevel mip in img.MIPLevels)
346 {
347 Console.WriteLine("\t\tMipLevel Stride: " + mip.Stride);
348 if (mip.Pixels.Count > 0)
349 {
350 Console.WriteLine("\t\tMipLevel Pixel: " + "{Pixel Data " + "[" + mip.Pixels.Count + "]}");
351 //// export image
352 //mip.Pixels.Export(@"exported_images\" + t.FromFileName.Name, t.Width, t.Height, mip.Stride);
353 }
354 }
355 }
356 Console.WriteLine("\tExtendedData: " + t.ExtendedData);
357 Console.WriteLine();
358 }
359 }
360 #endregion
361 #region private static void ReadMaterials(List<Material> materials)
362 private static void ReadMaterials(List<Material> materials)
363 {
364 Console.WriteLine("Material List:");
365 foreach (Material m in materials)
366 {
367 Console.WriteLine("\tMaterial Name: " + m.Name);
368 Console.WriteLine("\t\tMaterial IsTexture: " + m.IsTexture.ToString());
369 if (m.IsTexture)
370 {
371 Texture t = m.Texture;
372 Console.WriteLine("\t\tTexture:");
373 Console.WriteLine("\t\t\tName: " + t.FromFileName);
374 Console.WriteLine("\t\t\tType: " + t.TextureType);
375 Console.WriteLine("\t\t\tWidth: " + t.Width);
376 Console.WriteLine("\t\t\tHeight: " + t.Height);
377 Console.WriteLine("\t\t\tEncoding: " + t.Encoding);
378 Console.WriteLine("\t\t\tSubFormat: " + t.SubFormat);
379 // layout
380 Console.WriteLine("\t\t\tBytes Per Pixel: " + t.Layout.BytesPerPixel);
381 Console.WriteLine("\t\t\tShiftForComponent: " + new arraytostring<int, int[]>(t.Layout.ShiftForComponent));
382 Console.WriteLine("\t\t\tBitsForComponent: " + new arraytostring<int, int[]>(t.Layout.BitsForComponent));
383
384
385 Console.WriteLine("\t\t\tImage List:");
386 foreach (Image img in t.Images)
387 {
388 foreach (MIPLevel mip in img.MIPLevels)
389 {
390 Console.WriteLine("\t\t\t\tMipLevel Stride: " + mip.Stride);
391 if (mip.Pixels.Count > 0)
392 {
393 Console.WriteLine("\t\t\t\tMipLevel Pixel: " + "{Pixel Data " + "[" + mip.Pixels.Count + "]}");
394 //// export image
395 //mip.Pixels.Export(@"exported_images\" + t.FromFileName.Name, t.Width, t.Height, mip.Stride);
396 }
397 }
398 }
399
400 Console.WriteLine("\t\t\tExtendedData: " + t.ExtendedData);
401 Console.WriteLine();
402 }
403 Console.WriteLine("\t\tExtendedData: " + m.ExtendedData);
404 Console.WriteLine();
405 }
406 }
407 #endregion
408 #region private static void ReadSkeletons(List<Skeleton> skeletons)
409 private static void ReadSkeletons(List<Skeleton> skeletons)
410 {
411 Console.WriteLine("Skeleton List:");
412 foreach (Skeleton s in skeletons)
413 {
414 Console.WriteLine("\tSkeleton Name: " + s.SkeletonName);
415 Console.WriteLine("\tSkeleton LodType: " + s.LodType);
416 Console.WriteLine("\tBones:");
417 ReadBones(s.Bones);
418 Console.WriteLine("\t\tExtendedData: " + s.ExtendedData);
419 Console.WriteLine();
420 }
421 }
422 #endregion
423 #region private static void ReadBones(List<Bone> bones)
424 private static void ReadBones(List<Bone> bones)
425 {
426 foreach (Bone b in bones)
427 {
428 Console.WriteLine("\t\tName: " + b.BoneName);
429 Console.WriteLine("\t\tParent Index: " + b.ParentIndex);
430 Console.WriteLine("\t\tLod Error: " + b.LodError);
431 Console.WriteLine("\t\tTransform: " + b.Transform.ToString());
432 if (b.HasLightInfo) { Console.WriteLine("\t\tLightInfo ExtendedData: " + b.LightInfo.ExtendedData); }
433 else { Console.WriteLine("\t\tLightInfo ExtendedData: " + "No LightInfo"); }
434 if (b.HasCameraInfo) { Console.WriteLine("\t\tCameraInfo ExtendedData: " + b.CameraInfo.ExtendedData); }
435 else { Console.WriteLine("\t\tCameraInfo ExtendedData: " + "No CameraInfo"); }
436 Console.WriteLine();
437 }
438 }
439 #endregion
440 #endregion
441
442
443 private static void OnMessageLoggedEventHandler(object sender, granny_log_eventargs e)
444 {
445 // Granny2 API Has logged a message
446 // do something here if needed
447 Console.WriteLine("From: _logger_OnMessageLoggedEventHandler -> Caught: " + e.Message);
448 //GC.KeepAlive(grn_file.GrannyAPILogger);
449 }
450 }
451 }
452
453
454

  ViewVC Help
Powered by ViewVC 1.1.22