/[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 93 - (hide annotations) (download)
Thu Aug 19 11:15:19 2010 UTC (9 years, 6 months ago) by william
File MIME type: text/plain
File size: 53485 byte(s)
Create base class to act as proxy when determining which properties to show.
(i.e.) if a property is null, don't show it...

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 93 propgrid->SelectedObject = this->GR2LibPropertyWrapper;
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 93 // Model List
334     Models_ToManaged(_grn_file->GrannyFileInfo->Models,_grn_file->GrannyFileInfo->ModelCount);
335 william 12 }
336     void ConvertToNative()
337     {
338     // Art Tool info
339     ArtToolInfo_ToNative();
340 william 14 // Exporter Info
341     ExporterInfo_ToNative();
342 william 23 // Texture List
343     Textures_ToNative();
344 william 69 // Material List
345     Materials_ToNative();
346 william 74 // Skeleton List
347     Skeletons_ToNative();
348 william 93 // Model List
349     Models_ToNative();
350 william 12 }
351     #pragma endregion
352 william 71 #pragma region MarshalToMananaged
353 william 14 #pragma region ArtToolInfo_ToManaged
354 william 15 void ArtToolInfo_ToManaged(granny_art_tool_info* toolinfo)
355 william 12 {
356 william 15 //GR2LibPropertyWrapper->ArtToolInfo = gcnew ArtToolInfo();
357 william 19 if (toolinfo != NULL)
358     {
359 william 84 GR2LibPropertyWrapper->ArtToolInfo = gcnew ArtToolInfo();
360 william 19 GR2LibPropertyWrapper->ArtToolInfo->FromArtToolName = gcnew String(reinterpret_cast<const char*>(toolinfo->FromArtToolName));
361 william 6
362 william 19 // Tool Vector
363     Vector3* Origin = new Vector3(
364     toolinfo->Origin[0],
365     toolinfo->Origin[1],
366     toolinfo->Origin[2]);
367     Vector3* Right = new Vector3(
368     toolinfo->RightVector[0],
369     toolinfo->RightVector[1],
370     toolinfo->RightVector[2]);
371     Vector3* Up = new Vector3(
372     toolinfo->UpVector[0],
373     toolinfo->UpVector[1],
374     toolinfo->UpVector[2]);
375     Vector3* Back = new Vector3(
376     toolinfo->BackVector[0],
377     toolinfo->BackVector[1],
378     toolinfo->BackVector[2]);
379     GR2LibPropertyWrapper->ArtToolInfo->Vector = gcnew ArtToolInfoVector(*Origin,*Right,*Up,*Back);
380 william 6
381 william 19 // Tool Version
382     GR2LibPropertyWrapper->ArtToolInfo->ToolVersion = gcnew ArtToolInfoVersion(toolinfo->ArtToolMajorRevision,toolinfo->ArtToolMinorRevision);
383     // Tool Units Per Meter
384     GR2LibPropertyWrapper->ArtToolInfo->UnitsPerMeter = toolinfo->UnitsPerMeter;
385 william 71 // Get Extended Data
386     GR2LibPropertyWrapper->ArtToolInfo->ExtendedData = ExtendedData_ToManaged(toolinfo->ExtendedData);
387 william 19 }
388 william 12 }
389     #pragma endregion
390 william 14 #pragma region ExporterInfo_ToManaged
391 william 15 void ExporterInfo_ToManaged(granny_exporter_info* toolinfo)
392     {
393     //GR2LibPropertyWrapper->ExporterInfo = gcnew ExporterInfo();
394 william 19 if (toolinfo != NULL)
395     {
396 william 84 GR2LibPropertyWrapper->ExporterInfo = gcnew ExporterInfo();
397 william 19 GR2LibPropertyWrapper->ExporterInfo->ExporterName = gcnew String(reinterpret_cast<const char*>(toolinfo->ExporterName));
398     GR2LibPropertyWrapper->ExporterInfo->Version = gcnew versiontype(
399     toolinfo->ExporterMajorRevision,
400     toolinfo->ExporterMinorRevision,
401     toolinfo->ExporterCustomization,
402     toolinfo->ExporterBuildNumber);
403 william 84 GR2LibPropertyWrapper->ExporterInfo->ExtendedData = ExtendedData_ToManaged(toolinfo->ExtendedData);
404 william 19 }
405 william 84
406 william 14 }
407     #pragma endregion
408 william 22 #pragma region Textures_ToManaged
409     void Textures_ToManaged(granny_texture** toolinfo, granny_int32 TextureCount)
410     {
411     if (toolinfo != NULL)
412     {
413     GR2LibPropertyWrapper->Textures = gcnew List<Texture^>();
414     for(int i=0;i<TextureCount;i++)
415     {
416     Texture^ t = gcnew Texture();
417 william 29
418 william 22 t->FromFileName = gcnew FilePath(gcnew String(reinterpret_cast<const char*>(toolinfo[i]->FromFileName)));
419     t->TextureType = gcnew NameValuePair<String^,gr2lib::core::typedefs::granny_texture_type>(
420     ::coreapi::EnumToStringSupport::GetGrannyEnumTypeString<gr2lib::core::typedefs::granny_texture_type>(
421     (gr2lib::core::typedefs::granny_texture_type)toolinfo[i]->TextureType),
422     (gr2lib::core::typedefs::granny_texture_type)toolinfo[i]->TextureType);
423     t->Width = toolinfo[i]->Width;
424     t->Height = toolinfo[i]->Height;
425     t->Encoding = gcnew NameValuePair<String^,gr2lib::core::typedefs::granny_texture_encoding>(
426     ::coreapi::EnumToStringSupport::GetGrannyEnumTypeString<gr2lib::core::typedefs::granny_texture_encoding>(
427     (gr2lib::core::typedefs::granny_texture_encoding)toolinfo[i]->Encoding),
428     (gr2lib::core::typedefs::granny_texture_encoding)toolinfo[i]->Encoding);
429     t->SubFormat = gcnew NameValuePair<String^,gr2lib::core::typedefs::granny_pixel_layout>(
430     ::coreapi::EnumToStringSupport::GetGrannyEnumTypeString<gr2lib::core::typedefs::granny_pixel_layout>(
431     (gr2lib::core::typedefs::granny_pixel_layout)toolinfo[i]->SubFormat),
432     (gr2lib::core::typedefs::granny_pixel_layout)toolinfo[i]->SubFormat);
433 william 88
434     //t->Layout = gr2lib::core::typedefs::granny_pixel_layouts::GetPixelLayoutFromEnum(t->SubFormat->Value);
435    
436 william 22 t->Layout = gcnew gr2lib::core::coretypes::implementation::Layout();
437 william 29 t->Layout->BytesPerPixel = toolinfo[i]->Layout.BytesPerPixel;
438     for(int j=0;j<granny_pixel_layout_bitshift_size;j++)
439     {
440     t->Layout->ShiftForComponent[j] = toolinfo[i]->Layout.ShiftForComponent[j];
441     t->Layout->BitsForComponent[j] = toolinfo[i]->Layout.BitsForComponent[j];
442     }
443     t->Layout->NativePointer = *new IntPtr(&toolinfo[i]->Layout);
444 william 6
445 william 22 t->Images = gcnew List<gr2lib::core::coretypes::implementation::Image^>();
446     for(int j=0;j<toolinfo[i]->ImageCount;j++)
447     {
448     gr2lib::core::coretypes::implementation::Image^ img = gcnew gr2lib::core::coretypes::implementation::Image();
449     img->MIPLevels = gcnew List<gr2lib::core::coretypes::implementation::MIPLevel^>();
450 william 29
451 william 22 for(int k=0;k<toolinfo[i]->Images[j].MIPLevelCount;k++)
452     {
453     gr2lib::core::coretypes::implementation::MIPLevel^ mip = gcnew gr2lib::core::coretypes::implementation::MIPLevel();
454     mip->Stride = toolinfo[i]->Images[j].MIPLevels[k].Stride;
455 william 57 mip->Pixels = gcnew gr2lib::core::coretypes::implementation::Pixel();
456 william 22
457     unsigned char* bytes = (unsigned char*)malloc(toolinfo[i]->Images[j].MIPLevels[k].PixelByteCount);
458     for(int l =0;l<toolinfo[i]->Images[j].MIPLevels[k].PixelByteCount;l++)
459     {
460     bytes[l] =0;
461     }
462     bytes = (unsigned char*)toolinfo[i]->Images[j].MIPLevels[k].PixelBytes;
463    
464 william 58 mip->Pixels->NativeTexture = t;
465 william 59 mip->Pixels->NativeTexturePointer = *new IntPtr(toolinfo[i]);
466     mip->Pixels->ImageIndex = j;
467     mip->Pixels->MipIndex = k;
468 william 58
469 william 22 for(int l =0;l<toolinfo[i]->Images[j].MIPLevels[k].PixelByteCount;l++)
470 william 58 {
471     mip->Pixels->PixelBytes->Add(bytes[l]);
472 william 22 }
473     img->MIPLevels->Add(mip);
474 william 71
475 william 22 }
476     t->Images->Add(img);
477 william 29 t->NativePointer = *new IntPtr(toolinfo[i]);
478 william 71 t->ExtendedData = ExtendedData_ToManaged(toolinfo[i]->ExtendedData);
479 william 22 }
480     GR2LibPropertyWrapper->Textures->Add(t);
481     }
482     }
483     }
484     #pragma endregion
485 william 69 #pragma region Materials_ToManaged
486     void Materials_ToManaged(granny_material** toolinfo, granny_int32 MaterialCount)
487     {
488     if (toolinfo != NULL)
489     {
490     GR2LibPropertyWrapper->Materials = gcnew List<Material^>();
491     for(int i=0;i<MaterialCount;i++)
492     {
493     Material^ m = gcnew Material();
494 william 71 if (toolinfo[i]->Texture != NULL) { m = gcnew Material(*new IntPtr(&toolinfo[i]->Texture)); }
495    
496 william 69 m->Name = gcnew String(reinterpret_cast<const char*>(toolinfo[i]->Name));
497 william 71 m->ExtendedData = ExtendedData_ToManaged(toolinfo[i]->ExtendedData);
498 william 69 m->NativePointer = *new IntPtr(toolinfo[i]);
499     GR2LibPropertyWrapper->Materials->Add(m);
500     }
501     }
502     }
503     #pragma endregion
504 william 74 #pragma region Skeletons_ToManaged
505     void Skeletons_ToManaged(granny_skeleton** toolinfo, granny_int32 SkeletonCount)
506     {
507     if (toolinfo != NULL)
508     {
509     GR2LibPropertyWrapper->Skeletons = gcnew List<Skeleton^>();
510     for(int i=0;i<SkeletonCount;i++)
511     {
512     Skeleton^ s = gcnew Skeleton();
513     s->Name = gcnew String(reinterpret_cast<const char*>(toolinfo[i]->Name));
514     s->LODType = toolinfo[i]->LODType;
515     List<Bone^>^ bones = gcnew List<Bone^>();
516     for(int j=0;j<toolinfo[i]->BoneCount;j++)
517     {
518     Bone^ b = gcnew Bone();
519    
520     b->Name = gcnew String(reinterpret_cast<const char*>(toolinfo[i]->Bones[j].Name));
521     b->ParentIndex = toolinfo[i]->Bones[j].ParentIndex;
522    
523     Transform^ _transform = gcnew Transform();
524 william 76
525 william 74
526     _transform->Dimensions = toolinfo[i]->Bones[j].LocalTransform.Flags;
527     _transform->Origin = *gcnew Vector3(
528     toolinfo[i]->Bones[j].LocalTransform.Position[0],
529     toolinfo[i]->Bones[j].LocalTransform.Position[1],
530     toolinfo[i]->Bones[j].LocalTransform.Position[2]
531     );
532    
533     _transform->Rotation = *gcnew Quaternion(
534     toolinfo[i]->Bones[j].LocalTransform.Orientation[0],
535     toolinfo[i]->Bones[j].LocalTransform.Orientation[1],
536     toolinfo[i]->Bones[j].LocalTransform.Orientation[2],
537     toolinfo[i]->Bones[j].LocalTransform.Orientation[3]
538     );
539     _transform->Scale = *gcnew Matrix33
540     (
541     *gcnew Vector3(
542     toolinfo[i]->Bones[j].LocalTransform.ScaleShear[0][0],
543     toolinfo[i]->Bones[j].LocalTransform.ScaleShear[0][1],
544     toolinfo[i]->Bones[j].LocalTransform.ScaleShear[0][2]),
545     *gcnew Vector3(
546     toolinfo[i]->Bones[j].LocalTransform.ScaleShear[1][0],
547     toolinfo[i]->Bones[j].LocalTransform.ScaleShear[1][1],
548     toolinfo[i]->Bones[j].LocalTransform.ScaleShear[1][2]),
549     *gcnew Vector3(
550     toolinfo[i]->Bones[j].LocalTransform.ScaleShear[2][0],
551     toolinfo[i]->Bones[j].LocalTransform.ScaleShear[2][1],
552     toolinfo[i]->Bones[j].LocalTransform.ScaleShear[2][2])
553 william 76 );
554    
555    
556 william 74
557 william 76 Matrix44^ _matrix44 = gcnew Matrix44(_transform->Matrix);
558 william 74 _matrix44->right = *gcnew Vector4(
559     toolinfo[i]->Bones[j].InverseWorld4x4[0][0],
560     toolinfo[i]->Bones[j].InverseWorld4x4[0][1],
561     toolinfo[i]->Bones[j].InverseWorld4x4[0][2],
562     toolinfo[i]->Bones[j].InverseWorld4x4[0][3]
563 william 76 );
564 william 74 _matrix44->up = *gcnew Vector4(
565     toolinfo[i]->Bones[j].InverseWorld4x4[1][0],
566     toolinfo[i]->Bones[j].InverseWorld4x4[1][1],
567     toolinfo[i]->Bones[j].InverseWorld4x4[1][2],
568     toolinfo[i]->Bones[j].InverseWorld4x4[1][3]
569 william 76 );
570 william 74 _matrix44->at = *gcnew Vector4(
571     toolinfo[i]->Bones[j].InverseWorld4x4[2][0],
572     toolinfo[i]->Bones[j].InverseWorld4x4[2][1],
573     toolinfo[i]->Bones[j].InverseWorld4x4[2][2],
574     toolinfo[i]->Bones[j].InverseWorld4x4[2][3]
575 william 76 );
576 william 74 _matrix44->pos = *gcnew Vector4(
577     toolinfo[i]->Bones[j].InverseWorld4x4[3][0],
578     toolinfo[i]->Bones[j].InverseWorld4x4[3][1],
579     toolinfo[i]->Bones[j].InverseWorld4x4[3][2],
580     toolinfo[i]->Bones[j].InverseWorld4x4[3][3]
581     );
582 william 76 _transform->Matrix = *_matrix44;
583 william 74 b->LocalTransform = _transform;
584 william 76 //b->InverseWorld4x4 = *_matrix44;
585 william 74 b->LODError = toolinfo[i]->Bones[j].LODError;
586     b->ExtendedData = ExtendedData_ToManaged(toolinfo[i]->Bones[j].ExtendedData);
587     bones->Add(b);
588     }
589     s->Bones = bones;
590     GR2LibPropertyWrapper->Skeletons->Add(s);
591     }
592     }
593     }
594 william 71 #pragma endregion
595 william 93 #pragma region Models_ToManaged
596     void Models_ToManaged(granny_model** toolinfo, granny_int32 ModelCount)
597     {
598     if (toolinfo != NULL)
599     {
600     GR2LibPropertyWrapper->Models = gcnew List<Model^>();
601     for(int i=0;i<ModelCount;i++)
602     {
603     Model^ m = gcnew Model();
604     m->Name = gcnew String(reinterpret_cast<const char*>(toolinfo[i]->Name));
605    
606     Transform^ _transform = gcnew Transform();
607     _transform->Dimensions = toolinfo[i]->InitialPlacement.Flags;
608     _transform->Origin = *gcnew Vector3(
609     toolinfo[i]->InitialPlacement.Position[0],
610     toolinfo[i]->InitialPlacement.Position[1],
611     toolinfo[i]->InitialPlacement.Position[2]
612     );
613    
614     _transform->Rotation = *gcnew Quaternion(
615     toolinfo[i]->InitialPlacement.Orientation[0],
616     toolinfo[i]->InitialPlacement.Orientation[1],
617     toolinfo[i]->InitialPlacement.Orientation[2],
618     toolinfo[i]->InitialPlacement.Orientation[3]
619     );
620     _transform->Scale = *gcnew Matrix33
621     (
622     *gcnew Vector3(
623     toolinfo[i]->InitialPlacement.ScaleShear[0][0],
624     toolinfo[i]->InitialPlacement.ScaleShear[0][1],
625     toolinfo[i]->InitialPlacement.ScaleShear[0][2]),
626     *gcnew Vector3(
627     toolinfo[i]->InitialPlacement.ScaleShear[1][0],
628     toolinfo[i]->InitialPlacement.ScaleShear[1][1],
629     toolinfo[i]->InitialPlacement.ScaleShear[1][2]),
630     *gcnew Vector3(
631     toolinfo[i]->InitialPlacement.ScaleShear[2][0],
632     toolinfo[i]->InitialPlacement.ScaleShear[2][1],
633     toolinfo[i]->InitialPlacement.ScaleShear[2][2])
634     );
635     m->InitialPlacement = _transform;
636     //m->ExtendedData = ExtendedData_ToManaged(toolinfo[i]->ExtendedData);
637     GR2LibPropertyWrapper->Models->Add(m);
638     }
639     }
640     }
641 william 74 #pragma endregion
642 william 93 #pragma endregion
643 william 12 #pragma region MarshalToNative
644 william 14 #pragma region ArtToolInfo_ToNative
645 william 12 void ArtToolInfo_ToNative()
646     {
647 william 84 if (GR2LibPropertyWrapper->ArtToolInfo != nullptr)
648 william 19 {
649 william 84 if (_grn_file->GrannyFileInfo->ArtToolInfo == NULL)
650     {
651     _grn_file->GrannyFileInfo->ArtToolInfo = new granny_art_tool_info();
652     }
653 william 6
654 william 84 _grn_file->GrannyFileInfo->ArtToolInfo->FromArtToolName = (char*)Marshal::StringToHGlobalAnsi(GR2LibPropertyWrapper->ArtToolInfo->FromArtToolName).ToPointer();
655     _grn_file->GrannyFileInfo->ArtToolInfo->ArtToolMajorRevision = GR2LibPropertyWrapper->ArtToolInfo->ToolVersion->Major;
656     _grn_file->GrannyFileInfo->ArtToolInfo->ArtToolMinorRevision = GR2LibPropertyWrapper->ArtToolInfo->ToolVersion->Minor;
657     _grn_file->GrannyFileInfo->ArtToolInfo->UnitsPerMeter = GR2LibPropertyWrapper->ArtToolInfo->UnitsPerMeter;
658 william 6
659    
660 william 84 _grn_file->GrannyFileInfo->ArtToolInfo->Origin[0] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Origin.x;
661     _grn_file->GrannyFileInfo->ArtToolInfo->Origin[1] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Origin.y;
662     _grn_file->GrannyFileInfo->ArtToolInfo->Origin[2] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Origin.z;
663 william 12
664 william 84 _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[0] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Right.x;
665     _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[1] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Right.y;
666     _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[2] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Right.z;
667 william 12
668 william 84 _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[0] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Up.x;
669     _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[1] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Up.y;
670     _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[2] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Up.z;
671 william 12
672 william 84 _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[0] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Back.x;
673     _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[1] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Back.y;
674     _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[2] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Back.z;
675 william 12
676 william 84 _grn_file->GrannyFileInfo->ArtToolInfo->ExtendedData = ExtendedData_ToNative(GR2LibPropertyWrapper->ArtToolInfo->ExtendedData,_grn_file->GrannyFileInfo->ArtToolInfo->ExtendedData);
677     }
678 william 12 }
679     #pragma endregion
680 william 14 #pragma region ExporterInfo_ToNative
681     void ExporterInfo_ToNative()
682     {
683 william 84 if (GR2LibPropertyWrapper->ExporterInfo != nullptr)
684 william 19 {
685 william 84 if (_grn_file->GrannyFileInfo->ExporterInfo == NULL)
686     {
687     _grn_file->GrannyFileInfo->ExporterInfo = new granny_exporter_info();
688     }
689     _grn_file->GrannyFileInfo->ExporterInfo->ExporterName = (char*)Marshal::StringToHGlobalAnsi(GR2LibPropertyWrapper->ExporterInfo->ExporterName).ToPointer();
690     _grn_file->GrannyFileInfo->ExporterInfo->ExporterMajorRevision = GR2LibPropertyWrapper->ExporterInfo->Version->major;
691     _grn_file->GrannyFileInfo->ExporterInfo->ExporterMinorRevision = GR2LibPropertyWrapper->ExporterInfo->Version->minor;
692     _grn_file->GrannyFileInfo->ExporterInfo->ExporterCustomization = GR2LibPropertyWrapper->ExporterInfo->Version->customization;
693     _grn_file->GrannyFileInfo->ExporterInfo->ExporterBuildNumber = GR2LibPropertyWrapper->ExporterInfo->Version->build;
694     _grn_file->GrannyFileInfo->ExporterInfo->ExtendedData = ExtendedData_ToNative(GR2LibPropertyWrapper->ExporterInfo->ExtendedData,_grn_file->GrannyFileInfo->ExporterInfo->ExtendedData);
695 william 19 }
696 william 14 }
697 william 12 #pragma endregion
698 william 22 #pragma region Textures_ToNative
699     void Textures_ToNative()
700     {
701 william 84 if (GR2LibPropertyWrapper->Textures != nullptr)
702 william 22 {
703 william 84 _grn_file->GrannyFileInfo->TextureCount = GR2LibPropertyWrapper->Textures->Count;
704     for(int i=0;i<_grn_file->GrannyFileInfo->TextureCount;i++)
705 william 51 {
706 william 84 _grn_file->GrannyFileInfo->Textures[i]->FromFileName = (char*)Marshal::StringToHGlobalAnsi(GR2LibPropertyWrapper->Textures[i]->FromFileName->FullPath).ToPointer();
707     _grn_file->GrannyFileInfo->Textures[i]->TextureType = (granny_int32)GR2LibPropertyWrapper->Textures[i]->TextureType->Value;
708     _grn_file->GrannyFileInfo->Textures[i]->Width = GR2LibPropertyWrapper->Textures[i]->Width;
709     _grn_file->GrannyFileInfo->Textures[i]->Height = GR2LibPropertyWrapper->Textures[i]->Height;
710     _grn_file->GrannyFileInfo->Textures[i]->Encoding = (granny_int32)GR2LibPropertyWrapper->Textures[i]->Encoding->Value;
711     _grn_file->GrannyFileInfo->Textures[i]->SubFormat = (granny_int32)GR2LibPropertyWrapper->Textures[i]->SubFormat->Value;
712 william 23
713 william 84 _grn_file->GrannyFileInfo->Textures[i]->Layout.BytesPerPixel = (granny_int32)GR2LibPropertyWrapper->Textures[i]->Layout->BytesPerPixel;
714     for(int j=0;j<granny_pixel_layout_bitshift_size;j++)
715 william 23 {
716 william 84 _grn_file->GrannyFileInfo->Textures[i]->Layout.ShiftForComponent[j] = GR2LibPropertyWrapper->Textures[i]->Layout->ShiftForComponent[j];
717     _grn_file->GrannyFileInfo->Textures[i]->Layout.BitsForComponent[j] = GR2LibPropertyWrapper->Textures[i]->Layout->BitsForComponent[j];
718     }
719 william 29
720 william 84 _grn_file->GrannyFileInfo->Textures[i]->ImageCount = GR2LibPropertyWrapper->Textures[i]->Images->Count;
721     _grn_file->GrannyFileInfo->Textures[i]->Images = (granny_texture_image*)malloc(_grn_file->GrannyFileInfo->Textures[i]->ImageCount);
722     for(int j=0;j<_grn_file->GrannyFileInfo->Textures[i]->ImageCount;j++)
723     {
724     _grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevelCount = GR2LibPropertyWrapper->Textures[i]->Images[j]->MIPLevels->Count;
725     _grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels = (granny_texture_mip_level*)malloc(_grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevelCount);
726     for(int k=0;k<_grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevelCount;k++)
727     {
728     _grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels[k].Stride = GR2LibPropertyWrapper->Textures[i]->Images[j]->MIPLevels[k]->Stride;
729     _grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels[k].PixelByteCount = GR2LibPropertyWrapper->Textures[i]->Images[j]->MIPLevels[k]->Pixels->PixelBytes->Count;
730     _grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels[k].PixelBytes = (unsigned char*)malloc(_grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels[k].PixelByteCount);
731 william 51
732 william 84
733     for (int l=0;l<_grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels[k].PixelByteCount;l++)
734     {
735     _grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels[k].PixelBytes[l] = GR2LibPropertyWrapper->Textures[i]->Images[j]->MIPLevels[k]->Pixels->PixelBytes[l];
736     }
737 william 23 }
738     }
739 william 84 _grn_file->GrannyFileInfo->Textures[i]->ExtendedData = ExtendedData_ToNative(GR2LibPropertyWrapper->Textures[i]->ExtendedData,_grn_file->GrannyFileInfo->Textures[i]->ExtendedData);
740 william 23 }
741 william 22 }
742     }
743 william 14 #pragma endregion
744 william 69 #pragma region Materials_ToNative
745     void Materials_ToNative()
746     {
747 william 84 if (GR2LibPropertyWrapper->Materials != nullptr)
748 william 69 {
749 william 84 _grn_file->GrannyFileInfo->MaterialCount = GR2LibPropertyWrapper->Materials->Count;
750     for(int i=0;i<_grn_file->GrannyFileInfo->MaterialCount;i++)
751     {
752     _grn_file->GrannyFileInfo->Materials[i]->Name = (char*)Marshal::StringToHGlobalAnsi(GR2LibPropertyWrapper->Materials[i]->Name).ToPointer();
753     // update extended data
754     _grn_file->GrannyFileInfo->Materials[i]->ExtendedData = ExtendedData_ToNative( GR2LibPropertyWrapper->Materials[i]->ExtendedData, _grn_file->GrannyFileInfo->Materials[i]->ExtendedData);
755     }
756 william 71 }
757     }
758     #pragma endregion
759 william 74 #pragma region Skeletons_ToNative
760     void Skeletons_ToNative()
761     {
762 william 84 if (GR2LibPropertyWrapper->Skeletons != nullptr)
763 william 74 {
764 william 84 _grn_file->GrannyFileInfo->SkeletonCount = GR2LibPropertyWrapper->Skeletons->Count;
765     for(int i=0;i<_grn_file->GrannyFileInfo->SkeletonCount;i++)
766 william 74 {
767 william 84 _grn_file->GrannyFileInfo->Skeletons[i]->Name = (char*)Marshal::StringToHGlobalAnsi(GR2LibPropertyWrapper->Skeletons[i]->Name).ToPointer();
768     _grn_file->GrannyFileInfo->Skeletons[i]->LODType = GR2LibPropertyWrapper->Skeletons[i]->LODType;
769     _grn_file->GrannyFileInfo->Skeletons[i]->BoneCount = GR2LibPropertyWrapper->Skeletons[i]->Bones->Count;
770     for(int j=0;j<_grn_file->GrannyFileInfo->Skeletons[i]->BoneCount;j++)
771     {
772     _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].Name = (char*)Marshal::StringToHGlobalAnsi(GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->Name).ToPointer();
773     _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].ParentIndex = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->ParentIndex;
774 william 74
775 william 84 // Update LocalTransform
776     _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LocalTransform.Flags = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LocalTransform->Dimensions;
777 william 74
778 william 84 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LocalTransform.Position[0] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LocalTransform->Origin.x;
779     _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LocalTransform.Position[1] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LocalTransform->Origin.y;
780     _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LocalTransform.Position[2] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LocalTransform->Origin.z;
781     _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LocalTransform.Orientation[0] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LocalTransform->Rotation.v.x;
782     _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LocalTransform.Orientation[1] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LocalTransform->Rotation.v.y;
783     _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LocalTransform.Orientation[2] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LocalTransform->Rotation.v.z;
784     _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LocalTransform.Orientation[3] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LocalTransform->Rotation.n;
785     _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LocalTransform.ScaleShear[0][0] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LocalTransform->Scale.right.x;
786     _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LocalTransform.ScaleShear[0][1] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LocalTransform->Scale.right.y;
787     _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LocalTransform.ScaleShear[0][2] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LocalTransform->Scale.right.z;
788     _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LocalTransform.ScaleShear[1][0] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LocalTransform->Scale.up.x;
789     _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LocalTransform.ScaleShear[1][1] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LocalTransform->Scale.up.y;
790     _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LocalTransform.ScaleShear[1][2] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LocalTransform->Scale.up.z;
791     _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LocalTransform.ScaleShear[2][0] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LocalTransform->Scale.at.x;
792     _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LocalTransform.ScaleShear[2][1] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LocalTransform->Scale.at.y;
793     _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LocalTransform.ScaleShear[2][2] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LocalTransform->Scale.at.z;
794     // Update InverseWorld4x4
795     _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].InverseWorld4x4[0][0] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->InverseWorld4x4.right.x;
796     _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].InverseWorld4x4[0][1] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->InverseWorld4x4.right.y;
797     _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].InverseWorld4x4[0][2] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->InverseWorld4x4.right.z;
798     _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].InverseWorld4x4[0][3] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->InverseWorld4x4.right.w;
799     _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].InverseWorld4x4[1][0] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->InverseWorld4x4.up.x;
800     _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].InverseWorld4x4[1][1] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->InverseWorld4x4.up.y;
801     _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].InverseWorld4x4[1][2] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->InverseWorld4x4.up.z;
802     _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].InverseWorld4x4[1][3] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->InverseWorld4x4.up.w;
803     _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].InverseWorld4x4[2][0] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->InverseWorld4x4.at.x;
804     _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].InverseWorld4x4[2][1] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->InverseWorld4x4.at.y;
805     _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].InverseWorld4x4[2][2] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->InverseWorld4x4.at.z;
806     _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].InverseWorld4x4[2][3] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->InverseWorld4x4.at.w;
807     _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].InverseWorld4x4[3][0] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->InverseWorld4x4.pos.x;
808     _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].InverseWorld4x4[3][1] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->InverseWorld4x4.pos.y;
809     _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].InverseWorld4x4[3][2] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->InverseWorld4x4.pos.z;
810     _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].InverseWorld4x4[3][3] = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->InverseWorld4x4.pos.w;
811    
812     _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LODError = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LODError;
813     _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].ExtendedData = ExtendedData_ToNative( GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->ExtendedData,_grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].ExtendedData);
814     }
815 william 74 }
816     }
817     }
818 william 71 #pragma endregion
819 william 93 #pragma region Models_ToNative
820     void Models_ToNative()
821     {
822     if (GR2LibPropertyWrapper->Models != nullptr)
823     {
824     }
825     }
826 william 74 #pragma endregion
827 william 71 #pragma region ExtendedDataToManagedNative
828     #pragma region ExtendedData_ToManaged
829     GrannyExtendedData^ ExtendedData_ToManaged(granny_variant NativeExtendedData)
830     {
831     ExtendedDataWrapper* ExtendedDataWrapped = new ExtendedDataWrapper(NativeExtendedData, _grn_file->_logger);
832     List<ExtendedDataMemberStruct^>^ _ExtendedDataMember = gcnew List<ExtendedDataMemberStruct^>(ExtendedDataWrapped->MemberCount);
833     for (int j=0;j<ExtendedDataWrapped->MemberCount;j++)
834     {
835     ExtendedDataMemberStruct^ _ExtendedDataMemberStruct = gcnew ExtendedDataMemberStruct();
836     _ExtendedDataMemberStruct->Index = ExtendedDataWrapped->ExtendedDataMembers[j].Index;
837     _ExtendedDataMemberStruct->Name = gcnew String(reinterpret_cast<const char*>(ExtendedDataWrapped->ExtendedDataMembers[j].Name.c_str()));
838     _ExtendedDataMemberStruct->Type = (gr2lib::core::typedefs::granny_member_type)(int)ExtendedDataWrapped->ExtendedDataMembers[j].Type;
839     _ExtendedDataMemberStruct->Value = ExtendedDataWrapped->GetRealExtendedDataMemberValue(_ExtendedDataMemberStruct->Index);
840     _ExtendedDataMember->Add(_ExtendedDataMemberStruct);
841     }
842     return gcnew GrannyExtendedData(_ExtendedDataMember);
843     }
844     #pragma endregion
845     #pragma region ExtendedData_ToNative
846     granny_variant ExtendedData_ToNative(GrannyExtendedData^ ManagedExtendedData, granny_variant NativeExtendedData)
847     {
848 william 69
849 william 71 ExtendedDataWrapper* ExtendedDataWrapped = new ExtendedDataWrapper(NativeExtendedData, _grn_file->_logger);
850     int MemberCount = ManagedExtendedData->ExtendedData->Count;
851     for(int j=0;j<MemberCount;j++)
852     {
853     Object^ value = ManagedExtendedData->ExtendedData[j]->Value;
854     if (value->ToString() == (gcnew Object())->ToString()) continue;
855     int MemberType = ExtendedDataWrapped->ExtendedDataMembers[j].Type;
856     switch(ExtendedDataWrapped->ExtendedDataMembers[j].Type)
857     {
858 william 69 // //case granny_member_type::GrannyEndMember: return new void*(); break;
859     // //case granny_member_type::GrannyInlineMember: return new void*(); break;
860     // //case granny_member_type::GrannyReferenceMember: return new void*(); break;
861     // //case granny_member_type::GrannyReferenceToArrayMember: return new void*();break;
862     // //case granny_member_type::GrannyArrayOfReferencesMember: return new void*(); break;
863     // //case granny_member_type::GrannyVariantReferenceMember: return new void*(); break;
864     // //case granny_member_type::GrannyUnsupportedMemberType_Remove: return new void*(); break;
865     // //case granny_member_type::GrannyReferenceToVariantArrayMember: return new void*(); break;
866 william 71 case granny_member_type::GrannyStringMember:
867     char* _string;
868     _string = (char*)Marshal::StringToHGlobalAnsi((System::String^)value).ToPointer();
869     ((char*(*)[MAX_GRANNY_MEMBER_COUNT])NativeExtendedData.Object)[0][j] = _string;
870     break;
871     //case granny_member_type::GrannyTransformMember: return new void*();break;
872     case granny_member_type::GrannyReal32Member:
873     ((granny_real32(*)[MAX_GRANNY_MEMBER_COUNT])NativeExtendedData.Object)[0][j] = (granny_real32)value; break;
874     case granny_member_type::GrannyInt8Member:
875     ((granny_int8(*)[MAX_GRANNY_MEMBER_COUNT])NativeExtendedData.Object)[0][j] = (granny_int8)value; break;
876     case granny_member_type::GrannyUInt8Member:
877     ((granny_uint8(*)[MAX_GRANNY_MEMBER_COUNT])NativeExtendedData.Object)[0][j] =(granny_uint8)value; break;
878     case granny_member_type::GrannyBinormalInt8Member:
879     ((granny_int8(*)[MAX_GRANNY_MEMBER_COUNT])NativeExtendedData.Object)[0][j] = (granny_int8)value; break;
880     case granny_member_type::GrannyNormalUInt8Member:
881     ((granny_uint8(*)[MAX_GRANNY_MEMBER_COUNT])NativeExtendedData.Object)[0][j] = (granny_uint8)value; break;
882     case granny_member_type::GrannyInt16Member:
883     ((granny_int16(*)[MAX_GRANNY_MEMBER_COUNT])NativeExtendedData.Object)[0][j] = (granny_int16)value; break;
884     case granny_member_type::GrannyUInt16Member:
885     ((granny_uint16(*)[MAX_GRANNY_MEMBER_COUNT])NativeExtendedData.Object)[0][j] = (granny_uint16)value; break;
886     case granny_member_type::GrannyBinormalInt16Member:
887     ((granny_int16(*)[MAX_GRANNY_MEMBER_COUNT])NativeExtendedData.Object)[0][j] = (granny_int16)value; break;
888     case granny_member_type::GrannyNormalUInt16Member:
889     ((granny_uint16(*)[MAX_GRANNY_MEMBER_COUNT])NativeExtendedData.Object)[0][j] = (granny_uint16)value; break;
890     case granny_member_type::GrannyInt32Member:
891     ((granny_int32(*)[MAX_GRANNY_MEMBER_COUNT])NativeExtendedData.Object)[0][j] = (granny_int32)value; break;
892     case granny_member_type::GrannyUInt32Member:
893     ((granny_uint32(*)[MAX_GRANNY_MEMBER_COUNT])NativeExtendedData.Object)[0][j] = (granny_uint32)value; break;
894     case granny_member_type::GrannyReal16Member:
895     ((granny_real16(*)[MAX_GRANNY_MEMBER_COUNT])NativeExtendedData.Object)[0][j] = (granny_real16)value; break;
896 william 69 //case granny_member_type::GrannyEmptyReferenceMember:
897     // ((granny_int32(*)[MAX_GRANNY_MEMBER_COUNT])_grn_file->GrannyFileInfo->Materials[i]->ExtendedData.Object)[0][j] = value; break;
898 william 71 //case granny_member_type::GrannyOnePastLastMemberType: break;
899     //case granny_member_type::GrannyBool32Member: break;
900     default: throw gcnew System::InvalidOperationException("Encountered an Invalid Granny Member Type: " + MemberType);
901 william 69 }
902     }
903 william 71
904     return NativeExtendedData;
905 william 69 }
906 william 22 #pragma endregion
907 william 69 #pragma endregion
908 william 12 #pragma endregion
909 william 51
910 william 6 private: System::Void mnuItemExit_Click(System::Object^ sender, System::EventArgs^ e)
911 william 84 {
912 william 89 if (this->IsRigLoaded && this->RigContainsUnsavedChanges)
913     {
914     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);
915     if (result != System::Windows::Forms::DialogResult::Yes) mnuItemSave->PerformClick();
916     }
917 william 6 this->Close();
918     }
919     private: System::Void mnuItemOpen_Click(System::Object^ sender, System::EventArgs^ e)
920     {
921 william 89 if (this->IsRigLoaded && this->RigContainsUnsavedChanges)
922     {
923     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);
924     if (result == System::Windows::Forms::DialogResult::Yes) mnuItemSave->PerformClick();
925     }
926 william 19 System::Windows::Forms::DialogResult result = RigLoader->ShowDialog();
927     if (result != System::Windows::Forms::DialogResult::OK) return;
928     const char* fn = (char*)Marshal::StringToHGlobalAnsi(RigLoader->FileName).ToPointer();
929    
930 william 12 _grn_file = new grannyfile();
931     const char* loading_msg = "Loading File: ";
932     int msg_malloc = (strlen(loading_msg) + strlen(fn));
933     char* msg = (char*)malloc(msg_malloc);
934     for (int i=0; i<msg_malloc; i++) { msg[i] = 0; }
935     strcat(msg,loading_msg);
936     strcat(msg,fn);
937     strcat(msg,"\n");
938     _grn_file->_logger->LogMessage(msg);
939     //_grn_file->_logger->SetLogFileName("c:\\gr2_logs",fn);
940     _grn_file = new grannyfile(fn);
941    
942 william 29 this->GR2LibPropertyWrapper = gcnew GR2LibWrapper();
943     ConvertToManaged();
944 william 93 propgrid->SelectedObject = this->GR2LibPropertyWrapper;
945 william 89 this->IsRigLoaded = true;
946     this->RigContainsUnsavedChanges = false;
947 william 6 }
948 william 12 private: System::Void gr2lib_rigeditor_frm_FormClosed(System::Object^ sender, System::Windows::Forms::FormClosedEventArgs^ e)
949     {
950     //TerminateConsoleIO();
951     }
952 william 19 private: System::Void gr2lib_rigeditor_frm_Load(System::Object^ sender, System::EventArgs^ e)
953     {
954     #if defined SHOW_DEBUG_MENU
955     mnuDebug->Visible = true;
956     #else
957     mnuDebug->Visible = false;
958     #endif
959     }
960     private: System::Void mnuTestArtToolInfoReturnValues_Click(System::Object^ sender, System::EventArgs^ e)
961     {
962     // Convert ArtToolInfo To Native, and ouput the values -> to check that they were updated correctly
963     ArtToolInfo_ToNative();
964     VSDebugWriterW VSDebugWriter;
965     VSDebugWriter
966     << "\n\n\tArtToolInfo ->"
967     << "\n\t\tTool Name: "
968 william 29 << _grn_file->GrannyFileInfo->ArtToolInfo->FromArtToolName
969 william 19 << "\n\t\tTool Version: "
970 william 29 << _grn_file->GrannyFileInfo->ArtToolInfo->ArtToolMajorRevision
971     << "." << _grn_file->GrannyFileInfo->ArtToolInfo->ArtToolMinorRevision
972     << "\n\t\tUnits Per Meter: "
973     << _grn_file->GrannyFileInfo->ArtToolInfo->UnitsPerMeter
974     << "\n\t\tOrigin: "
975     << "\n\t\t\tX: "
976     << _grn_file->GrannyFileInfo->ArtToolInfo->Origin[0]
977     << "\n\t\t\tY: "
978     << _grn_file->GrannyFileInfo->ArtToolInfo->Origin[1]
979     << "\n\t\t\tZ: "
980     << _grn_file->GrannyFileInfo->ArtToolInfo->Origin[2]
981     << "\n\t\tRight: "
982     << "\n\t\t\tX: "
983     << _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[0]
984     << "\n\t\t\tY: "
985     << _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[1]
986     << "\n\t\t\tZ: "
987     << _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[2]
988     << "\n\t\tUp: "
989     << "\n\t\t\tX: "
990     << _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[0]
991     << "\n\t\t\tY: "
992     << _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[1]
993     << "\n\t\t\tZ: "
994     << _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[2]
995     << "\n\t\tBack: "
996     << "\n\t\t\tX: "
997     << _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[0]
998     << "\n\t\t\tY: "
999     << _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[1]
1000     << "\n\t\t\tZ: "
1001     << _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[2]
1002 william 19 ;
1003     }
1004     private: System::Void mnuTestExporterInfoReturnValues_Click(System::Object^ sender, System::EventArgs^ e)
1005     {
1006 william 29 // Convert ExporterInfo To Native, and ouput the values -> to check that they were updated correctly
1007     ExporterInfo_ToNative();
1008 william 19 VSDebugWriterW VSDebugWriter;
1009     VSDebugWriter
1010     << "\n\n\tExporterInfo ->"
1011     << "\n\t\tExporter Name: "
1012 william 29 << _grn_file->GrannyFileInfo->ExporterInfo->ExporterName
1013 william 19 << "\n\t\tExporter Version: "
1014 william 29 << _grn_file->GrannyFileInfo->ExporterInfo->ExporterMajorRevision
1015     << "." << _grn_file->GrannyFileInfo->ExporterInfo->ExporterMinorRevision
1016     << "." << _grn_file->GrannyFileInfo->ExporterInfo->ExporterCustomization
1017     << "." << _grn_file->GrannyFileInfo->ExporterInfo->ExporterBuildNumber
1018 william 19 ;
1019     }
1020     private: System::Void mnuItemSave_Click(System::Object^ sender, System::EventArgs^ e)
1021     {
1022     // convert Data to Native
1023 william 50 try
1024 william 89 {
1025     if (!this->IsRigLoaded)
1026     {
1027     System::Windows::Forms::MessageBox::Show("Please open a Granny2 Rig file before attempting to save it.", "File Writer:", MessageBoxButtons::OK,MessageBoxIcon::Asterisk);
1028     return;
1029     }
1030 william 50 ConvertToNative();
1031     const char* filename = _grn_file->_GrannyFilename;
1032 william 51 GrannyFileWriter::WriteFile(filename,_grn_file->GrannyFileInfo,_grn_file->_logger);
1033 william 50 System::Windows::Forms::MessageBox::Show("Successfully Saved: \n" + gcnew String(_grn_file->GrannyFilename()),"File Writer:", MessageBoxButtons::OK,MessageBoxIcon::Information);
1034 william 89 this->RigContainsUnsavedChanges = false;
1035 william 50 }
1036     catch(Exception^ ex)
1037     {
1038     System::Windows::Forms::MessageBox::Show("Failed to Save: \n" + gcnew String(_grn_file->GrannyFilename()),"File Writer:", MessageBoxButtons::OK,MessageBoxIcon::Error);
1039     }
1040 william 19 }
1041     private: System::Void mnuItemSaveAs_Click(System::Object^ sender, System::EventArgs^ e)
1042     {
1043 william 29 // convert Data to Native
1044 william 50 try
1045     {
1046 william 89 if (!this->IsRigLoaded)
1047     {
1048     System::Windows::Forms::MessageBox::Show("Please open a Granny2 Rig file before attempting to save it.", "File Writer:", MessageBoxButtons::OK,MessageBoxIcon::Asterisk);
1049     return;
1050     }
1051 william 50 ConvertToNative();
1052     System::Windows::Forms::DialogResult result = RigSaver->ShowDialog();
1053     if (result != System::Windows::Forms::DialogResult::OK) return;
1054     const char* filename = (char*)Marshal::StringToHGlobalAnsi(RigSaver->FileName).ToPointer();
1055 william 51 GrannyFileWriter::WriteFile(filename,_grn_file->GrannyFileInfo,_grn_file->_logger);
1056 william 50 System::Windows::Forms::MessageBox::Show("Successfully Saved: \n" + gcnew String(_grn_file->GrannyFilename()),"File Writer:", MessageBoxButtons::OK,MessageBoxIcon::Information);
1057 william 89 this->RigContainsUnsavedChanges = false;
1058 william 50 }
1059     catch(Exception^ ex)
1060     {
1061     System::Windows::Forms::MessageBox::Show("Failed to Save: \n" + gcnew String(_grn_file->GrannyFilename()),"File Writer:", MessageBoxButtons::OK,MessageBoxIcon::Error);
1062     }
1063 william 19 }
1064 william 26 private: System::Void mnuItemClose_Click(System::Object^ sender, System::EventArgs^ e)
1065     {
1066 william 89 if (this->IsRigLoaded && this->RigContainsUnsavedChanges)
1067     {
1068     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);
1069     if (result == System::Windows::Forms::DialogResult::Yes) mnuItemSave->PerformClick();
1070     }
1071 william 55 propgrid->SelectedObject = nullptr;
1072 william 89 this->IsRigLoaded = false;
1073     this->RigContainsUnsavedChanges = false;
1074 william 26 }
1075 william 89 private: System::Void propgrid_PropertyValueChanged(System::Object^ s, System::Windows::Forms::PropertyValueChangedEventArgs^ e)
1076     {
1077     this->RigContainsUnsavedChanges =true;
1078     }
1079 william 6 };
1080     // }
1081     // }
1082 william 7 //}
1083 william 50 #endif /* GR2LIB_RIGEDITOR_FRM_H */

  ViewVC Help
Powered by ViewVC 1.1.22