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

Annotation of /trunk/gr2lib_cpp/gr2lib_rigeditor_frm.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 74 - (hide annotations) (download)
Sat Aug 14 10:47:15 2010 UTC (9 years, 6 months ago) by william
File MIME type: text/plain
File size: 49812 byte(s)
Add support for :
** converting Skeletons/Bones to managed/native
** editing bone extended data

1 william 55 #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 william 71 #pragma warning( disable : 4482 ) // disable 'nonstandard extension used' warnings (related to case switch statements using enums)
5 william 55
6 william 19 #define SHOW_DEBUG_MENU // if defined, will show the debug menu -> else it will not be shown
7 william 23
8     #define granny_pixel_layout_bitshift_size 4
9    
10 william 5 #pragma once
11 william 7 //#include "gr2lib_core.h"
12     //#include "gr2lib_core_imports.h"
13     #ifndef GR2LIB_RIGEDITOR_FRM_H
14     #define GR2LIB_RIGEDITOR_FRM_H
15 william 69 #include "..\gr2lib_cpp_typedefs\core.h"
16 william 7 #include "grannyfile.h"
17 william 12 //#include "guicon.h"
18 william 19 #include "VSDebugOutput.h"
19     #include "GrannyFileWriter.h"
20 william 7 #include <stdio.h>
21     #include <iostream>
22     #include <stdlib.h>
23     #include <assert.h>
24     #include <string>
25     #include <sstream>
26 william 12 #include <vcclr.h>
27 william 7 using namespace std;
28 william 5
29 william 69 using namespace gr2lib_cpp::typedefs;
30 william 7 using namespace gr2lib::core;
31     using namespace gr2lib::core::coretypes::implementation;
32 william 14 using namespace gr2lib::core::apiversion;
33 william 22 using namespace gr2lib::core::ui::helpers;
34     using namespace gr2lib::core::helpers;
35 william 5 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 william 6 using namespace System::Runtime::InteropServices;
43 william 49 //using namespace Microsoft::Xna::Framework;
44     //using namespace Microsoft::Xna::Framework::Graphics;
45 william 6 //
46     //namespace gr2lib
47     //{
48     // namespace core
49     // {
50     // namespace rigeditor
51     // {
52 william 12 /// <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 william 5
69 william 12 const char* product_version = (char*)(void*)Marshal::StringToHGlobalAnsi(Application::ProductVersion);
70     const char* version_prefix = "v";
71     const char* startup_string = " {Starting up...}";
72 william 5
73 william 6
74 william 12 int msg_malloc = (strlen(ApplicationName) + strlen(product_version) + strlen(version_prefix) + strlen(startup_string)) + 3;
75 william 5
76 william 12 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 william 5
81 william 12 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 william 15 this->GR2LibPropertyWrapper = gcnew GR2LibWrapper();
109     ConvertToManaged();
110     propgrid->SelectedObject = this->GR2LibPropertyWrapper;
111 william 12
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 william 19 private: System::Windows::Forms::ToolStripMenuItem^ mnuDebug;
134     private: System::Windows::Forms::ToolStripMenuItem^ mnuDebug_UnitTests;
135     private: System::Windows::Forms::ToolStripMenuItem^ mnuTestArtToolInfoReturnValues;
136 william 12
137 william 19 private: System::Windows::Forms::OpenFileDialog^ RigLoader;
138     private: System::Windows::Forms::ToolStripMenuItem^ mnuTestExporterInfoReturnValues;
139     private: System::Windows::Forms::SaveFileDialog^ RigSaver;
140 william 26 private: System::Windows::Forms::ToolStripMenuItem^ mnuItemClose;
141 william 49 private: System::Windows::Forms::ToolStripMenuItem^ mnuItemTestDDSRender;
142 william 19
143    
144    
145    
146 william 49
147 william 12 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 william 49 this->mnuItemClose = (gcnew System::Windows::Forms::ToolStripMenuItem());
167 william 12 this->mnuItemSave = (gcnew System::Windows::Forms::ToolStripMenuItem());
168     this->mnuItemSaveAs = (gcnew System::Windows::Forms::ToolStripMenuItem());
169     this->mnuItemExit = (gcnew System::Windows::Forms::ToolStripMenuItem());
170 william 19 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 william 49 this->mnuItemTestDDSRender = (gcnew System::Windows::Forms::ToolStripMenuItem());
175 william 19 this->RigLoader = (gcnew System::Windows::Forms::OpenFileDialog());
176     this->RigSaver = (gcnew System::Windows::Forms::SaveFileDialog());
177 william 12 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 william 22 this->propgrid->PropertySort = System::Windows::Forms::PropertySort::Categorized;
186 william 12 this->propgrid->Size = System::Drawing::Size(558, 456);
187     this->propgrid->TabIndex = 4;
188     this->propgrid->ToolbarVisible = false;
189     //
190     // mainmenu
191     //
192 william 19 this->mainmenu->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {this->mnuFile, this->mnuDebug});
193 william 12 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 william 26 this->mnuFile->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(5) {this->mnuItemOpen,
202     this->mnuItemClose, this->mnuItemSave, this->mnuItemSaveAs, this->mnuItemExit});
203 william 12 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 william 49 this->mnuItemOpen->Size = System::Drawing::Size(114, 22);
211 william 12 this->mnuItemOpen->Text = L"&Open";
212     this->mnuItemOpen->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuItemOpen_Click);
213     //
214 william 49 // 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 william 12 // mnuItemSave
222     //
223     this->mnuItemSave->Name = L"mnuItemSave";
224 william 49 this->mnuItemSave->Size = System::Drawing::Size(114, 22);
225 william 12 this->mnuItemSave->Text = L"&Save";
226 william 19 this->mnuItemSave->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuItemSave_Click);
227 william 12 //
228     // mnuItemSaveAs
229     //
230     this->mnuItemSaveAs->Name = L"mnuItemSaveAs";
231 william 49 this->mnuItemSaveAs->Size = System::Drawing::Size(114, 22);
232 william 12 this->mnuItemSaveAs->Text = L"Save &As";
233 william 19 this->mnuItemSaveAs->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuItemSaveAs_Click);
234 william 12 //
235     // mnuItemExit
236     //
237     this->mnuItemExit->Name = L"mnuItemExit";
238 william 49 this->mnuItemExit->Size = System::Drawing::Size(114, 22);
239 william 12 this->mnuItemExit->Text = L"&Exit";
240     this->mnuItemExit->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuItemExit_Click);
241     //
242 william 19 // mnuDebug
243     //
244 william 49 this->mnuDebug->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {this->mnuDebug_UnitTests,
245     this->mnuItemTestDDSRender});
246 william 19 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 william 49 this->mnuDebug_UnitTests->Size = System::Drawing::Size(161, 22);
256 william 19 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 william 49 // 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 william 19 // 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 william 12 // 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 william 19 this->Load += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::gr2lib_rigeditor_frm_Load);
302 william 12 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 william 23
311 william 71
312    
313     #pragma region MarshalToManagedNative
314 william 15 //ArtToolInfo^ _ArtToolInfo;
315     //ExporterInfo^ _ExporterInfo;
316     GR2LibWrapper^ GR2LibPropertyWrapper;
317 william 12 #pragma region ManagedNativeParsing
318 william 15 void ConvertToManaged()
319 william 12 {
320     // Art Tool info
321 william 15 ArtToolInfo_ToManaged(_grn_file->GrannyFileInfo->ArtToolInfo);
322 william 14 // Exporter Info
323 william 15 ExporterInfo_ToManaged(_grn_file->GrannyFileInfo->ExporterInfo);
324 william 22 // Texture List
325     Textures_ToManaged(_grn_file->GrannyFileInfo->Textures,_grn_file->GrannyFileInfo->TextureCount);
326 william 69 // Material List
327     Materials_ToManaged(_grn_file->GrannyFileInfo->Materials,_grn_file->GrannyFileInfo->MaterialCount);
328 william 74 // Skeleton List
329     Skeletons_ToManaged(_grn_file->GrannyFileInfo->Skeletons, _grn_file->GrannyFileInfo->SkeletonCount);
330 william 12 }
331     void ConvertToNative()
332     {
333     // Art Tool info
334     ArtToolInfo_ToNative();
335 william 14 // Exporter Info
336     ExporterInfo_ToNative();
337 william 23 // Texture List
338     Textures_ToNative();
339 william 69 // Material List
340     Materials_ToNative();
341 william 74 // Skeleton List
342     Skeletons_ToNative();
343 william 12 }
344     #pragma endregion
345 william 71 #pragma region MarshalToMananaged
346 william 14 #pragma region ArtToolInfo_ToManaged
347 william 15 void ArtToolInfo_ToManaged(granny_art_tool_info* toolinfo)
348 william 12 {
349 william 15 //GR2LibPropertyWrapper->ArtToolInfo = gcnew ArtToolInfo();
350 william 19 if (toolinfo != NULL)
351     {
352     GR2LibPropertyWrapper->ArtToolInfo->FromArtToolName = gcnew String(reinterpret_cast<const char*>(toolinfo->FromArtToolName));
353 william 6
354 william 19 // 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 william 6
373 william 19 // Tool Version
374     GR2LibPropertyWrapper->ArtToolInfo->ToolVersion = gcnew ArtToolInfoVersion(toolinfo->ArtToolMajorRevision,toolinfo->ArtToolMinorRevision);
375     // Tool Units Per Meter
376     GR2LibPropertyWrapper->ArtToolInfo->UnitsPerMeter = toolinfo->UnitsPerMeter;
377 william 71 // Get Extended Data
378     GR2LibPropertyWrapper->ArtToolInfo->ExtendedData = ExtendedData_ToManaged(toolinfo->ExtendedData);
379 william 19 }
380 william 12 }
381     #pragma endregion
382 william 14 #pragma region ExporterInfo_ToManaged
383 william 15 void ExporterInfo_ToManaged(granny_exporter_info* toolinfo)
384     {
385     //GR2LibPropertyWrapper->ExporterInfo = gcnew ExporterInfo();
386 william 19 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 william 71 GR2LibPropertyWrapper->ExporterInfo->ExtendedData = ExtendedData_ToManaged(toolinfo->ExtendedData);
396 william 14 }
397     #pragma endregion
398 william 22 #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 william 29
408 william 22 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 william 29 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 william 6
432 william 22 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 william 29
438 william 22 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 william 57 mip->Pixels = gcnew gr2lib::core::coretypes::implementation::Pixel();
443 william 22
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 william 58 mip->Pixels->NativeTexture = t;
452 william 59 mip->Pixels->NativeTexturePointer = *new IntPtr(toolinfo[i]);
453     mip->Pixels->ImageIndex = j;
454     mip->Pixels->MipIndex = k;
455 william 58
456 william 22 for(int l =0;l<toolinfo[i]->Images[j].MIPLevels[k].PixelByteCount;l++)
457 william 58 {
458     mip->Pixels->PixelBytes->Add(bytes[l]);
459 william 22 }
460     img->MIPLevels->Add(mip);
461 william 71
462 william 22 }
463     t->Images->Add(img);
464 william 29 t->NativePointer = *new IntPtr(toolinfo[i]);
465 william 71 t->ExtendedData = ExtendedData_ToManaged(toolinfo[i]->ExtendedData);
466 william 22 }
467     GR2LibPropertyWrapper->Textures->Add(t);
468     }
469     }
470     }
471     #pragma endregion
472 william 69 #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 william 71 if (toolinfo[i]->Texture != NULL) { m = gcnew Material(*new IntPtr(&toolinfo[i]->Texture)); }
482    
483 william 69 m->Name = gcnew String(reinterpret_cast<const char*>(toolinfo[i]->Name));
484 william 71 m->ExtendedData = ExtendedData_ToManaged(toolinfo[i]->ExtendedData);
485 william 69 m->NativePointer = *new IntPtr(toolinfo[i]);
486     GR2LibPropertyWrapper->Materials->Add(m);
487     }
488     }
489     }
490     #pragma endregion
491 william 74 #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     Matrix44^ _matrix44 = gcnew Matrix44(_transform->Matrix);
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     _matrix44->right = *gcnew Vector4(
543     toolinfo[i]->Bones[j].InverseWorld4x4[0][0],
544     toolinfo[i]->Bones[j].InverseWorld4x4[0][1],
545     toolinfo[i]->Bones[j].InverseWorld4x4[0][2],
546     toolinfo[i]->Bones[j].InverseWorld4x4[0][3]
547     );
548    
549     _matrix44->up = *gcnew Vector4(
550     toolinfo[i]->Bones[j].InverseWorld4x4[1][0],
551     toolinfo[i]->Bones[j].InverseWorld4x4[1][1],
552     toolinfo[i]->Bones[j].InverseWorld4x4[1][2],
553     toolinfo[i]->Bones[j].InverseWorld4x4[1][3]
554     );
555    
556     _matrix44->at = *gcnew Vector4(
557     toolinfo[i]->Bones[j].InverseWorld4x4[2][0],
558     toolinfo[i]->Bones[j].InverseWorld4x4[2][1],
559     toolinfo[i]->Bones[j].InverseWorld4x4[2][2],
560     toolinfo[i]->Bones[j].InverseWorld4x4[2][3]
561     );
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    
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 william 71 #pragma endregion
582 william 74 #pragma endregion
583 william 12 #pragma region MarshalToNative
584 william 14 #pragma region ArtToolInfo_ToNative
585 william 12 void ArtToolInfo_ToNative()
586     {
587 william 19 if (_grn_file->GrannyFileInfo->ArtToolInfo == NULL)
588     {
589     _grn_file->GrannyFileInfo->ArtToolInfo = new granny_art_tool_info();
590     }
591 william 6
592 william 15 _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 william 6
597    
598 william 15 _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 william 12
602 william 15 _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 william 12
606 william 15 _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 william 12
610 william 15 _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 william 12
614 william 71 _grn_file->GrannyFileInfo->ArtToolInfo->ExtendedData = ExtendedData_ToNative(GR2LibPropertyWrapper->ArtToolInfo->ExtendedData,_grn_file->GrannyFileInfo->ArtToolInfo->ExtendedData);
615    
616 william 12 }
617     #pragma endregion
618 william 14 #pragma region ExporterInfo_ToNative
619     void ExporterInfo_ToNative()
620     {
621 william 19 if (_grn_file->GrannyFileInfo->ExporterInfo == NULL)
622     {
623     _grn_file->GrannyFileInfo->ExporterInfo = new granny_exporter_info();
624     }
625 william 15 _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 william 71 _grn_file->GrannyFileInfo->ExporterInfo->ExtendedData = ExtendedData_ToNative(GR2LibPropertyWrapper->ExporterInfo->ExtendedData,_grn_file->GrannyFileInfo->ExporterInfo->ExtendedData);
631 william 14 }
632 william 12 #pragma endregion
633 william 22 #pragma region Textures_ToNative
634     void Textures_ToNative()
635     {
636 william 29 //_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 william 23
639     _grn_file->GrannyFileInfo->TextureCount = GR2LibPropertyWrapper->Textures->Count;
640     for(int i=0;i<_grn_file->GrannyFileInfo->TextureCount;i++)
641 william 22 {
642 william 23 _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 william 29
649 william 23 _grn_file->GrannyFileInfo->Textures[i]->Layout.BytesPerPixel = (granny_int32)GR2LibPropertyWrapper->Textures[i]->Layout->BytesPerPixel;
650 william 51 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 william 23
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 william 57 _grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels[k].PixelByteCount = GR2LibPropertyWrapper->Textures[i]->Images[j]->MIPLevels[k]->Pixels->PixelBytes->Count;
666 william 23 _grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels[k].PixelBytes = (unsigned char*)malloc(_grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels[k].PixelByteCount);
667 william 29
668 william 51
669 william 23 for (int l=0;l<_grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels[k].PixelByteCount;l++)
670     {
671 william 57 _grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels[k].PixelBytes[l] = GR2LibPropertyWrapper->Textures[i]->Images[j]->MIPLevels[k]->Pixels->PixelBytes[l];
672 william 23 }
673     }
674     }
675 william 71 _grn_file->GrannyFileInfo->Textures[i]->ExtendedData = ExtendedData_ToNative(GR2LibPropertyWrapper->Textures[i]->ExtendedData,_grn_file->GrannyFileInfo->Textures[i]->ExtendedData);
676 william 22 }
677 william 23
678 william 22 }
679 william 14 #pragma endregion
680 william 69 #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 william 71 _grn_file->GrannyFileInfo->Materials[i]->ExtendedData = ExtendedData_ToNative( GR2LibPropertyWrapper->Materials[i]->ExtendedData, _grn_file->GrannyFileInfo->Materials[i]->ExtendedData);
689 william 69
690 william 71 }
691     }
692     #pragma endregion
693 william 74 #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 william 71 #pragma endregion
750 william 74 #pragma endregion
751 william 71 #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 william 69
773 william 71 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 william 69 // //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 william 71 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 william 69 //case granny_member_type::GrannyEmptyReferenceMember:
821     // ((granny_int32(*)[MAX_GRANNY_MEMBER_COUNT])_grn_file->GrannyFileInfo->Materials[i]->ExtendedData.Object)[0][j] = value; break;
822 william 71 //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 william 69 }
826     }
827 william 71
828     return NativeExtendedData;
829 william 69 }
830 william 22 #pragma endregion
831 william 69 #pragma endregion
832 william 12 #pragma endregion
833 william 51
834 william 71
835 william 51 #pragma region DoPostSave_Operations
836     void DoPostSave_Operations()
837     {
838     //// Compress Bink Textures
839     //for(int i=0;i<_grn_file->GrannyFileInfo->TextureCount;i++)
840     //{
841     // if (_grn_file->GrannyFileInfo->Textures[i]->Encoding == granny_texture_encoding::GrannyBinkTextureEncoding)
842     // {
843     // int bink_compress = GrannyBinkCompressTexture(
844     // _grn_file->GrannyFileInfo->Textures[i]->Width,
845     // _grn_file->GrannyFileInfo->Textures[i]->Height,
846     // _grn_file->GrannyFileInfo->Textures[i]->Width * _grn_file->GrannyFileInfo->Textures[i]->Layout.BytesPerPixel,
847     // _grn_file->GrannyFileInfo->Textures[i]->Images,
848     // granny_bink_texture_flags::GrannyBinkEncodeAlpha,
849     // granny_compression_type::GrannyNoCompression,
850     // _grn_file->GrannyFileInfo->Textures[i]);
851     // int a = 0;
852     // }
853     //}
854     }
855     #pragma endregion
856    
857 william 6 private: System::Void mnuItemExit_Click(System::Object^ sender, System::EventArgs^ e)
858     {
859     ConvertToNative();
860     this->Close();
861     }
862     private: System::Void mnuItemOpen_Click(System::Object^ sender, System::EventArgs^ e)
863     {
864 william 19 System::Windows::Forms::DialogResult result = RigLoader->ShowDialog();
865     if (result != System::Windows::Forms::DialogResult::OK) return;
866     const char* fn = (char*)Marshal::StringToHGlobalAnsi(RigLoader->FileName).ToPointer();
867    
868 william 12 _grn_file = new grannyfile();
869     const char* loading_msg = "Loading File: ";
870     int msg_malloc = (strlen(loading_msg) + strlen(fn));
871     char* msg = (char*)malloc(msg_malloc);
872     for (int i=0; i<msg_malloc; i++) { msg[i] = 0; }
873     strcat(msg,loading_msg);
874     strcat(msg,fn);
875     strcat(msg,"\n");
876     _grn_file->_logger->LogMessage(msg);
877     //_grn_file->_logger->SetLogFileName("c:\\gr2_logs",fn);
878     _grn_file = new grannyfile(fn);
879    
880 william 29 this->GR2LibPropertyWrapper = gcnew GR2LibWrapper();
881     ConvertToManaged();
882 william 15 propgrid->SelectedObject = this->GR2LibPropertyWrapper;
883 william 6 }
884 william 12 private: System::Void gr2lib_rigeditor_frm_FormClosed(System::Object^ sender, System::Windows::Forms::FormClosedEventArgs^ e)
885     {
886     //TerminateConsoleIO();
887     }
888 william 19 private: System::Void gr2lib_rigeditor_frm_Load(System::Object^ sender, System::EventArgs^ e)
889     {
890     #if defined SHOW_DEBUG_MENU
891     mnuDebug->Visible = true;
892     #else
893     mnuDebug->Visible = false;
894     #endif
895     }
896     private: System::Void mnuTestArtToolInfoReturnValues_Click(System::Object^ sender, System::EventArgs^ e)
897     {
898     // Convert ArtToolInfo To Native, and ouput the values -> to check that they were updated correctly
899     ArtToolInfo_ToNative();
900     VSDebugWriterW VSDebugWriter;
901     VSDebugWriter
902     << "\n\n\tArtToolInfo ->"
903     << "\n\t\tTool Name: "
904 william 29 << _grn_file->GrannyFileInfo->ArtToolInfo->FromArtToolName
905 william 19 << "\n\t\tTool Version: "
906 william 29 << _grn_file->GrannyFileInfo->ArtToolInfo->ArtToolMajorRevision
907     << "." << _grn_file->GrannyFileInfo->ArtToolInfo->ArtToolMinorRevision
908     << "\n\t\tUnits Per Meter: "
909     << _grn_file->GrannyFileInfo->ArtToolInfo->UnitsPerMeter
910     << "\n\t\tOrigin: "
911     << "\n\t\t\tX: "
912     << _grn_file->GrannyFileInfo->ArtToolInfo->Origin[0]
913     << "\n\t\t\tY: "
914     << _grn_file->GrannyFileInfo->ArtToolInfo->Origin[1]
915     << "\n\t\t\tZ: "
916     << _grn_file->GrannyFileInfo->ArtToolInfo->Origin[2]
917     << "\n\t\tRight: "
918     << "\n\t\t\tX: "
919     << _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[0]
920     << "\n\t\t\tY: "
921     << _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[1]
922     << "\n\t\t\tZ: "
923     << _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[2]
924     << "\n\t\tUp: "
925     << "\n\t\t\tX: "
926     << _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[0]
927     << "\n\t\t\tY: "
928     << _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[1]
929     << "\n\t\t\tZ: "
930     << _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[2]
931     << "\n\t\tBack: "
932     << "\n\t\t\tX: "
933     << _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[0]
934     << "\n\t\t\tY: "
935     << _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[1]
936     << "\n\t\t\tZ: "
937     << _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[2]
938 william 19 ;
939     }
940     private: System::Void mnuTestExporterInfoReturnValues_Click(System::Object^ sender, System::EventArgs^ e)
941     {
942 william 29 // Convert ExporterInfo To Native, and ouput the values -> to check that they were updated correctly
943     ExporterInfo_ToNative();
944 william 19 VSDebugWriterW VSDebugWriter;
945     VSDebugWriter
946     << "\n\n\tExporterInfo ->"
947     << "\n\t\tExporter Name: "
948 william 29 << _grn_file->GrannyFileInfo->ExporterInfo->ExporterName
949 william 19 << "\n\t\tExporter Version: "
950 william 29 << _grn_file->GrannyFileInfo->ExporterInfo->ExporterMajorRevision
951     << "." << _grn_file->GrannyFileInfo->ExporterInfo->ExporterMinorRevision
952     << "." << _grn_file->GrannyFileInfo->ExporterInfo->ExporterCustomization
953     << "." << _grn_file->GrannyFileInfo->ExporterInfo->ExporterBuildNumber
954 william 19 ;
955     }
956     private: System::Void mnuItemSave_Click(System::Object^ sender, System::EventArgs^ e)
957     {
958     // convert Data to Native
959 william 50 try
960     {
961     ConvertToNative();
962     const char* filename = _grn_file->_GrannyFilename;
963 william 51 GrannyFileWriter::WriteFile(filename,_grn_file->GrannyFileInfo,_grn_file->_logger);
964     //DoPostSave_Operations();
965     //GrannyFileWriter::WriteFile(filename,_grn_file->GrannyFileInfo,_grn_file->_logger);
966 william 50 System::Windows::Forms::MessageBox::Show("Successfully Saved: \n" + gcnew String(_grn_file->GrannyFilename()),"File Writer:", MessageBoxButtons::OK,MessageBoxIcon::Information);
967     }
968     catch(Exception^ ex)
969     {
970     System::Windows::Forms::MessageBox::Show("Failed to Save: \n" + gcnew String(_grn_file->GrannyFilename()),"File Writer:", MessageBoxButtons::OK,MessageBoxIcon::Error);
971     }
972 william 19 }
973     private: System::Void mnuItemSaveAs_Click(System::Object^ sender, System::EventArgs^ e)
974     {
975 william 29 // convert Data to Native
976 william 50 try
977     {
978     ConvertToNative();
979     System::Windows::Forms::DialogResult result = RigSaver->ShowDialog();
980     if (result != System::Windows::Forms::DialogResult::OK) return;
981     const char* filename = (char*)Marshal::StringToHGlobalAnsi(RigSaver->FileName).ToPointer();
982 william 51 GrannyFileWriter::WriteFile(filename,_grn_file->GrannyFileInfo,_grn_file->_logger);
983     //DoPostSave_Operations();
984     //GrannyFileWriter::WriteFile(filename,_grn_file->GrannyFileInfo,_grn_file->_logger);
985 william 50 System::Windows::Forms::MessageBox::Show("Successfully Saved: \n" + gcnew String(_grn_file->GrannyFilename()),"File Writer:", MessageBoxButtons::OK,MessageBoxIcon::Information);
986     }
987     catch(Exception^ ex)
988     {
989     System::Windows::Forms::MessageBox::Show("Failed to Save: \n" + gcnew String(_grn_file->GrannyFilename()),"File Writer:", MessageBoxButtons::OK,MessageBoxIcon::Error);
990     }
991 william 19 }
992 william 26 private: System::Void mnuItemClose_Click(System::Object^ sender, System::EventArgs^ e)
993     {
994 william 55 propgrid->SelectedObject = nullptr;
995 william 26 }
996 william 6 };
997     // }
998     // }
999 william 7 //}
1000 william 50 #endif /* GR2LIB_RIGEDITOR_FRM_H */

  ViewVC Help
Powered by ViewVC 1.1.22