/[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 88 - (show annotations) (download)
Sun Aug 15 00:51:50 2010 UTC (9 years, 6 months ago) by william
File MIME type: text/plain
File size: 49261 byte(s)
Added Support for:
** When displaying the Granny2 Data, don't show properties that don't exist in the rig file
   this incarnation, actually works.

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

  ViewVC Help
Powered by ViewVC 1.1.22