Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk® FBX® / FBX SDK / FBX exporter with CGFX
  RSS 2.0 ATOM  

FBX exporter with CGFX
Rate this thread
 
50839
 
Permlink of this thread  
avatar
  • erdooom
  • Posted: 29 December 2010 07:42 PM
  • Total Posts: 17
  • Joined: 17 August 2010 08:33 AM

I am trying to figure out how to write an exporter that exports properties and attributes of a cgfx shader (including textures). Is there any code sample one can look at ? the only thing in the sdk is a import sample. there it seems that one needs both a binding with entries for each field and a property (which i assume is connected to the material) still there is very very little documentation on this subject, seems there are a few types of properties and so forth, so any help will be very welcome.

Thanks,



Replies: 0
avatar
  • nian.wu
  • Posted: 30 January 2011 04:41 PM

Following code is a sample to export a Cgfx material, hope it helpful to you:

KFbxSurfaceMaterialCreateCgfxShader(KFbxScenepScene)
{
    KFbxSurfaceMaterial
lCgfxMat KFbxSurfaceMaterial::Create(pScene"CgfxShader" );

    
KFbxImplementationlImpl KFbxImplementation::Create(pSceneKString("Cgfx_Implementation"));

    
lCgfxMat->AddImplementationlImpl );
    
lCgfxMat->SetDefaultImplementationlImpl );
    
lImpl->RenderAPI sOpenGL;
    
lImpl->RenderAPIVersion "1.5"

    
lImpl->Language sCGFX;
    
lImpl->LanguageVersion "1.5";

    
KFbxBindingTablelTable 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(lCgfxMatDTVector3D"SurfColor""SurfColor");

    
lProp.ModifyFlag(KFbxProperty::eUSERtrue);
    
fbxDouble3 lSurfVal(010);
    
lProp.Set(lSurfVal);
    
CreateTableEntry(lTablelProp); // for every property, create a table entry in binding table
        
    // Property MasterAlpha
    
lProp KFbxProperty::Create(lCgfxMatDTFloat"MasterAlpha""MasterAlpha");

    
lProp.ModifyFlag(KFbxProperty::eUSERtrue);
    
lProp.Set(0.35);
    
CreateTableEntry(lTablelProp);

    
// Property EnvSample, the property type is sample, so connect a texture to it
    
lProp KFbxProperty::Create(lCgfxMatDTVector3D"EnvSampler""EnvSampler");

    
lProp.ModifyFlag(KFbxProperty::eUSERtrue);
    
fbxDouble3 lSampleVal(000);
    
lProp.Set(lSampleVal);
    
CreateTableEntry(lTablelProp);

    
KFbxFileTexturelTexture KFbxFileTexture::Create(pScene"EnvSamplerTex");
    
lTexture->SetFileName(TEXTURE_FILE);
    
lTexture->SetTextureUse(KFbxTexture::eSTANDARD);
    
lTexture->SetMappingType(KFbxTexture::eUV);

    
lTexture->ConnectDstProperty(lProp);

    return 
lCgfxMat;
}


void CreateTableEntry
(KFbxBindingTablepTableKFbxPropertypProp)
{
    
// create entry
    
KFbxBindingTableEntrylEntry pTable->AddNewEntry();
    
// set src to the fbx property, in this sample, fbx properties have the same name with shader parameters
    
KFbxPropertyEntryView lSrc( &lEntrytruetrue );
    
lSrc.SetPropertypProp.GetName());

    
// set dst to the shader parameter
    
KFbxSemanticEntryView lDst( &lEntryfalsetrue );
    
lDst.SetSemanticpProp.GetName() );
}


Nian Wu
AutoDesk FBX Team

Replies: 2
/img/forum/dark/default_avatar.png

Great thanks ! ill let you know if it works for me.

Author: erdooom

Replied: 30 January 2011 05:35 PM  
/img/forum/dark/default_avatar.png

Dear Mr. Nian Wu

There is no documentation of “KFbxFileTexture”
appears in your sample code and it does not appear anywhere in the SDK.
Where do I find it?

Thanks,
Yoav.

Author: Yoaviv

Replied: 31 January 2011 12:23 AM  
avatar

Does KFbxTexture work?



Replies: 1
/img/forum/dark/default_avatar.png

Tried that instead of KfbxFileTexture but it does not work:

Code does compile, texture file name is exprted to FBX file.
But when I open the FBX in maya I can see the default image file which
is in the cgfx shader. I want the image which I set in
“SetFileName” in the example code to appear and not the default image file
in the shader.

So how I do that?

Author: Yoaviv

Replied: 01 February 2011 01:33 AM  
avatar
  • nian.wu
  • Posted: 09 February 2011 02:25 PM

Sorry, I wrote the sample against our latest code.
I rewrote it based on FBX2011.3.1. The sample is attached and you can compile it directly.

I ran the sample and import the FBX file to Maya2010. The image is correct as I set in code. Please try the new sample again.



Nian Wu
AutoDesk FBX Team

Attachment Attachment
Replies: 1
/img/forum/dark/default_avatar.png

Thats great ! thanks :) yes we were scratching our heads for a while there trying to figure out how to make this code work.

Author: erdooom

Replied: 09 February 2011 05:55 PM