tools/toolscene/ortoolscene_tool.cxx

tools/toolscene/ortoolscene_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 "ortoolscene_tool.h"
//--- Registration defines
#define ORTOOLSCENE__CLASS ORTOOLSCENE__CLASSNAME
#define ORTOOLSCENE__LABEL "Scene Viewer"
#define ORTOOLSCENE__DESC "OR - Scene Viewer Description"
//--- FiLMBOX implementation and registration
FBToolImplementation( ORTOOLSCENE__CLASS );
FBRegisterTool ( ORTOOLSCENE__CLASS,
ORTOOLSCENE__LABEL,
ORTOOLSCENE__DESC,
FB_DEFAULT_SDK_ICON ); // Icon filename (default=Open Reality icon)
/************************************************
* FiLMBOX Constructor.
************************************************/
bool ORToolScene::FBCreate()
{
StartSize[0] = 600;
StartSize[1] = 300;
// Create/reset/manage UI
UICreate ();
UIConfigure ();
UIReset ();
// Add tool callbacks
OnShow.Add ( this, (FBCallback) &ORToolScene::EventToolShow );
OnIdle.Add ( this, (FBCallback) &ORToolScene::EventToolIdle );
((FBScene*)mSystem.Scene)->OnChange.Add (this, (FBCallback) &ORToolScene::EventSceneChange );
return true;
}
/************************************************
* FiLMBOX Destruction function.
************************************************/
void ORToolScene::FBDestroy()
{
// Remove tool callbacks
OnShow.Remove ( this, (FBCallback) &ORToolScene::EventToolShow );
OnIdle.Remove ( this, (FBCallback) &ORToolScene::EventToolIdle );
((FBScene*)mSystem.Scene)->OnChange.Remove (this, (FBCallback) &ORToolScene::EventSceneChange );
// Free user allocated memory
}
/************************************************
* UI Management
************************************************/
void ORToolScene::UICreate()
{
int lS = 4;
int lW = 200;
// Configure layout
AddRegion( "LabelDirections","LabelDirections",
lS, kFBAttachLeft, "", 1.0,
lS, kFBAttachTop, "", 1.0,
-lS, kFBAttachRight, "", 1.0,
30, kFBAttachTop, "", 1.0 );
AddRegion( "TreeScene", "TreeScene",
lS, kFBAttachLeft, "", 1.0,
lS, kFBAttachBottom, "LabelDirections", 1.0,
lW, kFBAttachNone, NULL, 1.0,
-lS, kFBAttachBottom, "", 1.0 );
AddRegion( "PropertyInspector","PropertyInspector",
1, kFBAttachRight, "TreeScene", 1.0,
0, kFBAttachTop, "TreeScene", 1.0,
-lS, kFBAttachRight, "", 1.0,
0, kFBAttachBottom, "TreeScene", 1.0 );
SetControl( "LabelDirections", mLabelDirections );
SetControl( "TreeScene", mTreeScene );
SetControl( "PropertyInspector", mPI );
}
void ORToolScene::UIConfigure()
{
mLabelDirections.Caption = "This is a tree to browse the different elements in both the scene and the SDK.\n"
"Elements, when selected are viewed in the property inspector on the right.";
mTreeScene.OnSelect.Add( this, (FBCallback) &ORToolScene::EventTreeSelect );
}
void ORToolScene::UIReset()
{
UIResetTree();
}
void ORToolScene::UIRefresh()
{
}
FBArrayTemplate<FBComponent*> ComponentStack;
void ORToolScene::UIResetTree()
{
int lCnt;
// FBScene* lScene = mSystem.Scene;
// lCnt = lScene->Components.GetCount(); // to force the mapping of the whole scene
FBTreeNode* lRoot = mTreeScene.GetRoot();
mTreeScene.Clear();
int i;
FBTreeNode* lSceneNode = mTreeScene.InsertLast( lRoot, "Scene" );
FBTreeNode* lAudioSubNode = mTreeScene.InsertLast( lRoot, "Audio" );
FBTreeNode* lCameraSubNode = mTreeScene.InsertLast( lRoot, "Cameras" );
FBTreeNode* lConstraintNode = mTreeScene.InsertLast( lRoot, "Constraints" );
FBTreeNode* lDevNode = mTreeScene.InsertLast( lRoot, "Devices" );
FBTreeNode* lGroupSubNode = mTreeScene.InsertLast( lRoot, "Groups" );
FBTreeNode* lSetSubNode = mTreeScene.InsertLast( lRoot, "Sets" );
FBTreeNode* lLightSubNode = mTreeScene.InsertLast( lRoot, "Lights" );
FBTreeNode* lMaterialSubNode= mTreeScene.InsertLast( lRoot, "Material" );
FBTreeNode* lPoseSubNode = mTreeScene.InsertLast( lRoot, "Poses" );
FBTreeNode* lShaderSubNode = mTreeScene.InsertLast( lRoot, "Shaders" );
FBTreeNode* lTakeSubNode = mTreeScene.InsertLast( lRoot, "Takes" );
FBTreeNode* lTextureSubNode = mTreeScene.InsertLast( lRoot, "Textures" );
FBTreeNode* lVideoSubNode = mTreeScene.InsertLast( lRoot, "Video" );
FBTreeNode* lFBSDK = mTreeScene.InsertLast( lRoot, "FBSDK" );
FBTreeNode* lSceneSubNode = mTreeScene.InsertLast( lFBSDK, "Scene" );
FBTreeNode* lManipSubNode = mTreeScene.InsertLast( lFBSDK, "Manipulators" );
FBTreeNode* lSystemNode = mTreeScene.InsertLast( lFBSDK, "System" );
FBTreeNode* lRenderSubNode = mTreeScene.InsertLast( lFBSDK, "Render" );
FBTreeNode* lAnimSubNode = mTreeScene.InsertLast( lFBSDK, "Animation" );
FBTreeNode* lStorySubNode = mTreeScene.InsertLast( lFBSDK, "Story" );
FBTreeNode* lFolderSubNode = mTreeScene.InsertLast( lFBSDK, "Folders" );
FBTreeNode* lUnsortedNode = mTreeScene.InsertLast( lFBSDK, "UNSORTED" );
FBTreeNode* lUINode = mTreeScene.InsertLast( lFBSDK, "UI" );
lCnt = FBGetComponentArray().GetCount();
for( i=0; i<lCnt; i++ )
{
FBComponent* lComp = FBGetComponentArray().operator[](i);
ComponentStack.Clear();
if( lComp->Is( FBDevice::TypeInfo ) )
{
AddToTree( lDevNode, lComp );
}
else if( lComp->Is( FBCamera::TypeInfo ) )
{
AddToTree( lCameraSubNode, lComp );
}
else if( lComp->Is( FBLight::TypeInfo )
|| lComp->Is( FBGlobalLight::TypeInfo ) )
{
AddToTree( lLightSubNode, lComp );
}
else if( lComp->Is( FBConstraint::TypeInfo ))
{
AddToTree( lConstraintNode, lComp );
}
else if( lComp->Is( FBPose::TypeInfo ) )
{
AddToTree( lPoseSubNode, lComp );
}
else if( lComp->Is( FBModel::TypeInfo ) )
{
if (FBString(lComp->Name)==FBString("Scene"))
{
AddToTree( lSceneNode, lComp, false );
}
}
else if( lComp->Is( FBShader::TypeInfo ) )
{
AddToTree( lShaderSubNode, lComp );
}
else if(lComp->Is( FBSystem::TypeInfo )
|| lComp->Is( FBApplication::TypeInfo )
|| lComp->Is( FBPlayerControl::TypeInfo )
|| lComp->Is( FBConstraintManager::TypeInfo )
#ifndef K_NO_TRIGGER
|| lComp->Is( FBTriggerManager::TypeInfo )
#endif
)
{
AddToTree( lSystemNode, lComp );
}
else if( lComp->Is( FBScene::TypeInfo ) )
{
AddToTree( lSceneSubNode, lComp, false );
}
else if(lComp->Is( FBRenderer::TypeInfo ))
{
AddToTree( lRenderSubNode, lComp );
}
else if(lComp->Is( FBMaterial::TypeInfo ))
{
AddToTree( lMaterialSubNode, lComp );
}
else if(lComp->Is( FBTexture::TypeInfo ))
{
AddToTree( lTextureSubNode, lComp );
}
else if(lComp->Is( FBVideo::TypeInfo ))
{
AddToTree( lVideoSubNode, lComp );
}
else if(lComp->Is( FBAudioIn::TypeInfo )
|| lComp->Is( FBAudioOut::TypeInfo )
)
{
AddToTree( lAudioSubNode, lComp );
}
else if(lComp->Is( FBStory::TypeInfo ))
{
AddToTree( lStorySubNode, lComp );
}
else if(lComp->Is( FBGroup::TypeInfo ))
{
AddToTree( lGroupSubNode, lComp );
}
else if(lComp->Is( FBSet::TypeInfo ))
{
AddToTree( lSetSubNode, lComp );
}
else if(lComp->Is( FBTake::TypeInfo ))
{
AddToTree( lTakeSubNode, lComp );
}
else if( lComp->Is( FBManipulator::TypeInfo ) )
{
AddToTree( lManipSubNode, lComp );
}
else if( lComp->Is( FBFolder::TypeInfo ) )
{
AddToTree( lFolderSubNode, lComp );
}
else if( lComp->Is( FBVisualComponent::TypeInfo ) )
{
AddToTree( lUINode, lComp );
}
else if(lComp->Is( FBAnimationNode::TypeInfo )
|| lComp->Is( FBFCurve::TypeInfo )
)
{
AddToTree( lAnimSubNode, lComp );
}
else if( !lComp->Is(FBBox::TypeInfo) // Already in a constraint
&& !lComp->Is(FBTreeNode::TypeInfo ) // We don't need that
)
{
AddToTree( lUnsortedNode, lComp );
}
}
}
void ORToolScene::AddToTree( FBTreeNode* pNode, FBComponent* pComp, bool pAddRoot /*=true */ )
{
if( !pComp )
return;
if (ComponentStack.Find( pComp )==-1)
{
ComponentStack.Add( pComp );
FBTreeNode* lNode;
if (pAddRoot)
{
// Add this
lNode = mTreeScene.InsertLast( pNode, pComp->Name );
lNode->Reference = (kReference)pComp;
} else
{
lNode = pNode;
}
// Add children
int i;
int lCnt = pComp->Components.GetCount();
for( i=0; i<lCnt; i++ )
{
FBComponent* lComp = pComp->Components[i];
AddToTree( lNode, lComp );
}
}
}
void ORToolScene::EventSceneChange( HISender pSender, HKEvent pEvent )
{
static bool TransactionStarted = false;
FBEventSceneChange lEvent( pEvent );
switch( lEvent.Type )
{
{
TransactionStarted = true;
}
break;
{
UIResetTree();
TransactionStarted = false;
}
break;
{
if (!TransactionStarted) UIResetTree();
}
break;
{
if (mPI.Component == lEvent.ChildComponent)
{
mPI.Component = NULL;
}
if (!TransactionStarted) UIResetTree();
}
break;
}
}
void ORToolScene::EventTreeSelect( HISender pSender, HKEvent pEvent )
{
FBEventTreeSelect lEvent( pEvent );
FBTreeNode* lNode = lEvent.TreeNode;
FBComponent* lComp = (FBComponent*)(kReference)lNode->Reference;
mPI.Component = lComp;
}
/************************************************
* UI Idle callback.
************************************************/
void ORToolScene::EventToolIdle( HISender pSender, HKEvent pEvent )
{
UIRefresh();
}
/************************************************
* Handle tool activation (selection/unselection).
************************************************/
void ORToolScene::EventToolShow( HISender pSender, HKEvent pEvent )
{
FBEventShow lEvent( pEvent );
if( lEvent.Shown )
{
UIReset();
}
else
{
}
}
/************************************************
* FBX Storage.
************************************************/
bool ORToolScene::FbxStore ( FBFbxObject* pFbxObject, kFbxObjectStore pStoreWhat )
{
pFbxObject->FieldWriteBegin( "ORToolSceneSection" );
{
}
pFbxObject->FieldWriteEnd();
return true;
}
/************************************************
* FBX Retrieval.
************************************************/
bool ORToolScene::FbxRetrieve( FBFbxObject* pFbxObject, kFbxObjectStore pStoreWhat )
{
pFbxObject->FieldReadBegin( "ORToolSceneSection" );
{
}
pFbxObject->FieldReadEnd();
return true;
}