tools/toolbatch/ortoolbatch_tool.cxx

tools/toolbatch/ortoolbatch_tool.cxx
/***************************************************************************************
Autodesk(R) Open Reality(R) Samples
(C) 2009 Autodesk, Inc. and/or its licensors
All rights reserved.
AUTODESK SOFTWARE LICENSE AGREEMENT
Autodesk, Inc. licenses this Software to you only upon the condition that
you accept all of the terms contained in the Software License Agreement ("Agreement")
that is embedded in or that is delivered with this Software. By selecting
the "I ACCEPT" button at the end of the Agreement or by copying, installing,
uploading, accessing or using all or any portion of the Software you agree
to enter into the Agreement. A contract is then formed between Autodesk and
either you personally, if you acquire the Software for yourself, or the company
or other legal entity for which you are acquiring the software.
AUTODESK, INC., MAKES NO WARRANTY, EITHER EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
PURPOSE REGARDING THESE MATERIALS, AND MAKES SUCH MATERIALS AVAILABLE SOLELY ON AN
"AS-IS" BASIS.
IN NO EVENT SHALL AUTODESK, INC., BE LIABLE TO ANYONE FOR SPECIAL, COLLATERAL,
INCIDENTAL, OR CONSEQUENTIAL DAMAGES IN CONNECTION WITH OR ARISING OUT OF PURCHASE
OR USE OF THESE MATERIALS. THE SOLE AND EXCLUSIVE LIABILITY TO AUTODESK, INC.,
REGARDLESS OF THE FORM OF ACTION, SHALL NOT EXCEED THE PURCHASE PRICE OF THE
MATERIALS DESCRIBED HEREIN.
Autodesk, Inc., reserves the right to revise and improve its products as it sees fit.
Autodesk and Open Reality are registered trademarks or trademarks of Autodesk, Inc.,
in the U.S.A. and/or other countries. All other brand names, product names, or
trademarks belong to their respective holders.
GOVERNMENT USE
Use, duplication, or disclosure by the U.S. Government is subject to restrictions as
set forth in FAR 12.212 (Commercial Computer Software-Restricted Rights) and
DFAR 227.7202 (Rights in Technical Data and Computer Software), as applicable.
Manufacturer is Autodesk, Inc., 10 Duke Street, Montreal, Quebec, Canada, H3C 2L7.
***************************************************************************************/
// Class declaration
#include "ortoolbatch_tool.h"
//--- Registration defines
#define ORTOOLBATCH__CLASS ORTOOLBATCH__CLASSNAME
#define ORTOOLBATCH__LABEL "OR Batch"
#define ORTOOLBATCH__DESC "OR - Batch Tool Description"
//--- FiLMBOX Registration & Implementation.
FBToolImplementation( ORTOOLBATCH__CLASS );
FBRegisterTool ( ORTOOLBATCH__CLASS,
ORTOOLBATCH__LABEL,
ORTOOLBATCH__DESC,
FB_DEFAULT_SDK_ICON ); // Icon filename (default=Open Reality icon)
//--- The maximum number of FBModel we want in our list
#define MAX_FBMODEL_COUNT 100
//--- Strings associated with each status value returned by the batch process
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",
};
/************************************************
* Utility function to verify if a file exists
************************************************/
bool FileExist( const char* pFileName )
{
bool lReturn = false;
FILE* lFile = fopen( pFileName, "r" );
if( lFile != NULL )
{
lReturn = true;
fclose(lFile);
}
return lReturn;
}
/************************************************
* FiLMBOX Constructor.
************************************************/
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;
}
/************************************************
* FiLMBOX Destructor.
************************************************/
void ORToolBatch::FBDestroy()
{
}
/************************************************
* Create the UI.
************************************************/
void ORToolBatch::UICreate()
{
int lSpace = 4;
int lButtonW = 100;
int lButtonH = 18;
int lEditW = 375;
int lEditH = 18;
int lBrowseW = 20;
int lBrowseH = 20;
//
// Create regions
//
// Description
AddRegion( "LabelDescription", "LabelDescription",
lSpace, kFBAttachLeft, "", 1.0,
lSpace, kFBAttachTop, "", 1.0,
-lSpace, kFBAttachRight, "", 1.0,
85, kFBAttachNone, NULL, 1.0 );
// Load Character
AddRegion( "LabelCharacter", "LabelCharacter",
lSpace, kFBAttachLeft, "", 1.0,
lSpace * 4, kFBAttachBottom, "LabelDescription", 1.0,
-lSpace, kFBAttachRight, "", 1.0,
25, kFBAttachNone, NULL, 1.0 );
AddRegion( "EditCharacterPath", "EditCharacterPath",
lSpace, kFBAttachLeft, "", 1.0,
lSpace, kFBAttachBottom, "LabelCharacter", 1.0,
lEditW, kFBAttachNone, NULL, 1.0,
lEditH, kFBAttachNone, NULL, 1.0 );
AddRegion( "ButtonBrowseCharacter", "ButtonBrowseCharacter",
lSpace, kFBAttachRight, "EditCharacterPath", 1.0,
lSpace, kFBAttachBottom, "LabelCharacter", 1.0,
lBrowseW, kFBAttachNone, NULL, 1.0,
lBrowseH, kFBAttachNone, NULL, 1.0 );
AddRegion( "ButtonLoadCharacter", "ButtonLoadCharacter",
lSpace, kFBAttachLeft, "", 1.0,
lSpace * 2, kFBAttachBottom, "EditCharacterPath", 1.0,
lButtonW, kFBAttachNone, NULL, 1.0,
lButtonH, kFBAttachNone, NULL, 1.0 );
// Input dir
AddRegion( "LabelInputDir", "LabelInputDir",
lSpace, kFBAttachLeft, "", 1.0,
lSpace * 4, kFBAttachBottom, "ButtonLoadCharacter", 1.0,
-lSpace, kFBAttachRight, "", 1.0,
40, kFBAttachNone, NULL, 1.0 );
AddRegion( "EditInputDir", "EditInputDir",
lSpace, kFBAttachLeft, "", 1.0,
lSpace, kFBAttachBottom, "LabelInputDir", 1.0,
lEditW, kFBAttachNone, NULL, 1.0,
lEditH, kFBAttachNone, NULL, 1.0 );
AddRegion( "ButtonBrowseInputDir", "ButtonBrowseInputDir",
lSpace, kFBAttachRight, "EditInputDir", 1.0,
lSpace, kFBAttachBottom, "LabelInputDir", 1.0,
lBrowseW, kFBAttachNone, NULL, 1.0,
lBrowseH, kFBAttachNone, NULL, 1.0 );
// Output dir
AddRegion( "LabelOutputDir", "LabelOutputDir",
lSpace, kFBAttachLeft, "", 1.0,
lSpace * 4, kFBAttachBottom, "EditInputDir", 1.0,
-lSpace, kFBAttachRight, "", 1.0,
40, kFBAttachNone, NULL, 1.0 );
AddRegion( "EditOutputDir", "EditOutputDir",
lSpace, kFBAttachLeft, "", 1.0,
lSpace, kFBAttachBottom, "LabelOutputDir", 1.0,
lEditW, kFBAttachNone, NULL, 1.0,
lEditH, kFBAttachNone, NULL, 1.0 );
AddRegion( "ButtonBrowseOutputDir", "ButtonBrowseOutputDir",
lSpace, kFBAttachRight, "EditOutputDir", 1.0,
lSpace, kFBAttachBottom, "LabelOutputDir", 1.0,
lBrowseW, kFBAttachNone, NULL, 1.0,
lBrowseH, kFBAttachNone, NULL, 1.0 );
// Start
AddRegion( "LabelStart", "LabelStart",
lSpace, kFBAttachLeft, "", 1.0,
lSpace * 4, kFBAttachBottom, "EditOutputDir", 1.0,
-lSpace, kFBAttachRight, "", 1.0,
25, kFBAttachNone, NULL, 1.0 );
AddRegion( "ButtonStart", "ButtonStart",
lSpace, kFBAttachLeft, "", 1.0,
lSpace * 2, kFBAttachBottom, "LabelStart", 1.0,
lButtonW, kFBAttachNone, NULL, 1.0,
lButtonH, kFBAttachNone, NULL, 1.0 );
//
// Assign regions
//
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 );
// Description
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";
// Load Character
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";
// Input dir
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 = "...";
// Output dir
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 = "...";
// Start
mLabelStart.Caption = "Step 4.\n"
"Click on the button to start the batch process.";
mButtonStart.Caption = "Start";
//
// Callbacks
//
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()
{
}
/************************************************
* Browse Character button callback.
************************************************/
void ORToolBatch::EventButtonBrowseCharacterClick( HISender pSender, HKEvent pEvent )
{
//
// Show the file popup to select the file
//
FBFilePopup lFilePopup;
lFilePopup.Caption = "Open";
lFilePopup.Filter = "*.fbx";
lFilePopup.Path = (const char*)mEditCharacterPath.Text;
lFilePopup.Style = kFBFilePopupOpen;
lFilePopup.Execute();
//
// Set the path in the edit box
//
mEditCharacterPath.Text = (const char*)lFilePopup.FullFilename;
}
/************************************************
* Load Character button callback.
************************************************/
void ORToolBatch::EventButtonLoadCharacterClick( HISender pSender, HKEvent pEvent )
{
//
// Verify if the file exists
//
if( FileExist( mEditCharacterPath.Text ) == true )
{
//
// Load the file
//
mApplication.FileOpen( mEditCharacterPath.Text );
}
}
/************************************************
* Browse InputDir button callback.
************************************************/
void ORToolBatch::EventButtonBrowseInputDirClick( HISender pSender, HKEvent pEvent )
{
//
// Show the folder popup to select the folder
//
FBFolderPopup lFolderPopup;
lFolderPopup.Path = (const char*)mEditInputDir.Text;
lFolderPopup.Execute();
//
// Set the path in the edit box
//
mEditInputDir.Text = (const char*)lFolderPopup.Path;
}
/************************************************
* Browse OutputDir button callback.
************************************************/
void ORToolBatch::EventButtonBrowseOutputDirClick( HISender pSender, HKEvent pEvent )
{
//
// Show the folder popup to select the folder
//
FBFolderPopup lFolderPopup;
lFolderPopup.Path = (const char*)mEditOutputDir.Text;
lFolderPopup.Execute();
//
// Set the path in the edit box
//
mEditOutputDir.Text = (const char*)lFolderPopup.Path;
}
/************************************************
* Start button callback.
************************************************/
void ORToolBatch::EventButtonStartClick( HISender pSender, HKEvent pEvent )
{
//
// Verify if there is a character in the scene
//
FBScene* lScene = mSystem.Scene;
FBPropertyListCharacter& lCharacterList = lScene->Characters;
if( lCharacterList.GetCount() <= 0 )
{
FBMessageBox( "Error", "There is no character in the scene.", "Ok", NULL, NULL, 1 );
}
else
{
//
// Fill the plot options
//
FBPlotOptions lPlotOptions;
lPlotOptions.mPlotAllTakes = false;
lPlotOptions.mPlotOnFrame = true;
lPlotOptions.mPlotPeriod.SetSecondDouble ( 1.0 / 30.0 ); // 30 fps
lPlotOptions.mRotationFilterToApply = kFBRotationFilterUnroll;
lPlotOptions.mUseConstantKeyReducer = false;
lPlotOptions.mPlotTranslationOnRootOnly = false;
lPlotOptions.mPreciseTimeDiscontinuities = false;
//
// Fill the batch options
//
FBBatchOptions lBatchOptions;
lBatchOptions.mInputFileFormat = kFBBatchFileFormatC3D;
lBatchOptions.mOutputFileFormat = kFBBatchFileFormatFBX;
lBatchOptions.mProcessType = kFBBatchProcessTypeConvert;
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;
//
// Start the batch process
//
lStatus = mApplication.FileBatch( &lBatchOptions, &lPlotOptions );
//
// Show the returned status
//
FBMessageBox( "Batch Status", gBatchStatusText[lStatus], "Ok", NULL, NULL, 1 );
}
}
/************************************************
* Show event.
************************************************/
void ORToolBatch::EventToolShow( HISender pSender, HKEvent pEvent )
{
FBEventShow lEvent( pEvent );
if( lEvent.Shown )
{
UIReset();
}
else
{
}
}
/************************************************
* UI Idle event.
************************************************/
void ORToolBatch::EventToolIdle( HISender pSender, HKEvent pEvent )
{
UIRefresh();
}