Ejemplo n.º 1
0
        /// <summary>
        /// Recursively searches for a bone given the name and returns it if found
        /// </summary>
        /// <param name="rParent">Parent to search through</param>
        /// <param name="rBoneName">Bone to find</param>
        /// <returns>Transform of the bone or null</returns>
        public static Transform FindTransform(this Transform rThis, HumanBodyBones rBone)
        {
            Animator lAnimator = rThis.gameObject.GetComponent<Animator>();
            if (lAnimator != null) { return lAnimator.GetBoneTransform(rBone); }

            return null;
        }
		public override void Reset()
		{
			gameObject = null;
			bone = HumanBodyBones.Hips;
			boneAsString = new FsmString(){UseVariable=false};
			boneGameObject = null;
		}
Ejemplo n.º 3
0
        public static GameObject SpawnRagdoll(Actor actor, HumanBodyBones originPart, HumanBodyBones keptPart)
        {
            GameObject obj = Object.Instantiate(RagdollSpawner.rd);
            Animator anim = obj.GetComponent<Animator>();
            SyncBones(actor.transform.Find("ScientistSkeleton"), obj.transform.Find("ScientistSkeleton"));
            anim.GetBoneTransform(originPart).localScale = ScaleDown * Vector3.one;
            anim.GetBoneTransform(keptPart).localScale = ScaleUp * Vector3.one;

            return obj;
        }
Ejemplo n.º 4
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;
    }
		static void AddBoneLine( HumanBodyBones bone, BoneLine bone_line, params object[] args )
		{
			if( args.Length < 3 || bone == HumanBodyBones.Hips )
			{
				return;
			}
			
			Material mat = (Material)args[0];
			float parent_width = (float)args[1];
			float child_width = (float)args[2];
			
			if( bone >= HumanBodyBones.LeftThumbProximal && bone <= HumanBodyBones.RightLittleDistal )
			{
				bone_line.AddRenderer( mat, parent_width / 3.0f, child_width / 3.0f, bone_line.transform.parent, bone_line.transform );
			}
			else
			{
				bone_line.AddRenderer( mat, parent_width, child_width, bone_line.transform.parent, bone_line.transform );
			}
		}
        /// <summary>
        /// Returns the index of the muscle that has the humanBodyBone target (works only with a Humanoid avatar).
        /// </summary>
        public int GetMuscleIndex(HumanBodyBones humanBodyBone)
        {
            if (!CheckIfInitiated()) return -1;

            if (targetAnimator == null) {
                Debug.LogWarning("PuppetMaster 'Target Root' has no Animator component on it nor on it's children.", transform);
                return -1;
            }
            if (!targetAnimator.isHuman) {
                Debug.LogWarning("PuppetMaster target's Animator does not belong to a Humanoid, can hot get human muscle index.", transform);
                return -1;
            }

            var bone = targetAnimator.GetBoneTransform(humanBodyBone);
            if (bone == null) {
                Debug.LogWarning("PuppetMaster target's Avatar does not contain a bone Transform for " + humanBodyBone, transform);
                return -1;
            }

            return GetMuscleIndex(bone);
        }
	// set rotation for bone in animator
	static void SetRotation( Animator animator, HumanBodyBones bone, Vector3 rotation, float lerp_ratio )
	{
		Transform t = animator.GetBoneTransform( bone );
		if( t != null )
		{
			Quaternion rot = Quaternion.Slerp( t.localRotation, Quaternion.Euler( rotation ), lerp_ratio );
			if( !float.IsNaN( rot.x ) && !float.IsNaN( rot.y ) && !float.IsNaN( rot.z ) && !float.IsNaN( rot.w ) )
			{
				t.localRotation = rot;
			}
		}
	}
Ejemplo n.º 8
0
 public Transform GetBodyPart(HumanBodyBones bone) => Animator.GetBoneTransform(bone);
//	private bool GetModelBoxHeight(ref float height, ref float width)
//	{
//		SkinnedMeshRenderer renderer = GetComponentInChildren<SkinnedMeshRenderer>();
//
//		if (renderer && bodyScaleTransform)
//		{
//			renderer.updateWhenOffscreen = true;
//			Bounds bounds = renderer.localBounds;
//			Vector3 scale = bodyScaleTransform.localScale;
//			//renderer.updateWhenOffscreen = false;
//
//			height = bounds.size.z / scale.y;
//			width = bounds.size.x / scale.x;
//
//			return true;
//		}
//
//		return false;
//	}

    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);
    }
