#include <fbxsdk.h>
#include "../Common/Common.h"
#include "../Common/GeometryUtility.h"
#define SAMPLE_FILENAME "ExportShader.fbx"
#define CGFX_SHADERFILE "xfSkyBox.cgfx"
#define HLSL_SHADERFILE "glass.fx"
#define TEXTURE_FILE "Default_reflection.dds"
bool CreateScene(FbxManager* pSdkManager, FbxScene* pScene);
FbxSurfaceMaterial* CreateCgfxShader(FbxScene* pScene);
FbxSurfaceMaterial* CreateHlslShader(FbxScene* pScene);
void CreateTableEntry(FbxBindingTable* pTable, FbxProperty& pProp);
int main(int argc, char** argv)
{
FbxManager* lSdkManager = NULL;
FbxScene* lScene = NULL;
bool lResult;
InitializeSdkObjects(lSdkManager, lScene);
lResult = CreateScene(lSdkManager, lScene);
if(lResult == false)
{
FBXSDK_printf("\n\nAn error occurred while creating the scene...\n");
DestroySdkObjects(lSdkManager, lResult);
return 0;
}
const char* lSampleFileName = NULL;
for( int i = 1; i < argc; ++i )
{
if( FBXSDK_stricmp(argv[i], "-test") == 0 ) continue;
else if( !lSampleFileName ) lSampleFileName = argv[i];
}
if( !lSampleFileName ) lSampleFileName = SAMPLE_FILENAME;
lResult = SaveScene(lSdkManager, lScene, lSampleFileName, -1, true);
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(FbxManager *pSdkManager, FbxScene* pScene)
{
FbxDocumentInfo* sceneInfo = FbxDocumentInfo::Create(pSdkManager,"SceneInfo");
sceneInfo->mTitle = "Example scene";
sceneInfo->mSubject = "Illustrates the creation of shader.";
sceneInfo->mAuthor = "ExportShader sample program.";
sceneInfo->mRevision = "rev. 1.0";
sceneInfo->mKeywords = "shader";
sceneInfo->mComment = "no particular comments required.";
pScene->SetSceneInfo(sceneInfo);
FbxDouble3 lCgfxTranslation(0, 0, 0);
FbxNode* lCgfxNode = CreateCube(pScene, "CgfxCube", lCgfxTranslation);
FbxSurfaceMaterial* lCgfxMat = CreateCgfxShader(pScene);
lCgfxNode->AddMaterial(lCgfxMat);
FbxDouble3 lHlslTranslation(20, 0, 0);
FbxNode* lHlslNode = CreateCube(pScene, "HlslCube", lHlslTranslation);
FbxSurfaceMaterial* lHlslMat = CreateHlslShader(pScene);
lHlslNode->AddMaterial(lHlslMat);
FbxNode* lRootNode = pScene->GetRootNode();
lRootNode->AddChild(lCgfxNode);
lRootNode->AddChild(lHlslNode);
return true;
}
FbxSurfaceMaterial* CreateCgfxShader(FbxScene* pScene)
{
FbxSurfaceMaterial* lCgfxMat = FbxSurfaceMaterial::Create(pScene, "CgfxShader" );
FbxImplementation* lImpl = FbxImplementation::Create(pScene, FbxString("Cgfx_Implementation"));
lCgfxMat->AddImplementation( lImpl );
lCgfxMat->SetDefaultImplementation( lImpl );
lImpl->RenderAPI = FBXSDK_RENDERING_API_OPENGL;
lImpl->RenderAPIVersion = "1.5";
lImpl->Language = FBXSDK_SHADING_LANGUAGE_CGFX;
lImpl->LanguageVersion = "1.5";
FbxBindingTable* lTable = lTable = lImpl->AddNewTable("root", "shader");
lImpl->RootBindingName = "root";
lTable->DescAbsoluteURL = CGFX_SHADERFILE;
lTable->DescTAG = "user";
FbxProperty lRootProp = FbxProperty::Create( lCgfxMat, FbxCompoundDT, "ShaderExample");
FbxProperty lProp = FbxProperty::Create( lRootProp, FbxDouble3DT, "SurfColor" );
FbxDouble3 lSurfVal(0, 1, 0);
lProp.Set(lSurfVal);
CreateTableEntry(lTable, lProp);
lProp = FbxProperty::Create(lRootProp, FbxFloatDT, "MasterAlpha");
lProp.Set(0.35);
CreateTableEntry(lTable, lProp);
lProp = FbxProperty::Create(lRootProp, FbxDouble3DT, "EnvSampler", "EnvSampler");
FbxDouble3 lSampleVal(0, 0, 0);
lProp.Set(lSampleVal);
CreateTableEntry(lTable, lProp);
FbxFileTexture* lTexture = FbxFileTexture::Create(pScene, "EnvSamplerTex");
lTexture->SetFileName(TEXTURE_FILE);
lTexture->SetTextureUse(FbxTexture::eStandard);
lTexture->SetMappingType(FbxTexture::eUV);
lTexture->ConnectDstProperty(lProp);
return lCgfxMat;
}
FbxSurfaceMaterial* CreateHlslShader(FbxScene* pScene)
{
FbxSurfaceMaterial* lHlslMat = FbxSurfaceMaterial::Create(pScene, "HlslShader" );
FbxImplementation* lImpl = FbxImplementation::Create(pScene, FbxString("Hlsl_Implementation"));
lHlslMat->AddImplementation( lImpl );
lHlslMat->SetDefaultImplementation( lImpl );
lImpl->RenderAPI = FBXSDK_RENDERING_API_DIRECTX;
lImpl->RenderAPIVersion = "9.0";
lImpl->Language = FBXSDK_SHADING_LANGUAGE_HLSL;
lImpl->LanguageVersion = "1.0";
FbxBindingTable* lTable = lTable = lImpl->AddNewTable("root", "shader");
lImpl->RootBindingName = "root";
lTable->DescAbsoluteURL = HLSL_SHADERFILE;
lTable->DescTAG = "dx9";
FbxProperty lProp = FbxProperty::Create(lHlslMat, FbxFloatDT, "Script", "Script");
lProp.ModifyFlag(FbxPropertyAttr::eUserDefined, true);
lProp.Set(0.8);
CreateTableEntry(lTable, lProp);
lProp = FbxProperty::Create(lHlslMat, FbxFloatDT, "reflectStrength", "reflectStrength");
lProp.ModifyFlag(FbxPropertyAttr::eUserDefined, true);
lProp.Set(0.35);
CreateTableEntry(lTable, lProp);
lProp = FbxProperty::Create(lHlslMat, FbxFloatDT, "refractStrength", "refractStrength");
lProp.ModifyFlag(FbxPropertyAttr::eUserDefined, true);
lProp.Set(0.75);
CreateTableEntry(lTable, lProp);
lProp = FbxProperty::Create(lHlslMat, FbxDouble3DT, "etas", "etas");
lProp.ModifyFlag(FbxPropertyAttr::eUserDefined, true);
FbxDouble3 lEtasVal(0.8, 0.6, 0.4);
lProp.Set(lEtasVal);
CreateTableEntry(lTable, lProp);
lProp = FbxProperty::Create(lHlslMat, FbxDouble3DT, "fresnelTex", "fresnelTex");
lProp.ModifyFlag(FbxPropertyAttr::eUserDefined, true);
FbxDouble3 lTexVal(0, 0, 0);
lProp.Set(lTexVal);
CreateTableEntry(lTable, lProp);
lProp = FbxProperty::Create(lHlslMat, FbxDouble3DT, "cubeMap", "cubeMap");
lProp.ModifyFlag(FbxPropertyAttr::eUserDefined, true);
FbxDouble3 lMapVal(0, 1, 0);
lProp.Set(lMapVal);
CreateTableEntry(lTable, lProp);
FbxFileTexture* lTexture = FbxFileTexture::Create(pScene, "cubeMapTex");
lTexture->SetFileName(TEXTURE_FILE);
lTexture->SetTextureUse(FbxTexture::eStandard);
lTexture->SetMappingType(FbxTexture::eUV);
lTexture->ConnectDstProperty(lProp);
return lHlslMat;
}
void CreateTableEntry(FbxBindingTable* pTable, FbxProperty& pProp)
{
FbxBindingTableEntry& lEntry = pTable->AddNewEntry();
FbxPropertyEntryView lSrc( &lEntry, true, true );
lSrc.SetProperty( pProp.GetHierarchicalName());
FbxSemanticEntryView lDst( &lEntry, false, true );
lDst.SetSemantic( pProp.GetName() );
}