GetBoneTransform() public method

public GetBoneTransform ( HumanBodyBones humanBoneId ) : Transform
humanBoneId HumanBodyBones
return Transform
Beispiel #1
1
 void Start()
 {
     animator = GetComponent<Animator>();
     bone1 = animator.GetBoneTransform(HumanBodyBones.LeftFoot);
     bone2 = animator.GetBoneTransform(HumanBodyBones.RightFoot);
     shadow = transform.FindChild("Shadow");
     tr = transform;
 }
Beispiel #2
0
 void Start()
 {
     anim = GetComponent<Animator> ();
     x = anim.GetBoneTransform (testBone).localRotation.x;
     y = anim.GetBoneTransform (testBone).localRotation.y;
     z = anim.GetBoneTransform (testBone).localRotation.z;
 }
Beispiel #3
0
    void Start()
    {
        // store the Animator component
        animator = GetComponent<Animator>();
        tpController = GetComponent<ThirdPersonController>();
        // find character chest and hips
        characterChest = animator.GetBoneTransform(HumanBodyBones.Chest);
        characterHips = animator.GetBoneTransform(HumanBodyBones.Hips);

        // set all RigidBodies to kinematic so that they can be controlled with Mecanim
        // and there will be no glitches when transitioning to a ragdoll
        setKinematic(true);
        setCollider(true);

        // find all the transforms in the character, assuming that this script is attached to the root
        Component[] components = GetComponentsInChildren(typeof(Transform));

        // for each of the transforms, create a BodyPart instance and store the transform 
        foreach (Component c in components)
        {
            BodyPart bodyPart = new BodyPart();
            bodyPart.transform = c as Transform;
            bodyParts.Add(bodyPart);
        }
    }
    void Start()
    {
        animator = GetComponent<Animator>();

        leftFoot = animator.GetBoneTransform (HumanBodyBones.LeftFoot);
        rightFoot = animator.GetBoneTransform (HumanBodyBones.RightFoot);

        leftFootRot = leftFoot.rotation;
        rightFootRot = rightFoot.rotation;
    }
Beispiel #5
0
	 // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
	override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
		_components = animator.GetComponent<ComponentsList> ();
		_head = animator.GetBoneTransform (HumanBodyBones.Head);
		_leftHand = animator.GetBoneTransform (HumanBodyBones.LeftHand);
		_rightHand = animator.GetBoneTransform (HumanBodyBones.RightHand);
		_chest = animator.GetBoneTransform (HumanBodyBones.Chest);
		_spine = animator.GetBoneTransform (HumanBodyBones.Spine);
		_slot = _components.inventory._currentSlot;
		UpdateStatePower (animator,stateInfo,layerIndex);
	}
    private Quaternion m_spineDeltaRotation; // The delta rotation of the spine component.
    // private Quaternion m_targetRotation;  // The target rotation of the head?


    // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state.
    override public void OnStateEnter (Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
        m_components = animator.GetComponent<NetworkedRouterOfComponentsForObserver> (); // Query the ComponentList in the gameObject containing the Animator.
        m_head = animator.GetBoneTransform (HumanBodyBones.Head); // Populate the Head component.
        m_spine = animator.GetBoneTransform(HumanBodyBones.Spine); // Populate the Spine component.
        m_chest = animator.GetBoneTransform(HumanBodyBones.Chest); // Populate the Chest component.
        m_leftHand = animator.GetBoneTransform (HumanBodyBones.LeftHand); // Populate the Left Hand (off hand) component.
        m_rightHand = animator.GetBoneTransform (HumanBodyBones.RightHand); // Populate the Right Hand (gun hand) component.
        m_slot = m_components.inventory.m_currentSlot; // Populate from the current inventory slot of PlayerPrefab.
        UpdateStateProgress(animator, stateInfo, layerIndex);
    }
Beispiel #7
0
 void Start()
 {
     animator = GetComponent<Animator>();
     bone1 = animator.GetBoneTransform(HumanBodyBones.LeftFoot);
     bone2 = animator.GetBoneTransform(HumanBodyBones.RightFoot);
     shadow = transform.FindChild("Shadow");
     List<Transform> list = new List<Transform>();
     foreach (Transform tf in GameObject.Find("Enemies").transform)
         list.Add(tf);
     enemies = list.ToArray();
     tr = transform;
 }
    void Awake()
    {
        animator = transform.parent.GetComponent<Animator>();

        //*** Store the initial local bone positions before the animation puts the avatar out of T-pose
        {
            Transform trans = transform.parent;

            initialHeadPos = trans.InverseTransformPoint( animator.GetBoneTransform( HumanBodyBones.Head ).position );

            if ( useNeckBone )
                initialNeckPos = trans.InverseTransformPoint( animator.GetBoneTransform( HumanBodyBones.Neck ).position );

            initialLeftShoulderPos = trans.InverseTransformPoint( animator.GetBoneTransform( HumanBodyBones.LeftUpperArm ).position );
            initialRightShoulderPos = trans.InverseTransformPoint( animator.GetBoneTransform( HumanBodyBones.RightUpperArm ).position );

            initialLeftEllbowPos = trans.InverseTransformPoint( animator.GetBoneTransform( HumanBodyBones.LeftLowerArm ).position );
            initialRightEllbowPos = trans.InverseTransformPoint( animator.GetBoneTransform( HumanBodyBones.RightLowerArm ).position );

            initialLeftHandPos = trans.InverseTransformPoint( animator.GetBoneTransform( HumanBodyBones.LeftHand ).position );
            initialRightHandPos = trans.InverseTransformPoint( animator.GetBoneTransform( HumanBodyBones.RightHand ).position );

            Vector3 averageFootPosition = 0.5f * (animator.GetBoneTransform( HumanBodyBones.LeftFoot ).position +
                                                animator.GetBoneTransform( HumanBodyBones.RightFoot ).position );
            avatarScale = animator.GetBoneTransform( HumanBodyBones.Head ).position.y - averageFootPosition.y;
        }
    }
