tools/toolcharacter/ortoolcharacter_tool.cxx

tools/toolcharacter/ortoolcharacter_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 "ortoolcharacter_tool.h"
//--- Registration defines
#define ORTOOLCHARACTER__CLASS ORTOOLCHARACTER__CLASSNAME
#define ORTOOLCHARACTER__LABEL "Character"
#define ORTOOLCHARACTER__DESC "OR - Character Tool Description"
//--- FiLMBOX Registration & Implementation.
FBToolImplementation( ORTOOLCHARACTER__CLASS );
FBRegisterTool ( ORTOOLCHARACTER__CLASS,
ORTOOLCHARACTER__LABEL,
ORTOOLCHARACTER__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
/************************************************
* 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 ORToolCharacter::FBCreate()
{
// mActor = NULL;
// mMarkerSet = NULL;
// mCharacter = NULL;
StartSize[0] = 490;
StartSize[1] = 335;
UICreate ();
UIConfigure ();
UIReset ();
OnShow.Add( this, (FBCallback) &ORToolCharacter::EventToolShow );
OnIdle.Add( this, (FBCallback) &ORToolCharacter::EventToolIdle );
return true;
}
/************************************************
* FiLMBOX Destructor.
************************************************/
void ORToolCharacter::FBDestroy()
{
}
/************************************************
* Create the UI.
************************************************/
void ORToolCharacter::UICreate()
{
int lSpace = 4;
int lButtonW = 100;
int lButtonH = 18;
int lEditW = 300;
int lEditH = 18;
int lBrowseW = 20;
int lBrowseH = 18;
//
// Create regions
//
AddRegion( "ListSteps", "ListSteps",
lSpace, kFBAttachLeft, "", 1.0,
lSpace, kFBAttachTop, "", 1.0,
100, kFBAttachNone, NULL, 1.0,
300, kFBAttachNone, NULL, 1.0 );
AddRegion( "RegionMain", "RegionMain",
lSpace, kFBAttachRight, "ListSteps", 1.0,
lSpace, kFBAttachTop, "", 1.0,
-lSpace, kFBAttachRight, NULL, 1.0,
400, kFBAttachNone, NULL, 1.0 );
// Description
mLayoutDescription.AddRegion( "LabelDescription", "LabelDescription",
lSpace, kFBAttachLeft, "", 1.0,
lSpace, kFBAttachTop, "", 1.0,
-lSpace, kFBAttachRight, "", 1.0,
185, kFBAttachNone, NULL, 1.0 );
mLayoutDescription.AddRegion( "ButtonStart", "ButtonStart",
lSpace, kFBAttachLeft, "", 1.0,
lSpace * 3, kFBAttachBottom, "LabelDescription", 1.0,
lButtonW, kFBAttachNone, NULL, 1.0,
lButtonH, kFBAttachNone, NULL, 1.0 );
// Load motion
mLayoutLoadMotion.AddRegion( "LabelLoadMotion", "LabelLoadMotion",
lSpace, kFBAttachLeft, "", 1.0,
lSpace, kFBAttachTop, "", 1.0,
-lSpace, kFBAttachRight, "", 1.0,
100, kFBAttachNone, NULL, 1.0 );
mLayoutLoadMotion.AddRegion( "LabelMotionFile", "LabelMotionFile",
lSpace, kFBAttachLeft, "", 1.0,
lSpace, kFBAttachBottom, "LabelLoadMotion", 1.0,
30, kFBAttachNone, NULL, 1.0,
20, kFBAttachNone, NULL, 1.0 );
mLayoutLoadMotion.AddRegion( "EditMotionFile", "EditMotionFile",
lSpace, kFBAttachRight, "LabelMotionFile", 1.0,
lSpace, kFBAttachBottom, "LabelLoadMotion", 1.0,
lEditW, kFBAttachNone, NULL, 1.0,
lEditH, kFBAttachNone, NULL, 1.0 );
mLayoutLoadMotion.AddRegion( "ButtonBrowseMotionFile", "ButtonBrowseMotionFile",
lSpace, kFBAttachRight, "EditMotionFile", 1.0,
lSpace, kFBAttachBottom, "LabelLoadMotion", 1.0,
lBrowseW, kFBAttachNone, NULL, 1.0,
lBrowseH, kFBAttachNone, NULL, 1.0 );
mLayoutLoadMotion.AddRegion( "ButtonLoadMotion", "ButtonLoadMotion",
lSpace, kFBAttachLeft, "", 1.0,
lSpace * 4, kFBAttachBottom, "LabelMotionFile", 1.0,
lButtonW, kFBAttachNone, NULL, 1.0,
lButtonH, kFBAttachNone, NULL, 1.0 );
// Load actor
mLayoutLoadActor.AddRegion( "LabelLoadActor", "LabelLoadActor",
lSpace, kFBAttachLeft, "", 1.0,
lSpace, kFBAttachTop, "", 1.0,
-lSpace, kFBAttachRight, "", 1.0,
100, kFBAttachNone, NULL, 1.0 );
mLayoutLoadActor.AddRegion( "LabelActorFile", "LabelActorFile",
lSpace, kFBAttachLeft, "", 1.0,
lSpace, kFBAttachBottom, "LabelLoadActor", 1.0,
30, kFBAttachNone, NULL, 1.0,
20, kFBAttachNone, NULL, 1.0 );
mLayoutLoadActor.AddRegion( "EditActorFile", "EditActorFile",
lSpace, kFBAttachRight, "LabelActorFile", 1.0,
lSpace, kFBAttachBottom, "LabelLoadActor", 1.0,
lEditW, kFBAttachNone, NULL, 1.0,
lEditH, kFBAttachNone, NULL, 1.0 );
mLayoutLoadActor.AddRegion( "ButtonBrowseActorFile", "ButtonBrowseActorFile",
lSpace, kFBAttachRight, "EditActorFile", 1.0,
lSpace, kFBAttachBottom, "LabelLoadActor", 1.0,
lBrowseW, kFBAttachNone, NULL, 1.0,
lBrowseH, kFBAttachNone, NULL, 1.0 );
mLayoutLoadActor.AddRegion( "ButtonLoadActor", "ButtonLoadActor",
lSpace, kFBAttachLeft, "", 1.0,
lSpace * 4, kFBAttachBottom, "LabelActorFile", 1.0,
lButtonW, kFBAttachNone, NULL, 1.0,
lButtonH, kFBAttachNone, NULL, 1.0 );
// Load character
mLayoutLoadCharacter.AddRegion( "LabelLoadCharacter", "LabelLoadCharacter",
lSpace, kFBAttachLeft, "", 1.0,
lSpace, kFBAttachTop, "", 1.0,
-lSpace, kFBAttachRight, "", 1.0,
100, kFBAttachNone, NULL, 1.0 );
mLayoutLoadCharacter.AddRegion( "LabelCharacterFile", "LabelCharacterFile",
lSpace, kFBAttachLeft, "", 1.0,
lSpace, kFBAttachBottom, "LabelLoadCharacter", 1.0,
30, kFBAttachNone, NULL, 1.0,
20, kFBAttachNone, NULL, 1.0 );
mLayoutLoadCharacter.AddRegion( "EditCharacterFile", "EditCharacterFile",
lSpace, kFBAttachRight, "LabelCharacterFile", 1.0,
lSpace, kFBAttachBottom, "LabelLoadCharacter", 1.0,
lEditW, kFBAttachNone, NULL, 1.0,
lEditH, kFBAttachNone, NULL, 1.0 );
mLayoutLoadCharacter.AddRegion( "ButtonBrowseCharacterFile", "ButtonBrowseCharacterFile",
lSpace, kFBAttachRight, "EditCharacterFile", 1.0,
lSpace, kFBAttachBottom, "LabelLoadCharacter", 1.0,
lBrowseW, kFBAttachNone, NULL, 1.0,
lBrowseH, kFBAttachNone, NULL, 1.0 );
mLayoutLoadCharacter.AddRegion( "ButtonLoadCharacter", "ButtonLoadCharacter",
lSpace, kFBAttachLeft, "", 1.0,
lSpace * 4, kFBAttachBottom, "LabelCharacterFile", 1.0,
lButtonW, kFBAttachNone, NULL, 1.0,
lButtonH, kFBAttachNone, NULL, 1.0 );
// Bind actor
mLayoutBindActor.AddRegion( "LabelBindActor", "LabelBindActor",
lSpace, kFBAttachLeft, "", 1.0,
lSpace, kFBAttachTop, "", 1.0,
-lSpace, kFBAttachRight, "", 1.0,
100, kFBAttachNone, NULL, 1.0 );
mLayoutBindActor.AddRegion( "ButtonBindActor", "ButtonBindActor",
lSpace, kFBAttachLeft, "", 1.0,
lSpace * 4, kFBAttachBottom, "LabelBindActor", 1.0,
lButtonW, kFBAttachNone, NULL, 1.0,
lButtonH, kFBAttachNone, NULL, 1.0 );
// Bind character
mLayoutBindCharacter.AddRegion( "LabelBindCharacter", "LabelBindCharacter",
lSpace, kFBAttachLeft, "", 1.0,
lSpace, kFBAttachTop, "", 1.0,
-lSpace, kFBAttachRight, "", 1.0,
100, kFBAttachNone, NULL, 1.0 );
mLayoutBindCharacter.AddRegion( "ButtonBindCharacter", "ButtonBindCharacter",
lSpace, kFBAttachLeft, "", 1.0,
lSpace * 4, kFBAttachBottom, "LabelBindCharacter", 1.0,
lButtonW, kFBAttachNone, NULL, 1.0,
lButtonH, kFBAttachNone, NULL, 1.0 );
// Plot character
mLayoutPlotCharacter.AddRegion( "LabelPlotCharacter", "LabelPlotCharacter",
lSpace, kFBAttachLeft, "", 1.0,
lSpace, kFBAttachTop, "", 1.0,
-lSpace, kFBAttachRight, "", 1.0,
100, kFBAttachNone, NULL, 1.0 );
mLayoutPlotCharacter.AddRegion( "ButtonPlotCharacter", "ButtonPlotCharacter",
lSpace, kFBAttachLeft, "", 1.0,
lSpace * 4, kFBAttachBottom, "LabelPlotCharacter", 1.0,
lButtonW, kFBAttachNone, NULL, 1.0,
lButtonH, kFBAttachNone, NULL, 1.0 );
// Done
mLayoutDone.AddRegion( "LabelDone", "LabelDone",
lSpace, kFBAttachLeft, "", 1.0,
lSpace, kFBAttachTop, "", 1.0,
-lSpace, kFBAttachRight, "", 1.0,
100, kFBAttachNone, NULL, 1.0 );
mLayoutDone.AddRegion( "ButtonClear", "ButtonClear",
lSpace, kFBAttachLeft, "", 1.0,
lSpace * 4, kFBAttachBottom, "LabelDone", 1.0,
lButtonW, kFBAttachNone, NULL, 1.0,
lButtonH, kFBAttachNone, NULL, 1.0 );
//
// Assign regions
//
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 );
//
// Configuration
//
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" );
mListSteps.Style = kFBVerticalList;
// Description
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;
// Load Motion
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;
// Load Actor
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;
// Load Character
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;
// Bind Actor
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;
// Bind Character
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;
// Plot Character
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;
// Done
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;
//
// Callbacks
//
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()
{
}
/************************************************
* Create Actor button callback.
************************************************/
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 );
}
}
/************************************************
* Create Actor button callback.
************************************************/
void ORToolCharacter::EventButtonStartClick( HISender pSender, HKEvent pEvent )
{
//
// Goto the first step
//
mListSteps.Selected( 1, true );
SetControl( "RegionMain", mLayoutLoadMotion );
}
/************************************************
* Load Motion button callback.
************************************************/
void ORToolCharacter::EventButtonLoadMotionClick( HISender pSender, HKEvent pEvent )
{
//
// Verify if the file exists
//
if( FileExist( mEditMotionFile.Text ) == true )
{
//
// Load the file
//
mApplication.FileOpen( mEditMotionFile.Text );
//
// Goto the next step
//
mListSteps.Selected( 2, true );
SetControl( "RegionMain", mLayoutLoadActor );
mButtonLoadMotion.Enabled = false;
mButtonLoadActor.Enabled = true;
}
else
{
//
// Display an error message, File not found
//
FBMessageBox( "Error", "File not found.", "Ok", NULL, NULL );
}
}
/************************************************
* Load Actor button callback.
************************************************/
void ORToolCharacter::EventButtonLoadActorClick( HISender pSender, HKEvent pEvent )
{
//
// Verify if the file exists
//
if( FileExist( mEditActorFile.Text ) == true )
{
//
// Merge inthe actor
//
mApplication.FileMerge( mEditActorFile.Text );
//
// Get the actor
//
FBScene* lScene = mSystem.Scene;
if( lScene->Actors.GetCount() > 0 )
{
mHdlActor = lScene->Actors[0];
}
//
// Make sure our motion take is the current take
//
int i;
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())
{
//
// Display an error message, No actor found
//
FBMessageBox( "Error", "No actor found in the scene.", "Ok", NULL, NULL );
}
else
{
//
// Goto the next step
//
mListSteps.Selected( 3, true );
SetControl( "RegionMain", mLayoutLoadCharacter );
mButtonLoadActor.Enabled = false;
mButtonLoadCharacter.Enabled = true;
}
}
else
{
//
// Display an error message, File not found
//
FBMessageBox( "Error", "File not found.", "Ok", NULL, NULL );
}
}
/************************************************
* Load Character button callback.
************************************************/
void ORToolCharacter::EventButtonLoadCharacterClick( HISender pSender, HKEvent pEvent )
{
//
// Verify if the file exists
//
if( FileExist( mEditCharacterFile.Text ) == true )
{
//
// Merge in the character
//
mApplication.FileMerge( mEditCharacterFile.Text );
//
// Get the character
//
FBScene* lScene = mSystem.Scene;
if( lScene->Characters.GetCount() > 0 )
{
mHdlCharacter = lScene->Characters[0];
}
//
// Make sure our motion take is the current take
//
int i;
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())
{
//
// Display an error message, No character found
//
FBMessageBox( "Error", "No character found in the scene.", "Ok", NULL, NULL );
}
else
{
//
// Goto the next step
//
mListSteps.Selected( 4, true );
SetControl( "RegionMain", mLayoutBindActor );
mButtonLoadCharacter.Enabled = false;
mButtonBindActor.Enabled = true;
}
}
else
{
//
// Display an error message, File not found
//
FBMessageBox( "Error", "File not found.", "Ok", NULL, NULL );
}
}
/************************************************
* Browse Motion button callback.
************************************************/
void ORToolCharacter::EventButtonBrowseMotionClick( HISender pSender, HKEvent pEvent )
{
FBSystem lSystem;
FBString lBinPath( lSystem.ApplicationPath );
//
// Show the file popup to select the file
//
FBFilePopup lFilePopup;
lFilePopup.Caption = "Open";
lFilePopup.Filter = "*.fbx";
lFilePopup.Path = lBinPath + "\\..\\OpenRealitySDK\\Samples\\tools\\toolcharacter\\res\\";
lFilePopup.Style = kFBFilePopupOpen;
lFilePopup.Execute();
//
// Set the path in the edit box
//
mEditMotionFile.Text = (const char*)lFilePopup.FullFilename;
}
/************************************************
* Browse Actor button callback.
************************************************/
void ORToolCharacter::EventButtonBrowseActorClick( HISender pSender, HKEvent pEvent )
{
FBSystem lSystem;
FBString lBinPath( lSystem.ApplicationPath );
//
// Show the file popup to select the file
//
FBFilePopup lFilePopup;
lFilePopup.Caption = "Open";
lFilePopup.Filter = "*.fbx";
lFilePopup.Path = lBinPath + "\\..\\OpenRealitySDK\\Samples\\tools\\toolcharacter\\res\\";
lFilePopup.Style = kFBFilePopupOpen;
lFilePopup.Execute();
//
// Set the path in the edit box
//
mEditActorFile.Text = (const char*)lFilePopup.FullFilename;
}
/************************************************
* Browse Character button callback.
************************************************/
void ORToolCharacter::EventButtonBrowseCharacterClick( HISender pSender, HKEvent pEvent )
{
FBSystem lSystem;
FBString lBinPath( lSystem.ApplicationPath );
//
// Show the file popup to select the file
//
FBFilePopup lFilePopup;
lFilePopup.Caption = "Open";
lFilePopup.Filter = "*.fbx";
lFilePopup.Path = lBinPath + "\\..\\OpenRealitySDK\\Samples\\tools\\toolcharacter\\res\\";
lFilePopup.Style = kFBFilePopupOpen;
lFilePopup.Execute();
//
// Set the path in the edit box
//
mEditCharacterFile.Text = (const char*)lFilePopup.FullFilename;
}
/************************************************
* Active Actor button callback.
************************************************/
void ORToolCharacter::EventButtonBindActorClick( HISender pSender, HKEvent pEvent )
{
if( mHdlActor.Ok() )
{
//
// Get the list of all optical models.
// In our case, it is the children of the model named "C3D:optical".
//
FBModelList lModelList;
const char* lOpticalModelName = "optical";
int i;
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;
}
}
}
//
// Associate the optical models with the markers of our Actors's Marker Set.
// The models will be matched to markers by comparing their name.
//
if( mHdlActor->MarkerSet )
{
mHdlActor->MarkerSet->SetMultipleMarkerModels( &lModelList );
}
//
// Activate the Marker Set input of the actor.
//
mHdlActor->Active = true;
//
// Goto the next step
//
mListSteps.Selected( 5, true );
SetControl( "RegionMain", mLayoutBindCharacter );
mButtonBindActor.Enabled = false;
mButtonBindCharacter.Enabled = true;
}
}
/************************************************
* Bind Character Set button callback.
************************************************/
void ORToolCharacter::EventButtonBindCharacterClick( HISender pSender, HKEvent pEvent )
{
if( mHdlCharacter.Ok() )
{
//
// Bind the character with the actor
//
if( mHdlActor.Ok() )
{
//
// Set the actor we will use for the input
//
mHdlCharacter->InputActor = mHdlActor;
//
// Set the input type to Actor input
//
mHdlCharacter->InputType = kFBCharacterInputActor;
}
//
// Active the input
//
mHdlCharacter->ActiveInput = true;
//
// Goto the next step
//
mListSteps.Selected( 6, true );
SetControl( "RegionMain", mLayoutPlotCharacter );
mButtonBindCharacter.Enabled = false;
mButtonPlotCharacter.Enabled = true;
}
}
/************************************************
* Bind Character Set button callback.
************************************************/
void ORToolCharacter::EventButtonPlotCharacterClick( HISender pSender, HKEvent pEvent )
{
if( mHdlCharacter.Ok() )
{
//
// Set the plot options
//
FBPlotOptions lPlotOptions;
lPlotOptions.mPlotAllTakes = true;
lPlotOptions.mPlotOnFrame = true;
lPlotOptions.mPlotPeriod .SetSecondDouble( 1.0 / 30.0 ); // 30 fps
lPlotOptions.mRotationFilterToApply = kFBRotationFilterUnroll;
lPlotOptions.mUseConstantKeyReducer = true;
lPlotOptions.mPlotTranslationOnRootOnly = false;
lPlotOptions.mPreciseTimeDiscontinuities = false;
//
// Plot the input of the character to its skeleton
//
mHdlCharacter->PlotAnimation( kFBCharacterPlotOnSkeleton, &lPlotOptions );
//
// Goto the next step
//
mListSteps.Selected( 7, true );
SetControl( "RegionMain", mLayoutDone );
mButtonPlotCharacter.Enabled = false;
}
}
/************************************************
* Bind Character Set button callback.
************************************************/
void ORToolCharacter::EventButtonClearClick( HISender pSender, HKEvent pEvent )
{
//
// Clear the scene
//
mApplication.FileNew();
//
// Reset our data variables
// ** Note: We never need to destroy an FBCharacter, FBActor or FBMarkerSet we created.
// Upon creation, they are automatically added in the scene and will
// be destroyed when the scene is cleared.
//
mHdlActor=NULL;
mHdlCharacter=NULL;
//
// Reset the UI
//
mButtonStart.Enabled = true;
mButtonLoadMotion.Enabled = true;
mButtonLoadActor.Enabled = false;
mButtonLoadCharacter.Enabled = false;
mButtonBindActor.Enabled = false;
mButtonBindCharacter.Enabled = false;
mButtonPlotCharacter.Enabled = false;
mButtonClear.Enabled = true;
//
// Goto the first step
//
mListSteps.Selected( 0, true );
SetControl( "RegionMain", mLayoutDescription );
}
/************************************************
* Show event.
************************************************/
void ORToolCharacter::EventToolShow( HISender pSender, HKEvent pEvent )
{
FBEventShow lEvent( pEvent );
if( lEvent.Shown )
{
UIReset();
}
else
{
}
}
/************************************************
* UI Idle event.
************************************************/
void ORToolCharacter::EventToolIdle( HISender pSender, HKEvent pEvent )
{
UIRefresh();
}