#include "orconstraintdeformer_constraint.h"
#include "orconstraintdeformer_layout.h"
#define ORCONSTRAINTDEFORMER__CLASS ORCONSTRAINTDEFORMER__CLASSNAME
#define ORCONSTRAINTDEFORMER__NAME "Q-Stretch Deformer"
#define ORCONSTRAINTDEFORMER__LABEL "OR - Q-Stretch Deformer"
#define ORCONSTRAINTDEFORMER__DESC "OR - Q-Stretch Deformation Constraint"
ORCONSTRAINTDEFORMER__CLASS,
ORCONSTRAINTDEFORMER__LABEL,
ORCONSTRAINTDEFORMER__DESC,
template <>
const char* FBPropertyBaseEnum<enum FBAlterPoints>::mStrings[] = {
"kFBAlterPointsEven",
"kFBAlterPointsOdd",
"kFBAlterPointsBoth",
NULL};
bool ORConstraintDeformer::FBCreate()
{
mGroupSource = ReferenceGroupAdd( "Source Object", 1 );
mGroupDeform = ReferenceGroupAdd( "Deform", 1 );
Deformer = true;
HasLayout = true;
mSourceTranslation =
NULL;
mFirstTime = true;
double lDispMultiplier = 0.94;
return true;
}
void ORConstraintDeformer::FBDestroy()
{
}
bool ORConstraintDeformer::ReferenceAddNotify( int pGroupIndex, FBModel* pModel )
{
if ( pGroupIndex==mGroupDeform )
{
DeformerBind(pModel);
}
return true;
}
bool ORConstraintDeformer::ReferenceRemoveNotify( int pGroupIndex, FBModel* pModel )
{
if (pGroupIndex==mGroupDeform)
{
DeformerUnBind(pModel);
}
return true;
}
void ORConstraintDeformer::SetupAllAnimationNodes()
{
if ( ReferenceGet( mGroupSource, 0 ) )
{
}
if ( ReferenceGet( mGroupDeform, 0 ) )
{
}
}
void ORConstraintDeformer::RemoveAllAnimationNodes()
{
}
void ORConstraintDeformer::FreezeSuggested()
{
mFirstTime = true;
if( ReferenceGet( 0, 0) )
{
FreezeSRT( (FBModel*)ReferenceGet( 0, 0), true, true, true );
}
}
bool ORConstraintDeformer::AnimationNodeNotify(FBAnimationNode* pConnector,FBEvaluateInfo* pEvaluateInfo,FBConstraintInfo* pConstraintInfo)
{
double lPosition[3];
if( mSourceTranslation )
{
mSourceTranslation->ReadData ( lPosition, pEvaluateInfo );
mGhostNode->WriteData ( lPosition, pEvaluateInfo );
mPosition = lPosition;
}
return true;
}
bool ORConstraintDeformer::DeformerNotify(FBModel* pModel,
const FBVertex* pSrcVertex,
const FBVertex* pSrcNormal,
int pCount,
FBVertex* pDstVertex,
FBVertex* pDstNormal)
{
if (!mFirstTime)
{
FBSub ( mDelta, mOldPosition, mPosition );
FBAdd ( mDisplacement, mDisplacement, mDelta );
FBMult ( mDisplacement, mDisplacement, DispMultiplier );
for (int Count=0; Count<pCount; Count++)
{
if((AlterPoints==kFBAlterPointsBoth)
|| ((AlterPoints==kFBAlterPointsEven) && Count % 2==0)
|| ((AlterPoints==kFBAlterPointsOdd) && Count % 2==1))
{
double mLength =
FBLength(pSrcVertex[Count]);
pDstVertex[Count][0] = pSrcVertex[Count][0] + mDisplacement[0]*mLength*0.1/mScaling[0];
pDstVertex[Count][1] = pSrcVertex[Count][1] + mDisplacement[1]*mLength*0.1/mScaling[1];
pDstVertex[Count][2] = pSrcVertex[Count][2] + mDisplacement[2]*mLength*0.1/mScaling[2];
} else
{
pDstVertex[Count][0] = pSrcVertex[Count][0];
pDstVertex[Count][1] = pSrcVertex[Count][1];
pDstVertex[Count][2] = pSrcVertex[Count][2];
}
}
}
mOldPosition = mPosition;
if( mFirstTime )
{
mFirstTime = false;
}
return true;
}
bool ORConstraintDeformer::FbxStore( FBFbxObject* pFbxObject,
kFbxObjectStore pStoreWhat )
{
return true;
}
bool ORConstraintDeformer::FbxRetrieve( FBFbxObject* pFbxObject,
kFbxObjectStore pStoreWhat )
{
return true;
}