Beispiel #9
0
	void Start()
	{
		animator = GetComponentInChildren<Animator>();
		leftHand = animator.GetBoneTransform (HumanBodyBones.LeftHand);
		SetUpAnimator();
		
		  
	}
void Awake()
{

animator = transform.parent.GetComponent<Animator>();


transform.parent = animator.GetBoneTransform(HumanBodyBones.Spine).transform;

}
    public ArmBasics(InstantVR ivr, BodySide bodySide_in, BodyMovementsBasics bodyMovements_in)
    {
        this.ivr = ivr;
        animator = ivr.GetComponentInChildren<Animator>();

        this.bodyMovements = bodyMovements_in;
        this.bodySide = bodySide_in;

        if (bodySide_in == BodySide.Left) {
            upperArm = animator.GetBoneTransform(HumanBodyBones.LeftUpperArm);
            forearm = animator.GetBoneTransform(HumanBodyBones.LeftLowerArm);
            hand = animator.GetBoneTransform(HumanBodyBones.LeftHand);

            if (bodyMovements.fromNormLeftHand == Quaternion.identity) {
                bodyMovements.fromNormLeftUpperArm = Quaternion.Inverse(Quaternion.LookRotation(forearm.position - upperArm.position)) * upperArm.rotation;
                bodyMovements.fromNormLeftForearm = Quaternion.Inverse(Quaternion.LookRotation(hand.position - forearm.position)) * forearm.rotation;
                bodyMovements.fromNormLeftHand = Quaternion.Inverse(Quaternion.LookRotation(hand.position - forearm.position)) * hand.rotation;
            }
            if (fromNormHand == Quaternion.identity) {
                fromNormUpperArm = Quaternion.Inverse(Quaternion.LookRotation(forearm.position - upperArm.position)) * upperArm.rotation;
                fromNormForearm = Quaternion.Inverse(Quaternion.LookRotation(hand.position - forearm.position)) * forearm.rotation;
                fromNormHand = Quaternion.Inverse(Quaternion.LookRotation(hand.position - forearm.position)) * hand.rotation;
            }
        } else {
            upperArm = animator.GetBoneTransform(HumanBodyBones.RightUpperArm);
            forearm = animator.GetBoneTransform(HumanBodyBones.RightLowerArm);
            hand = animator.GetBoneTransform(HumanBodyBones.RightHand);

            if (bodyMovements.fromNormRightHand == Quaternion.identity) {
                bodyMovements.fromNormRightUpperArm = Quaternion.Inverse(Quaternion.LookRotation(forearm.position - upperArm.position)) * upperArm.rotation;
                bodyMovements.fromNormRightForearm = Quaternion.Inverse(Quaternion.LookRotation(hand.position - forearm.position)) * forearm.rotation;
                bodyMovements.fromNormRightHand = Quaternion.Inverse(Quaternion.LookRotation(hand.position - forearm.position)) * hand.rotation;
            }
            if (fromNormHand == Quaternion.identity) {
                fromNormUpperArm = Quaternion.Inverse(Quaternion.LookRotation(forearm.position - upperArm.position)) * upperArm.rotation;
                fromNormForearm = Quaternion.Inverse(Quaternion.LookRotation(hand.position - forearm.position)) * forearm.rotation;
                fromNormHand = Quaternion.Inverse(Quaternion.LookRotation(hand.position - forearm.position)) * hand.rotation;
            }
        }

        float upperArmLength = Vector3.Distance(upperArm.position, forearm.position);
        float forearmLength = Vector3.Distance(forearm.position, hand.position);
        length = upperArmLength + forearmLength;

        upperArmStartPosition = upperArm.position;
    }