Ejemplo n.º 10
0
        //ボーン位置同期
        private void BoneSynchronize(HumanBodyBones bone, Vector3 pos, Quaternion rot)
        {
            //操作可能な状態かチェック
            if (animator != null && bone != HumanBodyBones.LastBone)
            {
                //ボーンによって操作を分ける
                var t = animator.GetBoneTransform(bone);
                if (t != null)
                {
                    //指ボーン
                    if (bone == HumanBodyBones.LeftIndexDistal ||
                        bone == HumanBodyBones.LeftIndexIntermediate ||
                        bone == HumanBodyBones.LeftIndexProximal ||
                        bone == HumanBodyBones.LeftLittleDistal ||
                        bone == HumanBodyBones.LeftLittleIntermediate ||
                        bone == HumanBodyBones.LeftLittleProximal ||
                        bone == HumanBodyBones.LeftMiddleDistal ||
                        bone == HumanBodyBones.LeftMiddleIntermediate ||
                        bone == HumanBodyBones.LeftMiddleProximal ||
                        bone == HumanBodyBones.LeftRingDistal ||
                        bone == HumanBodyBones.LeftRingIntermediate ||
                        bone == HumanBodyBones.LeftRingProximal ||
                        bone == HumanBodyBones.LeftThumbDistal ||
                        bone == HumanBodyBones.LeftThumbIntermediate ||
                        bone == HumanBodyBones.LeftThumbProximal ||

                        bone == HumanBodyBones.RightIndexDistal ||
                        bone == HumanBodyBones.RightIndexIntermediate ||
                        bone == HumanBodyBones.RightIndexProximal ||
                        bone == HumanBodyBones.RightLittleDistal ||
                        bone == HumanBodyBones.RightLittleIntermediate ||
                        bone == HumanBodyBones.RightLittleProximal ||
                        bone == HumanBodyBones.RightMiddleDistal ||
                        bone == HumanBodyBones.RightMiddleIntermediate ||
                        bone == HumanBodyBones.RightMiddleProximal ||
                        bone == HumanBodyBones.RightRingDistal ||
                        bone == HumanBodyBones.RightRingIntermediate ||
                        bone == HumanBodyBones.RightRingProximal ||
                        bone == HumanBodyBones.RightThumbDistal ||
                        bone == HumanBodyBones.RightThumbIntermediate ||
                        bone == HumanBodyBones.RightThumbProximal)
                    {
                        //指ボーンカットオフが有効でなければ
                        if (!HandPoseSynchronizeCutoff)
                        {
                            //ボーン同期する。ただしフィルタはかけない
                            BoneSynchronizeSingle(t, ref bone, ref pos, ref rot, false, false);
                        }
                    }
                    //目ボーン
                    else if (bone == HumanBodyBones.LeftEye ||
                             bone == HumanBodyBones.RightEye)
                    {
                        //目ボーンカットオフが有効でなければ
                        if (!EyeBoneSynchronizeCutoff)
                        {
                            //ボーン同期する。ただしフィルタはかけない
                            BoneSynchronizeSingle(t, ref bone, ref pos, ref rot, false, false);
                        }
                    }
                    else
                    {
                        //ボーン同期する。フィルタは設定依存
                        BoneSynchronizeSingle(t, ref bone, ref pos, ref rot, BonePositionFilterEnable, BoneRotationFilterEnable);
                    }
                }
            }
        }
Ejemplo n.º 11
0
 // Token: 0x06004FFA RID: 20474 RVA: 0x001B5178 File Offset: 0x001B3578
 public Quaternion GetTPoseRotation(HumanBodyBones bone)
 {
     return(this.tPoseRotations[bone]);
 }
	// set position for bone in animator
	static void SetPosition( Animator animator, HumanBodyBones bone, Vector3 position, float lerp_ratio )
	{
		Transform t = animator.GetBoneTransform( bone );
		if( t != null )
		{
			// calculate position when we have scale
			position.Scale( new Vector3( 1.0f / t.parent.lossyScale.x, 1.0f / t.parent.lossyScale.y, 1.0f / t.parent.lossyScale.z ) );
			
			Vector3 pos = Vector3.Lerp( t.localPosition, position, lerp_ratio );
			if( !float.IsNaN( pos.x ) && !float.IsNaN( pos.y ) && !float.IsNaN( pos.z ) )
			{
				t.localPosition = pos;
			}
		}
	}
