#include "mbextension.h"
#include "../../miscellaneous/material_template/ormaterial_template_material.h"
#include <fbxsdk/fbxsdk_nsbegin.h>
static FbxManager* gFbxManager =
NULL;
static bool gProcessedOnce = false;
#define MY_CUSTOM_SURFACE_CLASS_NAME "MyCustomSurfaceClass"
#define MY_CUSTOM_SURFACE_CLASS_SUBTYPE "MyCustomSurfaceClass" // need to match the SURFACE_CLASS_NAME so the class can be recognized
class MyCustomSurface : public FbxSurfaceMaterial
{
FBXSDK_OBJECT_DECLARE(MyCustomSurface, FbxSurfaceMaterial);
protected:
void ConstructProperties(bool pForceSet)
{
ParentClass::ConstructProperties(pForceSet);
Diffuse.StaticInit(this, "Diffuse", FbxColor3DT, FbxDouble3(0,0,0), pForceSet);
}
public:
FbxPropertyT<FbxDouble3> Diffuse;
};
FBXSDK_OBJECT_IMPLEMENT(MyCustomSurface);
class MBCustomSurfacePlugin : public FbxPlugin
{
FBXSDK_PLUGIN_DECLARE(MBCustomSurfacePlugin);
protected:
explicit MBCustomSurfacePlugin(const FbxPluginDef& pDefinition, FbxModule pFbxModule) : FbxPlugin(pDefinition, pFbxModule)
{
}
virtual bool SpecificInitialize()
{
gFbxManager = GetData().mSDKManager;
gFbxManager->RegisterFbxClass(MY_CUSTOM_SURFACE_CLASS_NAME, FBX_TYPE(MyCustomSurface),FBX_TYPE(FbxSurfaceMaterial), FIELD_OBJECT_DEFINITION_OBJECT_TYPE_MATERIAL, MY_CUSTOM_SURFACE_CLASS_SUBTYPE);
return true;
}
virtual bool SpecificTerminate()
{
gFbxManager->UnregisterFbxClass(FBX_TYPE(MyCustomSurface));
return true;
}
};
FBXSDK_PLUGIN_IMPLEMENT(MBCustomSurfacePlugin);
extern "C"
{
static MBCustomSurfacePlugin* sPlugin =
NULL;
EXPORT_DLL void FBXPluginRegistration(FbxPluginContainer& pContainer, FbxModule pFbxModule)
{
{
FbxPluginDef sPluginDef;
sPluginDef.mName = "MBCustomSurfacePlugin";
sPluginDef.mVersion = "1.0";
sPlugin = MBCustomSurfacePlugin::Create(sPluginDef, pFbxModule);
pContainer.Register(*sPlugin);
}
}
FBX_MB_EXTENSION_DECLARE();
}
bool MBExt_ExportHandled( FBComponent* pFBComponent )
{
return false;
}
void MBExt_ExportBegin(FbxScene* pFbxScene)
{
}
void MBExt_ExportTranslated(FbxObject* pFbxObject, FBComponent* pFBComponent)
{
}
bool MBExt_ExportProcess( FbxObject*& pOutputFbxObject, FBComponent* pInputObject, FbxScene* pFbxScene)
{
if (pOutputFbxObject ==
NULL || pInputObject ==
NULL || pFbxScene ==
NULL)
return false;
if (FBString(pInputObject->ClassName())==ORMATERIALCUSTOM__CLASSSTR)
{
static FbxClassId MyCustomSurfaceDataClassId = gFbxManager->FindClass(MY_CUSTOM_SURFACE_CLASS_NAME);
if( !MyCustomSurfaceDataClassId.IsValid() ) return false;
MyCustomSurface* MyCustomSurfaceInstance = MyCustomSurface::Create(pFbxScene, pInputObject->Name);
MyCustomSurfaceInstance->Diffuse.Set(FbxDouble3(1, 1, 1));
if(pOutputFbxObject) pOutputFbxObject->Destroy();
pOutputFbxObject = FbxCast<FbxObject>(MyCustomSurfaceInstance);;
}
return false;
}
void MBExt_ExportEnd(FbxScene* pFbxScene)
{
}
bool MBExt_ImportHandled( FbxObject* pFbxObject )
{
return false;
}
void MBExt_ImportBegin(FbxScene* pFbxScene)
{
}
bool MBExt_ImportProcess( FBComponent*& pOutputObject, FbxObject* pInputFbxObject, bool pIsAnInstance, bool pMerge)
{
if (pInputFbxObject ==
NULL)
return false;
if (pIsAnInstance)
{
if (gProcessedOnce)
return true;
else
gProcessedOnce = true;
}
FbxSurfaceMaterial* lSurfaceMat = FbxCast<FbxSurfaceMaterial>(pInputFbxObject);
return false;
if (!lSurfaceMat->Is<MyCustomSurface>())
return false;
MyCustomSurface* lCustSurface = (MyCustomSurface*)lSurfaceMat;
FbxDouble3 lFbxColor = lCustSurface->Diffuse.Get();
ORMaterialCustom* lTempMaterial;
if (pMerge)
{
if (pOutputObject ==
NULL)
{
return false;
}
lTempMaterial = (FBString(pOutputObject->ClassName())==ORMATERIALCUSTOM__CLASSSTR) ? (ORMaterialCustom*)(pOutputObject) :
NULL;
}
else
{
pOutputObject->FBDelete();
lTempMaterial = (ORMaterialCustom*)
FBCreateObject(
"Browsing/Templates/Shading Elements",ORMATERIALCUSTOM__CLASSSTR,lSurfaceMat->GetName());
pOutputObject = lTempMaterial;
}
if(lTempMaterial)
{
lTempMaterial->Diffuse.SetData(&lFbxColor);
}
return false;
}
void MBExt_ImportTranslated( FbxObject* pFbxObject, FBComponent* pFBComponent )
{
}
void MBExt_ImportEnd(FbxScene* pFbxScene)
{
}
#include <fbxsdk/fbxsdk_nsend.h>