Beispiel #12
0
        public void CheckConsistency( Animator animator, EyeAndHeadAnimator eyeAndHeadAnimator )
        {
            if ( eyeControl == EyeControl.MecanimEyeBones )
            {
                if ( null == animator )
                    throw new System.Exception("No Animator found.");
                if ( null == animator.GetBoneTransform(HumanBodyBones.LeftEye) || null == animator.GetBoneTransform(HumanBodyBones.LeftEye) )
                    throw new System.Exception("Mecanim humanoid eye bones not found.");

                if ( false == isEyeBoneDefaultSet )
                    SaveDefault( eyeAndHeadAnimator );
            }
            else if ( eyeControl == EyeControl.SelectedObjects )
            {
                if ( null == leftEye )
                    throw new System.Exception("The left eye object hasn't been assigned.");
                if ( null == rightEye )
                    throw new System.Exception("The right eye object hasn't been assigned.");

                if ( false == isEyeBallDefaultSet )
                    SaveDefault( eyeAndHeadAnimator );
            }

            if ( eyelidControl == EyelidControl.Bones )
            {
                if ( upperEyeLidLeft == null || upperEyeLidRight == null )
                    throw new System.Exception("The upper eyelid bones haven't been assigned.");
                if ( false == isEyelidBonesDefaultSet )
                    throw new System.Exception("The default eyelid position hasn't been saved.");
                if ( false == isEyelidBonesClosedSet )
                    throw new System.Exception("The eyes closed eyelid position hasn't been saved.");
                if ( false == isEyelidBonesLookUpSet )
                    throw new System.Exception("The eyes look up eyelid position hasn't been saved.");
                if ( false == isEyelidBonesLookDownSet )
                    throw new System.Exception("The eyes look down eyelid position hasn't been saved.");
             }
             else if ( eyelidControl == EyelidControl.Blendshapes )
             {
                if ( false == isEyelidBlendshapeDefaultSet )
                    throw new System.Exception("The default eyelid position hasn't been saved.");
                if ( false == isEyelidBlendshapeClosedSet )
                    throw new System.Exception("The eyes closed eyelid position hasn't been saved.");
                if ( false == isEyelidBlendshapeLookUpSet )
                    throw new System.Exception("The eyes look up eyelid position hasn't been saved.");
                if ( false == isEyelidBlendshapeLookDownSet )
                    throw new System.Exception("The eyes look down eyelid position hasn't been saved.");
            }
        }
Beispiel #13
0
    private bool GetModelBoneLength(Animator animatorComponent, HumanBodyBones baseJoint, HumanBodyBones endJoint, ref float length)
    {
        length = 0f;

        if(animatorComponent)
        {
            Transform joint1 = animatorComponent.GetBoneTransform(baseJoint);
            Transform joint2 = animatorComponent.GetBoneTransform(endJoint);

            if(joint1 && joint2)
            {
                length = (joint2.position - joint1.position).magnitude;
                return true;
            }
        }

        return false;
    }
Beispiel #14
0
    private bool GetModelBodyHeight(Animator animatorComponent, ref float height)
    {
        height = 0f;

        if(animatorComponent)
        {
            //Transform hipCenter = animatorComponent.GetBoneTransform(HumanBodyBones.Hips);

            Transform leftUpperArm = animatorComponent.GetBoneTransform(HumanBodyBones.LeftUpperArm);
            Transform rightUpperArm = animatorComponent.GetBoneTransform(HumanBodyBones.RightUpperArm);

            Transform leftUpperLeg = animatorComponent.GetBoneTransform(HumanBodyBones.LeftUpperLeg);
            Transform rightUpperLeg = animatorComponent.GetBoneTransform(HumanBodyBones.RightUpperLeg);

            if(leftUpperArm && rightUpperArm && leftUpperLeg && rightUpperLeg)
            {
                Vector3 posShoulderCenter = (leftUpperArm.position + rightUpperArm.position) / 2;
                Vector3 posHipCenter = (leftUpperLeg.position + rightUpperLeg.position) / 2;  // hipCenter.position

                height = (posShoulderCenter.y - posHipCenter.y);

                return true;
            }
        }

        return false;
    }
 // Returns the Muscle.Group of the specified bone Transform (only if using the Humanoid rig)
 private static Muscle.Group FindGroup(Animator animator, Transform t)
 {
     if (!animator.isHuman) return Muscle.Group.Hips;
     if (t == animator.GetBoneTransform(HumanBodyBones.Chest)) return Muscle.Group.Spine;
     if (t == animator.GetBoneTransform(HumanBodyBones.Head)) return Muscle.Group.Head;
     if (t == animator.GetBoneTransform(HumanBodyBones.Hips)) return Muscle.Group.Hips;
     if (t == animator.GetBoneTransform(HumanBodyBones.LeftFoot)) return Muscle.Group.Foot;
     if (t == animator.GetBoneTransform(HumanBodyBones.LeftHand)) return Muscle.Group.Hand;
     if (t == animator.GetBoneTransform(HumanBodyBones.LeftLowerArm)) return Muscle.Group.Arm;
     if (t == animator.GetBoneTransform(HumanBodyBones.LeftLowerLeg)) return Muscle.Group.Leg;
     if (t == animator.GetBoneTransform(HumanBodyBones.LeftUpperArm)) return Muscle.Group.Arm;
     if (t == animator.GetBoneTransform(HumanBodyBones.LeftUpperLeg)) return Muscle.Group.Leg;
     if (t == animator.GetBoneTransform(HumanBodyBones.RightFoot)) return Muscle.Group.Foot;
     if (t == animator.GetBoneTransform(HumanBodyBones.RightHand)) return Muscle.Group.Hand;
     if (t == animator.GetBoneTransform(HumanBodyBones.RightLowerArm)) return Muscle.Group.Arm;
     if (t == animator.GetBoneTransform(HumanBodyBones.RightLowerLeg)) return Muscle.Group.Leg;
     if (t == animator.GetBoneTransform(HumanBodyBones.RightUpperArm)) return Muscle.Group.Arm;
     if (t == animator.GetBoneTransform(HumanBodyBones.RightUpperLeg)) return Muscle.Group.Leg;
     return Muscle.Group.Spine;
 }
