This repository has been archived by the owner on Apr 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathfbxExport.cpp
5339 lines (4773 loc) · 183 KB
/
fbxExport.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*Release uncomment remove all instances of this to restore fbx extract
#include <fbxsdk.h>
#include "tilemap.h"
#include "gameobjects.h"
#include "main.h"
#include "fbxExport.h"
#include "gameobjectsrender.h"
#include "textures.h"
#include <vector>
int PrimCount = 0;
//FbxSurfacePhong* gMaterial[280];// = NULL;
bool InitializeSdkObjects(FbxManager*& pManager, FbxScene*& pScene);
void DestroySdkObjects(FbxManager* pManager, bool pExitStatus);
void SetInitialCubeData();
bool SaveScene(FbxManager* pSdkManager, FbxDocument* pScene, const char* pFilename, int pFileFormat, bool pEmbedMedia);
void RenderFBXTile(FbxScene*& gScene, int game, int x, int y, tile &t, short Water, short invert, short skipFloor, short skipCeil);
void RenderFBXSolidTile(FbxScene*& gScene, int x, int y, tile &t, short Water);
void RenderFBXOpenTile(FbxScene*& gScene, int x, int y, tile &t, short Water, short invert);
void RenderFBXCuboid(FbxScene*& gScene, int x, int y, tile &t, short Water, int Bottom, int Top, char *TileName);
void RenderFBXCuboidByPoints(FbxScene*& gScene, int x, int y, tile &t, short Water, int Bottom, int Top, char *TileName,
FbxVector4 lControlPoint0,
FbxVector4 lControlPoint1,
FbxVector4 lControlPoint2,
FbxVector4 lControlPoint3,
FbxVector4 lControlPoint4,
FbxVector4 lControlPoint5,
FbxVector4 lControlPoint6,
FbxVector4 lControlPoint7,
float HorzOffsetEastPos, float HorzOffsetEastScale,
float HorzOffsetWestPos, float HorzOffsetWestScale,
float HorzOffsetNorthPos, float HorzOffsetNorthScale,
float HorzOffsetSouthPos, float HorzOffsetSouthScale
);
void RenderFBXCuboidByPoints(FbxScene*& gScene, int x, int y, tile &t, short Water, int Bottom, int Top, char *TileName,
FbxVector4 lControlPoint0,
FbxVector4 lControlPoint1,
FbxVector4 lControlPoint2,
FbxVector4 lControlPoint3,
FbxVector4 lControlPoint4,
FbxVector4 lControlPoint5,
FbxVector4 lControlPoint6,
FbxVector4 lControlPoint7,
float VertOffsetPos, float VertOffsetScale
);
void RenderFBXDiagSEPortion(FbxScene*& gScene, int Bottom, int Top, tile t, char *TileName);
void RenderFBXDiagSWPortion(FbxScene*& gScene, int Bottom, int Top, tile t, char *TileName);
void RenderFBXDiagNWPortion(FbxScene*& gScene, int Bottom, int Top, tile t, char *TileName);
void RenderFBXDiagNEPortion(FbxScene*& gScene, int Bottom, int Top, tile t, char *TileName);
void RenderFBXDiagSETile(FbxScene*& gScene, int x, int y, tile &t, short Water, short invert);
void RenderFBXDiagSWTile(FbxScene*& gScene, int x, int y, tile &t, short Water, short invert);
void RenderFBXDiagNWTile(FbxScene*& gScene, int x, int y, tile &t, short Water, short invert);
void RenderFBXDiagNETile(FbxScene*& gScene, int x, int y, tile &t, short Water, short invert);
void RenderFBXSlopeNTile(FbxScene*& gScene, int x, int y, tile &t, short Water, short invert);
void RenderFBXSlopeSTile(FbxScene*& gScene, int x, int y, tile &t, short Water, short invert);
void RenderFBXSlopeETile(FbxScene*& gScene, int x, int y, tile &t, short Water, short invert);
void RenderFBXSlopeWTile(FbxScene*& gScene, int x, int y, tile &t, short Water, short invert);
void RenderFBXRidgeSETile(FbxScene*& gScene, int x, int y, tile &t, short Water, short invert);
void RenderFBXRidgeNETile(FbxScene*& gScene, int x, int y, tile &t, short Water, short invert);
void RenderFBXRidgeSWTile(FbxScene*& gScene, int x, int y, tile &t, short Water, short invert);
void RenderFBXRidgeNWTile(FbxScene*& gScene, int x, int y, tile &t, short Water, short invert);
void RenderFBXValleyNETile(FbxScene*& gScene, int x, int y, tile &t, short Water, short invert);
void RenderFBXValleySETile(FbxScene*& gScene, int x, int y, tile &t, short Water, short invert);
void RenderFBXValleySWTile(FbxScene*& gScene, int x, int y, tile &t, short Water, short invert);
void RenderFBXValleyNWTile(FbxScene*& gScene, int x, int y, tile &t, short Water, short invert);
//void RenderSlopedFBXCuboid(FbxScene*& gScene, int x, int y, tile &t, short Water, int Bottom, int Top, int SlopeDir, int Steepness, int Floor);
void RenderSlopedFBXCuboid(FbxScene*& gScene, int x, int y, tile &t, short Water, int Bottom, int Top, int SlopeDir, int Steepness, int Floor, char *TileName);
void CreateFBXMaterials(FbxScene*& gScene, int game);
int FloorTexture(FbxScene*& gScene, FbxNode*& lNode, int face, tile t);
int WallTexture(FbxScene*& gScene, FbxNode*& lNode, int face, tile t);
void RenderFBXPlane(FbxScene*& gScene, int x, int y, tile &t, short Water, int Bottom, int Top, char *TileName, int face, int Surface
, int CP0_x, int CP0_Y, int CP0_Z
, int CP1_x, int CP1_Y, int CP1_Z
, int CP2_x, int CP2_Y, int CP2_Z
, int CP3_x, int CP3_Y, int CP3_Z
, FbxVector4 Normal
);
void insertTexture(int *texArray, int targetIndex, int textureNo, int arraysize);
float CalcCeilOffset(int game, int face, tile &t);
void RenderFBXDoorway(FbxScene*& gScene, int game, int x, int y, tile &t, ObjectItem currDoor, ObjectItem objList[1600]);
void RenderFBXPillars(FbxScene*& gScene, int game, tile LevelInfo[64][64], ObjectItem objList[1600]);
void RenderFBXBridges(FbxScene*& gScene, int game, tile LevelInfo[64][64], ObjectItem objList[1600]);
void RenderTerrainChangeTiles(FbxScene*& gScene, int game, tile LevelInfo[64][64], ObjectItem objList[1600]);
void CreateDoorModel(FbxScene*& gScene);
void CreateShockBridgeModel(FbxScene*& gScene);
//
//int gCubeNumber = 1; // Cube Number
//int gCubeRotationAxis = 1; // Cube Rotation Axis 0==X, 1==Y, 2==Z
//double gCubeXPos = 0.0; // initial CubXPos
//double gCubeYPos = 20.0; // initial CubeYPos
//double gCubeZPos = 0.0; // initial CubeZPos
//FbxAnimLayer* gAnimLayer = NULL; // holder of animation curves
//FbxString* gAppPath = NULL; // path where the application started
/* Tab character ("\t") counter */
/*Release uncomment
int numTabs = 0;
extern int iGame;
extern long SHOCK_CEILING_HEIGHT;
extern long UW_CEILING_HEIGHT;
///**
//* Print the required number of tabs.
//*/
//void PrintTabs() {
// for (int i = 0; i < numTabs; i++)
// printf("\t");
// }
//
///**
//* Return a string-based representation based on the attribute type.
//*/
//FbxString GetAttributeTypeName(FbxNodeAttribute::EType type) {
// switch (type) {
// case FbxNodeAttribute::eUnknown: return "unidentified";
// case FbxNodeAttribute::eNull: return "null";
// case FbxNodeAttribute::eMarker: return "marker";
// case FbxNodeAttribute::eSkeleton: return "skeleton";
// case FbxNodeAttribute::eMesh: return "mesh";
// case FbxNodeAttribute::eNurbs: return "nurbs";
// case FbxNodeAttribute::ePatch: return "patch";
// case FbxNodeAttribute::eCamera: return "camera";
// case FbxNodeAttribute::eCameraStereo: return "stereo";
// case FbxNodeAttribute::eCameraSwitcher: return "camera switcher";
// case FbxNodeAttribute::eLight: return "light";
// case FbxNodeAttribute::eOpticalReference: return "optical reference";
// case FbxNodeAttribute::eOpticalMarker: return "marker";
// case FbxNodeAttribute::eNurbsCurve: return "nurbs curve";
// case FbxNodeAttribute::eTrimNurbsSurface: return "trim nurbs surface";
// case FbxNodeAttribute::eBoundary: return "boundary";
// case FbxNodeAttribute::eNurbsSurface: return "nurbs surface";
// case FbxNodeAttribute::eShape: return "shape";
// case FbxNodeAttribute::eLODGroup: return "lodgroup";
// case FbxNodeAttribute::eSubDiv: return "subdiv";
// default: return "unknown";
// }
// }
//
//
//
///**
//* Print an attribute.
//*/
//void PrintAttribute(FbxNodeAttribute* pAttribute) {
// if (!pAttribute) return;
//
// FbxString typeName = GetAttributeTypeName(pAttribute->GetAttributeType());
// FbxString attrName = pAttribute->GetName();
// PrintTabs();
// // Note: to retrieve the character array of a FbxString, use its Buffer() method.
// printf("<attribute type='%s' name='%s'/>\n", typeName.Buffer(), attrName.Buffer());
// }
//
//
///**
//* Print a node, its attributes, and all its children recursively.
//*/
//void PrintNode(FbxNode* pNode) {
// PrintTabs();
// const char* nodeName = pNode->GetName();
// FbxDouble3 translation = pNode->LclTranslation.Get();
// FbxDouble3 rotation = pNode->LclRotation.Get();
// FbxDouble3 scaling = pNode->LclScaling.Get();
//
// // Print the contents of the node.
// printf("<node name='%s' translation='(%f, %f, %f)' rotation='(%f, %f, %f)' scaling='(%f, %f, %f)'>\n",
// nodeName,
// translation[0], translation[1], translation[2],
// rotation[0], rotation[1], rotation[2],
// scaling[0], scaling[1], scaling[2]
// );
// numTabs++;
//
// // Print the node's attributes.
// for (int i = 0; i < pNode->GetNodeAttributeCount(); i++)
// PrintAttribute(pNode->GetNodeAttributeByIndex(i));
//
// // Recursively print the children.
// for (int j = 0; j < pNode->GetChildCount(); j++)
// PrintNode(pNode->GetChild(j));
//
// numTabs--;
// PrintTabs();
// printf("</node>\n");
// }
//
//
//
//void FBXTest()
// {
//
// // Change the following filename to a suitable filename value.
// const char* lFilename = "uw1_1.fbx";
//
// // Initialize the SDK manager. This object handles all our memory management.
// FbxManager* lSdkManager = FbxManager::Create();
//
// // Create the IO settings object.
// FbxIOSettings *ios = FbxIOSettings::Create(lSdkManager, IOSROOT);
// lSdkManager->SetIOSettings(ios);
//
// // Create an importer using the SDK manager.
// FbxImporter* lImporter = FbxImporter::Create(lSdkManager, "");
//
// // Use the first argument as the filename for the importer.
// if (!lImporter->Initialize(lFilename, -1, lSdkManager->GetIOSettings())) {
// printf("Call to FbxImporter::Initialize() failed.\n");
// printf("Error returned: %s\n\n", lImporter->GetStatus().GetErrorString());
// exit(-1);
// }
//
// // Create a new scene so that it can be populated by the imported file.
// FbxScene* lScene = FbxScene::Create(lSdkManager, "myScene");
//
// // Import the contents of the file into the scene.
// lImporter->Import(lScene);
//
// // The file is imported; so get rid of the importer.
// lImporter->Destroy();
//
// // Print the nodes of the scene and their attributes recursively.
// // Note that we are not printing the root node because it should
// // not contain any attributes.
// FbxNode* lRootNode = lScene->GetRootNode();
// if (lRootNode) {
// for (int i = 0; i < lRootNode->GetChildCount(); i++)
// PrintNode(lRootNode->GetChild(i));
// }
// // Destroy the SDK manager and all the other objects it was handling.
// lSdkManager->Destroy();
// }
//
//void FBXExport()
// {
//
// // Initialize the FbxManager and the FbxScene
// if (InitializeSdkObjects(gSdkManager, gScene) == false)
// {
// return;
// }
//
// // create a marker
// FbxNode* lMarker = CreateMarker(gScene, "Marker");
//
// // create a camera
// FbxNode* lCamera = CreateCamera(gScene, "Camera");
//
// // create a single texture shared by all cubes
// CreateTexture(gScene);
// CreateTexture2(gScene);
// // create a material shared by all faces of all cubes
// CreateMaterial(gScene);
// CreateMaterial2(gScene);
// // set the camera point of interest on the marker
// SetCameraPointOfInterest(lCamera, lMarker);
//
// // set the marker position
// SetMarkerDefaultPosition(lMarker);
//
// // set the camera position
// SetCameraDefaultPosition(lCamera);
//
// // animate the camera
// //AnimateCamera(lCamera, gAnimLayer);
//
// // build a minimum scene graph
// FbxNode* lRootNode = gScene->GetRootNode();
// lRootNode->AddChild(lMarker);
// lRootNode->AddChild(lCamera);
//
//
// // create a new cube with option selected
// CreateCube(1, 0);
//
// SaveScene(gSdkManager, gScene, "fbx_output.fbx", 0, true); // true -> embed texture file
//
// return;
//
//
// }
/*Release uncomment
bool InitializeSdkObjects(FbxManager*& pManager, FbxScene*& pScene)
{
//The first thing to do is to create the FBX Manager which is the object allocator for almost all the classes in the SDK
pManager = FbxManager::Create();
if (!pManager)
{
FBXSDK_printf("Error: Unable to create FBX Manager!\n");
exit(1);
}
else FBXSDK_printf("Autodesk FBX SDK version %s\n", pManager->GetVersion());
//Create an IOSettings object. This object holds all import/export settings.
FbxIOSettings* ios = FbxIOSettings::Create(pManager, IOSROOT);
pManager->SetIOSettings(ios);
//Create an FBX scene. This object holds most objects imported/exported from/to files.
pScene = FbxScene::Create(pManager, "My Scene");
if (!pScene)
{
FBXSDK_printf("Error: Unable to create FBX scene!\n");
exit(1);
}
return true;
}
void DestroySdkObjects(FbxManager* pManager, bool pExitStatus)
{
//Delete the FBX Manager. All the objects that have been allocated using the FBX Manager and that haven't been explicitly destroyed are also automatically destroyed.
if (pManager) pManager->Destroy();
if (pExitStatus) FBXSDK_printf("Program Success!\n");
}
//// Create a global texture for cube.
//void CreateTexture(FbxScene* pScene)
// {
// gTexture = FbxFileTexture::Create(pScene, "Diffuse Texture");
//
// // Resource file must be in the application's directory.
// //FbxString lTexPath = gAppPath ? *gAppPath + "\\uw1_000.jpg" : "";
// FbxString lTexPath = "uw1_000.jpg";
//
// // Set texture properties.
// gTexture->SetFileName(lTexPath.Buffer());
// gTexture->SetTextureUse(FbxTexture::eStandard);
// gTexture->SetMappingType(FbxTexture::eUV);
// gTexture->SetMaterialUse(FbxFileTexture::eModelMaterial);
// gTexture->SetSwapUV(false);
// gTexture->SetTranslation(0.0, 0.0);
// gTexture->SetScale(1.0, 1.0);
// gTexture->SetRotation(0.0, 0.0);
// }
//
//// Create a global texture for cube.
//void CreateTexture2(FbxScene* pScene)
// {
// gTexture2 = FbxFileTexture::Create(pScene, "Diffuse Texture2");
//
// // Resource file must be in the application's directory.
// //FbxString lTexPath = gAppPath ? *gAppPath + "\\uw1_261.tga" : "";
// FbxString lTexPath = "uw1_261.tga";
//
// // Set texture properties.
// gTexture2->SetFileName(lTexPath.Buffer());
// gTexture2->SetTextureUse(FbxTexture::eStandard);
// gTexture2->SetMappingType(FbxTexture::eUV);
// gTexture2->SetMaterialUse(FbxFileTexture::eModelMaterial);
// gTexture2->SetSwapUV(false);
// gTexture2->SetTranslation(0.0, 0.0);
// gTexture2->SetScale(1.0, 1.0);
// gTexture2->SetRotation(0.0, 0.0);
// }
//
//
//// Set target of the camera.
//void SetCameraPointOfInterest(FbxNode* pCamera, FbxNode* pPointOfInterest)
// {
// // Set the camera to always point at this node.
// pCamera->SetTarget(pPointOfInterest);
// }
//
//// Set marker default position.
//void SetMarkerDefaultPosition(FbxNode* pMarker)
// {
// // The marker is positioned above the origin. There is no rotation and no scaling.
// pMarker->LclTranslation.Set(FbxVector4(0.0, 40.0, 0.0));
// pMarker->LclRotation.Set(FbxVector4(0.0, 0.0, 0.0));
// pMarker->LclScaling.Set(FbxVector4(1.0, 1.0, 1.0));
// }
//
//// Compute the camera position.
//void SetCameraDefaultPosition(FbxNode* pCamera)
// {
// // set the initial camera position
// FbxVector4 lCameraLocation(0.0, 200.0, -100.0);
// pCamera->LclTranslation.Set(lCameraLocation);
// }
//
//// Create global material for cube.
//void CreateMaterial(FbxScene* pScene)
// {
// FbxString lMaterialName = "material";
// FbxString lShadingName = "Phong";
// FbxDouble3 lBlack(0.0, 0.0, 0.0);
// FbxDouble3 lRed(1.0, 0.0, 0.0);
// FbxDouble3 lDiffuseColor(0.75, 0.75, 0.0);
// gMaterial = FbxSurfacePhong::Create(pScene, lMaterialName.Buffer());
//
// // Generate primary and secondary colors.
// gMaterial->Emissive.Set(lBlack);
// gMaterial->Ambient.Set(lRed);
// gMaterial->Diffuse.Set(lDiffuseColor);
// gMaterial->TransparencyFactor.Set(40.5);
// gMaterial->ShadingModel.Set(lShadingName);
// gMaterial->Shininess.Set(0.5);
//
// // the texture need to be connected to the material on the corresponding property
// if (gTexture)
// gMaterial->Diffuse.ConnectSrcObject(gTexture);
// }
//void AddMaterials(FbxMesh* pMesh)
// {
// FbxSurfacePhong* gMaterial = NULL;
// // Set material mapping.
// FbxGeometryElementMaterial* lMaterialElement = pMesh->CreateElementMaterial();
// lMaterialElement->SetMappingMode(FbxGeometryElement::eByPolygon);
// lMaterialElement->SetReferenceMode(FbxGeometryElement::eIndexToDirect);
//
// //get the node of mesh, add material for it.
// FbxNode* lNode = pMesh->GetNode();
// if (lNode == NULL)
// return;
// lNode->AddMaterial(gMaterial);
// //lNode->AddMaterial(gMaterial2);
// // We are in eByPolygon, so there's only need for 6 index (a cube has 6 polygons).
// lMaterialElement->GetIndexArray().SetCount(6);
//
// // Set the Index 0 to 6 to the material in position 0 of the direct array.
// for (int i = 0; i<6; ++i)
// if (i == 0)
// {
// lMaterialElement->GetIndexArray().SetAt(i, 1);
// }
// else
// {
// lMaterialElement->GetIndexArray().SetAt(i, 0);
// }
//
// }
//// Create global material for cube.
//void CreateMaterial2(FbxScene* pScene)
// {
// FbxString lMaterialName = "material2";
// FbxString lShadingName = "Phong";
// FbxDouble3 lBlack(0.0, 0.0, 0.0);
// FbxDouble3 lRed(1.0, 0.0, 0.0);
// FbxDouble3 lDiffuseColor(0.75, 0.75, 0.0);
// gMaterial2 = FbxSurfacePhong::Create(pScene, lMaterialName.Buffer());
//
// // Generate primary and secondary colors.
// gMaterial2->Emissive.Set(lBlack);
// gMaterial2->Ambient.Set(lRed);
// gMaterial2->Diffuse.Set(lDiffuseColor);
// gMaterial2->TransparencyFactor.Set(40.5);
// gMaterial2->ShadingModel.Set(lShadingName);
// gMaterial2->Shininess.Set(0.5);
//
// // the texture need to be connected to the material on the corresponding property
// if (gTexture2)
// gMaterial2->Diffuse.ConnectSrcObject(gTexture2);
// }
//
//// Reset camera values
//void SetInitialCubeData()
// {
// gCubeNumber = 1; // Cube Number
// gCubeRotationAxis = 1; // Cube Rotation Axis 0==X, 1==Y, 2==Z
// gCubeXPos = 0.0; // initial CubXPos
// gCubeYPos = 20.0; // initial CubeYPos
// gCubeZPos = 0.0; // initial CubeZPos
// }
//
//// Create a marker to use a point of interest for the camera.
//FbxNode* CreateMarker(FbxScene* pScene, char* pName)
// {
// FbxMarker* lMarker = FbxMarker::Create(pScene, pName);
//
// FbxNode* lNode = FbxNode::Create(pScene, pName);
//
// lNode->SetNodeAttribute(lMarker);
//
// return lNode;
// }
//
//// Create a camera.
//FbxNode* CreateCamera(FbxScene* pScene, char* pName)
// {
// FbxCamera* lCamera = FbxCamera::Create(pScene, pName);
//
// // Set camera property for a classic TV projection with aspect ratio 4:3
// lCamera->SetFormat(FbxCamera::eNTSC);
//
// FbxNode* lNode = FbxNode::Create(pScene, pName);
//
// lNode->SetNodeAttribute(lCamera);
//
// return lNode;
// }
//
//
//// create a new cube
//void CreateCube(bool pWithTexture, bool pAnimate)
// {
// // make a new cube name
// FbxString lCubeName = "Cube number ";
// lCubeName += FbxString(gCubeNumber);
//
// // create a new cube
// CreateCubeDetailed(lCubeName.Buffer(),
// gCubeXPos,
// gCubeYPos,
// gCubeZPos,
// gCubeRotationAxis,
// pWithTexture,
// pAnimate
// );
//
// // compute for next cube creation
// gCubeNumber++; // cube number
//
// // set next pos
// if (gCubeXPos >= 0.0)
// {
// gCubeXPos += 50.0;
// gCubeXPos *= -1.0;
// gCubeRotationAxis++; // change rotation axis
// }
// else
// {
// gCubeXPos *= -1.0;
// }
//
// // go up
// gCubeYPos += 30.0;
//
// if (gCubeRotationAxis > 2) gCubeRotationAxis = 0; // cube rotation
// }
//
//
//// create a new cube
//void CreateCubeDetailed(char* pCubeName,
// double pX,
// double pY,
// double pZ,
// int pRotateAxe,
// bool pWithTexture,
// bool pAnimate
// )
// {
// FbxNode* lCube = CreateCubeMesh(gScene, pCubeName);
//
// // set the cube position
// lCube->LclTranslation.Set(FbxVector4(pX, pY, pZ));
//
// //if (pAnimate)
// // {
// // AnimateCube(lCube, gAnimLayer, pRotateAxe);
// // }
//
// if (pWithTexture)
// {
// // if we asked to create the cube with a texture, we need
// // a material present because the texture connects to the
// // material DiffuseColor property
// AddMaterials(lCube->GetMesh());
// }
//
// gScene->GetRootNode()->AddChild(lCube);
// }
//
//
//// Create a cube mesh.
//FbxNode* CreateCubeMesh(FbxScene* pScene, char* pName)
// {
// int i, j;
// FbxMesh* lMesh = FbxMesh::Create(pScene, pName);
//
// FbxVector4 lControlPoint0(-50, 0, 50);
// FbxVector4 lControlPoint1(50, 0, 50);
// FbxVector4 lControlPoint2(50, 100, 50);
// FbxVector4 lControlPoint3(-50, 100, 50);
// FbxVector4 lControlPoint4(-50, 0, -50);
// FbxVector4 lControlPoint5(50, 0, -50);
// FbxVector4 lControlPoint6(50, 100, -50);
// FbxVector4 lControlPoint7(-50, 100, -50);
//
// FbxVector4 lNormalXPos(1, 0, 0);
// FbxVector4 lNormalXNeg(-1, 0, 0);
// FbxVector4 lNormalYPos(0, 1, 0);
// FbxVector4 lNormalYNeg(0, -1, 0);
// FbxVector4 lNormalZPos(0, 0, 1);
// FbxVector4 lNormalZNeg(0, 0, -1);
//
// // Create control points.
// lMesh->InitControlPoints(24);
// FbxVector4* lControlPoints = lMesh->GetControlPoints();
//
// lControlPoints[0] = lControlPoint0;
// lControlPoints[1] = lControlPoint1;
// lControlPoints[2] = lControlPoint2;
// lControlPoints[3] = lControlPoint3;
// lControlPoints[4] = lControlPoint1;
// lControlPoints[5] = lControlPoint5;
// lControlPoints[6] = lControlPoint6;
// lControlPoints[7] = lControlPoint2;
// lControlPoints[8] = lControlPoint5;
// lControlPoints[9] = lControlPoint4;
// lControlPoints[10] = lControlPoint7;
// lControlPoints[11] = lControlPoint6;
// lControlPoints[12] = lControlPoint4;
// lControlPoints[13] = lControlPoint0;
// lControlPoints[14] = lControlPoint3;
// lControlPoints[15] = lControlPoint7;
// lControlPoints[16] = lControlPoint3;
// lControlPoints[17] = lControlPoint2;
// lControlPoints[18] = lControlPoint6;
// lControlPoints[19] = lControlPoint7;
// lControlPoints[20] = lControlPoint1;
// lControlPoints[21] = lControlPoint0;
// lControlPoints[22] = lControlPoint4;
// lControlPoints[23] = lControlPoint5;
//
// // We want to have one normal for each vertex (or control point),
// // so we set the mapping mode to eByControlPoint.
// FbxGeometryElementNormal* lGeometryElementNormal = lMesh->CreateElementNormal();
//
// lGeometryElementNormal->SetMappingMode(FbxGeometryElement::eByControlPoint);
//
// // Set the normal values for every control point.
// lGeometryElementNormal->SetReferenceMode(FbxGeometryElement::eDirect);
//
// lGeometryElementNormal->GetDirectArray().Add(lNormalZPos);
// lGeometryElementNormal->GetDirectArray().Add(lNormalZPos);
// lGeometryElementNormal->GetDirectArray().Add(lNormalZPos);
// lGeometryElementNormal->GetDirectArray().Add(lNormalZPos);
// lGeometryElementNormal->GetDirectArray().Add(lNormalXPos);
// lGeometryElementNormal->GetDirectArray().Add(lNormalXPos);
// lGeometryElementNormal->GetDirectArray().Add(lNormalXPos);
// lGeometryElementNormal->GetDirectArray().Add(lNormalXPos);
// lGeometryElementNormal->GetDirectArray().Add(lNormalZNeg);
// lGeometryElementNormal->GetDirectArray().Add(lNormalZNeg);
// lGeometryElementNormal->GetDirectArray().Add(lNormalZNeg);
// lGeometryElementNormal->GetDirectArray().Add(lNormalZNeg);
// lGeometryElementNormal->GetDirectArray().Add(lNormalXNeg);
// lGeometryElementNormal->GetDirectArray().Add(lNormalXNeg);
// lGeometryElementNormal->GetDirectArray().Add(lNormalXNeg);
// lGeometryElementNormal->GetDirectArray().Add(lNormalXNeg);
// lGeometryElementNormal->GetDirectArray().Add(lNormalYPos);
// lGeometryElementNormal->GetDirectArray().Add(lNormalYPos);
// lGeometryElementNormal->GetDirectArray().Add(lNormalYPos);
// lGeometryElementNormal->GetDirectArray().Add(lNormalYPos);
// lGeometryElementNormal->GetDirectArray().Add(lNormalYNeg);
// lGeometryElementNormal->GetDirectArray().Add(lNormalYNeg);
// lGeometryElementNormal->GetDirectArray().Add(lNormalYNeg);
// lGeometryElementNormal->GetDirectArray().Add(lNormalYNeg);
//
//
// // Array of polygon vertices.
// int lPolygonVertices[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
// 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 };
//
//
// // Create UV for Diffuse channel.
// FbxGeometryElementUV* lUVDiffuseElement = lMesh->CreateElementUV("DiffuseUV");
// FBX_ASSERT(lUVDiffuseElement != NULL);
// lUVDiffuseElement->SetMappingMode(FbxGeometryElement::eByPolygonVertex);
// lUVDiffuseElement->SetReferenceMode(FbxGeometryElement::eIndexToDirect);
//
// FbxVector2 lVectors0(0, 0);
// FbxVector2 lVectors1(1, 0);
// FbxVector2 lVectors2(1, 1);
// FbxVector2 lVectors3(0, 1);
//
// lUVDiffuseElement->GetDirectArray().Add(lVectors0);
// lUVDiffuseElement->GetDirectArray().Add(lVectors1);
// lUVDiffuseElement->GetDirectArray().Add(lVectors2);
// lUVDiffuseElement->GetDirectArray().Add(lVectors3);
//
// //Now we have set the UVs as eIndexToDirect reference and in eByPolygonVertex mapping mode
// //we must update the size of the index array.
// lUVDiffuseElement->GetIndexArray().SetCount(24);
//
// // Create polygons. Assign texture and texture UV indices.
// for (i = 0; i < 6; i++)
// {
// // all faces of the cube have the same texture
// lMesh->BeginPolygon(-1, -1, -1, false);
//
// for (j = 0; j < 4; j++)
// {
// // Control point index
// lMesh->AddPolygon(lPolygonVertices[i * 4 + j]);
//
// // update the index array of the UVs that map the texture to the face
// lUVDiffuseElement->GetIndexArray().SetAt(i * 4 + j, j);
// }
//
// lMesh->EndPolygon();
// }
//
// // create a FbxNode
// FbxNode* lNode = FbxNode::Create(pScene, pName);
//
// // set the node attribute
// lNode->SetNodeAttribute(lMesh);
//
// // set the shading mode to view texture
// lNode->SetShadingMode(FbxNode::eTextureShading);
//
// // rescale the cube
// lNode->LclScaling.Set(FbxVector4(0.3, 0.3, 0.3));
//
// // return the FbxNode
// return lNode;
// }
// to save a scene to a FBX file
bool SaveScene(FbxManager* pSdkManager, FbxDocument* pScene, const char* pFilename, int pFileFormat, bool pEmbedMedia)
{
if (pSdkManager == NULL) return false;
if (pScene == NULL) return false;
if (pFilename == NULL) return false;
bool lStatus = true;
// Create an exporter.
FbxExporter* lExporter = FbxExporter::Create(pSdkManager, "");
if (pFileFormat < 0 || pFileFormat >= pSdkManager->GetIOPluginRegistry()->GetWriterFormatCount())
{
// Write in fall back format if pEmbedMedia is true
pFileFormat = pSdkManager->GetIOPluginRegistry()->GetNativeWriterFormat();
if (!pEmbedMedia)
{
//Try to export in ASCII if possible
int lFormatIndex, lFormatCount = pSdkManager->GetIOPluginRegistry()->GetWriterFormatCount();
for (lFormatIndex = 0; lFormatIndex<lFormatCount; lFormatIndex++)
{
if (pSdkManager->GetIOPluginRegistry()->WriterIsFBX(lFormatIndex))
{
FbxString lDesc = pSdkManager->GetIOPluginRegistry()->GetWriterFormatDescription(lFormatIndex);
char *lASCII = "ascii";
if (lDesc.Find(lASCII) >= 0)
{
pFileFormat = lFormatIndex;
break;
}
}
}
}
}
// Initialize the exporter by providing a filename.
if (lExporter->Initialize(pFilename, pFileFormat, pSdkManager->GetIOSettings()) == false)
{
return false;
}
// Set the export states. By default, the export states are always set to
// true except for the option eEXPORT_TEXTURE_AS_EMBEDDED. The code below
// shows how to change these states.
//IOS_REF.SetBoolProp(EXP_FBX_MATERIAL, true);
//IOS_REF.SetBoolProp(EXP_FBX_TEXTURE, true);
//IOS_REF.SetBoolProp(EXP_FBX_EMBEDDED, pEmbedMedia);
//IOS_REF.SetBoolProp(EXP_FBX_SHAPE, true);
//IOS_REF.SetBoolProp(EXP_FBX_GOBO, true);
//IOS_REF.SetBoolProp(EXP_FBX_ANIMATION, true);
//IOS_REF.SetBoolProp(EXP_FBX_GLOBAL_SETTINGS, true);
// Export the scene.
lStatus = lExporter->Export(pScene);
// Destroy the exporter.
lExporter->Destroy();
return lStatus;
}
void RenderFBXLevel(tile LevelInfo[64][64], ObjectItem objList[1600], int game)
{
int x; int y;
int skipCeil = 0;
FbxManager* gSdkManager = NULL;
FbxScene* gScene = NULL;
iGame = game;
//Levels use different ceiling heights.
//Shock is variable, UW is fixed.
switch (game)
{
case SHOCK:
{
CEILING_HEIGHT = SHOCK_CEILING_HEIGHT;
break;
}
default://UW1&2
{
skipCeil = 1;
CEILING_HEIGHT = UW_CEILING_HEIGHT;
break;
}
}
// Initialize the FbxManager and the FbxScene
if (InitializeSdkObjects(gSdkManager, gScene) == false)
{
return;
}
CreateFBXMaterials(gScene, game);
for (y = 0; y <= 63; y++)
{
for (x = 0; x <= 63; x++)
{
RenderFBXTile(gScene, game, x, y, LevelInfo[x][y], 0, 0, 0, skipCeil);
RenderFBXTile(gScene, game, x, y, LevelInfo[x][y], 1, 0, 0, skipCeil);
}
}
tile tmp;
if (game != SHOCK)
{
//Ceiling
tmp.tileType = 1;
tmp.Render = 1;
tmp.isWater = 0;
tmp.tileX = 0;
tmp.tileY = 0;
tmp.DimX = 64;
tmp.DimY = 64;
tmp.ceilingHeight = 0;
tmp.floorTexture = LevelInfo[0][0].shockCeilingTexture;
tmp.shockCeilingTexture = LevelInfo[0][0].shockCeilingTexture;
tmp.East = LevelInfo[0][0].shockCeilingTexture;//CAULK;
tmp.West = LevelInfo[0][0].shockCeilingTexture;//CAULK;
tmp.North = LevelInfo[0][0].shockCeilingTexture;//CAULK;
tmp.South = LevelInfo[0][0].shockCeilingTexture;//CAULK;
tmp.shockEastCeilHeight = 0;
tmp.shockWestCeilHeight = 0;
tmp.shockNorthCeilHeight = 0;
tmp.shockSouthCeilHeight = 0;
tmp.VisibleFaces[vTOP] = 0;
tmp.VisibleFaces[vEAST] = 0;
tmp.VisibleFaces[vBOTTOM] = 1;
tmp.VisibleFaces[vWEST] = 0;
tmp.VisibleFaces[vNORTH] = 0;
tmp.VisibleFaces[vSOUTH] = 0;
// top,east,bottom,west,north,south
RenderFBXTile(gScene, game, x, y, tmp, 0, 0, 1, 0);
}
//Tmp code for generating all materials into unity
// for (int j = 0; j < 261; j++)
// {
// tmp.DimX=1;tmp.DimY=1;
// tmp.North = j;
// RenderFBXTile(gScene, game, 0, j, tmp, 0, 0, 1, 0);
// }
//Now render a room to store objects
tmp.DimX = 1;
tmp.DimY = 1;
tmp.floorHeight = 0;
for (int i = 0; i < 6; i++)
{
tmp.VisibleFaces[i] = 1;
}
for (x = 65; x < 68; x++)
{
for (y = 65; y < 68; y++)
{
tmp.tileX = x;
tmp.tileY = y;
if ((x != 66) || (y != 66))
{
tmp.tileType = 0;
}
else
{
tmp.tileType = 1;
}
RenderFBXTile(gScene, game, x, y, tmp, 0, 0, 0, 0);
}
}
//And at 99,99 for special stuff.
for (x = 98; x < 101; x++)
{
for (y = 98; y < 101; y++)
{
tmp.tileX = x;
tmp.tileY = y;
if ((x != 99) || (y != 99))
{
tmp.tileType = 0;
}
else
{
tmp.tileType = 1;
}
RenderFBXTile(gScene, game, x, y, tmp, 0, 0, 0, 0);
}
}
//Render doors
if (game != SHOCK)
{
for (y = 0; y <= 63; y++)
{
for (x = 0; x <= 63; x++)
{
if ((LevelInfo[x][y].hasElevator == 0))//Elevators are rendered as func_statics
{
if (LevelInfo[x][y].isDoor == 1)
{//Adds a UW door frame.
RenderFBXDoorway(gScene, game, x, y, LevelInfo[x][y], objList[LevelInfo[x][y].DoorIndex],objList);
}
}
}
}
}
//Render Pillars
if (game != SHOCK)
{
RenderFBXBridges(gScene, game, LevelInfo, objList);
RenderFBXPillars(gScene, game, LevelInfo, objList);
RenderTerrainChangeTiles(gScene, game, LevelInfo, objList);
}
//CreateDoorModel(gScene);
//CreateShockBridgeModel(gScene);
gScene->Compact();
SaveScene(gSdkManager, gScene, "level8.fbx", 1, true);
}
void RenderFBXTile(FbxScene*& gScene, int game, int x, int y, tile &t, short Water, short invert, short skipFloor, short skipCeil)
{
//Picks the tile to render based on tile type/flags.
switch (t.tileType)
{
case TILE_SOLID: //0
{ //solid
RenderFBXSolidTile(gScene, x, y, t, Water);
return;
}
case TILE_OPEN: //1
{//open
if (skipFloor != 1) { RenderFBXOpenTile(gScene, x, y, t, Water, 0); } //floor
if ((skipCeil != 1)) { RenderFBXOpenTile(gScene, x, y, t, Water, 1); } //ceiling
return;
}
case 2:
{//diag se
if (skipFloor != 1) { RenderFBXDiagSETile(gScene, x, y, t, Water, 0); }//floor
if ((skipCeil != 1)) { RenderFBXDiagSETile(gScene, x, y, t, Water, 1); }
return;
}
case 3:
{ //diag sw
if (skipFloor != 1) { RenderFBXDiagSWTile(gScene, x, y, t, Water, 0); }//floor
if ((skipCeil != 1)) { RenderFBXDiagSWTile(gScene, x, y, t, Water, 1); }
return;
}
case 4:
{ //diag ne
if (skipFloor != 1) { RenderFBXDiagNETile(gScene, x, y, t, Water, invert); }//floor
if ((skipCeil != 1)) { RenderFBXDiagNETile(gScene, x, y, t, Water, 1); }
return;
}
case 5:
{//diag nw
if (skipFloor != 1) { RenderFBXDiagNWTile(gScene, x, y, t, Water, invert); }//floor
if ((skipCeil != 1)) { RenderFBXDiagNWTile(gScene, x, y, t, Water, 1); }
return;
}
case TILE_SLOPE_N: //6
{//slope n
switch (t.shockSlopeFlag)
{
case SLOPE_BOTH_PARALLEL:
{
if (skipFloor != 1) { RenderFBXSlopeNTile(gScene, x, y, t, Water, 0); }//floor
if ((skipCeil != 1)) { RenderFBXSlopeNTile(gScene, x, y, t, Water, 1); }
break;
}
case SLOPE_BOTH_OPPOSITE:
{