-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cxx
1602 lines (1336 loc) · 61 KB
/
main.cxx
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
/****************************************************************************************
Copyright (C) 2015 Autodesk, Inc.
All rights reserved.
Use of this software is subject to the terms of the Autodesk license agreement
provided at the time of installation or download, or which otherwise accompanies
this software in either electronic or hard copy form.
****************************************************************************************/
/////////////////////////////////////////////////////////////////////////
//
// The scene created in this example is a textured cube, a pyramid
// with materials mapped on it's faces and triangle deformed by vertex cache.
// An animation stack displays 6 different angles of all models.
//
// The example illustrates how to:
// 1) create a cube in mesh
// 2) map textures on diffuse, ambient and emissive channel of the cube
// 3) create an UV set for each channel with a texture for the cube
// 4) create a pyramid in mesh
// 5) create and map materials on the diffuse channel for each faces of the pyramid
// 6) create a cube with our custom mesh type
// 7) create and map materials on the diffuse channel for our custom mesh cube
// 8) create and add to our custom meshed cube a User Data Layer
// 9) create vertex cache deformer (by default maya caches are created in 64bits (mcx extension))
// 10) create an animation stack
// 11) animate vertex
// 12) export a scene in a .FBX file
//
//
// 1. To test vertex (3 doubles) cache (default) :
//
// ./ExportScene03 cacheFileName
//
// 2. To test int32 cache :
//
// ./ExportScene03 cacheFileName 1
//
/////////////////////////////////////////////////////////////////////////
#include <fbxsdk.h>
#include "Common.h"
#include "MyKFbxMesh.h"
#define SAMPLE_FILENAME_MC "ExportScene03_MC.fbx"
#define SAMPLE_FILENAME_PC2 "ExportScene03_PC2.fbx"
#define SAMPLE_CACHE_TYPE 2
#define PID_MY_GEOMETRY_LEMENT 0
// Function prototypes.
bool CreateScene(FbxScene* pScene, char* pSampleFileName);
FbxNode* CreateCubeWithTexture(FbxScene* pScene, const char* pName);
FbxNode* CreatePyramidWithMaterials(FbxScene* pScene, const char* pName);
FbxNode* CreateTriangle(FbxScene* pScene, const char* pName);
FbxNode* CreateCubeWithMaterialAndMyKFbxMesh(FbxScene* pScene, const char* pName);
void CreateTexture(FbxScene* pScene, FbxMesh* pMesh);
void CreateMaterials(FbxScene* pScene, FbxMesh* pMesh);
void CreateMaterialsWithMyKFbxMesh(FbxScene* pScene, MyKFbxMesh* pMyKFbxMesh);
void MapShapeOnPyramid(FbxScene* pScene, FbxNode* pPyramid);
void MapVertexCacheOnTriangle(FbxScene* pScene, FbxNode* pTriangle, char* pSampleFileName);
void SetCubeDefaultPosition(FbxNode* pCube);
void SetPyramidDefaultPosition(FbxNode* pPyramid);
void SetTriangleDefaultPosition(FbxNode* pTriangle);
void SetMyKFbxMeshCubeDefaultPosition(FbxNode* pMyKFbxCube);
void Animate(FbxNode* pNode, FbxAnimLayer* pAnimLayer);
void AnimateVertexCacheOnTriangleDoubleVertex(FbxNode* pNode, double pFrameRate);
void AnimateVertexCacheOnTriangleInt32(FbxNode* pNode, double pFrameRate);
void AnimateVertexCacheOnTriangleFloat(FbxNode* pNode, double pFrameRate);
bool gExportVertexCacheMCFormat = true;
// Declare the UV names globally so we can create them on the mesh and then assign them properly
// to our textures when we create them
static const char* gDiffuseElementName = "DiffuseUV";
static const char* gAmbientElementName = "AmbientUV";
static const char* gEmissiveElementName = "EmissiveUV";
// gCacheType == 0 (default) - double vertex array
// == 1 - int32 array
// == 2 - float array
int gCacheType = -1;
int main(int argc, char** argv)
{
FbxManager* lSdkManager = NULL;
FbxScene* lScene = NULL;
char* lSampleFileName = NULL;
bool lResult;
// Prepare the FBX SDK.
InitializeSdkObjects(lSdkManager, lScene);
//Add the new class we have created to the Sdk Manager
//Our class MyKFbxMesh is derived from FbxMesh
lSdkManager->RegisterFbxClass("MyKFbxMesh", FBX_TYPE(MyKFbxMesh), FBX_TYPE(FbxMesh));
//Now, our class MyKFbxMesh is ready to be used
lSdkManager->RegisterFbxClass("MyFbxObject", FBX_TYPE(MyFbxObject), FBX_TYPE(FbxObject), "MyFbxObjectType", "MyFbxObjectSubType");
//The example can take an output file name as an argument, and a cache format
for( int i = 1; i < argc; ++i )
{
if( FBXSDK_stricmp(argv[i], "-test") == 0 ) continue;
else
{
if( !lSampleFileName ) lSampleFileName = argv[i];
else if( gCacheType == -1 ) gCacheType = atoi(argv[i]);
}
}
if( !lSampleFileName ) lSampleFileName = gExportVertexCacheMCFormat ? (char *)SAMPLE_FILENAME_MC : (char *)SAMPLE_FILENAME_PC2;
if( gCacheType == -1 ) gCacheType = SAMPLE_CACHE_TYPE;
// Create the scene.
lResult = CreateScene(lScene, lSampleFileName);
if(lResult == false)
{
FBXSDK_printf("\n\nAn error occurred while creating the scene...\n");
DestroySdkObjects(lSdkManager, lResult);
return 0;
}
// Save the scene.
lResult = SaveScene(lSdkManager, lScene, lSampleFileName);
if(lResult == false)
{
FBXSDK_printf("\n\nAn error occurred while saving the scene...\n");
DestroySdkObjects(lSdkManager, lResult);
return 0;
}
// Destroy all objects created by the FBX SDK.
DestroySdkObjects(lSdkManager, lResult);
return 0;
}
bool CreateScene(FbxScene* pScene, char* pSampleFileName)
{
FbxNode* lCube = CreateCubeWithTexture(pScene, "Cube");
FbxNode* lPyramid = CreatePyramidWithMaterials(pScene, "Pyramid");
FbxNode* lTriangle = CreateTriangle(pScene, "Triangle");
FbxNode* lMyKFbxMeshCube = CreateCubeWithMaterialAndMyKFbxMesh(pScene, "CubeMyKFbxMesh");
MyFbxObject* lMyFbxObject = MyFbxObject::Create(pScene, "MyFbxObject 1");
MapShapeOnPyramid(pScene, lPyramid);
MapVertexCacheOnTriangle(pScene, lTriangle, pSampleFileName);
SetCubeDefaultPosition(lCube);
SetPyramidDefaultPosition(lPyramid);
SetTriangleDefaultPosition(lTriangle);
SetMyKFbxMeshCubeDefaultPosition(lMyKFbxMeshCube);
// Build the node tree.
FbxNode* lRootNode = pScene->GetRootNode();
lRootNode->AddChild(lCube);
lRootNode->AddChild(lPyramid);
lRootNode->AddChild(lMyKFbxMeshCube);
lRootNode->AddChild(lTriangle);
lRootNode->ConnectSrcObject(lMyFbxObject);
// Create the Animation Stack
FbxAnimStack* lAnimStack = FbxAnimStack::Create(pScene, "Show all faces");
// The animation nodes can only exist on AnimLayers therefore it is mandatory to
// add at least one AnimLayer to the AnimStack. And for the purpose of this example,
// one layer is all we need.
FbxAnimLayer* lAnimLayer = FbxAnimLayer::Create(pScene, "Base Layer");
lAnimStack->AddMember(lAnimLayer);
//Create a simple animated fcurve
FbxProperty lMyProperty = lMyFbxObject->FindProperty("MyAnimatedPropertyName");
if( lMyProperty.IsValid() )
{
lMyProperty.Set(0.0); //Default value
lMyProperty.ModifyFlag(FbxPropertyFlags::eAnimatable, true);
lMyProperty.CreateCurveNode(lAnimLayer);
FbxAnimCurve* lMyFCurve = lMyProperty.GetCurve(lAnimLayer, true);
if( lMyFCurve )
{
FbxAnimCurveKey key;
key.Set(FBXSDK_TIME_ZERO, -100); lMyFCurve->KeyAdd(key.GetTime(), key);
key.Set(FbxTime(100), 0) ; lMyFCurve->KeyAdd(key.GetTime(), key);
key.Set(FbxTime(200), 100) ; lMyFCurve->KeyAdd(key.GetTime(), key);
}
}
Animate(lCube, lAnimLayer);
Animate(lPyramid, lAnimLayer);
Animate(lMyKFbxMeshCube, lAnimLayer);
FbxGlobalSettings& lGlobalSettings = pScene->GetGlobalSettings();
switch(gCacheType)
{
case 0:
default:
AnimateVertexCacheOnTriangleDoubleVertex(lTriangle, FbxTime::GetFrameRate(lGlobalSettings.GetTimeMode()));
break;
case 1:
AnimateVertexCacheOnTriangleInt32(lTriangle, FbxTime::GetFrameRate(lGlobalSettings.GetTimeMode()));
break;
case 2:
AnimateVertexCacheOnTriangleFloat(lTriangle, FbxTime::GetFrameRate(lGlobalSettings.GetTimeMode()));
break;
}
return true;
}
// Create a cube with a texture.
FbxNode* CreateCubeWithTexture(FbxScene* pScene, const 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);
// Here are two different ways to set the normal values.
bool firstWayNormalCalculations=true;
if (firstWayNormalCalculations)
{
// The first method is to set the actual normal value
// 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);
}
else
{
// The second method is to the possible values of the normals
// in the direct array, and set the index of that value
// in the index array for every control point.
lGeometryElementNormal->SetReferenceMode(FbxGeometryElement::eIndexToDirect);
// Add the 6 different normals to the direct array
lGeometryElementNormal->GetDirectArray().Add(lNormalZPos);
lGeometryElementNormal->GetDirectArray().Add(lNormalXPos);
lGeometryElementNormal->GetDirectArray().Add(lNormalZNeg);
lGeometryElementNormal->GetDirectArray().Add(lNormalXNeg);
lGeometryElementNormal->GetDirectArray().Add(lNormalYPos);
lGeometryElementNormal->GetDirectArray().Add(lNormalYNeg);
// Now for each control point, we need to specify which normal to use
lGeometryElementNormal->GetIndexArray().Add(0); // index of lNormalZPos in the direct array.
lGeometryElementNormal->GetIndexArray().Add(0); // index of lNormalZPos in the direct array.
lGeometryElementNormal->GetIndexArray().Add(0); // index of lNormalZPos in the direct array.
lGeometryElementNormal->GetIndexArray().Add(0); // index of lNormalZPos in the direct array.
lGeometryElementNormal->GetIndexArray().Add(1); // index of lNormalXPos in the direct array.
lGeometryElementNormal->GetIndexArray().Add(1); // index of lNormalXPos in the direct array.
lGeometryElementNormal->GetIndexArray().Add(1); // index of lNormalXPos in the direct array.
lGeometryElementNormal->GetIndexArray().Add(1); // index of lNormalXPos in the direct array.
lGeometryElementNormal->GetIndexArray().Add(2); // index of lNormalZNeg in the direct array.
lGeometryElementNormal->GetIndexArray().Add(2); // index of lNormalZNeg in the direct array.
lGeometryElementNormal->GetIndexArray().Add(2); // index of lNormalZNeg in the direct array.
lGeometryElementNormal->GetIndexArray().Add(2); // index of lNormalZNeg in the direct array.
lGeometryElementNormal->GetIndexArray().Add(3); // index of lNormalXNeg in the direct array.
lGeometryElementNormal->GetIndexArray().Add(3); // index of lNormalXNeg in the direct array.
lGeometryElementNormal->GetIndexArray().Add(3); // index of lNormalXNeg in the direct array.
lGeometryElementNormal->GetIndexArray().Add(3); // index of lNormalXNeg in the direct array.
lGeometryElementNormal->GetIndexArray().Add(4); // index of lNormalYPos in the direct array.
lGeometryElementNormal->GetIndexArray().Add(4); // index of lNormalYPos in the direct array.
lGeometryElementNormal->GetIndexArray().Add(4); // index of lNormalYPos in the direct array.
lGeometryElementNormal->GetIndexArray().Add(4); // index of lNormalYPos in the direct array.
lGeometryElementNormal->GetIndexArray().Add(5); // index of lNormalYNeg in the direct array.
lGeometryElementNormal->GetIndexArray().Add(5); // index of lNormalYNeg in the direct array.
lGeometryElementNormal->GetIndexArray().Add(5); // index of lNormalYNeg in the direct array.
lGeometryElementNormal->GetIndexArray().Add(5); // index of lNormalYNeg in the direct array.
}
// 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( gDiffuseElementName);
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);
// Create UV for Ambient channel
FbxGeometryElementUV* lUVAmbientElement = lMesh->CreateElementUV(gAmbientElementName);
lUVAmbientElement->SetMappingMode(FbxGeometryElement::eByPolygonVertex);
lUVAmbientElement->SetReferenceMode(FbxGeometryElement::eIndexToDirect);
lVectors0.Set(0, 0);
lVectors1.Set(1, 0);
lVectors2.Set(0, 0.418586879968643);
lVectors3.Set(1, 0.418586879968643);
lUVAmbientElement->GetDirectArray().Add(lVectors0);
lUVAmbientElement->GetDirectArray().Add(lVectors1);
lUVAmbientElement->GetDirectArray().Add(lVectors2);
lUVAmbientElement->GetDirectArray().Add(lVectors3);
// Create UV for Emissive channel
FbxGeometryElementUV* lUVEmissiveElement = lMesh->CreateElementUV(gEmissiveElementName);
lUVEmissiveElement->SetMappingMode(FbxGeometryElement::eByPolygonVertex);
lUVEmissiveElement->SetReferenceMode(FbxGeometryElement::eIndexToDirect);
lVectors0.Set(0.2343, 0);
lVectors1.Set(1, 0.555);
lVectors2.Set(0.333, 0.999);
lVectors3.Set(0.555, 0.666);
lUVEmissiveElement->GetDirectArray().Add(lVectors0);
lUVEmissiveElement->GetDirectArray().Add(lVectors1);
lUVEmissiveElement->GetDirectArray().Add(lVectors2);
lUVEmissiveElement->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);
lUVAmbientElement->GetIndexArray().SetCount(24);
lUVEmissiveElement->GetIndexArray().SetCount(24);
// Create polygons. Assign texture and texture UV indices.
for(i = 0; i < 6; i++)
{
//we won't use the default way of assigning textures, as we have
//textures on more than just the default (diffuse) channel.
lMesh->BeginPolygon(-1, -1, false);
for(j = 0; j < 4; j++)
{
//this function points
lMesh->AddPolygon(lPolygonVertices[i*4 + j] // Control point index.
);
//Now we have to update the index array of the UVs for diffuse, ambient and emissive
lUVDiffuseElement->GetIndexArray().SetAt(i*4+j, j);
lUVAmbientElement->GetIndexArray().SetAt(i*4+j, j);
lUVEmissiveElement->GetIndexArray().SetAt(i*4+j, j);
}
lMesh->EndPolygon ();
}
FbxNode* lNode = FbxNode::Create(pScene,pName);
lNode->SetNodeAttribute(lMesh);
lNode->SetShadingMode(FbxNode::eTextureShading);
CreateTexture(pScene, lMesh);
return lNode;
}
// Create a pyramid with materials.
FbxNode* CreatePyramidWithMaterials(FbxScene* pScene, const char* pName)
{
int i, j;
FbxMesh* lMesh = FbxMesh::Create(pScene, pName);
FbxVector4 lControlPoint0(-50, 0, 50);
FbxVector4 lControlPoint1(50, 0, 50);
FbxVector4 lControlPoint2(50, 0, -50);
FbxVector4 lControlPoint3(-50, 0, -50);
FbxVector4 lControlPoint4(0, 100, 0);
FbxVector4 lNormalP0(0, 1, 0);
FbxVector4 lNormalP1(0, 0.447, 0.894);
FbxVector4 lNormalP2(0.894, 0.447, 0);
FbxVector4 lNormalP3(0, 0.447, -0.894);
FbxVector4 lNormalP4(-0.894, 0.447, 0);
// Create control points.
lMesh->InitControlPoints(16);
FbxVector4* lControlPoints = lMesh->GetControlPoints();
lControlPoints[0] = lControlPoint0;
lControlPoints[1] = lControlPoint1;
lControlPoints[2] = lControlPoint2;
lControlPoints[3] = lControlPoint3;
lControlPoints[4] = lControlPoint0;
lControlPoints[5] = lControlPoint1;
lControlPoints[6] = lControlPoint4;
lControlPoints[7] = lControlPoint1;
lControlPoints[8] = lControlPoint2;
lControlPoints[9] = lControlPoint4;
lControlPoints[10] = lControlPoint2;
lControlPoints[11] = lControlPoint3;
lControlPoints[12] = lControlPoint4;
lControlPoints[13] = lControlPoint3;
lControlPoints[14] = lControlPoint0;
lControlPoints[15] = lControlPoint4;
// specify normals per control point.
FbxGeometryElementNormal* lNormalElement= lMesh->CreateElementNormal();
lNormalElement->SetMappingMode(FbxGeometryElement::eByControlPoint);
lNormalElement->SetReferenceMode(FbxGeometryElement::eDirect);
lNormalElement->GetDirectArray().Add(lNormalP0);
lNormalElement->GetDirectArray().Add(lNormalP0);
lNormalElement->GetDirectArray().Add(lNormalP0);
lNormalElement->GetDirectArray().Add(lNormalP0);
lNormalElement->GetDirectArray().Add(lNormalP1);
lNormalElement->GetDirectArray().Add(lNormalP1);
lNormalElement->GetDirectArray().Add(lNormalP1);
lNormalElement->GetDirectArray().Add(lNormalP2);
lNormalElement->GetDirectArray().Add(lNormalP2);
lNormalElement->GetDirectArray().Add(lNormalP2);
lNormalElement->GetDirectArray().Add(lNormalP3);
lNormalElement->GetDirectArray().Add(lNormalP3);
lNormalElement->GetDirectArray().Add(lNormalP3);
lNormalElement->GetDirectArray().Add(lNormalP4);
lNormalElement->GetDirectArray().Add(lNormalP4);
lNormalElement->GetDirectArray().Add(lNormalP4);
// Array of polygon vertices.
int lPolygonVertices[] = { 0, 3, 2, 1,
4, 5, 6,
7, 8, 9,
10, 11, 12,
13, 14, 15 };
// Set material mapping.
FbxGeometryElementMaterial* lMaterialElement = lMesh->CreateElementMaterial();
lMaterialElement->SetMappingMode(FbxGeometryElement::eByPolygon);
lMaterialElement->SetReferenceMode(FbxGeometryElement::eIndexToDirect);
// Create polygons. Assign material indices.
// Pyramid base.
lMesh->BeginPolygon(0); // Material index.
for(j = 0; j < 4; j++)
{
lMesh->AddPolygon(lPolygonVertices[j]); // Control point index.
}
lMesh->EndPolygon ();
// Pyramid sides.
for(i = 1; i < 5; i++)
{
lMesh->BeginPolygon(i); // Material index.
for(j = 0; j < 3; j++)
{
lMesh->AddPolygon(lPolygonVertices[4 + 3*(i - 1) + j]); // Control point index.
}
lMesh->EndPolygon ();
}
FbxNode* lNode = FbxNode::Create(pScene,pName);
lNode->SetNodeAttribute(lMesh);
CreateMaterials(pScene, lMesh);
return lNode;
}
FbxNode* CreateTriangle(FbxScene* pScene, const char* pName)
{
FbxMesh* lMesh = FbxMesh::Create(pScene, pName);
// The three vertices
FbxVector4 lControlPoint0(-50, 0, 50);
FbxVector4 lControlPoint1(50, 0, 50);
FbxVector4 lControlPoint2(0, 50, -50);
// Create control points.
lMesh->InitControlPoints(3);
FbxVector4* lControlPoints = lMesh->GetControlPoints();
lControlPoints[0] = lControlPoint0;
lControlPoints[1] = lControlPoint1;
lControlPoints[2] = lControlPoint2;
// Create the triangle's polygon
lMesh->BeginPolygon();
lMesh->AddPolygon(0); // Control point 0
lMesh->AddPolygon(1); // Control point 1
lMesh->AddPolygon(2); // Control point 2
lMesh->EndPolygon();
FbxNode* lNode = FbxNode::Create(pScene,pName);
lNode->SetNodeAttribute(lMesh);
return lNode;
}
FbxNode* CreateCubeWithMaterialAndMyKFbxMesh(FbxScene* pScene, const char* pName)
{
int i, j;
//create a cube with our newly created class
MyKFbxMesh* lMyKFbxMesh = MyKFbxMesh::Create(pScene,pName);
FbxDouble3 lVector3(0.1, 0.2, 0.3);
FbxDouble4 lVector4(0.1, 0.2, 0.3, 0.4);
FbxDouble4 lVector41(1.1, 1.2, 1.3, 1.4);
FbxDouble4 lVector42(2.1, 2.2, 2.3, 2.4);
FbxDouble4 lVector43(3.1, 3.2, 3.3, 3.4);
FbxDouble4x4 lMatrix(lVector4,lVector41,lVector42,lVector43);
FbxColor lGreen(0.0, 0.0, 1.0);
FbxTime lTime(333);
//Set user-specific properties of our classes
FbxString lString = "My Property 5 Value";
lMyKFbxMesh->GetProperty((int) MyKFbxMesh::eMY_PROPERTY1).Set(true);
lMyKFbxMesh->GetProperty((int) MyKFbxMesh::eMY_PROPERTY2).Set((int) 1);
lMyKFbxMesh->GetProperty((int) MyKFbxMesh::eMY_PROPERTY3).Set((float)2.2);
lMyKFbxMesh->GetProperty((int) MyKFbxMesh::eMY_PROPERTY4).Set((double)3.3);
lMyKFbxMesh->GetProperty((int) MyKFbxMesh::eMY_PROPERTY5).Set(lString);
lMyKFbxMesh->GetProperty((int) MyKFbxMesh::eMY_PROPERTY6).Set(lVector3);
lMyKFbxMesh->GetProperty((int) MyKFbxMesh::eMY_PROPERTY6).Set(lGreen);
lMyKFbxMesh->GetProperty((int) MyKFbxMesh::eMY_PROPERTY8).Set(lVector4);
lMyKFbxMesh->GetProperty((int) MyKFbxMesh::eMY_PROPERTY9).Set(lMatrix);
lMyKFbxMesh->GetProperty((int) MyKFbxMesh::eMY_PROPERTY10).Set(3);
lMyKFbxMesh->GetProperty((int) MyKFbxMesh::eMY_PROPERTY10).AddEnumValue("AAA");
lMyKFbxMesh->GetProperty((int) MyKFbxMesh::eMY_PROPERTY10).AddEnumValue("BBB");
lMyKFbxMesh->GetProperty((int) MyKFbxMesh::eMY_PROPERTY10).AddEnumValue("CCC");
lMyKFbxMesh->GetProperty((int) MyKFbxMesh::eMY_PROPERTY10).AddEnumValue("DDD");
lMyKFbxMesh->GetProperty((int) MyKFbxMesh::eMY_PROPERTY11).Set(lTime);
FbxVector4 lControlPoint0(-25, 0, 25);
FbxVector4 lControlPoint1(25, 0, 25);
FbxVector4 lControlPoint2(25, 50, 25);
FbxVector4 lControlPoint3(-25, 50, 25);
FbxVector4 lControlPoint4(-25, 0, -25);
FbxVector4 lControlPoint5(25, 0, -25);
FbxVector4 lControlPoint6(25, 50, -25);
FbxVector4 lControlPoint7(-25, 50, -25);
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.
lMyKFbxMesh->InitControlPoints(24);
FbxVector4* lControlPoints = lMyKFbxMesh->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 = lMyKFbxMesh->CreateElementNormal();
lGeometryElementNormal->SetMappingMode(FbxGeometryElement::eByControlPoint);
// The second method is to the possible values of the normals
// in the direct array, and set the index of that value
// in the index array for every control point.
lGeometryElementNormal->SetReferenceMode(FbxGeometryElement::eIndexToDirect);
// Add the 6 different normals to the direct array
lGeometryElementNormal->GetDirectArray().Add(lNormalZPos);
lGeometryElementNormal->GetDirectArray().Add(lNormalXPos);
lGeometryElementNormal->GetDirectArray().Add(lNormalZNeg);
lGeometryElementNormal->GetDirectArray().Add(lNormalXNeg);
lGeometryElementNormal->GetDirectArray().Add(lNormalYPos);
lGeometryElementNormal->GetDirectArray().Add(lNormalYNeg);
// Now for each control point, we need to specify which normal to use
lGeometryElementNormal->GetIndexArray().Add(0); // index of lNormalZPos in the direct array.
lGeometryElementNormal->GetIndexArray().Add(0); // index of lNormalZPos in the direct array.
lGeometryElementNormal->GetIndexArray().Add(0); // index of lNormalZPos in the direct array.
lGeometryElementNormal->GetIndexArray().Add(0); // index of lNormalZPos in the direct array.
lGeometryElementNormal->GetIndexArray().Add(1); // index of lNormalXPos in the direct array.
lGeometryElementNormal->GetIndexArray().Add(1); // index of lNormalXPos in the direct array.
lGeometryElementNormal->GetIndexArray().Add(1); // index of lNormalXPos in the direct array.
lGeometryElementNormal->GetIndexArray().Add(1); // index of lNormalXPos in the direct array.
lGeometryElementNormal->GetIndexArray().Add(2); // index of lNormalZNeg in the direct array.
lGeometryElementNormal->GetIndexArray().Add(2); // index of lNormalZNeg in the direct array.
lGeometryElementNormal->GetIndexArray().Add(2); // index of lNormalZNeg in the direct array.
lGeometryElementNormal->GetIndexArray().Add(2); // index of lNormalZNeg in the direct array.
lGeometryElementNormal->GetIndexArray().Add(3); // index of lNormalXNeg in the direct array.
lGeometryElementNormal->GetIndexArray().Add(3); // index of lNormalXNeg in the direct array.
lGeometryElementNormal->GetIndexArray().Add(3); // index of lNormalXNeg in the direct array.
lGeometryElementNormal->GetIndexArray().Add(3); // index of lNormalXNeg in the direct array.
lGeometryElementNormal->GetIndexArray().Add(4); // index of lNormalYPos in the direct array.
lGeometryElementNormal->GetIndexArray().Add(4); // index of lNormalYPos in the direct array.
lGeometryElementNormal->GetIndexArray().Add(4); // index of lNormalYPos in the direct array.
lGeometryElementNormal->GetIndexArray().Add(4); // index of lNormalYPos in the direct array.
lGeometryElementNormal->GetIndexArray().Add(5); // index of lNormalYNeg in the direct array.
lGeometryElementNormal->GetIndexArray().Add(5); // index of lNormalYNeg in the direct array.
lGeometryElementNormal->GetIndexArray().Add(5); // index of lNormalYNeg in the direct array.
lGeometryElementNormal->GetIndexArray().Add(5); // index of lNormalYNeg in the direct array.
// 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 };
// Set material mapping.
FbxGeometryElementMaterial* lMaterialElement = lMyKFbxMesh->CreateElementMaterial();
lMaterialElement->SetMappingMode(FbxGeometryElement::eByPolygon);
lMaterialElement->SetReferenceMode(FbxGeometryElement::eIndexToDirect);
// Create UV coordinates.
FbxGeometryElementUV* lUVElement = lMyKFbxMesh->CreateElementUV( "");
FBX_ASSERT( lUVElement != NULL);
lUVElement->SetMappingMode(FbxGeometryElement::eByPolygonVertex);
lUVElement->SetReferenceMode(FbxGeometryElement::eIndexToDirect);
FbxVector2 lVectors0(0, 0);
FbxVector2 lVectors1(1, 0);
FbxVector2 lVectors2(1, 1);
FbxVector2 lVectors3(0, 1);
lUVElement->GetDirectArray().Add(lVectors0);
lUVElement->GetDirectArray().Add(lVectors1);
lUVElement->GetDirectArray().Add(lVectors2);
lUVElement->GetDirectArray().Add(lVectors3);
for(i = 0; i < 6; i++)
{
//we created 6 lambert materials in the MyKFbxMesh
//make each face use a different one
lMyKFbxMesh->BeginPolygon(i);
for(j = 0; j < 4; j++)
{
lMyKFbxMesh->AddPolygon(lPolygonVertices[i*4 + j], // Control point index.
j); // Valid texture UV index since texture UV mapping is by polygon vertex.
}
lMyKFbxMesh->EndPolygon ();
}
//Add a User Data Element
//As of now, the types supported by a User Data Element are: FbxBoolDT, FbxIntDT, FbxFloatDT and FbxDoubleDT
//For this example, we will create a element which possess 1 float and 1 bool
//create a template array of KFbxDataTypes
FbxArray<FbxDataType> lArrayType;
//Create a template array of const char*
FbxArray<const char*> lArrayNames;
//let's add our types and the names of each of the added types
lArrayType.Add(FbxFloatDT);
lArrayNames.Add("My Float");
lArrayType.Add(FbxBoolDT);
lArrayNames.Add("My Bool");
//Now we are ready to create the User Data Element
FbxGeometryElementUserData* lFbxGeometryElementUserData = FbxGeometryElementUserData::Create(lMyKFbxMesh, "My Geometry Element",PID_MY_GEOMETRY_LEMENT,lArrayType, lArrayNames);
//And UserData create function is still in implementing
//For this example we will set the mapping mode to POLYGON_VERTEX
lFbxGeometryElementUserData->SetMappingMode(FbxGeometryElement::eByPolygonVertex);
//As we are using the eDirect Reference mode, and we are using polygon vertex Mapping mode
//we have to resize the direct array to the number of polygon vertex we have in this mesh
lFbxGeometryElementUserData->ResizeAllDirectArrays(lMyKFbxMesh->GetPolygonVertexCount());
//To change the values in the direct array, we simply get the array and modify what we need to
FbxLayerElementArrayTemplate<void*>* directArrayF = lFbxGeometryElementUserData->GetDirectArrayVoid("My Float");
float *lDirectArrayFloat = NULL;
lDirectArrayFloat = directArrayF->GetLocked(lDirectArrayFloat);
FbxLayerElementArrayTemplate<void*>* directArrayB = lFbxGeometryElementUserData->GetDirectArrayVoid("My Bool");
bool *lDirectArrayBool = NULL;
directArrayB->GetLocked(lDirectArrayBool);
//Modify every data for each polygon vertex on our mesh with some value
for(i=0; i<lMyKFbxMesh->GetPolygonVertexCount(); ++i)
{
if(lDirectArrayFloat)
lDirectArrayFloat[i]=(float)(i+0.5);
if(lDirectArrayBool)
lDirectArrayBool[i]= (i%2==0);
}
directArrayF->Release((void**)&lDirectArrayFloat);
directArrayB->Release((void**)&lDirectArrayBool);
FbxNode* lNode = FbxNode::Create(pScene,pName);
lNode->SetNodeAttribute(lMyKFbxMesh);
lNode->SetShadingMode(FbxNode::eTextureShading);
//let's create the materials
//6 materials, 1 for each face of the cube
CreateMaterialsWithMyKFbxMesh(pScene, lMyKFbxMesh);
return lNode;
}
// Create texture for cube.
void CreateTexture(FbxScene* pScene, FbxMesh* pMesh)
{
// A texture need to be connected to a property on the material,
// so let's use the material (if it exists) or create a new one
FbxSurfacePhong* lMaterial = NULL;
//get the node of mesh, add material for it.
FbxNode* lNode = pMesh->GetNode();
if(lNode)
{
lMaterial = lNode->GetSrcObject<FbxSurfacePhong>(0);
if (lMaterial == NULL)
{
FbxString lMaterialName = "toto";
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);
FbxLayer* lLayer = pMesh->GetLayer(0);
// Create a layer element material to handle proper mapping.
FbxLayerElementMaterial* lLayerElementMaterial = FbxLayerElementMaterial::Create(pMesh, lMaterialName.Buffer());
// This allows us to control where the materials are mapped. Using eAllSame
// means that all faces/polygons of the mesh will be assigned the same material.
lLayerElementMaterial->SetMappingMode(FbxLayerElement::eAllSame);
lLayerElementMaterial->SetReferenceMode(FbxLayerElement::eIndexToDirect);
// Save the material on the layer
lLayer->SetMaterials(lLayerElementMaterial);
// Add an index to the lLayerElementMaterial. Since we have only one, and are using eAllSame mapping mode,
// we only need to add one.
lLayerElementMaterial->GetIndexArray().Add(0);
lMaterial = FbxSurfacePhong::Create(pScene, lMaterialName.Buffer());
// Generate primary and secondary colors.
lMaterial->Emissive .Set(lBlack);
lMaterial->Ambient .Set(lRed);
lMaterial->AmbientFactor .Set(1.);
// Add texture for diffuse channel
lMaterial->Diffuse .Set(lDiffuseColor);
lMaterial->DiffuseFactor .Set(1.);
lMaterial->TransparencyFactor.Set(0.4);
lMaterial->ShadingModel .Set(lShadingName);
lMaterial->Shininess .Set(0.5);
lMaterial->Specular .Set(lBlack);
lMaterial->SpecularFactor .Set(0.3);
lNode->AddMaterial(lMaterial);
}
}
FbxFileTexture* lTexture = FbxFileTexture::Create(pScene,"Diffuse Texture");
// Set texture properties.
lTexture->SetFileName("scene03.jpg"); // Resource file is in current directory.
lTexture->SetTextureUse(FbxTexture::eStandard);
lTexture->SetMappingType(FbxTexture::eUV);
lTexture->SetMaterialUse(FbxFileTexture::eModelMaterial);
lTexture->SetSwapUV(false);
lTexture->SetTranslation(0.0, 0.0);
lTexture->SetScale(1.0, 1.0);
lTexture->SetRotation(0.0, 0.0);
lTexture->UVSet.Set(FbxString(gDiffuseElementName)); // Connect texture to the proper UV
// don't forget to connect the texture to the corresponding property of the material
if (lMaterial)
lMaterial->Diffuse.ConnectSrcObject(lTexture);
lTexture = FbxFileTexture::Create(pScene,"Ambient Texture");
// Set texture properties.
lTexture->SetFileName("gradient.jpg"); // Resource file is in current directory.
lTexture->SetTextureUse(FbxTexture::eStandard);
lTexture->SetMappingType(FbxTexture::eUV);
lTexture->SetMaterialUse(FbxFileTexture::eModelMaterial);
lTexture->SetSwapUV(false);
lTexture->SetTranslation(0.0, 0.0);
lTexture->SetScale(1.0, 1.0);
lTexture->SetRotation(0.0, 0.0);
lTexture->UVSet.Set(FbxString(gAmbientElementName)); // Connect texture to the proper UV
// don't forget to connect the texture to the corresponding property of the material
if (lMaterial)
lMaterial->Ambient.ConnectSrcObject(lTexture);
lTexture = FbxFileTexture::Create(pScene,"Emissive Texture");
// Set texture properties.
lTexture->SetFileName("spotty.jpg"); // Resource file is in current directory.
lTexture->SetTextureUse(FbxTexture::eStandard);
lTexture->SetMappingType(FbxTexture::eUV);
lTexture->SetMaterialUse(FbxFileTexture::eModelMaterial);
lTexture->SetSwapUV(false);
lTexture->SetTranslation(0.0, 0.0);
lTexture->SetScale(1.0, 1.0);
lTexture->SetRotation(0.0, 0.0);
lTexture->UVSet.Set(FbxString(gEmissiveElementName)); // Connect texture to the proper UV
// don't forget to connect the texture to the corresponding property of the material
if (lMaterial)
lMaterial->Emissive.ConnectSrcObject(lTexture);
}
// Create materials for pyramid.
void CreateMaterials(FbxScene* pScene, FbxMesh* pMesh)
{
int i;
for (i = 0; i < 5; i++ )
{
FbxString lMaterialName = "material";
FbxString lShadingName = "Phong";
lMaterialName += i;
FbxDouble3 lBlack(0.0, 0.0, 0.0);
FbxDouble3 lRed(1.0, 0.0, 0.0);
FbxDouble3 lColor;
FbxSurfacePhong *lMaterial = FbxSurfacePhong::Create(pScene, lMaterialName.Buffer());
// Generate primary and secondary colors.
lMaterial->Emissive.Set(lBlack);
lMaterial->Ambient.Set(lRed);
lColor = FbxDouble3(i > 2 ? 1.0 : 0.0,
i > 0 && i < 4 ? 1.0 : 0.0,
i % 2 ? 0.0 : 1.0);
lMaterial->Diffuse.Set(lColor);
lMaterial->TransparencyFactor.Set(0.0);
lMaterial->ShadingModel.Set(lShadingName);
lMaterial->Shininess.Set(0.5);
//get the node of mesh, add material for it.
FbxNode* lNode = pMesh->GetNode();
if(lNode)
lNode->AddMaterial(lMaterial);
}
}
void CreateMaterialsWithMyKFbxMesh(FbxScene* pScene, MyKFbxMesh* pMyKFbxMesh)
{
int i;
for (i = 0; i != 6; ++i )
{
FbxString lMaterialName = "material";
FbxString lShadingModelName = i%2==0 ? "Lambert" : "Phong";
lMaterialName += i;
FbxDouble3 lBlack(0.0, 0.0, 0.0);
FbxDouble3 lRed(1.0, 0.0, 0.0);
FbxDouble3 lColor;
FbxSurfaceLambert *lMaterial = FbxSurfaceLambert::Create(pScene, lMaterialName.Buffer());
// Generate primary and secondary colors.
lMaterial->Emissive.Set(lBlack);
lMaterial->Ambient.Set(lRed);
lColor = FbxDouble3(i > 2 ? 1.0 : 0.0,
i > 0 && i < 4 ? 1.0 : 0.0,
i % 2 ? 0.0 : 1.0);
lMaterial->Diffuse.Set(lColor);
lMaterial->TransparencyFactor.Set(0.0);
lMaterial->ShadingModel.Set(lShadingModelName);
//get the node of mesh, add material for it.
FbxNode* lNode = pMyKFbxMesh->GetNode();
if(lNode)
lNode->AddMaterial(lMaterial);
}
}
// Map pyramid control points onto an upside down shape.
void MapShapeOnPyramid(FbxScene* pScene, FbxNode* pPyramid)
{
FbxShape* lShape = FbxShape::Create(pScene,"Upside Down");
FbxVector4 lControlPoint0(-50, 100, 50);
FbxVector4 lControlPoint1(50, 100, 50);
FbxVector4 lControlPoint2(50, 100, -50);
FbxVector4 lControlPoint3(-50, 100, -50);
FbxVector4 lControlPoint4(0, 0, 0);
FbxVector4 lNormalP0(0, 1, 0);
FbxVector4 lNormalP1(0, -0.447, 0.894);
FbxVector4 lNormalP2(0.894, -0.447, 0);
FbxVector4 lNormalP3(0, -0.447, -0.894);
FbxVector4 lNormalP4(-0.894, -0.447, 0);