Ejemplo n.º 13
0
        public MuscleLimit GetMuscleLimit(Avatar avatar, HumanBodyBones humanoidIndex)
        {
            if (humanoidIndex < 0)
            {
                return(null);
            }
            var serializedObject = new UnityEditor.SerializedObject(avatar);
            int skeletonIndex    = -1;

            if (humanoidIndex <= HumanBodyBones.Jaw || humanoidIndex == HumanBodyBones.UpperChest)
            {
                int humanId = -1;
                if (humanoidIndex <= HumanBodyBones.Chest)
                {
                    humanId = (int)humanoidIndex;
                }
                else if (humanoidIndex <= HumanBodyBones.Jaw)
                {
                    humanId = (int)humanoidIndex + 1;
                }
                else
                {
                    humanId = 9;
                }
                var pHumanBoneIndexArray = serializedObject.FindProperty("m_Avatar.m_Human.data.m_HumanBoneIndex");
                if (pHumanBoneIndexArray == null || !pHumanBoneIndexArray.isArray || humanId < 0 || humanId >= pHumanBoneIndexArray.arraySize)
                {
                    return(null);
                }
                skeletonIndex = pHumanBoneIndexArray.GetArrayElementAtIndex(humanId).intValue;
            }
            else if (humanoidIndex <= HumanBodyBones.LeftLittleDistal)
            {
                int handId = (int)humanoidIndex - (int)HumanBodyBones.LeftThumbProximal;
                var pHandBoneIndexArray = serializedObject.FindProperty("m_Avatar.m_Human.data.m_LeftHand.data.m_HandBoneIndex");
                if (pHandBoneIndexArray == null || !pHandBoneIndexArray.isArray || handId < 0 || handId >= pHandBoneIndexArray.arraySize)
                {
                    return(null);
                }
                skeletonIndex = pHandBoneIndexArray.GetArrayElementAtIndex(handId).intValue;
            }
            else if (humanoidIndex <= HumanBodyBones.RightLittleDistal)
            {
                int handId = (int)humanoidIndex - (int)HumanBodyBones.RightThumbProximal;
                var pHandBoneIndexArray = serializedObject.FindProperty("m_Avatar.m_Human.data.m_RightHand.data.m_HandBoneIndex");
                if (pHandBoneIndexArray == null || !pHandBoneIndexArray.isArray || handId < 0 || handId >= pHandBoneIndexArray.arraySize)
                {
                    return(null);
                }
                skeletonIndex = pHandBoneIndexArray.GetArrayElementAtIndex(handId).intValue;
            }
            var pNodeArray = serializedObject.FindProperty("m_Avatar.m_Human.data.m_Skeleton.data.m_Node");

            if (pNodeArray == null || !pNodeArray.isArray || skeletonIndex < 0 || skeletonIndex >= pNodeArray.arraySize)
            {
                return(null);
            }
            var pNode = pNodeArray.GetArrayElementAtIndex(skeletonIndex);

            if (pNode == null)
            {
                return(null);
            }
            var axedId = pNode.FindPropertyRelative("m_AxesId").intValue;

            if (axedId < 0)
            {
                return(null);
            }
            var pAxesArray = serializedObject.FindProperty("m_Avatar.m_Human.data.m_Skeleton.data.m_AxesArray");

            if (pAxesArray == null || !pAxesArray.isArray || axedId < 0 || axedId >= pAxesArray.arraySize)
            {
                return(null);
            }
            var pAxes = pAxesArray.GetArrayElementAtIndex(axedId);

            if (pAxes == null)
            {
                return(null);
            }
            Vector3 min = new Vector3(pAxes.FindPropertyRelative("m_Limit.m_Min.x").floatValue,
                                      pAxes.FindPropertyRelative("m_Limit.m_Min.y").floatValue,
                                      pAxes.FindPropertyRelative("m_Limit.m_Min.z").floatValue) * Mathf.Rad2Deg;
            Vector3 max = new Vector3(pAxes.FindPropertyRelative("m_Limit.m_Max.x").floatValue,
                                      pAxes.FindPropertyRelative("m_Limit.m_Max.y").floatValue,
                                      pAxes.FindPropertyRelative("m_Limit.m_Max.z").floatValue) * Mathf.Rad2Deg;

            return(new MuscleLimit()
            {
                min = min, max = max
            });
        }
