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

Annotation of /trunk/gr2lib_UnitTest/Program.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 191 - (hide annotations) (download)
Sat Jul 24 06:31:50 2010 UTC (9 years, 6 months 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 william 97 //#define HAVE_GRN_REFERENCE // when defined enabled GRN_REFERNCE in Header, else it is disabled
2 william 156 //#define HAVE_GRANNY_API_LOGGER // when enabled, enable granny_log_callback_builder
3 william 97 using System;
4 william 9 using System.Collections.Generic;
5     using System.Text;
6    
7 william 16 using gr2lib.core;
8 william 70 //using gr2lib.core.coretypes;
9 william 16 using gr2lib.core.apiversion;
10 william 50 using gr2lib.core.exceptions;
11 william 69 using gr2lib.core.helpers;
12 william 70 using gr2lib.core.coretypes.implementation;
13 william 86 using System.Runtime.CompilerServices;
14 william 96 using gr2lib.core.header;
15 william 100 using System.Windows.Forms;
16 william 107 using System.Diagnostics;
17 william 116 using gr2lib.core.ui.rigeditor;
18 william 141 using gr2lib.core.coreclasses.header;
19 william 142 using gr2lib.core.typedefs;
20 william 156 using System.Runtime.InteropServices;
21 william 16
22 william 9 namespace gr2lib_UnitTest
23     {
24 william 77
25 william 9 class Program
26     {
27 william 165 private static granny_file grn_file = null;
28 william 128 [STAThreadAttribute]
29 william 9 static void Main(string[] args)
30 william 77 {
31 william 65 string GrannyFilename = shared.GRANNY_TEST_FILE;
32 william 165
33 william 50 try
34     {
35 william 100
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 william 70 #region Check Granny2 API Version
55 william 50 // Setup access to check loaded Granny2 API Version
56 william 58 granny2apiversion apiversion = new granny2apiversion(shared.EXPECTED_API_VERSION);
57 william 16
58 william 50 // 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 william 133 "\t Loaded Granny2 DLL Version: " + apiversion.apiversion.ToString() + "\n" +
64     "\t Expected Version: " + apiversion.expectedapiversion.ToString());
65 william 50 // return from void to exit application
66     return;
67     }
68     else
69     {
70     // the loaded version matches
71 william 133 Console.WriteLine("Loaded granny2.dll: " + apiversion.apiversion.ToString());
72 william 50 }
73 william 70 #endregion
74    
75 william 116 if (!shared.USE_RIGEDITOR_CONTROL)
76 william 65 {
77 william 61
78 william 116 #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 william 61
88 william 116 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 william 158
98 william 165 grn_file = new granny_file(new granny_log_callback_builder.OnMessageLogged(OnMessageLoggedEventHandler));
99     //grn_file = new granny_file();
100 william 158 grn_file = granny_file.ReadFromFile(GrannyFilename, ref grn_file, new granny_log_callback_builder.OnMessageLogged(OnMessageLoggedEventHandler));
101 william 116 //grnfileinfo info = grnfileinfo.GetFileInfo(grn_file);
102     grnfileinfo info = grn_file.GrannyFileInfo;
103 william 96
104 william 136 #region Read Granny2 Data
105 william 97
106 william 136
107 william 116 #region granny_file data
108     Console.WriteLine();
109     if (grn_file != null)
110 william 100 {
111 william 141 ReadTopLevelGrannyData(grn_file);
112 william 116 if (grn_file.HaveHeader)
113     {
114 william 141 ReadHeaderData(grn_file.Header);
115 william 116 }
116     else { Console.WriteLine("Header: " + "No Header Available"); }
117    
118     if (grn_file.HaveMagic)
119     {
120 william 141 ReadMagicData(grn_file.SourceMagicValue);
121 william 116 }
122     else { Console.WriteLine("Magic: " + "No Magic Available"); }
123 william 100 }
124 william 116 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 william 97
128 william 116 #region Read FromFileName
129     Console.WriteLine();
130     if (info.HaveFromFileName)
131 william 100 {
132 william 141 ReadFromFileName(info);
133 william 100 }
134 william 116 else { Console.WriteLine("From File Name: " + "No From File Name Available"); }
135     Console.WriteLine("Press {ENTER} to Continue."); Console.ReadLine();
136     #endregion
137 william 96
138 william 116 #region Read ArtToolInfo
139     Console.WriteLine();
140     if (info.HaveArtToolInfo)
141     {
142 william 141 ReadArtToolInfo(info.ArtToolInfo);
143 william 116 }
144     else { Console.WriteLine("Art Tool Data: " + "No Art Tool Info Available"); }
145     Console.WriteLine("Press {ENTER} to Continue."); Console.ReadLine();
146     #endregion
147 william 70
148 william 116 #region Read ExporterInfo
149     Console.WriteLine();
150     if (info.HaveExporterInfo)
151     {
152 william 141 ReadExporterInfo(info.ExporterInfo);
153 william 116 }
154     else { Console.WriteLine("Exporter Info: " + "No Exporter Info Available"); }
155     Console.WriteLine("Press {ENTER} to Continue."); Console.ReadLine();
156     #endregion
157 william 71
158 william 116 #region Read Textures
159     Console.WriteLine();
160     if (info.HaveTextures)
161 william 72 {
162 william 141 ReadTexture(info.Textures);
163 william 72 }
164 william 116 else { Console.WriteLine("Texture List: " + "No Textures Available"); }
165     Console.WriteLine("Press {ENTER} to Continue."); Console.ReadLine();
166     #endregion
167 william 72
168 william 116 #region Read Materials
169     Console.WriteLine();
170     if (info.HaveMaterials)
171 william 81 {
172 william 141 ReadMaterials(info.Materials);
173 william 81 }
174 william 116 else { Console.WriteLine("Material List: " + "No Materials Available"); }
175     Console.WriteLine("Press {ENTER} to Continue."); Console.ReadLine();
176     #endregion
177 william 83
178 william 116 #region Read Skeletons
179     Console.WriteLine();
180     if (info.HaveSkeletons)
181 william 83 {
182 william 141 ReadSkeletons(info.Skeletons);
183 william 116
184 william 83 }
185 william 116 else { Console.WriteLine("Skeleton List: " + "No Skeletons Available"); }
186     Console.WriteLine("Press {ENTER} to Continue."); Console.ReadLine();
187     #endregion
188 william 90
189 william 156 #if HAVE_GRANNY_API_LOGGER
190     grn_file.GrannyAPILogger.StopLogging();
191     #endif
192 william 116 #endregion
193 william 70 }
194 william 116 else
195     {
196 william 166 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 william 167 UserRigEditorControlfrm editor = new UserRigEditorControlfrm(ref grn_file);
200 william 166 editor.OnMessageLoggedEventHandler = OnMessageLogged;
201 william 128 editor.ParseGrannyFile();
202 william 116 editor.ShowDialog();
203 william 136
204 william 164 #region Granny2Data Update Testing Code (Code used to check if values were changed/updated)
205     #endregion
206 william 163
207 william 136 Console.WriteLine("Press {ENTER} to Continue."); Console.ReadLine();
208    
209 william 156 //grn_file.GrannyAPILogger.StopLogging();
210 william 116 }
211 william 153
212 william 116
213 william 153
214 william 90 }
215 william 70
216 william 90
217 william 50 catch (granny2apiloadexception ex)
218 william 16 {
219 william 107 StackTrace st = new StackTrace(true);
220 william 116 Granny2ExceptionWriter.WriteToConsole(ex, st);
221 william 16 }
222 william 58 catch (Exception ex)
223     {
224 william 107 StackTrace st = new StackTrace(true);
225 william 86 RuntimeWrappedException rwe = ex as RuntimeWrappedException;
226     if (rwe != null)
227     {
228 william 107 Granny2ExceptionWriter.WriteToConsole(rwe, st);
229 william 86 }
230     else
231     {
232 william 116 Granny2ExceptionWriter.WriteToConsole(ex, st);
233 william 86 }
234 william 58 }
235 william 9 }
236 william 141
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 william 153
443 william 156 private static void OnMessageLoggedEventHandler(object sender, granny_log_eventargs e)
444 william 153 {
445     // Granny2 API Has logged a message
446     // do something here if needed
447 william 165 Console.WriteLine("From: _logger_OnMessageLoggedEventHandler -> Caught: " + e.Message);
448 william 166 //GC.KeepAlive(grn_file.GrannyAPILogger);
449 william 153 }
450 william 9 }
451     }
452 william 70
453 william 96
454 william 97

  ViewVC Help
Powered by ViewVC 1.1.22