コード例 #1
0
ファイル: ImportMayaNodes.cs プロジェクト: seusman/Paws
    /// <summary>
    /// Process a property for an orientConstraint 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 ProcessOrientConstraintProperty(GameObject go, string nodeName, string attributeName, System.Object val)
    {
        OrientConstraint node = GetMayaNodeOnGameObject(nodeName, typeof(OrientConstraint), go) as OrientConstraint;

        node.constrainedObject = go.transform;
        switch (attributeName)
        {
        case "offset":
            node.offset = (Vector4)val;
            break;

        case "interpType":
            node.interpType = (QuaternionInterpolationMode)int.Parse(val as string);
            break;

        default:
            if (IsConstraintWeightAttribute(attributeName))
            {
                node.InsertTargetUsingWeightAttribute(attributeName, (float)val);
            }
            if (IsConstraintTargetAttribute(attributeName))
            {
                node.InsertTargetUsingTargetAttribute(attributeName, val as string);
            }
            break;
        }
    }
コード例 #2
0
ファイル: ShoulderConstraint.cs プロジェクト: seusman/Paws
 /// <summary>
 /// Add a new twist joint
 /// </summary>
 /// <param name="twistJoint">
 /// A <see cref="OrientConstraint"/>
 /// </param>
 public void AppendTwistJoint(OrientConstraint twistJoint)
 {
     OrientConstraint[] newTwist = new OrientConstraint[twistJoints.Length + 1];
     for (int i = 0; i < twistJoints.Length; i++)
     {
         newTwist[i] = twistJoints[i];
     }
     newTwist[newTwist.Length - 1] = twistJoint;
     twistJoints = newTwist;
     foreach (OrientConstraint twist in twistJoints)
     {
         twist.isInvokedExternally = true;
     }
 }
コード例 #3
0
ファイル: ShoulderConstraint.cs プロジェクト: dermisfit/Paws
	/// <summary>
	/// Add a new twist joint
	/// </summary>
	/// <param name="twistJoint">
	/// A <see cref="OrientConstraint"/>
	/// </param>
	public void AppendTwistJoint(OrientConstraint twistJoint)
	{
		OrientConstraint[] newTwist = new OrientConstraint[twistJoints.Length+1];
		for (int i=0; i<twistJoints.Length; i++)
			newTwist[i] = twistJoints[i];
		newTwist[newTwist.Length-1] = twistJoint;
		twistJoints = newTwist;
		foreach (OrientConstraint twist in twistJoints) twist.isInvokedExternally = true;
	}
コード例 #4
0
ファイル: ImportMayaNodes.cs プロジェクト: seusman/Paws
    /// <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);
                }
            }
        }
    }