ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/gr2lib/trunk/gr2lib_UnitTest/Program.cs
Revision: 90
Committed: Sat Jul 17 00:00:16 2010 UTC (13 years, 4 months ago) by william
File size: 12752 byte(s)
Log Message:
Add boolean indicators, that indicate if each type is present

File Contents

# Content
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4
5 using gr2lib.core;
6 //using gr2lib.core.coretypes;
7 using gr2lib.core.apiversion;
8 using gr2lib.core.exceptions;
9 using gr2lib.core.helpers;
10 using gr2lib.core.coretypes.implementation;
11 using System.Runtime.CompilerServices;
12
13 namespace gr2lib_UnitTest
14 {
15
16 class Program
17 {
18 static void Main(string[] args)
19 {
20 string GrannyFilename = shared.GRANNY_TEST_FILE;
21 try
22 {
23 #region Check Granny2 API Version
24 // Setup access to check loaded Granny2 API Version
25 granny2apiversion apiversion = new granny2apiversion(shared.EXPECTED_API_VERSION);
26
27 // Check if the Loaded API Version Matches
28 if (!apiversion.apiversionsmatch)
29 {
30 // the loaded version does not match
31 Console.WriteLine("Warning:\n" +
32 "\t Loaded Granny2 DLL Version: " + apiversion.apiversion.version + "\n" +
33 "\t Expected Version: " + apiversion.expectedapiversion.version);
34 // return from void to exit application
35 return;
36 }
37 else
38 {
39 // the loaded version matches
40 Console.WriteLine("Loaded granny2.dll: " + apiversion.apiversion.version);
41 }
42 #endregion
43
44 #region Parse Commandline
45 if (args.Length == 1)
46 {
47 GrannyFilename = args[0];
48 }
49 else if (args.Length > 1)
50 {
51 throw new InvalidOperationException("ERROR: Recieved Invalid Commandline: " + new arraytostring<string, string[]>(args));
52 }
53
54 if (System.IO.File.Exists(GrannyFilename))
55 {
56 Console.WriteLine("Using Granny2 File: " + GrannyFilename);
57 }
58 else
59 {
60 throw new System.IO.FileNotFoundException("Unable to find: " + GrannyFilename);
61 }
62 #endregion
63
64 #region Read Granny2 Data
65
66 grnfileinfo info = grnfileinfo.ReadFromFile(GrannyFilename);
67
68 #region Read FromFileName
69 Console.WriteLine();
70 if (info.HaveFromFileName)
71 {
72 Console.WriteLine("From File Name: " + info.FromFileName);
73 Console.WriteLine("ExtendedData: " + info.ExtendedData);
74 }
75 else { Console.WriteLine("From File Name: " + "No From File Name Available"); }
76
77 #endregion
78
79 #region Read ArtToolInfo
80 Console.WriteLine();
81 if (info.HaveArtToolInfo)
82 {
83 Console.WriteLine("Art Tool Data:");
84 Console.WriteLine("\tTool Name: " + info.ArtToolInfo.FromArtToolName);
85 Console.WriteLine("\tTool Version: " + string.Format("{0}.{1}", info.ArtToolInfo.ArtToolMajorRevision, info.ArtToolInfo.ArtToolMinorRevision));
86 Console.WriteLine("\tTool Units Per Meter: " + info.ArtToolInfo.UnitsPerMeter);
87
88 Console.WriteLine("\tTool Origin: " + string.Format("[{0},{1},{2}]", info.ArtToolInfo.Origin.x, info.ArtToolInfo.Origin.y, info.ArtToolInfo.Origin.z));
89 Console.WriteLine("\tTool Right: " + string.Format("[{0},{1},{2}]", info.ArtToolInfo.Right.x, info.ArtToolInfo.Right.y, info.ArtToolInfo.Right.z));
90 Console.WriteLine("\tTool Up: " + string.Format("[{0},{1},{2}]", info.ArtToolInfo.Up.x, info.ArtToolInfo.Up.y, info.ArtToolInfo.Up.z));
91 Console.WriteLine("\tTool Back: " + string.Format("[{0},{1},{2}]", info.ArtToolInfo.Back.x, info.ArtToolInfo.Back.y, info.ArtToolInfo.Back.z));
92
93 Console.WriteLine("\tTool ExtendedData: " + info.ArtToolInfo.ExtendedData);
94 }
95 else { Console.WriteLine("Art Tool Data: " + "No Art Tool Info Available"); }
96 #endregion
97
98 #region Read ExporterInfo
99 Console.WriteLine();
100 if (info.HaveExporterInfo)
101 {
102 Console.WriteLine("Exporter Info:");
103 Console.WriteLine("\tExporter Name: " + info.ExporterInfo.ExporterName);
104
105 Console.WriteLine("\tExporter Version: " +
106 string.Format("{0}.{1}.{2}.{3}",
107 info.ExporterInfo.ExporterMajorRevision,
108 info.ExporterInfo.ExporterMinorRevision,
109 info.ExporterInfo.ExporterCustomization,
110 info.ExporterInfo.ExporterBuildNumber));
111
112 Console.WriteLine("\tExporter ExtendedData: " + info.ExporterInfo.ExtendedData);
113 }
114 else { Console.WriteLine("Exporter Info: " + "No Exporter Info Available"); }
115 #endregion
116
117 #region Read Textures
118 Console.WriteLine();
119 if (info.HaveTextures)
120 {
121 Console.WriteLine("Texture List:");
122 foreach (Texture t in info.Textures)
123 {
124 Console.WriteLine("\tName: " + t.FromFileName);
125 Console.WriteLine("\tType: " + t.TextureType);
126 Console.WriteLine("\tWidth: " + t.Width);
127 Console.WriteLine("\tHeight: " + t.Height);
128 Console.WriteLine("\tEncoding: " + t.Encoding);
129 Console.WriteLine("\tSubFormat: " + t.SubFormat);
130 // layout
131 Console.WriteLine("\tBytes Per Pixel: " + t.Layout.BytesPerPixel);
132 Console.WriteLine("\tShiftForComponent: " + new arraytostring<int, int[]>(t.Layout.ShiftForComponent));
133 Console.WriteLine("\tBitsForComponent: " + new arraytostring<int, int[]>(t.Layout.BitsForComponent));
134 // images
135 Console.WriteLine("\tImage List:");
136 foreach (Image img in t.Images)
137 {
138 foreach (MIPLevel mip in img.MIPLevels)
139 {
140 Console.WriteLine("\t\tMipLevel Stride: " + mip.Stride);
141 if (mip.Pixels.Count > 0)
142 {
143 Console.WriteLine("\t\tMipLevel Pixel: " + "{Pixel Data " + "[" + mip.Pixels.Count + "]}");
144 //// export image
145 //mip.Pixels.Export(@"exported_images\" + t.FromFileName.Name, t.Width, t.Height, mip.Stride);
146 }
147 }
148 }
149 Console.WriteLine("\tExtendedData: " + t.ExtendedData);
150 Console.WriteLine();
151 }
152 }
153 else { Console.WriteLine("Texture List: " + "No Textures Available"); }
154 #endregion
155
156 #region Read Materials
157 Console.WriteLine();
158 if (info.HaveMaterials)
159 {
160 Console.WriteLine("Material List:");
161 foreach (Material m in info.Materials)
162 {
163 Console.WriteLine("\tMaterial Name: " + m.Name);
164 Console.WriteLine("\t\tMaterial IsTexture: " + m.IsTexture.ToString());
165 if (m.IsTexture)
166 {
167 Texture t = m.Texture;
168 Console.WriteLine("\t\tTexture:");
169 Console.WriteLine("\t\t\tName: " + t.FromFileName);
170 Console.WriteLine("\t\t\tType: " + t.TextureType);
171 Console.WriteLine("\t\t\tWidth: " + t.Width);
172 Console.WriteLine("\t\t\tHeight: " + t.Height);
173 Console.WriteLine("\t\t\tEncoding: " + t.Encoding);
174 Console.WriteLine("\t\t\tSubFormat: " + t.SubFormat);
175 // layout
176 Console.WriteLine("\t\t\tBytes Per Pixel: " + t.Layout.BytesPerPixel);
177 Console.WriteLine("\t\t\tShiftForComponent: " + new arraytostring<int, int[]>(t.Layout.ShiftForComponent));
178 Console.WriteLine("\t\t\tBitsForComponent: " + new arraytostring<int, int[]>(t.Layout.BitsForComponent));
179
180
181 Console.WriteLine("\t\t\tImage List:");
182 foreach (Image img in t.Images)
183 {
184 foreach (MIPLevel mip in img.MIPLevels)
185 {
186 Console.WriteLine("\t\t\t\tMipLevel Stride: " + mip.Stride);
187 if (mip.Pixels.Count > 0)
188 {
189 Console.WriteLine("\t\t\t\tMipLevel Pixel: " + "{Pixel Data " + "[" + mip.Pixels.Count + "]}");
190 //// export image
191 //mip.Pixels.Export(@"exported_images\" + t.FromFileName.Name, t.Width, t.Height, mip.Stride);
192 }
193 }
194 }
195
196 Console.WriteLine("\t\t\tExtendedData: " + t.ExtendedData);
197 Console.WriteLine();
198 }
199 Console.WriteLine("\t\tExtendedData: " + m.ExtendedData);
200 Console.WriteLine();
201 }
202 }
203 else { Console.WriteLine("Material List: " + "No Materials Available"); }
204 #endregion
205
206
207 #region Read Skeletons
208 Console.WriteLine();
209 if (info.HaveSkeletons)
210 {
211 Console.WriteLine("Skeleton List:");
212 foreach (Skeleton s in info.Skeletons)
213 {
214 Console.WriteLine("\tSkeleton Name: " + s.SkeletonName);
215 Console.WriteLine("\tSkeleton LodType: " + s.LodType);
216 Console.WriteLine("\tBones:");
217 foreach (Bone b in s.Bones)
218 {
219 Console.WriteLine("\t\tName: " + b.BoneName);
220 Console.WriteLine("\t\tParent Index: " + b.ParentIndex);
221 Console.WriteLine("\t\tLod Error: " + b.LodError);
222 Console.WriteLine("\t\tTransform: " + b.Transform.ToString());
223 if (b.HasLightInfo) { Console.WriteLine("\t\tLightInfo ExtendedData: " + b.LightInfo.ExtendedData); }
224 else { Console.WriteLine("\t\tLightInfo ExtendedData: " + "No LightInfo"); }
225 if (b.HasCameraInfo) { Console.WriteLine("\t\tCameraInfo ExtendedData: " + b.CameraInfo.ExtendedData); }
226 else { Console.WriteLine("\t\tCameraInfo ExtendedData: " + "No CameraInfo"); }
227 Console.WriteLine();
228 }
229 Console.WriteLine("\t\tExtendedData: " + s.ExtendedData);
230 Console.WriteLine();
231 }
232
233 }
234 else { Console.WriteLine("Skeleton List: " + "No Skeletons Available"); }
235 #endregion
236 }
237 #endregion
238
239
240 catch (granny2apiloadexception ex)
241 {
242 Console.WriteLine(ex.Message);
243 }
244 catch (Exception ex)
245 {
246 RuntimeWrappedException rwe = ex as RuntimeWrappedException;
247 if (rwe != null)
248 {
249 Console.WriteLine(rwe.ToString());
250 }
251 else
252 {
253 Console.WriteLine(ex.Message);
254 }
255 }
256 }
257 }
258 }
259