Ejemplo n.º 14
0
    // private method

    private void _ConvertAnim_original(string newClipAssetPath)
    {
        // 0. prepare
        if (!m_Animator.isHuman)
        {
            Dbg.LogWarn("MuscleClipConverterEditor._ConvertAnim: Need to change to Humanoid rig first!");
            return;
        }

        m_SMR = m_Animator.GetComponentInChildren <SkinnedMeshRenderer>();
        if (m_SMR == null)
        {
            Dbg.LogWarn("MuscleClipConverterEditor._ConvertAnim: failed to find SMR under {0}", m_Animator.name);
            return;
        }

        m_Animator.Update(0);
#if !U5
        var ainfos = m_Animator.GetCurrentAnimationClipState(0); //only effect after Update is called
#else
        var ainfos = m_Animator.GetCurrentAnimatorClipInfo(0);   //only effect after Update is called
#endif
        AnimationClip         clip        = ainfos[0].clip;
        AnimationClipSettings clipSetting = AnimationUtility.GetAnimationClipSettings(clip);

        //{//debug
        //    var bindings = AnimationUtility.GetCurveBindings(clip);
        //    foreach( var b in bindings)
        //    {
        //        Dbg.Log("path: {0}, prop: {1}", b.path, b.propertyName);
        //    }
        //}

        Transform animatorTr = m_Animator.transform;
        Transform hipsBone   = null;
        CurveDict curveDict  = new CurveDict();

        float SAMPLE_RATE = clip.frameRate;
        float clipLen     = clip.length;

        Matrix4x4 animatorInitW2LMat = animatorTr.worldToLocalMatrix;
        Matrix4x4 hipsInitW2LMat     = Matrix4x4.identity;

        List <Transform> boneLst = new List <Transform>();
        for (HumanBodyBones boneIdx = 0; boneIdx < HumanBodyBones.LastBone; ++boneIdx)
        {
            Transform tr = m_Animator.GetBoneTransform(boneIdx);
            //Dbg.Log("Map: {0}->{1}", boneIdx, tr);
            if (tr != null)
            {
                boneLst.Add(tr);
                if (boneIdx == HumanBodyBones.Hips)
                {
                    hipsBone       = tr;
                    hipsInitW2LMat = hipsBone.parent.worldToLocalMatrix;
                    //clipSetting.level = -hipsBone.localPosition.y; // set Y offset
                    clipSetting.keepOriginalPositionY = false; //use RootNode position
                }
            }
        }
        Transform[] bones = boneLst.ToArray();

        // init curves for each bone
        for (int idx = 0; idx < bones.Length; ++idx)
        {
            Transform oneBone = bones[idx];
            string    trPath  = AnimationUtility.CalculateTransformPath(oneBone, animatorTr);

            var curves = new _Curves();
            curves.relPath = trPath;

            curveDict.Add(oneBone, curves);
        }

        // init rootmotion curve
        {
            var curves = new _Curves();
            curveDict.Add(animatorTr, curves);
        }

        AnimatorStateInfo curStateInfo = m_Animator.GetCurrentAnimatorStateInfo(0);
        float             nt           = curStateInfo.normalizedTime;
        m_Animator.Update(-nt * clipLen); //revert to 0 time

        {                                 // 1. bake animation info into curve on all bones transform
            float time      = 0f;
            float deltaTime = 1f / (SAMPLE_RATE);
            for (;
                 time <= clipLen || Mathf.Approximately(time, clipLen);
                 )
            {
                //Dbg.Log("nt = {0}", m_Animator.GetCurrentAnimatorStateInfo(0).normalizedTime);

                // bone
                for (int idx = 0; idx < bones.Length; ++idx)
                {
                    Transform oneBone = bones[idx];
                    _Curves   curves  = curveDict[oneBone];

                    if (oneBone == hipsBone)
                    {
                        continue; //skip the HipsBone. This is to add rootMotion matrix on hips, so Legacy is right
                    }
                    Vector3    pos = oneBone.localPosition;
                    Quaternion rot = oneBone.localRotation;

                    curves.X.AddKey(time, rot.x);
                    curves.Y.AddKey(time, rot.y);
                    curves.Z.AddKey(time, rot.z);
                    curves.W.AddKey(time, rot.w);

                    curves.PX.AddKey(time, pos.x);
                    curves.PY.AddKey(time, pos.y);
                    curves.PZ.AddKey(time, pos.z);
                }

                // root motion process
                {
                    { //on Animator transform
                        Vector3 pos = /*animatorTr.localPosition*/ animatorTr.position;
                        Vector3 fwd = animatorTr.forward;
                        Vector3 up  = animatorTr.up;

                        _Curves rootMotionCurves = curveDict[animatorTr];
                        Vector3 lpos             = animatorInitW2LMat.MultiplyPoint(pos);
                        Vector3 lfwd             = animatorInitW2LMat.MultiplyVector(fwd);
                        Vector3 lup = animatorInitW2LMat.MultiplyVector(up);

                        Quaternion rot = Quaternion.LookRotation(lfwd, lup);

                        rootMotionCurves.X.AddKey(time, rot.x);
                        rootMotionCurves.Y.AddKey(time, rot.y);
                        rootMotionCurves.Z.AddKey(time, rot.z);
                        rootMotionCurves.W.AddKey(time, rot.w);

                        rootMotionCurves.PX.AddKey(time, lpos.x);
                        rootMotionCurves.PY.AddKey(time, lpos.y);
                        rootMotionCurves.PZ.AddKey(time, lpos.z);
                    }

                    { //on hips transform
                        if (hipsBone != null)
                        {
                            Vector3 pos = hipsBone.position;
                            Vector3 fwd = hipsBone.forward;
                            Vector3 up  = hipsBone.up;

                            _Curves hipsCurves = curveDict[hipsBone];
                            Vector3 lpos       = hipsInitW2LMat.MultiplyPoint(pos);
                            Vector3 lfwd       = hipsInitW2LMat.MultiplyVector(fwd);
                            Vector3 lup        = hipsInitW2LMat.MultiplyVector(up);

                            //Dbg.Log("time: {0}, lpos: {1}", time, lpos.ToString("F2"));

                            Quaternion rot = Quaternion.LookRotation(lfwd, lup);

                            hipsCurves.X.AddKey(time, rot.x);
                            hipsCurves.Y.AddKey(time, rot.y);
                            hipsCurves.Z.AddKey(time, rot.z);
                            hipsCurves.W.AddKey(time, rot.w);

                            hipsCurves.PX.AddKey(time, lpos.x);
                            hipsCurves.PY.AddKey(time, lpos.y);
                            hipsCurves.PZ.AddKey(time, lpos.z);
                        }
                    }
                }

                if (!Mathf.Approximately(time + deltaTime, clipLen))
                {
                    m_Animator.Update(deltaTime);
                    time += deltaTime;
                }
                else
                {
                    m_Animator.Update(deltaTime - 0.005f); //keep it in the range, if go beyond, something bad could happen
                    time += deltaTime - 0.005f;
                }
            }
        } //end of 1.


        { // 2. set animation clip and store in AssetDatabase
            AnimationClip newClip = new AnimationClip();
            newClip.frameRate   = SAMPLE_RATE;
            newClip.localBounds = clip.localBounds;

            // set bone curves
            for (var ie = curveDict.GetEnumerator(); ie.MoveNext();)
            {
                var curves = ie.Current.Value;
                if (ie.Current.Key == animatorTr)
                { //root motion
                    newClip.SetCurve(curves.relPath, typeof(Animator), "MotionT.x", curves.PX);
                    newClip.SetCurve(curves.relPath, typeof(Animator), "MotionT.y", curves.PY);
                    newClip.SetCurve(curves.relPath, typeof(Animator), "MotionT.z", curves.PZ);

                    newClip.SetCurve(curves.relPath, typeof(Animator), "MotionQ.x", curves.X);
                    newClip.SetCurve(curves.relPath, typeof(Animator), "MotionQ.y", curves.Y);
                    newClip.SetCurve(curves.relPath, typeof(Animator), "MotionQ.z", curves.Z);
                    newClip.SetCurve(curves.relPath, typeof(Animator), "MotionQ.w", curves.W);
                }
                else
                {
                    newClip.SetCurve(curves.relPath, typeof(Transform), "localRotation.x", curves.X);
                    newClip.SetCurve(curves.relPath, typeof(Transform), "localRotation.y", curves.Y);
                    newClip.SetCurve(curves.relPath, typeof(Transform), "localRotation.z", curves.Z);
                    newClip.SetCurve(curves.relPath, typeof(Transform), "localRotation.w", curves.W);

                    newClip.SetCurve(curves.relPath, typeof(Transform), "localPosition.x", curves.PX);
                    newClip.SetCurve(curves.relPath, typeof(Transform), "localPosition.y", curves.PY);
                    newClip.SetCurve(curves.relPath, typeof(Transform), "localPosition.z", curves.PZ);
                }
            }

            // 2.1 copy the unmapped curves to new clip( not mapped by Muscle clip )
            _CopyOtherCurves(newClip, clip);

            // some setting work
            newClip.EnsureQuaternionContinuity();

#if !U5
            AnimationUtility.SetAnimationType(newClip, m_AnimType);
            RCall.CallMtd("UnityEditor.AnimationUtility", "SetAnimationClipSettings", null, newClip, clipSetting);
#else
            if (m_AnimType == ModelImporterAnimationType.Legacy)
            {
                newClip.legacy = true;
            }
            AnimationUtility.SetAnimationClipSettings(newClip, clipSetting);
#endif

            EUtil.SaveAnimClip(newClip, newClipAssetPath);

            EUtil.ShowNotification("Converted to: " + m_AnimType +
                                   (hipsBone != null ? ("\nroot=" + AnimationUtility.CalculateTransformPath(hipsBone, animatorTr)) : ""),
                                   3f
                                   );
        } //end of 2.

        // 3. clean job
        curveDict = null;
        AssetDatabase.SaveAssets();

        Dbg.Log("Converted: {0}", newClipAssetPath);
    }