Beispiel #16
0
        //**********************************************************************************//
        // INITIAL SETUP 																	//
        // prepare the initial information for capsule collider, physics materials, etc...  //
        //**********************************************************************************//
        public void InitialSetup()
        {
            animator = GetComponent<Animator>();

            tpCamera = TPCamera.instance;
            // create a offset pivot to the character, to align camera position when transition to ragdoll
            var hips = animator.GetBoneTransform(HumanBodyBones.Hips);
            offSetPivot = Vector3.Distance(transform.position, hips.position);
            tpCamera.offSetPlayerPivot = offSetPivot;

            if (hud == null) Debug.Log("Missing HUDController, please assign on ThirdPersonController");

            // prevents the collider from slipping on ramps
            frictionPhysics = new PhysicMaterial();
            frictionPhysics.name = "frictionPhysics";
            frictionPhysics.staticFriction = 0.6f;
            frictionPhysics.dynamicFriction = 0.6f;

            // default physics
            defaultPhysics = new PhysicMaterial();
            defaultPhysics.name = "defaultPhysics";
            defaultPhysics.staticFriction = 0f;
            defaultPhysics.dynamicFriction = 0f;

            // rigidbody info
            _rigidbody = GetComponent<Rigidbody>();

            // capsule collider
            capsuleCollider = GetComponent<CapsuleCollider>();

            // save your collider preferences
            colliderCenter = GetComponent<CapsuleCollider>().center;
            colliderRadius = GetComponent<CapsuleCollider>().radius;
            colliderHeight = GetComponent<CapsuleCollider>().height;

            currentHealth = startingHealth;
            currentStamina = startingStamina;

            if (hud == null)
                return;

            hud.damageImage.color = new Color(0f, 0f, 0f, 0f);
        }
        public Leg(ArmBasics.BodySide bodySide_in, Animator animator, Transform characterTransform_in)
        {
            characterTransform = characterTransform_in;

            if (bodySide_in == ArmBasics.BodySide.Left) {
                upperLeg = animator.GetBoneTransform(HumanBodyBones.LeftUpperLeg);
                lowerLeg = animator.GetBoneTransform(HumanBodyBones.LeftLowerLeg);
                foot = animator.GetBoneTransform(HumanBodyBones.LeftFoot);
            } else {
                upperLeg = animator.GetBoneTransform(HumanBodyBones.RightUpperLeg);
                lowerLeg = animator.GetBoneTransform(HumanBodyBones.RightLowerLeg);
                foot = animator.GetBoneTransform(HumanBodyBones.RightFoot);
            }

            fromNormUpperLeg = Quaternion.Inverse(Quaternion.LookRotation (foot.position - upperLeg.position, characterTransform.forward)) * upperLeg.rotation;
            fromNormLowerLeg = Quaternion.Inverse(Quaternion.LookRotation(foot.position - lowerLeg.position, characterTransform.forward)) * lowerLeg.rotation;
            fromNormFoot = Quaternion.Inverse(Quaternion.LookRotation (characterTransform.forward)) * foot.rotation;

            upperLegLength = Vector3.Distance(upperLeg.position, lowerLeg.position);
            lowerLegLength = Vector3.Distance(lowerLeg.position, foot.position);

            upperLegLength2 = upperLegLength * upperLegLength;
            lowerLegLength2 = lowerLegLength * lowerLegLength;
        }
        /// <summary>
        /// Setups the model.
        /// Bind the model with the animation.
        /// This funciton will use Macanim animator to find the right bones, 
        /// then it will store it in an array by animation segment id
        /// </summary>
        /// <param name='model'>
        /// Model.
        /// </param>
        /// <param name='modelRef'>
        /// Model reference.
        /// </param>
        /// <returns>
        /// true on success
        /// </returns>
        public bool setupModel(Transform model, Transform[] modelRef)
        {
            animator = model.GetComponent("Animator") as Animator;
            if (!animator)
            {
                Debug.LogError("[xsens] No Animator component found for the model! You need to have an Animator attached to your model!");
                return false;
            }

            //face the input model same as our animation
            model.rotation = transform.rotation;
            model.position = transform.position;

            //go through the model's segments and store values
            for (int i = 0; i < XsMvnPose.MvnSegmentCount; i++)
            {

                XsAnimationSegment segID = (XsAnimationSegment)segmentOrder[i];
                HumanBodyBones boneID = mecanimBones[(XsAnimationSegment)segmentOrder[i]];

                try
                {

                    if (boneID == HumanBodyBones.LastBone)
                    {
                        //not used bones
                        modelRef[(int)segID] = null;
                        modelPosTP[(int)segID] = Vector3.zero;
                        modelRotTP[(int)segID] = Quaternion.Euler(Vector3.zero);

                    }
                    else
                    {
                        //used bones
                        modelRef[(int)segID] = animator.GetBoneTransform(boneID);
                        modelPosTP[(int)segID] = modelRef[(int)segID].position;
                        modelRotTP[(int)segID] = modelRef[(int)segID].rotation;
                    }
                }
                catch (Exception e)
                {
                    Debug.Log("[xsens] Can't find " + boneID + " in the model! " + e);
                    modelRef[(int)segID] = null;
                    modelPosTP[(int)segID] = Vector3.zero;
                    modelRotTP[(int)segID] = Quaternion.Euler(Vector3.zero);

                    return false;
                }

            }

            //calculate simple scale factor
            scale = (float)(modelPosTP[(int)XsAnimationSegment.Pelvis].y / pelvisPosTP.y);

            return true;
        }
