miscellaneous/model_comp_sel_template/ormodel_model_display.cxx

miscellaneous/model_comp_sel_template/ormodel_model_display.cxx
/***************************************************************************************
Autodesk(R) Open Reality(R) Samples
(C) 2016 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 "ormodel_model_display.h"
FBClassImplementation( ORModelDisplay );
FBStorableCustomModelImplementation( ORModelDisplay, ORMODELDISPLAY__DESCSTR );
/************************************************
* Constructor.
************************************************/
ORModelDisplay::ORModelDisplay( const char* pName, HIObject pObject )
: FBModel( pName, pObject )
, mMesh(NULL)
, mPickedSubItem(-1)
{
mSubComponentSelected[0] = false;
mSubComponentSelected[1] = false;
}
/************************************************
* FiLMBOX Constructor.
************************************************/
bool ORModelDisplay::FBCreate()
{
FBPropertyPublish( this, Scale, "Scale", NULL, NULL );
Scale.SetPropertyValue(20.0);
return true;
}
/************************************************
* FiLMBOX Destructor.
************************************************/
void ORModelDisplay::FBDestroy()
{
}
void ORModelDisplay::CreateGeometry()
{
}
void ORModelDisplay::CustomModelDisplay( FBCamera* pCamera, FBModelShadingMode pShadingMode, FBModelRenderPass pRenderPass, float pPickingAreaWidth, float pPickingAreaHeight)
{
FBViewingOptions* lViewingOptions = FBSystem::TheOne().Renderer->GetViewingOptions();
bool lIsColorBufferPicking = lViewingOptions->IsInColorBufferPicking();
// Request / Release additional uniquecolorId resources.
SetAdditionalUniqueColorIDCount( lIsColorBufferPicking ? 2 : 0);
double lScale = Scale;
glLineWidth(15.0);
glPushAttrib(GL_COLOR_BUFFER_BIT | GL_POLYGON_BIT | GL_TRANSFORM_BIT | GL_LINE_BIT); //Push Current GL states.
{
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
{
FBVector3d T = Translation;
glTranslated(T[0],T[1],T[2]);
if (!lIsColorBufferPicking) // non-picking
{
bool ASelected = (bool)Selected && mSubComponentSelected[0];
bool BSelected = (bool)Selected && mSubComponentSelected[1];
bool allSelected = ASelected && BSelected;
// Draw sub component 0
if (allSelected)
glColor3d(0.0, 1.0, 0.0);
else if (ASelected)
{
glColor3d(0.0,1.0,0.0);
glEnable (GL_LINE_STIPPLE);
glLineStipple (1, 0x0101);
}
else
glColor3d(1.0,1.0,1.0);
glBegin(GL_LINES);
glVertex3d(lScale,0,0);
glVertex3d(lScale,lScale,lScale);
glEnd();
glDisable (GL_LINE_STIPPLE);
// Draw sub component 1
if (allSelected)
glColor3d(0.0, 1.0, 0.0);
else if (BSelected)
{
glColor3d(0.0,1.0,0.0);
glEnable (GL_LINE_STIPPLE);
glLineStipple (1, 0x0101);
}
else
glColor3d(1.0,1.0,1.0);
glBegin(GL_LINES);
glVertex3d(-lScale,0,0);
glVertex3d(-lScale,lScale,lScale);
glEnd();
glDisable (GL_LINE_STIPPLE);
}
else // picking
{
// Draw sub component 0 with ColorID
glColor3dv(GetAdditionalUniqueColorID(0));
glBegin(GL_LINES);
glVertex3d(lScale,0,0);
glVertex3d(lScale,lScale,lScale);
glEnd();
// Draw component 1 with ColorID
glColor3dv(GetAdditionalUniqueColorID(1));
glBegin(GL_LINES);
glVertex3d(-lScale,0,0);
glVertex3d(-lScale,lScale,lScale);
glEnd();
}
}
glPopMatrix();
}
glPopAttrib();
}
bool ORModelDisplay::CustomModelPicking(int pNbHits, unsigned int *pSelectBuffer, FBCamera* pCamera,
int pMouseX,int pMouseY,
FBTVector* localRaySrc, FBTVector* localRayDir,
FBTVector* pWorldRaySrc, FBTVector* pWorldRayDir,
FBMatrix* pGlobalInverseMatrix,
FBTVector* pOutPickedPoint)
{
// no hits
if( pNbHits <= 0)
return false;
mPickedSubItem = -1;
for (int Count=0; Count<pNbHits; Count++)
{
/* Each hit record contains the following information stored as unsigned ints:
* - Number of names in the name stack for this hit record
* - Minimum depth value of primitives (range 0 to 2^32-1)
* - Maximum depth value of primitives (range 0 to 2^32-1)
* - Name stack contents (one name for each unsigned int).
* see http://www.opengl.org/archives/resources/faq/technical/selection.htm
*/
unsigned int NameCount = *pSelectBuffer++;
assert(NameCount == 1);
// Skip two items (Min & Max Depth)
pSelectBuffer+=2;
// Fetch the first name from stack.
unsigned int NameIndex = *pSelectBuffer++;
if(NameIndex==1)
{
mPickedSubItem = 0;
if(pOutPickedPoint)
{
*pOutPickedPoint = FBTVector(100,100,100,0);
}
}
else if(NameIndex==2)
{
mPickedSubItem = 1;
if(pOutPickedPoint)
{
*pOutPickedPoint = FBTVector(-100,100,100,0);
}
}
}
// FBTrace("CustomModelPicking %s SubItem[%d]\n", GetFullName(), mPickedSubItem);
return true;
}
bool ORModelDisplay::ClosestRayIntersection(const FBTVector& pRayOrigin, const FBTVector& pRayEnd, FBTVector& pIntersectPos, FBNormal& pIntersecNormal)
{
// Here we always return the triangle center, user could write real intersection code for production usage.
pIntersectPos = FBTVector(0, 2.0 * Scale / 3.0, 2.0 * Scale / 3.0); //return the center
pIntersecNormal = FBNormal(1, 0, 0);
return true;
}
bool ORModelDisplay::ManipulatorNotify(FBSelectionAction pAction)
{
bool bRetVal = true;
if (FBSystem::TheOne().Renderer->IDBufferPicking)
{
if(pAction == kFBManipulatorReplace ) FBTrace("Replace\n");
if(pAction == kFBManipulatorAdd ) FBTrace("Add\n");
if(pAction == kFBManipulatorRemove ) FBTrace("Remove\n");
if(pAction == kFBManipulatorToggle ) FBTrace("Toggle\n");
if(pAction == kFBManipulatorAddAll ) FBTrace("AddAll\n");
if(pAction == kFBManipulatorRemoveAll) FBTrace("RemoveAll\n");
bool preSelectionState = mSubComponentSelected[0] || mSubComponentSelected[1];
switch(pAction)
{
{
if (pAction == kFBManipulatorReplace)
{
mSubComponentSelected[0] = false;
mSubComponentSelected[1] = false;
}
FBPickInfosList* lPickInfoList = FBCreatePickInfosList();
if (FBSystem::TheOne().Renderer->GetLastPickInfoList(*lPickInfoList))
{
for (int lIndex = 0; lIndex < lPickInfoList->GetCount(); lIndex++)
{
FBPickInfos lPickInfo = lPickInfoList->GetAt(lIndex);
if (lPickInfo.mModel == this)
{
mSubComponentSelected[lPickInfo.mSubItemIndex] = true;
FBTrace(" [%d] = true\n",lPickInfo.mSubItemIndex);
}
}
}
break;
}
{
FBPickInfosList* lPickInfoList = FBCreatePickInfosList();
if (FBSystem::TheOne().Renderer->GetLastPickInfoList(*lPickInfoList))
{
for (int lIndex = 0; lIndex < lPickInfoList->GetCount(); lIndex++)
{
FBPickInfos lPickInfo = lPickInfoList->GetAt(lIndex);
if (lPickInfo.mModel == this)
{
// toggle selection state
// toggle instead of setting the state to false. It is to handle the situation where some sub
// components are of this model are already selected.
if (pAction == kFBManipulatorRemove)
{
mSubComponentSelected[lPickInfo.mSubItemIndex] = false;
FBTrace(" [%d] = true\n",lPickInfo.mSubItemIndex);
} else {
mSubComponentSelected[lPickInfo.mSubItemIndex] = !mSubComponentSelected[lPickInfo.mSubItemIndex];
if (mSubComponentSelected[lPickInfo.mSubItemIndex])
FBTrace(" [%d] = true = !false\n",lPickInfo.mSubItemIndex);
else
FBTrace(" [%d] = false = !true\n",lPickInfo.mSubItemIndex);
}
}
}
}
break;
}
{
mSubComponentSelected[0] = true;
mSubComponentSelected[1] = true;
break;
}
{
mSubComponentSelected[0] = false;
mSubComponentSelected[1] = false;
break;
}
default:
break;
}
bool postSelectionState = mSubComponentSelected[0] || mSubComponentSelected[1];
bRetVal = preSelectionState != postSelectionState;
}
if (bRetVal)
FBTrace(" return true;\n");
else
FBTrace(" return false;\n");
return bRetVal;
}
bool ORModelDisplay::FbxStore(FBFbxObject* pFbxObject, kFbxObjectStore pStoreWhat)
{
return true;
}
bool ORModelDisplay::FbxRetrieve(FBFbxObject* pFbxObject, kFbxObjectStore pStoreWhat)
{
return true;
}