Ejemplo n.º 15
0
 public void changeBone(HumanBodyBones b)
 {
     bone       = b;
     savedValue = animator.GetBoneTransform(bone).localRotation;
 }
Ejemplo n.º 16
0
 public Bone(HumanBodyBones from, HumanBodyBones to, float radius)
 {
     JointFrom = from;
     JointTo   = to;
     Radius    = radius;
 }
Ejemplo n.º 17
0
 public static VRMBone FromHumanBodyBone(this HumanBodyBones human)
 {
     return(EnumUtil.TryParseOrDefault <VRMBone>(human.ToString(), VRMBone.unknown));
 }
Ejemplo n.º 18
0
 private static void INTERNAL_CALL_SetBoneLocalRotationInternal(Animator self, HumanBodyBones humanBoneId, ref Quaternion rotation)
 {
     throw new NotImplementedException("なにこれ");
 }
 Transform GetBoneTransform(HumanBodyBones humanBone)
 {
     return(GetComponentInParent <Animator> ().GetBoneTransform(humanBone));
     //return transform.FindDeepChild(MakehumanMappings.mappings.human [System.Array.IndexOf (MakehumanMappings.mappings.boneType, humanBone)].boneName);
 }
Ejemplo n.º 20
0
 void UpdateFinger(
     int noiseSeed, bool thumb, bool right,
     HumanBodyBones bone1, HumanBodyBones bone2, HumanBodyBones bone3)
 {
     var a = thumb ? Vector3.up : Vector3.forward;
     var r = thumb ? _noiseToThumbRotation : _noiseToFingerRotation;
     var n = _noise2.Value01(noiseSeed) * (right ? -1 : 1);
     var q = Quaternion.AngleAxis(r * n, a);
     _animator.SetBoneLocalRotation(bone1, q);
     _animator.SetBoneLocalRotation(bone2, q);
     _animator.SetBoneLocalRotation(bone3, q);
 }
        /// <summary>
        /// Sets the muscle weights for the muscle that has the humanBodyBone target (works only with a Humanoid avatar) and all it's child muscles (when called on the upper arm, will set weights for the upper arm, forearm and hand of the same limb).
        /// </summary>
        public void SetMuscleWeightsRecursive(HumanBodyBones humanBodyBone, float muscleWeight, float pinWeight = 1f, float mappingWeight = 1f, float muscleDamper = 1f)
        {
            if (!CheckIfInitiated()) return;

            int index = GetMuscleIndex(humanBodyBone);
            if (index == -1) return;
            SetMuscleWeightsRecursive(index, muscleWeight, pinWeight, mappingWeight, muscleDamper);
        }
