Schematic View Relationships

Animatable derived classes can add relationships to schematic view by override the Animatable::SvTraverseAnimGraph() method. In Relationships are added to schematic view during scene traversal. If SvTraverseAnimGraph is already implemented, add your relationship code after the existing code. In our example, the default implementation for controllers (Control::SvTraverseAnimGraph()) is called first. Valid flags to the method Animatable::SvTraverseAnimGraph() are values of type SvRelationshipType.

The following example is taken from maxsdk\samples\controllers\lookat_cnstrnt. cpp.

SvGraphNodeReference LookAtConstRotation::SvTraverseAnimGraph( IGraphObjectManager *gom, Animatable *owner, int id, DWORD flags)
{
     SvGraphNodeReference nodeRef = Control::SvTraverseAnimGraph( gom, owner, id, flags );
    if( nodeRef.stat == SVT_PROCEED ) {
        for( int i=0; i<GetNumTargets(); i++ ) {
             gom->AddRelationship( nodeRef.gNode, GetNode(i), i, RELTYPE_CONSTRAINT );
        }
    }
    return nodeRef;
}

You can provide your own tool-tip to describe the relationship by overriding Animatable::SvGetRelTip().

TSTR LookAtConstRotation::SvGetRelTip( IGraphObjectManager *gom, IGraphNode *gNodeTarget, int id, IGraphNode *gNodeMaker)
{
    return SvGetName(gom, gNodeMaker, false) + " -> " + gNodeTarget->GetAnim()->SvGetName(gom, gNodeTarget, false);
}

Relationships can also be deleted or detached. The following two methods are used to provide detach functionality for the relationship. The id parameter passed into Animatable::SvDetachRel() is the same id passed into IGraphObjectManager::AddRelationship() in Animatable::SvTraverseAnimGraph(). This id could also have been used to identify which relationship to detach.

bool LookAtConstRotation::SvCanDetachRel( IGraphObjectManager *gom, IGraphNode *gNodeTarget, int id, IGraphNode *gNodeMaker)
{
    return true;
}  
bool LookAtConstRotation::SvDetachRel( IGraphObjectManager *gom, IGraphNode *gNodeTarget, int id, IGraphNode *gNodeMaker)
{
    for( int i=0; i<GetNumTargets(); i++ ) {
        if( GetNode(i) == gNodeTarget->GetAnim() ) {
             DeleteTarget(i);
             return true;
        }
    }
    return false;
}

Classes adding relationships can also provide double-click functionality. The Look At Constraint in our example does not implement any double-click functionality. To do this, you would implement the Animatable::SvHandleRelDoubleClick() method. You can use the IGraphObjectManager::GetHWnd() method to use the schematic view as the parent window for your dialog.

bool MyPlugin::SvHandleRelDoubleClick( IGraphObjectManager *gom, IGraphNode *gNodeTarget, int id, IGraphNode *gNodeMaker)
{
    ShowMyDialog( gom->GetHWnd(), gNodeTarget->GetAnim() );
    return true;
}