Пример #1
0
    private static void Solve(
        AnimationStream stream,
        TransformStreamHandle joint,
        TransformSceneHandle target,
        Vector3 jointAxis,
        float minAngle,
        float maxAngle)
    {
        var jointPosition  = joint.GetPosition(stream);
        var jointRotation  = joint.GetRotation(stream);
        var targetPosition = target.GetPosition(stream);

        var fromDir = jointRotation * jointAxis;
        var toDir   = targetPosition - jointPosition;

        var axis  = Vector3.Cross(fromDir, toDir).normalized;
        var angle = Vector3.Angle(fromDir, toDir);

        angle = Mathf.Clamp(angle, minAngle, maxAngle);
        var jointToTargetRotation = Quaternion.AngleAxis(angle, axis);

        jointRotation = jointToTargetRotation * jointRotation;

        joint.SetRotation(stream, jointRotation);
    }
Пример #2
0
    private static void Solve(AnimationStream stream, TransformStreamHandle topHandle, TransformStreamHandle midHandle, TransformStreamHandle lowHandle, TransformSceneHandle effectorHandle)
    {
        Quaternion aRotation = topHandle.GetRotation(stream);
        Quaternion bRotation = midHandle.GetRotation(stream);
        Quaternion eRotation = effectorHandle.GetRotation(stream);

        Vector3 aPosition = topHandle.GetPosition(stream);
        Vector3 bPosition = midHandle.GetPosition(stream);
        Vector3 cPosition = lowHandle.GetPosition(stream);
        Vector3 ePosition = effectorHandle.GetPosition(stream);

        Vector3 ab = bPosition - aPosition;
        Vector3 bc = cPosition - bPosition;
        Vector3 ac = cPosition - aPosition;
        Vector3 ae = ePosition - aPosition;

        float   abcAngle = TriangleAngle(ac.magnitude, ab, bc);
        float   abeAngle = TriangleAngle(ae.magnitude, ab, bc);
        float   angle    = (abcAngle - abeAngle) * Mathf.Rad2Deg;
        Vector3 axis     = Vector3.Cross(ab, bc).normalized;

        Quaternion fromToRotation = Quaternion.AngleAxis(angle, axis);

        Quaternion worldQ = fromToRotation * bRotation;

        midHandle.SetRotation(stream, worldQ);

        cPosition = lowHandle.GetPosition(stream);
        ac        = cPosition - aPosition;
        Quaternion fromTo = Quaternion.FromToRotation(ac, ae);

        topHandle.SetRotation(stream, fromTo * aRotation);

        //lowHandle.SetRotation(stream, eRotation);
    }
Пример #3
0
    public void Setup(Animator animator, Transform topX, Transform midX, Transform lowX, Transform effectorX)
    {
        top = animator.BindStreamTransform(topX);
        mid = animator.BindStreamTransform(midX);
        low = animator.BindStreamTransform(lowX);

        effector = animator.BindSceneTransform(effectorX);
    }
Пример #4
0
//
    public bool Setup(Animator animator, EditorSettings editorSettings)
    {
        jobSettings = editorSettings.jobSettings;

        m_CameraHandle  = animator.BindStreamTransform(editorSettings.cameraBone);
        m_CharacterRoot = animator.BindStreamTransform(editorSettings.characterRootBone);
        return(true);
    }
Пример #5
0
 public static MirrorPoseJob Create(TransformStreamHandle root, int mirroringTransformsLength, int mirroringParentConstraintsLength)
 {
     return(new MirrorPoseJob {
         mirror = false,
         root = root,
         mirroringTransforms = new NativeArray <MirroringTransform> (mirroringTransformsLength, Allocator.Persistent, NativeArrayOptions.UninitializedMemory),
         mirroringConstrants = new NativeArray <MirroringConstrant> (mirroringParentConstraintsLength, Allocator.Persistent, NativeArrayOptions.UninitializedMemory)
     });
 }