Ejemplo n.º 22
0
 public void RepairBone(HumanBodyBones bone)
 {
     dismemberment.RepairBone(bone);
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Converts our Unity bone id into the name equivalent
 /// </summary>
 /// <param name="rBoneName">Name of the human bone</param>
 /// <returns>String representing the human bone name or an empty string if it isn't found</returns>
 public static string GetHumanBodyBoneName(HumanBodyBones rBoneID)
 {
     string lBoneName = "Unity " + rBoneID.ToString();
     return lBoneName;
 }
Ejemplo n.º 24
0
 /*
  *  repairs a bone, if dismemebred
  */
 public void RepairBone(HumanBodyBones bone)
 {
     InitializeDismemberedBones();
     RepairBone(dismemberedBones[bone]);
     dismemberedBones[bone] = null;
 }
Ejemplo n.º 25
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="feetPositions"></param>
 /// <param name="foot"></param>
 private void AdjustFeetTarget(ref Vector3 feetPositions, HumanBodyBones foot)
 {
     feetPositions   = anim.GetBoneTransform(foot).position;
     feetPositions.y = transform.position.y + heightFromGroundRaycast;
 }
		static void RemoveBoneLine( HumanBodyBones bone, BoneLine bone_line, params object[] args )
		{
			bone_line.RemoveRenderer();
		}
Ejemplo n.º 27
0
 public static bool BoneIsPhysicsBone(HumanBodyBones bone)
 {
     return(Bone2Index(bone) != -1);
 }
Ejemplo n.º 28
0
 public void SetBoneLocalRotation(HumanBodyBones humanBoneId, Quaternion rotation)
 {
     this.CheckIfInIKPass();
     this.SetBoneLocalRotationInternal(humanBoneId, rotation);
 }
Ejemplo n.º 29
0
 // Token: 0x06004FF9 RID: 20473 RVA: 0x001B516A File Offset: 0x001B356A
 public bool HasTPoseBone(HumanBodyBones bone)
 {
     return(this.tPoseRotations.ContainsKey(bone));
 }
Ejemplo n.º 30
0
 private static extern void INTERNAL_CALL_SetBoneLocalRotationInternal(Animator self, HumanBodyBones humanBoneId, ref Quaternion rotation);
Ejemplo n.º 31
0
 // Token: 0x06004FFB RID: 20475 RVA: 0x001B5186 File Offset: 0x001B3586
 public Vector3 GetTPosePosition(HumanBodyBones bone)
 {
     return(this.tPosePositions[bone]);
 }
Ejemplo n.º 32
0
 public Transform GetBoneTransform(HumanBodyBones humanBoneId)
 {
     throw new NotImplementedException();
 }
        /*
         *      set the velocities we calculated in late update for each animated bone
         *      on the actual ragdoll
         */
        void SetPhysicsVelocities(float deltaTime)
        {
            float dot = Vector3.Dot(ragdoll.RootBone().transform.up, Vector3.up);

            float maxVelocityForGravityAdd2 = profile.maxGravityAddVelocity * profile.maxGravityAddVelocity;

            float fallDecayCurveSample = 1f - fallDecay;             //set up curves backwards... whoops

            // for each physics bone...
            for (int i = 0; i < Ragdoll.bonesCount; i++)
            {
                HumanBodyBones unityBone = Ragdoll.humanBones[i];

                RagdollTransform bone = ragdoll.GetBone(unityBone);

                if (ragdoll.BoneDismembered(bone))
                {
                    continue;
                }

                if (bone.rigidbody.isKinematic)
                {
                    continue;
                }


                Vector3 ragdollBoneVelocty = bone.rigidbody.velocity;

                // get the manually set bone decay value
                float boneDecay = boneDecays[unityBone];

                /*
                 *      calculate the force decay based on the overall fall decay and the bone profile's
                 *      fall force decay curve
                 */
                float forceDecay = Mathf.Clamp01(profile.boneData[unityBone].fallForceDecay.Evaluate(fallDecayCurveSample));

                //subtract manual decay
                forceDecay = Mathf.Clamp01(forceDecay - boneDecay);

                // if we're flipped to extremely, stop trying to follow anim
                // makes it look like it's 'gliding' forward in superman stance
                if (dot < profile.loseFollowDot)
                {
                    forceDecay = 0;
                }

                // if we're still using some force to follow
                if (forceDecay != 0)
                {
                    Vector3 animVelocity = animationVelocityTrackers[i].velocity;

                    /*
                     *      if animation velocity is below threshold magnitude, add some gravity to it
                     */
                    if (animVelocity.sqrMagnitude < maxVelocityForGravityAdd2)
                    {
                        animVelocity.y = Physics.gravity.y * deltaTime;
                    }

                    /*
                     *      if bone decay was manually set to make room for external velocities,
                     *      use the most extreme component of each vector as the "target animated" velocity
                     */
                    if (boneDecay != 0)
                    {
                        animVelocity = MaxAbs(ragdollBoneVelocty, animVelocity);
                    }

                    // set the velocity on the ragdoll rigidbody (based on the force decay)
                    bone.rigidbody.velocity = Vector3.Lerp(ragdollBoneVelocty, animVelocity, forceDecay);
                }

                if (i != 0)
                {
                    /*
                     *      calculate the force decay based on the overall fall decay and the bone profile's
                     *      fall force decay curve
                     */
                    float torqueDecay = Mathf.Clamp01(profile.boneData[unityBone].fallTorqueDecay.Evaluate(fallDecayCurveSample));

                    //subtract manual decay
                    torqueDecay = Mathf.Clamp01(torqueDecay - boneDecay);

                    /*
                     *      handle joints target for the ragdoll joints
                     */
                    HandleJointFollow(bone, profile.maxTorque * torqueDecay, i);
                }
            }

            CheckForFallEnd(fallDecay);
        }
		static void AddRigidBody( HumanBodyBones bone, Rigidbody rigidbody, object[] args )
		{
			rigidbody.useGravity = false;
			rigidbody.isKinematic = true;
		}
Ejemplo n.º 35
0
 public extern Transform GetBoneTransform(HumanBodyBones humanBoneId);
Ejemplo n.º 36
0
        /// <summary>
        /// Anchors the mount point to the specified bone, essencially making
        /// this mount point a child of the bone.
        /// </summary>
        /// <param name="rBoneName">Bone name to anchor to or empty string to anchor to the root</param>
        public void AnchorTo(HumanBodyBones rHumanBodyBoneID)
        {
            if (rHumanBodyBoneID < 0) { return; }
            if (rHumanBodyBoneID > HumanBodyBones.LastBone) { return; }

            _BoneName = "";
            Transform lParentTransform = _Owner.transform;

            if (_Anchor == null) { _Anchor = new GameObject(); }

            Animator lAnimator = _Owner.GetComponent<Animator>();
            if (lAnimator != null)
            {
                lParentTransform = lAnimator.GetBoneTransform(rHumanBodyBoneID);
                if (lParentTransform != null)
                {
                    _BoneName = MountPoints.GetHumanBodyBoneName(rHumanBodyBoneID);
                }
            }            

            // Parent the mount point to this new transform. We don't
            // change it's position or rotation since we may need an offset.
            _Anchor.transform.parent = lParentTransform;
        }
Ejemplo n.º 37
0
 internal void SetBoneLocalRotationInternal(HumanBodyBones humanBoneId, Quaternion rotation)
 {
     Animator.INTERNAL_CALL_SetBoneLocalRotationInternal(this, humanBoneId, ref rotation);
 }
Ejemplo n.º 38
0
    // is soccerball close enough to Limb
    public bool CloseEnough(Vector3 SoccerballPosition, string Limb, float MixDis = 0.1f)
    {
        HumanBodyBones[] RightHandArray = new HumanBodyBones[]
        {
            HumanBodyBones.RightHand,
            HumanBodyBones.RightLowerArm,
            HumanBodyBones.RightUpperArm,
            HumanBodyBones.RightShoulder
        };

        HumanBodyBones[] LeftHandArray = new HumanBodyBones[]
        {
            HumanBodyBones.LeftHand,
            HumanBodyBones.LeftLowerArm,
            HumanBodyBones.LeftUpperArm,
            HumanBodyBones.LeftShoulder
        };

        HumanBodyBones[] RightFootArray = new HumanBodyBones[]
        {
            HumanBodyBones.RightToes,
            HumanBodyBones.RightFoot,
            HumanBodyBones.RightLowerLeg,
            HumanBodyBones.RightUpperLeg,
        };

        HumanBodyBones[] LeftFootArray = new HumanBodyBones[] {
            HumanBodyBones.LeftToes,
            HumanBodyBones.LeftFoot,
            HumanBodyBones.LeftLowerLeg,
            HumanBodyBones.LeftUpperLeg
        };

        HumanBodyBones[] Array;
        if (Limb.Equals("左手"))
        {
            Array = LeftHandArray;
        }
        else if (Limb.Equals("右手"))
        {
            Array = RightHandArray;
        }
        else if (Limb.Equals("左脚"))
        {
            Array = LeftFootArray;
        }
        else
        {
            Array = RightFootArray;
        }


        foreach (HumanBodyBones point in Array)
        {
            Vector3 position    = _Animator.GetBoneTransform(point).position;
            float   disance_now = (position - SoccerballPosition).sqrMagnitude;
            if (disance_now < MixDis)
            {
                return(true);
            }
        }

        return(false);
    }
Ejemplo n.º 39
0
 private void SetupIKLimbHandle(ref FullBodyIKJob.IKLimbHandle handle, HumanBodyBones top, HumanBodyBones middle, HumanBodyBones end)
 {
     handle.top    = m_Animator.BindStreamTransform(m_Animator.GetBoneTransform(top));
     handle.middle = m_Animator.BindStreamTransform(m_Animator.GetBoneTransform(middle));
     handle.end    = m_Animator.BindStreamTransform(m_Animator.GetBoneTransform(end));
 }
Ejemplo n.º 40
0
		public Transform GetBoneTransform(HumanBodyBones humanBoneId){}
        // remove bone line by animator
        //static NSH.OnRemoveBoneComponent<BoneLine>	delegate_remove_bone_line = new NSH.OnRemoveBoneComponent<BoneLine>( RemoveBoneLine );

        static void RemoveBoneLine(HumanBodyBones bone, BoneLine bone_line, params object[] args)
        {
            bone_line.RemoveRenderer();
        }
 public void Add(HumanBodyBones key, HumanBodyBones parentKey, Vector3 headPosition, Quaternion headRotation)
 {
     Add(key, _Skeleton[parentKey], headPosition, headRotation);
 }
Ejemplo n.º 43
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;
    }
 public void UpdateRotation(HumanBodyBones key, Quaternion localRotation)
 {
     _Skeleton[key].localRotation = localRotation;
 }
