#include "../Common/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
bool CreateScene(
FbxScene* pScene,
char* pSampleFileName);
FbxNode* CreateCubeWithMaterialAndMyKFbxMesh(
FbxScene* pScene,
const char* pName);
void CreateMaterialsWithMyKFbxMesh(
FbxScene* pScene, MyKFbxMesh* pMyKFbxMesh);
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 AnimateVertexCacheOnTriangleDoubleVertex(
FbxNode* pNode,
double pFrameRate);
void AnimateVertexCacheOnTriangleInt32(
FbxNode* pNode,
double pFrameRate);
void AnimateVertexCacheOnTriangleFloat(
FbxNode* pNode,
double pFrameRate);
bool gExportVertexCacheMCFormat = true;
static const char* gDiffuseElementName = "DiffuseUV";
static const char* gAmbientElementName = "AmbientUV";
static const char* gEmissiveElementName = "EmissiveUV";
int gCacheType = -1;
int main(int argc, char** argv)
{
char* lSampleFileName =
NULL;
bool lResult;
InitializeSdkObjects(lSdkManager, lScene);
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;
lResult = CreateScene(lScene, lSampleFileName);
if(lResult == false)
{
FBXSDK_printf("\n\nAn error occurred while creating the scene...\n");
DestroySdkObjects(lSdkManager, lResult);
return 0;
}
lResult = SaveScene(lSdkManager, lScene, lSampleFileName);
if(lResult == false)
{
FBXSDK_printf("\n\nAn error occurred while saving the scene...\n");
DestroySdkObjects(lSdkManager, lResult);
return 0;
}
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);
FbxProperty lMyProperty = lMyFbxObject->FindProperty(
"MyAnimatedPropertyName");
{
if( lMyFCurve )
{
}
}
Animate(lCube, lAnimLayer);
Animate(lPyramid, lAnimLayer);
Animate(lMyKFbxMeshCube, lAnimLayer);
switch(gCacheType)
{
case 0:
default:
break;
case 1:
break;
case 2:
break;
}
return true;
}
{
int i, j;
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;
bool firstWayNormalCalculations=true;
if (firstWayNormalCalculations)
{
}
else
{
}
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 };
FBX_ASSERT( lUVDiffuseElement !=
NULL);
lVectors0.Set(0, 0);
lVectors1.Set(1, 0);
lVectors2.Set(0, 0.418586879968643);
lVectors3.Set(1, 0.418586879968643);
lVectors0.Set(0.2343, 0);
lVectors1.Set(1, 0.555);
lVectors2.Set(0.333, 0.999);
lVectors3.Set(0.555, 0.666);
for(i = 0; i < 6; i++)
{
for(j = 0; j < 4; j++)
{
);
}
}
CreateTexture(pScene, lMesh);
return lNode;
}
{
int i, j;
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;
int lPolygonVertices[] = { 0, 3, 2, 1,
4, 5, 6,
7, 8, 9,
10, 11, 12,
13, 14, 15 };
for(j = 0; j < 4; j++)
{
}
for(i = 1; i < 5; i++)
{
for(j = 0; j < 3; j++)
{
lMesh->
AddPolygon(lPolygonVertices[4 + 3*(i - 1) + j]);
}
}
CreateMaterials(pScene, lMesh);
return lNode;
}
{
lControlPoints[0] = lControlPoint0;
lControlPoints[1] = lControlPoint1;
lControlPoints[2] = lControlPoint2;
return lNode;
}
FbxNode* CreateCubeWithMaterialAndMyKFbxMesh(
FbxScene* pScene,
const char* pName)
{
int i, j;
MyKFbxMesh* lMyKFbxMesh = MyKFbxMesh::Create(pScene,pName);
FbxDouble4x4 lMatrix(lVector4,lVector41,lVector42,lVector43);
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);
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;
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 };
FBX_ASSERT( lUVElement !=
NULL);
for(i = 0; i < 6; i++)
{
lMyKFbxMesh->BeginPolygon(i);
for(j = 0; j < 4; j++)
{
lMyKFbxMesh->AddPolygon(lPolygonVertices[i*4 + j],
j);
}
lMyKFbxMesh->EndPolygon ();
}
lArrayNames.
Add(
"My Float");
lArrayNames.
Add(
"My Bool");
float *lDirectArrayFloat =
NULL;
lDirectArrayFloat = directArrayF->
GetLocked(lDirectArrayFloat);
bool *lDirectArrayBool =
NULL;
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);
CreateMaterialsWithMyKFbxMesh(pScene, lMyKFbxMesh);
return lNode;
}
{
if(lNode)
{
{
lMaterial->
Diffuse .Set(lDiffuseColor);
}
}
if (lMaterial)
lMaterial->
Diffuse.ConnectSrcObject(lTexture);
if (lMaterial)
lMaterial->
Ambient.ConnectSrcObject(lTexture);
if (lMaterial)
lMaterial->
Emissive.ConnectSrcObject(lTexture);
}
{
int i;
for (i = 0; i < 5; i++ )
{
lMaterialName += i;
i > 0 && i < 4 ? 1.0 : 0.0,
i % 2 ? 0.0 : 1.0);
if(lNode)
}
}
void CreateMaterialsWithMyKFbxMesh(
FbxScene* pScene, MyKFbxMesh* pMyKFbxMesh)
{
int i;
for (i = 0; i != 6; ++i )
{
FbxString lShadingModelName = i%2==0 ?
"Lambert" :
"Phong";
lMaterialName += i;
i > 0 && i < 4 ? 1.0 : 0.0,
i % 2 ? 0.0 : 1.0);
FbxNode* lNode = pMyKFbxMesh->GetNode();
if(lNode)
}
}
{
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;
}
void MapVertexCacheOnTriangle(
FbxScene* pScene,
FbxNode* pTriangle,
char* pSampleFileName)
{
lFPCAbsoluteDirectory += "/";
lFPCAbsoluteDirectory += "_fpc";
lAbsolutePCFileName += gExportVertexCacheMCFormat ? ".xml" : ".pc2";
{
return;
}
if (gExportVertexCacheMCFormat && gCacheType != 1)
{
channelName += "_normals";
}
}
void SetCubeDefaultPosition(
FbxNode* pCube)
{
}
void SetPyramidDefaultPosition(
FbxNode* pPyramid)
{
}
void SetTriangleDefaultPosition(
FbxNode* pTriangle)
{
}
void SetMyKFbxMeshCubeDefaultPosition(
FbxNode* pMyKFbxCube)
{
}
{
int lKeyIndex = 0;
if (lCurve)
{
lKeyIndex = lCurve->
KeyAdd(lTime);
lKeyIndex = lCurve->
KeyAdd(lTime);
lKeyIndex = lCurve->
KeyAdd(lTime);
lKeyIndex = lCurve->
KeyAdd(lTime);
lKeyIndex = lCurve->
KeyAdd(lTime);
}
if (lCurve)
{
lKeyIndex = lCurve->
KeyAdd(lTime);
lKeyIndex = lCurve->
KeyAdd(lTime);
lKeyIndex = lCurve->
KeyAdd(lTime);
lKeyIndex = lCurve->
KeyAdd(lTime);
}
if (lCurve)
{
lKeyIndex = lCurve->
KeyAdd(lTime);
lKeyIndex = lCurve->
KeyAdd(lTime);
lKeyIndex = lCurve->
KeyAdd(lTime);
}
}
void AnimateVertexCacheOnTriangleDoubleVertex(
FbxNode* pTriangle,
double pFrameRate)
{
bool lRet;
FbxTime lTimeIncrement, lCurrentTime, lStopTime;
lTimeIncrement.
SetTime(0, 0, 0, 1);
unsigned int lFrameCount = (
unsigned int)(lStopTime.
Get()/lTimeIncrement.
Get());
unsigned int lNormalChannelIndex;
if (gExportVertexCacheMCFormat)
{
if (lRet)
{
channelName += "_normals";
}
}
else
{
}
if (!lRet)
{
return;
}
unsigned int lCurrentFrame = 0;
while (lCurrentTime <= lStopTime)
{
double lVertices[3][3];
lVertices[0][0] = -50.0 * lScaleFactor;
lVertices[0][1] = 0.0;
lVertices[0][2] = 50.0 * lScaleFactor;
lVertices[1][0] = 50.0 * lScaleFactor;
lVertices[1][1] = 0.0;
lVertices[1][2] = 50.0 * lScaleFactor;
lVertices[2][0] = 0.0 * lScaleFactor;
lVertices[2][1] = 50.0 * lScaleFactor;
lVertices[2][2] = -50.0 * lScaleFactor;
if (gExportVertexCacheMCFormat)
{
float lNormals[3][3];
for (int i = 0; i < 3; i++)
{
lNormals[i][0] = 0.0f;
lNormals[i][1] = 1.0f;
lNormals[i][2] = 0.0f;
}
lCache->
Write(lChannelIndex, lCurrentTime, &lVertices[0][0], 3);
lCache->
Write(lNormalChannelIndex, lCurrentTime, &lNormals[0][0], 3);
}
else
{
lCache->
Write(lCurrentFrame, &lVertices[0][0]);
}
lCurrentTime += lTimeIncrement;
lCurrentFrame++;
}
{
}
}
void AnimateVertexCacheOnTriangleInt32(
FbxNode* pTriangle,
double pFrameRate)
{
bool lRet = false;
FbxTime lTimeIncrement, lCurrentTime, lStopTime;
lTimeIncrement.
SetTime(0, 0, 0, 1);
if (gExportVertexCacheMCFormat)
{
}
if (!lRet)
{
return;
}
int lCurrentFrame = 0;
while (lCurrentTime <= lStopTime)
{
int v[2];
v[0] = -10 + lCurrentFrame;
v[1] = v[0]+1;
if (gExportVertexCacheMCFormat)
{
lCache->
Write(lChannelIndex, lCurrentTime, &v[0], 2);
}
lCurrentTime += lTimeIncrement;
lCurrentFrame++;
}
{
}
if (gExportVertexCacheMCFormat)
{
}
if (!lRet)
{
return;
}
lCurrentFrame = 0;
FBXSDK_printf("Testing awCache int32 array read and write\n");
bool passTest = true;
while (lCurrentTime2 <= lStopTime)
{
int v[2];
if (gExportVertexCacheMCFormat)
{
lCache->
Read(lChannelIndex, lCurrentTime2, &v[0], 2);
if ((v[0] != -10 + lCurrentFrame) || (v[0]+1 != v[1]) )
{
FBXSDK_printf("awCache int32 array read/write mismatch\n");
passTest = false;
break;
}
}
lCurrentTime2 += lTimeIncrement;
lCurrentFrame++;
}
{
}
if (passTest)
{
FBXSDK_printf("awCache int32 array read and write test passed\n");
}
}
void AnimateVertexCacheOnTriangleFloat(
FbxNode* pTriangle,
double pFrameRate)
{
bool lRet;
FbxTime lTimeIncrement, lCurrentTime, lStopTime;
lTimeIncrement.
SetTime(0, 0, 0, 1);
unsigned int lNormalChannelIndex;
if (gExportVertexCacheMCFormat)
{
if (lRet)
{
channelName += "_normals";
lRet = lCache->
AddChannel(channelName, FbxCache::eFloatVectorArray,
"normals", lNormalChannelIndex, &lStatus);
}
}
else
{
lRet = false;
}
if (!lRet)
{
return;
}
unsigned int lCurrentFrame = 0;
while (lCurrentTime <= lStopTime)
{
float lVertices[3][3];
lVertices[0][0] = -50.0f * lScaleFactor;
lVertices[0][1] = 0.0f;
lVertices[0][2] = 50.0f * lScaleFactor;
lVertices[1][0] = 50.0f * lScaleFactor;
lVertices[1][1] = 0.0f;
lVertices[1][2] = 50.0f * lScaleFactor;
lVertices[2][0] = 0.0f * lScaleFactor;
lVertices[2][1] = 50.0f * lScaleFactor;
lVertices[2][2] = -50.0f * lScaleFactor;
float lNormals[3][3];
for (int i = 0; i < 3; i++)
{
lNormals[i][0] = 0.0f;
lNormals[i][1] = 1.0f;
lNormals[i][2] = 0.0f;
}
if (gExportVertexCacheMCFormat)
{
lCache->
Write(lChannelIndex, lCurrentTime, &lVertices[0][0], 3);
lCache->
Write(lNormalChannelIndex, lCurrentTime, &lNormals[0][0], 3);
}
lCurrentTime += lTimeIncrement;
lCurrentFrame++;
}
{
}
if (gExportVertexCacheMCFormat)
{
}
if (!lRet)
{
return;
}
lCurrentFrame = 0;
#define AbsFlt(a) (((a) < 0) ? -(a) : (a))
#define CmpFlt(a,b) (AbsFlt((a)-(b)) > 1e-5)
FBXSDK_printf("Testing awCache Float3 array read and write\n");
bool passTest = true;
while (lCurrentTime2 <= lStopTime && passTest)
{
float lVertices[3][3];
float lNormals[3][3];
if (gExportVertexCacheMCFormat)
{
lCache->
Read(lChannelIndex, lCurrentTime2, &lVertices[0][0], 3);
lCache->
Read(lNormalChannelIndex, lCurrentTime2, &lNormals[0][0], 3);
if ((CmpFlt(lVertices[0][0], -50.0f * lScaleFactor) || CmpFlt(lVertices[0][1], 0.0f ) || CmpFlt(lVertices[0][2], 50.0f * lScaleFactor)) ||
(CmpFlt(lVertices[1][0], 50.0f * lScaleFactor) || CmpFlt(lVertices[1][1], 0.0f ) || CmpFlt(lVertices[1][2], 50.0f * lScaleFactor)) ||
(CmpFlt(lVertices[2][0], 0.0f * lScaleFactor) || CmpFlt(lVertices[2][1], 50.0f * lScaleFactor) || CmpFlt(lVertices[2][2],-50.0f * lScaleFactor)))
{
FBXSDK_printf("awCache Float3 vertex array read/write mismatch\n");
passTest = false;
break;
}
for (int i = 0; i < 3; i++)
{
if ((CmpFlt(lNormals[i][0], 0.0f) || CmpFlt(lNormals[i][1], 1.0f ) || CmpFlt(lNormals[i][2], 0.0f)))
{
FBXSDK_printf("awCache Float3 normal array read/write mismatch\n");
passTest = false;
break;
}
}
}
lCurrentTime2 += lTimeIncrement;
lCurrentFrame++;
}
#undef AbsFlt
#undef CmpFlt
{
}
if (passTest)
{
FBXSDK_printf("awCache float3 array read and write test passed\n");
}
}