constraints/CharacterSolver/CustomMarkerSolver/orcharactersolver_custom.cxx

constraints/CharacterSolver/CustomMarkerSolver/orcharactersolver_custom.cxx
/***************************************************************************************
Autodesk(R) Open Reality(R) Samples
(C) 2013 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 declarations
#include "orcharactersolver_custom.h"
//--- implementation and registration
FBCharacterSolverImplementation ( ORCONSTRAINTCUSTOM__CLASS );
FBRegisterCharacterSolver ( ORCONSTRAINTCUSTOM__NAME,
ORCONSTRAINTCUSTOM__CLASS,
ORCONSTRAINTCUSTOM__LABEL,
ORCONSTRAINTCUSTOM__DESC,
"default.tif" ); // Icon filename (default=Open Reality icon)
bool ORCharacterSolver_Custom::FBCreate()
{
ClearNodes();
return true;
}
void ORCharacterSolver_Custom::FBDestroy()
{
RemoveAllAnimationNodes();
}
void ORCharacterSolver_Custom::AnimationNodeMapping::Setup(FBModel* pModel, FBConstraint* pConstraint, int pIndex)
{
mModel = pModel;
if(mModel)
{
mT = pConstraint->AnimationNodeInCreate(pIndex, mModel, ANIMATIONNODE_TYPE_TRANSLATION);
mR = pConstraint->AnimationNodeInCreate(pIndex, mModel, ANIMATIONNODE_TYPE_ROTATION);
mS = pConstraint->AnimationNodeInCreate(pIndex, mModel, ANIMATIONNODE_TYPE_SCALING);
}
}
void ORCharacterSolver_Custom::AnimationNodeMapping::Write( FBMatrix& pMatrix, FBEvaluateInfo* pEvaluateInfo, bool pWriteT, bool pWriteR, bool pWriteS )
{
if(Valid())
{
FBSVector lS;
FBMatrixToTRS(lT, lR, lS, pMatrix);
if(pWriteT && mT) mT->WriteData(lT.mValue,pEvaluateInfo);
if(pWriteR && mR) mR->WriteData(lR.mValue,pEvaluateInfo);
if(pWriteS && mS) mS->WriteData(lS.mValue,pEvaluateInfo);
}
}
void ORCharacterSolver_Custom::SetupAllAnimationNodes()
{
FBCharacter* lCharacter = TargetCharacter;
if(lCharacter != NULL && lCharacter->GetCharacterize() && AnimationNodeInGet())
{
if(TargetCharacter->InputType == kFBCharacterInputMoCap)
{
FBCharacterMarkerSet* lMarkerSet = TargetCharacter->GetCharacterMarkerSet();
if( lMarkerSet )
{
for( int lBodyNodeId = kFBHipsNodeId; lBodyNodeId < kFBLastNodeId; lBodyNodeId++ )
{
if(lBodyNodeId != kFBReferenceNodeId)
{
mNodes[lBodyNodeId].Setup(lCharacter->GetModel((FBBodyNodeId)lBodyNodeId), this, lBodyNodeId);
}
}
}
}
}
}
void ORCharacterSolver_Custom::RemoveAllAnimationNodes()
{
// all animation Nodes are cleared by the system
ClearNodes();
}
bool ORCharacterSolver_Custom::AnimationNodeNotify(FBAnimationNode* pConnector,FBEvaluateInfo* pEvaluateInfo,FBConstraintInfo* pConstraintInfo)
{
//get state for this evaluation
if(mEvaluateId != pEvaluateInfo->GetEvaluationID())
{
mEvaluateId = pEvaluateInfo->GetEvaluationID();
//character marker set
if(TargetCharacter->InputType == kFBCharacterInputMoCap)
{
// simple logic that retarget goal state onto skeleton
FBCharacterMarkerSet* lMarkerSet = TargetCharacter->GetCharacterMarkerSet();
if(lMarkerSet)
{
FBControlSetState* lFKState = TargetCharacter->GetControlSetEvaluationCache(pEvaluateInfo);
FBEffectorSetState* lIKState = TargetCharacter->GetEffectorEvaluationCache(pEvaluateInfo);
lMarkerSet->ReadCtrlSetAndEffectorState(lFKState,lIKState,pEvaluateInfo);
// plotting directly to control rig was not implemented (check HIK sample for implementation details)
//const bool lPlotToRig = (TargetCharacter->InputType == kFBCharacterOutputMarkerSet || TargetCharacter->IsPlottingActorToCtrlRig());
FBMatrix lGX;
FBMatrix lCtr2Skeleton;
FBRVector lROffset;
for( int lBodyNodeId = kFBHipsNodeId; lBodyNodeId < kFBLastNodeId; lBodyNodeId++ )
{
// get global matrix for body node in control rig space
lFKState->GetNodeMatrix((FBBodyNodeId)lBodyNodeId, lGX);
// conversion from control rig to skeleton space
TargetCharacter->GetROffset((FBBodyNodeId)lBodyNodeId, &lROffset);
FBRotationToMatrix(lCtr2Skeleton, lROffset);
FBMatrixMult(lGX, lGX, lCtr2Skeleton);
// write "solve" on skeleton
mNodes[lBodyNodeId].Write(lGX, pEvaluateInfo, (lBodyNodeId == kFBHipsNodeId));
}
}
}
AnimationNodesOutDisableIfNotWritten(pEvaluateInfo);
}
return true;
}
bool ORCharacterSolver_Custom::FbxStore( FBFbxObject* pFbxObject, kFbxObjectStore pStoreWhat )
{
return true;
}
bool ORCharacterSolver_Custom::FbxRetrieve( FBFbxObject* pFbxObject, kFbxObjectStore pStoreWhat )
{
return true;
}