Пример #6
0
        public void ProcessAnimation(AnimationStream stream)
        {
            AnimationStream inputStream = stream.GetInputStream(0);

            if (BlendActive)
            {
                for (int i = 0; i < TargetAnimationTransforms.Length; ++i)
                {
                    TransformStreamHandle TargetTransform   = TargetAnimationTransforms[i];
                    TransformSceneHandle  CurrentTransform  = CurrentAnimationTransforms[i];
                    TransformData         PreviousTransform = PreviousAnimationTransforms[i];

                    float3 currentPos = float3.zero;
                    if (i == 0)
                    {
                        float3 targetPos = TargetTransform.GetLocalPosition(inputStream);
                        currentPos = CurrentTransform.GetLocalPosition(stream);

                        float3 pos = Inertialize(PreviousTransform.Position,
                                                 currentPos, targetPos, DeltaTime, RemainingTime, DeltaTime);

                        TargetTransform.SetLocalPosition(stream, pos);
                    }

                    quaternion targetRot  = TargetTransform.GetLocalRotation(inputStream);
                    quaternion currentRot = CurrentTransform.GetLocalRotation(stream);

                    quaternion rot = Inertialize(PreviousTransform.Rotation,
                                                 currentRot, targetRot, DeltaTime, RemainingTime, DeltaTime);

                    TargetTransform.SetLocalRotation(stream, rot);

                    PreviousAnimationTransforms[i] = new TransformData(currentPos,
                                                                       currentRot);
                }
            }
            else
            {
                for (int i = 0; i < TargetAnimationTransforms.Length; ++i)
                {
                    TransformStreamHandle TargetTransform  = TargetAnimationTransforms[i];
                    TransformSceneHandle  CurrentTransform = CurrentAnimationTransforms[i];

                    if (i == 0)
                    {
                        TargetTransform.SetLocalPosition(stream, TargetTransform.GetLocalPosition(inputStream));
                    }

                    TargetTransform.SetLocalRotation(stream, TargetTransform.GetLocalRotation(inputStream));

                    PreviousAnimationTransforms[i] = new TransformData(CurrentTransform.GetLocalPosition(stream),
                                                                       CurrentTransform.GetLocalRotation(stream));
                }
            }
        }
Пример #7
0
    public bool Setup(Animator animator, IkChain chain, Type componentType, string weightProperty, string weightOffsetProperty, string targetOffsetProperty)
    {
        if (!chain.HasValidData())
        {
            return(false);
        }

        // Target
        m_TargetOffset = chain.target.offset;

        if (chain.target.readFrom == TargetType.Stream)
        {
            m_EffectorStreamHandle = animator.BindStreamTransform(chain.target.target);
            m_UseStreamEffector    = true;
        }
        else
        {
            m_EffectorSceneHandle = animator.BindSceneTransform(chain.target.target);
            m_UseStreamEffector   = false;
        }


        // Weight
        if (chain.weight.useAnimatorProperty && chain.weight.propertyName != "")
        {
            m_AnimatorWeight      = animator.BindStreamProperty(animator.transform, typeof(Animator), chain.weight.propertyName);
            m_UseAnimatorProperty = true;
        }

        m_WeightHandle         = animator.BindSceneProperty(animator.transform, componentType, weightProperty);
        m_AnimatorWeightOffset = animator.BindSceneProperty(animator.transform, componentType, weightOffsetProperty);


        // Driven
        m_IkType = chain.driven.type;

        if (m_IkType == IkType.Generic)
        {
            var end   = chain.driven.genericEndJoint;
            var mid   = end.parent;
            var start = mid.parent;

            m_StartHandle = animator.BindStreamTransform(start);
            m_MidHandle   = animator.BindStreamTransform(mid);
            m_EndHandle   = animator.BindStreamTransform(end);
        }
        else
        {
            m_HumanLimb = chain.driven.humanoidLimb;
        }

        return(true);
    }