Beispiel #19
0
    // This script should actually be moved to the main thing, honestly. And various
    // things should be edited to reflect that. Use anim.GetBoneTransform instead
    void Start()
    {
        anim = GetComponent<Animator>();
        decapitate = GetComponent<NoHead>();
        // set up listener
        string filename = @"./output.txt";
        FileStream traceLog;
        if (logging)
        {
            traceLog = new FileStream(filename, FileMode.OpenOrCreate);
            listener = new TextWriterTraceListener(traceLog);
        }

        headTransform = anim.GetBoneTransform(HumanBodyBones.Head);
        neckTransform = anim.GetBoneTransform(HumanBodyBones.Neck);
        spineTransform = anim.GetBoneTransform(HumanBodyBones.Spine);
        cameraRigTransform = headTransform.Find("CameraRig");
        cameraTransform = cameraRigTransform.Find("Camera");

        initHeadRot = headTransform.localRotation.eulerAngles;
    }
Beispiel #20
0
    void Start()
    {
        player	= (GameObject)this.gameObject;
        anim	= GetComponent<Animator>();
        Hips	= anim.GetBoneTransform(HumanBodyBones.Hips);

        _speed = speed;
        isGrounded = true;
        isJumped = false;
    }
 /// <summary>
 /// Capsule Collider height based on the Character height
 /// </summary>
 /// <param name="animator">animator humanoid</param>
 /// <returns></returns>
 float ColliderHeight(Animator animator)
 {
     var foot = animator.GetBoneTransform(HumanBodyBones.LeftFoot);
     var hips = animator.GetBoneTransform(HumanBodyBones.Hips);
     return (float) System.Math.Round(Vector3.Distance(foot.position, hips.position) * 2f, 2);
 }
		public void Initialize()
		{
			if ( isInitialized )
				return;

			if ( controlData == null )
				return;

			eyeDistance = 0.064f;
			animator = GetComponentInChildren<Animator>();
			#if USE_FINAL_IK
				lookAtIK = GetComponentInChildren<RootMotion.FinalIK.LookAtIK>();
			#endif

			controlData.CheckConsistency( animator, this );
			controlData.Initialize( );

			if ( createdTargetXforms[0] == null )
			{
				createdTargetXforms[0] = new GameObject(name + "_createdEyeTarget_1").transform;
				DestroyNotifier destroyNotifer = createdTargetXforms[0].gameObject.AddComponent<DestroyNotifier>();
				destroyNotifer.OnDestroyedEvent += OnCreatedXformDestroyed;
				DontDestroyOnLoad(createdTargetXforms[0].gameObject);
				createdTargetXforms[0].gameObject.hideFlags = HideFlags.HideInHierarchy;
			}

			if ( createdTargetXforms[1] == null )
			{
				createdTargetXforms[1] = new GameObject(name + "_createdEyeTarget_2").transform;
				DestroyNotifier destroyNotifer = createdTargetXforms[1].gameObject.AddComponent<DestroyNotifier>();
				destroyNotifer.OnDestroyedEvent += OnCreatedXformDestroyed;
				DontDestroyOnLoad(createdTargetXforms[1].gameObject);
				createdTargetXforms[1].gameObject.hideFlags = HideFlags.HideInHierarchy;
			}


			Transform headXform=null;
			if (animator != null)
				headXform = animator.GetBoneTransform(HumanBodyBones.Head);
			#if USE_FINAL_IK
				if ( headXform == null && lookAtIK != null )
					headXform = lookAtIK.solver.head.transform;
			#endif
			if ( headXform == null )
				headXform = transform;

			Transform spineXform = null;
			if ( animator != null )
			{
				spineXform = animator.GetBoneTransform(HumanBodyBones.Chest);
				if ( spineXform == null )
					spineXform = animator.GetBoneTransform(HumanBodyBones.Spine);
			}
			if ( spineXform == null )
				spineXform = transform;

			if ( headParentXform == null )
			{
				headParentXform = new GameObject(name + " head parent").transform;
				headParentXform.gameObject.hideFlags = HideFlags.HideInHierarchy;
				headParentXform.parent = spineXform;
				headParentXform.position = headXform.position;
				headParentXform.rotation = transform.rotation;
			}

			if ( headTargetPivotXform == null )
			{
				headTargetPivotXform = new GameObject(name + " head target").transform;
				headTargetPivotXform.gameObject.hideFlags = HideFlags.HideInHierarchy;
				headTargetPivotXform.parent = headParentXform;
				headTargetPivotXform.localPosition = Vector3.zero;
				headTargetPivotXform.localRotation = Quaternion.identity;

				critDampTween = new CritDampTweenQuaternion(headTargetPivotXform.localRotation, kHeadOmega, kMaxHeadVelocity);
 				lastHeadEuler = headTargetPivotXform.localEulerAngles;
			}

			//*** Eyes
			{
				if ( controlData.eyeControl == ControlData.EyeControl.MecanimEyeBones || controlData.eyeControl == ControlData.EyeControl.SelectedObjects )
				{
					if ( controlData.eyeControl == ControlData.EyeControl.MecanimEyeBones )
					{
						Transform leftEyeBoneXform = animator.GetBoneTransform(HumanBodyBones.LeftEye);
						Transform rightEyeBoneXform = animator.GetBoneTransform(HumanBodyBones.RightEye);
						leftEyeAnchor = leftEyeBoneXform;
						rightEyeAnchor = rightEyeBoneXform;
						if ( leftEyeAnchor == null )
							Debug.LogError("Left eye bone not found in Mecanim rig");
						if ( rightEyeAnchor == null )
							Debug.LogError("Right eye bone not found in Mecanim rig");
					}
					else if ( controlData.eyeControl == ControlData.EyeControl.SelectedObjects )
					{
						leftEyeAnchor = controlData.leftEye;
						rightEyeAnchor = controlData.rightEye;
					}
				}

				if ( eyesRootXform == null )
				{
					eyesRootXform = new GameObject(name + "_eyesRoot").transform;
					eyesRootXform.gameObject.hideFlags = HideFlags.HideInHierarchy;
					eyesRootXform.rotation = transform.rotation;
				}

				if ( leftEyeAnchor != null && rightEyeAnchor != null )
				{
					eyeDistance = Vector3.Distance( leftEyeAnchor.position, rightEyeAnchor.position );
					eyeDistanceScale = eyeDistance/0.064f;
					controlData.RestoreDefault();
					Quaternion inverse = Quaternion.Inverse(eyesRootXform.rotation);
					leftEyeRootFromAnchorQ = inverse * leftEyeAnchor.rotation;
					rightEyeRootFromAnchorQ = inverse * rightEyeAnchor.rotation;
					leftAnchorFromEyeRootQ = Quaternion.Inverse(leftEyeRootFromAnchorQ);
					rightAnchorFromEyeRootQ = Quaternion.Inverse(rightEyeRootFromAnchorQ);

					originalLeftEyeLocalQ = leftEyeAnchor.localRotation;
					originalRightEyeLocalQ = rightEyeAnchor.localRotation;

					eyesRootXform.position = 0.5f * (leftEyeAnchor.position + rightEyeAnchor.position);
					Transform commonAncestorXform = Utils.GetCommonAncestor( leftEyeAnchor, rightEyeAnchor );
					eyesRootXform.parent =  (commonAncestorXform != null) ? commonAncestorXform : leftEyeAnchor.parent;
				}
				else if ( animator != null )
				{
					if ( headXform != null )
					{
						eyesRootXform.position = headXform.position;
						eyesRootXform.parent = headXform;
					}
					else
					{
						eyesRootXform.position = transform.position;
						eyesRootXform.parent = transform;
					}
				}
				else
				{
					eyesRootXform.position = transform.position;
					eyesRootXform.parent = transform;
				}
			}


			//*** Eye lids
			{
				if ( controlData.eyelidControl == ControlData.EyelidControl.Bones )
				{
					if ( controlData.upperEyeLidLeft != null && controlData.upperEyeLidRight != null )
						useUpperEyelids = true;

					if ( controlData.lowerEyeLidLeft != null && controlData.lowerEyeLidRight != null )
						useLowerEyelids = true;
				}

				blink01 = 0;
				timeOfNextBlink = Time.time + Random.Range(3f, 6f);
				ikWeight = headWeight;
			}

			isInitialized = true;
		}
		/// <summary>
		/// Fills in BipedReferences using Animator.GetBoneTransform().
		/// </summary>
		public static void AssignHumanoidReferences(ref BipedReferences references, Animator animator, AutoDetectParams autoDetectParams) {
			if (references == null) references = new BipedReferences();

			if (animator == null || !animator.isHuman) return;
			
			references.spine = new Transform[0];
			references.eyes = new Transform[0];
			
			references.head = animator.GetBoneTransform(HumanBodyBones.Head);
			
			references.leftThigh = animator.GetBoneTransform(HumanBodyBones.LeftUpperLeg);
			references.leftCalf = animator.GetBoneTransform(HumanBodyBones.LeftLowerLeg);
			references.leftFoot = animator.GetBoneTransform(HumanBodyBones.LeftFoot);
			
			references.rightThigh = animator.GetBoneTransform(HumanBodyBones.RightUpperLeg);
			references.rightCalf = animator.GetBoneTransform(HumanBodyBones.RightLowerLeg);
			references.rightFoot = animator.GetBoneTransform(HumanBodyBones.RightFoot);
			
			references.leftUpperArm = animator.GetBoneTransform(HumanBodyBones.LeftUpperArm);
			references.leftForearm = animator.GetBoneTransform(HumanBodyBones.LeftLowerArm);
			references.leftHand = animator.GetBoneTransform(HumanBodyBones.LeftHand);
			
			references.rightUpperArm = animator.GetBoneTransform(HumanBodyBones.RightUpperArm);
			references.rightForearm = animator.GetBoneTransform(HumanBodyBones.RightLowerArm);
			references.rightHand = animator.GetBoneTransform(HumanBodyBones.RightHand);
			
			references.pelvis = animator.GetBoneTransform(HumanBodyBones.Hips);
			
			AddBoneToHierarchy(ref references.spine, animator.GetBoneTransform(HumanBodyBones.Spine));
			AddBoneToHierarchy(ref references.spine, animator.GetBoneTransform(HumanBodyBones.Chest));
			
			// Make sure the neck bone is not above the arms
			if (references.leftUpperArm != null) {
				if (!IsNeckBone(animator.GetBoneTransform(HumanBodyBones.Neck), references.leftUpperArm)) AddBoneToHierarchy(ref references.spine, animator.GetBoneTransform(HumanBodyBones.Neck));
			}
			
			if (autoDetectParams.includeEyes) {
				AddBoneToHierarchy(ref references.eyes, animator.GetBoneTransform(HumanBodyBones.LeftEye));
				AddBoneToHierarchy(ref references.eyes, animator.GetBoneTransform(HumanBodyBones.RightEye));
			}
		}
