Exemple #1
0
    void InitIKFromRig(IKRigConfig rig)
    {
        if (rig == null)
        {
            Debug.LogError("*** Cannot initialize from rig, missing rig. ***");
            return;
        }

        Transform hmdTarget = hmd.transform.Find("CenterEyeAnchor/HeadIKTarget");          //Get the HeadIKTarget that we added to the OVRCameraRig.

        hmdTarget.transform.Rotate(rig.headIKOffset);
        ikLimbTorso = CreateIKLimb(
            "Torso",
            animator.GetBoneTransform(rig.torsoBaseBone),
            animator.GetBoneTransform(rig.torsoJointBone),
            animator.GetBoneTransform(rig.torsoTipBone),
            rig.torsoRotationPolicy,
            rig.torsoFalseBaseParent,
            rig.torsoJointParent,
            rig.torsoJointOffset
            );
        ikLimbTorso.target.parent      = hmdTarget;
        ikLimbTorso.elbowTarget.parent = animator.GetBoneTransform(rig.torsoJointParent);
        if (ikLimbTorso.elbowTarget.parent == null)
        {
            ikLimbTorso.elbowTarget.parent = this.transform;
        }
        ikLimbTorso.IsEnabled = true;
        Debug.Log("- Created Torso from Rig");

        ikLimbLeftHand = CreateIKLimb(
            "LeftArm",
            animator.GetBoneTransform(rig.leftArmBaseBone),
            animator.GetBoneTransform(rig.leftArmJointBone),
            animator.GetBoneTransform(rig.leftArmTipBone),
            rig.leftArmRotationPolicy,
            rig.leftArmFalseBaseParent,
            rig.leftArmJointParent,
            rig.leftArmJointOffset
            );
        ikLimbLeftHand.target.transform.localPosition = Vector3.zero;
        ikLimbLeftHand.target.transform.position     += ikLimbTorso.target.transform.right * -.2f;
        ikLimbLeftHand.IsEnabled = true;
        Debug.Log("- Created LeftArm from Rig.");

        ikLimbRightHand = CreateIKLimb(
            "RightArm",
            animator.GetBoneTransform(rig.rightArmBaseBone),
            animator.GetBoneTransform(rig.rightArmJointBone),
            animator.GetBoneTransform(rig.rightArmTipBone),
            rig.rightArmRotationPolicy,
            rig.rightArmFalseBaseParent,
            rig.rightArmJointParent,
            rig.rightArmJointOffset
            );
        ikLimbRightHand.target.transform.localPosition = Vector3.zero;
        ikLimbRightHand.target.transform.position     += ikLimbTorso.target.transform.right * .2f;
        ikLimbRightHand.IsEnabled = true;
        Debug.Log("- Created RightArm from Rig.");
    }
Exemple #2
0
    IKLimb CreateIKLimb(string name,
                        Transform baseT,
                        Transform jointT,
                        Transform tipT,
                        IKLimb.HandRotations rotationPolicy = IKLimb.HandRotations.KeepLocalRotation,
                        HumanBodyBones falseBaseParent      = HumanBodyBones.LastBone,
                        HumanBodyBones elbowParent          = HumanBodyBones.LastBone,
                        Vector3 elbowOffset = default(Vector3)
                        )
    {
        //Create the IKLimb GameObject
        GameObject go = new GameObject();

        go.name             = "IKLimb" + name;
        go.transform.parent = transform;
        IKLimb limb = go.AddComponent <IKLimb> ();

        //Create the IKLimb Joint Target GameObject
        GameObject jointTarget = new GameObject(name + "JointTarget");

        if (elbowParent != HumanBodyBones.LastBone)
        {
            jointTarget.transform.parent        = animator.GetBoneTransform(elbowParent);
            jointTarget.transform.localPosition = Vector3.zero;
        }
        else
        {
            jointTarget.transform.parent        = this.transform;
            jointTarget.transform.localPosition = Vector3.zero;
        }
        if (elbowOffset != Vector3.zero)
        {
            jointTarget.transform.localPosition += elbowOffset;
        }

        //Create the IKLimb Tip Target GameObject
        GameObject tipTarget = new GameObject(name + "TipTarget");

        tipTarget.transform.parent   = this.transform;
        tipTarget.transform.position = tipT.position;
        tipTarget.transform.rotation = tipT.rotation;

        //Assign all the values to the IKLimb
        if (falseBaseParent != HumanBodyBones.LastBone)
        {
            GameObject fbp = new GameObject("FalseBaseParent");
            fbp.transform.parent = animator.GetBoneTransform(falseBaseParent);
            limb.upperArm        = fbp.transform;
        }
        else
        {
            limb.upperArm = baseT;
        }
        limb.forearm            = jointT;
        limb.hand               = tipT;
        limb.elbowTarget        = jointTarget.transform;
        limb.target             = tipTarget.transform;
        limb.handRotationPolicy = rotationPolicy;
        return(limb);
    }
