/[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 89 - (hide annotations) (download)
Sun Aug 15 01:12:18 2010 UTC (9 years, 6 months ago) by william
File MIME type: text/plain
File size: 51549 byte(s)
Add support for:
** testing if a file has been loaded/has unsaved changes and act accordingly
still need to implement changed handler for List Members, etc ... that the parent
property grid does not see.

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

  ViewVC Help
Powered by ViewVC 1.1.22