Beispiel #24
0
    // Use this for initialization
    void Start()
    {
        Wilson = GameObject.Find ("Wilson");
        Diana = GameObject.Find ("Diana");
        animator = Wilson.GetComponent<Animator> ();
        relationTracker = GameObject.Find ("BehaviorController").GetComponent<RelationTracker> ();
        eventManager = GameObject.Find ("BehaviorController").GetComponent<EventManager> ();

        leftGrasper = animator.GetBoneTransform (HumanBodyBones.LeftHand).transform.gameObject;
        rightGrasper = animator.GetBoneTransform (HumanBodyBones.RightHand).transform.gameObject;

        graspController = Wilson.GetComponent<GraspScript> ();

        ikControl = Wilson.GetComponent<IKControl> ();
        leftTarget = ikControl.leftHandObj.GetComponent<IKTarget> ();
        rightTarget = ikControl.rightHandObj.GetComponent<IKTarget> ();
        headTarget = ikControl.lookObj.GetComponent<IKTarget> ();

        outputModality = GameObject.Find ("OutputModality").GetComponent<OutputModality>();

        goBack = false;

        currentStep = DemoStep.Step0;
        waitTimer = new Timer (WAIT_TIME);
        waitTimer.Enabled = false;
        waitTimer.Elapsed += Proceed;

        humanMoveComplete = false;
        leftAtTarget = false;
        rightAtTarget = false;
        eventManager.EventComplete += HumanMoveComplete;
        leftTarget.AtTarget += LeftAtTarget;
        rightTarget.AtTarget += RightAtTarget;
    }
        public static BipedRagdollReferences FromAvatar(Animator animator)
        {
            BipedRagdollReferences r = new BipedRagdollReferences();

            if (!animator.isHuman) return r;

            r.root = animator.transform;

            r.hips = animator.GetBoneTransform(HumanBodyBones.Hips);
            r.spine = animator.GetBoneTransform(HumanBodyBones.Spine);
            r.chest = animator.GetBoneTransform(HumanBodyBones.Chest);
            r.head = animator.GetBoneTransform(HumanBodyBones.Head);

            r.leftUpperArm = animator.GetBoneTransform(HumanBodyBones.LeftUpperArm);
            r.leftLowerArm = animator.GetBoneTransform(HumanBodyBones.LeftLowerArm);
            r.leftHand = animator.GetBoneTransform(HumanBodyBones.LeftHand);

            r.rightUpperArm = animator.GetBoneTransform(HumanBodyBones.RightUpperArm);
            r.rightLowerArm = animator.GetBoneTransform(HumanBodyBones.RightLowerArm);
            r.rightHand = animator.GetBoneTransform(HumanBodyBones.RightHand);

            r.leftUpperLeg = animator.GetBoneTransform(HumanBodyBones.LeftUpperLeg);
            r.leftLowerLeg = animator.GetBoneTransform(HumanBodyBones.LeftLowerLeg);
            r.leftFoot = animator.GetBoneTransform(HumanBodyBones.LeftFoot);

            r.rightUpperLeg = animator.GetBoneTransform(HumanBodyBones.RightUpperLeg);
            r.rightLowerLeg = animator.GetBoneTransform(HumanBodyBones.RightLowerLeg);
            r.rightFoot = animator.GetBoneTransform(HumanBodyBones.RightFoot);

            return r;
        }
