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

Contents of /trunk/gr2lib_cpp/gr2lib_rigeditor_frm.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 93 - (show 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 #define _CRT_SECURE_NO_WARNINGS
2 #pragma warning( disable : 4100 ) // disable 'unreferenced formal parameter' warnings
3 #pragma warning( disable : 4101 ) // disable 'unreferenced local variable' warnings
4 #pragma warning( disable : 4482 ) // disable 'nonstandard extension used' warnings (related to case switch statements using enums)
5
6 #define SHOW_DEBUG_MENU // if defined, will show the debug menu -> else it will not be shown
7
8 #define granny_pixel_layout_bitshift_size 4
9
10 #pragma once
11 //#include "gr2lib_core.h"
12 //#include "gr2lib_core_imports.h"
13 #ifndef GR2LIB_RIGEDITOR_FRM_H
14 #define GR2LIB_RIGEDITOR_FRM_H
15 #include "..\gr2lib_cpp_typedefs\core.h"
16 #include "grannyfile.h"
17 //#include "guicon.h"
18 #include "VSDebugOutput.h"
19 #include "GrannyFileWriter.h"
20 #include <stdio.h>
21 #include <iostream>
22 #include <stdlib.h>
23 #include <assert.h>
24 #include <string>
25 #include <sstream>
26 #include <vcclr.h>
27 using namespace std;
28
29 using namespace gr2lib_cpp::typedefs;
30 using namespace gr2lib::core;
31 using namespace gr2lib::core::coretypes::implementation;
32 using namespace gr2lib::core::apiversion;
33 using namespace gr2lib::core::ui::helpers;
34 using namespace gr2lib::core::helpers;
35 using namespace System;
36 using namespace System::ComponentModel;
37 using namespace System::Collections;
38 using namespace System::Collections::Generic;
39 using namespace System::Windows::Forms;
40 using namespace System::Data;
41 using namespace System::Drawing;
42 using namespace System::Runtime::InteropServices;
43 //using namespace Microsoft::Xna::Framework;
44 //using namespace Microsoft::Xna::Framework::Graphics;
45 //
46 //namespace gr2lib
47 //{
48 // namespace core
49 // {
50 // namespace rigeditor
51 // {
52 /// <summary>
53 /// Summary for gr2lib_rigeditor_frm
54 ///
55 /// WARNING: If you change the name of this class, you will need to change the
56 /// 'Resource File Name' property for the managed resource compiler tool
57 /// associated with all .resx files this class depends on. Otherwise,
58 /// the designers will not be able to interact properly with localized
59 /// resources associated with this form.
60 /// </summary>
61 public ref class gr2lib_rigeditor_frm : public System::Windows::Forms::Form
62 {
63 private:
64
65 bool IsRigLoaded;
66 bool RigContainsUnsavedChanges;
67 grannyfile* _grn_file;
68 void LogApplicationStartup()
69 {
70 const char* ApplicationName = "GR2Lib Rig Editor: ";
71
72 const char* product_version = (char*)(void*)Marshal::StringToHGlobalAnsi(Application::ProductVersion);
73 const char* version_prefix = "v";
74 const char* startup_string = " {Starting up...}";
75
76
77 int msg_malloc = (strlen(ApplicationName) + strlen(product_version) + strlen(version_prefix) + strlen(startup_string)) + 3;
78
79 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
84 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 this->GR2LibPropertyWrapper = gcnew GR2LibWrapper();
112 ConvertToManaged();
113 propgrid->SelectedObject = this->GR2LibPropertyWrapper;
114 }
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 private: System::Windows::Forms::ToolStripMenuItem^ mnuDebug;
136 private: System::Windows::Forms::ToolStripMenuItem^ mnuDebug_UnitTests;
137 private: System::Windows::Forms::ToolStripMenuItem^ mnuTestArtToolInfoReturnValues;
138
139 private: System::Windows::Forms::OpenFileDialog^ RigLoader;
140 private: System::Windows::Forms::ToolStripMenuItem^ mnuTestExporterInfoReturnValues;
141 private: System::Windows::Forms::SaveFileDialog^ RigSaver;
142 private: System::Windows::Forms::ToolStripMenuItem^ mnuItemClose;
143 private: System::Windows::Forms::ToolStripMenuItem^ mnuItemTestDDSRender;
144
145
146
147
148
149 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 this->mnuItemClose = (gcnew System::Windows::Forms::ToolStripMenuItem());
169 this->mnuItemSave = (gcnew System::Windows::Forms::ToolStripMenuItem());
170 this->mnuItemSaveAs = (gcnew System::Windows::Forms::ToolStripMenuItem());
171 this->mnuItemExit = (gcnew System::Windows::Forms::ToolStripMenuItem());
172 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 this->mnuItemTestDDSRender = (gcnew System::Windows::Forms::ToolStripMenuItem());
177 this->RigLoader = (gcnew System::Windows::Forms::OpenFileDialog());
178 this->RigSaver = (gcnew System::Windows::Forms::SaveFileDialog());
179 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 this->propgrid->PropertySort = System::Windows::Forms::PropertySort::Categorized;
188 this->propgrid->Size = System::Drawing::Size(558, 456);
189 this->propgrid->TabIndex = 4;
190 this->propgrid->ToolbarVisible = false;
191 this->propgrid->PropertyValueChanged += gcnew System::Windows::Forms::PropertyValueChangedEventHandler(this, &gr2lib_rigeditor_frm::propgrid_PropertyValueChanged);
192 //
193 // mainmenu
194 //
195 this->mainmenu->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {this->mnuFile, this->mnuDebug});
196 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 this->mnuFile->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(5) {this->mnuItemOpen,
205 this->mnuItemClose, this->mnuItemSave, this->mnuItemSaveAs, this->mnuItemExit});
206 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 this->mnuItemOpen->Size = System::Drawing::Size(152, 22);
214 this->mnuItemOpen->Text = L"&Open";
215 this->mnuItemOpen->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuItemOpen_Click);
216 //
217 // mnuItemClose
218 //
219 this->mnuItemClose->Name = L"mnuItemClose";
220 this->mnuItemClose->Size = System::Drawing::Size(152, 22);
221 this->mnuItemClose->Text = L"&Close";
222 this->mnuItemClose->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuItemClose_Click);
223 //
224 // mnuItemSave
225 //
226 this->mnuItemSave->Name = L"mnuItemSave";
227 this->mnuItemSave->Size = System::Drawing::Size(152, 22);
228 this->mnuItemSave->Text = L"&Save";
229 this->mnuItemSave->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuItemSave_Click);
230 //
231 // mnuItemSaveAs
232 //
233 this->mnuItemSaveAs->Name = L"mnuItemSaveAs";
234 this->mnuItemSaveAs->Size = System::Drawing::Size(152, 22);
235 this->mnuItemSaveAs->Text = L"Save &As";
236 this->mnuItemSaveAs->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuItemSaveAs_Click);
237 //
238 // mnuItemExit
239 //
240 this->mnuItemExit->Name = L"mnuItemExit";
241 this->mnuItemExit->Size = System::Drawing::Size(152, 22);
242 this->mnuItemExit->Text = L"&Exit";
243 this->mnuItemExit->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuItemExit_Click);
244 //
245 // mnuDebug
246 //
247 this->mnuDebug->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {this->mnuDebug_UnitTests,
248 this->mnuItemTestDDSRender});
249 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 this->mnuDebug_UnitTests->Size = System::Drawing::Size(161, 22);
259 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 // 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 // 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 // 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 this->Load += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::gr2lib_rigeditor_frm_Load);
305 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
314
315
316 #pragma region MarshalToManagedNative
317 //ArtToolInfo^ _ArtToolInfo;
318 //ExporterInfo^ _ExporterInfo;
319 GR2LibWrapper^ GR2LibPropertyWrapper;
320 #pragma region ManagedNativeParsing
321 void ConvertToManaged()
322 {
323 // Art Tool info
324 ArtToolInfo_ToManaged(_grn_file->GrannyFileInfo->ArtToolInfo);
325 // Exporter Info
326 ExporterInfo_ToManaged(_grn_file->GrannyFileInfo->ExporterInfo);
327 // Texture List
328 Textures_ToManaged(_grn_file->GrannyFileInfo->Textures,_grn_file->GrannyFileInfo->TextureCount);
329 // Material List
330 Materials_ToManaged(_grn_file->GrannyFileInfo->Materials,_grn_file->GrannyFileInfo->MaterialCount);
331 // Skeleton List
332 Skeletons_ToManaged(_grn_file->GrannyFileInfo->Skeletons, _grn_file->GrannyFileInfo->SkeletonCount);
333 // Model List
334 Models_ToManaged(_grn_file->GrannyFileInfo->Models,_grn_file->GrannyFileInfo->ModelCount);
335 }
336 void ConvertToNative()
337 {
338 // Art Tool info
339 ArtToolInfo_ToNative();
340 // Exporter Info
341 ExporterInfo_ToNative();
342 // Texture List
343 Textures_ToNative();
344 // Material List
345 Materials_ToNative();
346 // Skeleton List
347 Skeletons_ToNative();
348 // Model List
349 Models_ToNative();
350 }
351 #pragma endregion
352 #pragma region MarshalToMananaged
353 #pragma region ArtToolInfo_ToManaged
354 void ArtToolInfo_ToManaged(granny_art_tool_info* toolinfo)
355 {
356 //GR2LibPropertyWrapper->ArtToolInfo = gcnew ArtToolInfo();
357 if (toolinfo != NULL)
358 {
359 GR2LibPropertyWrapper->ArtToolInfo = gcnew ArtToolInfo();
360 GR2LibPropertyWrapper->ArtToolInfo->FromArtToolName = gcnew String(reinterpret_cast<const char*>(toolinfo->FromArtToolName));
361
362 // 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
381 // Tool Version
382 GR2LibPropertyWrapper->ArtToolInfo->ToolVersion = gcnew ArtToolInfoVersion(toolinfo->ArtToolMajorRevision,toolinfo->ArtToolMinorRevision);
383 // Tool Units Per Meter
384 GR2LibPropertyWrapper->ArtToolInfo->UnitsPerMeter = toolinfo->UnitsPerMeter;
385 // Get Extended Data
386 GR2LibPropertyWrapper->ArtToolInfo->ExtendedData = ExtendedData_ToManaged(toolinfo->ExtendedData);
387 }
388 }
389 #pragma endregion
390 #pragma region ExporterInfo_ToManaged
391 void ExporterInfo_ToManaged(granny_exporter_info* toolinfo)
392 {
393 //GR2LibPropertyWrapper->ExporterInfo = gcnew ExporterInfo();
394 if (toolinfo != NULL)
395 {
396 GR2LibPropertyWrapper->ExporterInfo = gcnew ExporterInfo();
397 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 GR2LibPropertyWrapper->ExporterInfo->ExtendedData = ExtendedData_ToManaged(toolinfo->ExtendedData);
404 }
405
406 }
407 #pragma endregion
408 #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
418 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
434 //t->Layout = gr2lib::core::typedefs::granny_pixel_layouts::GetPixelLayoutFromEnum(t->SubFormat->Value);
435
436 t->Layout = gcnew gr2lib::core::coretypes::implementation::Layout();
437 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
445 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
451 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 mip->Pixels = gcnew gr2lib::core::coretypes::implementation::Pixel();
456
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 mip->Pixels->NativeTexture = t;
465 mip->Pixels->NativeTexturePointer = *new IntPtr(toolinfo[i]);
466 mip->Pixels->ImageIndex = j;
467 mip->Pixels->MipIndex = k;
468
469 for(int l =0;l<toolinfo[i]->Images[j].MIPLevels[k].PixelByteCount;l++)
470 {
471 mip->Pixels->PixelBytes->Add(bytes[l]);
472 }
473 img->MIPLevels->Add(mip);
474
475 }
476 t->Images->Add(img);
477 t->NativePointer = *new IntPtr(toolinfo[i]);
478 t->ExtendedData = ExtendedData_ToManaged(toolinfo[i]->ExtendedData);
479 }
480 GR2LibPropertyWrapper->Textures->Add(t);
481 }
482 }
483 }
484 #pragma endregion
485 #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 if (toolinfo[i]->Texture != NULL) { m = gcnew Material(*new IntPtr(&toolinfo[i]->Texture)); }
495
496 m->Name = gcnew String(reinterpret_cast<const char*>(toolinfo[i]->Name));
497 m->ExtendedData = ExtendedData_ToManaged(toolinfo[i]->ExtendedData);
498 m->NativePointer = *new IntPtr(toolinfo[i]);
499 GR2LibPropertyWrapper->Materials->Add(m);
500 }
501 }
502 }
503 #pragma endregion
504 #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
525
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 );
554
555
556
557 Matrix44^ _matrix44 = gcnew Matrix44(_transform->Matrix);
558 _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 );
564 _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 );
570 _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 );
576 _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 _transform->Matrix = *_matrix44;
583 b->LocalTransform = _transform;
584 //b->InverseWorld4x4 = *_matrix44;
585 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 #pragma endregion
595 #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 #pragma endregion
642 #pragma endregion
643 #pragma region MarshalToNative
644 #pragma region ArtToolInfo_ToNative
645 void ArtToolInfo_ToNative()
646 {
647 if (GR2LibPropertyWrapper->ArtToolInfo != nullptr)
648 {
649 if (_grn_file->GrannyFileInfo->ArtToolInfo == NULL)
650 {
651 _grn_file->GrannyFileInfo->ArtToolInfo = new granny_art_tool_info();
652 }
653
654 _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
659
660 _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
664 _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
668 _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
672 _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
676 _grn_file->GrannyFileInfo->ArtToolInfo->ExtendedData = ExtendedData_ToNative(GR2LibPropertyWrapper->ArtToolInfo->ExtendedData,_grn_file->GrannyFileInfo->ArtToolInfo->ExtendedData);
677 }
678 }
679 #pragma endregion
680 #pragma region ExporterInfo_ToNative
681 void ExporterInfo_ToNative()
682 {
683 if (GR2LibPropertyWrapper->ExporterInfo != nullptr)
684 {
685 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 }
696 }
697 #pragma endregion
698 #pragma region Textures_ToNative
699 void Textures_ToNative()
700 {
701 if (GR2LibPropertyWrapper->Textures != nullptr)
702 {
703 _grn_file->GrannyFileInfo->TextureCount = GR2LibPropertyWrapper->Textures->Count;
704 for(int i=0;i<_grn_file->GrannyFileInfo->TextureCount;i++)
705 {
706 _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
713 _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 {
716 _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
720 _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
732
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 }
738 }
739 _grn_file->GrannyFileInfo->Textures[i]->ExtendedData = ExtendedData_ToNative(GR2LibPropertyWrapper->Textures[i]->ExtendedData,_grn_file->GrannyFileInfo->Textures[i]->ExtendedData);
740 }
741 }
742 }
743 #pragma endregion
744 #pragma region Materials_ToNative
745 void Materials_ToNative()
746 {
747 if (GR2LibPropertyWrapper->Materials != nullptr)
748 {
749 _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 }
757 }
758 #pragma endregion
759 #pragma region Skeletons_ToNative
760 void Skeletons_ToNative()
761 {
762 if (GR2LibPropertyWrapper->Skeletons != nullptr)
763 {
764 _grn_file->GrannyFileInfo->SkeletonCount = GR2LibPropertyWrapper->Skeletons->Count;
765 for(int i=0;i<_grn_file->GrannyFileInfo->SkeletonCount;i++)
766 {
767 _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
775 // Update LocalTransform
776 _grn_file->GrannyFileInfo->Skeletons[i]->Bones[j].LocalTransform.Flags = GR2LibPropertyWrapper->Skeletons[i]->Bones[j]->LocalTransform->Dimensions;
777
778 _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 }
816 }
817 }
818 #pragma endregion
819 #pragma region Models_ToNative
820 void Models_ToNative()
821 {
822 if (GR2LibPropertyWrapper->Models != nullptr)
823 {
824 }
825 }
826 #pragma endregion
827 #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
849 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 // //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 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 //case granny_member_type::GrannyEmptyReferenceMember:
897 // ((granny_int32(*)[MAX_GRANNY_MEMBER_COUNT])_grn_file->GrannyFileInfo->Materials[i]->ExtendedData.Object)[0][j] = value; break;
898 //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 }
902 }
903
904 return NativeExtendedData;
905 }
906 #pragma endregion
907 #pragma endregion
908 #pragma endregion
909
910 private: System::Void mnuItemExit_Click(System::Object^ sender, System::EventArgs^ e)
911 {
912 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 this->Close();
918 }
919 private: System::Void mnuItemOpen_Click(System::Object^ sender, System::EventArgs^ e)
920 {
921 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 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 _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 this->GR2LibPropertyWrapper = gcnew GR2LibWrapper();
943 ConvertToManaged();
944 propgrid->SelectedObject = this->GR2LibPropertyWrapper;
945 this->IsRigLoaded = true;
946 this->RigContainsUnsavedChanges = false;
947 }
948 private: System::Void gr2lib_rigeditor_frm_FormClosed(System::Object^ sender, System::Windows::Forms::FormClosedEventArgs^ e)
949 {
950 //TerminateConsoleIO();
951 }
952 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 << _grn_file->GrannyFileInfo->ArtToolInfo->FromArtToolName
969 << "\n\t\tTool Version: "
970 << _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 ;
1003 }
1004 private: System::Void mnuTestExporterInfoReturnValues_Click(System::Object^ sender, System::EventArgs^ e)
1005 {
1006 // Convert ExporterInfo To Native, and ouput the values -> to check that they were updated correctly
1007 ExporterInfo_ToNative();
1008 VSDebugWriterW VSDebugWriter;
1009 VSDebugWriter
1010 << "\n\n\tExporterInfo ->"
1011 << "\n\t\tExporter Name: "
1012 << _grn_file->GrannyFileInfo->ExporterInfo->ExporterName
1013 << "\n\t\tExporter Version: "
1014 << _grn_file->GrannyFileInfo->ExporterInfo->ExporterMajorRevision
1015 << "." << _grn_file->GrannyFileInfo->ExporterInfo->ExporterMinorRevision
1016 << "." << _grn_file->GrannyFileInfo->ExporterInfo->ExporterCustomization
1017 << "." << _grn_file->GrannyFileInfo->ExporterInfo->ExporterBuildNumber
1018 ;
1019 }
1020 private: System::Void mnuItemSave_Click(System::Object^ sender, System::EventArgs^ e)
1021 {
1022 // convert Data to Native
1023 try
1024 {
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 ConvertToNative();
1031 const char* filename = _grn_file->_GrannyFilename;
1032 GrannyFileWriter::WriteFile(filename,_grn_file->GrannyFileInfo,_grn_file->_logger);
1033 System::Windows::Forms::MessageBox::Show("Successfully Saved: \n" + gcnew String(_grn_file->GrannyFilename()),"File Writer:", MessageBoxButtons::OK,MessageBoxIcon::Information);
1034 this->RigContainsUnsavedChanges = false;
1035 }
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 }
1041 private: System::Void mnuItemSaveAs_Click(System::Object^ sender, System::EventArgs^ e)
1042 {
1043 // convert Data to Native
1044 try
1045 {
1046 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 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 GrannyFileWriter::WriteFile(filename,_grn_file->GrannyFileInfo,_grn_file->_logger);
1056 System::Windows::Forms::MessageBox::Show("Successfully Saved: \n" + gcnew String(_grn_file->GrannyFilename()),"File Writer:", MessageBoxButtons::OK,MessageBoxIcon::Information);
1057 this->RigContainsUnsavedChanges = false;
1058 }
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 }
1064 private: System::Void mnuItemClose_Click(System::Object^ sender, System::EventArgs^ e)
1065 {
1066 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 propgrid->SelectedObject = nullptr;
1072 this->IsRigLoaded = false;
1073 this->RigContainsUnsavedChanges = false;
1074 }
1075 private: System::Void propgrid_PropertyValueChanged(System::Object^ s, System::Windows::Forms::PropertyValueChangedEventArgs^ e)
1076 {
1077 this->RigContainsUnsavedChanges =true;
1078 }
1079 };
1080 // }
1081 // }
1082 //}
1083 #endif /* GR2LIB_RIGEDITOR_FRM_H */

  ViewVC Help
Powered by ViewVC 1.1.22