Ejemplo n.º 1
0
    /// <summary>
    /// Process a property for an am_shoulderConstraint node
    /// </summary>
    /// <param name="go">
    /// A <see cref="GameObject"/>
    /// </param>
    /// <param name="nodeName">
    /// A <see cref="System.String"/>
    /// </param>
    /// <param name="attributeName">
    /// A <see cref="System.String"/>
    /// </param>
    /// <param name="val">
    /// A <see cref="System.Object"/>
    /// </param>
    void ProcessShoulderConstraintProperty(GameObject go, string nodeName, string attributeName, System.Object val)
    {
        ShoulderConstraint node = GetMayaNodeOnGameObject(nodeName, typeof(ShoulderConstraint), go) as ShoulderConstraint;

        switch (attributeName)
        {
        case "raisedAngleOffset":
            node.raisedAngleOffset = (float)val;
            break;

        case "shoulder":
            node.shoulderObjectName = val as string;
            break;

        case "shoulderAimAxis":
            node.shoulderAimAxis = (Vector4)val;
            break;

        case "shoulderFrontAxis":
            node.shoulderFrontAxis = (Vector4)val;
            break;

        case "spine":
            node.spineObjectName = val as string;
            break;

        case "spineAimAxis":
            node.spineAimAxis = (Vector4)val;
            break;

        case "spineFrontAxis":
            node.spineFrontAxis = (Vector4)val;
            break;
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Link up components as needed
    /// </summary>
    /// <param name="go">
    /// A <see cref="GameObject"/>
    /// </param>
    void OnPostprocessModel(GameObject go)
    {
        // early out if this is not a source model
        if (!isInSourceModelFolder)
        {
            return;
        }

        // get the whole DAG hierarchy
        Component[] allDagObjects = go.GetComponentsInChildren <Transform>();

        // find all the nodes that have been added as components
        Component[] allMayaNodes = go.GetComponentsInChildren <MayaNode>();

        // link references for nodes
        foreach (MayaNode node in allMayaNodes)
        {
            // see if the node is a constraint node
            if (node.GetType().IsSubclassOf(typeof(MayaConstraint)))
            {
                // link targets
                if ((node as MayaConstraint).targets != null)
                {
                    foreach (MayaConstraint.Target target in (node as MayaConstraint).targets)
                    {
                        foreach (Transform dagObject in allDagObjects)
                        {
                            if (dagObject.name == target.targetName)
                            {
                                target.target = dagObject;
                            }
                        }
                    }
                }

                // aim constraints have a further unique property
                if (node.GetType() == typeof(AimConstraint))
                {
                    foreach (Transform dagObject in allDagObjects)
                    {
                        if (dagObject.name == (node as AimConstraint).worldUpObjectName)
                        {
                            (node as AimConstraint).worldUpObject = dagObject;
                        }
                    }
                }
            }
            // see if the node is an am_exposeTransform node
            else if (node.GetType() == typeof(ExposeTransform))
            {
                // link the object
                (node as ExposeTransform).t = node.transform;
                // link the reference
                foreach (Transform dagObject in allDagObjects)
                {
                    if (dagObject.name == (node as ExposeTransform).referenceName)
                    {
                        (node as ExposeTransform).reference = dagObject;
                    }
                }
            }
            // see if the node is an am_shoulderConstraint node
            else if (node.GetType() == typeof(ShoulderConstraint))
            {
                // link the shoulder and spine objects
                foreach (Transform dagObject in allDagObjects)
                {
                    if (dagObject.name == (node as ShoulderConstraint).shoulderObjectName)
                    {
                        (node as ShoulderConstraint).shoulderObject = dagObject;
                    }
                    if (dagObject.name == (node as ShoulderConstraint).spineObjectName)
                    {
                        (node as ShoulderConstraint).spineObject = dagObject;
                    }
                }
            }
            // see if the node is an am_hipConstraint node
            else if (node.GetType() == typeof(HipConstraint))
            {
                // link the shoulder and spine objects
                foreach (Transform dagObject in allDagObjects)
                {
                    if (dagObject.name == (node as HipConstraint).hipObjectName)
                    {
                        (node as HipConstraint).hipObject = dagObject;
                    }
                    if (dagObject.name == (node as HipConstraint).pelvisObjectName)
                    {
                        (node as HipConstraint).pelvisObject = dagObject;
                    }
                }
            }
        }

        // link up twist joints to their primary controllers to ensure proper evaluation order
        foreach (MayaNode node in allMayaNodes)
        {
            if (node.GetType() == typeof(OrientConstraint) && (node as OrientConstraint).targets.Length == 2)
            {
                OrientConstraint oc = node as OrientConstraint;

                // search for shoulder constraint target
                ShoulderConstraint sc = oc.targets[0].target.GetComponent <ShoulderConstraint>();
                short other           = 1;
                if (sc == null)
                {
                    sc    = oc.targets[other].target.GetComponent <ShoulderConstraint>();
                    other = 0;
                }
                if (sc != null && oc.targets[other].target == sc.shoulderObject)
                {
                    sc.AppendTwistJoint(oc);
                }

                // search for hip constraint target
                HipConstraint hc = oc.targets[0].target.GetComponent <HipConstraint>();
                other = 1;
                if (hc == null)
                {
                    hc    = oc.targets[other].target.GetComponent <HipConstraint>();
                    other = 0;
                }
                if (hc != null && oc.targets[other].target == hc.hipObject)
                {
                    hc.AppendTwistJoint(oc);
                }
            }
        }
    }