Beispiel #26
0
		private void ExtractHumanInfo(Animator animator, List<HumanBone> humanInfoList)
	    {
	        for (int i = 0; i < HumanTrait.BoneCount; i++)
	        {
	            var boneTransform = animator.GetBoneTransform((HumanBodyBones)i);
	            if (boneTransform != null)
	            {
	                humanInfoList.Add(new HumanBone() { boneName = boneTransform.name, humanName = HumanTrait.BoneName[i], limit = new HumanLimit() { useDefaultValues = true } });
	            }
	        }
	    }
Beispiel #27
0
    public void Initialize(InstantVR ivr, BodySide bodySide, IVR_BodyMovements bodyMovements) {
        this.ivr = ivr;

        this.bodySide = bodySide;
        animator = ivr.GetComponentInChildren<Animator>();

        if (bodySide == BodySide.Left) {
            upperArm = animator.GetBoneTransform(HumanBodyBones.LeftUpperArm);
            forearm = animator.GetBoneTransform(HumanBodyBones.LeftLowerArm);
            hand = animator.GetBoneTransform(HumanBodyBones.LeftHand);
        } else {
            upperArm = animator.GetBoneTransform(HumanBodyBones.RightUpperArm);
            forearm = animator.GetBoneTransform(HumanBodyBones.RightLowerArm);
            hand = animator.GetBoneTransform(HumanBodyBones.RightHand);
        }

        upperArmLength = Vector3.Distance(upperArm.position, forearm.position);
        forearmLength = Vector3.Distance(forearm.position, hand.position);
        length = upperArmLength + forearmLength;
        if (length == 0)
            Debug.LogError("Avatar arm positions are incorrect. Please restore avatar in T-pose.");

        upperArmLength2 = upperArmLength * upperArmLength;
        forearmLength2 = forearmLength * forearmLength;

        upperArmStartPosition = upperArm.position;
    }