Exemple #3
0
    /// <summary>
    /// Sets the variables on the IK parts correctly.
    /// </summary>
    public void SetVariablesCorrectly()
    {
        if (model.GetComponent <Animator>() == null)
        {
            return;
        }


        IKLimb lArm = leftArm.GetComponent <IKLimb>();
        IKLimb rArm = rightArm.GetComponent <IKLimb>();


        //left arm
        lArm.upperArm = model.GetComponent <Animator>().GetBoneTransform(HumanBodyBones.LeftUpperArm);
        lArm.forearm  = model.GetComponent <Animator>().GetBoneTransform(HumanBodyBones.LeftLowerArm);
        lArm.hand     = model.GetComponent <Animator>().GetBoneTransform(HumanBodyBones.LeftHand);
        lArm.target   = model.GetComponent <HandIK>().leftHandObj;

        //rightarm
        rArm.upperArm = model.GetComponent <Animator>().GetBoneTransform(HumanBodyBones.RightUpperArm);
        rArm.forearm  = model.GetComponent <Animator>().GetBoneTransform(HumanBodyBones.RightLowerArm);
        rArm.hand     = model.GetComponent <Animator>().GetBoneTransform(HumanBodyBones.RightHand);
        rArm.target   = model.GetComponent <HandIK>().rightHandObj;


        /*
         * //assign some variables
         * IKControl lArm = leftArm.GetComponent<IKControl>();
         * IKControl lHand = leftHand.GetComponent<IKControl>();
         * IKControl rArm = rightArm.GetComponent<IKControl>();
         * IKControl rHand = rightHand.GetComponent<IKControl>();
         *
         *
         * //start with the left arm
         * lArm.forearm = model.GetComponent<Animator>().GetBoneTransform(HumanBodyBones.LeftLowerArm);
         * lArm.hand = model.GetComponent<Animator>().GetBoneTransform(HumanBodyBones.LeftLowerArm);
         * lArm.target = model.GetComponent<Animator>().GetBoneTransform(HumanBodyBones.LeftHand);
         *
         * //then the left hand
         * lHand.forearm = model.GetComponent<Animator>().GetBoneTransform(HumanBodyBones.LeftLowerArm);
         * lHand.hand = model.GetComponent<Animator>().GetBoneTransform(HumanBodyBones.LeftHand);
         * lHand.target = model.GetComponent<HandIK>().leftHandObj;
         *
         * //now the right arm
         * rArm.forearm = model.GetComponent<Animator>().GetBoneTransform(HumanBodyBones.RightLowerArm);
         * rArm.hand = model.GetComponent<Animator>().GetBoneTransform(HumanBodyBones.RightLowerArm);
         * rArm.target = model.GetComponent<Animator>().GetBoneTransform(HumanBodyBones.RightHand);
         *
         * //then the right hand
         * rHand.forearm = model.GetComponent<Animator>().GetBoneTransform(HumanBodyBones.RightLowerArm);
         * rHand.hand = model.GetComponent<Animator>().GetBoneTransform(HumanBodyBones.RightHand);
         * rHand.target = model.GetComponent<HandIK>().rightHandObj;*/
    }
            public AnimationIKNode(PlayableGraph graph)
            {
                ikPlayable = ScriptPlayable <IKAnimationBehavior> .Create(graph);

                ikBehavior = ikPlayable.GetBehaviour();

                leftHand  = new IKLimb(ikBehavior.leftHand);
                rightHand = new IKLimb(ikBehavior.rightHand);
                leftFoot  = new IKLimb(ikBehavior.leftFoot);
                rightFoot = new IKLimb(ikBehavior.rightFoot);
                look      = new IKLook(ikBehavior.look);
            }
    IKLimb CreateIKLimb(string name, 
	                  Transform baseT, 
	                  Transform jointT, 
	                  Transform tipT, 
	                  IKLimb.HandRotations rotationPolicy = IKLimb.HandRotations.KeepLocalRotation, 
	                  HumanBodyBones falseBaseParent = HumanBodyBones.LastBone,
	                  HumanBodyBones elbowParent = HumanBodyBones.LastBone, 
	                  Vector3 elbowOffset = default(Vector3)
	    			)
    {
        //Create the IKLimb GameObject
        GameObject go = new GameObject ();
        go.name = "IKLimb" + name;
        go.transform.parent = transform;
        IKLimb limb = go.AddComponent<IKLimb> ();

        //Create the IKLimb Joint Target GameObject
        GameObject jointTarget = new GameObject (name + "JointTarget");
        if(elbowParent != HumanBodyBones.LastBone){
            jointTarget.transform.parent = animator.GetBoneTransform(elbowParent);
            jointTarget.transform.localPosition = Vector3.zero;
        }else{
            jointTarget.transform.parent = this.transform;
            jointTarget.transform.localPosition = Vector3.zero;
        }
        if(elbowOffset != Vector3.zero){
            jointTarget.transform.localPosition += elbowOffset;
        }

        //Create the IKLimb Tip Target GameObject
        GameObject tipTarget = new GameObject (name + "TipTarget");
        tipTarget.transform.parent = this.transform;
        tipTarget.transform.position = tipT.position;
        tipTarget.transform.rotation = tipT.rotation;

        //Assign all the values to the IKLimb
        if (falseBaseParent != HumanBodyBones.LastBone) {
            GameObject fbp = new GameObject("FalseBaseParent");
            fbp.transform.parent = animator.GetBoneTransform(falseBaseParent);
            limb.upperArm = fbp.transform;
        }else{
            limb.upperArm = baseT;
        }
        limb.forearm = jointT;
        limb.hand = tipT;
        limb.elbowTarget = jointTarget.transform;
        limb.target = tipTarget.transform;
        limb.handRotationPolicy = rotationPolicy;
        return limb;
    }
