#include "ortoolbatch_tool.h"
#define ORTOOLBATCH__CLASS ORTOOLBATCH__CLASSNAME
#define ORTOOLBATCH__LABEL "OR Batch"
#define ORTOOLBATCH__DESC "OR - Batch Tool Description"
ORTOOLBATCH__LABEL,
ORTOOLBATCH__DESC,
#define MAX_FBMODEL_COUNT 100
static const char* gBatchStatusText[] =
{
"Success",
"Error",
"Character is not specified",
"Character is not characterized",
"Character has no reference",
"Input actor is not specified",
"Actor input markerset is not specified",
"Actor input markerset has no reference model",
"Actor input markerset is not correctly associated with models",
"Input character is not characterized",
"Input character has no reference",
"Input directory is not valid",
"ASF skeleton file not specified",
"Can't open ASF skeleton file",
"Output directory is not valid",
};
bool FileExist( const char* pFileName )
{
bool lReturn = false;
FILE* lFile = fopen( pFileName,
"r" );
{
lReturn = true;
fclose(lFile);
}
return lReturn;
}
bool ORToolBatch::FBCreate()
{
StartSize[0] = 480;
StartSize[1] = 430;
UICreate ();
UIConfigure ();
UIReset ();
OnShow.Add(
this, (
FBCallback) &ORToolBatch::EventToolShow );
OnIdle.Add(
this, (
FBCallback) &ORToolBatch::EventToolIdle );
return true;
}
void ORToolBatch::FBDestroy()
{
}
void ORToolBatch::UICreate()
{
int lSpace = 4;
int lButtonW = 100;
int lButtonH = 18;
int lEditW = 375;
int lEditH = 18;
int lBrowseW = 20;
int lBrowseH = 20;
AddRegion( "LabelDescription", "LabelDescription",
AddRegion( "LabelCharacter", "LabelCharacter",
AddRegion( "EditCharacterPath", "EditCharacterPath",
AddRegion( "ButtonBrowseCharacter", "ButtonBrowseCharacter",
AddRegion( "ButtonLoadCharacter", "ButtonLoadCharacter",
AddRegion( "LabelInputDir", "LabelInputDir",
AddRegion( "EditInputDir", "EditInputDir",
AddRegion( "ButtonBrowseInputDir", "ButtonBrowseInputDir",
AddRegion( "LabelOutputDir", "LabelOutputDir",
AddRegion( "EditOutputDir", "EditOutputDir",
AddRegion( "ButtonBrowseOutputDir", "ButtonBrowseOutputDir",
AddRegion( "LabelStart", "LabelStart",
AddRegion( "ButtonStart", "ButtonStart",
SetControl( "LabelDescription", mLabelDescription );
SetControl( "LabelCharacter", mLabelCharacter );
SetControl( "EditCharacterPath", mEditCharacterPath );
SetControl( "ButtonBrowseCharacter", mButtonBrowseCharacter );
SetControl( "ButtonLoadCharacter", mButtonLoadCharacter );
SetControl( "LabelInputDir", mLabelInputDir );
SetControl( "EditInputDir", mEditInputDir );
SetControl( "ButtonBrowseInputDir", mButtonBrowseInputDir );
SetControl( "LabelOutputDir", mLabelOutputDir );
SetControl( "EditOutputDir", mEditOutputDir );
SetControl( "ButtonBrowseOutputDir", mButtonBrowseOutputDir );
SetControl( "LabelStart", mLabelStart );
SetControl( "ButtonStart", mButtonStart );
}
void ORToolBatch::UIConfigure()
{
FBSystem lSystem;
FBString lBinPath( lSystem.ApplicationPath );
mLabelDescription.Caption = "This SDK sample will show you how to use the Character Batch API.\n"
"This API can be used to batch load, batch plot and batch save a character\n"
"in all the file formats supported by MotionBuilder.\n"
"\n"
"In this sample, we will batch load a list of Vicon C3D motion files, plot\n"
"them on the character and finally save the result in individual FBX files.\n";
mLabelCharacter.Caption = "Step 1.\n"
"Load the file containing your actor and your character.";
mEditCharacterPath.Text = lBinPath + "\\..\\..\\OpenRealitySDK\\Samples\\tools\\toolbatch\\res\\Batch.fbx";
mButtonBrowseCharacter.Caption = "...";
mButtonLoadCharacter.Caption = "Load";
mLabelInputDir.Caption = "Step 2.\n"
"Select the folder containing the motion files you want to plot\n"
"on your character. In our case they must be in C3D format.";
mEditInputDir.Text = lBinPath + "\\..\\..\\OpenRealitySDK\\Samples\\tools\\toolbatch\\res\\motion\\";
mButtonBrowseInputDir.Caption = "...";
mLabelOutputDir.Caption = "Step 3.\n"
"Select the folder where you want the files to be saved.\n"
"There will be one file per take.";
mEditOutputDir.Text = lBinPath + "\\..\\..\\OpenRealitySDK\\Samples\\tools\\toolbatch\\res\\result\\";
mButtonBrowseOutputDir.Caption = "...";
mLabelStart.Caption = "Step 4.\n"
"Click on the button to start the batch process.";
mButtonStart.Caption = "Start";
mButtonBrowseCharacter.OnClick.Add (
this, (
FBCallback) &ORToolBatch::EventButtonBrowseCharacterClick );
mButtonLoadCharacter.OnClick.Add (
this, (
FBCallback) &ORToolBatch::EventButtonLoadCharacterClick );
mButtonBrowseInputDir.OnClick.Add (
this, (
FBCallback) &ORToolBatch::EventButtonBrowseInputDirClick );
mButtonBrowseOutputDir.OnClick.Add (
this, (
FBCallback) &ORToolBatch::EventButtonBrowseOutputDirClick );
mButtonStart.OnClick.Add (
this, (
FBCallback) &ORToolBatch::EventButtonStartClick );
}
void ORToolBatch::UIReset()
{
}
void ORToolBatch::UIRefresh()
{
}
void ORToolBatch::EventButtonBrowseCharacterClick(
HISender pSender,
HKEvent pEvent )
{
FBFilePopup lFilePopup;
lFilePopup.Caption = "Open";
lFilePopup.Filter = "*.fbx";
lFilePopup.Path = (const char*)mEditCharacterPath.Text;
lFilePopup.Execute();
mEditCharacterPath.Text = (const char*)lFilePopup.FullFilename;
}
void ORToolBatch::EventButtonLoadCharacterClick(
HISender pSender,
HKEvent pEvent )
{
if( FileExist( mEditCharacterPath.Text ) == true )
{
mApplication.FileOpen( mEditCharacterPath.Text );
}
}
void ORToolBatch::EventButtonBrowseInputDirClick(
HISender pSender,
HKEvent pEvent )
{
FBFolderPopup lFolderPopup;
lFolderPopup.Path = (const char*)mEditInputDir.Text;
lFolderPopup.Execute();
mEditInputDir.Text = (const char*)lFolderPopup.Path;
}
void ORToolBatch::EventButtonBrowseOutputDirClick(
HISender pSender,
HKEvent pEvent )
{
FBFolderPopup lFolderPopup;
lFolderPopup.Path = (const char*)mEditOutputDir.Text;
lFolderPopup.Execute();
mEditOutputDir.Text = (const char*)lFolderPopup.Path;
}
void ORToolBatch::EventButtonStartClick(
HISender pSender,
HKEvent pEvent )
{
FBScene* lScene = mSystem.Scene;
FBPropertyListCharacter& lCharacterList = lScene->Characters;
if( lCharacterList.GetCount() <= 0 )
{
}
else
{
FBPlotOptions lPlotOptions;
lPlotOptions.mPlotAllTakes = false;
lPlotOptions.mPlotOnFrame = true;
lPlotOptions.mPlotPeriod.SetSecondDouble ( 1.0 / 30.0 );
lPlotOptions.mUseConstantKeyReducer = false;
lPlotOptions.mPlotTranslationOnRootOnly = false;
lPlotOptions.mPreciseTimeDiscontinuities = false;
FBBatchOptions lBatchOptions;
lBatchOptions.mInputDirectory = mEditInputDir.Text;
lBatchOptions.mOutputDirectory = mEditOutputDir.Text;
lBatchOptions.mSkeletonFile = "";
lBatchOptions.mCharacter = lCharacterList[0];
lBatchOptions.mStartAnimationAtZero = true;
lBatchOptions.mFrameAnimation = true;
lBatchOptions.mOverwriteScaling = false;
lBatchOptions.mKeepDummyBones = false;
lBatchOptions.mWriteRate = false;
lBatchOptions.mWriteTranslation = false;
lBatchOptions.mPlotToCharacter = false;
lBatchOptions.mPlotToControlSet = false;
lBatchOptions.mUseSingleTake = false;
lBatchOptions.mUseBatchSuffix = false;
lBatchOptions.mKeepCharacterConstraint = true;
lStatus = mApplication.FileBatch( &lBatchOptions, &lPlotOptions );
}
}
{
FBEventShow lEvent( pEvent );
if( lEvent.Shown )
{
UIReset();
}
else
{
}
}
{
UIRefresh();
}