Ejemplo n.º 45
0
        static void DrawBoneProfileNeighbors(SerializedProperty neighborsProp, Rect position, HumanBodyBones baseBone)
        {
            if (GUI.Button(position, new GUIContent("Neighbors", "Define which bones count as neighbors for other bones (for the bone decay system)"), EditorStyles.miniButton))
            {
                int neighborsLength = neighborsProp.arraySize;
                System.Func <HumanBodyBones, bool> containsBone = (b) => {
                    int bi = (int)b;
                    for (int i = 0; i < neighborsLength; i++)
                    {
                        if (neighborsProp.GetArrayElementAtIndex(i).enumValueIndex == bi)
                        {
                            return(true);
                        }
                    }
                    return(false);
                };
                System.Func <HumanBodyBones, int> indexOf = (b) => {
                    int bi = (int)b;
                    for (int i = 0; i < neighborsLength; i++)
                    {
                        if (neighborsProp.GetArrayElementAtIndex(i).enumValueIndex == bi)
                        {
                            return(i);
                        }
                    }
                    return(-1);
                };

                System.Action <HumanBodyBones> removeBone = (b) => { neighborsProp.DeleteArrayElementAtIndex(indexOf(b)); };

                System.Action <HumanBodyBones> addBone = (b) => {
                    neighborsProp.InsertArrayElementAtIndex(neighborsLength);
                    neighborsProp.GetArrayElementAtIndex(neighborsLength).enumValueIndex = (int)b;
                };

                GenericMenu menu = new GenericMenu();
                for (int i = 0; i < Ragdoll.bonesCount; i++)
                {
                    HumanBodyBones hb = Ragdoll.humanBones[i];
                    if (hb == baseBone)
                    {
                        continue;
                    }

                    menu.AddItem(new GUIContent(hb.ToString()), containsBone(hb),
                                 (b) => {
                        HumanBodyBones hb2 = (HumanBodyBones)b;
                        if (containsBone(hb2))
                        {
                            removeBone(hb2);
                        }
                        else
                        {
                            addBone(hb2);
                        }
                    }, hb);
                }

                // display the menu
                menu.ShowAsContext();
            }
        }
