|
Following code is a sample to export a Cgfx material, hope it helpful to you:
KFbxSurfaceMaterial* CreateCgfxShader(KFbxScene* pScene) {
KFbxSurfaceMaterial* lCgfxMat = KFbxSurfaceMaterial::Create(pScene, "CgfxShader" );
KFbxImplementation* lImpl = KFbxImplementation::Create(pScene, KString("Cgfx_Implementation"));
lCgfxMat->AddImplementation( lImpl );
lCgfxMat->SetDefaultImplementation( lImpl );
lImpl->RenderAPI = sOpenGL;
lImpl->RenderAPIVersion = "1.5";
lImpl->Language = sCGFX;
lImpl->LanguageVersion = "1.5";
KFbxBindingTable* lTable = lTable = lImpl->AddNewTable("root", "shader");
lImpl->RootBindingName = "root";
// shader file
lTable->DescAbsoluteURL = CGFX_SHADERFILE;
// technique name
lTable->DescTAG = "user";
// Export properties in shader file
// Property "SurfColor"
KFbxProperty lProp = KFbxProperty::Create(lCgfxMat, DTVector3D, "SurfColor", "SurfColor");
lProp.ModifyFlag(KFbxProperty::eUSER, true);
fbxDouble3 lSurfVal(0, 1, 0);
lProp.Set(lSurfVal);
CreateTableEntry(lTable, lProp); // for every property, create a table entry in binding table
// Property MasterAlpha
lProp = KFbxProperty::Create(lCgfxMat, DTFloat, "MasterAlpha", "MasterAlpha");
lProp.ModifyFlag(KFbxProperty::eUSER, true);
lProp.Set(0.35);
CreateTableEntry(lTable, lProp);
// Property EnvSample, the property type is sample, so connect a texture to it
lProp = KFbxProperty::Create(lCgfxMat, DTVector3D, "EnvSampler", "EnvSampler");
lProp.ModifyFlag(KFbxProperty::eUSER, true);
fbxDouble3 lSampleVal(0, 0, 0);
lProp.Set(lSampleVal);
CreateTableEntry(lTable, lProp);
KFbxFileTexture* lTexture = KFbxFileTexture::Create(pScene, "EnvSamplerTex");
lTexture->SetFileName(TEXTURE_FILE);
lTexture->SetTextureUse(KFbxTexture::eSTANDARD);
lTexture->SetMappingType(KFbxTexture::eUV);
lTexture->ConnectDstProperty(lProp);
return lCgfxMat; }
void CreateTableEntry(KFbxBindingTable* pTable, KFbxProperty& pProp) {
// create entry
KFbxBindingTableEntry& lEntry = pTable->AddNewEntry();
// set src to the fbx property, in this sample, fbx properties have the same name with shader parameters
KFbxPropertyEntryView lSrc( &lEntry, true, true );
lSrc.SetProperty( pProp.GetName());
// set dst to the shader parameter
KFbxSemanticEntryView lDst( &lEntry, false, true );
lDst.SetSemantic( pProp.GetName() ); }
Nian Wu
AutoDesk FBX Team
|