/// <summary> /// Process a property for an am_hipConstraint 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 ProcessHipConstraintProperty(GameObject go, string nodeName, string attributeName, System.Object val) { HipConstraint node = GetMayaNodeOnGameObject(nodeName, typeof(HipConstraint), go) as HipConstraint; switch (attributeName) { case "hip": node.hipObjectName = val as string; break; case "hipAimAxis": node.hipAimAxis = (Vector4)val; break; case "hipFrontAxis": node.hipFrontAxis = (Vector4)val; break; case "pelvis": node.pelvisObjectName = val as string; break; case "pelvisAimAxis": node.pelvisAimAxis = (Vector4)val; break; case "pelvisFrontAxis": node.pelvisFrontAxis = (Vector4)val; break; } }
/// <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); } } } }