constraints/CharacterSolver/HIK2016Solver/orcharactersolver_hik.h

constraints/CharacterSolver/HIK2016Solver/orcharactersolver_hik.h
/***************************************************************************************
Autodesk(R) Open Reality(R) Samples
(C) 2015 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.
***************************************************************************************/
#ifndef __ORCONSTRAINT_HIKBRIDGE_CONSTRAINT_H__
#define __ORCONSTRAINT_HIKBRIDGE_CONSTRAINT_H__
//--- SDK include
#include <fbsdk/fbsdk.h>
#include "hikhostmb.h"
#include "orcharactersolver_hik_manipulator.h"
#include "charactersolverdefinition.h"
/*
Character Constraint
what is not supported yet:
- Story still doing an Internal Retargeting on the Character
what will not be supported:
- MB 5.5 Old Limits.
- No Support for Output Control Rig
*/
#define ORCONSTRAINTHIK__CLASS ORCharacterSolver_HIK
#define ORCONSTRAINTHIK__CLASSNAME "ORCharacterSolver_HIK"
class ORCharacterSolver_HIK : public FBCharacterSolver, public MultiState
{
//--- declaration
FBCharacterSolverDeclare( ORCharacterSolver_HIK, FBCharacterSolver );
public:
//--- Creation & Destruction
virtual bool FBCreate() override;
virtual void FBDestroy() override;
//--- Animation node management
virtual void RemoveAllAnimationNodes() override;
virtual void SetupAllAnimationNodes() override;
virtual void FreezeSuggested() override;
virtual bool AnimationNodeNotify ( FBAnimationNode* pAnimationNode, FBEvaluateInfo* pEvaluateInfo, FBConstraintInfo* pConstraintInfo ) override;
void ControlRigInputEvaluateAndWrite( FBEvaluateInfo* pEvaluateInfo, HIKEvaluationState* pState, const bool pRigAlign, const bool pDoubleSolve, const bool pWriteRig=true, int pDisableSolvingStep=0 );
static void BackgroundEvaluateInfoNotification(const FBAnimationNode* pDst, const FBAnimationNode* pSrc, void* pCustomData);
void ReadDoubleSolve( FBEvaluateInfo* pEvalInfo, HIKEvaluationState* pState );
//--- FBX Interface
virtual bool FbxStore ( FBFbxObject* pFbxObject, kFbxObjectStore pStoreWhat ) override;
virtual bool FbxRetrieve ( FBFbxObject* pFbxObject, kFbxObjectStore pStoreWhat ) override;
virtual double GetCharacterSolverVersion() override { return CHARACTER_SOLVER_VERSION; };
virtual bool PlugNotify(FBConnectionAction pAction,FBPlug* pThis,int pIndex,FBPlug* pPlug = NULL,FBConnectionType pConnectionType=kFBConnectionTypeNone,FBPlug* pNewPlug=NULL ) override;
virtual bool PlugStateNotify(FBConnectionAction pAction,FBPlug* pThis,void* pData=NULL,void* pDataOld=NULL,int pDataSize=0);
HIKEvaluationState* EvaluationStateCreator();
FBPropertyString HIKLibraryVersion;
FBPropertyAnimatableDouble ExtraCollarRatio;
FBPropertyAnimatableDouble CollarStiffnessX;
FBPropertyAnimatableDouble CollarStiffnessY;
FBPropertyAnimatableDouble CollarStiffnessZ;
FBPropertyAnimatableDouble ReachLeftShoulder;
FBPropertyAnimatableDouble ReachRightShoulder;
// new in 4.0
FBPropertyBool FingerSolvingPropagation;
FBPropertyAnimatableDouble RealisticLeftKneeSolving;
FBPropertyAnimatableDouble RealisticRightKneeSolving;
FBPropertyBool RealisticArmSolving;
FBPropertyAnimatableDouble TopSpineCorrection;
FBPropertyAnimatableDouble LowerSpineCorrection;
// SnS
FBPropertyAnimatableDouble StretchStartArmsAndLegs;
FBPropertyAnimatableDouble StretchStopArmsAndLegs;
FBPropertyAnimatableDouble SnSScaleArmsAndLegs;
FBPropertyAnimatableDouble SnSReachLeftWrist;
FBPropertyAnimatableDouble SnSReachRightWrist;
FBPropertyAnimatableDouble SnSReachLeftAnkle;
FBPropertyAnimatableDouble SnSReachRightAnkle;
FBPropertyAnimatableDouble SnSScaleSpineChildren;
FBPropertyAnimatableDouble SnSReachChestEnd;
FBPropertyBool SnSSmoothReach;
// new in 2014
FBPropertyAnimatableDouble SpineMinLength[10];
FBPropertyAnimatableDouble SpineMaxLength[10];
FBPropertyAnimatableDouble NeckMinLength[10];
FBPropertyAnimatableDouble NeckMaxLength[10];
#ifdef _DEBUG
// Debug Helpers
FBPropertyAction ActionSaveHIKCharacter;
FBPropertyAction ActionSaveHIKState;
FBPropertyAction ActionSaveHIKEffectors;
FBPropertyAction ActionSaveHIKProperties;
FBPropertyBool SolvingStepBodyPull;
FBPropertyBool SolvingStepContact;
FBPropertyBool SolvingStepContactApprox;
FBPropertyBool SolvingStepLeftShoulder;
FBPropertyBool SolvingStepRightShoulder;
FBPropertyBool SolvingStepLeftArm;
FBPropertyBool SolvingStepRightArm;
FBPropertyBool SolvingStepLeftLeg;
FBPropertyBool SolvingStepRightLeg;
FBPropertyBool SolvingStepLeftHand;
FBPropertyBool SolvingStepRightHand;
FBPropertyBool SolvingStepLeftFoot;
FBPropertyBool SolvingStepRightFoot;
FBPropertyBool SolvingStepHead;
FBPropertyBool SolvingStepSpine;
FBPropertyBool SolvingStepHipsTranslation;
FBPropertyBool SolvingStepRollExtraction;
FBPropertyBool SolvingStepLeftArmSnS;
FBPropertyBool SolvingStepRightArmSnS;
FBPropertyBool SolvingStepLeftLegSnS;
FBPropertyBool SolvingStepRightLegSnS;
FBPropertyBool SolvingStepModifiers;
FBPropertyBool SolvingStepAllParts;
void InitSolvingProperties();
#endif
void ModifySolvingStep(bool pEnable, int pStep);
// manipulator
virtual FBCharacterManipulatorCtrlSet* CreateCharacterManipulatorCtrlSet(const char* pName) override;
// Exposing Extra FK and Skeleton
virtual int GetExtraFKCount() override;
virtual const char* GetExtraFKNameAt(int pIndex) override;
virtual FBBodyPartId GetExtraFKBodyPartAt(int pIndex) override;
virtual int GetExtraBoneCount() override;
virtual const char* GetExtraBoneNameAt(int pIndex) override;
virtual FBBodyPartId GetExtraBoneBodyPartAt(int pIndex) override;
// Pose support
virtual void CharacterPasteState( FBCharacter* pFromCharacter, FBCharacterPose* pPose, FBCharacterPoseOptions& pCharacterPoseOptions ) override;
// Register solver extra properties
void RegisterExtraProperties(HIKCharacterHost<HIKHostNodeMB,HIKHostPropertyMB> &pHIKCharacterHost);
// Reset solver extra properties
virtual void ResetExtraProperties() override;
static void AddPropertiesToPropertyViewManager();
private:
int mInternalPropertiesCount; //used in referencing properties on character - only solver specific should be created
int mSolverPropertiesCount; //used in referencing properties on character - only solver specific should be created
int mSolvingStepFilter;
HIKCharacter* mHIKCharacter;
public:
HIKCharacterHost<HIKHostNodeMB,HIKHostPropertyMB> mHIKCharacterHost;
private:
HIKCharacter* mHIKCharacterSrc;
HIKCharacterHost<HIKHostNodeMB,HIKHostPropertyMB> mHIKCharacterHostSrc;
HIKControlRigHost<HIKHostNodeMB> mHIKControlRigHost;
HIKCharacter* mHIKActorSrc;
FBActor* mActorSrc;
public:
HIKControlRigHostEvaluator<HIKHostNodeMB,HIKHostPropertyMB> mHIKControlRigHostEvaluator;
HIKCharacterHostEvaluator<HIKHostNodeMB,HIKHostPropertyMB> mHIKCharacterHostEvaluator;
private:
FBCharacterManipulatorCtrlSet* mControlSetManipulator;
// setup of members (character, control rigs, etc)
void SetupTargetCharacter(FBCharacter* pCharacter);
void SetupInputControlRig(FBControlSet* pControlRig, bool pConstraintRig = false );
void SetupAutoProperties(FBCharacter* pCharacter);
void ResetSnSPropertiesVisibility(FBCharacter* lCharacter);
void CreateExtraFKIfNeeded(FBCharacter* pCharacter, int pExtraBoneId, HIKEvaluationState *pStanceState);
// Pose support
// paste HIK pose and candidate on rig. Important where we do it -> pPasteEvaluateInfo
void SolverPasteCharacterPose( HIKCharacter* pHIKCharacter,
HIKEvaluationState* pPasteState, HIKEvaluationState* pCurrentState,
HIKCharacter* pHIKFromCharacter, HIKEvaluationState* pFromState,
FBCharacterPose* pPose, FBCharacterPoseOptions& pCharacterPoseOptions,
FBMatrix& pHipsOffsetGX, FBEvaluateInfo* pPasteEvaluateInfo=FBGetDisplayInfo());
// override parts that should not be paste
void FilterBodyParts( HIKEvaluationState* pPasteState, HIKEvaluationState* pCurrentState );
// character extensions paste prepare and candidate
void DoPasteCharacterExtension(FBCharacterPose* pPose, FBCharacterPoseOptions& pCharacterPoseOptions, HIKEvaluationState* pCurrentState, FBEvaluateInfo* pPasteEvaluateInfo=FBGetDisplayInfo());
//Will apply the translation that were applied on the fk stored in the pose, useful when you have a pose with different limb length
void ApplyFKTranslation( HIKCharacter* pHIKCharacter, HIKEvaluationState* pPasteState, HIKCharacter* pHIKFromCharacter, HIKEvaluationState* lFromState );
//
// Paste pose to temporary hik character, which is a media to be used to get the match model's transformation from pose.
// inputs: pFromCharacter, pPose, pCharacterPoseOptions
// outputs: pHIKFromCharacter, pTempState
//
void PastePoseToTempHikCharacter( FBCharacter* pFromCharacter, FBCharacterPose* pPose, FBCharacterPoseOptions& pCharacterPoseOptions, // inputs
HIKCharacter*& pHIKFromCharacter, HIKEvaluationState* pTempState ); // outputs
// Get match model's offset between current global rotation matrix and pose global rotation matrix.
void GetRotationOffset( const FBMatrix& pMatchModel_GX, const FBMatrix& pMatchMode_PoseTRSM, const FBCharacterPoseOptions& pCharacterPoseOptions, FBMatrix& pHipsOffsetGX );
// Get match model's offset between current global translation matrix and pose global translation matrix.
void GetTranslationOffset( const FBMatrix& pMatchModel_GX, const FBMatrix& pMatchMode_PoseTRSM, const FBCharacterPoseOptions& pCharacterPoseOptions, FBMatrix& pHipsOffsetGX );
// reference properties on destination character
void AddSolverPropertiesToCharacter(FBCharacter* pDstCharacter);
void RemoveSolverPropertiesFromCharacter(FBCharacter* pDstCharacter);
void RenameSolverPropertiesOnCharacters();
void SyncVisibilitySolverPropertiesOnCharacters(FBProperty* pSourceProperty, FBProperty* pRefProperty=NULL);
//Initialize properties with default values
void ResetPropertiesToDefault();
//Clears animation for the properties defined in this class(excludes those defined in the parent classes)
void RemoveAnimations();
// Retarget extension
void RetargetExtensions( FBEvaluateInfo * pEvalInfo );
// Adjust solving step
void AdjustSolvingStep(HIKEvaluationState* pState, int& pDisableSolvingStep);
};
#endif /* __ORCONSTRAINT_HIKBRIDGE_CONSTRAINT_H__ */