Beispiel #28
0
	public void StartMovements() {
		ivr = this.GetComponent<InstantVR>();

		headTarget = ivr.headTarget;
		leftHandTarget = ivr.leftHandTarget;
		rightHandTarget = ivr.rightHandTarget;
		hipTarget = ivr.hipTarget;
		leftFootTarget = ivr.leftFootTarget;
		rightFootTarget = ivr.rightFootTarget;

		animator = ivr.transform.GetComponentInChildren<Animator>();
        if (animator == null) {
            StopMovements();
        } else {

            characterRigidbody = animator.GetComponent<Rigidbody>();

            if (characterRigidbody != null)
                characterTransform = characterRigidbody.GetComponent<Transform>();

            if (leftArm == null)
                leftArm = new ArmMovements(ivr, ArmMovements.BodySide.Left, this);
            leftArm.Initialize(ivr, ArmMovements.BodySide.Left, this);

            if (rightArm == null)
                rightArm = new ArmMovements(ivr, ArmMovements.BodySide.Right, this);
            rightArm.Initialize(ivr, ArmMovements.BodySide.Right, this);

            Transform neck, spine, hips;

            neck = animator.GetBoneTransform(HumanBodyBones.Neck);
            if (neck == null)
                neck = animator.GetBoneTransform(HumanBodyBones.Head);
            spine = animator.GetBoneTransform(HumanBodyBones.Spine);
            hips = animator.GetBoneTransform(HumanBodyBones.Hips);
            torso = new Torso(neck, spine, hips, hipTarget, headTarget, rightArm);

            leftLeg = new Leg(ArmMovements.BodySide.Left, animator, hipTarget);
            rightLeg = new Leg(ArmMovements.BodySide.Right, animator, hipTarget);

            if (rightHandTarget != null) {
                rightHandOTarget = rightHandTarget;
                /*
                float targetScaleZ = rightHandTarget.transform.localScale.z;
                rightPalmTarget = new GameObject();
                rightPalmTarget.name = "Palm_R_Target";
                rightPalmTarget.transform.parent = rightHandTarget.transform;
                rightPalmTarget.transform.localPosition = new Vector3(0, 0, -palmLength/targetScaleZ);
                rightPalmTarget.transform.localEulerAngles = Vector3.zero;
				
                rightHandTarget = rightPalmTarget.transform;
                */
            }

            if (leftHandTarget != null) {
                leftHandOTarget = leftHandTarget;
                /*
                float targetScaleZ = leftHandTarget.transform.localScale.z;
                leftPalmTarget = new GameObject();
                leftPalmTarget.name = "Palm_L_Target";
                leftPalmTarget.transform.parent = leftHandTarget.transform;
                leftPalmTarget.transform.localPosition = new Vector3(0, 0, -palmLength/targetScaleZ);
                leftPalmTarget.transform.localEulerAngles = Vector3.zero;

                leftHandTarget = leftPalmTarget.transform;
                */
            }

            if (headTarget == null && enableTorso) {
                GameObject neckTargetGO = new GameObject("Neck_Target");
                headTarget = neckTargetGO.transform;
                headTarget.parent = characterTransform;
                headTarget.position = torso.neck.position;
                headTarget.rotation = characterTransform.rotation;
            }

            if (enableLegs) {
                if (rightFootTarget == null) {
                    //userLegTargets = false;
                    GameObject rightFootTargetGO = new GameObject("Foot_R_Target");
                    rightFootTarget = rightFootTargetGO.transform;
                    rightFootTarget.parent = characterTransform;
                    rightFootTarget.position = rightLeg.foot.position;
                    rightFootTarget.rotation = characterTransform.rotation;
                }

                if (leftFootTarget == null) {
                    //userLegTargets = false;
                    GameObject leftFootTargetGO = new GameObject("Foot_L_Target");
                    leftFootTarget = leftFootTargetGO.transform;
                    leftFootTarget.parent = characterTransform;
                    leftFootTarget.position = leftLeg.foot.position;
                    leftFootTarget.rotation = characterTransform.rotation;
                }
            }


            if (IsInTPose(leftArm, rightArm)) {
                CalculateFromNormTPose(leftArm, rightArm);
            } else {
                CalculateFromNormTracking(leftArm, rightArm, leftHandTarget, rightHandTarget);
            }
        }
    }
Beispiel #29
0
 public Segment(Animator animator, HumanBodyBones bone1, HumanBodyBones bone2)
 {
     _joint1 = animator.GetBoneTransform(bone1);
     _joint2 = animator.GetBoneTransform(bone2);
     _length = (_joint1.position - _joint2.position).magnitude;
 }
Beispiel #30
0
 void Awake()
 {
     healthDisplay = transform.Find("Health").GetComponent<TextMesh>();
     anim = GetComponent<Animator>();
     Transform rightHand = anim.GetBoneTransform(HumanBodyBones.RightHand);
     saber = rightHand.Find("LSaber/Beam").gameObject;
     saberCont = rightHand.GetComponentInChildren<SaberController>();
     rb = GetComponent<Rigidbody>();
     health = MAX_HEALTH;
 }