#include "ortoolcharacter_tool.h"
#define ORTOOLCHARACTER__CLASS ORTOOLCHARACTER__CLASSNAME
#define ORTOOLCHARACTER__LABEL "Character"
#define ORTOOLCHARACTER__DESC "OR - Character Tool Description"
ORTOOLCHARACTER__LABEL,
ORTOOLCHARACTER__DESC,
#define MAX_FBMODEL_COUNT 100
bool FileExist( const char* pFileName )
{
bool lReturn = false;
FILE* lFile = fopen( pFileName,
"r" );
{
lReturn = true;
fclose(lFile);
}
return lReturn;
}
bool ORToolCharacter::FBCreate()
{
StartSize[0] = 490;
StartSize[1] = 335;
UICreate ();
UIConfigure ();
UIReset ();
OnShow.Add(
this, (
FBCallback) &ORToolCharacter::EventToolShow );
OnIdle.Add(
this, (
FBCallback) &ORToolCharacter::EventToolIdle );
return true;
}
void ORToolCharacter::FBDestroy()
{
}
void ORToolCharacter::UICreate()
{
int lSpace = 4;
int lButtonW = 100;
int lButtonH = 18;
int lEditW = 300;
int lEditH = 18;
int lBrowseW = 20;
int lBrowseH = 18;
AddRegion( "ListSteps", "ListSteps",
AddRegion( "RegionMain", "RegionMain",
mLayoutDescription.AddRegion( "LabelDescription", "LabelDescription",
mLayoutDescription.AddRegion( "ButtonStart", "ButtonStart",
mLayoutLoadMotion.AddRegion( "LabelLoadMotion", "LabelLoadMotion",
mLayoutLoadMotion.AddRegion( "LabelMotionFile", "LabelMotionFile",
mLayoutLoadMotion.AddRegion( "EditMotionFile", "EditMotionFile",
mLayoutLoadMotion.AddRegion( "ButtonBrowseMotionFile", "ButtonBrowseMotionFile",
mLayoutLoadMotion.AddRegion( "ButtonLoadMotion", "ButtonLoadMotion",
mLayoutLoadActor.AddRegion( "LabelLoadActor", "LabelLoadActor",
mLayoutLoadActor.AddRegion( "LabelActorFile", "LabelActorFile",
mLayoutLoadActor.AddRegion( "EditActorFile", "EditActorFile",
mLayoutLoadActor.AddRegion( "ButtonBrowseActorFile", "ButtonBrowseActorFile",
mLayoutLoadActor.AddRegion( "ButtonLoadActor", "ButtonLoadActor",
mLayoutLoadCharacter.AddRegion( "LabelLoadCharacter", "LabelLoadCharacter",
mLayoutLoadCharacter.AddRegion( "LabelCharacterFile", "LabelCharacterFile",
mLayoutLoadCharacter.AddRegion( "EditCharacterFile", "EditCharacterFile",
mLayoutLoadCharacter.AddRegion( "ButtonBrowseCharacterFile", "ButtonBrowseCharacterFile",
mLayoutLoadCharacter.AddRegion( "ButtonLoadCharacter", "ButtonLoadCharacter",
mLayoutBindActor.AddRegion( "LabelBindActor", "LabelBindActor",
mLayoutBindActor.AddRegion( "ButtonBindActor", "ButtonBindActor",
mLayoutBindCharacter.AddRegion( "LabelBindCharacter", "LabelBindCharacter",
mLayoutBindCharacter.AddRegion( "ButtonBindCharacter", "ButtonBindCharacter",
mLayoutPlotCharacter.AddRegion( "LabelPlotCharacter", "LabelPlotCharacter",
mLayoutPlotCharacter.AddRegion( "ButtonPlotCharacter", "ButtonPlotCharacter",
mLayoutDone.AddRegion( "LabelDone", "LabelDone",
mLayoutDone.AddRegion( "ButtonClear", "ButtonClear",
SetControl( "ListSteps", mListSteps );
SetControl( "RegionMain", mLayoutDescription );
mLayoutDescription.SetControl( "LabelDescription", mLabelDescription );
mLayoutDescription.SetControl( "ButtonStart", mButtonStart );
mLayoutLoadMotion.SetControl( "LabelLoadMotion", mLabelLoadMotion );
mLayoutLoadMotion.SetControl( "LabelMotionFile", mLabelMotionFile );
mLayoutLoadMotion.SetControl( "EditMotionFile", mEditMotionFile );
mLayoutLoadMotion.SetControl( "ButtonBrowseMotionFile", mButtonBrowseMotionFile );
mLayoutLoadMotion.SetControl( "ButtonLoadMotion", mButtonLoadMotion );
mLayoutLoadActor.SetControl( "LabelLoadActor", mLabelLoadActor );
mLayoutLoadActor.SetControl( "LabelActorFile", mLabelActorFile );
mLayoutLoadActor.SetControl( "EditActorFile", mEditActorFile );
mLayoutLoadActor.SetControl( "ButtonBrowseActorFile", mButtonBrowseActorFile );
mLayoutLoadActor.SetControl( "ButtonLoadActor", mButtonLoadActor );
mLayoutLoadCharacter.SetControl( "LabelLoadCharacter", mLabelLoadCharacter );
mLayoutLoadCharacter.SetControl( "LabelCharacterFile", mLabelCharacterFile );
mLayoutLoadCharacter.SetControl( "EditCharacterFile", mEditCharacterFile );
mLayoutLoadCharacter.SetControl( "ButtonBrowseCharacterFile", mButtonBrowseCharacterFile );
mLayoutLoadCharacter.SetControl( "ButtonLoadCharacter", mButtonLoadCharacter );
mLayoutBindActor.SetControl( "LabelBindActor", mLabelBindActor );
mLayoutBindActor.SetControl( "ButtonBindActor", mButtonBindActor );
mLayoutBindCharacter.SetControl( "LabelBindCharacter", mLabelBindCharacter );
mLayoutBindCharacter.SetControl( "ButtonBindCharacter", mButtonBindCharacter );
mLayoutPlotCharacter.SetControl( "LabelPlotCharacter", mLabelPlotCharacter );
mLayoutPlotCharacter.SetControl( "ButtonPlotCharacter", mButtonPlotCharacter );
mLayoutDone.SetControl( "LabelDone", mLabelDone );
mLayoutDone.SetControl( "ButtonClear", mButtonClear );
}
void ORToolCharacter::UIConfigure()
{
FBSystem lSystem;
FBString lBinPath( lSystem.ApplicationPath );
mListSteps.Items.Add( "Intro" );
mListSteps.Items.Add( "Load Motion" );
mListSteps.Items.Add( "Load Actor" );
mListSteps.Items.Add( "Load Character" );
mListSteps.Items.Add( "Bind Actor" );
mListSteps.Items.Add( "Bind Character" );
mListSteps.Items.Add( "Plot Character" );
mListSteps.Items.Add( "Done" );
mLabelDescription.Caption = "This SDK sample will show you how to use the Character and Actor API.\n"
"We will go through the steps required to bind a character to motion\n"
"data acquired from a motion capture source.\n"
"\n"
"The steps are the following :\n"
"1. Load a file containing the motion data.\n"
"2. Load a file containing your actor.\n"
"3. Load a file containing the target character.\n"
"4. Bind the actor to the motion data.\n"
"5. Bind the character to the actor.\n"
"6. Plot your character.\n"
"\n"
"Click on this button to start.";
mButtonStart.Caption = "Start";
mButtonStart.Enabled = true;
mLabelLoadMotion.Caption = "Step 1. Load motion file\n"
"\n"
"Select the FBX file containing the motion we will use for this sample.\n"
"Note: This sample is programmed to work with the StormMotion.fbx file.\n"
"because the names of optical markers are hardcoded. You may want\n"
"to change these names to fit with your naming scheme.";
mLabelMotionFile.Caption = "File : ";
mEditMotionFile.Text = lBinPath + "\\..\\..\\OpenRealitySDK\\Samples\\tools\\toolcharacter\\res\\StormMotion.fbx";
mButtonBrowseMotionFile.Caption = "...";
mButtonLoadMotion.Caption = "Load Motion File";
mButtonLoadMotion.Enabled = true;
mLabelLoadActor.Caption = "Step 2. Load actor file\n"
"\n"
"Select the FBX file containing the actor.\n"
"An actor is used to make the bridge between the motion data and the\n"
"character. The reason why we load an actor with a Marker Set instead\n"
"of creating one at runtime is because the characterization process\n"
"of the actor should be done at hand.";
mLabelActorFile.Caption = "File : ";
mEditActorFile.Text = lBinPath + "\\..\\..\\OpenRealitySDK\\Samples\\tools\\toolcharacter\\res\\StormActor.fbx";
mButtonBrowseActorFile.Caption = "...";
mButtonLoadActor.Caption = "Load Actor File";
mButtonLoadActor.Enabled = false;
mLabelLoadCharacter.Caption = "Step 3. Load character file\n"
"\n"
"Select the FBX file containing the character. At this step, you could\n"
"choose to load any character file you want. The first character found\n"
"in the scene will be used.";
mLabelCharacterFile.Caption = "File : ";
mEditCharacterFile.Text = lBinPath + "\\..\\..\\OpenRealitySDK\\Samples\\tools\\toolcharacter\\res\\NinjaCharacter.fbx";
mButtonBrowseCharacterFile.Caption = "...";
mButtonLoadCharacter.Caption = "Load Character File";
mButtonLoadCharacter.Enabled = false;
mLabelBindActor.Caption = "Step 4. Bind actor\n"
"\n"
"Now if you click play, you see that only the optical markers move.\n"
"We will associate every markers with a body part of the actor.";
mButtonBindActor.Caption = "Bind Actor";
mButtonBindActor.Enabled = false;
mLabelBindCharacter.Caption = "Step 5. Bind character\n"
"\n"
"If you click play now, you see that the actor is moving accordingly.\n"
"We can now re-target its motion on any character(s) we want\n";
mButtonBindCharacter.Caption = "Bind Character";
mButtonBindCharacter.Enabled = false;
mLabelPlotCharacter.Caption = "Step 6. Plot character\n"
"\n"
"Now you see that the character moves just like the actor. So we can\n"
"now plot this animation on the skeleton of the character.";
mButtonPlotCharacter.Caption = "Plot Character";
mButtonPlotCharacter.Enabled = false;
mLabelDone.Caption = "Done!\n"
"Now that your animation is plotted, you could choose to clean your\n"
"scene and save only your character with its animation.\n"
"\n"
"Click on this button to re-start this sample.\n"
"(The current scene will be closed)";
mButtonClear.Caption = "Restart sample";
mButtonClear.Enabled = true;
mListSteps.OnChange.Add (
this, (
FBCallback) &ORToolCharacter::EventListStepsChange );
mButtonStart.OnClick.Add (
this, (
FBCallback) &ORToolCharacter::EventButtonStartClick );
mButtonLoadMotion.OnClick.Add (
this, (
FBCallback) &ORToolCharacter::EventButtonLoadMotionClick );
mButtonLoadActor.OnClick.Add (
this, (
FBCallback) &ORToolCharacter::EventButtonLoadActorClick );
mButtonLoadCharacter.OnClick.Add (
this, (
FBCallback) &ORToolCharacter::EventButtonLoadCharacterClick );
mButtonBrowseMotionFile.OnClick.Add (
this, (
FBCallback) &ORToolCharacter::EventButtonBrowseMotionClick );
mButtonBrowseActorFile.OnClick.Add (
this, (
FBCallback) &ORToolCharacter::EventButtonBrowseActorClick );
mButtonBrowseCharacterFile.OnClick.Add (
this, (
FBCallback) &ORToolCharacter::EventButtonBrowseCharacterClick );
mButtonBindActor.OnClick.Add (
this, (
FBCallback) &ORToolCharacter::EventButtonBindActorClick );
mButtonBindCharacter.OnClick.Add (
this, (
FBCallback) &ORToolCharacter::EventButtonBindCharacterClick );
mButtonPlotCharacter.OnClick.Add (
this, (
FBCallback) &ORToolCharacter::EventButtonPlotCharacterClick );
mButtonClear.OnClick.Add (
this, (
FBCallback) &ORToolCharacter::EventButtonClearClick );
}
void ORToolCharacter::UIReset()
{
}
void ORToolCharacter::UIRefresh()
{
}
void ORToolCharacter::EventListStepsChange(
HISender pSender,
HKEvent pEvent )
{
if( strcmp( mListSteps.Items[ mListSteps.ItemIndex ], "Intro" ) == 0 )
{
SetControl( "RegionMain", mLayoutDescription );
}
else if( strcmp( mListSteps.Items[ mListSteps.ItemIndex ], "Load Motion" ) == 0 )
{
SetControl( "RegionMain", mLayoutLoadMotion );
}
else if( strcmp( mListSteps.Items[ mListSteps.ItemIndex ], "Load Actor" ) == 0 )
{
SetControl( "RegionMain", mLayoutLoadActor );
}
else if( strcmp( mListSteps.Items[ mListSteps.ItemIndex ], "Load Character" ) == 0 )
{
SetControl( "RegionMain", mLayoutLoadCharacter );
}
else if( strcmp( mListSteps.Items[ mListSteps.ItemIndex ], "Bind Actor" ) == 0 )
{
SetControl( "RegionMain", mLayoutBindActor );
}
else if( strcmp( mListSteps.Items[ mListSteps.ItemIndex ], "Bind Character" ) == 0 )
{
SetControl( "RegionMain", mLayoutBindCharacter );
}
else if( strcmp( mListSteps.Items[ mListSteps.ItemIndex ], "Plot Character" ) == 0 )
{
SetControl( "RegionMain", mLayoutPlotCharacter );
}
else if( strcmp( mListSteps.Items[ mListSteps.ItemIndex ], "Done" ) == 0 )
{
SetControl( "RegionMain", mLayoutDone );
}
}
void ORToolCharacter::EventButtonStartClick(
HISender pSender,
HKEvent pEvent )
{
mListSteps.Selected( 1, true );
SetControl( "RegionMain", mLayoutLoadMotion );
}
void ORToolCharacter::EventButtonLoadMotionClick(
HISender pSender,
HKEvent pEvent )
{
if( FileExist( mEditMotionFile.Text ) == true )
{
mApplication.FileOpen( mEditMotionFile.Text );
mListSteps.Selected( 2, true );
SetControl( "RegionMain", mLayoutLoadActor );
mButtonLoadMotion.Enabled = false;
mButtonLoadActor.Enabled = true;
}
else
{
}
}
void ORToolCharacter::EventButtonLoadActorClick(
HISender pSender,
HKEvent pEvent )
{
if( FileExist( mEditActorFile.Text ) == true )
{
mApplication.FileMerge( mEditActorFile.Text );
FBScene* lScene = mSystem.Scene;
if( lScene->Actors.GetCount() > 0 )
{
mHdlActor = lScene->Actors[0];
}
for( i = 0; i < mSystem.Scene->Takes.GetCount(); i++ )
{
if( strcmp( mSystem.Scene->Takes[i]->Name, "Storm" ) == 0 )
{
mSystem.CurrentTake = mSystem.Scene->Takes[
i];
}
}
if( !mHdlActor.Ok())
{
}
else
{
mListSteps.Selected( 3, true );
SetControl( "RegionMain", mLayoutLoadCharacter );
mButtonLoadActor.Enabled = false;
mButtonLoadCharacter.Enabled = true;
}
}
else
{
}
}
void ORToolCharacter::EventButtonLoadCharacterClick(
HISender pSender,
HKEvent pEvent )
{
if( FileExist( mEditCharacterFile.Text ) == true )
{
mApplication.FileMerge( mEditCharacterFile.Text );
FBScene* lScene = mSystem.Scene;
if( lScene->Characters.GetCount() > 0 )
{
mHdlCharacter = lScene->Characters[0];
}
for( i = 0; i < mSystem.Scene->Takes.GetCount(); i++ )
{
if( strcmp( mSystem.Scene->Takes[i]->Name, "Storm" ) == 0 )
{
mSystem.CurrentTake = mSystem.Scene->Takes[
i];
}
}
if(!mHdlCharacter.Ok())
{
}
else
{
mListSteps.Selected( 4, true );
SetControl( "RegionMain", mLayoutBindActor );
mButtonLoadCharacter.Enabled = false;
mButtonBindActor.Enabled = true;
}
}
else
{
}
}
void ORToolCharacter::EventButtonBrowseMotionClick(
HISender pSender,
HKEvent pEvent )
{
FBSystem lSystem;
FBString lBinPath( lSystem.ApplicationPath );
FBFilePopup lFilePopup;
lFilePopup.Caption = "Open";
lFilePopup.Filter = "*.fbx";
lFilePopup.Path = lBinPath + "\\..\\OpenRealitySDK\\Samples\\tools\\toolcharacter\\res\\";
lFilePopup.Execute();
mEditMotionFile.Text = (const char*)lFilePopup.FullFilename;
}
void ORToolCharacter::EventButtonBrowseActorClick(
HISender pSender,
HKEvent pEvent )
{
FBSystem lSystem;
FBString lBinPath( lSystem.ApplicationPath );
FBFilePopup lFilePopup;
lFilePopup.Caption = "Open";
lFilePopup.Filter = "*.fbx";
lFilePopup.Path = lBinPath + "\\..\\OpenRealitySDK\\Samples\\tools\\toolcharacter\\res\\";
lFilePopup.Execute();
mEditActorFile.Text = (const char*)lFilePopup.FullFilename;
}
void ORToolCharacter::EventButtonBrowseCharacterClick(
HISender pSender,
HKEvent pEvent )
{
FBSystem lSystem;
FBString lBinPath( lSystem.ApplicationPath );
FBFilePopup lFilePopup;
lFilePopup.Caption = "Open";
lFilePopup.Filter = "*.fbx";
lFilePopup.Path = lBinPath + "\\..\\OpenRealitySDK\\Samples\\tools\\toolcharacter\\res\\";
lFilePopup.Execute();
mEditCharacterFile.Text = (const char*)lFilePopup.FullFilename;
}
void ORToolCharacter::EventButtonBindActorClick(
HISender pSender,
HKEvent pEvent )
{
if( mHdlActor.Ok() )
{
const char* lOpticalModelName = "optical";
int j;
for( i = 0; i < mSystem.SceneRootModel->Children.GetCount(); i++ )
{
if( mSystem.SceneRootModel->Children[i] !=
NULL )
{
if( strcmp( mSystem.SceneRootModel->Children[i]->Name, lOpticalModelName ) == 0 )
{
for( j = 0; j < mSystem.SceneRootModel->Children[
i]->Children.GetCount(); j++ )
{
lModelList.Add( mSystem.SceneRootModel->Children[i]->Children[j] );
}
break;
}
}
}
if( mHdlActor->MarkerSet )
{
mHdlActor->MarkerSet->SetMultipleMarkerModels( &lModelList );
}
mHdlActor->Active = true;
mListSteps.Selected( 5, true );
SetControl( "RegionMain", mLayoutBindCharacter );
mButtonBindActor.Enabled = false;
mButtonBindCharacter.Enabled = true;
}
}
void ORToolCharacter::EventButtonBindCharacterClick(
HISender pSender,
HKEvent pEvent )
{
if( mHdlCharacter.Ok() )
{
if( mHdlActor.Ok() )
{
mHdlCharacter->InputActor = mHdlActor;
}
mHdlCharacter->ActiveInput = true;
mListSteps.Selected( 6, true );
SetControl( "RegionMain", mLayoutPlotCharacter );
mButtonBindCharacter.Enabled = false;
mButtonPlotCharacter.Enabled = true;
}
}
void ORToolCharacter::EventButtonPlotCharacterClick(
HISender pSender,
HKEvent pEvent )
{
if( mHdlCharacter.Ok() )
{
FBPlotOptions lPlotOptions;
lPlotOptions.mPlotAllTakes = true;
lPlotOptions.mPlotOnFrame = true;
lPlotOptions.mPlotPeriod .SetSecondDouble( 1.0 / 30.0 );
lPlotOptions.mUseConstantKeyReducer = true;
lPlotOptions.mPlotTranslationOnRootOnly = false;
lPlotOptions.mPreciseTimeDiscontinuities = false;
mListSteps.Selected( 7, true );
SetControl( "RegionMain", mLayoutDone );
mButtonPlotCharacter.Enabled = false;
}
}
void ORToolCharacter::EventButtonClearClick(
HISender pSender,
HKEvent pEvent )
{
mApplication.FileNew();
mButtonStart.Enabled = true;
mButtonLoadMotion.Enabled = true;
mButtonLoadActor.Enabled = false;
mButtonLoadCharacter.Enabled = false;
mButtonBindActor.Enabled = false;
mButtonBindCharacter.Enabled = false;
mButtonPlotCharacter.Enabled = false;
mButtonClear.Enabled = true;
mListSteps.Selected( 0, true );
SetControl( "RegionMain", mLayoutDescription );
}
{
FBEventShow lEvent( pEvent );
if( lEvent.Shown )
{
UIReset();
}
else
{
}
}
{
UIRefresh();
}