Пример #8
0
    public static void UpdateStream(TransformStreamHandle handle, AnimationStream stream, AnimationStream A, AnimationStream B, float w)
    {
        var posA = handle.GetLocalPosition(A);
        var posB = handle.GetLocalPosition(B);
        var pos  = Vector3.Lerp(posA, posB, w);

        var rotA = handle.GetLocalRotation(A);
        var rotB = handle.GetLocalRotation(B);
        var rot  = Quaternion.Slerp(rotA, rotB, w);

        handle.SetLocalPosition(stream, pos);
        handle.SetLocalRotation(stream, rot);
    }
Пример #9
0
    public bool Setup(Animator animator, EditorSettings editorSettings, float deltaTime, NativeQueue <Quaternion> dragHistory)
    {
        if (!editorSettings.HasValidData())
        {
            return(false);
        }

        settings           = editorSettings.settings;
        m_Effectorhandle   = animator.BindStreamTransform(editorSettings.weaponHandBone);
        m_WeaponPivot      = animator.BindStreamTransform(editorSettings.weaponBone);
        m_WeaponHandResult = animator.BindSceneTransform(editorSettings.applyResultOn);
        m_DragHistory      = dragHistory;
        return(true);
    }
Пример #10
0
        public void Setup(Animator animator, Transform[] bones, Transform target, Transform poleTarget, Transform aimTransform)
        {
            this.bones       = new NativeArray <TransformStreamHandle>(bones.Length, Allocator.Persistent);
            this.boneWeights = new NativeArray <PropertySceneHandle>(bones.Length, Allocator.Persistent);

            for (int i = 0; i < this.bones.Length; i++)
            {
                this.bones[i] = animator.BindStreamTransform(bones[i]);
            }


            for (int i = 0; i < this.bones.Length; i++)
            {
                var boneParams = bones[i].gameObject.GetComponent <IKJBoneParams>();
                if (boneParams == null)
                {
                    boneParams = bones[i].gameObject.AddComponent <IKJBoneParams>();
                }

                this.boneWeights[i] = animator.BindSceneProperty(bones[i].transform, typeof(IKJBoneParams), "weight");
            }

            // Rotation Limits
            SetUpRotationLimits(animator, bones);

            _target           = animator.BindSceneTransform(target);
            _poleTarget       = animator.BindSceneTransform(poleTarget);
            _transform        = animator.BindStreamTransform(aimTransform);
            _IKPositionWeight = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "weight");
            _poleWeight       = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "poleWeight");
            _axisX            = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "axisX");
            _axisY            = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "axisY");
            _axisZ            = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "axisZ");
            _poleAxisX        = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "poleAxisX");
            _poleAxisY        = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "poleAxisY");
            _poleAxisZ        = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "poleAxisZ");
            _clampWeight      = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "clampWeight");
            _clampSmoothing   = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "clampSmoothing");
            _maxIterations    = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "maxIterations");
            _tolerance        = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "tolerance");
            _XY = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "XY");
            _useRotationLimits = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "useRotationLimits");

            step = 1f / (float)bones.Length;
        }
