/[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 84 - (show annotations) (download)
Sat Aug 14 20:21:40 2010 UTC (9 years, 6 months ago) by william
File MIME type: text/plain
File size: 49225 byte(s)
Add Support for:
** Only displaying the Granny2 Properties that are needed (don't show things that don't exist in the rig file)
** Add initial class for VertexData (currently unimplemented)

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

  ViewVC Help
Powered by ViewVC 1.1.22