tools/toolpath3d/ortoolpath3d_tool.cxx

tools/toolpath3d/ortoolpath3d_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 "ortoolpath3d_tool.h"
//--- Registration defines
#define ORTOOLPATH3D__CLASS ORTOOLPATH3D__CLASSNAME
#define ORTOOLPATH3D__LABEL "Path3D"
#define ORTOOLPATH3D__DESC "FBSDK - Path3D Description"
//--- FiLMBOX implementation and registration
FBToolImplementation( ORTOOLPATH3D__CLASS );
FBRegisterTool ( ORTOOLPATH3D__CLASS,
ORTOOLPATH3D__LABEL,
ORTOOLPATH3D__DESC,
FB_DEFAULT_SDK_ICON ); // Icon filename (default=Open Reality icon)
#include <math.h> //For sin() and cos().
/************************************************
* FiLMBOX Constructor.
************************************************/
bool ORToolPath3D::FBCreate()
{
// Tool options
StartSize[0] = 160;
StartSize[1] = 95;
int lB = 10;
//int lS = 4;
int lW = 100;
int lH = 18;
// Configure layout
AddRegion( "ButtonTest", "ButtonTest",
lB, kFBAttachLeft, "", 1.0 ,
lB, kFBAttachTop, "", 1.0,
lW, kFBAttachNone, "", 1.0,
lH, kFBAttachNone, "", 1.0 );
SetControl( "ButtonTest", mButtonTest );
// Configure button
mButtonTest.OnClick.Add( this, (FBCallback) &ORToolPath3D::EventButtonTestClick );
mButtonTest.Caption = "Create scene";
// Add tool callbacks
OnShow.Add ( this, (FBCallback) &ORToolPath3D::EventToolShow );
OnIdle.Add ( this, (FBCallback) &ORToolPath3D::EventToolIdle );
OnResize.Add( this, (FBCallback) &ORToolPath3D::EventToolResize );
OnPaint.Add ( this, (FBCallback) &ORToolPath3D::EventToolPaint );
OnInput.Add ( this, (FBCallback) &ORToolPath3D::EventToolInput );
mState=0;
return true;
}
/************************************************
* FiLMBOX Destruction function.
************************************************/
void ORToolPath3D::FBDestroy()
{
// Remove tool callbacks
OnShow.Remove ( this, (FBCallback) &ORToolPath3D::EventToolShow );
OnIdle.Remove ( this, (FBCallback) &ORToolPath3D::EventToolIdle );
OnPaint.Remove ( this, (FBCallback) &ORToolPath3D::EventToolPaint );
OnInput.Remove ( this, (FBCallback) &ORToolPath3D::EventToolInput );
OnResize.Remove ( this, (FBCallback) &ORToolPath3D::EventToolResize);
// Free user allocated memory
}
bool ORToolPath3D::IsSetupValid()
{
return mHdlSet.Ok() && mHdlPath.Ok() && mHdlCube.Ok() && mHdlCube1.Ok() && mHdlConstraint.Ok();
}
void ORToolPath3D::ClearSetup()
{
// Delete model
if( mHdlSet.Ok() )
{
mHdlSet->FBDelete();
}
if( mHdlPath.Ok() )
{
mHdlPath->FBDelete();
}
if( mHdlCube.Ok() )
{
mHdlCube->FBDelete();
}
if( mHdlCube1.Ok() )
{
mHdlCube1->FBDelete();
}
if( mHdlConstraint.Ok() )
{
mHdlConstraint->FBDelete();
}
mButtonTest.Caption = "Create scene";
mState = 0;
}
/************************************************
* Button click callback.
************************************************/
void ORToolPath3D::EventButtonTestClick( HISender pSender, HKEvent pEvent )
{
bool lSceneIsValid = true;
switch( mState )
{
case 0:
{
mHdlSet = new FBSet("Set from SDK");
//Create helix path
mHdlPath = new FBModelPath3D("3D Path from SDK");
float x;
for( x = -300; x <= 300; x += 10 )
{
v4d[0] = x;
v4d[1] = 20 * sin(15 * x);
v4d[2] = 20 * cos(15 * x);
mHdlPath->PathKeyEndAdd(v4d);
}
//PATCH: Remove the two first point, they are unnecessary
mHdlPath->PathKeyRemove(0);
mHdlPath->PathKeyRemove(0);
//Create cube and constrain it to the 3D path
mHdlCube = new FBModelCube("Cube from SDK");
mHdlCube1 = new FBModelCube("Cube 1 from SDK");
v3d[0] = v3d[1] = v3d[2] = 10.0f;
mHdlCube->Scaling = v3d;
mHdlCube1->Scaling = v3d;
mHdlConstraint = FBConstraintManager::TheOne().TypeCreateConstraint("Path");
if( !mHdlConstraint.Ok() ) FBMessageBox("Error", "Unable to create 3D Path constraint! Object will not be constrained.", "Ok");
else
{
mHdlConstraint->ReferenceAdd(0, mHdlCube);
mHdlConstraint->ReferenceAdd(1, mHdlPath);
}
mButtonTest.Caption = "Make visible";
lSceneIsValid = IsSetupValid();
}
break;
case 1:
{
lSceneIsValid = IsSetupValid();
if(lSceneIsValid)
{
mHdlSet->Items.Add(mHdlCube);
mHdlSet->Items.Add(mHdlCube1);
// Make the model visible
mHdlPath->Show = true;
mHdlCube->Show = true;
mHdlCube1->Show = true;
mHdlConstraint->Active = true;
v3d = mHdlCube->Translation;
v3d[1] += 50;
mHdlCube1->Translation = v3d;
mHdlCube1->Parent = mHdlCube;
mHdlConstraint->PropertyList.Find("FollowPath")->SetInt(1);
mButtonTest.Caption = "Remove model";
}
}
break;
case 2:
{
lSceneIsValid = IsSetupValid();
if(lSceneIsValid)
{
// Remove model from visible set
mHdlPath->Show = false;
mHdlCube->Show = false;
mHdlCube1->Show = false;
mHdlConstraint->Active = false;
mButtonTest.Caption = "Delete model";
}
}
break;
case 3:
{
lSceneIsValid = false;
}
break;
}
if(lSceneIsValid)
{
mState=(mState+1) % 4;
}
else
{
ClearSetup();
}
}
/************************************************
* UI Idle callback.
************************************************/
void ORToolPath3D::EventToolIdle( HISender pSender, HKEvent pEvent )
{
}
/************************************************
* Handle tool activation (selection/unselection).
************************************************/
void ORToolPath3D::EventToolShow( HISender pSender, HKEvent pEvent )
{
FBEventShow lEvent( pEvent );
if( lEvent.Shown )
{
// Reset the UI here.
}
else
{
}
}
/************************************************
* Paint callback for tool (on expose).
************************************************/
void ORToolPath3D::EventToolPaint( HISender pSender, HKEvent pEvent )
{
}
/************************************************
* Tool resize callback.
************************************************/
void ORToolPath3D::EventToolResize( HISender pSender, HKEvent pEvent )
{
}
/************************************************
* Handle input into the tool.
************************************************/
void ORToolPath3D::EventToolInput( HISender pSender, HKEvent pEvent )
{
}
/************************************************
* FBX Storage.
************************************************/
bool ORToolPath3D::FbxStore ( FBFbxObject* pFbxObject, kFbxObjectStore pStoreWhat )
{
pFbxObject->FieldWriteBegin( "ORToolPath3DSection" );
{
pFbxObject->FieldWriteC( mButtonTest.Caption );
}
pFbxObject->FieldWriteEnd();
return true;
}
/************************************************
* FBX Retrieval.
************************************************/
bool ORToolPath3D::FbxRetrieve( FBFbxObject* pFbxObject, kFbxObjectStore pStoreWhat )
{
pFbxObject->FieldReadBegin( "ORToolPath3DSection" );
{
mButtonTest.Caption = pFbxObject->FieldReadC();
}
pFbxObject->FieldReadEnd();
return true;
}