#include "mbextension.h"
#include "IOPlugin/MyOwnWriter.h"
#include "IOPlugin/MyOwnReader.h"
#include "IOPlugin/MyOwnIOPlugin.h"
#include <fbxsdk/fbxsdk_nsbegin.h>
#define MY_CUSTOM_CLASS_NAME "MyCustomClass"
#define MY_CUSTOM_CLASS_TYPE "MyCustomType"
#define MY_CUSTOM_CLASS_SUBTYPE "MyCustomSubType"
static FbxManager* gFbxManager =
NULL;
class MyCustomObject : public FbxObject
{
FBXSDK_OBJECT_DECLARE( MyCustomObject, FbxObject );
protected:
};
FBXSDK_OBJECT_IMPLEMENT( MyCustomObject );
class MBCustomDataPlugin : public FbxPlugin
{
FBXSDK_PLUGIN_DECLARE( MBCustomDataPlugin );
protected:
explicit MBCustomDataPlugin( const FbxPluginDef& pDefinition, FbxModule pLibHandle ) : FbxPlugin( pDefinition, pLibHandle )
{
}
virtual bool SpecificInitialize()
{
gFbxManager = GetData().mSDKManager;
gFbxManager->RegisterFbxClass( MY_CUSTOM_CLASS_NAME, FBX_TYPE(MyCustomObject ), FBX_TYPE( FbxObject ), MY_CUSTOM_CLASS_TYPE, MY_CUSTOM_CLASS_SUBTYPE );
int FirstPluginID, RegistredCount;
gFbxManager->GetIOPluginRegistry()->RegisterReader(CreateMyOwnReader, GetMyOwnReaderInfo, FirstPluginID, RegistredCount, FillOwnReaderIOSettings, true );
gFbxManager->GetIOPluginRegistry()->RegisterWriter(CreateMyOwnWriter, GetMyOwnWriterInfo, FirstPluginID, RegistredCount, FillOwnWriterIOSettings, true );
return true;
}
virtual bool SpecificTerminate()
{
gFbxManager->UnregisterFbxClass( FBX_TYPE( MyCustomObject ) );
return true;
}
};
FBXSDK_PLUGIN_IMPLEMENT( MBCustomDataPlugin );
extern "C"
{
static MBCustomDataPlugin* sPlugin =
NULL;
EXPORT_DLL void FBXPluginRegistration( FbxPluginContainer& pContainer, FbxModule pLibHandle )
{
{
FbxPluginDef sPluginDef;
sPluginDef.mName = "MBCustomDataPlugin";
sPluginDef.mVersion = "1.0";
sPlugin = MBCustomDataPlugin::Create( sPluginDef, pLibHandle );
pContainer.Register( *sPlugin );
}
}
FBX_MB_EXTENSION_DECLARE();
}
bool MBExt_ExportHandled( FBComponent* pFBComponent )
{
if ( !pFBComponent->Is( FBCamera::TypeInfo ) && pFBComponent->Is( FBModelCube::TypeInfo ) )
{
if ( FBString( pFBComponent->Name ) == FBString( "MyCubeToNotExport" ) )
{
( ( FBModelCube* )pFBComponent )->Translation =
FBVector3d( 150.0, 100.0, 0.0 );
return true;
}
else if ( FBString( pFBComponent->Name ) == FBString( "MyCubeToNotImport" ) )
{
( ( FBModelCube* )pFBComponent )->Translation =
FBVector3d( -150.0, 100.0, 0.0 );
}
}
return false;
}
void MBExt_ExportBegin( FbxScene* pFbxScene )
{
FBModelCube* lMyCube1 = new FBModelCube("MyCubeToNotExport");
FBModelCube* lMyCube2 = new FBModelCube("MyCubeToNotImport");
FBModelCube* lMyCube3 = new FBModelCube("MyCubeToTestWith");
lMyCube1->Show = true;
lMyCube2->Show = true;
lMyCube3->Show = true;
lMyCube1->Translation =
FBVector3d(0.0, 100.0, 0.0);
lMyCube2->Translation =
FBVector3d(0.0, 100.0, 0.0);
lMyCube3->Translation =
FBVector3d(0.0, 100.0, 0.0);
}
bool MBExt_ExportProcess( FbxObject*& pOutputFbxObject, FBComponent* pInputObject, FbxScene* pFbxScene)
{
const char* lOutput = "NULL";
const char* lInput = "NULL";
if(pOutputFbxObject)
{
lOutput = pOutputFbxObject->GetName();
}
if(pInputObject)
{
lInput = pInputObject->GetFullName();
}
FBTrace(
"FBXExtension::MBExt_ExportProcess output = %s, input = %s\n", lOutput, lInput );
return false;
}
void MBExt_ExportTranslated(FbxObject* pFbxObject, FBComponent* pFBComponent)
{
FbxMesh* lFbxMesh =
NULL;
if ( !pFBComponent->Is( FBCamera::TypeInfo ) && pFBComponent->Is( FBModelCube::TypeInfo ) )
{
if ( FBString( pFBComponent->Name ) == FBString( "MyCubeToNotExport" ) )
{
}
else if ( FBString( pFBComponent->Name ) == FBString( "MyCubeToTestWith" ) )
{
lFBMesh = ( ( FBModelCube* )pFBComponent )->TessellatedMesh;
}
}
if ( pFbxObject->Is<FbxNode>() )
{
FbxNode* lFbxNode = FbxCast<FbxNode>( pFbxObject );
FbxNodeAttribute* lNodeAttribute = lFbxNode->GetNodeAttribute();
if ( lNodeAttribute->Is<FbxMesh>() )
{
if ( FbxString(lNodeAttribute->GetName() ) == FbxString( "MyCubeToNotExport" ) )
{
}
else if ( FbxString(lNodeAttribute->GetName() ) == FbxString( "MyCubeToTestWith" ) )
{
lFbxMesh = FbxCast<FbxMesh>( lNodeAttribute );
}
}
}
if ( lFBMesh && lFbxMesh )
{
if ( lFBMesh->PolygonCount() == lFbxMesh->GetPolygonCount() && lFBMesh->VertexCount() == lFbxMesh->GetPolygonVertexCount() )
{
}
}
}
void MBExt_ExportEnd( FbxScene* pFbxScene )
{
FbxClassId MyCustomDataClassId = gFbxManager->FindClass( MY_CUSTOM_CLASS_NAME );
if( !MyCustomDataClassId.IsValid() ) return;
for(
int i=0;
i<lCnt;
i++ )
{
if ( !lComp->Is( FBCamera::TypeInfo ) && lComp->Is( FBModelCube::TypeInfo ) )
{
if ( FBString( lComp->Name ) == FBString( "MyCubeToNotExport" ) )
{
MyCustomObject* MyCustomObjectInstance = MyCustomObject::Create( pFbxScene, "My Custom Object Instance" );
FBMesh* lFBMesh = ( ( FBModelCube* )lComp )->TessellatedMesh;
float Value = lFBMesh->VertexCount();
FbxString PropertyName = "MyCustomData";
FbxProperty NewProperty = FbxProperty::Create( MyCustomObjectInstance, FbxFloatDT, PropertyName.Buffer() );
if ( NewProperty.IsValid() ) NewProperty.Set( Value );
}
}
}
}
bool MBExt_ImportHandled( FbxObject* pFbxObject )
{
if ( pFbxObject->Is<FbxNode>() )
{
FbxNode* lFbxNode = FbxCast<FbxNode>( pFbxObject );
FbxNodeAttribute* lNodeAttribute = lFbxNode->GetNodeAttribute();
if ( lNodeAttribute->Is<FbxMesh>() )
{
if ( FbxString(lNodeAttribute->GetName() ) == FbxString( "MyCubeToNotImport" ) )
{
return true;
}
}
}
return false;
}
void MBExt_ImportBegin( FbxScene* pFbxScene )
{
FBTrace(
"%s\n",
"FBXExtension::MBExt_ImportBegin" );
}
bool MBExt_ImportProcess( FBComponent*& pOutputObject, FbxObject* pInputFbxObject, bool pIsAnInstance, bool pMerge)
{
const char* lOutput = "NULL";
const char* lInput = "NULL";
if(pOutputObject)
{
lOutput = pOutputObject->GetFullName();
}
if(pInputFbxObject)
{
lInput = pInputFbxObject->GetName();
}
FBTrace(
"FBXExtension::MBExt_ImportProcess output = %s, input = %s\n", lOutput, lInput );
return false;
}
void MBExt_ImportTranslated( FbxObject* pFbxObject, FBComponent* pFBComponent )
{
}
void MBExt_ImportEnd( FbxScene* pFbxScene )
{
bool Result = false;
FbxClassId MyCustomDataClassId = gFbxManager->FindClass( MY_CUSTOM_CLASS_NAME );
if ( !MyCustomDataClassId.IsValid() ) return;
int Iter, Count = pFbxScene->GetSrcObjectCount<MyCustomObject>( );
for ( Iter = 0; Iter < Count; ++Iter )
{
MyCustomObject* MyCustomObjectInstance = FbxCast<MyCustomObject>( pFbxScene->GetSrcObject<MyCustomObject>( 0 ) );
if ( MyCustomObjectInstance )
{
if ( MyCustomObjectInstance->FindProperty( "MyCustomData" ).IsValid() )
{
Result = true;
}
}
}
FBTrace(
"%s\n",
"FBXExtension::MBExt_ImportEnd" );
}
#include <fbxsdk/fbxsdk_nsend.h>