/[Sims3RigEditor]/trunk/gr2lib_cpp/gr2lib_rigeditor_frm.h
ViewVC logotype

Contents of /trunk/gr2lib_cpp/gr2lib_rigeditor_frm.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 81 - (show annotations) (download)
Sat Aug 14 12:49:25 2010 UTC (9 years, 6 months ago) by william
File MIME type: text/plain
File size: 48759 byte(s)
remove DoPostSaveOperations <-- not needed

1 #define _CRT_SECURE_NO_WARNINGS
2 #pragma warning( disable : 4100 ) // disable 'unreferenced formal parameter' warnings
3 #pragma warning( disable : 4101 ) // disable 'unreferenced local variable' warnings
4 #pragma warning( disable : 4482 ) // disable 'nonstandard extension used' warnings (related to case switch statements using enums)
5
6 #define SHOW_DEBUG_MENU // if defined, will show the debug menu -> else it will not be shown
7
8 #define granny_pixel_layout_bitshift_size 4
9
10 #pragma once
11 //#include "gr2lib_core.h"
12 //#include "gr2lib_core_imports.h"
13 #ifndef GR2LIB_RIGEDITOR_FRM_H
14 #define GR2LIB_RIGEDITOR_FRM_H
15 #include "..\gr2lib_cpp_typedefs\core.h"
16 #include "grannyfile.h"
17 //#include "guicon.h"
18 #include "VSDebugOutput.h"
19 #include "GrannyFileWriter.h"
20 #include <stdio.h>
21 #include <iostream>
22 #include <stdlib.h>
23 #include <assert.h>
24 #include <string>
25 #include <sstream>
26 #include <vcclr.h>
27 using namespace std;
28
29 using namespace gr2lib_cpp::typedefs;
30 using namespace gr2lib::core;
31 using namespace gr2lib::core::coretypes::implementation;
32 using namespace gr2lib::core::apiversion;
33 using namespace gr2lib::core::ui::helpers;
34 using namespace gr2lib::core::helpers;
35 using namespace System;
36 using namespace System::ComponentModel;
37 using namespace System::Collections;
38 using namespace System::Collections::Generic;
39 using namespace System::Windows::Forms;
40 using namespace System::Data;
41 using namespace System::Drawing;
42 using namespace System::Runtime::InteropServices;
43 //using namespace Microsoft::Xna::Framework;
44 //using namespace Microsoft::Xna::Framework::Graphics;
45 //
46 //namespace gr2lib
47 //{
48 // namespace core
49 // {
50 // namespace rigeditor
51 // {
52 /// <summary>
53 /// Summary for gr2lib_rigeditor_frm
54 ///
55 /// WARNING: If you change the name of this class, you will need to change the
56 /// 'Resource File Name' property for the managed resource compiler tool
57 /// associated with all .resx files this class depends on. Otherwise,
58 /// the designers will not be able to interact properly with localized
59 /// resources associated with this form.
60 /// </summary>
61 public ref class gr2lib_rigeditor_frm : public System::Windows::Forms::Form
62 {
63 private:
64 grannyfile* _grn_file;
65 void LogApplicationStartup()
66 {
67 const char* ApplicationName = "GR2Lib Rig Editor: ";
68
69 const char* product_version = (char*)(void*)Marshal::StringToHGlobalAnsi(Application::ProductVersion);
70 const char* version_prefix = "v";
71 const char* startup_string = " {Starting up...}";
72
73
74 int msg_malloc = (strlen(ApplicationName) + strlen(product_version) + strlen(version_prefix) + strlen(startup_string)) + 3;
75
76 char* msg = (char*)malloc(msg_malloc);
77 for (int i=0; i<msg_malloc; i++) {
78 msg[i] = 0; // Initialize all elements to zero.
79 }
80
81 strcat(msg,ApplicationName);
82 strcat(msg,version_prefix);
83 strcat(msg,product_version);
84 strcat(msg,startup_string);
85 strcat(msg,"\n");
86 _grn_file->_logger->LogMessage(msg);
87 }
88 public:
89 gr2lib_rigeditor_frm(void)
90 {
91 InitializeComponent();
92 _grn_file = new grannyfile();
93 //
94 //TODO: Add the constructor code here
95 //
96 // Log Application Startup
97 LogApplicationStartup();
98 }
99 gr2lib_rigeditor_frm(grannyfile* grn_file)
100 {
101 InitializeComponent();
102 // parse art tool info
103 _grn_file = grn_file;
104
105 // Log Application Startup
106 LogApplicationStartup();
107
108 this->GR2LibPropertyWrapper = gcnew GR2LibWrapper();
109 ConvertToManaged();
110 propgrid->SelectedObject = this->GR2LibPropertyWrapper;
111
112 }
113
114 protected:
115 /// <summary>
116 /// Clean up any resources being used.
117 /// </summary>
118 ~gr2lib_rigeditor_frm()
119 {
120 if (components)
121 {
122 delete components;
123 }
124 }
125 private: System::Windows::Forms::PropertyGrid^ propgrid;
126 protected:
127 private: System::Windows::Forms::MenuStrip^ mainmenu;
128 private: System::Windows::Forms::ToolStripMenuItem^ mnuFile;
129 private: System::Windows::Forms::ToolStripMenuItem^ mnuItemExit;
130 private: System::Windows::Forms::ToolStripMenuItem^ mnuItemOpen;
131 private: System::Windows::Forms::ToolStripMenuItem^ mnuItemSave;
132 private: System::Windows::Forms::ToolStripMenuItem^ mnuItemSaveAs;
133 private: System::Windows::Forms::ToolStripMenuItem^ mnuDebug;
134 private: System::Windows::Forms::ToolStripMenuItem^ mnuDebug_UnitTests;
135 private: System::Windows::Forms::ToolStripMenuItem^ mnuTestArtToolInfoReturnValues;
136
137 private: System::Windows::Forms::OpenFileDialog^ RigLoader;
138 private: System::Windows::Forms::ToolStripMenuItem^ mnuTestExporterInfoReturnValues;
139 private: System::Windows::Forms::SaveFileDialog^ RigSaver;
140 private: System::Windows::Forms::ToolStripMenuItem^ mnuItemClose;
141 private: System::Windows::Forms::ToolStripMenuItem^ mnuItemTestDDSRender;
142
143
144
145
146
147 protected:
148
149 private:
150 /// <summary>
151 /// Required designer variable.
152 /// </summary>
153 System::ComponentModel::Container ^components;
154
155 #pragma region Windows Form Designer generated code
156 /// <summary>
157 /// Required method for Designer support - do not modify
158 /// the contents of this method with the code editor.
159 /// </summary>
160 void InitializeComponent(void)
161 {
162 this->propgrid = (gcnew System::Windows::Forms::PropertyGrid());
163 this->mainmenu = (gcnew System::Windows::Forms::MenuStrip());
164 this->mnuFile = (gcnew System::Windows::Forms::ToolStripMenuItem());
165 this->mnuItemOpen = (gcnew System::Windows::Forms::ToolStripMenuItem());
166 this->mnuItemClose = (gcnew System::Windows::Forms::ToolStripMenuItem());
167 this->mnuItemSave = (gcnew System::Windows::Forms::ToolStripMenuItem());
168 this->mnuItemSaveAs = (gcnew System::Windows::Forms::ToolStripMenuItem());
169 this->mnuItemExit = (gcnew System::Windows::Forms::ToolStripMenuItem());
170 this->mnuDebug = (gcnew System::Windows::Forms::ToolStripMenuItem());
171 this->mnuDebug_UnitTests = (gcnew System::Windows::Forms::ToolStripMenuItem());
172 this->mnuTestArtToolInfoReturnValues = (gcnew System::Windows::Forms::ToolStripMenuItem());
173 this->mnuTestExporterInfoReturnValues = (gcnew System::Windows::Forms::ToolStripMenuItem());
174 this->mnuItemTestDDSRender = (gcnew System::Windows::Forms::ToolStripMenuItem());
175 this->RigLoader = (gcnew System::Windows::Forms::OpenFileDialog());
176 this->RigSaver = (gcnew System::Windows::Forms::SaveFileDialog());
177 this->mainmenu->SuspendLayout();
178 this->SuspendLayout();
179 //
180 // propgrid
181 //
182 this->propgrid->Dock = System::Windows::Forms::DockStyle::Fill;
183 this->propgrid->Location = System::Drawing::Point(0, 24);
184 this->propgrid->Name = L"propgrid";
185 this->propgrid->PropertySort = System::Windows::Forms::PropertySort::Categorized;
186 this->propgrid->Size = System::Drawing::Size(558, 456);
187 this->propgrid->TabIndex = 4;
188 this->propgrid->ToolbarVisible = false;
189 //
190 // mainmenu
191 //
192 this->mainmenu->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {this->mnuFile, this->mnuDebug});
193 this->mainmenu->Location = System::Drawing::Point(0, 0);
194 this->mainmenu->Name = L"mainmenu";
195 this->mainmenu->Size = System::Drawing::Size(558, 24);
196 this->mainmenu->TabIndex = 3;
197 this->mainmenu->Text = L"menuStrip1";
198 //
199 // mnuFile
200 //
201 this->mnuFile->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(5) {this->mnuItemOpen,
202 this->mnuItemClose, this->mnuItemSave, this->mnuItemSaveAs, this->mnuItemExit});
203 this->mnuFile->Name = L"mnuFile";
204 this->mnuFile->Size = System::Drawing::Size(37, 20);
205 this->mnuFile->Text = L"&File";
206 //
207 // mnuItemOpen
208 //
209 this->mnuItemOpen->Name = L"mnuItemOpen";
210 this->mnuItemOpen->Size = System::Drawing::Size(114, 22);
211 this->mnuItemOpen->Text = L"&Open";
212 this->mnuItemOpen->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuItemOpen_Click);
213 //
214 // mnuItemClose
215 //
216 this->mnuItemClose->Name = L"mnuItemClose";
217 this->mnuItemClose->Size = System::Drawing::Size(114, 22);
218 this->mnuItemClose->Text = L"&Close";
219 this->mnuItemClose->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuItemClose_Click);
220 //
221 // mnuItemSave
222 //
223 this->mnuItemSave->Name = L"mnuItemSave";
224 this->mnuItemSave->Size = System::Drawing::Size(114, 22);
225 this->mnuItemSave->Text = L"&Save";
226 this->mnuItemSave->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuItemSave_Click);
227 //
228 // mnuItemSaveAs
229 //
230 this->mnuItemSaveAs->Name = L"mnuItemSaveAs";
231 this->mnuItemSaveAs->Size = System::Drawing::Size(114, 22);
232 this->mnuItemSaveAs->Text = L"Save &As";
233 this->mnuItemSaveAs->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuItemSaveAs_Click);
234 //
235 // mnuItemExit
236 //
237 this->mnuItemExit->Name = L"mnuItemExit";
238 this->mnuItemExit->Size = System::Drawing::Size(114, 22);
239 this->mnuItemExit->Text = L"&Exit";
240 this->mnuItemExit->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuItemExit_Click);
241 //
242 // mnuDebug
243 //
244 this->mnuDebug->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {this->mnuDebug_UnitTests,
245 this->mnuItemTestDDSRender});
246 this->mnuDebug->Name = L"mnuDebug";
247 this->mnuDebug->Size = System::Drawing::Size(56, 20);
248 this->mnuDebug->Text = L"&DEBUG";
249 //
250 // mnuDebug_UnitTests
251 //
252 this->mnuDebug_UnitTests->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {this->mnuTestArtToolInfoReturnValues,
253 this->mnuTestExporterInfoReturnValues});
254 this->mnuDebug_UnitTests->Name = L"mnuDebug_UnitTests";
255 this->mnuDebug_UnitTests->Size = System::Drawing::Size(161, 22);
256 this->mnuDebug_UnitTests->Text = L"&Unit Tests...";
257 //
258 // mnuTestArtToolInfoReturnValues
259 //
260 this->mnuTestArtToolInfoReturnValues->Name = L"mnuTestArtToolInfoReturnValues";
261 this->mnuTestArtToolInfoReturnValues->Size = System::Drawing::Size(238, 22);
262 this->mnuTestArtToolInfoReturnValues->Text = L"Test ArtoolInfo Rerturn values";
263 this->mnuTestArtToolInfoReturnValues->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuTestArtToolInfoReturnValues_Click);
264 //
265 // mnuTestExporterInfoReturnValues
266 //
267 this->mnuTestExporterInfoReturnValues->Name = L"mnuTestExporterInfoReturnValues";
268 this->mnuTestExporterInfoReturnValues->Size = System::Drawing::Size(238, 22);
269 this->mnuTestExporterInfoReturnValues->Text = L"Test ExporterInfo Return Values";
270 this->mnuTestExporterInfoReturnValues->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuTestExporterInfoReturnValues_Click);
271 //
272 // mnuItemTestDDSRender
273 //
274 this->mnuItemTestDDSRender->Name = L"mnuItemTestDDSRender";
275 this->mnuItemTestDDSRender->Size = System::Drawing::Size(161, 22);
276 this->mnuItemTestDDSRender->Text = L"Test DDS Render";
277 //
278 // RigLoader
279 //
280 this->RigLoader->DefaultExt = L"gr2";
281 this->RigLoader->Filter = L"Granny2 Files|*.gr2;*.grannyrig";
282 this->RigLoader->SupportMultiDottedExtensions = true;
283 this->RigLoader->Title = L"Please choose the Granny2 Rig file to load";
284 //
285 // RigSaver
286 //
287 this->RigSaver->DefaultExt = L"gr2";
288 this->RigSaver->Filter = L"Granny2 Files|*.gr2;*.grannyrig";
289 this->RigSaver->SupportMultiDottedExtensions = true;
290 this->RigSaver->Title = L"Please select the Granny2 Rig to write to or create";
291 //
292 // gr2lib_rigeditor_frm
293 //
294 this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
295 this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
296 this->ClientSize = System::Drawing::Size(558, 480);
297 this->Controls->Add(this->propgrid);
298 this->Controls->Add(this->mainmenu);
299 this->Name = L"gr2lib_rigeditor_frm";
300 this->Text = L"gr2lib_rigeditor_frm";
301 this->Load += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::gr2lib_rigeditor_frm_Load);
302 this->FormClosed += gcnew System::Windows::Forms::FormClosedEventHandler(this, &gr2lib_rigeditor_frm::gr2lib_rigeditor_frm_FormClosed);
303 this->mainmenu->ResumeLayout(false);
304 this->mainmenu->PerformLayout();
305 this->ResumeLayout(false);
306 this->PerformLayout();
307
308 }
309 #pragma endregion
310
311
312
313 #pragma region MarshalToManagedNative
314 //ArtToolInfo^ _ArtToolInfo;
315 //ExporterInfo^ _ExporterInfo;
316 GR2LibWrapper^ GR2LibPropertyWrapper;
317 #pragma region ManagedNativeParsing
318 void ConvertToManaged()
319 {
320 // Art Tool info
321 ArtToolInfo_ToManaged(_grn_file->GrannyFileInfo->ArtToolInfo);
322 // Exporter Info
323 ExporterInfo_ToManaged(_grn_file->GrannyFileInfo->ExporterInfo);
324 // Texture List
325 Textures_ToManaged(_grn_file->GrannyFileInfo->Textures,_grn_file->GrannyFileInfo->TextureCount);
326 // Material List
327 Materials_ToManaged(_grn_file->GrannyFileInfo->Materials,_grn_file->GrannyFileInfo->MaterialCount);
328 // Skeleton List
329 Skeletons_ToManaged(_grn_file->GrannyFileInfo->Skeletons, _grn_file->GrannyFileInfo->SkeletonCount);
330 }
331 void ConvertToNative()
332 {
333 // Art Tool info
334 ArtToolInfo_ToNative();
335 // Exporter Info
336 ExporterInfo_ToNative();
337 // Texture List
338 Textures_ToNative();
339 // Material List
340 Materials_ToNative();
341 // Skeleton List
342 Skeletons_ToNative();
343 }
344 #pragma endregion
345 #pragma region MarshalToMananaged
346 #pragma region ArtToolInfo_ToManaged
347 void ArtToolInfo_ToManaged(granny_art_tool_info* toolinfo)
348 {
349 //GR2LibPropertyWrapper->ArtToolInfo = gcnew ArtToolInfo();
350 if (toolinfo != NULL)
351 {
352 GR2LibPropertyWrapper->ArtToolInfo->FromArtToolName = gcnew String(reinterpret_cast<const char*>(toolinfo->FromArtToolName));
353
354 // Tool Vector
355 Vector3* Origin = new Vector3(
356 toolinfo->Origin[0],
357 toolinfo->Origin[1],
358 toolinfo->Origin[2]);
359 Vector3* Right = new Vector3(
360 toolinfo->RightVector[0],
361 toolinfo->RightVector[1],
362 toolinfo->RightVector[2]);
363 Vector3* Up = new Vector3(
364 toolinfo->UpVector[0],
365 toolinfo->UpVector[1],
366 toolinfo->UpVector[2]);
367 Vector3* Back = new Vector3(
368 toolinfo->BackVector[0],
369 toolinfo->BackVector[1],
370 toolinfo->BackVector[2]);
371 GR2LibPropertyWrapper->ArtToolInfo->Vector = gcnew ArtToolInfoVector(*Origin,*Right,*Up,*Back);
372
373 // Tool Version
374 GR2LibPropertyWrapper->ArtToolInfo->ToolVersion = gcnew ArtToolInfoVersion(toolinfo->ArtToolMajorRevision,toolinfo->ArtToolMinorRevision);
375 // Tool Units Per Meter
376 GR2LibPropertyWrapper->ArtToolInfo->UnitsPerMeter = toolinfo->UnitsPerMeter;
377 // Get Extended Data
378 GR2LibPropertyWrapper->ArtToolInfo->ExtendedData = ExtendedData_ToManaged(toolinfo->ExtendedData);
379 }
380 }
381 #pragma endregion
382 #pragma region ExporterInfo_ToManaged
383 void ExporterInfo_ToManaged(granny_exporter_info* toolinfo)
384 {
385 //GR2LibPropertyWrapper->ExporterInfo = gcnew ExporterInfo();
386 if (toolinfo != NULL)
387 {
388 GR2LibPropertyWrapper->ExporterInfo->ExporterName = gcnew String(reinterpret_cast<const char*>(toolinfo->ExporterName));
389 GR2LibPropertyWrapper->ExporterInfo->Version = gcnew versiontype(
390 toolinfo->ExporterMajorRevision,
391 toolinfo->ExporterMinorRevision,
392 toolinfo->ExporterCustomization,
393 toolinfo->ExporterBuildNumber);
394 }
395 GR2LibPropertyWrapper->ExporterInfo->ExtendedData = ExtendedData_ToManaged(toolinfo->ExtendedData);
396 }
397 #pragma endregion
398 #pragma region Textures_ToManaged
399 void Textures_ToManaged(granny_texture** toolinfo, granny_int32 TextureCount)
400 {
401 if (toolinfo != NULL)
402 {
403 GR2LibPropertyWrapper->Textures = gcnew List<Texture^>();
404 for(int i=0;i<TextureCount;i++)
405 {
406 Texture^ t = gcnew Texture();
407
408 t->FromFileName = gcnew FilePath(gcnew String(reinterpret_cast<const char*>(toolinfo[i]->FromFileName)));
409 t->TextureType = gcnew NameValuePair<String^,gr2lib::core::typedefs::granny_texture_type>(
410 ::coreapi::EnumToStringSupport::GetGrannyEnumTypeString<gr2lib::core::typedefs::granny_texture_type>(
411 (gr2lib::core::typedefs::granny_texture_type)toolinfo[i]->TextureType),
412 (gr2lib::core::typedefs::granny_texture_type)toolinfo[i]->TextureType);
413 t->Width = toolinfo[i]->Width;
414 t->Height = toolinfo[i]->Height;
415 t->Encoding = gcnew NameValuePair<String^,gr2lib::core::typedefs::granny_texture_encoding>(
416 ::coreapi::EnumToStringSupport::GetGrannyEnumTypeString<gr2lib::core::typedefs::granny_texture_encoding>(
417 (gr2lib::core::typedefs::granny_texture_encoding)toolinfo[i]->Encoding),
418 (gr2lib::core::typedefs::granny_texture_encoding)toolinfo[i]->Encoding);
419 t->SubFormat = gcnew NameValuePair<String^,gr2lib::core::typedefs::granny_pixel_layout>(
420 ::coreapi::EnumToStringSupport::GetGrannyEnumTypeString<gr2lib::core::typedefs::granny_pixel_layout>(
421 (gr2lib::core::typedefs::granny_pixel_layout)toolinfo[i]->SubFormat),
422 (gr2lib::core::typedefs::granny_pixel_layout)toolinfo[i]->SubFormat);
423 t->Layout = gcnew gr2lib::core::coretypes::implementation::Layout();
424 t->Layout->BytesPerPixel = toolinfo[i]->Layout.BytesPerPixel;
425 for(int j=0;j<granny_pixel_layout_bitshift_size;j++)
426 {
427 t->Layout->ShiftForComponent[j] = toolinfo[i]->Layout.ShiftForComponent[j];
428 t->Layout->BitsForComponent[j] = toolinfo[i]->Layout.BitsForComponent[j];
429 }
430 t->Layout->NativePointer = *new IntPtr(&toolinfo[i]->Layout);
431
432 t->Images = gcnew List<gr2lib::core::coretypes::implementation::Image^>();
433 for(int j=0;j<toolinfo[i]->ImageCount;j++)
434 {
435 gr2lib::core::coretypes::implementation::Image^ img = gcnew gr2lib::core::coretypes::implementation::Image();
436 img->MIPLevels = gcnew List<gr2lib::core::coretypes::implementation::MIPLevel^>();
437
438 for(int k=0;k<toolinfo[i]->Images[j].MIPLevelCount;k++)
439 {
440 gr2lib::core::coretypes::implementation::MIPLevel^ mip = gcnew gr2lib::core::coretypes::implementation::MIPLevel();
441 mip->Stride = toolinfo[i]->Images[j].MIPLevels[k].Stride;
442 mip->Pixels = gcnew gr2lib::core::coretypes::implementation::Pixel();
443
444 unsigned char* bytes = (unsigned char*)malloc(toolinfo[i]->Images[j].MIPLevels[k].PixelByteCount);
445 for(int l =0;l<toolinfo[i]->Images[j].MIPLevels[k].PixelByteCount;l++)
446 {
447 bytes[l] =0;
448 }
449 bytes = (unsigned char*)toolinfo[i]->Images[j].MIPLevels[k].PixelBytes;
450
451 mip->Pixels->NativeTexture = t;
452 mip->Pixels->NativeTexturePointer = *new IntPtr(toolinfo[i]);
453 mip->Pixels->ImageIndex = j;
454 mip->Pixels->MipIndex = k;
455
456 for(int l =0;l<toolinfo[i]->Images[j].MIPLevels[k].PixelByteCount;l++)
457 {
458 mip->Pixels->PixelBytes->Add(bytes[l]);
459 }
460 img->MIPLevels->Add(mip);
461
462 }
463 t->Images->Add(img);
464 t->NativePointer = *new IntPtr(toolinfo[i]);
465 t->ExtendedData = ExtendedData_ToManaged(toolinfo[i]->ExtendedData);
466 }
467 GR2LibPropertyWrapper->Textures->Add(t);
468 }
469 }
470 }
471 #pragma endregion
472 #pragma region Materials_ToManaged
473 void Materials_ToManaged(granny_material** toolinfo, granny_int32 MaterialCount)
474 {
475 if (toolinfo != NULL)
476 {
477 GR2LibPropertyWrapper->Materials = gcnew List<Material^>();
478 for(int i=0;i<MaterialCount;i++)
479 {
480 Material^ m = gcnew Material();
481 if (toolinfo[i]->Texture != NULL) { m = gcnew Material(*new IntPtr(&toolinfo[i]->Texture)); }
482
483 m->Name = gcnew String(reinterpret_cast<const char*>(toolinfo[i]->Name));
484 m->ExtendedData = ExtendedData_ToManaged(toolinfo[i]->ExtendedData);
485 m->NativePointer = *new IntPtr(toolinfo[i]);
486 GR2LibPropertyWrapper->Materials->Add(m);
487 }
488 }
489 }
490 #pragma endregion
491 #pragma region Skeletons_ToManaged
492 void Skeletons_ToManaged(granny_skeleton** toolinfo, granny_int32 SkeletonCount)
493 {
494 if (toolinfo != NULL)
495 {
496 GR2LibPropertyWrapper->Skeletons = gcnew List<Skeleton^>();
497 for(int i=0;i<SkeletonCount;i++)
498 {
499 Skeleton^ s = gcnew Skeleton();
500 s->Name = gcnew String(reinterpret_cast<const char*>(toolinfo[i]->Name));
501 s->LODType = toolinfo[i]->LODType;
502 List<Bone^>^ bones = gcnew List<Bone^>();
503 for(int j=0;j<toolinfo[i]->BoneCount;j++)
504 {
505 Bone^ b = gcnew Bone();
506
507 b->Name = gcnew String(reinterpret_cast<const char*>(toolinfo[i]->Bones[j].Name));
508 b->ParentIndex = toolinfo[i]->Bones[j].ParentIndex;
509
510 Transform^ _transform = gcnew Transform();
511
512
513 _transform->Dimensions = toolinfo[i]->Bones[j].LocalTransform.Flags;
514 _transform->Origin = *gcnew Vector3(
515 toolinfo[i]->Bones[j].LocalTransform.Position[0],
516 toolinfo[i]->Bones[j].LocalTransform.Position[1],
517 toolinfo[i]->Bones[j].LocalTransform.Position[2]
518 );
519
520 _transform->Rotation = *gcnew Quaternion(
521 toolinfo[i]->Bones[j].LocalTransform.Orientation[0],
522 toolinfo[i]->Bones[j].LocalTransform.Orientation[1],
523 toolinfo[i]->Bones[j].LocalTransform.Orientation[2],
524 toolinfo[i]->Bones[j].LocalTransform.Orientation[3]
525 );
526 _transform->Scale = *gcnew Matrix33
527 (
528 *gcnew Vector3(
529 toolinfo[i]->Bones[j].LocalTransform.ScaleShear[0][0],
530 toolinfo[i]->Bones[j].LocalTransform.ScaleShear[0][1],
531 toolinfo[i]->Bones[j].LocalTransform.ScaleShear[0][2]),
532 *gcnew Vector3(
533 toolinfo[i]->Bones[j].LocalTransform.ScaleShear[1][0],
534 toolinfo[i]->Bones[j].LocalTransform.ScaleShear[1][1],
535 toolinfo[i]->Bones[j].LocalTransform.ScaleShear[1][2]),
536 *gcnew Vector3(
537 toolinfo[i]->Bones[j].LocalTransform.ScaleShear[2][0],
538 toolinfo[i]->Bones[j].LocalTransform.ScaleShear[2][1],
539 toolinfo[i]->Bones[j].LocalTransform.ScaleShear[2][2])
540 );
541
542
543
544 Matrix44^ _matrix44 = gcnew Matrix44(_transform->Matrix);
545 _matrix44->right = *gcnew Vector4(
546 toolinfo[i]->Bones[j].InverseWorld4x4[0][0],
547 toolinfo[i]->Bones[j].InverseWorld4x4[0][1],
548 toolinfo[i]->Bones[j].InverseWorld4x4[0][2],
549 toolinfo[i]->Bones[j].InverseWorld4x4[0][3]
550 );
551 _matrix44->up = *gcnew Vector4(
552 toolinfo[i]->Bones[j].InverseWorld4x4[1][0],
553 toolinfo[i]->Bones[j].InverseWorld4x4[1][1],
554 toolinfo[i]->Bones[j].InverseWorld4x4[1][2],
555 toolinfo[i]->Bones[j].InverseWorld4x4[1][3]
556 );
557 _matrix44->at = *gcnew Vector4(
558 toolinfo[i]->Bones[j].InverseWorld4x4[2][0],
559 toolinfo[i]->Bones[j].InverseWorld4x4[2][1],
560 toolinfo[i]->Bones[j].InverseWorld4x4[2][2],
561 toolinfo[i]->Bones[j].InverseWorld4x4[2][3]
562 );
563 _matrix44->pos = *gcnew Vector4(
564 toolinfo[i]->Bones[j].InverseWorld4x4[3][0],
565 toolinfo[i]->Bones[j].InverseWorld4x4[3][1],
566 toolinfo[i]->Bones[j].InverseWorld4x4[3][2],
567 toolinfo[i]->Bones[j].InverseWorld4x4[3][3]
568 );
569 _transform->Matrix = *_matrix44;
570 b->LocalTransform = _transform;
571 //b->InverseWorld4x4 = *_matrix44;
572 b->LODError = toolinfo[i]->Bones[j].LODError;
573 b->ExtendedData = ExtendedData_ToManaged(toolinfo[i]->Bones[j].ExtendedData);
574 bones->Add(b);
575 }
576 s->Bones = bones;
577 GR2LibPropertyWrapper->Skeletons->Add(s);
578 }
579 }
580 }
581 #pragma endregion
582 #pragma endregion
583 #pragma region MarshalToNative
584 #pragma region ArtToolInfo_ToNative
585 void ArtToolInfo_ToNative()
586 {
587 if (_grn_file->GrannyFileInfo->ArtToolInfo == NULL)
588 {
589 _grn_file->GrannyFileInfo->ArtToolInfo = new granny_art_tool_info();
590 }
591
592 _grn_file->GrannyFileInfo->ArtToolInfo->FromArtToolName = (char*)Marshal::StringToHGlobalAnsi(GR2LibPropertyWrapper->ArtToolInfo->FromArtToolName).ToPointer();
593 _grn_file->GrannyFileInfo->ArtToolInfo->ArtToolMajorRevision = GR2LibPropertyWrapper->ArtToolInfo->ToolVersion->Major;
594 _grn_file->GrannyFileInfo->ArtToolInfo->ArtToolMinorRevision = GR2LibPropertyWrapper->ArtToolInfo->ToolVersion->Minor;
595 _grn_file->GrannyFileInfo->ArtToolInfo->UnitsPerMeter = GR2LibPropertyWrapper->ArtToolInfo->UnitsPerMeter;
596
597
598 _grn_file->GrannyFileInfo->ArtToolInfo->Origin[0] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Origin.x;
599 _grn_file->GrannyFileInfo->ArtToolInfo->Origin[1] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Origin.y;
600 _grn_file->GrannyFileInfo->ArtToolInfo->Origin[2] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Origin.z;
601
602 _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[0] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Right.x;
603 _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[1] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Right.y;
604 _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[2] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Right.z;
605
606 _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[0] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Up.x;
607 _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[1] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Up.y;
608 _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[2] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Up.z;
609
610 _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[0] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Back.x;
611 _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[1] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Back.y;
612 _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[2] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Back.z;
613
614 _grn_file->GrannyFileInfo->ArtToolInfo->ExtendedData = ExtendedData_ToNative(GR2LibPropertyWrapper->ArtToolInfo->ExtendedData,_grn_file->GrannyFileInfo->ArtToolInfo->ExtendedData);
615
616 }
617 #pragma endregion
618 #pragma region ExporterInfo_ToNative
619 void ExporterInfo_ToNative()
620 {
621 if (_grn_file->GrannyFileInfo->ExporterInfo == NULL)
622 {
623 _grn_file->GrannyFileInfo->ExporterInfo = new granny_exporter_info();
624 }
625 _grn_file->GrannyFileInfo->ExporterInfo->ExporterName = (char*)Marshal::StringToHGlobalAnsi(GR2LibPropertyWrapper->ExporterInfo->ExporterName).ToPointer();
626 _grn_file->GrannyFileInfo->ExporterInfo->ExporterMajorRevision = GR2LibPropertyWrapper->ExporterInfo->Version->major;
627 _grn_file->GrannyFileInfo->ExporterInfo->ExporterMinorRevision = GR2LibPropertyWrapper->ExporterInfo->Version->minor;
628 _grn_file->GrannyFileInfo->ExporterInfo->ExporterCustomization = GR2LibPropertyWrapper->ExporterInfo->Version->customization;
629 _grn_file->GrannyFileInfo->ExporterInfo->ExporterBuildNumber = GR2LibPropertyWrapper->ExporterInfo->Version->build;
630 _grn_file->GrannyFileInfo->ExporterInfo->ExtendedData = ExtendedData_ToNative(GR2LibPropertyWrapper->ExporterInfo->ExtendedData,_grn_file->GrannyFileInfo->ExporterInfo->ExtendedData);
631 }
632 #pragma endregion
633 #pragma region Textures_ToNative
634 void Textures_ToNative()
635 {
636 //_grn_file->GrannyFileInfo->Textures = (granny_texture**)malloc(GR2LibPropertyWrapper->Textures->Count);
637 //for(int i=0;i<GR2LibPropertyWrapper->Textures->Count;i++) { _grn_file->GrannyFileInfo->Textures[i] = new granny_texture(); }
638
639 _grn_file->GrannyFileInfo->TextureCount = GR2LibPropertyWrapper->Textures->Count;
640 for(int i=0;i<_grn_file->GrannyFileInfo->TextureCount;i++)
641 {
642 _grn_file->GrannyFileInfo->Textures[i]->FromFileName = (char*)Marshal::StringToHGlobalAnsi(GR2LibPropertyWrapper->Textures[i]->FromFileName->FullPath).ToPointer();
643 _grn_file->GrannyFileInfo->Textures[i]->TextureType = (granny_int32)GR2LibPropertyWrapper->Textures[i]->TextureType->Value;
644 _grn_file->GrannyFileInfo->Textures[i]->Width = GR2LibPropertyWrapper->Textures[i]->Width;
645 _grn_file->GrannyFileInfo->Textures[i]->Height = GR2LibPropertyWrapper->Textures[i]->Height;
646 _grn_file->GrannyFileInfo->Textures[i]->Encoding = (granny_int32)GR2LibPropertyWrapper->Textures[i]->Encoding->Value;
647 _grn_file->GrannyFileInfo->Textures[i]->SubFormat = (granny_int32)GR2LibPropertyWrapper->Textures[i]->SubFormat->Value;
648
649 _grn_file->GrannyFileInfo->Textures[i]->Layout.BytesPerPixel = (granny_int32)GR2LibPropertyWrapper->Textures[i]->Layout->BytesPerPixel;
650 for(int j=0;j<granny_pixel_layout_bitshift_size;j++)
651 {
652 _grn_file->GrannyFileInfo->Textures[i]->Layout.ShiftForComponent[j] = GR2LibPropertyWrapper->Textures[i]->Layout->ShiftForComponent[j];
653 _grn_file->GrannyFileInfo->Textures[i]->Layout.BitsForComponent[j] = GR2LibPropertyWrapper->Textures[i]->Layout->BitsForComponent[j];
654 }
655
656 _grn_file->GrannyFileInfo->Textures[i]->ImageCount = GR2LibPropertyWrapper->Textures[i]->Images->Count;
657 _grn_file->GrannyFileInfo->Textures[i]->Images = (granny_texture_image*)malloc(_grn_file->GrannyFileInfo->Textures[i]->ImageCount);
658 for(int j=0;j<_grn_file->GrannyFileInfo->Textures[i]->ImageCount;j++)
659 {
660 _grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevelCount = GR2LibPropertyWrapper->Textures[i]->Images[j]->MIPLevels->Count;
661 _grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels = (granny_texture_mip_level*)malloc(_grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevelCount);
662 for(int k=0;k<_grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevelCount;k++)
663 {
664 _grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels[k].Stride = GR2LibPropertyWrapper->Textures[i]->Images[j]->MIPLevels[k]->Stride;
665 _grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels[k].PixelByteCount = GR2LibPropertyWrapper->Textures[i]->Images[j]->MIPLevels[k]->Pixels->PixelBytes->Count;
666 _grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels[k].PixelBytes = (unsigned char*)malloc(_grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels[k].PixelByteCount);
667
668
669 for (int l=0;l<_grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels[k].PixelByteCount;l++)
670 {
671 _grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels[k].PixelBytes[l] = GR2LibPropertyWrapper->Textures[i]->Images[j]->MIPLevels[k]->Pixels->PixelBytes[l];
672 }
673 }
674 }
675 _grn_file->GrannyFileInfo->Textures[i]->ExtendedData = ExtendedData_ToNative(GR2LibPropertyWrapper->Textures[i]->ExtendedData,_grn_file->GrannyFileInfo->Textures[i]->ExtendedData);
676 }
677
678 }
679 #pragma endregion
680 #pragma region Materials_ToNative
681 void Materials_ToNative()
682 {
683 _grn_file->GrannyFileInfo->MaterialCount = GR2LibPropertyWrapper->Materials->Count;
684 for(int i=0;i<_grn_file->GrannyFileInfo->MaterialCount;i++)
685 {
686 _grn_file->GrannyFileInfo->Materials[i]->Name = (char*)Marshal::StringToHGlobalAnsi(GR2LibPropertyWrapper->Materials[i]->Name).ToPointer();
687 // update extended data
688 _grn_file->GrannyFileInfo->Materials[i]->ExtendedData = ExtendedData_ToNative( GR2LibPropertyWrapper->Materials[i]->ExtendedData, _grn_file->GrannyFileInfo->Materials[i]->ExtendedData);
689
690 }
691 }
692 #pragma endregion
693 #pragma region Skeletons_ToNative
694 void Skeletons_ToNative()
695 {
696 _grn_file->GrannyFileInfo->SkeletonCount = GR2LibPropertyWrapper->Skeletons->Count;
697 for(int i=0;i<_grn_file->GrannyFileInfo->SkeletonCount;i++)
698 {
699 _grn_file->GrannyFileInfo->Skeletons[i]->Name = (char*)Marshal::StringToHGlobalAnsi(GR2LibPropertyWrapper->Skeletons[i]->Name).ToPointer();
700 _grn_file->GrannyFileInfo->Skeletons[i]->LODType = GR2LibPropertyWrapper->Skeletons[i]->LODType;
701 _grn_file->GrannyFileInfo->Skeletons[i]->BoneCount = GR2LibPropertyWrapper->Skeletons[i]->Bones->Count;
702 for(int j=0;j<_grn_file->GrannyFileInfo->Skeletons[i]->BoneCount;j++)
703 {
704 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].Name = (char*)Marshal::StringToHGlobalAnsi(GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->Name).ToPointer();
705 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].ParentIndex = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->ParentIndex;
706
707 // Update LocalTransform
708 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LocalTransform.Flags = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LocalTransform->Dimensions;
709
710 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LocalTransform.Position[0] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LocalTransform->Origin.x;
711 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LocalTransform.Position[1] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LocalTransform->Origin.y;
712 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LocalTransform.Position[2] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LocalTransform->Origin.z;
713 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LocalTransform.Orientation[0] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LocalTransform->Rotation.v.x;
714 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LocalTransform.Orientation[1] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LocalTransform->Rotation.v.y;
715 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LocalTransform.Orientation[2] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LocalTransform->Rotation.v.z;
716 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LocalTransform.Orientation[3] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LocalTransform->Rotation.n;
717 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LocalTransform.ScaleShear[0][0] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LocalTransform->Scale.right.x;
718 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LocalTransform.ScaleShear[0][1] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LocalTransform->Scale.right.y;
719 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LocalTransform.ScaleShear[0][2] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LocalTransform->Scale.right.z;
720 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LocalTransform.ScaleShear[1][0] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LocalTransform->Scale.up.x;
721 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LocalTransform.ScaleShear[1][1] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LocalTransform->Scale.up.y;
722 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LocalTransform.ScaleShear[1][2] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LocalTransform->Scale.up.z;
723 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LocalTransform.ScaleShear[2][0] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LocalTransform->Scale.at.x;
724 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LocalTransform.ScaleShear[2][1] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LocalTransform->Scale.at.y;
725 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LocalTransform.ScaleShear[2][2] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LocalTransform->Scale.at.z;
726 // Update InverseWorld4x4
727 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].InverseWorld4x4[0][0] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->InverseWorld4x4.right.x;
728 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].InverseWorld4x4[0][1] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->InverseWorld4x4.right.y;
729 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].InverseWorld4x4[0][2] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->InverseWorld4x4.right.z;
730 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].InverseWorld4x4[0][3] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->InverseWorld4x4.right.w;
731 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].InverseWorld4x4[1][0] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->InverseWorld4x4.up.x;
732 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].InverseWorld4x4[1][1] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->InverseWorld4x4.up.y;
733 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].InverseWorld4x4[1][2] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->InverseWorld4x4.up.z;
734 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].InverseWorld4x4[1][3] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->InverseWorld4x4.up.w;
735 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].InverseWorld4x4[2][0] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->InverseWorld4x4.at.x;
736 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].InverseWorld4x4[2][1] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->InverseWorld4x4.at.y;
737 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].InverseWorld4x4[2][2] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->InverseWorld4x4.at.z;
738 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].InverseWorld4x4[2][3] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->InverseWorld4x4.at.w;
739 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].InverseWorld4x4[3][0] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->InverseWorld4x4.pos.x;
740 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].InverseWorld4x4[3][1] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->InverseWorld4x4.pos.y;
741 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].InverseWorld4x4[3][2] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->InverseWorld4x4.pos.z;
742 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].InverseWorld4x4[3][3] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->InverseWorld4x4.pos.w;
743
744 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LODError = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LODError;
745 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].ExtendedData = ExtendedData_ToNative( GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->ExtendedData,_grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].ExtendedData);
746 }
747 }
748 }
749 #pragma endregion
750 #pragma endregion
751 #pragma region ExtendedDataToManagedNative
752 #pragma region ExtendedData_ToManaged
753 GrannyExtendedData^ ExtendedData_ToManaged(granny_variant NativeExtendedData)
754 {
755 ExtendedDataWrapper* ExtendedDataWrapped = new ExtendedDataWrapper(NativeExtendedData, _grn_file->_logger);
756 List<ExtendedDataMemberStruct^>^ _ExtendedDataMember = gcnew List<ExtendedDataMemberStruct^>(ExtendedDataWrapped->MemberCount);
757 for (int j=0;j<ExtendedDataWrapped->MemberCount;j++)
758 {
759 ExtendedDataMemberStruct^ _ExtendedDataMemberStruct = gcnew ExtendedDataMemberStruct();
760 _ExtendedDataMemberStruct->Index = ExtendedDataWrapped->ExtendedDataMembers[j].Index;
761 _ExtendedDataMemberStruct->Name = gcnew String(reinterpret_cast<const char*>(ExtendedDataWrapped->ExtendedDataMembers[j].Name.c_str()));
762 _ExtendedDataMemberStruct->Type = (gr2lib::core::typedefs::granny_member_type)(int)ExtendedDataWrapped->ExtendedDataMembers[j].Type;
763 _ExtendedDataMemberStruct->Value = ExtendedDataWrapped->GetRealExtendedDataMemberValue(_ExtendedDataMemberStruct->Index);
764 _ExtendedDataMember->Add(_ExtendedDataMemberStruct);
765 }
766 return gcnew GrannyExtendedData(_ExtendedDataMember);
767 }
768 #pragma endregion
769 #pragma region ExtendedData_ToNative
770 granny_variant ExtendedData_ToNative(GrannyExtendedData^ ManagedExtendedData, granny_variant NativeExtendedData)
771 {
772
773 ExtendedDataWrapper* ExtendedDataWrapped = new ExtendedDataWrapper(NativeExtendedData, _grn_file->_logger);
774 int MemberCount = ManagedExtendedData->ExtendedData->Count;
775 for(int j=0;j<MemberCount;j++)
776 {
777 Object^ value = ManagedExtendedData->ExtendedData[j]->Value;
778 if (value->ToString() == (gcnew Object())->ToString()) continue;
779 int MemberType = ExtendedDataWrapped->ExtendedDataMembers[j].Type;
780 switch(ExtendedDataWrapped->ExtendedDataMembers[j].Type)
781 {
782 // //case granny_member_type::GrannyEndMember: return new void*(); break;
783 // //case granny_member_type::GrannyInlineMember: return new void*(); break;
784 // //case granny_member_type::GrannyReferenceMember: return new void*(); break;
785 // //case granny_member_type::GrannyReferenceToArrayMember: return new void*();break;
786 // //case granny_member_type::GrannyArrayOfReferencesMember: return new void*(); break;
787 // //case granny_member_type::GrannyVariantReferenceMember: return new void*(); break;
788 // //case granny_member_type::GrannyUnsupportedMemberType_Remove: return new void*(); break;
789 // //case granny_member_type::GrannyReferenceToVariantArrayMember: return new void*(); break;
790 case granny_member_type::GrannyStringMember:
791 char* _string;
792 _string = (char*)Marshal::StringToHGlobalAnsi((System::String^)value).ToPointer();
793 ((char*(*)[MAX_GRANNY_MEMBER_COUNT])NativeExtendedData.Object)[0][j] = _string;
794 break;
795 //case granny_member_type::GrannyTransformMember: return new void*();break;
796 case granny_member_type::GrannyReal32Member:
797 ((granny_real32(*)[MAX_GRANNY_MEMBER_COUNT])NativeExtendedData.Object)[0][j] = (granny_real32)value; break;
798 case granny_member_type::GrannyInt8Member:
799 ((granny_int8(*)[MAX_GRANNY_MEMBER_COUNT])NativeExtendedData.Object)[0][j] = (granny_int8)value; break;
800 case granny_member_type::GrannyUInt8Member:
801 ((granny_uint8(*)[MAX_GRANNY_MEMBER_COUNT])NativeExtendedData.Object)[0][j] =(granny_uint8)value; break;
802 case granny_member_type::GrannyBinormalInt8Member:
803 ((granny_int8(*)[MAX_GRANNY_MEMBER_COUNT])NativeExtendedData.Object)[0][j] = (granny_int8)value; break;
804 case granny_member_type::GrannyNormalUInt8Member:
805 ((granny_uint8(*)[MAX_GRANNY_MEMBER_COUNT])NativeExtendedData.Object)[0][j] = (granny_uint8)value; break;
806 case granny_member_type::GrannyInt16Member:
807 ((granny_int16(*)[MAX_GRANNY_MEMBER_COUNT])NativeExtendedData.Object)[0][j] = (granny_int16)value; break;
808 case granny_member_type::GrannyUInt16Member:
809 ((granny_uint16(*)[MAX_GRANNY_MEMBER_COUNT])NativeExtendedData.Object)[0][j] = (granny_uint16)value; break;
810 case granny_member_type::GrannyBinormalInt16Member:
811 ((granny_int16(*)[MAX_GRANNY_MEMBER_COUNT])NativeExtendedData.Object)[0][j] = (granny_int16)value; break;
812 case granny_member_type::GrannyNormalUInt16Member:
813 ((granny_uint16(*)[MAX_GRANNY_MEMBER_COUNT])NativeExtendedData.Object)[0][j] = (granny_uint16)value; break;
814 case granny_member_type::GrannyInt32Member:
815 ((granny_int32(*)[MAX_GRANNY_MEMBER_COUNT])NativeExtendedData.Object)[0][j] = (granny_int32)value; break;
816 case granny_member_type::GrannyUInt32Member:
817 ((granny_uint32(*)[MAX_GRANNY_MEMBER_COUNT])NativeExtendedData.Object)[0][j] = (granny_uint32)value; break;
818 case granny_member_type::GrannyReal16Member:
819 ((granny_real16(*)[MAX_GRANNY_MEMBER_COUNT])NativeExtendedData.Object)[0][j] = (granny_real16)value; break;
820 //case granny_member_type::GrannyEmptyReferenceMember:
821 // ((granny_int32(*)[MAX_GRANNY_MEMBER_COUNT])_grn_file->GrannyFileInfo->Materials[i]->ExtendedData.Object)[0][j] = value; break;
822 //case granny_member_type::GrannyOnePastLastMemberType: break;
823 //case granny_member_type::GrannyBool32Member: break;
824 default: throw gcnew System::InvalidOperationException("Encountered an Invalid Granny Member Type: " + MemberType);
825 }
826 }
827
828 return NativeExtendedData;
829 }
830 #pragma endregion
831 #pragma endregion
832 #pragma endregion
833
834 private: System::Void mnuItemExit_Click(System::Object^ sender, System::EventArgs^ e)
835 {
836 ConvertToNative();
837 this->Close();
838 }
839 private: System::Void mnuItemOpen_Click(System::Object^ sender, System::EventArgs^ e)
840 {
841 System::Windows::Forms::DialogResult result = RigLoader->ShowDialog();
842 if (result != System::Windows::Forms::DialogResult::OK) return;
843 const char* fn = (char*)Marshal::StringToHGlobalAnsi(RigLoader->FileName).ToPointer();
844
845 _grn_file = new grannyfile();
846 const char* loading_msg = "Loading File: ";
847 int msg_malloc = (strlen(loading_msg) + strlen(fn));
848 char* msg = (char*)malloc(msg_malloc);
849 for (int i=0; i<msg_malloc; i++) { msg[i] = 0; }
850 strcat(msg,loading_msg);
851 strcat(msg,fn);
852 strcat(msg,"\n");
853 _grn_file->_logger->LogMessage(msg);
854 //_grn_file->_logger->SetLogFileName("c:\\gr2_logs",fn);
855 _grn_file = new grannyfile(fn);
856
857 this->GR2LibPropertyWrapper = gcnew GR2LibWrapper();
858 ConvertToManaged();
859 propgrid->SelectedObject = this->GR2LibPropertyWrapper;
860 }
861 private: System::Void gr2lib_rigeditor_frm_FormClosed(System::Object^ sender, System::Windows::Forms::FormClosedEventArgs^ e)
862 {
863 //TerminateConsoleIO();
864 }
865 private: System::Void gr2lib_rigeditor_frm_Load(System::Object^ sender, System::EventArgs^ e)
866 {
867 #if defined SHOW_DEBUG_MENU
868 mnuDebug->Visible = true;
869 #else
870 mnuDebug->Visible = false;
871 #endif
872 }
873 private: System::Void mnuTestArtToolInfoReturnValues_Click(System::Object^ sender, System::EventArgs^ e)
874 {
875 // Convert ArtToolInfo To Native, and ouput the values -> to check that they were updated correctly
876 ArtToolInfo_ToNative();
877 VSDebugWriterW VSDebugWriter;
878 VSDebugWriter
879 << "\n\n\tArtToolInfo ->"
880 << "\n\t\tTool Name: "
881 << _grn_file->GrannyFileInfo->ArtToolInfo->FromArtToolName
882 << "\n\t\tTool Version: "
883 << _grn_file->GrannyFileInfo->ArtToolInfo->ArtToolMajorRevision
884 << "." << _grn_file->GrannyFileInfo->ArtToolInfo->ArtToolMinorRevision
885 << "\n\t\tUnits Per Meter: "
886 << _grn_file->GrannyFileInfo->ArtToolInfo->UnitsPerMeter
887 << "\n\t\tOrigin: "
888 << "\n\t\t\tX: "
889 << _grn_file->GrannyFileInfo->ArtToolInfo->Origin[0]
890 << "\n\t\t\tY: "
891 << _grn_file->GrannyFileInfo->ArtToolInfo->Origin[1]
892 << "\n\t\t\tZ: "
893 << _grn_file->GrannyFileInfo->ArtToolInfo->Origin[2]
894 << "\n\t\tRight: "
895 << "\n\t\t\tX: "
896 << _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[0]
897 << "\n\t\t\tY: "
898 << _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[1]
899 << "\n\t\t\tZ: "
900 << _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[2]
901 << "\n\t\tUp: "
902 << "\n\t\t\tX: "
903 << _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[0]
904 << "\n\t\t\tY: "
905 << _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[1]
906 << "\n\t\t\tZ: "
907 << _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[2]
908 << "\n\t\tBack: "
909 << "\n\t\t\tX: "
910 << _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[0]
911 << "\n\t\t\tY: "
912 << _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[1]
913 << "\n\t\t\tZ: "
914 << _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[2]
915 ;
916 }
917 private: System::Void mnuTestExporterInfoReturnValues_Click(System::Object^ sender, System::EventArgs^ e)
918 {
919 // Convert ExporterInfo To Native, and ouput the values -> to check that they were updated correctly
920 ExporterInfo_ToNative();
921 VSDebugWriterW VSDebugWriter;
922 VSDebugWriter
923 << "\n\n\tExporterInfo ->"
924 << "\n\t\tExporter Name: "
925 << _grn_file->GrannyFileInfo->ExporterInfo->ExporterName
926 << "\n\t\tExporter Version: "
927 << _grn_file->GrannyFileInfo->ExporterInfo->ExporterMajorRevision
928 << "." << _grn_file->GrannyFileInfo->ExporterInfo->ExporterMinorRevision
929 << "." << _grn_file->GrannyFileInfo->ExporterInfo->ExporterCustomization
930 << "." << _grn_file->GrannyFileInfo->ExporterInfo->ExporterBuildNumber
931 ;
932 }
933 private: System::Void mnuItemSave_Click(System::Object^ sender, System::EventArgs^ e)
934 {
935 // convert Data to Native
936 try
937 {
938 ConvertToNative();
939 const char* filename = _grn_file->_GrannyFilename;
940 GrannyFileWriter::WriteFile(filename,_grn_file->GrannyFileInfo,_grn_file->_logger);
941 System::Windows::Forms::MessageBox::Show("Successfully Saved: \n" + gcnew String(_grn_file->GrannyFilename()),"File Writer:", MessageBoxButtons::OK,MessageBoxIcon::Information);
942 }
943 catch(Exception^ ex)
944 {
945 System::Windows::Forms::MessageBox::Show("Failed to Save: \n" + gcnew String(_grn_file->GrannyFilename()),"File Writer:", MessageBoxButtons::OK,MessageBoxIcon::Error);
946 }
947 }
948 private: System::Void mnuItemSaveAs_Click(System::Object^ sender, System::EventArgs^ e)
949 {
950 // convert Data to Native
951 try
952 {
953 ConvertToNative();
954 System::Windows::Forms::DialogResult result = RigSaver->ShowDialog();
955 if (result != System::Windows::Forms::DialogResult::OK) return;
956 const char* filename = (char*)Marshal::StringToHGlobalAnsi(RigSaver->FileName).ToPointer();
957 GrannyFileWriter::WriteFile(filename,_grn_file->GrannyFileInfo,_grn_file->_logger);
958 System::Windows::Forms::MessageBox::Show("Successfully Saved: \n" + gcnew String(_grn_file->GrannyFilename()),"File Writer:", MessageBoxButtons::OK,MessageBoxIcon::Information);
959 }
960 catch(Exception^ ex)
961 {
962 System::Windows::Forms::MessageBox::Show("Failed to Save: \n" + gcnew String(_grn_file->GrannyFilename()),"File Writer:", MessageBoxButtons::OK,MessageBoxIcon::Error);
963 }
964 }
965 private: System::Void mnuItemClose_Click(System::Object^ sender, System::EventArgs^ e)
966 {
967 propgrid->SelectedObject = nullptr;
968 }
969 };
970 // }
971 // }
972 //}
973 #endif /* GR2LIB_RIGEDITOR_FRM_H */

  ViewVC Help
Powered by ViewVC 1.1.22