Пример #11
0
    public static void SolveTwoBoneIK
    (
        AnimationStream stream,
        TransformStreamHandle topHandle,
        TransformStreamHandle midHandle,
        TransformStreamHandle lowHandle,
        Vector3 effectorPosition,
        Quaternion effectorRotation,
        float posWeight,
        float rotWeight)
    {
        Quaternion aRotation = topHandle.GetRotation(stream);
        Quaternion bRotation = midHandle.GetRotation(stream);

        Vector3 aPosition = topHandle.GetPosition(stream);
        Vector3 bPosition = midHandle.GetPosition(stream);
        Vector3 cPosition = lowHandle.GetPosition(stream);

        Vector3 ab = bPosition - aPosition;
        Vector3 bc = cPosition - bPosition;
        Vector3 ac = cPosition - aPosition;
        Vector3 ad = (Vector3.Lerp(cPosition, effectorPosition, posWeight) - aPosition);

        float oldAbcAngle = TriangleAngle(ac.magnitude, ab, bc);
        float newAbcAngle = TriangleAngle(ad.magnitude, ab, bc);

        Vector3    axis = Vector3.Cross(ab, bc).normalized;
        float      a    = 0.5f * (oldAbcAngle - newAbcAngle);
        float      sin  = Mathf.Sin(a);
        float      cos  = Mathf.Cos(a);
        Quaternion q    = new Quaternion(axis.x * sin, axis.y * sin, axis.z * sin, cos);

        Quaternion worldQ = q * bRotation;

        midHandle.SetRotation(stream, worldQ);

        aRotation = topHandle.GetRotation(stream);
        cPosition = lowHandle.GetPosition(stream);
        ac        = cPosition - aPosition;
        Quaternion fromTo = Quaternion.FromToRotation(ac, ad);

        topHandle.SetRotation(stream, fromTo * aRotation);
        lowHandle.SetRotation(stream, Quaternion.Lerp(lowHandle.GetRotation(stream), effectorRotation, rotWeight));
    }
Пример #12
0
    public bool Setup(Animator animator, EditorSettings editorSettings, float deltaTime,
                      NativeArray <MuscleHandle> headMuscles, NativeArray <MuscleHandle> spineMuscles)
    {
        if (!editorSettings.HasValidData())
        {
            return(false);
        }

        m_SkeletonHandle = animator.BindStreamTransform(editorSettings.bankTransform);

        m_HeadLeftRightMuscles  = headMuscles;
        m_SpineLeftRightMuscles = spineMuscles;

        m_HeadLeftRightMuscles[0] = new MuscleHandle(HeadDof.NeckLeftRight);
        m_HeadLeftRightMuscles[1] = new MuscleHandle(HeadDof.HeadLeftRight);

        m_SpineLeftRightMuscles[0] = new MuscleHandle(BodyDof.SpineLeftRight);
        m_SpineLeftRightMuscles[1] = new MuscleHandle(BodyDof.ChestLeftRight);
        m_SpineLeftRightMuscles[2] = new MuscleHandle(BodyDof.UpperChestLeftRight);


        return(true);
    }
Пример #13
0
        private static void Solve(AnimationStream stream, TransformStreamHandle topHandle, TransformStreamHandle midHandle, TransformStreamHandle lowHandle,
                                  TransformSceneHandle effectorHandle)
        {
            var aRotation = topHandle.GetRotation(stream);
            var bRotation = midHandle.GetRotation(stream);
            var eRotation = effectorHandle.GetRotation(stream);

            var aPosition = topHandle.GetPosition(stream);
            var bPosition = midHandle.GetPosition(stream);
            var cPosition = lowHandle.GetPosition(stream);
            var ePosition = effectorHandle.GetPosition(stream);

            var ab = bPosition - aPosition;
            var bc = cPosition - bPosition;
            var ac = cPosition - aPosition;
            var ae = ePosition - aPosition;

            var abcAngle = TriangleAngle(ac.magnitude, ab, bc);
            var abeAngle = TriangleAngle(ae.magnitude, ab, bc);
            var angle    = (abcAngle - abeAngle) * Mathf.Rad2Deg;
            var axis     = Vector3.Cross(ab, bc).normalized;

            var fromToRotation = Quaternion.AngleAxis(angle, axis);

            var worldQ = fromToRotation * bRotation;

            midHandle.SetRotation(stream, worldQ);

            cPosition = lowHandle.GetPosition(stream);
            ac        = cPosition - aPosition;
            var fromTo = Quaternion.FromToRotation(ac, ae);

            topHandle.SetRotation(stream, fromTo * aRotation);

            lowHandle.SetRotation(stream, eRotation);
        }
Пример #14
0
 public void Setup(Animator animator, Transform boneToFollow, Transform slavedTransform)
 {
     m_BoneToFollow    = animator.BindStreamTransform(boneToFollow);
     m_SlavedTransform = animator.BindSceneTransform(slavedTransform);
 }