Exemplo n.º 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);
    }
Exemplo n.º 2
0
        public void Setup(Animator animator, Transform[] bones, Transform target)
        {
            this.bones       = new NativeArray <TransformStreamHandle>(bones.Length, Allocator.Persistent);
            this.boneWeights = new NativeArray <PropertySceneHandle>(bones.Length - 1, Allocator.Persistent);
            this.boneSqrMags = new NativeArray <float>(bones.Length - 1, 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 - 1; 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);
            _IKPositionWeight = animator.BindSceneProperty(animator.transform, typeof(CCDIKJ), "weight");
            _maxIterations    = animator.BindSceneProperty(animator.transform, typeof(CCDIKJ), "maxIterations");
            _tolerance        = animator.BindSceneProperty(animator.transform, typeof(CCDIKJ), "tolerance");
            _XY = animator.BindSceneProperty(animator.transform, typeof(CCDIKJ), "XY");
            _useRotationLimits = animator.BindSceneProperty(animator.transform, typeof(CCDIKJ), "useRotationLimits");
        }
Exemplo n.º 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);
    }
Exemplo n.º 4
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));
                }
            }
        }
Exemplo n.º 5
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);
    }
Exemplo n.º 6
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);
    }
Exemplo n.º 7
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;
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
 public void Setup(Animator animator, Transform boneToFollow, Transform slavedTransform)
 {
     m_BoneToFollow    = animator.BindStreamTransform(boneToFollow);
     m_SlavedTransform = animator.BindSceneTransform(slavedTransform);
 }
Exemplo n.º 10
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);
    }