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

Contents of /trunk/gr2lib_UnitTest/Program.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 97 - (show annotations) (download)
Sat Jul 17 05:53:44 2010 UTC (11 years, 4 months ago) by william
File size: 16643 byte(s)
Add:
#define HAVE_GRN_REFERENCE
when defined enables GRN_REFERENCE class, else disables it (the code does not work)

1 //#define HAVE_GRN_REFERENCE // when defined enabled GRN_REFERNCE in Header, else it is disabled
2 using System;
3 using System.Collections.Generic;
4 using System.Text;
5
6 using gr2lib.core;
7 //using gr2lib.core.coretypes;
8 using gr2lib.core.apiversion;
9 using gr2lib.core.exceptions;
10 using gr2lib.core.helpers;
11 using gr2lib.core.coretypes.implementation;
12 using System.Runtime.CompilerServices;
13 using gr2lib.core.header;
14
15 namespace gr2lib_UnitTest
16 {
17
18 class Program
19 {
20 static void Main(string[] args)
21 {
22 string GrannyFilename = shared.GRANNY_TEST_FILE;
23 try
24 {
25 #region Check Granny2 API Version
26 // Setup access to check loaded Granny2 API Version
27 granny2apiversion apiversion = new granny2apiversion(shared.EXPECTED_API_VERSION);
28
29 // Check if the Loaded API Version Matches
30 if (!apiversion.apiversionsmatch)
31 {
32 // the loaded version does not match
33 Console.WriteLine("Warning:\n" +
34 "\t Loaded Granny2 DLL Version: " + apiversion.apiversion.version + "\n" +
35 "\t Expected Version: " + apiversion.expectedapiversion.version);
36 // return from void to exit application
37 return;
38 }
39 else
40 {
41 // the loaded version matches
42 Console.WriteLine("Loaded granny2.dll: " + apiversion.apiversion.version);
43 }
44 #endregion
45
46 #region Parse Commandline
47 if (args.Length == 1)
48 {
49 GrannyFilename = args[0];
50 }
51 else if (args.Length > 1)
52 {
53 throw new InvalidOperationException("ERROR: Recieved Invalid Commandline: " + new arraytostring<string, string[]>(args));
54 }
55
56 if (System.IO.File.Exists(GrannyFilename))
57 {
58 Console.WriteLine("Using Granny2 File: " + GrannyFilename);
59 }
60 else
61 {
62 throw new System.IO.FileNotFoundException("Unable to find: " + GrannyFilename);
63 }
64 #endregion
65
66 #region Read Granny2 Data
67
68 granny_file grn_file = granny_file.ReadFromFile(GrannyFilename);
69 //grnfileinfo info = grnfileinfo.GetFileInfo(grn_file);
70 grnfileinfo info = grn_file.GrannyFileInfo;
71
72
73 #region granny_file data
74 Console.WriteLine();
75 Console.WriteLine("grann_file data:");
76 Console.WriteLine("\tIs Byte Reversed: {0}", grn_file.IsByteReversed.ToString());
77 Console.WriteLine("\tIs Marshalled: {0}", grn_file.Marshalled.ToString());
78 Console.WriteLine("\tIs User Memory: {0}", grn_file.IsUserMemory.ToString());
79 Console.WriteLine("\tSection Count: 0x{0}", grn_file.SectionCount.ToString("X8"));
80 Console.WriteLine("\tSections Pointer: 0x{0}", grn_file.Sections.ToString("X8"));
81 Console.WriteLine("\tConversion Buffer Pointer: 0x{0}", grn_file.ConversionBuffer.ToString("X8"));
82
83 Console.WriteLine("\tHeader: ");
84 Console.WriteLine("\t\tHeader Version: 0x{0}", grn_file.Header.Version.ToString("X2"));
85 Console.WriteLine("\t\tHeader Total Size: 0x{0}",grn_file.Header.TotalSize.ToString("X8"));
86 Console.WriteLine("\t\tHeader CRC: 0x{0}", grn_file.Header.CRC.ToString("X8"));
87 Console.WriteLine("\t\tHeader Section Array Offset: 0x{0}",grn_file.Header.SectionArrayOffset.ToString("X4"));
88 Console.WriteLine("\t\tHeader Section Array Count: 0x{0}", grn_file.Header.SectionArrayCount.ToString("X4"));
89
90 #if HAVE_GRN_REFERENCE
91 Console.WriteLine("\t\tHeader RootObjectTypeDefinition:");
92 Console.WriteLine("\t\t\tSectionIndex: " + grn_file.Header.RootObjectTypeDefinition.SectionIndex);
93 Console.WriteLine("\t\t\tOffset: " + grn_file.Header.RootObjectTypeDefinition.Offset);
94
95 Console.WriteLine("\t\tHeader RootObject:");
96 Console.WriteLine("\t\t\tSectionIndex: " + grn_file.Header.RootObject.SectionIndex);
97 Console.WriteLine("\t\t\tOffset: " + grn_file.Header.RootObject.Offset);
98 #endif
99 Console.WriteLine("\t\tHeader Type Tag: 0x{0}",grn_file.Header.TypeTag.ToString("X8"));
100 Console.WriteLine("\t\tHeader Extra Tags: {0}", new arraytostring<int, int[]>(grn_file.Header.ExtraTags));
101 Console.WriteLine("\t\tHeader String Database CRC: 0x{0}", grn_file.Header.StringDatabaseCRC.ToString("X8"));
102 Console.WriteLine("\t\tHeader Reserved Unused: {0}",new arraytostring<int, int[]>(grn_file.Header.ReservedUnused));
103
104 Console.WriteLine("\tMagic: ");
105 Console.WriteLine("\t\tMagic Value: {0}", new arraytostring<int, int[]>(grn_file.SourceMagicValue.MagicValue));
106 Console.WriteLine("\t\tMagic Header Size: 0x{0}", grn_file.SourceMagicValue.HeaderSize.ToString("X8"));
107 Console.WriteLine("\t\tMagic Header Format: 0x{0}", grn_file.SourceMagicValue.HeaderFormat.ToString("X8"));
108 Console.WriteLine("\t\tMagic Reserved: {0}", new arraytostring<int, int[]>(grn_file.SourceMagicValue.Reserved));
109
110 Console.WriteLine("Press {ENTER} to Continue."); Console.ReadLine();
111 #endregion
112
113 #region Read FromFileName
114 Console.WriteLine();
115 if (info.HaveFromFileName)
116 {
117 Console.WriteLine("From File Name: " + info.FromFileName);
118 Console.WriteLine("ExtendedData: " + info.ExtendedData);
119 }
120 else { Console.WriteLine("From File Name: " + "No From File Name Available"); }
121 Console.WriteLine("Press {ENTER} to Continue."); Console.ReadLine();
122 #endregion
123
124 #region Read ArtToolInfo
125 Console.WriteLine();
126 if (info.HaveArtToolInfo)
127 {
128 Console.WriteLine("Art Tool Data:");
129 Console.WriteLine("\tTool Name: " + info.ArtToolInfo.FromArtToolName);
130 Console.WriteLine("\tTool Version: " + string.Format("{0}.{1}", info.ArtToolInfo.ArtToolMajorRevision, info.ArtToolInfo.ArtToolMinorRevision));
131 Console.WriteLine("\tTool Units Per Meter: " + info.ArtToolInfo.UnitsPerMeter);
132
133 Console.WriteLine("\tTool Origin: " + string.Format("[{0},{1},{2}]", info.ArtToolInfo.Origin.x, info.ArtToolInfo.Origin.y, info.ArtToolInfo.Origin.z));
134 Console.WriteLine("\tTool Right: " + string.Format("[{0},{1},{2}]", info.ArtToolInfo.Right.x, info.ArtToolInfo.Right.y, info.ArtToolInfo.Right.z));
135 Console.WriteLine("\tTool Up: " + string.Format("[{0},{1},{2}]", info.ArtToolInfo.Up.x, info.ArtToolInfo.Up.y, info.ArtToolInfo.Up.z));
136 Console.WriteLine("\tTool Back: " + string.Format("[{0},{1},{2}]", info.ArtToolInfo.Back.x, info.ArtToolInfo.Back.y, info.ArtToolInfo.Back.z));
137
138 Console.WriteLine("\tTool ExtendedData: " + info.ArtToolInfo.ExtendedData);
139 }
140 else { Console.WriteLine("Art Tool Data: " + "No Art Tool Info Available"); }
141 Console.WriteLine("Press {ENTER} to Continue."); Console.ReadLine();
142 #endregion
143
144 #region Read ExporterInfo
145 Console.WriteLine();
146 if (info.HaveExporterInfo)
147 {
148 Console.WriteLine("Exporter Info:");
149 Console.WriteLine("\tExporter Name: " + info.ExporterInfo.ExporterName);
150
151 Console.WriteLine("\tExporter Version: " +
152 string.Format("{0}.{1}.{2}.{3}",
153 info.ExporterInfo.ExporterMajorRevision,
154 info.ExporterInfo.ExporterMinorRevision,
155 info.ExporterInfo.ExporterCustomization,
156 info.ExporterInfo.ExporterBuildNumber));
157
158 Console.WriteLine("\tExporter ExtendedData: " + info.ExporterInfo.ExtendedData);
159 }
160 else { Console.WriteLine("Exporter Info: " + "No Exporter Info Available"); }
161 Console.WriteLine("Press {ENTER} to Continue."); Console.ReadLine();
162 #endregion
163
164 #region Read Textures
165 Console.WriteLine();
166 if (info.HaveTextures)
167 {
168 Console.WriteLine("Texture List:");
169 foreach (Texture t in info.Textures)
170 {
171 Console.WriteLine("\tName: " + t.FromFileName);
172 Console.WriteLine("\tType: " + t.TextureType);
173 Console.WriteLine("\tWidth: " + t.Width);
174 Console.WriteLine("\tHeight: " + t.Height);
175 Console.WriteLine("\tEncoding: " + t.Encoding);
176 Console.WriteLine("\tSubFormat: " + t.SubFormat);
177 // layout
178 Console.WriteLine("\tBytes Per Pixel: " + t.Layout.BytesPerPixel);
179 Console.WriteLine("\tShiftForComponent: " + new arraytostring<int, int[]>(t.Layout.ShiftForComponent));
180 Console.WriteLine("\tBitsForComponent: " + new arraytostring<int, int[]>(t.Layout.BitsForComponent));
181 // images
182 Console.WriteLine("\tImage List:");
183 foreach (Image img in t.Images)
184 {
185 foreach (MIPLevel mip in img.MIPLevels)
186 {
187 Console.WriteLine("\t\tMipLevel Stride: " + mip.Stride);
188 if (mip.Pixels.Count > 0)
189 {
190 Console.WriteLine("\t\tMipLevel Pixel: " + "{Pixel Data " + "[" + mip.Pixels.Count + "]}");
191 //// export image
192 //mip.Pixels.Export(@"exported_images\" + t.FromFileName.Name, t.Width, t.Height, mip.Stride);
193 }
194 }
195 }
196 Console.WriteLine("\tExtendedData: " + t.ExtendedData);
197 Console.WriteLine();
198 }
199 }
200 else { Console.WriteLine("Texture List: " + "No Textures Available"); }
201 Console.WriteLine("Press {ENTER} to Continue."); Console.ReadLine();
202 #endregion
203
204 #region Read Materials
205 Console.WriteLine();
206 if (info.HaveMaterials)
207 {
208 Console.WriteLine("Material List:");
209 foreach (Material m in info.Materials)
210 {
211 Console.WriteLine("\tMaterial Name: " + m.Name);
212 Console.WriteLine("\t\tMaterial IsTexture: " + m.IsTexture.ToString());
213 if (m.IsTexture)
214 {
215 Texture t = m.Texture;
216 Console.WriteLine("\t\tTexture:");
217 Console.WriteLine("\t\t\tName: " + t.FromFileName);
218 Console.WriteLine("\t\t\tType: " + t.TextureType);
219 Console.WriteLine("\t\t\tWidth: " + t.Width);
220 Console.WriteLine("\t\t\tHeight: " + t.Height);
221 Console.WriteLine("\t\t\tEncoding: " + t.Encoding);
222 Console.WriteLine("\t\t\tSubFormat: " + t.SubFormat);
223 // layout
224 Console.WriteLine("\t\t\tBytes Per Pixel: " + t.Layout.BytesPerPixel);
225 Console.WriteLine("\t\t\tShiftForComponent: " + new arraytostring<int, int[]>(t.Layout.ShiftForComponent));
226 Console.WriteLine("\t\t\tBitsForComponent: " + new arraytostring<int, int[]>(t.Layout.BitsForComponent));
227
228
229 Console.WriteLine("\t\t\tImage List:");
230 foreach (Image img in t.Images)
231 {
232 foreach (MIPLevel mip in img.MIPLevels)
233 {
234 Console.WriteLine("\t\t\t\tMipLevel Stride: " + mip.Stride);
235 if (mip.Pixels.Count > 0)
236 {
237 Console.WriteLine("\t\t\t\tMipLevel Pixel: " + "{Pixel Data " + "[" + mip.Pixels.Count + "]}");
238 //// export image
239 //mip.Pixels.Export(@"exported_images\" + t.FromFileName.Name, t.Width, t.Height, mip.Stride);
240 }
241 }
242 }
243
244 Console.WriteLine("\t\t\tExtendedData: " + t.ExtendedData);
245 Console.WriteLine();
246 }
247 Console.WriteLine("\t\tExtendedData: " + m.ExtendedData);
248 Console.WriteLine();
249 }
250 }
251 else { Console.WriteLine("Material List: " + "No Materials Available"); }
252 Console.WriteLine("Press {ENTER} to Continue."); Console.ReadLine();
253 #endregion
254
255
256 #region Read Skeletons
257 Console.WriteLine();
258 if (info.HaveSkeletons)
259 {
260 Console.WriteLine("Skeleton List:");
261 foreach (Skeleton s in info.Skeletons)
262 {
263 Console.WriteLine("\tSkeleton Name: " + s.SkeletonName);
264 Console.WriteLine("\tSkeleton LodType: " + s.LodType);
265 Console.WriteLine("\tBones:");
266 foreach (Bone b in s.Bones)
267 {
268 Console.WriteLine("\t\tName: " + b.BoneName);
269 Console.WriteLine("\t\tParent Index: " + b.ParentIndex);
270 Console.WriteLine("\t\tLod Error: " + b.LodError);
271 Console.WriteLine("\t\tTransform: " + b.Transform.ToString());
272 if (b.HasLightInfo) { Console.WriteLine("\t\tLightInfo ExtendedData: " + b.LightInfo.ExtendedData); }
273 else { Console.WriteLine("\t\tLightInfo ExtendedData: " + "No LightInfo"); }
274 if (b.HasCameraInfo) { Console.WriteLine("\t\tCameraInfo ExtendedData: " + b.CameraInfo.ExtendedData); }
275 else { Console.WriteLine("\t\tCameraInfo ExtendedData: " + "No CameraInfo"); }
276 Console.WriteLine();
277 }
278 Console.WriteLine("\t\tExtendedData: " + s.ExtendedData);
279 Console.WriteLine();
280 }
281
282 }
283 else { Console.WriteLine("Skeleton List: " + "No Skeletons Available"); }
284 Console.WriteLine("Press {ENTER} to Continue."); Console.ReadLine();
285 #endregion
286 }
287 #endregion
288
289
290 catch (granny2apiloadexception ex)
291 {
292 Console.WriteLine(ex.Message);
293 }
294 catch (Exception ex)
295 {
296 RuntimeWrappedException rwe = ex as RuntimeWrappedException;
297 if (rwe != null)
298 {
299 Console.WriteLine(rwe.ToString());
300 }
301 else
302 {
303 Console.WriteLine(ex.Message);
304 }
305 }
306 }
307 }
308 }
309
310
311

  ViewVC Help
Powered by ViewVC 1.1.22