Exemple #6
0
 // Use this for initialization
 void Start()
 {
     effectComponent = GetComponent <IKLimb>();
     target          = effectComponent.target;
     torchlight      = torch.GetComponent <Light>();
 }
    void InitIKFromRig(IKRigConfig rig)
    {
        if (rig == null) {
            Debug.LogError ("*** Cannot initialize from rig, missing rig. ***");
            return;
        }

        Transform hmdTarget = hmd.transform.Find ("CenterEyeAnchor/HeadIKTarget"); //Get the HeadIKTarget that we added to the OVRCameraRig.
        hmdTarget.transform.Rotate(rig.headIKOffset);
        ikLimbTorso = CreateIKLimb(
            "Torso",
            animator.GetBoneTransform(rig.torsoBaseBone),
            animator.GetBoneTransform(rig.torsoJointBone),
            animator.GetBoneTransform(rig.torsoTipBone),
            rig.torsoRotationPolicy,
            rig.torsoFalseBaseParent,
            rig.torsoJointParent,
            rig.torsoJointOffset
        );
        ikLimbTorso.target.parent = hmdTarget;
        ikLimbTorso.elbowTarget.parent = animator.GetBoneTransform(rig.torsoJointParent);
        if(ikLimbTorso.elbowTarget.parent==null)
            ikLimbTorso.elbowTarget.parent = this.transform;
        ikLimbTorso.IsEnabled = true;
        Debug.Log ("- Created Torso from Rig");

        ikLimbLeftHand = CreateIKLimb (
            "LeftArm",
            animator.GetBoneTransform(rig.leftArmBaseBone),
            animator.GetBoneTransform(rig.leftArmJointBone),
            animator.GetBoneTransform(rig.leftArmTipBone),
            rig.leftArmRotationPolicy,
            rig.leftArmFalseBaseParent,
            rig.leftArmJointParent,
            rig.leftArmJointOffset
        );
        ikLimbLeftHand.target.transform.localPosition = Vector3.zero;
        ikLimbLeftHand.target.transform.position += ikLimbTorso.target.transform.right * -.2f;
        ikLimbLeftHand.IsEnabled = true;
        Debug.Log ("- Created LeftArm from Rig.");

        ikLimbRightHand = CreateIKLimb (
            "RightArm",
            animator.GetBoneTransform(rig.rightArmBaseBone),
            animator.GetBoneTransform(rig.rightArmJointBone),
            animator.GetBoneTransform(rig.rightArmTipBone),
            rig.rightArmRotationPolicy,
            rig.rightArmFalseBaseParent,
            rig.rightArmJointParent,
            rig.rightArmJointOffset
        );
        ikLimbRightHand.target.transform.localPosition = Vector3.zero;
        ikLimbRightHand.target.transform.position += ikLimbTorso.target.transform.right * .2f;
        ikLimbRightHand.IsEnabled = true;
        Debug.Log ("- Created RightArm from Rig.");
    }