Ejemplo n.º 46
0
 public static VRMBone FromHumanBodyBone(this HumanBodyBones human)
 {
     return(human.ToVrmBone());
 }
Ejemplo n.º 47
0
 public Segment(Animator animator, HumanBodyBones bone1, HumanBodyBones bone2)
 {
     _joint1 = animator.GetBoneTransform(bone1);
     _joint2 = animator.GetBoneTransform(bone2);
     _length = (_joint1.position - _joint2.position).magnitude;
 }
	static void SetScale( Animator animator, HumanBodyBones bone, float size, float referenceSize )
	{	
		Transform t = animator.GetBoneTransform( bone );
		if( t != null && bone <= HumanBodyBones.Jaw )
		{
			float ratio = size / referenceSize;
			
			Vector3 newScale = new Vector3( ratio, ratio, ratio );
			newScale.Scale( new Vector3( 1.0f / t.parent.lossyScale.x, 1.0f / t.parent.lossyScale.y, 1.0f / t.parent.lossyScale.z ) );
			
			if( ValidateVector3( newScale ) )
			{
				t.localScale = newScale;
			}
			
//			for( int i = 0; i < t.childCount; ++i )
//			{
//				t.GetChild( i ).localScale = new Vector3( 1.0f / t.lossyScale.x, 1.0f / t.lossyScale.y, 1.0f / t.lossyScale.z );
//			}
			
			//Debug.Log( string.Format( "bone {0} reference {1} received {2} ratio {3}", bone, referenceSize, size, newScale.x ) );
		}
	}