tools/toolpathplot/ortoolpathplot_tool.cxx

tools/toolpathplot/ortoolpathplot_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 "ortoolpathplot_tool.h"
//--- Registration defines
#define ORTOOLPATHPLOT__CLASS ORTOOLPATHPLOT__CLASSNAME
#define ORTOOLPATHPLOT__LABEL "Path Plot"
#define ORTOOLPATHPLOT__DESC "OR - Plot Path Tool Description"
//--- FiLMBOX implementation and registration
FBToolImplementation( ORTOOLPATHPLOT__CLASS );
FBRegisterTool ( ORTOOLPATHPLOT__CLASS,
ORTOOLPATHPLOT__LABEL,
ORTOOLPATHPLOT__DESC,
FB_DEFAULT_SDK_ICON ); // Icon filename (default=Open Reality icon)
/************************************************
* FiLMBOX Constructor.
************************************************/
bool ORToolPathPlot::FBCreate()
{
StartSize[0] = 220;
StartSize[1] = 120;
// Create/reset/manage UI
UICreate ();
UIConfigure ();
UIReset ();
// Add tool callbacks
OnShow.Add ( this, (FBCallback) &ORToolPathPlot::EventToolShow );
OnIdle.Add ( this, (FBCallback) &ORToolPathPlot::EventToolIdle );
mSystem.Scene->OnChange.Add ( this, (FBCallback) &ORToolPathPlot::EventSceneChange );
mSystem.Scene->OnTakeChange.Add ( this, (FBCallback) &ORToolPathPlot::EventTakeChange );
return true;
}
/************************************************
* FiLMBOX Destruction function.
************************************************/
void ORToolPathPlot::FBDestroy()
{
// Remove tool callbacks
OnShow.Remove ( this, (FBCallback) &ORToolPathPlot::EventToolShow );
OnIdle.Remove ( this, (FBCallback) &ORToolPathPlot::EventToolIdle );
mSystem.Scene->OnChange.Remove ( this, (FBCallback) &ORToolPathPlot::EventSceneChange );
mSystem.Scene->OnTakeChange.Remove ( this, (FBCallback) &ORToolPathPlot::EventTakeChange );
// Free user allocated memory
}
/************************************************
* UI Management
************************************************/
void ORToolPathPlot::UICreate()
{
int lS = 4;
int lW = 200;
int lH = 18;
// Configure layout
AddRegion( "LabelDirections", "LabelDirections",
lS, kFBAttachLeft, "", 1.0 ,
lS, kFBAttachTop, "", 1.0,
lW, kFBAttachNone, "", 1.0,
25, kFBAttachNone, "", 1.0 );
AddRegion( "ListCameras", "ListCameras",
0, kFBAttachLeft, "LabelDirections", 1.0 ,
lS, kFBAttachBottom, "LabelDirections", 1.0,
0, kFBAttachWidth, "LabelDirections", 1.0,
lH, kFBAttachNone, "", 1.0 );
AddRegion( "ListModelType", "ListModelType",
0, kFBAttachLeft, "ListCameras", 1.0,
lS, kFBAttachBottom, "ListCameras", 1.0,
100, kFBAttachNone, NULL, 1.0,
0, kFBAttachHeight, "ListCameras", 1.0);
AddRegion( "EditNumberFrequency", "EditNumberFrequency",
lS, kFBAttachRight, "ListModelType", 1.0,
0, kFBAttachTop, "ListModelType", 1.0,
0, kFBAttachRight, "ListCameras", 1.0,
0, kFBAttachHeight, "ListModelType", 1.0 );
AddRegion( "ButtonPlot", "ButtonPlot",
0, kFBAttachLeft, "ListModelType", 1.0,
lS, kFBAttachBottom, "ListModelType", 1.0,
100, kFBAttachNone, NULL, 1.0,
0, kFBAttachHeight, "ListModelType", 1.0);
AddRegion( "ButtonUseInterest", "ButtonUseInterest",
lS, kFBAttachRight, "ButtonPlot", 1.0,
0, kFBAttachTop, "ButtonPlot", 1.0,
0, kFBAttachRight, "EditNumberFrequency", 1.0,
0, kFBAttachHeight, "ButtonPlot", 1.0 );
// Assign regions
SetControl( "LabelDirections", mLabelDirections );
SetControl( "ListCameras", mListCameras );
SetControl( "ListModelType", mListModelType );
SetControl( "EditNumberFrequency", mEditNumberFrequency );
SetControl( "ButtonPlot", mButtonPlot );
SetControl( "ButtonUseInterest", mButtonUseInterest );
}
void ORToolPathPlot::UIConfigure()
{
mLabelDirections.Caption = "This tool plots an animation path onto\n"
"the movement of a camera.";
mEditNumberFrequency.Precision = 3.3;
mEditNumberFrequency.LargeStep = 0.1;
mEditNumberFrequency.SmallStep = 0.1;
mEditNumberFrequency.Min = 0.001;
mEditNumberFrequency.Value = 10.0;
mListModelType.Items.Add( "Marker", eMarker );
mListModelType.Items.Add( "Null", eNull );
mButtonUseInterest.Caption = "Use Interest";
mButtonUseInterest.Style = kFB2States;
mButtonPlot.Caption = "Plot";
mButtonPlot.OnClick.Add( this, (FBCallback)&ORToolPathPlot::EventButtonPlotClick );
}
void ORToolPathPlot::UIReset()
{
FBString lSelection;
bool lIsSelected = false;
// If there is a selected camera, note which one.
if( mListCameras.ItemIndex != -1 )
{
lIsSelected = true;
lSelection = mListCameras.Items.GetAt(mListCameras.ItemIndex);
}
// Rebuild camera list.
mListCameras.Items.Clear();
for( int i=0; i<mSystem.Scene->Cameras.GetCount(); i++)
{
mListCameras.Items.Add( mSystem.Scene->Cameras[i]->Name, (kReference) mSystem.Scene->Cameras[i] );
}
// Re-select the correct camera (if previously selected).
if( lIsSelected )
{
mListCameras.ItemIndex = mListCameras.Items.Find( lSelection );
}
}
void ORToolPathPlot::UIRefresh()
{
}
/************************************************
* Create model callback.
************************************************/
void ORToolPathPlot::EventButtonPlotClick( HISender pSender, HKEvent pEvent )
{
double lRate = mEditNumberFrequency.Value;
if( lRate != 0 )
{
if( mListCameras.ItemIndex != -1 )
{
mExport.mHdlCamera = (FBCamera*) mListCameras.Items.GetReferenceAt( mListCameras.ItemIndex );
mExport.mStep.SetSecondDouble(1.0/lRate);
mExport.mOriginalTime = mSystem.LocalTime;
mExport.mTimeSpan = mSystem.CurrentTake->LocalTimeSpan;
mExport.mHdlRoot = new FBModelRoot("Root-1");
mExport.mHdlRoot->Show = true;
mExport.mModelType = (EModelType)mListModelType.Items.GetReferenceAt( mListModelType.ItemIndex );
mExport.mUseInterest = (mButtonUseInterest.State!=0);
mExport.mId = 0;
mExport.mHdlProgress = new FBProgress;
mExport.mHdlProgress->Caption = "Path Plot";
mExport.mHdlProgress->Text = mExport.mHdlCamera->Name;
mPlayerControl.Goto( mExport.mTimeSpan.GetStart() );
mState = eModelNext;
}
}
}
/************************************************
* UI Idle callback.
************************************************/
void ORToolPathPlot::EventToolIdle( HISender pSender, HKEvent pEvent )
{
switch( mState )
{
case eIdle:
{
}
break;
case eModelNext:
{
mState = eModel;
}
break;
case eModel:
{
if( ((FBTime)mSystem.LocalTime) < mExport.mTimeSpan.GetStop() )
{
//
// Progress percentage
//
if( mExport.mTimeSpan.GetDuration() != 0 )
{
FBTime lCurrent = mSystem.LocalTime;
FBTime lStart = mExport.mTimeSpan.GetStart();
FBTime lTotal = mExport.mTimeSpan.GetDuration();
FBTime lDelta = lCurrent-lStart;
if (mExport.mHdlProgress.Ok()) mExport.mHdlProgress->Percent = (lDelta.GetSecondDouble() / lTotal.GetSecondDouble())*100.0;
}
else
{
if (mExport.mHdlProgress.Ok()) mExport.mHdlProgress->Percent = 0.0;
}
//
// Create Model
//
FBModel* lModel = NULL;
char lBuffer[1024];
sprintf(lBuffer,"Step %d-1", mExport.mId++);
switch( mExport.mModelType )
{
default:
case eMarker: lModel = new FBModelMarker(lBuffer); break;
case eNull: lModel = new FBModelNull(lBuffer); break;
}
lModel->Show = true;
if(mExport.mHdlRoot.Ok()) mExport.mHdlRoot->Children.Add( lModel );
//
// Get Camera position & Set marker position
//
FBVector3d lPos;
FBVector3d lRot;
if (mExport.mHdlCamera.Ok()){
mExport.mHdlCamera->GetVector(lPos, kModelTranslation, true);
mExport.mHdlCamera->GetVector(lRot, kModelTranslation, true);
}
lModel->SetVector( lPos, kModelTranslation, true );
lModel->SetVector( lRot, kModelTranslation, true );
//
// If interest is used
//
if( mExport.mUseInterest&& mExport.mHdlCamera.Ok() )
{
lModel->LookAt = mExport.mHdlCamera->LookAt;
}
//
// Next step in transport control
//
mPlayerControl.Goto( ((FBTime)mSystem.LocalTime) + mExport.mStep );
}
else
{
//
// Clear export state
//
if (mExport.mHdlProgress.Ok()) mExport.mHdlProgress->FBDelete();
mExport.mHdlProgress=NULL;
mExport.mHdlRoot=NULL;
mExport.mHdlCamera=NULL;
mExport.mOriginalTime.Set(0);
mExport.mStep.Set(0);
mExport.mId = 0;
//
// Go back to original time
// put in idle state.
//
mPlayerControl.Goto( mExport.mOriginalTime );
mState = eIdle;
}
}
break;
}
UIRefresh();
}
/************************************************
* Handle tool activation (selection/unselection).
************************************************/
void ORToolPathPlot::EventToolShow( HISender pSender, HKEvent pEvent )
{
FBEventShow lEvent( pEvent );
if( lEvent.Shown )
{
UIReset();
}
else
{
}
}
void ORToolPathPlot::EventSceneChange( HISender pSender, HKEvent pEvent )
{
UIReset();
}
const char* gTakeEventName[] = {
"kFBTakeChangeAdded",
"kFBTakeChangeRemoved",
"kFBTakeChangeOpened",
"kFBTakeChangeClosed",
"kFBTakeChangeRenamed",
"kFBTakeChangeUpdated",
"kFBTakeChangeMoved",
"kFBTakeChangeNone"
};
void ORToolPathPlot::EventTakeChange( HISender pSender, HKEvent pEvent )
{
char lMsg[1024];
FBEventTakeChange lEvent( pEvent );
FBTake* lTake = lEvent.Take;
sprintf( lMsg, "(%s): %s", gTakeEventName[lEvent.Type], (const char*)lTake->Name );
FBMessageBox( "Take Change Event", lMsg, "OK", NULL, NULL );
}
/************************************************
* FBX Storage.
************************************************/
bool ORToolPathPlot::FbxStore ( FBFbxObject* pFbxObject, kFbxObjectStore pStoreWhat )
{
pFbxObject->FieldWriteBegin( "ORToolPathPlotSection" );
{
// sample value
// selected camera
// model type
// use interest
}
pFbxObject->FieldWriteEnd();
return true;
}
/************************************************
* FBX Retrieval.
************************************************/
bool ORToolPathPlot::FbxRetrieve( FBFbxObject* pFbxObject, kFbxObjectStore pStoreWhat )
{
pFbxObject->FieldReadBegin( "ORToolPathPlotSection" );
{
}
pFbxObject->FieldReadEnd();
return true;
}